lisp/gnus/gnus-sum.el (gnus-summary-make-menu-bar): Add "Display HTML images" to...
[emacs.git] / lisp / gnus / gnus-art.el
blob19da2cce42f3dba17cc04287aa875149ed58d0c4
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
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/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
167 (defcustom gnus-visible-headers
168 "^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:"
169 "*All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "*This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
197 'empty Headers with no content.
198 'newsgroups Newsgroup identical to Gnus group.
199 'to-address To identical to To-address.
200 'to-list To identical to To-list.
201 'cc-list CC identical to To-list.
202 'followup-to Followup-to identical to Newsgroups.
203 'reply-to Reply-to identical to From.
204 'date Date less than four days old.
205 'long-to To and/or Cc longer than 1024 characters.
206 'many-to Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "CC identical to To-list." cc-list)
212 (const :tag "Followup-to identical to Newsgroups." followup-to)
213 (const :tag "Reply-to identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
256 (defcustom gnus-hidden-properties
257 (if (featurep 'xemacs)
258 ;; `intangible' is evil, but I keep it here in case it's useful.
259 '(invisible t intangible t)
260 ;; Emacs's command loop moves point out of invisible text anyway, so
261 ;; `intangible' is clearly not needed there.
262 '(invisible t))
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo \
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | ee -")
277 (if (gnus-image-type-available-p 'pbm)
278 'gnus-display-x-face-in-from
279 "{ echo \
280 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
281 ; uncompface; } | icontopbm | display -"))
282 "*String or function to be executed to display an X-Face header.
283 If it is a string, the command will be executed in a sub-shell
284 asynchronously. The compressed face will be piped to this command."
285 :type `(choice string
286 (function-item gnus-display-x-face-in-from)
287 function)
288 :version "21.1"
289 :group 'gnus-picon
290 :group 'gnus-article-washing)
292 (defcustom gnus-article-x-face-too-ugly nil
293 "Regexp matching posters whose face shouldn't be shown automatically."
294 :type '(choice regexp (const nil))
295 :group 'gnus-article-washing)
297 (defcustom gnus-article-banner-alist nil
298 "Banner alist for stripping.
299 For example,
300 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301 :version "21.1"
302 :type '(repeat (cons symbol regexp))
303 :group 'gnus-article-washing)
305 (gnus-define-group-parameter
306 banner
307 :variable-document
308 "Alist of regexps (to match group names) and banner."
309 :variable-group gnus-article-washing
310 :parameter-type
311 '(choice :tag "Banner"
312 :value nil
313 (const :tag "Remove signature" signature)
314 (symbol :tag "Item in `gnus-article-banner-alist'" none)
315 regexp
316 (const :tag "None" nil))
317 :parameter-document
318 "If non-nil, specify how to remove `banners' from articles.
320 Symbol `signature' means to remove signatures delimited by
321 `gnus-signature-separator'. Any other symbol is used to look up a
322 regular expression to match the banner in `gnus-article-banner-alist'.
323 A string is used as a regular expression to match the banner
324 directly.")
326 (defcustom gnus-article-address-banner-alist nil
327 "Alist of mail addresses and banners.
328 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
329 to match a mail address in the From: header, BANNER is one of a symbol
330 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
331 If ADDRESS matches author's mail address, it will remove things like
332 advertisements. For example:
334 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
336 :type '(repeat
337 (cons
338 (regexp :tag "Address")
339 (choice :tag "Banner" :value nil
340 (const :tag "Remove signature" signature)
341 (symbol :tag "Item in `gnus-article-banner-alist'" none)
342 regexp
343 (const :tag "None" nil))))
344 :version "22.1"
345 :group 'gnus-article-washing)
347 (defmacro gnus-emphasis-custom-with-format (&rest body)
348 `(let ((format "\
349 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
350 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351 ,@body))
353 (defun gnus-emphasis-custom-value-to-external (value)
354 (gnus-emphasis-custom-with-format
355 (if (consp (car value))
356 (list (format format (car (car value)) (cdr (car value)))
358 (if (nth 1 value) 2 3)
359 (nth 2 value))
360 value)))
362 (defun gnus-emphasis-custom-value-to-internal (value)
363 (gnus-emphasis-custom-with-format
364 (let ((regexp (concat "\\`"
365 (format (regexp-quote format)
366 "\\([^()]+\\)" "\\([^()]+\\)")
367 "\\'"))
368 pattern)
369 (if (string-match regexp (setq pattern (car value)))
370 (list (cons (match-string 1 pattern) (match-string 2 pattern))
371 (= (nth 2 value) 2)
372 (nth 3 value))
373 value))))
375 (defcustom gnus-emphasis-alist
376 (let ((types
377 '(("\\*" "\\*" bold nil 2)
378 ("_" "_" underline)
379 ("/" "/" italic)
380 ("_/" "/_" underline-italic)
381 ("_\\*" "\\*_" underline-bold)
382 ("\\*/" "/\\*" bold-italic)
383 ("_\\*/" "/\\*_" underline-bold-italic))))
384 (nconc
385 (gnus-emphasis-custom-with-format
386 (mapcar (lambda (spec)
387 (list (format format (car spec) (cadr spec))
388 (or (nth 3 spec) 2)
389 (or (nth 4 spec) 3)
390 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391 types))
392 '(;; I've never seen anyone use this strikethru convention whereas I've
393 ;; several times seen it triggered by normal text. --Stef
394 ;; Miles suggests that this form is sometimes used but for italics,
395 ;; so maybe we should map it to `italic'.
396 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
397 ;; 2 3 gnus-emphasis-strikethru)
398 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
399 2 3 gnus-emphasis-underline))))
400 "*Alist that says how to fontify certain phrases.
401 Each item looks like this:
403 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
405 The first element is a regular expression to be matched. The second
406 is a number that says what regular expression grouping used to find
407 the entire emphasized word. The third is a number that says what
408 regexp grouping should be displayed and highlighted. The fourth
409 is the face used for highlighting."
410 :type
411 '(repeat
412 (menu-choice
413 :format "%[Customizing Style%]\n%v"
414 :indent 2
415 (group :tag "Default"
416 :value ("" 0 0 default)
417 :value-create
418 (lambda (widget)
419 (let ((value (widget-get
420 (cadr (widget-get (widget-get widget :parent)
421 :args))
422 :value)))
423 (if (not (eq (nth 2 value) 'default))
424 (widget-put
425 widget
426 :value
427 (gnus-emphasis-custom-value-to-external value))))
428 (widget-group-value-create widget))
429 regexp
430 (integer :format "Match group: %v")
431 (integer :format "Emphasize group: %v")
432 face)
433 (group :tag "Simple"
434 :value (("_" . "_") nil default)
435 (cons :format "%v"
436 (regexp :format "Start regexp: %v")
437 (regexp :format "End regexp: %v"))
438 (boolean :format "Show start and end patterns: %[%v%]\n"
439 :on " On " :off " Off ")
440 face)))
441 :get (lambda (symbol)
442 (mapcar 'gnus-emphasis-custom-value-to-internal
443 (default-value symbol)))
444 :set (lambda (symbol value)
445 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446 value)))
447 :group 'gnus-article-emphasis)
449 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
450 "A regexp to describe whitespace which should not be emphasized.
451 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
452 The former avoids underlining of leading and trailing whitespace,
453 and the latter avoids underlining any whitespace at all."
454 :version "21.1"
455 :group 'gnus-article-emphasis
456 :type 'regexp)
458 (defface gnus-emphasis-bold '((t (:bold t)))
459 "Face used for displaying strong emphasized text (*word*)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-italic '((t (:italic t)))
463 "Face used for displaying italic emphasized text (/word/)."
464 :group 'gnus-article-emphasis)
466 (defface gnus-emphasis-underline '((t (:underline t)))
467 "Face used for displaying underlined emphasized text (_word_)."
468 :group 'gnus-article-emphasis)
470 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
471 "Face used for displaying underlined bold emphasized text (_*word*_)."
472 :group 'gnus-article-emphasis)
474 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
475 "Face used for displaying underlined italic emphasized text (_/word/_)."
476 :group 'gnus-article-emphasis)
478 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
479 "Face used for displaying bold italic emphasized text (/*word*/)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-underline-bold-italic
483 '((t (:bold t :italic t :underline t)))
484 "Face used for displaying underlined bold italic emphasized text.
485 Example: (_/*word*/_)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
489 '((t (:strikethru t)))
490 '((t (:strike-through t))))
491 "Face used for displaying strike-through text (-word-)."
492 :group 'gnus-article-emphasis)
494 (defface gnus-emphasis-highlight-words
495 '((t (:background "black" :foreground "yellow")))
496 "Face used for displaying highlighted words."
497 :group 'gnus-article-emphasis)
499 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
500 "Format for display of Date headers in article bodies.
501 See `format-time-string' for the possible values.
503 The variable can also be function, which should return a complete Date
504 header. The function is called with one argument, the time, which can
505 be fed to `format-time-string'."
506 :type '(choice string function)
507 :link '(custom-manual "(gnus)Article Date")
508 :group 'gnus-article-washing)
510 (defcustom gnus-save-all-headers t
511 "*If non-nil, don't remove any headers before saving.
512 This will be overridden by the `:headers' property that the symbol of
513 the saver function, which is specified by `gnus-default-article-saver',
514 might have."
515 :group 'gnus-article-saving
516 :type 'boolean)
518 (defcustom gnus-prompt-before-saving 'always
519 "*This variable says how much prompting is to be done when saving articles.
520 If it is nil, no prompting will be done, and the articles will be
521 saved to the default files. If this variable is `always', each and
522 every article that is saved will be preceded by a prompt, even when
523 saving large batches of articles. If this variable is neither nil not
524 `always', there the user will be prompted once for a file name for
525 each invocation of the saving commands."
526 :group 'gnus-article-saving
527 :type '(choice (item always)
528 (item :tag "never" nil)
529 (sexp :tag "once" :format "%t\n" :value t)))
531 (defcustom gnus-saved-headers gnus-visible-headers
532 "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving. This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539 :group 'gnus-article-saving
540 :type 'regexp)
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544 "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
548 Gnus provides the following functions:
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
560 The symbol of each function may have the following properties:
562 * :decode
563 The value non-nil means save decoded articles. This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file. This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file. This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved. If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580 :group 'gnus-article-saving
581 :type '(radio (function-item gnus-summary-save-in-rmail)
582 (function-item gnus-summary-save-in-mail)
583 (function-item gnus-summary-save-in-folder)
584 (function-item gnus-summary-save-in-file)
585 (function-item gnus-summary-save-body-in-file)
586 (function-item gnus-summary-save-in-vm)
587 (function-item gnus-summary-write-to-file)
588 (function-item gnus-summary-write-body-to-file)
589 (function-item gnus-summary-save-in-pipe)
590 (function)))
592 (defcustom gnus-article-save-coding-system
593 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597 "Coding system used to save decoded articles to a file.
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text. This is used by the
601 commands including:
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
608 and the functions to which you may set `gnus-default-article-saver':
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil. Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619 :group 'gnus-article-saving
620 :type `(choice
621 :format "%{%t%}:\n %[Value Menu%] %v"
622 (const :tag "Save raw articles" nil)
623 ,@(delq nil
624 (mapcar
625 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626 '((const :tag "UTF-8" utf-8)
627 (const :tag "iso-2022-7bit" iso-2022-7bit)
628 (const :tag "Emacs internal" emacs-mule)
629 (const :tag "escape-quoted" escape-quoted))))
630 (symbol :tag "Coding system")))
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639 "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645 "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647 :group 'gnus-article-saving
648 :type 'function)
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651 "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654 :group 'gnus-article-saving
655 :type 'function)
657 (defcustom gnus-split-methods
658 '((gnus-article-archive-name)
659 (gnus-article-nndoc-name))
660 "*Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
665 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
672 If the match is a string, it is used as a regexp match on the
673 article. If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter. If it is a list, it will be evalled in the same buffer.
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680 :group 'gnus-article-saving
681 :type '(repeat (choice (list :value (fun) function)
682 (cons :value ("" "") regexp (repeat string))
683 (sexp :value nil))))
685 (defcustom gnus-page-delimiter "^\^L"
686 "*Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689 :type 'regexp
690 :group 'gnus-article-various)
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693 "*The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
696 The following additional specs are available:
698 %w The article washing status.
699 %m The number of MIME parts in the article."
700 :version "24.1"
701 :type 'string
702 :group 'gnus-article-various)
704 (defcustom gnus-article-mode-hook nil
705 "*A hook for Gnus article mode."
706 :type 'hook
707 :group 'gnus-article-various)
709 (when (featurep 'xemacs)
710 ;; Extracted from gnus-xmas-define in order to preserve user settings
711 (when (fboundp 'turn-off-scroll-in-place)
712 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
713 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
714 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
716 (defcustom gnus-article-menu-hook nil
717 "*Hook run after the creation of the article mode menu."
718 :type 'hook
719 :group 'gnus-article-various)
721 (defcustom gnus-article-prepare-hook nil
722 "*A hook called after an article has been prepared in the article buffer."
723 :type 'hook
724 :group 'gnus-article-various)
726 (defcustom gnus-copy-article-ignored-headers nil
727 "List of headers to be removed when copying an article.
728 Each element is a regular expression."
729 :version "23.1" ;; No Gnus
730 :type '(repeat regexp)
731 :group 'gnus-article-various)
733 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
734 "Gnus 5.10 (Emacs 22.1)")
736 (defface gnus-button
737 '((t (:weight bold)))
738 "Face used for highlighting a button in the article buffer."
739 :group 'gnus-article-buttons)
741 (defcustom gnus-article-button-face 'gnus-button
742 "Face used for highlighting buttons in the article buffer.
744 An article button is a piece of text that you can activate by pressing
745 `RET' or `mouse-2' above it."
746 :type 'face
747 :group 'gnus-article-buttons)
749 (defcustom gnus-article-mouse-face 'highlight
750 "Face used for mouse highlighting in the article buffer.
752 Article buttons will be displayed in this face when the cursor is
753 above them."
754 :type 'face
755 :group 'gnus-article-buttons)
757 (defcustom gnus-signature-face 'gnus-signature
758 "Face used for highlighting a signature in the article buffer.
759 Obsolete; use the face `gnus-signature' for customizations instead."
760 :type 'face
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
764 (defface gnus-signature
765 '((t
766 (:italic t)))
767 "Face used for highlighting a signature in the article buffer."
768 :group 'gnus-article-highlight
769 :group 'gnus-article-signature)
770 ;; backward-compatibility alias
771 (put 'gnus-signature-face 'face-alias 'gnus-signature)
772 (put 'gnus-signature-face 'obsolete-face "22.1")
774 (defface gnus-header-from
775 '((((class color)
776 (background dark))
777 (:foreground "PaleGreen1"))
778 (((class color)
779 (background light))
780 (:foreground "red3"))
782 (:italic t)))
783 "Face used for displaying from headers."
784 :group 'gnus-article-headers
785 :group 'gnus-article-highlight)
786 ;; backward-compatibility alias
787 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
788 (put 'gnus-header-from-face 'obsolete-face "22.1")
790 (defface gnus-header-subject
791 '((((class color)
792 (background dark))
793 (:foreground "SeaGreen1"))
794 (((class color)
795 (background light))
796 (:foreground "red4"))
798 (:bold t :italic t)))
799 "Face used for displaying subject headers."
800 :group 'gnus-article-headers
801 :group 'gnus-article-highlight)
802 ;; backward-compatibility alias
803 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
804 (put 'gnus-header-subject-face 'obsolete-face "22.1")
806 (defface gnus-header-newsgroups
807 '((((class color)
808 (background dark))
809 (:foreground "yellow" :italic t))
810 (((class color)
811 (background light))
812 (:foreground "MidnightBlue" :italic t))
814 (:italic t)))
815 "Face used for displaying newsgroups headers.
816 In the default setup this face is only used for crossposted
817 articles."
818 :group 'gnus-article-headers
819 :group 'gnus-article-highlight)
820 ;; backward-compatibility alias
821 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
822 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
824 (defface gnus-header-name
825 '((((class color)
826 (background dark))
827 (:foreground "SpringGreen2"))
828 (((class color)
829 (background light))
830 (:foreground "maroon"))
832 (:bold t)))
833 "Face used for displaying header names."
834 :group 'gnus-article-headers
835 :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
838 (put 'gnus-header-name-face 'obsolete-face "22.1")
840 (defface gnus-header-content
841 '((((class color)
842 (background dark))
843 (:foreground "SpringGreen1" :italic t))
844 (((class color)
845 (background light))
846 (:foreground "indianred4" :italic t))
848 (:italic t))) "Face used for displaying header content."
849 :group 'gnus-article-headers
850 :group 'gnus-article-highlight)
851 ;; backward-compatibility alias
852 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
853 (put 'gnus-header-content-face 'obsolete-face "22.1")
855 (defcustom gnus-header-face-alist
856 '(("From" nil gnus-header-from)
857 ("Subject" nil gnus-header-subject)
858 ("Newsgroups:.*," nil gnus-header-newsgroups)
859 ("" gnus-header-name gnus-header-content))
860 "*Controls highlighting of article headers.
862 An alist of the form (HEADER NAME CONTENT).
864 HEADER is a regular expression which should match the name of a
865 header and NAME and CONTENT are either face names or nil.
867 The name of each header field will be displayed using the face
868 specified by the first element in the list where HEADER matches
869 the header name and NAME is non-nil. Similarly, the content will
870 be displayed by the first non-nil matching CONTENT face."
871 :group 'gnus-article-headers
872 :group 'gnus-article-highlight
873 :type '(repeat (list (regexp :tag "Header")
874 (choice :tag "Name"
875 (item :tag "skip" nil)
876 (face :value default))
877 (choice :tag "Content"
878 (item :tag "skip" nil)
879 (face :value default)))))
881 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
882 '((xface . (:face gnus-x-face)))
883 '((pbm . (:face gnus-x-face))
884 (png . nil)))
885 "Alist of image types and properties applied to Face and X-Face images.
886 Here are examples:
888 ;; Specify the altitude of Face images in the From header.
889 \(setq gnus-face-properties-alist
890 '((pbm . (:face gnus-x-face :ascent 80))
891 (png . (:ascent 80))))
893 ;; Show Face images as pressed buttons.
894 \(setq gnus-face-properties-alist
895 '((pbm . (:face gnus-x-face :relief -2))
896 (png . (:relief -2))))
898 See the manual for the valid properties for various image types.
899 Currently, `pbm' is used for X-Face images and `png' is used for Face
900 images in Emacs. Only the `:face' property is effective on the `xface'
901 image type in XEmacs if it is built with the libcompface library."
902 :version "23.1" ;; No Gnus
903 :group 'gnus-article-headers
904 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
906 (defcustom gnus-article-decode-hook
907 '(article-decode-charset article-decode-encoded-words
908 article-decode-group-name article-decode-idna-rhs)
909 "*Hook run to decode charsets in articles."
910 :group 'gnus-article-headers
911 :type 'hook)
913 (defcustom gnus-display-mime-function 'gnus-display-mime
914 "Function to display MIME articles."
915 :group 'gnus-article-mime
916 :type 'function)
918 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
919 "Function used to decode headers.")
921 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
922 "Function used to decode addresses.")
924 (defvar gnus-article-dumbquotes-map
925 '((?\200 "EUR")
926 (?\202 ",")
927 (?\203 "f")
928 (?\204 ",,")
929 (?\205 "...")
930 (?\213 "<")
931 (?\214 "OE")
932 (?\221 "`")
933 (?\222 "'")
934 (?\223 "``")
935 (?\224 "\"")
936 (?\225 "*")
937 (?\226 "-")
938 (?\227 "--")
939 (?\230 "~")
940 (?\231 "(TM)")
941 (?\233 ">")
942 (?\234 "oe")
943 (?\264 "'"))
944 "Table for MS-to-Latin1 translation.")
946 (defcustom gnus-ignored-mime-types nil
947 "List of MIME types that should be ignored by Gnus."
948 :version "21.1"
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
952 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
953 "List of MIME types that should not be given buttons when rendered inline.
954 See also `gnus-buttonized-mime-types' which may override this variable.
955 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956 :version "21.1"
957 :group 'gnus-article-mime
958 :type '(repeat regexp))
960 (defcustom gnus-buttonized-mime-types nil
961 "List of MIME types that should be given buttons when rendered inline.
962 If set, this variable overrides `gnus-unbuttonized-mime-types'.
963 To see e.g. security buttons you could set this to
964 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
965 this list to display radio buttons that allow you to choose one of two
966 media types those mails include. See also `mm-discouraged-alternatives'.
967 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type '(repeat regexp))
972 (defcustom gnus-inhibit-mime-unbuttonizing nil
973 "If non-nil, all MIME parts get buttons.
974 When nil (the default value), then some MIME parts do not get buttons,
975 as described by the variables `gnus-buttonized-mime-types' and
976 `gnus-unbuttonized-mime-types'."
977 :version "22.1"
978 :group 'gnus-article-mime
979 :type 'boolean)
981 (defcustom gnus-body-boundary-delimiter "_"
982 "String used to delimit header and body.
983 This variable is used by `gnus-article-treat-body-boundary' which can
984 be controlled by `gnus-treat-body-boundary'."
985 :version "22.1"
986 :group 'gnus-article-various
987 :type '(choice (item :tag "None" :value nil)
988 string))
990 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991 "/usr/share/picons")
992 "Defines the location of the faces database.
993 For information on obtaining this database of pretty pictures, please
994 see http://www.cs.indiana.edu/picons/ftp/index.html"
995 :version "22.1"
996 :type '(repeat directory)
997 :link '(url-link :tag "download"
998 "http://www.cs.indiana.edu/picons/ftp/index.html")
999 :link '(custom-manual "(gnus)Picons")
1000 :group 'gnus-picon)
1002 (defun gnus-picons-installed-p ()
1003 "Say whether picons are installed on your machine."
1004 (let ((installed nil))
1005 (dolist (database gnus-picon-databases)
1006 (when (file-exists-p database)
1007 (setq installed t)))
1008 installed))
1010 (defcustom gnus-article-mime-part-function nil
1011 "Function called with a MIME handle as the argument.
1012 This is meant for people who want to do something automatic based
1013 on parts -- for instance, adding Vcard info to a database."
1014 :group 'gnus-article-mime
1015 :type '(choice (const nil)
1016 function))
1018 (defcustom gnus-mime-multipart-functions nil
1019 "An alist of MIME types to functions to display them."
1020 :version "21.1"
1021 :group 'gnus-article-mime
1022 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1024 (defcustom gnus-article-date-headers '(combined-lapsed)
1025 "A list of Date header formats to display.
1026 Valid formats are `ut' (universal time), `local' (local time
1027 zone), `english' (readable English), `lapsed' (elapsed time),
1028 `combined-lapsed' (both the original date and the elapsed time),
1029 `original' (the original date header), `iso8601' (ISO8601
1030 format), and `user-defined' (a user-defined format defined by the
1031 `gnus-article-time-format' variable).
1033 You have as many date headers as you want in the article buffer.
1034 Some of these headers are updated automatically. See
1035 `gnus-article-update-date-headers' for details."
1036 :version "24.1"
1037 :group 'gnus-article-headers
1038 :type '(set
1039 (const :tag "Universal time (UT)" ut)
1040 (const :tag "Local time zone" local)
1041 (const :tag "Readable English" english)
1042 (const :tag "Elapsed time" lapsed)
1043 (const :tag "Original and elapsed time" combined-lapsed)
1044 (const :tag "Original date header" original)
1045 (const :tag "ISO8601 format" iso8601)
1046 (const :tag "User-defined" user-defined)))
1048 (defcustom gnus-article-update-date-headers nil
1049 "A number that says how often to update the date header (in seconds).
1050 If nil, don't update it at all."
1051 :version "24.1"
1052 :group 'gnus-article-headers
1053 :type '(choice
1054 (item :tag "Don't update" :value nil)
1055 integer))
1057 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1058 "Function called with a MIME handle as the argument.
1059 This is meant for people who want to view first matched part.
1060 For `undisplayed-alternative' (default), the first undisplayed
1061 part or alternative part is used. For `undisplayed', the first
1062 undisplayed part is used. For a function, the first part which
1063 the function return t is used. For nil, the first part is
1064 used."
1065 :version "21.1"
1066 :group 'gnus-article-mime
1067 :type '(choice
1068 (item :tag "first" :value nil)
1069 (item :tag "undisplayed" :value undisplayed)
1070 (item :tag "undisplayed or alternative"
1071 :value undisplayed-alternative)
1072 (function)))
1074 (defcustom gnus-mime-action-alist
1075 '(("save to file" . gnus-mime-save-part)
1076 ("save and strip" . gnus-mime-save-part-and-strip)
1077 ("replace with file" . gnus-mime-replace-part)
1078 ("delete part" . gnus-mime-delete-part)
1079 ("display as text" . gnus-mime-inline-part)
1080 ("view the part" . gnus-mime-view-part)
1081 ("pipe to command" . gnus-mime-pipe-part)
1082 ("toggle display" . gnus-article-press-button)
1083 ("toggle display" . gnus-article-view-part-as-charset)
1084 ("view as type" . gnus-mime-view-part-as-type)
1085 ("view internally" . gnus-mime-view-part-internally)
1086 ("view externally" . gnus-mime-view-part-externally))
1087 "An alist of actions that run on the MIME attachment."
1088 :group 'gnus-article-mime
1089 :type '(repeat (cons (string :tag "name")
1090 (function))))
1092 (defcustom gnus-auto-select-part 1
1093 "Advance to next MIME part when deleting or stripping parts.
1095 When 0, point will be placed on the same part as before. When
1096 positive (negative), move point forward (backwards) this many
1097 parts. When nil, redisplay article."
1098 :version "23.1" ;; No Gnus
1099 :group 'gnus-article-mime
1100 :type '(choice (const nil :tag "Redisplay article.")
1101 (const 1 :tag "Next part.")
1102 (const 0 :tag "Current part.")
1103 integer))
1106 ;;; The treatment variables
1109 (defvar gnus-part-display-hook nil
1110 "Hook called on parts that are to receive treatment.")
1112 (defvar gnus-article-treat-custom
1113 '(choice (const :tag "Off" nil)
1114 (const :tag "On" t)
1115 (const :tag "Header" head)
1116 (const :tag "First" first)
1117 (const :tag "Last" last)
1118 (integer :tag "Less")
1119 (repeat :tag "Groups" regexp)
1120 (sexp :tag "Predicate")))
1122 (defvar gnus-article-treat-head-custom
1123 '(choice (const :tag "Off" nil)
1124 (const :tag "Header" head)))
1126 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 "text/x-patch" "text/html")
1128 "Part types eligible for treatment.")
1130 (defvar gnus-inhibit-treatment nil
1131 "Whether to inhibit treatment.")
1133 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1134 "Highlight the signature.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-signature 'highlight t)
1142 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1143 "Add buttons.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-custom)
1149 (put 'gnus-treat-buttonize 'highlight t)
1151 (defcustom gnus-treat-buttonize-head 'head
1152 "Add buttons to the head.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-head-custom)
1158 (put 'gnus-treat-buttonize-head 'highlight t)
1160 (defcustom gnus-treat-date 'head
1161 "Display dates according to the `gnus-article-date-headers' variable.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :version "24.1"
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
1167 :type gnus-article-treat-head-custom)
1169 (defcustom gnus-treat-emphasize 50000
1170 "Emphasize text.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :group 'gnus-article-treat
1174 :link '(custom-manual "(gnus)Customizing Articles")
1175 :type gnus-article-treat-custom)
1176 (put 'gnus-treat-emphasize 'highlight t)
1178 (defcustom gnus-treat-strip-cr nil
1179 "Remove carriage returns.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate. See Info node `(gnus)Customizing Articles'."
1182 :version "22.1"
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1187 (defcustom gnus-treat-unsplit-urls nil
1188 "Remove newlines from within URLs.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :version "22.1"
1192 :group 'gnus-article-treat
1193 :link '(custom-manual "(gnus)Customizing Articles")
1194 :type gnus-article-treat-custom)
1196 (defcustom gnus-treat-leading-whitespace nil
1197 "Remove leading whitespace in headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :version "22.1"
1201 :group 'gnus-article-treat
1202 :link '(custom-manual "(gnus)Customizing Articles")
1203 :type gnus-article-treat-custom)
1205 (defcustom gnus-treat-hide-headers 'head
1206 "Hide headers.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate. See Info node `(gnus)Customizing Articles'."
1209 :group 'gnus-article-treat
1210 :link '(custom-manual "(gnus)Customizing Articles")
1211 :type gnus-article-treat-head-custom)
1213 (defcustom gnus-treat-hide-boring-headers nil
1214 "Hide boring headers.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate. See Info node `(gnus)Customizing Articles'."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-head-custom)
1221 (defcustom gnus-treat-hide-signature nil
1222 "Hide the signature.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate. See Info node `(gnus)Customizing Articles'."
1225 :group 'gnus-article-treat
1226 :link '(custom-manual "(gnus)Customizing Articles")
1227 :type gnus-article-treat-custom)
1229 (defcustom gnus-treat-fill-article nil
1230 "Fill the article.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate. See Info node `(gnus)Customizing Articles'."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1237 (defcustom gnus-treat-hide-citation nil
1238 "Hide cited text.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate. See Info node `(gnus)Customizing Articles'.
1242 See `gnus-article-highlight-citation' for variables used to
1243 control what it hides."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1248 (defcustom gnus-treat-hide-citation-maybe nil
1249 "Hide cited text according to certain conditions.
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate. See Info node `(gnus)Customizing Articles'.
1253 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1254 how to control what it hides."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (defcustom gnus-treat-strip-list-identifiers 'head
1260 "Strip list identifiers from `gnus-list-identifiers`.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate. See Info node `(gnus)Customizing Articles'."
1263 :version "21.1"
1264 :group 'gnus-article-treat
1265 :link '(custom-manual "(gnus)Customizing Articles")
1266 :type gnus-article-treat-custom)
1268 (gnus-define-group-parameter
1269 list-identifier
1270 :variable-document
1271 "Alist of regexps and correspondent identifiers."
1272 :variable-group gnus-article-washing
1273 :parameter-type
1274 '(choice :tag "Identifier"
1275 :value nil
1276 (symbol :tag "Item in `gnus-list-identifiers'" none)
1277 regexp
1278 (const :tag "None" nil))
1279 :parameter-document
1280 "If non-nil, specify how to remove `identifiers' from articles' subject.
1282 Any symbol is used to look up a regular expression to match the
1283 banner in `gnus-list-identifiers'. A string is used as a regular
1284 expression to match the identifier directly.")
1286 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1287 "Gnus 5.10 (Emacs 22.1)")
1289 (defcustom gnus-treat-strip-pem nil
1290 "Strip PEM signatures.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate. See Info node `(gnus)Customizing Articles'."
1293 :group 'gnus-article-treat
1294 :link '(custom-manual "(gnus)Customizing Articles")
1295 :type gnus-article-treat-custom)
1297 (defcustom gnus-treat-strip-banner t
1298 "Strip banners from articles.
1299 The banner to be stripped is specified in the `banner' group parameter.
1300 Valid values are nil, t, `head', `first', `last', an integer or a
1301 predicate. See Info node `(gnus)Customizing Articles'."
1302 :group 'gnus-article-treat
1303 :link '(custom-manual "(gnus)Customizing Articles")
1304 :type gnus-article-treat-custom)
1306 (defcustom gnus-treat-highlight-headers 'head
1307 "Highlight the headers.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate. See Info node `(gnus)Customizing Articles'."
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-head-custom)
1313 (put 'gnus-treat-highlight-headers 'highlight t)
1315 (defcustom gnus-treat-highlight-citation t
1316 "Highlight cited text.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-custom)
1322 (put 'gnus-treat-highlight-citation 'highlight t)
1324 (defcustom gnus-treat-strip-headers-in-body t
1325 "Strip the X-No-Archive header line from the beginning of the body.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'."
1328 :version "21.1"
1329 :group 'gnus-article-treat
1330 :link '(custom-manual "(gnus)Customizing Articles")
1331 :type gnus-article-treat-custom)
1333 (defcustom gnus-treat-strip-trailing-blank-lines nil
1334 "Strip trailing blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate. See Info node `(gnus)Customizing Articles'.
1338 When set to t, it also strips trailing blanks in all MIME parts.
1339 Consider to use `last' instead."
1340 :group 'gnus-article-treat
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :type gnus-article-treat-custom)
1344 (defcustom gnus-treat-strip-leading-blank-lines nil
1345 "Strip leading blank lines.
1346 Valid values are nil, t, `head', `first', `last', an integer or a
1347 predicate. See Info node `(gnus)Customizing Articles'.
1349 When set to t, it also strips trailing blanks in all MIME parts."
1350 :group 'gnus-article-treat
1351 :link '(custom-manual "(gnus)Customizing Articles")
1352 :type gnus-article-treat-custom)
1354 (defcustom gnus-treat-strip-multiple-blank-lines nil
1355 "Strip multiple blank lines.
1356 Valid values are nil, t, `head', `first', `last', an integer or a
1357 predicate. See Info node `(gnus)Customizing Articles'."
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1362 (defcustom gnus-treat-unfold-headers 'head
1363 "Unfold folded header lines.
1364 Valid values are nil, t, `head', `first', `last', an integer or a
1365 predicate. See Info node `(gnus)Customizing Articles'."
1366 :version "22.1"
1367 :group 'gnus-article-treat
1368 :link '(custom-manual "(gnus)Customizing Articles")
1369 :type gnus-article-treat-custom)
1371 (defcustom gnus-article-unfold-long-headers nil
1372 "If non-nil, allow unfolding headers even if the header is long.
1373 If it is a regexp, only long headers matching this regexp are unfolded.
1374 If it is t, all long headers are unfolded.
1376 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1377 :version "23.1" ;; No Gnus
1378 :group 'gnus-article-treat
1379 :type '(choice (const nil)
1380 (const :tag "all" t)
1381 (regexp)))
1383 (defcustom gnus-treat-fold-headers nil
1384 "Fold headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles'."
1387 :version "22.1"
1388 :group 'gnus-article-treat
1389 :link '(custom-manual "(gnus)Customizing Articles")
1390 :type gnus-article-treat-custom)
1392 (defcustom gnus-treat-fold-newsgroups 'head
1393 "Fold the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :version "22.1"
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1401 (defcustom gnus-treat-overstrike t
1402 "Treat overstrike highlighting.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate. See Info node `(gnus)Customizing Articles'."
1405 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :type gnus-article-treat-custom)
1408 (put 'gnus-treat-overstrike 'highlight t)
1410 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1411 "Treat ANSI SGR control sequences.
1412 Valid values are nil, t, `head', `first', `last', an integer or a
1413 predicate. See Info node `(gnus)Customizing Articles'."
1414 :group 'gnus-article-treat
1415 :link '(custom-manual "(gnus)Customizing Articles")
1416 :type gnus-article-treat-custom)
1418 (make-obsolete-variable 'gnus-treat-display-xface
1419 'gnus-treat-display-x-face "Emacs 22.1")
1421 (defcustom gnus-treat-display-x-face
1422 (and (not noninteractive)
1423 (gnus-image-type-available-p 'xbm)
1424 (if (featurep 'xemacs)
1425 (featurep 'xface)
1426 (condition-case nil
1427 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1428 (executable-find "icontopbm"))
1429 ;; shell-command-to-string may signal an error, e.g. if
1430 ;; shell-file-name is not found.
1431 (error nil)))
1432 'head)
1433 "Display X-Face headers.
1434 Valid values are nil and `head'.
1435 See Info node `(gnus)Customizing Articles' and Info node
1436 `(gnus)X-Face' for details."
1437 :group 'gnus-article-treat
1438 :version "21.1"
1439 :link '(custom-manual "(gnus)Customizing Articles")
1440 :link '(custom-manual "(gnus)X-Face")
1441 :type gnus-article-treat-head-custom
1442 :set (lambda (symbol value)
1443 (set-default
1444 symbol
1445 (cond ((or (boundp symbol) (get symbol 'saved-value))
1446 value)
1447 ((boundp 'gnus-treat-display-xface)
1448 (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450 use gnus-treat-display-x-face instead")
1451 (default-value 'gnus-treat-display-xface))
1452 ((get 'gnus-treat-display-xface 'saved-value)
1453 (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455 use gnus-treat-display-x-face instead")
1456 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1458 value)))))
1459 (put 'gnus-treat-display-x-face 'highlight t)
1461 (defcustom gnus-treat-display-face
1462 (and (not noninteractive)
1463 (gnus-image-type-available-p 'png)
1464 'head)
1465 "Display Face headers.
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate. See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Face' for details."
1469 :group 'gnus-article-treat
1470 :version "22.1"
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :link '(custom-manual "(gnus)X-Face")
1473 :type gnus-article-treat-head-custom)
1474 (put 'gnus-treat-display-face 'highlight t)
1476 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477 "Display smileys.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Smileys' for details."
1481 :group 'gnus-article-treat
1482 :version "21.1"
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Smileys")
1485 :type gnus-article-treat-custom)
1486 (put 'gnus-treat-display-smileys 'highlight t)
1488 (defcustom gnus-treat-from-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in the From header.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-from-picon 'highlight t)
1504 (defcustom gnus-treat-mail-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in To and Cc headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-mail-picon 'highlight t)
1520 (defcustom gnus-treat-newsgroups-picon
1521 (if (and (gnus-image-type-available-p 'xpm)
1522 (gnus-picons-installed-p))
1523 'head nil)
1524 "Display picons in the Newsgroups and Followup-To headers.
1525 Valid values are nil, t, `head', `first', `last', an integer or a
1526 predicate. See Info node `(gnus)Customizing Articles' and Info
1527 node `(gnus)Picons' for details."
1528 :version "22.1"
1529 :group 'gnus-article-treat
1530 :group 'gnus-picon
1531 :link '(custom-manual "(gnus)Customizing Articles")
1532 :link '(custom-manual "(gnus)Picons")
1533 :type gnus-article-treat-head-custom)
1534 (put 'gnus-treat-newsgroups-picon 'highlight t)
1536 (defcustom gnus-treat-from-gravatar nil
1537 "Display gravatars in the From header.
1538 Valid values are nil, t, `head', `first', `last', an integer or a
1539 predicate. See Info node `(gnus)Customizing Articles' and Info
1540 node `(gnus)Gravatars' for details."
1541 :version "24.1"
1542 :group 'gnus-article-treat
1543 :group 'gnus-gravatar
1544 :link '(custom-manual "(gnus)Customizing Articles")
1545 :link '(custom-manual "(gnus)Gravatars")
1546 :type gnus-article-treat-head-custom)
1547 (put 'gnus-treat-from-gravatar 'highlight t)
1549 (defcustom gnus-treat-mail-gravatar nil
1550 "Display gravatars in To and Cc headers.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate. See Info node `(gnus)Customizing Articles' and Info
1553 node `(gnus)Gravatars' for details."
1554 :version "24.1"
1555 :group 'gnus-article-treat
1556 :group 'gnus-gravatar
1557 :link '(custom-manual "(gnus)Customizing Articles")
1558 :link '(custom-manual "(gnus)Gravatars")
1559 :type gnus-article-treat-head-custom)
1560 (put 'gnus-treat-mail-gravatar 'highlight t)
1562 (defcustom gnus-treat-body-boundary
1563 (if (or gnus-treat-newsgroups-picon
1564 gnus-treat-mail-picon
1565 gnus-treat-from-picon
1566 gnus-treat-from-gravatar
1567 gnus-treat-mail-gravatar)
1568 ;; If there's much decoration, the user might prefer a boundary.
1569 'head
1570 nil)
1571 "Draw a boundary at the end of the headers.
1572 Valid values are nil and `head'.
1573 See Info node `(gnus)Customizing Articles' for details."
1574 :version "22.1"
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-head-custom)
1579 (defcustom gnus-treat-capitalize-sentences nil
1580 "Capitalize sentence-starting words.
1581 Valid values are nil, t, `head', `first', `last', an integer or a
1582 predicate. See Info node `(gnus)Customizing Articles'."
1583 :version "21.1"
1584 :group 'gnus-article-treat
1585 :link '(custom-manual "(gnus)Customizing Articles")
1586 :type gnus-article-treat-custom)
1588 (defcustom gnus-treat-wash-html nil
1589 "Format as HTML.
1590 Valid values are nil, t, `head', `first', `last', an integer or a
1591 predicate. See Info node `(gnus)Customizing Articles'."
1592 :version "22.1"
1593 :group 'gnus-article-treat
1594 :link '(custom-manual "(gnus)Customizing Articles")
1595 :type gnus-article-treat-custom)
1597 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598 "Fill long lines.
1599 Valid values are nil, t, `head', `first', `last', an integer or a
1600 predicate. See Info node `(gnus)Customizing Articles'."
1601 :version "24.1"
1602 :group 'gnus-article-treat
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1606 (defcustom gnus-treat-x-pgp-sig nil
1607 "Verify X-PGP-Sig.
1608 To automatically treat X-PGP-Sig, set it to head.
1609 Valid values are nil, t, `head', `first', `last', an integer or a
1610 predicate. See Info node `(gnus)Customizing Articles'."
1611 :version "22.1"
1612 :group 'gnus-article-treat
1613 :group 'mime-security
1614 :link '(custom-manual "(gnus)Customizing Articles")
1615 :type gnus-article-treat-custom)
1617 (defvar gnus-article-encrypt-protocol-alist
1618 '(("PGP" . mml2015-self-encrypt)))
1620 ;; Set to nil if more than one protocol added to
1621 ;; gnus-article-encrypt-protocol-alist.
1622 (defcustom gnus-article-encrypt-protocol "PGP"
1623 "The protocol used for encrypt articles.
1624 It is a string, such as \"PGP\". If nil, ask user."
1625 :version "22.1"
1626 :type 'string
1627 :group 'mime-security)
1629 (defvar idna-program)
1631 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1632 (mm-coding-system-p 'utf-8)
1633 idna-program
1634 (executable-find idna-program))
1635 "Whether IDNA decoding of headers is used when viewing messages.
1636 This requires GNU Libidn, and by default only enabled if it is found."
1637 :version "22.1"
1638 :group 'gnus-article-headers
1639 :type 'boolean)
1641 (defcustom gnus-article-over-scroll nil
1642 "If non-nil, allow scrolling the article buffer even when there no more text."
1643 :version "22.1"
1644 :group 'gnus-article
1645 :type 'boolean)
1647 (defcustom gnus-inhibit-images nil
1648 "Non-nil means inhibit displaying of images inline in the article body."
1649 :version "24.1"
1650 :group 'gnus-article
1651 :type 'boolean)
1653 (defcustom gnus-blocked-images 'gnus-block-private-groups
1654 "Images that have URLs matching this regexp will be blocked.
1655 This can also be a function to be evaluated. If so, it will be
1656 called with the group name as the parameter, and should return a
1657 regexp."
1658 :version "24.1"
1659 :group 'gnus-art
1660 :type '(choice regexp function))
1662 ;;; Internal variables
1664 (defvar gnus-english-month-names
1665 '("January" "February" "March" "April" "May" "June" "July" "August"
1666 "September" "October" "November" "December"))
1668 (defvar article-goto-body-goes-to-point-min-p nil)
1669 (defvar gnus-article-wash-types nil)
1670 (defvar gnus-article-emphasis-alist nil)
1671 (defvar gnus-article-image-alist nil)
1673 (defvar gnus-article-mime-handle-alist-1 nil)
1674 (defvar gnus-treatment-function-alist
1675 '((gnus-treat-strip-cr gnus-article-remove-cr)
1676 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1677 (gnus-treat-strip-banner gnus-article-strip-banner)
1678 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1679 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1680 (gnus-treat-buttonize gnus-article-add-buttons)
1681 (gnus-treat-fill-article gnus-article-fill-cited-article)
1682 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1683 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1684 (gnus-treat-display-x-face gnus-article-display-x-face)
1685 (gnus-treat-display-face gnus-article-display-face)
1686 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1687 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1688 (gnus-treat-hide-signature gnus-article-hide-signature)
1689 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1690 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1691 (gnus-treat-from-picon gnus-treat-from-picon)
1692 (gnus-treat-mail-picon gnus-treat-mail-picon)
1693 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1694 (gnus-treat-strip-pem gnus-article-hide-pem)
1695 (gnus-treat-date gnus-article-treat-date)
1696 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1697 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1698 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1699 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1700 (gnus-treat-strip-trailing-blank-lines
1701 gnus-article-remove-trailing-blank-lines)
1702 (gnus-treat-strip-leading-blank-lines
1703 gnus-article-strip-leading-blank-lines)
1704 (gnus-treat-strip-multiple-blank-lines
1705 gnus-article-strip-multiple-blank-lines)
1706 (gnus-treat-overstrike gnus-article-treat-overstrike)
1707 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1708 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1709 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1710 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1711 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1712 (gnus-treat-display-smileys gnus-treat-smiley)
1713 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1714 (gnus-treat-wash-html gnus-article-wash-html)
1715 (gnus-treat-emphasize gnus-article-emphasize)
1716 (gnus-treat-hide-citation gnus-article-hide-citation)
1717 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1718 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1719 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1721 (defvar gnus-article-mime-handle-alist nil)
1722 (defvar article-lapsed-timer nil)
1723 (defvar gnus-article-current-summary nil)
1725 (defvar gnus-article-mode-syntax-table
1726 (let ((table (copy-syntax-table text-mode-syntax-table)))
1727 ;; This causes the citation match run O(2^n).
1728 ;; (modify-syntax-entry ?- "w" table)
1729 (modify-syntax-entry ?> ")<" table)
1730 (modify-syntax-entry ?< "(>" table)
1731 ;; make M-. in article buffers work for `foo' strings
1732 (modify-syntax-entry ?' " " table)
1733 (modify-syntax-entry ?` " " table)
1734 table)
1735 "Syntax table used in article mode buffers.
1736 Initialized from `text-mode-syntax-table.")
1738 (defvar gnus-save-article-buffer nil)
1740 (defvar gnus-number-of-articles-to-be-saved nil)
1742 (defvar gnus-inhibit-hiding nil)
1744 (defvar gnus-article-edit-mode nil)
1746 ;;; Macros for dealing with the article buffer.
1748 (defmacro gnus-with-article-headers (&rest forms)
1749 `(with-current-buffer gnus-article-buffer
1750 (save-restriction
1751 (let ((inhibit-read-only t)
1752 (inhibit-point-motion-hooks t)
1753 (case-fold-search t))
1754 (article-narrow-to-head)
1755 ,@forms))))
1757 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1758 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1760 (defmacro gnus-with-article-buffer (&rest forms)
1761 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1762 (with-current-buffer gnus-article-buffer
1763 (let ((inhibit-read-only t))
1764 ,@forms))))
1766 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1767 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1769 (defun gnus-article-goto-header (header)
1770 "Go to HEADER, which is a regular expression."
1771 (re-search-forward (concat "^\\(" header "\\):") nil t))
1773 (defsubst gnus-article-hide-text (b e props)
1774 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1775 (gnus-add-text-properties-when 'article-type nil b e props)
1776 (when (memq 'intangible props)
1777 (put-text-property
1778 (max (1- b) (point-min))
1779 b 'intangible (cddr (memq 'intangible props)))))
1781 (defsubst gnus-article-unhide-text (b e)
1782 "Remove hidden text properties from region between B and E."
1783 (remove-text-properties b e gnus-hidden-properties)
1784 (when (memq 'intangible gnus-hidden-properties)
1785 (put-text-property (max (1- b) (point-min))
1786 b 'intangible nil)))
1788 (defun gnus-article-hide-text-type (b e type)
1789 "Hide text of TYPE between B and E."
1790 (gnus-add-wash-type type)
1791 (gnus-article-hide-text
1792 b e (cons 'article-type (cons type gnus-hidden-properties))))
1794 (defun gnus-article-unhide-text-type (b e type)
1795 "Unhide text of TYPE between B and E."
1796 (gnus-delete-wash-type type)
1797 (remove-text-properties
1798 b e (cons 'article-type (cons type gnus-hidden-properties)))
1799 (when (memq 'intangible gnus-hidden-properties)
1800 (put-text-property (max (1- b) (point-min))
1801 b 'intangible nil)))
1803 (defun gnus-article-delete-text-of-type (type)
1804 "Delete text of TYPE in the current buffer."
1805 (save-excursion
1806 (let ((b (point-min)))
1807 (if (eq type 'multipart)
1808 ;; Remove MIME buttons associated with multipart/alternative parts.
1809 (progn
1810 (goto-char b)
1811 (while (if (get-text-property (point) 'gnus-part)
1812 (setq b (point))
1813 (when (setq b (next-single-property-change (point)
1814 'gnus-part))
1815 (goto-char b)
1817 (end-of-line)
1818 (skip-chars-forward "\n")
1819 (when (eq (get-text-property b 'article-type) 'multipart)
1820 (delete-region b (point)))))
1821 (while (setq b (text-property-any b (point-max) 'article-type type))
1822 (delete-region
1823 b (or (text-property-not-all b (point-max) 'article-type type)
1824 (point-max))))))))
1826 (defun gnus-article-delete-invisible-text ()
1827 "Delete all invisible text in the current buffer."
1828 (save-excursion
1829 (let ((b (point-min)))
1830 (while (setq b (text-property-any b (point-max) 'invisible t))
1831 (delete-region
1832 b (or (text-property-not-all b (point-max) 'invisible t)
1833 (point-max)))))))
1835 (defsubst gnus-article-header-rank ()
1836 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1837 (let ((list gnus-sorted-header-list)
1838 (i 1))
1839 (while list
1840 (if (looking-at (car list))
1841 (setq list nil)
1842 (setq list (cdr list))
1843 (incf i)))
1846 (defun article-hide-headers (&optional _arg _delete)
1847 "Hide unwanted headers and possibly sort them as well."
1848 (interactive)
1849 ;; This function might be inhibited.
1850 (unless gnus-inhibit-hiding
1851 (let ((inhibit-read-only t)
1852 (case-fold-search t)
1853 (max (1+ (length gnus-sorted-header-list)))
1854 (inhibit-point-motion-hooks t)
1855 (cur (current-buffer))
1856 ignored visible beg)
1857 (save-excursion
1858 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1859 ;; group parameters, so we should go to the summary buffer.
1860 (when (prog1
1861 (condition-case nil
1862 (progn (set-buffer gnus-summary-buffer) t)
1863 (error nil))
1864 (setq ignored (when (not gnus-visible-headers)
1865 (cond ((stringp gnus-ignored-headers)
1866 gnus-ignored-headers)
1867 ((listp gnus-ignored-headers)
1868 (mapconcat 'identity
1869 gnus-ignored-headers
1870 "\\|"))))
1871 visible (cond ((stringp gnus-visible-headers)
1872 gnus-visible-headers)
1873 ((and gnus-visible-headers
1874 (listp gnus-visible-headers))
1875 (mapconcat 'identity
1876 gnus-visible-headers
1877 "\\|")))))
1878 (set-buffer cur))
1879 (save-restriction
1880 ;; First we narrow to just the headers.
1881 (article-narrow-to-head)
1882 ;; Hide any "From " lines at the beginning of (mail) articles.
1883 (while (looking-at "From ")
1884 (forward-line 1))
1885 (unless (bobp)
1886 (delete-region (point-min) (point)))
1887 ;; Then treat the rest of the header lines.
1888 ;; Then we use the two regular expressions
1889 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1890 ;; select which header lines is to remain visible in the
1891 ;; article buffer.
1892 (while (re-search-forward "^[^ \t:]*:" nil t)
1893 (beginning-of-line)
1894 ;; Mark the rank of the header.
1895 (put-text-property
1896 (point) (1+ (point)) 'message-rank
1897 (if (or (and visible (looking-at visible))
1898 (and ignored
1899 (not (looking-at ignored))))
1900 (gnus-article-header-rank)
1901 (+ 2 max)))
1902 (forward-line 1))
1903 (message-sort-headers-1)
1904 (when (setq beg (text-property-any
1905 (point-min) (point-max) 'message-rank (+ 2 max)))
1906 ;; We delete the unwanted headers.
1907 (gnus-add-wash-type 'headers)
1908 (add-text-properties (point-min) (+ 5 (point-min))
1909 '(article-type headers dummy-invisible t))
1910 (delete-region beg (point-max))))))))
1912 (defun article-hide-boring-headers (&optional arg)
1913 "Toggle hiding of headers that aren't very interesting.
1914 If given a negative prefix, always show; if given a positive prefix,
1915 always hide."
1916 (interactive (gnus-article-hidden-arg))
1917 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1918 (not gnus-show-all-headers))
1919 (save-excursion
1920 (save-restriction
1921 (let ((inhibit-read-only t)
1922 (inhibit-point-motion-hooks t))
1923 (article-narrow-to-head)
1924 (dolist (elem gnus-boring-article-headers)
1925 (goto-char (point-min))
1926 (cond
1927 ;; Hide empty headers.
1928 ((eq elem 'empty)
1929 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1930 (forward-line -1)
1931 (gnus-article-hide-text-type
1932 (point-at-bol)
1933 (progn
1934 (end-of-line)
1935 (if (re-search-forward "^[^ \t]" nil t)
1936 (match-beginning 0)
1937 (point-max)))
1938 'boring-headers)))
1939 ;; Hide boring Newsgroups header.
1940 ((eq elem 'newsgroups)
1941 (when (gnus-string-equal
1942 (gnus-fetch-field "newsgroups")
1943 (gnus-group-real-name
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name
1946 "")))
1947 (gnus-article-hide-header "newsgroups")))
1948 ((eq elem 'to-address)
1949 (let ((to (message-fetch-field "to"))
1950 (to-address
1951 (gnus-parameter-to-address
1952 (if (boundp 'gnus-newsgroup-name)
1953 gnus-newsgroup-name ""))))
1954 (when (and to to-address
1955 (ignore-errors
1956 (gnus-string-equal
1957 ;; only one address in To
1958 (nth 1 (mail-extract-address-components to))
1959 to-address)))
1960 (gnus-article-hide-header "to"))))
1961 ((eq elem 'to-list)
1962 (let ((to (message-fetch-field "to"))
1963 (to-list
1964 (gnus-parameter-to-list
1965 (if (boundp 'gnus-newsgroup-name)
1966 gnus-newsgroup-name ""))))
1967 (when (and to to-list
1968 (ignore-errors
1969 (gnus-string-equal
1970 ;; only one address in To
1971 (nth 1 (mail-extract-address-components to))
1972 to-list)))
1973 (gnus-article-hide-header "to"))))
1974 ((eq elem 'cc-list)
1975 (let ((cc (message-fetch-field "cc"))
1976 (to-list
1977 (gnus-parameter-to-list
1978 (if (boundp 'gnus-newsgroup-name)
1979 gnus-newsgroup-name ""))))
1980 (when (and cc to-list
1981 (ignore-errors
1982 (gnus-string-equal
1983 ;; only one address in CC
1984 (nth 1 (mail-extract-address-components cc))
1985 to-list)))
1986 (gnus-article-hide-header "cc"))))
1987 ((eq elem 'followup-to)
1988 (when (gnus-string-equal
1989 (message-fetch-field "followup-to")
1990 (message-fetch-field "newsgroups"))
1991 (gnus-article-hide-header "followup-to")))
1992 ((eq elem 'reply-to)
1993 (if (gnus-group-find-parameter
1994 gnus-newsgroup-name 'broken-reply-to)
1995 (gnus-article-hide-header "reply-to")
1996 (let ((from (message-fetch-field "from"))
1997 (reply-to (message-fetch-field "reply-to")))
1998 (when
1999 (and
2000 from reply-to
2001 (ignore-errors
2002 (equal
2003 (sort (mapcar
2004 (lambda (x) (downcase (cadr x)))
2005 (mail-extract-address-components from t))
2006 'string<)
2007 (sort (mapcar
2008 (lambda (x) (downcase (cadr x)))
2009 (mail-extract-address-components reply-to t))
2010 'string<))))
2011 (gnus-article-hide-header "reply-to")))))
2012 ((eq elem 'date)
2013 (let ((date (with-current-buffer gnus-original-article-buffer
2014 ;; If date in `gnus-article-buffer' is localized
2015 ;; (`gnus-treat-date-user-defined'),
2016 ;; `days-between' might fail.
2017 (message-fetch-field "date"))))
2018 (when (and date
2019 (< (days-between (current-time-string) date)
2021 (gnus-article-hide-header "date"))))
2022 ((eq elem 'long-to)
2023 (let ((to (message-fetch-field "to"))
2024 (cc (message-fetch-field "cc")))
2025 (when (> (length to) 1024)
2026 (gnus-article-hide-header "to"))
2027 (when (> (length cc) 1024)
2028 (gnus-article-hide-header "cc"))))
2029 ((eq elem 'many-to)
2030 (let ((to-count 0)
2031 (cc-count 0))
2032 (goto-char (point-min))
2033 (while (re-search-forward "^to:" nil t)
2034 (setq to-count (1+ to-count)))
2035 (when (> to-count 1)
2036 (while (> to-count 0)
2037 (goto-char (point-min))
2038 (save-restriction
2039 (re-search-forward "^to:" nil nil to-count)
2040 (forward-line -1)
2041 (narrow-to-region (point) (point-max))
2042 (gnus-article-hide-header "to"))
2043 (setq to-count (1- to-count))))
2044 (goto-char (point-min))
2045 (while (re-search-forward "^cc:" nil t)
2046 (setq cc-count (1+ cc-count)))
2047 (when (> cc-count 1)
2048 (while (> cc-count 0)
2049 (goto-char (point-min))
2050 (save-restriction
2051 (re-search-forward "^cc:" nil nil cc-count)
2052 (forward-line -1)
2053 (narrow-to-region (point) (point-max))
2054 (gnus-article-hide-header "cc"))
2055 (setq cc-count (1- cc-count)))))))))))))
2057 (defun gnus-article-hide-header (header)
2058 (save-excursion
2059 (goto-char (point-min))
2060 (when (re-search-forward (concat "^" header ":") nil t)
2061 (gnus-article-hide-text-type
2062 (point-at-bol)
2063 (progn
2064 (end-of-line)
2065 (if (re-search-forward "^[^ \t]" nil t)
2066 (match-beginning 0)
2067 (point-max)))
2068 'boring-headers))))
2070 (defvar gnus-article-normalized-header-length 40
2071 "Length of normalized headers.")
2073 (defun article-normalize-headers ()
2074 "Make all header lines 40 characters long."
2075 (interactive)
2076 (let ((inhibit-read-only t)
2077 column)
2078 (save-excursion
2079 (save-restriction
2080 (article-narrow-to-head)
2081 (while (not (eobp))
2082 (cond
2083 ((< (setq column (- (point-at-eol) (point)))
2084 gnus-article-normalized-header-length)
2085 (end-of-line)
2086 (insert (make-string
2087 (- gnus-article-normalized-header-length column)
2088 ? )))
2089 ((> column gnus-article-normalized-header-length)
2090 (gnus-put-text-property
2091 (progn
2092 (forward-char gnus-article-normalized-header-length)
2093 (point))
2094 (point-at-eol)
2095 'invisible t))
2097 ;; Do nothing.
2099 (forward-line 1))))))
2101 (defun article-treat-dumbquotes ()
2102 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2103 Note that this function guesses whether a character is a sm*rtq**t* or
2104 not, so it should only be used interactively.
2106 Sm*rtq**t*s are M****s***'s unilateral extension to the
2107 iso-8859-1 character map in an attempt to provide more quoting
2108 characters. If you see something like \\222 or \\264 where
2109 you're expecting some kind of apostrophe or quotation mark, then
2110 try this wash."
2111 (interactive)
2112 (article-translate-strings gnus-article-dumbquotes-map))
2114 (defvar org-entities)
2116 (defun article-treat-non-ascii ()
2117 "Translate many Unicode characters into their ASCII equivalents."
2118 (interactive)
2119 (require 'org-entities)
2120 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2121 (dolist (elem org-entities)
2122 (when (and (listp elem)
2123 (= (length (nth 6 elem)) 1))
2124 (if (featurep 'xemacs)
2125 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2126 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2127 (save-excursion
2128 (when (article-goto-body)
2129 (let ((inhibit-read-only t)
2130 replace props)
2131 (while (not (eobp))
2132 (if (not (setq replace (if (featurep 'xemacs)
2133 (get-char-table (following-char) table)
2134 (aref table (following-char)))))
2135 (forward-char 1)
2136 (if (prog1
2137 (setq props (text-properties-at (point)))
2138 (delete-char 1))
2139 (add-text-properties (point) (progn (insert replace) (point))
2140 props)
2141 (insert replace)))))))))
2143 (defun article-translate-strings (map)
2144 "Translate all string in the body of the article according to MAP.
2145 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2146 (save-excursion
2147 (when (article-goto-body)
2148 (let ((inhibit-read-only t))
2149 (dolist (elem map)
2150 (let ((from (car elem))
2151 (to (cadr elem)))
2152 (save-excursion
2153 (if (stringp from)
2154 (while (search-forward from nil t)
2155 (replace-match to))
2156 (while (not (eobp))
2157 (if (eq (following-char) from)
2158 (progn
2159 (delete-char 1)
2160 (insert to))
2161 (forward-char 1)))))))))))
2163 (defun article-treat-overstrike ()
2164 "Translate overstrikes into bold text."
2165 (interactive)
2166 (save-excursion
2167 (when (article-goto-body)
2168 (let ((inhibit-read-only t))
2169 (while (search-forward "\b" nil t)
2170 (let ((next (char-after))
2171 (previous (char-after (- (point) 2))))
2172 ;; We do the boldification/underlining by hiding the
2173 ;; overstrikes and putting the proper text property
2174 ;; on the letters.
2175 (cond
2176 ((eq next previous)
2177 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2178 (put-text-property (point) (1+ (point)) 'face 'bold))
2179 ((eq next ?_)
2180 (gnus-article-hide-text-type
2181 (1- (point)) (1+ (point)) 'overstrike)
2182 (put-text-property
2183 (- (point) 2) (1- (point)) 'face 'underline))
2184 ((eq previous ?_)
2185 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2186 (put-text-property
2187 (point) (1+ (point)) 'face 'underline)))))))))
2189 (defun article-treat-ansi-sequences ()
2190 "Translate ANSI SGR control sequences into overlays or extents."
2191 (interactive)
2192 (save-excursion
2193 (when (article-goto-body)
2194 (let ((inhibit-read-only t))
2195 (ansi-color-apply-on-region (point) (point-max))))))
2197 (defun gnus-article-treat-unfold-headers ()
2198 "Unfold folded message headers.
2199 Only the headers that fit into the current window width will be
2200 unfolded."
2201 (interactive)
2202 (gnus-with-article-headers
2203 (let (length)
2204 (while (not (eobp))
2205 (save-restriction
2206 (mail-header-narrow-to-field)
2207 (let* ((header (buffer-string))
2208 (unfoldable
2209 (or (equal gnus-article-unfold-long-headers t)
2210 (and (stringp gnus-article-unfold-long-headers)
2211 (string-match gnus-article-unfold-long-headers
2212 header)))))
2213 (with-temp-buffer
2214 (insert header)
2215 (goto-char (point-min))
2216 (while (re-search-forward "\n[\t ]" nil t)
2217 (replace-match " " t t)))
2218 (setq length (- (point-max) (point-min) 1))
2219 (when (or unfoldable
2220 (< length (window-width)))
2221 (while (re-search-forward "\n[\t ]" nil t)
2222 (replace-match " " t t))))
2223 (goto-char (point-max)))))))
2225 (defun gnus-article-treat-fold-headers ()
2226 "Fold message headers."
2227 (interactive)
2228 (gnus-with-article-headers
2229 (while (not (eobp))
2230 (save-restriction
2231 (mail-header-narrow-to-field)
2232 (mail-header-fold-field)
2233 (goto-char (point-max))))))
2235 (defun gnus-treat-smiley ()
2236 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2237 (interactive)
2238 (gnus-with-article-buffer
2239 (if (memq 'smiley gnus-article-wash-types)
2240 (gnus-delete-images 'smiley)
2241 (article-goto-body)
2242 (let ((images (smiley-region (point) (point-max))))
2243 (when images
2244 (gnus-add-wash-type 'smiley)
2245 (dolist (image images)
2246 (gnus-add-image 'smiley image)))))))
2248 (defun gnus-article-remove-images ()
2249 "Remove all images from the article buffer."
2250 (interactive)
2251 (gnus-with-article-buffer
2252 (save-restriction
2253 (widen)
2254 (dolist (elem gnus-article-image-alist)
2255 (gnus-delete-images (car elem))))))
2257 (autoload 'w3m-toggle-inline-images "w3m")
2259 (defun gnus-article-show-images ()
2260 "Show any images that are in the HTML-rendered article buffer.
2261 This only works if the article in question is HTML."
2262 (interactive)
2263 (gnus-with-article-buffer
2264 (save-restriction
2265 (widen)
2266 (if (eq mm-text-html-renderer 'w3m)
2267 (let ((mm-inline-text-html-with-images nil))
2268 (w3m-toggle-inline-images))
2269 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2270 'image-displayer))
2271 (destructuring-bind (start end function) region
2272 (funcall function (get-text-property start 'image-url)
2273 start end)))))))
2275 (defun gnus-article-treat-fold-newsgroups ()
2276 "Unfold folded message headers.
2277 Only the headers that fit into the current window width will be
2278 unfolded."
2279 (interactive)
2280 (gnus-with-article-headers
2281 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2282 (save-restriction
2283 (mail-header-narrow-to-field)
2284 (while (re-search-forward ", *" nil t)
2285 (replace-match ", " t t))
2286 (mail-header-fold-field)
2287 (goto-char (point-max))))))
2289 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2290 "Value of `truncate-lines' in Gnus Article buffer.
2291 Valid values are nil, t, `head', `first', `last', an integer or a
2292 predicate. See Info node `(gnus)Customizing Articles'."
2293 :version "23.1" ;; No Gnus
2294 :group 'gnus-article
2295 ;; :link '(custom-manual "(gnus)Customizing Articles")
2296 :type 'boolean)
2298 (defun gnus-article-toggle-truncate-lines (&optional arg)
2299 "Toggle whether to fold or truncate long lines in article the buffer.
2300 If ARG is non-nil and not a number, toggle
2301 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2302 long lines if and only if arg is positive."
2303 (interactive "P")
2304 (cond
2305 ((and (numberp arg) (> arg 0))
2306 (setq gnus-article-truncate-lines t))
2307 ((numberp arg)
2308 (setq gnus-article-truncate-lines nil))
2309 (arg
2310 (setq gnus-article-truncate-lines
2311 (not gnus-article-truncate-lines))))
2312 (gnus-with-article-buffer
2313 (cond
2314 ((and (numberp arg) (> arg 0))
2315 (setq truncate-lines nil))
2316 ((numberp arg)
2317 (setq truncate-lines t)))
2318 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2319 ;; `toggle-truncate-lines' needs an argument.
2320 (toggle-truncate-lines)))
2322 (defun gnus-article-treat-body-boundary ()
2323 "Place a boundary line at the end of the headers."
2324 (interactive)
2325 (when (and gnus-body-boundary-delimiter
2326 (> (length gnus-body-boundary-delimiter) 0))
2327 (gnus-with-article-headers
2328 (goto-char (point-max))
2329 (let ((start (point)))
2330 (insert "X-Boundary: ")
2331 (gnus-add-text-properties start (point) '(invisible t intangible t))
2332 (insert (let (str (max (window-width)))
2333 (if (featurep 'xemacs)
2334 (setq max (1- max)))
2335 (while (>= max (length str))
2336 (setq str (concat str gnus-body-boundary-delimiter)))
2337 (substring str 0 max))
2338 "\n")
2339 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2341 (defun article-fill-long-lines ()
2342 "Fill lines that are wider than the window width."
2343 (interactive)
2344 (save-excursion
2345 (let ((inhibit-read-only t)
2346 (width (window-width (get-buffer-window (current-buffer)))))
2347 (save-restriction
2348 (article-goto-body)
2349 (let ((adaptive-fill-mode nil)) ;Why? -sm
2350 (while (not (eobp))
2351 (end-of-line)
2352 (when (>= (current-column) (min fill-column width))
2353 (narrow-to-region (min (1+ (point)) (point-max))
2354 (point-at-bol))
2355 (let ((goback (point-marker)))
2356 (fill-paragraph nil)
2357 (goto-char (marker-position goback)))
2358 (widen))
2359 (forward-line 1)))))))
2361 (defun article-capitalize-sentences ()
2362 "Capitalize the first word in each sentence."
2363 (interactive)
2364 (save-excursion
2365 (let ((inhibit-read-only t)
2366 (paragraph-start "^[\n\^L]"))
2367 (article-goto-body)
2368 (while (not (eobp))
2369 (capitalize-word 1)
2370 (forward-sentence)))))
2372 (defun article-remove-cr ()
2373 "Remove trailing CRs and then translate remaining CRs into LFs."
2374 (interactive)
2375 (save-excursion
2376 (let ((inhibit-read-only t))
2377 (goto-char (point-min))
2378 (while (re-search-forward "\r+$" nil t)
2379 (replace-match "" t t))
2380 (goto-char (point-min))
2381 (while (search-forward "\r" nil t)
2382 (replace-match "\n" t t)))))
2384 (defun article-remove-trailing-blank-lines ()
2385 "Remove all trailing blank lines from the article."
2386 (interactive)
2387 (save-excursion
2388 (let ((inhibit-read-only t))
2389 (goto-char (point-max))
2390 (delete-region
2391 (point)
2392 (progn
2393 (while (and (not (bobp))
2394 (looking-at "^[ \t]*$")
2395 (not (gnus-annotation-in-region-p
2396 (point) (point-at-eol))))
2397 (forward-line -1))
2398 (forward-line 1)
2399 (point))))))
2401 (defvar gnus-face-properties-alist)
2403 (defun article-display-face (&optional force)
2404 "Display any Face headers in the header."
2405 (interactive (list 'force))
2406 (let ((wash-face-p buffer-read-only))
2407 (gnus-with-article-headers
2408 ;; When displaying parts, this function can be called several times on
2409 ;; the same article, without any intended toggle semantic (as typing `W
2410 ;; D d' would have). So face deletion must occur only when we come from
2411 ;; an interactive command, that is when the *Article* buffer is
2412 ;; read-only.
2413 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2414 (gnus-delete-images 'face)
2415 (let ((from (message-fetch-field "from"))
2416 faces)
2417 (save-current-buffer
2418 (when (and wash-face-p
2419 (gnus-buffer-live-p gnus-original-article-buffer)
2420 (not (re-search-forward "^Face:[\t ]*" nil t)))
2421 (set-buffer gnus-original-article-buffer))
2422 (save-restriction
2423 (mail-narrow-to-head)
2424 (when (or force
2425 ;; Check whether this face is censored.
2426 (not (and gnus-article-x-face-too-ugly
2427 (or from
2428 (setq from (message-fetch-field "from")))
2429 (string-match gnus-article-x-face-too-ugly
2430 from))))
2431 (while (gnus-article-goto-header "Face")
2432 (push (mail-header-field-value) faces)))))
2433 (when faces
2434 (goto-char (point-min))
2435 (let (png image)
2436 (unless (setq from (gnus-article-goto-header "from"))
2437 (insert "From:")
2438 (setq from (point))
2439 (insert " [no `from' set]\n"))
2440 (while faces
2441 (when (setq png (gnus-convert-face-to-png (pop faces)))
2442 (setq image
2443 (apply 'gnus-create-image png 'png t
2444 (cdr (assq 'png gnus-face-properties-alist))))
2445 (goto-char from)
2446 (when image
2447 (gnus-add-wash-type 'face)
2448 (gnus-add-image 'face image)
2449 (gnus-put-image image nil 'face)))))))))))
2451 (defun article-display-x-face (&optional force)
2452 "Look for an X-Face header and display it if present."
2453 (interactive (list 'force))
2454 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2455 (gnus-with-article-headers
2456 ;; Delete the old process, if any.
2457 (when (process-status "article-x-face")
2458 (delete-process "article-x-face"))
2459 ;; See the comment in `article-display-face'.
2460 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2461 ;; We have already displayed X-Faces, so we remove them
2462 ;; instead.
2463 (gnus-delete-images 'xface)
2464 ;; Display X-Faces.
2465 (let ((from (message-fetch-field "from"))
2466 x-faces)
2467 (save-current-buffer
2468 (when (and wash-face-p
2469 (gnus-buffer-live-p gnus-original-article-buffer)
2470 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2471 ;; If type `W f', use gnus-original-article-buffer,
2472 ;; otherwise use the current buffer because displaying
2473 ;; RFC822 parts calls this function too.
2474 (set-buffer gnus-original-article-buffer))
2475 (save-restriction
2476 (mail-narrow-to-head)
2477 (and gnus-article-x-face-command
2478 (or force
2479 ;; Check whether this face is censored.
2480 (not (and gnus-article-x-face-too-ugly
2481 (or from
2482 (setq from (message-fetch-field "from")))
2483 (string-match gnus-article-x-face-too-ugly
2484 from))))
2485 (while (gnus-article-goto-header "X-Face")
2486 (push (mail-header-field-value) x-faces)))))
2487 (when x-faces
2488 ;; We display the face.
2489 (cond ((functionp gnus-article-x-face-command)
2490 ;; The command is a lisp function, so we call it.
2491 (mapc gnus-article-x-face-command x-faces))
2492 ((stringp gnus-article-x-face-command)
2493 ;; The command is a string, so we interpret the command
2494 ;; as a, well, command, and fork it off.
2495 (let ((process-connection-type nil))
2496 (gnus-set-process-query-on-exit-flag
2497 (start-process
2498 "article-x-face" nil shell-file-name
2499 shell-command-switch gnus-article-x-face-command)
2500 nil)
2501 ;; Sending multiple EOFs to xv doesn't work,
2502 ;; so we only do a single external face.
2503 (with-temp-buffer
2504 (insert (car x-faces))
2505 (process-send-region "article-x-face"
2506 (point-min) (point-max)))
2507 (process-send-eof "article-x-face")))
2509 (error "`%s' set to `%s' is not a function"
2510 gnus-article-x-face-command
2511 'gnus-article-x-face-command)))))))))
2513 (defun article-decode-mime-words ()
2514 "Decode all MIME-encoded words in the article."
2515 (interactive)
2516 (gnus-with-article-buffer
2517 (let ((inhibit-point-motion-hooks t)
2518 (mail-parse-charset gnus-newsgroup-charset)
2519 (mail-parse-ignored-charsets
2520 (with-current-buffer gnus-summary-buffer
2521 gnus-newsgroup-ignored-charsets)))
2522 (mail-decode-encoded-word-region (point-min) (point-max)))))
2524 (defun article-decode-charset (&optional prompt)
2525 "Decode charset-encoded text in the article.
2526 If PROMPT (the prefix), prompt for a coding system to use."
2527 (interactive "P")
2528 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2529 (inhibit-read-only t)
2530 (mail-parse-charset gnus-newsgroup-charset)
2531 (mail-parse-ignored-charsets
2532 (save-excursion (condition-case nil
2533 (set-buffer gnus-summary-buffer)
2534 (error))
2535 gnus-newsgroup-ignored-charsets))
2536 ct cte ctl charset format)
2537 (save-excursion
2538 (save-restriction
2539 (article-narrow-to-head)
2540 (setq ct (message-fetch-field "Content-Type" t)
2541 cte (message-fetch-field "Content-Transfer-Encoding" t)
2542 ctl (and ct (mail-header-parse-content-type ct))
2543 charset (cond
2544 (prompt
2545 (mm-read-coding-system "Charset to decode: "))
2546 (ctl
2547 (mail-content-type-get ctl 'charset)))
2548 format (and ctl (mail-content-type-get ctl 'format)))
2549 (when cte
2550 (setq cte (mail-header-strip cte)))
2551 (if (and ctl (not (string-match "/" (car ctl))))
2552 (setq ctl nil))
2553 (goto-char (point-max)))
2554 (forward-line 1)
2555 (save-restriction
2556 (narrow-to-region (point) (point-max))
2557 (when (and (eq mail-parse-charset 'gnus-decoded)
2558 (eq (mm-body-7-or-8) '8bit))
2559 ;; The text code could have been decoded.
2560 (setq charset mail-parse-charset))
2561 (when (and (or (not ctl)
2562 (equal (car ctl) "text/plain"))
2563 (not format)) ;; article with format will decode later.
2564 (mm-decode-body
2565 charset (and cte (intern (downcase
2566 (gnus-strip-whitespace cte))))
2567 (car ctl)))))))
2569 (defun article-decode-encoded-words ()
2570 "Remove encoded-word encoding from headers."
2571 (let ((inhibit-point-motion-hooks t)
2572 (mail-parse-charset gnus-newsgroup-charset)
2573 (mail-parse-ignored-charsets
2574 (save-excursion (condition-case nil
2575 (set-buffer gnus-summary-buffer)
2576 (error))
2577 gnus-newsgroup-ignored-charsets))
2578 (inhibit-read-only t)
2579 end start)
2580 (goto-char (point-min))
2581 (when (search-forward "\n\n" nil 'move)
2582 (forward-line -1))
2583 (setq end (point))
2584 (while (not (bobp))
2585 (while (progn
2586 (forward-line -1)
2587 (and (not (bobp))
2588 (memq (char-after) '(?\t ? )))))
2589 (setq start (point))
2590 (if (looking-at "\
2591 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2592 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2593 (funcall gnus-decode-address-function start end)
2594 (funcall gnus-decode-header-function start end))
2595 (goto-char (setq end start)))))
2597 (defun article-decode-group-name ()
2598 "Decode group names in Newsgroups, Followup-To and Xref headers."
2599 (let ((inhibit-point-motion-hooks t)
2600 (inhibit-read-only t)
2601 (method (gnus-find-method-for-group gnus-newsgroup-name))
2602 regexp)
2603 (when (and (or gnus-group-name-charset-method-alist
2604 gnus-group-name-charset-group-alist)
2605 (gnus-buffer-live-p gnus-original-article-buffer))
2606 (save-restriction
2607 (article-narrow-to-head)
2608 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2609 (with-current-buffer gnus-original-article-buffer
2610 (goto-char (point-min)))
2611 (setq regexp (concat "^" header
2612 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2613 (while (re-search-forward regexp nil t)
2614 (replace-match (save-match-data
2615 (gnus-decode-newsgroups
2616 ;; XXX how to use data in article buffer?
2617 (with-current-buffer gnus-original-article-buffer
2618 (re-search-forward regexp nil t)
2619 (match-string 1))
2620 gnus-newsgroup-name method))
2621 t t nil 1))
2622 (goto-char (point-min)))))))
2624 (autoload 'idna-to-unicode "idna")
2626 (defun article-decode-idna-rhs ()
2627 "Decode IDNA strings in RHS in various headers in current buffer.
2628 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2629 Mail-Reply-To: and Mail-Followup-To:."
2630 (when gnus-use-idna
2631 (save-restriction
2632 (let ((inhibit-point-motion-hooks t)
2633 (inhibit-read-only t))
2634 (article-narrow-to-head)
2635 (goto-char (point-min))
2636 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2637 (let (ace unicode)
2638 (when (save-match-data
2639 (and (setq ace (match-string 1))
2640 (save-excursion
2641 (and (re-search-backward "^[^ \t]" nil t)
2642 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2643 (setq unicode (idna-to-unicode ace))))
2644 (unless (string= ace unicode)
2645 (replace-match unicode nil nil nil 1)))))))))
2647 (defun article-de-quoted-unreadable (&optional force read-charset)
2648 "Translate a quoted-printable-encoded article.
2649 If FORCE, decode the article whether it is marked as quoted-printable
2650 or not.
2651 If READ-CHARSET, ask for a coding system."
2652 (interactive (list 'force current-prefix-arg))
2653 (save-excursion
2654 (let ((inhibit-read-only t) type charset)
2655 (if (gnus-buffer-live-p gnus-original-article-buffer)
2656 (with-current-buffer gnus-original-article-buffer
2657 (setq type
2658 (gnus-fetch-field "content-transfer-encoding"))
2659 (let* ((ct (gnus-fetch-field "content-type"))
2660 (ctl (and ct (mail-header-parse-content-type ct))))
2661 (setq charset (and ctl
2662 (mail-content-type-get ctl 'charset)))
2663 (if (stringp charset)
2664 (setq charset (intern (downcase charset)))))))
2665 (if read-charset
2666 (setq charset (mm-read-coding-system "Charset: " charset)))
2667 (unless charset
2668 (setq charset gnus-newsgroup-charset))
2669 (when (or force
2670 (and type (let ((case-fold-search t))
2671 (string-match "quoted-printable" type))))
2672 (article-goto-body)
2673 (quoted-printable-decode-region
2674 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2676 (defun article-de-base64-unreadable (&optional force read-charset)
2677 "Translate a base64 article.
2678 If FORCE, decode the article whether it is marked as base64 not.
2679 If READ-CHARSET, ask for a coding system."
2680 (interactive (list 'force current-prefix-arg))
2681 (save-excursion
2682 (let ((inhibit-read-only t) type charset)
2683 (if (gnus-buffer-live-p gnus-original-article-buffer)
2684 (with-current-buffer gnus-original-article-buffer
2685 (setq type
2686 (gnus-fetch-field "content-transfer-encoding"))
2687 (let* ((ct (gnus-fetch-field "content-type"))
2688 (ctl (and ct (mail-header-parse-content-type ct))))
2689 (setq charset (and ctl
2690 (mail-content-type-get ctl 'charset)))
2691 (if (stringp charset)
2692 (setq charset (intern (downcase charset)))))))
2693 (if read-charset
2694 (setq charset (mm-read-coding-system "Charset: " charset)))
2695 (unless charset
2696 (setq charset gnus-newsgroup-charset))
2697 (when (or force
2698 (and type (let ((case-fold-search t))
2699 (string-match "base64" type))))
2700 (article-goto-body)
2701 (save-restriction
2702 (narrow-to-region (point) (point-max))
2703 (base64-decode-region (point-min) (point-max))
2704 (mm-decode-coding-region
2705 (point-min) (point-max)
2706 (mm-charset-to-coding-system charset nil t)))))))
2708 (eval-when-compile
2709 (require 'rfc1843))
2711 (defun article-decode-HZ ()
2712 "Translate a HZ-encoded article."
2713 (interactive)
2714 (require 'rfc1843)
2715 (save-excursion
2716 (let ((inhibit-read-only t))
2717 (rfc1843-decode-region (point-min) (point-max)))))
2719 (defun article-unsplit-urls ()
2720 "Remove the newlines that some other mailers insert into URLs."
2721 (interactive)
2722 (save-excursion
2723 (let ((inhibit-read-only t))
2724 (goto-char (point-min))
2725 (while (re-search-forward
2726 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2727 (replace-match "\\1\\3" t)))
2728 (when (gmm-called-interactively-p 'any)
2729 (gnus-treat-article nil))))
2731 (defun article-wash-html ()
2732 "Format an HTML article."
2733 (interactive)
2734 (let ((handles nil)
2735 (buffer-read-only nil))
2736 (when (gnus-buffer-live-p gnus-original-article-buffer)
2737 (with-current-buffer gnus-original-article-buffer
2738 (setq handles (mm-dissect-buffer t t))))
2739 (article-goto-body)
2740 (delete-region (point) (point-max))
2741 (mm-enable-multibyte)
2742 (mm-inline-text-html handles)))
2744 (defvar gnus-article-browse-html-temp-list nil
2745 "List of temporary files created by `gnus-article-browse-html-parts'.
2746 Internal variable.")
2748 (defcustom gnus-article-browse-delete-temp 'ask
2749 "What to do with temporary files from `gnus-article-browse-html-parts'.
2750 If nil, don't delete temporary files. If it is t, delete them on
2751 exit from the summary buffer. If it is the symbol `file', query
2752 on each file, if it is `ask' ask once when exiting from the
2753 summary buffer."
2754 :group 'gnus-article
2755 :version "23.1" ;; No Gnus
2756 :type '(choice (const :tag "Don't delete" nil)
2757 (const :tag "Don't ask" t)
2758 (const :tag "Ask" ask)
2759 (const :tag "Ask for each file" file)))
2761 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2763 (defun gnus-article-browse-delete-temp-files (&optional how)
2764 "Delete temp-files created by `gnus-article-browse-html-parts'."
2765 (when (and gnus-article-browse-html-temp-list
2766 (progn
2767 (or how (setq how gnus-article-browse-delete-temp))
2768 (if (eq how 'ask)
2769 (let ((files (length gnus-article-browse-html-temp-list)))
2770 (or (gnus-y-or-n-p
2771 (if (= files 1)
2772 "Delete the temporary HTML file? "
2773 (format "Delete all %s temporary HTML files? "
2774 files)))
2775 (setq gnus-article-browse-html-temp-list nil)))
2776 how)))
2777 (dolist (file gnus-article-browse-html-temp-list)
2778 (cond ((file-directory-p file)
2779 (when (or (not (eq how 'file))
2780 (gnus-y-or-n-p
2781 (format
2782 "Delete temporary HTML file(s) in directory `%s'? "
2783 (file-name-as-directory file))))
2784 (gnus-delete-directory file)))
2785 ((file-exists-p file)
2786 (when (or (not (eq how 'file))
2787 (gnus-y-or-n-p
2788 (format "Delete temporary HTML file `%s'? " file)))
2789 (delete-file file)))))
2790 ;; Also remove file from the list when not deleted or if file doesn't
2791 ;; exist anymore.
2792 (setq gnus-article-browse-html-temp-list nil))
2793 gnus-article-browse-html-temp-list)
2795 (defun gnus-article-browse-html-save-cid-content (cid handles directory abs)
2796 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2797 Return absolute file name if ABS is non-nil, otherwise relative to
2798 the parent of DIRECTORY."
2799 (save-match-data
2800 (let (file afile)
2801 (catch 'found
2802 (dolist (handle handles)
2803 (cond
2804 ((not (listp handle)))
2805 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2806 ;; may create.
2807 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2808 ((equal (mm-handle-media-supertype handle) "multipart")
2809 (when (setq file (gnus-article-browse-html-save-cid-content
2810 cid handle directory abs))
2811 (throw 'found file)))
2812 ((equal (concat "<" cid ">") (mm-handle-id handle))
2813 (setq file (or (mm-handle-filename handle)
2814 (concat
2815 (make-temp-name "cid")
2816 (car (rassoc (car (mm-handle-type handle))
2817 mailcap-mime-extensions))))
2818 afile (expand-file-name file directory))
2819 (mm-save-part-to-file handle afile)
2820 (throw 'found (if abs
2821 afile
2822 (concat (file-name-nondirectory
2823 (directory-file-name directory))
2824 "/" file))))))))))
2826 (defun gnus-article-browse-html-parts (list &optional header)
2827 "View all \"text/html\" parts from LIST.
2828 Recurse into multiparts. The optional HEADER that should be a decoded
2829 message header will be added to the bodies of the \"text/html\" parts."
2830 ;; Internal function used by `gnus-article-browse-html-article'.
2831 (let (type file charset content cid-dir tmp-file showed)
2832 ;; Find and show the html-parts.
2833 (dolist (handle list)
2834 ;; If HTML, show it:
2835 (cond ((not (listp handle)))
2836 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2837 (and (equal (car type) "message/external-body")
2838 (or header
2839 (setq file (mm-handle-filename handle)))
2840 (or (mm-handle-cache handle)
2841 (condition-case code
2842 (progn (mm-extern-cache-contents handle) t)
2843 (error
2844 (gnus-message 3 "%s" (error-message-string code))
2845 (when (>= gnus-verbose 3) (sit-for 2))
2846 nil)))
2847 (progn
2848 (setq handle (mm-handle-cache handle)
2849 type (mm-handle-type handle))
2850 (equal (car type) "text/html"))))
2851 (setq charset (mail-content-type-get type 'charset)
2852 content (mm-get-part handle))
2853 (with-temp-buffer
2854 (if (eq charset 'gnus-decoded)
2855 (mm-enable-multibyte)
2856 (mm-disable-multibyte))
2857 (insert content)
2858 ;; resolve cid contents
2859 (let ((case-fold-search t)
2860 abs st cid-file)
2861 (goto-char (point-min))
2862 (when (re-search-forward "<head[\t\n >]" nil t)
2863 (setq st (match-end 0)
2864 abs (or
2865 (not (re-search-forward "</head[\t\n >]" nil t))
2866 (re-search-backward "<base[\t\n >]" st t))))
2867 (while (re-search-forward "\
2868 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2869 nil t)
2870 (unless cid-dir
2871 (setq cid-dir (mm-make-temp-file "cid" t))
2872 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2873 (setq file nil
2874 content nil)
2875 (when (setq cid-file
2876 (gnus-article-browse-html-save-cid-content
2877 (match-string 2)
2878 (with-current-buffer gnus-article-buffer
2879 gnus-article-mime-handles)
2880 cid-dir abs))
2881 (when abs
2882 (setq cid-file
2883 (if (eq system-type 'cygwin)
2884 (concat "file:///"
2885 (substring
2886 (with-output-to-string
2887 (call-process "cygpath" nil
2888 standard-output
2889 nil "-m" cid-file))
2890 0 -1))
2891 (concat "file://" cid-file))))
2892 (replace-match cid-file nil nil nil 1))))
2893 (unless content (setq content (buffer-string))))
2894 (when (or charset header (not file))
2895 (setq tmp-file (mm-make-temp-file
2896 ;; Do we need to care for 8.3 filenames?
2897 "mm-" nil ".html")))
2898 ;; Add a meta html tag to specify charset and a header.
2899 (cond
2900 (header
2901 (let (title eheader body hcharset coding)
2902 (with-temp-buffer
2903 (mm-enable-multibyte)
2904 (setq case-fold-search t)
2905 (insert header "\n")
2906 (setq title (message-fetch-field "subject"))
2907 (goto-char (point-min))
2908 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2909 nil t)
2910 (replace-match (cond ((match-beginning 1) "&lt;")
2911 ((match-beginning 2) "&gt;")
2912 ((match-beginning 3) "&amp;")
2913 (t "<br>\n"))))
2914 (goto-char (point-min))
2915 (while (re-search-forward "^[\t ]+" nil t)
2916 (dotimes (i (prog1
2917 (current-column)
2918 (delete-region (match-beginning 0)
2919 (match-end 0))))
2920 (insert "&nbsp;")))
2921 (goto-char (point-min))
2922 (insert "<div align=\"left\">\n")
2923 (goto-char (point-max))
2924 (insert "</div>\n<hr>\n")
2925 ;; We have to examine charset one by one since
2926 ;; charset specified in parts might be different.
2927 (if (eq charset 'gnus-decoded)
2928 (setq charset 'utf-8
2929 eheader (mm-encode-coding-string (buffer-string)
2930 charset)
2931 title (when title
2932 (mm-encode-coding-string title charset))
2933 body (mm-encode-coding-string content charset))
2934 (setq hcharset (mm-find-mime-charset-region (point-min)
2935 (point-max)))
2936 (cond ((= (length hcharset) 1)
2937 (setq hcharset (car hcharset)
2938 coding (mm-charset-to-coding-system
2939 hcharset nil t)))
2940 ((> (length hcharset) 1)
2941 (setq hcharset 'utf-8
2942 coding hcharset)))
2943 (if coding
2944 (if charset
2945 (progn
2946 (setq body
2947 (mm-charset-to-coding-system charset
2948 nil t))
2949 (if (eq coding body)
2950 (setq eheader (mm-encode-coding-string
2951 (buffer-string) coding)
2952 title (when title
2953 (mm-encode-coding-string
2954 title coding))
2955 body content)
2956 (setq charset 'utf-8
2957 eheader (mm-encode-coding-string
2958 (buffer-string) charset)
2959 title (when title
2960 (mm-encode-coding-string
2961 title charset))
2962 body (mm-encode-coding-string
2963 (mm-decode-coding-string
2964 content body)
2965 charset))))
2966 (setq charset hcharset
2967 eheader (mm-encode-coding-string
2968 (buffer-string) coding)
2969 title (when title
2970 (mm-encode-coding-string
2971 title coding))
2972 body content))
2973 (setq eheader (mm-string-as-unibyte (buffer-string))
2974 body content)))
2975 (erase-buffer)
2976 (mm-disable-multibyte)
2977 (insert body)
2978 (when charset
2979 (mm-add-meta-html-tag handle charset t))
2980 (when title
2981 (goto-char (point-min))
2982 (unless (search-forward "<title>" nil t)
2983 (re-search-forward "<head>\\s-*" nil t)
2984 (insert "<title>" title "</title>\n")))
2985 (goto-char (point-min))
2986 (or (re-search-forward
2987 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2988 (re-search-forward
2989 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2990 (insert eheader)
2991 (mm-write-region (point-min) (point-max)
2992 tmp-file nil nil nil 'binary t))))
2993 (charset
2994 (mm-with-unibyte-buffer
2995 (insert (if (eq charset 'gnus-decoded)
2996 (mm-encode-coding-string content
2997 (setq charset 'utf-8))
2998 content))
2999 (if (or (mm-add-meta-html-tag handle charset)
3000 (not file))
3001 (mm-write-region (point-min) (point-max)
3002 tmp-file nil nil nil 'binary t)
3003 (setq tmp-file nil))))
3004 (tmp-file
3005 (mm-save-part-to-file handle tmp-file)))
3006 (when tmp-file
3007 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3008 (add-hook 'gnus-summary-prepare-exit-hook
3009 'gnus-article-browse-delete-temp-files)
3010 (add-hook 'gnus-exit-gnus-hook
3011 (lambda ()
3012 (gnus-article-browse-delete-temp-files t)))
3013 ;; FIXME: Warn if there's an <img> tag?
3014 (browse-url-of-file (or tmp-file (expand-file-name file)))
3015 (setq showed t))
3016 ;; If multipart, recurse
3017 ((equal (mm-handle-media-supertype handle) "multipart")
3018 (when (gnus-article-browse-html-parts handle header)
3019 (setq showed t)))
3020 ((equal (mm-handle-media-type handle) "message/rfc822")
3021 (mm-with-multibyte-buffer
3022 (mm-insert-part handle)
3023 (setq handle (mm-dissect-buffer t t))
3024 (when (and (bufferp (car handle))
3025 (stringp (car (mm-handle-type handle))))
3026 (setq handle (list handle)))
3027 (when header
3028 (article-decode-encoded-words)
3029 (let ((gnus-visible-headers
3030 (or (get 'gnus-visible-headers 'standard-value)
3031 gnus-visible-headers)))
3032 (article-hide-headers))
3033 (goto-char (point-min))
3034 (search-forward "\n\n" nil 'move)
3035 (skip-chars-backward "\t\n ")
3036 (setq header (buffer-substring (point-min) (point)))))
3037 (when (prog1
3038 (gnus-article-browse-html-parts handle header)
3039 (mm-destroy-parts handle))
3040 (setq showed t)))))
3041 showed))
3043 (defun gnus-article-browse-html-article (&optional arg)
3044 "View \"text/html\" parts of the current article with a WWW browser.
3045 Inline images embedded in a message using the cid scheme, as they are
3046 generally considered to be safe, will be processed properly.
3047 The message header is added to the beginning of every html part unless
3048 the prefix argument ARG is given.
3050 Warning: Spammers use links to images (using the http scheme) in HTML
3051 articles to verify whether you have read the message. As
3052 `gnus-article-browse-html-article' passes the HTML content to the
3053 browser without eliminating these \"web bugs\" you should only
3054 use it for mails from trusted senders.
3056 If you always want to display HTML parts in the browser, set
3057 `mm-text-html-renderer' to nil.
3059 This command creates temporary files to pass HTML contents including
3060 images if any to the browser, and deletes them when exiting the group
3061 \(if you want)."
3062 ;; Cf. `mm-w3m-safe-url-regexp'
3063 (interactive "P")
3064 (if arg
3065 (gnus-summary-show-article)
3066 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3067 gnus-visible-headers))
3068 ;; As we insert a <hr>, there's no need for the body boundary.
3069 (gnus-treat-body-boundary nil))
3070 (gnus-summary-show-article)))
3071 (with-current-buffer gnus-article-buffer
3072 (let ((header (unless arg
3073 (save-restriction
3074 (widen)
3075 (buffer-substring-no-properties
3076 (goto-char (point-min))
3077 (if (search-forward "\n\n" nil t)
3078 (match-beginning 0)
3079 (goto-char (point-max))
3080 (skip-chars-backward "\t\n ")
3081 (point))))))
3082 parts)
3083 (set-buffer gnus-original-article-buffer)
3084 (setq parts (mm-dissect-buffer t t))
3085 ;; If singlepart, enforce a list.
3086 (when (and (bufferp (car parts))
3087 (stringp (car (mm-handle-type parts))))
3088 (setq parts (list parts)))
3089 ;; Process the list
3090 (unless (gnus-article-browse-html-parts parts header)
3091 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3092 (mm-destroy-parts parts)
3093 (unless arg
3094 (gnus-summary-show-article)))))
3096 (defun article-hide-list-identifiers ()
3097 "Remove list identifiers from the Subject header.
3098 The `gnus-list-identifiers' variable specifies what to do."
3099 (interactive)
3100 (let ((inhibit-point-motion-hooks t)
3101 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3102 (inhibit-read-only t))
3103 (when regexp
3104 (save-excursion
3105 (save-restriction
3106 (article-narrow-to-head)
3107 (goto-char (point-min))
3108 (while (re-search-forward
3109 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3110 nil t)
3111 (delete-region (match-beginning 2) (match-end 0))
3112 (beginning-of-line))
3113 (when (re-search-forward
3114 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3115 (delete-region (match-beginning 1) (match-end 1))))))))
3117 (defun article-hide-pem (&optional arg)
3118 "Toggle hiding of any PEM headers and signatures in the current article.
3119 If given a negative prefix, always show; if given a positive prefix,
3120 always hide."
3121 (interactive (gnus-article-hidden-arg))
3122 (unless (gnus-article-check-hidden-text 'pem arg)
3123 (save-excursion
3124 (let ((inhibit-read-only t) end)
3125 (goto-char (point-min))
3126 ;; Hide the horrendously ugly "header".
3127 (when (and (search-forward
3128 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3129 nil t)
3130 (setq end (1+ (match-beginning 0))))
3131 (gnus-add-wash-type 'pem)
3132 (gnus-article-hide-text-type
3134 (if (search-forward "\n\n" nil t)
3135 (match-end 0)
3136 (point-max))
3137 'pem)
3138 ;; Hide the trailer as well
3139 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3140 nil t)
3141 (gnus-article-hide-text-type
3142 (match-beginning 0) (match-end 0) 'pem)))))))
3144 (defun article-strip-banner ()
3145 "Strip the banners specified by the `banner' group parameter and by
3146 `gnus-article-address-banner-alist'."
3147 (interactive)
3148 (save-excursion
3149 (save-restriction
3150 (let ((inhibit-point-motion-hooks t))
3151 (when (gnus-parameter-banner gnus-newsgroup-name)
3152 (article-really-strip-banner
3153 (gnus-parameter-banner gnus-newsgroup-name)))
3154 (when gnus-article-address-banner-alist
3155 ;; Note that the From header is decoded here, so it is
3156 ;; required that the *-extract-address-components function
3157 ;; supports non-ASCII text.
3158 (let ((from (save-restriction
3159 (widen)
3160 (article-narrow-to-head)
3161 (mail-fetch-field "from"))))
3162 (when (and from
3163 (setq from
3164 (cadr (funcall gnus-extract-address-components
3165 from))))
3166 (catch 'found
3167 (dolist (pair gnus-article-address-banner-alist)
3168 (when (string-match (car pair) from)
3169 (throw 'found
3170 (article-really-strip-banner (cdr pair)))))))))))))
3172 (defun article-really-strip-banner (banner)
3173 "Strip the banner specified by the argument."
3174 (save-excursion
3175 (save-restriction
3176 (let ((inhibit-point-motion-hooks t)
3177 (gnus-signature-limit nil)
3178 (inhibit-read-only t))
3179 (article-goto-body)
3180 (cond
3181 ((eq banner 'signature)
3182 (when (gnus-article-narrow-to-signature)
3183 (widen)
3184 (forward-line -1)
3185 (delete-region (point) (point-max))))
3186 ((symbolp banner)
3187 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3188 (while (re-search-forward banner nil t)
3189 (delete-region (match-beginning 0) (match-end 0)))))
3190 ((stringp banner)
3191 (while (re-search-forward banner nil t)
3192 (delete-region (match-beginning 0) (match-end 0)))))))))
3194 (defun article-babel ()
3195 "Translate article using an online translation service."
3196 (interactive)
3197 (require 'babel)
3198 (gnus-with-article-buffer
3199 (when (article-goto-body)
3200 (let* ((start (point))
3201 (end (point-max))
3202 (orig (buffer-substring start end))
3203 (trans (babel-as-string orig)))
3204 (save-restriction
3205 (narrow-to-region start end)
3206 (delete-region start end)
3207 (insert trans))))))
3209 (defun article-hide-signature (&optional arg)
3210 "Hide the signature in the current article.
3211 If given a negative prefix, always show; if given a positive prefix,
3212 always hide."
3213 (interactive (gnus-article-hidden-arg))
3214 (unless (gnus-article-check-hidden-text 'signature arg)
3215 (save-excursion
3216 (save-restriction
3217 (let ((inhibit-read-only t))
3218 (when (gnus-article-narrow-to-signature)
3219 (gnus-article-hide-text-type
3220 (point-min) (point-max) 'signature))))))
3221 (gnus-set-mode-line 'article))
3223 (defun article-strip-headers-in-body ()
3224 "Strip offensive headers from bodies."
3225 (interactive)
3226 (save-excursion
3227 (article-goto-body)
3228 (let ((case-fold-search t))
3229 (when (looking-at "x-no-archive:")
3230 (gnus-delete-line)))))
3232 (defun article-strip-leading-blank-lines ()
3233 "Remove all blank lines from the beginning of the article."
3234 (interactive)
3235 (save-excursion
3236 (let ((inhibit-point-motion-hooks t)
3237 (inhibit-read-only t))
3238 (when (article-goto-body)
3239 (while (and (not (eobp))
3240 (looking-at "[ \t]*$"))
3241 (gnus-delete-line))))))
3243 (defun article-narrow-to-head ()
3244 "Narrow the buffer to the head of the message.
3245 Point is left at the beginning of the narrowed-to region."
3246 (narrow-to-region
3247 (goto-char (point-min))
3248 (cond
3249 ;; Absolutely no headers displayed.
3250 ((looking-at "\n")
3251 (point))
3252 ;; Normal headers.
3253 ((search-forward "\n\n" nil 1)
3254 (1- (point)))
3255 ;; Nothing but headers.
3257 (point-max))))
3258 (goto-char (point-min)))
3260 (defun article-goto-body ()
3261 "Place point at the start of the body."
3262 (goto-char (point-min))
3263 (cond
3264 ;; This variable is only bound when dealing with separate
3265 ;; MIME body parts.
3266 (article-goto-body-goes-to-point-min-p
3268 ((search-forward "\n\n" nil t)
3271 (goto-char (point-max))
3272 nil)))
3274 (defun article-strip-multiple-blank-lines ()
3275 "Replace consecutive blank lines with one empty line."
3276 (interactive)
3277 (save-excursion
3278 (let ((inhibit-point-motion-hooks t)
3279 (inhibit-read-only t))
3280 ;; First make all blank lines empty.
3281 (article-goto-body)
3282 (while (re-search-forward "^[ \t]+$" nil t)
3283 (unless (gnus-annotation-in-region-p
3284 (match-beginning 0) (match-end 0))
3285 (replace-match "" nil t)))
3286 ;; Then replace multiple empty lines with a single empty line.
3287 (article-goto-body)
3288 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3289 (unless (gnus-annotation-in-region-p
3290 (match-beginning 0) (match-end 0))
3291 (delete-region (match-beginning 1) (match-end 1)))))))
3293 (defun article-strip-leading-space ()
3294 "Remove all white space from the beginning of the lines in the article."
3295 (interactive)
3296 (save-excursion
3297 (let ((inhibit-point-motion-hooks t)
3298 (inhibit-read-only t))
3299 (article-goto-body)
3300 (while (re-search-forward "^[ \t]+" nil t)
3301 (replace-match "" t t)))))
3303 (defun article-strip-trailing-space ()
3304 "Remove all white space from the end of the lines in the article."
3305 (interactive)
3306 (save-excursion
3307 (let ((inhibit-point-motion-hooks t)
3308 (inhibit-read-only t))
3309 (article-goto-body)
3310 (while (re-search-forward "[ \t]+$" nil t)
3311 (replace-match "" t t)))))
3313 (defun article-strip-blank-lines ()
3314 "Strip leading, trailing and multiple blank lines."
3315 (interactive)
3316 (article-strip-leading-blank-lines)
3317 (article-remove-trailing-blank-lines)
3318 (article-strip-multiple-blank-lines))
3320 (defun article-strip-all-blank-lines ()
3321 "Strip all blank lines."
3322 (interactive)
3323 (save-excursion
3324 (let ((inhibit-point-motion-hooks t)
3325 (inhibit-read-only t))
3326 (article-goto-body)
3327 (while (re-search-forward "^[ \t]*\n" nil t)
3328 (replace-match "" t t)))))
3330 (defun gnus-article-narrow-to-signature ()
3331 "Narrow to the signature; return t if a signature is found, else nil."
3332 (let ((inhibit-point-motion-hooks t))
3333 (when (gnus-article-search-signature)
3334 (forward-line 1)
3335 ;; Check whether we have some limits to what we consider
3336 ;; to be a signature.
3337 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3338 (list gnus-signature-limit)))
3339 limit limited)
3340 (while (setq limit (pop limits))
3341 (if (or (and (integerp limit)
3342 (< (- (point-max) (point)) limit))
3343 (and (floatp limit)
3344 (< (count-lines (point) (point-max)) limit))
3345 (and (functionp limit)
3346 (funcall limit))
3347 (and (stringp limit)
3348 (not (re-search-forward limit nil t))))
3349 () ; This limit did not succeed.
3350 (setq limited t
3351 limits nil)))
3352 (unless limited
3353 (narrow-to-region (point) (point-max))
3354 t)))))
3356 (defun gnus-article-search-signature ()
3357 "Search the current buffer for the signature separator.
3358 Put point at the beginning of the signature separator."
3359 (let ((cur (point)))
3360 (goto-char (point-max))
3361 (if (if (stringp gnus-signature-separator)
3362 (re-search-backward gnus-signature-separator nil t)
3363 (let ((seps gnus-signature-separator))
3364 (while (and seps
3365 (not (re-search-backward (car seps) nil t)))
3366 (pop seps))
3367 seps))
3369 (goto-char cur)
3370 nil)))
3372 (defun gnus-article-hidden-arg ()
3373 "Return the current prefix arg as a number, or 0 if no prefix."
3374 (list (if current-prefix-arg
3375 (prefix-numeric-value current-prefix-arg)
3376 0)))
3378 (defun gnus-article-check-hidden-text (type arg)
3379 "Return nil if hiding is necessary.
3380 Arg can be nil or a number. nil and positive means hide, negative
3381 means show, 0 means toggle."
3382 (save-excursion
3383 (save-restriction
3384 (let ((hide (gnus-article-hidden-text-p type)))
3385 (cond
3386 ((or (null arg)
3387 (> arg 0))
3388 nil)
3389 ((< arg 0)
3390 (gnus-article-show-hidden-text type)
3393 (if (eq hide 'hidden)
3394 (progn
3395 (gnus-article-show-hidden-text type)
3397 nil)))))))
3399 (defun gnus-article-hidden-text-p (type)
3400 "Say whether the current buffer contains hidden text of type TYPE."
3401 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3402 (while (and pos
3403 (not (get-text-property pos 'invisible))
3404 (not (get-text-property pos 'dummy-invisible)))
3405 (setq pos
3406 (text-property-any (1+ pos) (point-max) 'article-type type)))
3407 (if pos
3408 'hidden
3409 nil)))
3411 (defun gnus-article-show-hidden-text (type &optional _dummy)
3412 "Show all hidden text of type TYPE.
3413 Originally it is hide instead of DUMMY."
3414 (let ((inhibit-read-only t)
3415 (inhibit-point-motion-hooks t))
3416 (gnus-remove-text-properties-when
3417 'article-type type
3418 (point-min) (point-max)
3419 (cons 'article-type (cons type
3420 gnus-hidden-properties)))
3421 (gnus-delete-wash-type type)))
3423 (defconst article-time-units
3424 `((year . ,(* 365.25 24 60 60))
3425 (week . ,(* 7 24 60 60))
3426 (day . ,(* 24 60 60))
3427 (hour . ,(* 60 60))
3428 (minute . 60)
3429 (second . 1))
3430 "Mapping from time units to seconds.")
3432 (defun gnus-article-forward-header ()
3433 "Move point to the start of the next header.
3434 If the current header is a continuation header, this can be several
3435 lines forward."
3436 (let ((ended nil))
3437 (while (not ended)
3438 (forward-line 1)
3439 (if (looking-at "[ \t]+[^ \t]")
3440 (forward-line 1)
3441 (setq ended t)))))
3443 (defun article-treat-date ()
3444 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3445 (with-current-buffer gnus-summary-buffer
3446 gnus-article-date-headers)
3447 gnus-article-date-headers)
3450 (defun article-date-ut (&optional type _highlight date-position)
3451 "Convert DATE date to TYPE in the current article.
3452 The default type is `ut'. See `gnus-article-date-headers' for
3453 possible values."
3454 (interactive (list 'ut t))
3455 (let* ((case-fold-search t)
3456 (inhibit-read-only t)
3457 (inhibit-point-motion-hooks t)
3458 (visible-date (mail-fetch-field "Date"))
3459 pos date bface eface)
3460 (save-excursion
3461 (if date-position
3462 (progn
3463 (goto-char date-position)
3464 (setq date (get-text-property (point) 'original-date))
3465 (when (looking-at "[^:]+:[\t ]*")
3466 (setq bface (get-text-property (match-beginning 0) 'face)
3467 eface (get-text-property (match-end 0) 'face)))
3468 (delete-region (point)
3469 (progn
3470 (gnus-article-forward-header)
3471 (point)))
3472 (article-transform-date date type bface eface))
3473 (save-restriction
3474 (widen)
3475 (goto-char (point-min))
3476 (while (or (get-text-property (setq pos (point)) 'original-date)
3477 (and (setq pos (next-single-property-change
3478 (point) 'original-date))
3479 (goto-char pos)))
3480 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3481 (1+ (match-beginning 0))
3482 (point-max)))
3483 (while (setq pos (text-property-not-all pos (point-max)
3484 'gnus-date-type nil))
3485 (setq date (get-text-property pos 'original-date))
3486 (goto-char pos)
3487 (when (looking-at "[^:]+:[\t ]*")
3488 (setq bface (get-text-property (match-beginning 0) 'face)
3489 eface (get-text-property (match-end 0) 'face)))
3490 (delete-region pos (or (text-property-any pos (point-max)
3491 'gnus-date-type nil)
3492 (point-max))))
3493 (unless date ;; the 1st time
3494 (goto-char (point-min))
3495 (while (re-search-forward "^Date:[\t ]*" nil t)
3496 (setq date (get-text-property (match-beginning 0)
3497 'original-date)
3498 bface (get-text-property (match-beginning 0) 'face)
3499 eface (get-text-property (match-end 0) 'face))
3500 (delete-region (point-at-bol) (progn
3501 (gnus-article-forward-header)
3502 (point)))))
3503 (when (and (not date)
3504 visible-date)
3505 (setq date visible-date))
3506 (when date
3507 (article-transform-date date type bface eface))
3508 (goto-char (point-max))
3509 (widen)))))))
3511 (defun article-transform-date (date type bface eface)
3512 (dolist (this-type (cond
3513 ((null type)
3514 (list 'ut))
3515 ((atom type)
3516 (list type))
3518 type)))
3519 (goto-char
3520 (prog1
3521 (point)
3522 (add-text-properties
3523 (point)
3524 (progn
3525 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3526 (point))
3527 (list 'original-date date 'gnus-date-type this-type))))
3528 ;; Do highlighting.
3529 (when (looking-at
3530 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3531 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3532 (when (match-beginning 2)
3533 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3534 (while (and (zerop (forward-line 1))
3535 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3536 (when (match-beginning 1)
3537 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3539 (defun article-make-date-line (date type)
3540 "Return a DATE line of TYPE."
3541 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3542 combined-lapsed))
3543 (error "Unknown conversion type: %s" type))
3544 (condition-case ()
3545 (let ((time (ignore-errors (date-to-time date))))
3546 (cond
3547 ;; Convert to the local timezone.
3548 ((eq type 'local)
3549 (concat "Date: " (message-make-date time)))
3550 ;; Convert to Universal Time.
3551 ((eq type 'ut)
3552 (concat "Date: "
3553 (substring
3554 (message-make-date
3555 (let* ((e (parse-time-string date))
3556 (tm (apply 'encode-time e))
3557 (ms (car tm))
3558 (ls (- (cadr tm) (car (current-time-zone time)))))
3559 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3560 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3561 (t (list ms ls)))))
3562 0 -5)
3563 "UT"))
3564 ;; Get the original date from the article.
3565 ((eq type 'original)
3566 (concat "Date: " (if (string-match "\n+$" date)
3567 (substring date 0 (match-beginning 0))
3568 date)))
3569 ;; Let the user define the format.
3570 ((eq type 'user-defined)
3571 (let ((format (or (condition-case nil
3572 (with-current-buffer gnus-summary-buffer
3573 gnus-article-time-format)
3574 (error nil))
3575 gnus-article-time-format)))
3576 (if (functionp format)
3577 (funcall format time)
3578 (concat "Date: " (format-time-string format time)))))
3579 ;; ISO 8601.
3580 ((eq type 'iso8601)
3581 (let ((tz (car (current-time-zone time))))
3582 (concat
3583 "Date: "
3584 (format-time-string "%Y%m%dT%H%M%S" time)
3585 (format "%s%02d%02d"
3586 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3587 (/ (% (abs tz) 3600) 60)))))
3588 ;; Do a lapsed format.
3589 ((eq type 'lapsed)
3590 (concat "Date: " (article-lapsed-string time)))
3591 ;; A combined date/lapsed format.
3592 ((eq type 'combined-lapsed)
3593 (let ((date-string (article-make-date-line date 'original))
3594 (segments 3)
3595 lapsed-string)
3596 (while (and
3597 time
3598 (setq lapsed-string
3599 (concat " (" (article-lapsed-string time segments) ")"))
3600 (> (+ (length date-string)
3601 (length lapsed-string))
3602 (+ fill-column 6))
3603 (> segments 0))
3604 (setq segments (1- segments)))
3605 (if (> segments 0)
3606 (concat date-string lapsed-string)
3607 date-string)))
3608 ;; Display the date in proper English
3609 ((eq type 'english)
3610 (let ((dtime (decode-time time)))
3611 (concat
3612 "Date: the "
3613 (number-to-string (nth 3 dtime))
3614 (let ((digit (% (nth 3 dtime) 10)))
3615 (cond
3616 ((memq (nth 3 dtime) '(11 12 13)) "th")
3617 ((= digit 1) "st")
3618 ((= digit 2) "nd")
3619 ((= digit 3) "rd")
3620 (t "th")))
3621 " of "
3622 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3624 (number-to-string (nth 5 dtime))
3625 " at "
3626 (format "%02d" (nth 2 dtime))
3628 (format "%02d" (nth 1 dtime)))))))
3629 (foo
3630 (format "Date: %s (from Gnus)" date))))
3632 (defun article-lapsed-string (time &optional max-segments)
3633 ;; If the date is seriously mangled, the timezone functions are
3634 ;; liable to bug out, so we ignore all errors.
3635 (let* ((now (current-time))
3636 (real-time (subtract-time now time))
3637 (real-sec (and real-time
3638 (+ (* (float (car real-time)) 65536)
3639 (cadr real-time))))
3640 (sec (and real-time (abs real-sec)))
3641 (segments 0)
3642 num prev)
3643 (unless max-segments
3644 (setq max-segments (length article-time-units)))
3645 (cond
3646 ((null real-time)
3647 "Unknown")
3648 ((zerop sec)
3649 "Now")
3651 (concat
3652 ;; This is a bit convoluted, but basically we go
3653 ;; through the time units for years, weeks, etc,
3654 ;; and divide things to see whether that results
3655 ;; in positive answers.
3656 (mapconcat
3657 (lambda (unit)
3658 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3659 (>= segments max-segments))
3660 ;; The (remaining) seconds are too few to
3661 ;; be divided into this time unit.
3663 ;; It's big enough, so we output it.
3664 (setq sec (- sec (* num (cdr unit))))
3665 (prog1
3666 (concat (if prev ", " "") (int-to-string
3667 (floor num))
3668 " " (symbol-name (car unit))
3669 (if (> num 1) "s" ""))
3670 (setq prev t
3671 segments (1+ segments)))))
3672 article-time-units "")
3673 ;; If dates are odd, then it might appear like the
3674 ;; article was sent in the future.
3675 (if (> real-sec 0)
3676 " ago"
3677 " in the future"))))))
3679 (defun article-date-local (&optional highlight)
3680 "Convert the current article date to the local timezone."
3681 (interactive (list t))
3682 (article-date-ut 'local highlight))
3684 (defun article-date-english (&optional highlight)
3685 "Convert the current article date to something that is proper English."
3686 (interactive (list t))
3687 (article-date-ut 'english highlight))
3689 (defun article-date-original (&optional highlight)
3690 "Convert the current article date to what it was originally.
3691 This is only useful if you have used some other date conversion
3692 function and want to see what the date was before converting."
3693 (interactive (list t))
3694 (article-date-ut 'original highlight))
3696 (defun article-date-lapsed (&optional highlight)
3697 "Convert the current article date to time lapsed since it was sent."
3698 (interactive (list t))
3699 (article-date-ut 'lapsed highlight))
3701 (defun article-date-combined-lapsed (&optional highlight)
3702 "Convert the current article date to time lapsed since it was sent."
3703 (interactive (list t))
3704 (article-date-ut 'combined-lapsed highlight))
3706 (defun article-update-date-lapsed ()
3707 "Function to be run from a timer to update the lapsed time line."
3708 (save-match-data
3709 (let ((buffer (current-buffer)))
3710 (ignore-errors
3711 (walk-windows
3712 (lambda (w)
3713 (set-buffer (window-buffer w))
3714 (when (derived-mode-p 'gnus-article-mode)
3715 (let ((old-line (count-lines (point-min) (point)))
3716 (old-column (- (point) (line-beginning-position)))
3717 (window-start (window-start w))
3718 (pos (point-min))
3719 type next end)
3720 (while (setq pos (text-property-not-all pos (point-max)
3721 'gnus-date-type nil))
3722 (setq next (or (next-single-property-change pos
3723 'gnus-date-type)
3724 (point-max)))
3725 (setq type (get-text-property pos 'gnus-date-type))
3726 (when (memq type '(lapsed combined-lapsed user-defined))
3727 (article-date-ut type t pos)
3728 (setq end (or (next-single-property-change pos
3729 'gnus-date-type)
3730 (point-max)))
3731 (when window-start
3732 (if (/= window-start next)
3733 (setq window-start nil)
3734 (set-window-start w end)))
3735 (setq next end))
3736 (setq pos next))
3737 (goto-char (point-min))
3738 (when (> old-column 0)
3739 (setq old-line (1- old-line)))
3740 (forward-line old-line)
3741 (end-of-line)
3742 (when (> (current-column) old-column)
3743 (beginning-of-line)
3744 (forward-char old-column)))))
3745 nil 'visible))
3746 (set-buffer buffer))))
3748 (defun gnus-start-date-timer (&optional n)
3749 "Start a timer to update the Date headers in the article buffers.
3750 The numerical prefix says how frequently (in seconds) the function
3751 is to run."
3752 (interactive "p")
3753 (unless n
3754 (setq n 1))
3755 (gnus-stop-date-timer)
3756 (setq article-lapsed-timer
3757 (run-at-time 1 n 'article-update-date-lapsed)))
3759 (defun gnus-stop-date-timer ()
3760 "Stop the Date timer."
3761 (interactive)
3762 (when article-lapsed-timer
3763 (nnheader-cancel-timer article-lapsed-timer)
3764 (setq article-lapsed-timer nil)))
3766 (defun article-date-user (&optional highlight)
3767 "Convert the current article date to the user-defined format.
3768 This format is defined by the `gnus-article-time-format' variable."
3769 (interactive (list t))
3770 (article-date-ut 'user highlight))
3772 (defun article-date-iso8601 (&optional highlight)
3773 "Convert the current article date to ISO8601."
3774 (interactive (list t))
3775 (article-date-ut 'iso8601 highlight))
3777 (defmacro gnus-article-save-original-date (&rest forms)
3778 "Save the original date as a text property and evaluate FORMS."
3779 `(let* ((case-fold-search t)
3780 (start (progn
3781 (goto-char (point-min))
3782 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3783 (not (bolp)))
3784 (match-end 0))))
3785 (date (when (and start
3786 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3787 nil t))
3788 (buffer-substring-no-properties start
3789 (match-beginning 0)))))
3790 (goto-char (point-max))
3791 (skip-chars-backward "\n")
3792 (put-text-property (point-min) (point) 'original-date date)
3793 ,@forms
3794 (goto-char (point-max))
3795 (skip-chars-backward "\n")
3796 (put-text-property (point-min) (point) 'original-date date)))
3798 ;; (defun article-show-all ()
3799 ;; "Show all hidden text in the article buffer."
3800 ;; (interactive)
3801 ;; (save-excursion
3802 ;; (let ((inhibit-read-only t))
3803 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3805 (defun article-remove-leading-whitespace ()
3806 "Remove excessive whitespace from all headers."
3807 (interactive)
3808 (save-excursion
3809 (save-restriction
3810 (let ((inhibit-read-only t))
3811 (article-narrow-to-head)
3812 (goto-char (point-min))
3813 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3814 (delete-region (match-beginning 1) (match-end 1)))))))
3816 (defun article-emphasize (&optional arg)
3817 "Emphasize text according to `gnus-emphasis-alist'."
3818 (interactive (gnus-article-hidden-arg))
3819 (unless (gnus-article-check-hidden-text 'emphasis arg)
3820 (save-excursion
3821 (let ((alist (or
3822 (condition-case nil
3823 (with-current-buffer gnus-summary-buffer
3824 gnus-article-emphasis-alist)
3825 (error))
3826 gnus-emphasis-alist))
3827 (inhibit-read-only t)
3828 (props (append '(article-type emphasis)
3829 gnus-hidden-properties))
3830 regexp elem beg invisible visible face)
3831 (article-goto-body)
3832 (setq beg (point))
3833 (while (setq elem (pop alist))
3834 (goto-char beg)
3835 (setq regexp (car elem)
3836 invisible (nth 1 elem)
3837 visible (nth 2 elem)
3838 face (nth 3 elem))
3839 (while (re-search-forward regexp nil t)
3840 (when (and (match-beginning visible) (match-beginning invisible))
3841 (gnus-article-hide-text
3842 (match-beginning invisible) (match-end invisible) props)
3843 (gnus-article-unhide-text-type
3844 (match-beginning visible) (match-end visible) 'emphasis)
3845 (gnus-put-overlay-excluding-newlines
3846 (match-beginning visible) (match-end visible) 'face face)
3847 (gnus-add-wash-type 'emphasis)
3848 (goto-char (match-end invisible)))))))))
3850 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3851 "Setup newsgroup emphasis alist."
3852 (unless gnus-article-emphasis-alist
3853 (let ((name (and gnus-newsgroup-name
3854 (gnus-group-real-name gnus-newsgroup-name))))
3855 (make-local-variable 'gnus-article-emphasis-alist)
3856 (setq gnus-article-emphasis-alist
3857 (nconc
3858 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3859 (while (setq elem (pop alist))
3860 (when (and name (string-match (car elem) name))
3861 (setq alist nil
3862 highlight (copy-sequence (cdr elem)))))
3863 highlight)
3864 (copy-sequence highlight-words)
3865 (if gnus-newsgroup-name
3866 (copy-sequence (gnus-group-find-parameter
3867 gnus-newsgroup-name 'highlight-words t)))
3868 gnus-emphasis-alist)))))
3870 (defvar gnus-summary-article-menu)
3871 (defvar gnus-summary-post-menu)
3873 ;;; Saving functions.
3875 (defun gnus-article-save (save-buffer file &optional num)
3876 "Save the currently selected article."
3877 (when (or (get gnus-default-article-saver :headers)
3878 (not gnus-save-all-headers))
3879 ;; Remove headers according to `gnus-saved-headers' or the value
3880 ;; of the `:headers' property that the saver function might have.
3881 (let ((gnus-visible-headers
3882 (or (symbol-value (get gnus-default-article-saver :headers))
3883 gnus-saved-headers gnus-visible-headers))
3884 ;; Ignore group parameter. See `article-hide-headers'.
3885 (gnus-summary-buffer nil))
3886 (with-current-buffer save-buffer
3887 (article-hide-headers 1 t))))
3888 (save-window-excursion
3889 (if (not gnus-default-article-saver)
3890 (error "No default saver is defined")
3891 ;; !!! Magic! The saving functions all save
3892 ;; `gnus-save-article-buffer' (or so they think), but we
3893 ;; bind that variable to our save-buffer.
3894 (set-buffer gnus-article-buffer)
3895 (let* ((gnus-save-article-buffer save-buffer)
3896 (filename
3897 (cond
3898 ((not gnus-prompt-before-saving) 'default)
3899 ((eq gnus-prompt-before-saving 'always) nil)
3900 (t file)))
3901 (gnus-number-of-articles-to-be-saved
3902 (when (eq gnus-prompt-before-saving t)
3903 num))) ; Magic
3904 (set-buffer gnus-article-current-summary)
3905 (funcall gnus-default-article-saver filename)))))
3907 (defun gnus-read-save-file-name (prompt &optional filename
3908 function group headers variable
3909 dir-var)
3910 (let ((default-name
3911 (funcall function group headers (symbol-value variable)))
3912 result)
3913 (setq result
3914 (expand-file-name
3915 (cond
3916 ((eq filename 'default)
3917 default-name)
3918 ((eq filename t)
3919 default-name)
3920 (filename filename)
3922 (when (symbol-value dir-var)
3923 (setq default-name (expand-file-name
3924 (file-name-nondirectory default-name)
3925 (symbol-value dir-var))))
3926 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3927 (prompt
3928 (format prompt
3929 (if (and gnus-number-of-articles-to-be-saved
3930 (> gnus-number-of-articles-to-be-saved 1))
3931 (format "these %d articles"
3932 gnus-number-of-articles-to-be-saved)
3933 "this article")))
3934 (file
3935 ;; Let the split methods have their say.
3936 (cond
3937 ;; No split name was found.
3938 ((null split-name)
3939 (read-file-name
3940 (concat prompt " (default "
3941 (file-name-nondirectory default-name) "): ")
3942 (file-name-directory default-name)
3943 default-name))
3944 ;; A single group name is returned.
3945 ((stringp split-name)
3946 (setq default-name
3947 (funcall function split-name headers
3948 (symbol-value variable)))
3949 (read-file-name
3950 (concat prompt " (default "
3951 (file-name-nondirectory default-name) "): ")
3952 (file-name-directory default-name)
3953 default-name))
3954 ;; A single split name was found
3955 ((= 1 (length split-name))
3956 (let* ((name (expand-file-name
3957 (car split-name)
3958 gnus-article-save-directory))
3959 (dir (cond ((file-directory-p name)
3960 (file-name-as-directory name))
3961 ((file-exists-p name) name)
3962 (t gnus-article-save-directory))))
3963 (read-file-name
3964 (concat prompt " (default " name "): ")
3965 dir name)))
3966 ;; A list of splits was found.
3968 (setq split-name (nreverse split-name))
3969 (let (result)
3970 (let ((file-name-history
3971 (nconc split-name file-name-history)))
3972 (setq result
3973 (expand-file-name
3974 (read-file-name
3975 (concat prompt " (`M-p' for defaults): ")
3976 gnus-article-save-directory
3977 (car split-name))
3978 gnus-article-save-directory)))
3979 (car (push result file-name-history)))))))
3980 ;; Create the directory.
3981 (gnus-make-directory (file-name-directory file))
3982 ;; If we have read a directory, we append the default file name.
3983 (when (file-directory-p file)
3984 (setq file (expand-file-name (file-name-nondirectory
3985 default-name)
3986 (file-name-as-directory file))))
3987 ;; Possibly translate some characters.
3988 (nnheader-translate-file-chars file))))))
3989 (gnus-make-directory (file-name-directory result))
3990 (when variable
3991 (set variable result))
3992 (when dir-var
3993 (set dir-var (file-name-directory result)))
3994 result))
3996 (defun gnus-article-archive-name (_group)
3997 "Return the first instance of an \"Archive-name\" in the current buffer."
3998 (let ((case-fold-search t))
3999 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
4000 (nnheader-concat gnus-article-save-directory
4001 (match-string 1)))))
4003 (defun gnus-article-nndoc-name (group)
4004 "If GROUP is an nndoc group, return the name of the parent group."
4005 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4006 (gnus-group-get-parameter group 'save-article-group)))
4008 (defun gnus-summary-save-in-rmail (&optional filename)
4009 "Append this article to Rmail file.
4010 Optional argument FILENAME specifies file name.
4011 Directory to save to is default to `gnus-article-save-directory'."
4012 (setq filename (gnus-read-save-file-name
4013 "Save %s in rmail file" filename
4014 gnus-rmail-save-name gnus-newsgroup-name
4015 gnus-current-headers 'gnus-newsgroup-last-rmail))
4016 (with-current-buffer gnus-save-article-buffer
4017 (save-excursion
4018 (save-restriction
4019 (widen)
4020 ;; Note that unlike gnus-summary-save-in-mail, there is no
4021 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4022 ;; not use Babyl.
4023 (gnus-output-to-rmail filename))))
4024 filename)
4026 (defun gnus-summary-save-in-mail (&optional filename)
4027 "Append this article to Unix mail 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 Unix mail file" filename
4032 gnus-mail-save-name gnus-newsgroup-name
4033 gnus-current-headers 'gnus-newsgroup-last-mail))
4034 (with-current-buffer gnus-save-article-buffer
4035 (save-excursion
4036 (save-restriction
4037 (widen)
4038 (if (and (file-readable-p filename)
4039 (file-regular-p filename)
4040 (mail-file-babyl-p filename))
4041 (gnus-output-to-rmail filename)
4042 (gnus-output-to-mail filename)))))
4043 filename)
4045 (put 'gnus-summary-save-in-file :decode t)
4046 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4047 (defun gnus-summary-save-in-file (&optional filename overwrite)
4048 "Append this article to file.
4049 Optional argument FILENAME specifies file name.
4050 Directory to save to is default 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 'gnus-newsgroup-last-file))
4055 (with-current-buffer gnus-save-article-buffer
4056 (save-excursion
4057 (save-restriction
4058 (widen)
4059 (when (and overwrite
4060 (file-exists-p filename))
4061 (delete-file filename))
4062 (gnus-output-to-file filename))))
4063 filename)
4065 (put 'gnus-summary-write-to-file :decode t)
4066 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4067 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4068 (defun gnus-summary-write-to-file (&optional filename)
4069 "Write this article to a file, overwriting it if the file exists.
4070 Optional argument FILENAME specifies file name.
4071 The directory to save in defaults to `gnus-article-save-directory'."
4072 (setq filename (gnus-read-save-file-name
4073 "Save %s in file" filename
4074 gnus-file-save-name gnus-newsgroup-name
4075 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4076 (gnus-summary-save-in-file filename t))
4078 (put 'gnus-summary-save-body-in-file :decode t)
4079 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4080 "Append this article body to a file.
4081 Optional argument FILENAME specifies file name.
4082 The directory to save in defaults to `gnus-article-save-directory'."
4083 (setq filename (gnus-read-save-file-name
4084 "Save %s body in file" filename
4085 gnus-file-save-name gnus-newsgroup-name
4086 gnus-current-headers 'gnus-newsgroup-last-file))
4087 (with-current-buffer gnus-save-article-buffer
4088 (save-excursion
4089 (save-restriction
4090 (widen)
4091 (when (article-goto-body)
4092 (narrow-to-region (point) (point-max)))
4093 (when (and overwrite
4094 (file-exists-p filename))
4095 (delete-file filename))
4096 (gnus-output-to-file filename))))
4097 filename)
4099 (put 'gnus-summary-write-body-to-file :decode t)
4100 (put 'gnus-summary-write-body-to-file
4101 :function 'gnus-summary-save-body-in-file)
4102 (defun gnus-summary-write-body-to-file (&optional filename)
4103 "Write this article body to a file, overwriting it if the file exists.
4104 Optional argument FILENAME specifies file name.
4105 The directory to save in defaults to `gnus-article-save-directory'."
4106 (setq filename (gnus-read-save-file-name
4107 "Save %s body in file" filename
4108 gnus-file-save-name gnus-newsgroup-name
4109 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4110 (gnus-summary-save-body-in-file filename t))
4112 (put 'gnus-summary-save-in-pipe :decode t)
4113 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4114 (defun gnus-summary-save-in-pipe (&optional command raw)
4115 "Pipe this article to subprocess COMMAND.
4116 Valid values for COMMAND include:
4117 a string
4118 The executable command name and possibly arguments.
4120 You will be prompted for the command in the minibuffer.
4121 the symbol `default'
4122 It will be replaced with the command which the variable
4123 `gnus-summary-pipe-output-default-command' holds or the command
4124 last used for saving.
4125 Non-nil value for RAW overrides `:decode' and `:headers' properties
4126 and the raw article including all headers will be piped."
4127 (let ((article (gnus-summary-article-number))
4128 (decode (unless raw
4129 (get 'gnus-summary-save-in-pipe :decode)))
4130 save-buffer default)
4131 (if article
4132 (if (vectorp (gnus-summary-article-header article))
4133 (save-current-buffer
4134 (gnus-summary-select-article decode decode nil article)
4135 (insert-buffer-substring
4136 (prog1
4137 (if decode
4138 gnus-article-buffer
4139 gnus-original-article-buffer)
4140 (setq save-buffer
4141 (nnheader-set-temp-buffer " *Gnus Save*"))))
4142 ;; Remove unwanted headers.
4143 (when (and (not raw)
4144 (or (get 'gnus-summary-save-in-pipe :headers)
4145 (not gnus-save-all-headers)))
4146 (let ((gnus-visible-headers
4147 (or (symbol-value (get 'gnus-summary-save-in-pipe
4148 :headers))
4149 gnus-saved-headers gnus-visible-headers))
4150 (gnus-summary-buffer nil))
4151 (article-hide-headers 1 t))))
4152 (error "%d is not a real article" article))
4153 (error "No article to pipe"))
4154 (setq default (or gnus-summary-pipe-output-default-command
4155 gnus-last-shell-command))
4156 (unless (stringp command)
4157 (setq command
4158 (if (and (eq command 'default) default)
4159 default
4160 (gnus-read-shell-command "Shell command on this article: "
4161 default))))
4162 (when (string-equal command "")
4163 (if default
4164 (setq command default)
4165 (error "A command is required")))
4166 (with-current-buffer save-buffer
4167 (save-restriction
4168 (widen)
4169 (shell-command-on-region (point-min) (point-max) command nil)))
4170 (gnus-kill-buffer save-buffer))
4171 (setq gnus-summary-pipe-output-default-command command))
4173 (defun gnus-summary-pipe-to-muttprint (&optional command)
4174 "Pipe this article to muttprint."
4175 (unless (stringp command)
4176 (setq command (read-string
4177 "Print using command: " gnus-summary-muttprint-program
4178 nil gnus-summary-muttprint-program)))
4179 (let ((gnus-summary-pipe-output-default-command
4180 gnus-summary-pipe-output-default-command))
4181 (gnus-summary-save-in-pipe command))
4182 (setq gnus-summary-muttprint-program command))
4184 ;;; Article file names when saving.
4186 (defun gnus-capitalize-newsgroup (newsgroup)
4187 "Capitalize NEWSGROUP name."
4188 (when (not (zerop (length newsgroup)))
4189 (concat (char-to-string (upcase (aref newsgroup 0)))
4190 (substring newsgroup 1))))
4192 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4193 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4194 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4195 Otherwise, it is like ~/News/news/group/num."
4196 (let ((default
4197 (expand-file-name
4198 (concat (if (gnus-use-long-file-name 'not-save)
4199 (gnus-capitalize-newsgroup newsgroup)
4200 (gnus-newsgroup-directory-form newsgroup))
4201 "/" (int-to-string (mail-header-number headers)))
4202 gnus-article-save-directory)))
4203 (if (and last-file
4204 (string-equal (file-name-directory default)
4205 (file-name-directory last-file))
4206 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4207 default
4208 (or last-file default))))
4210 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4211 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4212 If variable `gnus-use-long-file-name' is non-nil, it is
4213 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4214 (let ((default
4215 (expand-file-name
4216 (concat (if (gnus-use-long-file-name 'not-save)
4217 newsgroup
4218 (gnus-newsgroup-directory-form newsgroup))
4219 "/" (int-to-string (mail-header-number headers)))
4220 gnus-article-save-directory)))
4221 (if (and last-file
4222 (string-equal (file-name-directory default)
4223 (file-name-directory last-file))
4224 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4225 default
4226 (or last-file default))))
4228 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4229 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4230 If variable `gnus-use-long-file-name' is non-nil, it is
4231 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4232 (or last-file
4233 (expand-file-name
4234 (if (gnus-use-long-file-name 'not-save)
4235 newsgroup
4236 (file-relative-name
4237 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4238 default-directory))
4239 gnus-article-save-directory)))
4241 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4242 "Generate file name from sender."
4243 (let ((from (mail-header-from headers)))
4244 (expand-file-name
4245 (if (and from (string-match "\\([^ <]+\\)@" from))
4246 (match-string 1 from)
4247 "nobody")
4248 gnus-article-save-directory)))
4250 (defun article-verify-x-pgp-sig ()
4251 "Verify X-PGP-Sig."
4252 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4253 (interactive)
4254 (if (gnus-buffer-live-p gnus-original-article-buffer)
4255 (let ((sig (with-current-buffer gnus-original-article-buffer
4256 (gnus-fetch-field "X-PGP-Sig")))
4257 items info headers)
4258 (when (and sig
4259 mml2015-use
4260 (mml2015-clear-verify-function))
4261 (with-temp-buffer
4262 (insert-buffer-substring gnus-original-article-buffer)
4263 (setq items (split-string sig))
4264 (message-narrow-to-head)
4265 (let ((inhibit-point-motion-hooks t)
4266 (case-fold-search t))
4267 ;; Don't verify multiple headers.
4268 (setq headers (mapconcat (lambda (header)
4269 (concat header ": "
4270 (mail-fetch-field header)
4271 "\n"))
4272 (split-string (nth 1 items) ",") "")))
4273 (delete-region (point-min) (point-max))
4274 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4275 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4276 (insert headers)
4277 (widen)
4278 (forward-line)
4279 (while (not (eobp))
4280 (if (looking-at "^-")
4281 (insert "- "))
4282 (forward-line))
4283 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4284 (insert "Version: " (car items) "\n\n")
4285 (insert (mapconcat 'identity (cddr items) "\n"))
4286 (insert "\n-----END PGP SIGNATURE-----\n")
4287 (let ((mm-security-handle (list (format "multipart/signed"))))
4288 (mml2015-clean-buffer)
4289 (let ((coding-system-for-write (or gnus-newsgroup-charset
4290 'iso-8859-1)))
4291 (funcall (mml2015-clear-verify-function)))
4292 (setq info
4293 (or (mm-handle-multipart-ctl-parameter
4294 mm-security-handle 'gnus-details)
4295 (mm-handle-multipart-ctl-parameter
4296 mm-security-handle 'gnus-info)))))
4297 (when info
4298 (let ((inhibit-read-only t) bface eface)
4299 (save-restriction
4300 (message-narrow-to-head)
4301 (goto-char (point-max))
4302 (forward-line -1)
4303 (setq bface (get-text-property (point-at-bol) 'face)
4304 eface (get-text-property (1- (point-at-eol)) 'face))
4305 (message-remove-header "X-Gnus-PGP-Verify")
4306 (if (re-search-forward "^X-PGP-Sig:" nil t)
4307 (forward-line)
4308 (goto-char (point-max)))
4309 (narrow-to-region (point) (point))
4310 (insert "X-Gnus-PGP-Verify: " info "\n")
4311 (goto-char (point-min))
4312 (forward-line)
4313 (while (not (eobp))
4314 (if (not (looking-at "^[ \t]"))
4315 (insert " "))
4316 (forward-line))
4317 ;; Do highlighting.
4318 (goto-char (point-min))
4319 (when (looking-at "\\([^:]+\\): *")
4320 (put-text-property (match-beginning 1) (1+ (match-end 1))
4321 'face bface)
4322 (put-text-property (match-end 0) (point-max)
4323 'face eface)))))))))
4325 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4327 (defun article-verify-cancel-lock ()
4328 "Verify Cancel-Lock header."
4329 (interactive)
4330 (if (gnus-buffer-live-p gnus-original-article-buffer)
4331 (canlock-verify gnus-original-article-buffer)))
4333 (eval-and-compile
4334 (mapc
4335 (lambda (func)
4336 (let (afunc gfunc)
4337 (if (consp func)
4338 (setq afunc (car func)
4339 gfunc (cdr func))
4340 (setq afunc func
4341 gfunc (intern (format "gnus-%s" func))))
4342 (defalias gfunc
4343 (when (fboundp afunc)
4344 `(lambda (&optional interactive &rest args)
4345 ,(documentation afunc t)
4346 (interactive (list t))
4347 (with-current-buffer gnus-article-buffer
4348 (if interactive
4349 (call-interactively ',afunc)
4350 (apply ',afunc args))))))))
4351 '(article-hide-headers
4352 article-verify-x-pgp-sig
4353 article-verify-cancel-lock
4354 article-hide-boring-headers
4355 article-treat-overstrike
4356 article-treat-ansi-sequences
4357 article-fill-long-lines
4358 article-capitalize-sentences
4359 article-remove-cr
4360 article-remove-leading-whitespace
4361 article-display-x-face
4362 article-display-face
4363 article-de-quoted-unreadable
4364 article-de-base64-unreadable
4365 article-decode-HZ
4366 article-wash-html
4367 article-unsplit-urls
4368 article-hide-list-identifiers
4369 article-strip-banner
4370 article-babel
4371 article-hide-pem
4372 article-hide-signature
4373 article-strip-headers-in-body
4374 article-remove-trailing-blank-lines
4375 article-strip-leading-blank-lines
4376 article-strip-multiple-blank-lines
4377 article-strip-leading-space
4378 article-strip-trailing-space
4379 article-strip-blank-lines
4380 article-strip-all-blank-lines
4381 article-date-local
4382 article-date-english
4383 article-date-iso8601
4384 article-date-original
4385 article-treat-date
4386 article-date-ut
4387 article-decode-mime-words
4388 article-decode-charset
4389 article-decode-encoded-words
4390 article-date-user
4391 article-date-lapsed
4392 article-date-combined-lapsed
4393 article-emphasize
4394 article-treat-dumbquotes
4395 article-treat-non-ascii
4396 article-normalize-headers
4397 ;;(article-show-all . gnus-article-show-all-headers)
4401 ;;; Gnus article mode
4404 (put 'gnus-article-mode 'mode-class 'special)
4406 (set-keymap-parent gnus-article-mode-map widget-keymap)
4408 (gnus-define-keys gnus-article-mode-map
4409 " " gnus-article-goto-next-page
4410 [?\S-\ ] gnus-article-goto-prev-page
4411 "\177" gnus-article-goto-prev-page
4412 [delete] gnus-article-goto-prev-page
4413 "\C-c^" gnus-article-refer-article
4414 "h" gnus-article-show-summary
4415 "s" gnus-article-show-summary
4416 "\C-c\C-m" gnus-article-mail
4417 "?" gnus-article-describe-briefly
4418 "<" beginning-of-buffer
4419 ">" end-of-buffer
4420 "\C-c\C-i" gnus-info-find-node
4421 "\C-c\C-b" gnus-bug
4422 "R" gnus-article-reply-with-original
4423 "F" gnus-article-followup-with-original
4424 "\C-hk" gnus-article-describe-key
4425 "\C-hc" gnus-article-describe-key-briefly
4426 "\C-hb" gnus-article-describe-bindings
4428 "e" gnus-article-read-summary-keys
4429 "\C-d" gnus-article-read-summary-keys
4430 "\M-*" gnus-article-read-summary-keys
4431 "\M-#" gnus-article-read-summary-keys
4432 "\M-^" gnus-article-read-summary-keys
4433 "\M-g" gnus-article-read-summary-keys)
4435 (substitute-key-definition
4436 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4438 (defvar gnus-article-send-map)
4440 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4441 "W" gnus-article-wide-reply-with-original)
4442 (if (featurep 'xemacs)
4443 (set-keymap-default-binding gnus-article-send-map
4444 'gnus-article-read-summary-send-keys)
4445 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4447 (defun gnus-article-make-menu-bar ()
4448 (unless (boundp 'gnus-article-commands-menu)
4449 (gnus-summary-make-menu-bar))
4450 (unless (boundp 'gnus-article-article-menu)
4451 (easy-menu-define
4452 gnus-article-article-menu gnus-article-mode-map ""
4453 '("Article"
4454 ["Scroll forwards" gnus-article-goto-next-page t]
4455 ["Scroll backwards" gnus-article-goto-prev-page t]
4456 ["Show summary" gnus-article-show-summary t]
4457 ["Fetch Message-ID at point" gnus-article-refer-article t]
4458 ["Mail to address at point" gnus-article-mail t]
4459 ["Send a bug report" gnus-bug t]))
4461 (easy-menu-define
4462 gnus-article-treatment-menu gnus-article-mode-map ""
4463 ;; Fixme: this should use :active (and maybe :visible).
4464 '("Treatment"
4465 ["Hide headers" gnus-article-hide-headers t]
4466 ["Hide signature" gnus-article-hide-signature t]
4467 ["Hide citation" gnus-article-hide-citation t]
4468 ["Treat overstrike" gnus-article-treat-overstrike t]
4469 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4470 ["Remove carriage return" gnus-article-remove-cr t]
4471 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4472 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4473 ["Remove base64" gnus-article-de-base64-unreadable t]
4474 ["Treat html" gnus-article-wash-html t]
4475 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4476 ["Decode HZ" gnus-article-decode-HZ t]))
4478 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4480 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4482 (gnus-run-hooks 'gnus-article-menu-hook)))
4484 (defvar bookmark-make-record-function)
4485 (defvar shr-put-image-function)
4487 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4488 "Major mode for displaying an article.
4490 All normal editing commands are switched off.
4492 The following commands are available in addition to all summary mode
4493 commands:
4494 \\<gnus-article-mode-map>
4495 \\[gnus-article-next-page]\t Scroll the article one page forwards
4496 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4497 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4498 \\[gnus-article-show-summary]\t Display the summary buffer
4499 \\[gnus-article-mail]\t Send a reply to the address near point
4500 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4501 \\[gnus-info-find-node]\t Go to the Gnus info node"
4502 (gnus-simplify-mode-line)
4503 (make-local-variable 'minor-mode-alist)
4504 (when (gnus-visual-p 'article-menu 'menu)
4505 (gnus-article-make-menu-bar)
4506 (when gnus-summary-tool-bar-map
4507 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4508 (gnus-update-format-specifications nil 'article-mode)
4509 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4510 (set (make-local-variable 'gnus-page-broken) nil)
4511 (make-local-variable 'gnus-article-current-summary)
4512 (make-local-variable 'gnus-article-mime-handles)
4513 (make-local-variable 'gnus-article-decoded-p)
4514 (make-local-variable 'gnus-article-mime-handle-alist)
4515 (make-local-variable 'gnus-article-wash-types)
4516 (make-local-variable 'gnus-article-image-alist)
4517 (make-local-variable 'gnus-article-charset)
4518 (make-local-variable 'gnus-article-ignored-charsets)
4519 (set (make-local-variable 'bookmark-make-record-function)
4520 'gnus-summary-bookmark-make-record)
4521 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4522 ;; face.
4523 (set (make-local-variable 'nobreak-char-display) nil)
4524 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4525 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4526 (setq cursor-in-non-selected-windows nil)
4527 (gnus-set-default-directory)
4528 (buffer-disable-undo)
4529 (setq buffer-read-only t
4530 show-trailing-whitespace nil)
4531 (mm-enable-multibyte))
4533 (defun gnus-article-setup-buffer ()
4534 "Initialize the article buffer."
4535 (let* ((name (if gnus-single-article-buffer "*Article*"
4536 (concat "*Article "
4537 (gnus-group-decoded-name gnus-newsgroup-name)
4538 "*")))
4539 (original
4540 (progn (string-match "\\*Article" name)
4541 (concat " *Original Article"
4542 (substring name (match-end 0))))))
4543 (setq gnus-article-buffer name)
4544 (setq gnus-original-article-buffer original)
4545 (setq gnus-article-mime-handle-alist nil)
4546 (with-current-buffer gnus-summary-buffer
4547 ;; This might be a variable local to the summary buffer.
4548 (unless gnus-single-article-buffer
4549 (setq gnus-article-buffer name)
4550 (setq gnus-original-article-buffer original)
4551 (gnus-set-global-variables)))
4552 (gnus-article-setup-highlight-words)
4553 ;; Init original article buffer.
4554 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4555 (mm-enable-multibyte)
4556 (setq major-mode 'gnus-original-article-mode)
4557 (make-local-variable 'gnus-original-article))
4558 (if (and (get-buffer name)
4559 (with-current-buffer name
4560 (if gnus-article-edit-mode
4561 (if (y-or-n-p "Article mode edit in progress; discard? ")
4562 (progn
4563 (set-buffer-modified-p nil)
4564 (gnus-kill-buffer name)
4565 (message "")
4566 nil)
4567 (error "Action aborted"))
4568 t)))
4569 (let ((summary gnus-summary-buffer))
4570 (with-current-buffer name
4571 (set (make-local-variable 'gnus-article-edit-mode) nil)
4572 (gnus-article-stop-animations)
4573 (when gnus-article-mime-handles
4574 (mm-destroy-parts gnus-article-mime-handles)
4575 (setq gnus-article-mime-handles nil))
4576 ;; Set it to nil in article-buffer!
4577 (setq gnus-article-mime-handle-alist nil)
4578 (buffer-disable-undo)
4579 (setq buffer-read-only t)
4580 (unless (derived-mode-p 'gnus-article-mode)
4581 (gnus-article-mode))
4582 (set (make-local-variable 'gnus-summary-buffer) summary)
4583 (setq truncate-lines gnus-article-truncate-lines)
4584 (current-buffer)))
4585 (let ((summary gnus-summary-buffer))
4586 (with-current-buffer (gnus-get-buffer-create name)
4587 (gnus-article-mode)
4588 (setq truncate-lines gnus-article-truncate-lines)
4589 (set (make-local-variable 'gnus-summary-buffer) summary)
4590 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4591 (when article-lapsed-timer
4592 (gnus-stop-date-timer))
4593 (when gnus-article-update-date-headers
4594 (gnus-start-date-timer gnus-article-update-date-headers))
4595 (current-buffer))))))
4597 (defun gnus-article-stop-animations ()
4598 (dolist (timer (and (boundp 'timer-list)
4599 timer-list))
4600 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4601 (cancel-timer timer))))
4603 (defun gnus-stop-downloads ()
4604 (when (boundp 'url-queue)
4605 (set (intern "url-queue" obarray) nil)))
4607 ;; Set article window start at LINE, where LINE is the number of lines
4608 ;; from the head of the article.
4609 (defun gnus-article-set-window-start (&optional line)
4610 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4611 (when article-window
4612 (set-window-start
4613 article-window
4614 (with-current-buffer gnus-article-buffer
4615 (goto-char (point-min))
4616 (if (not line)
4617 (point-min)
4618 (gnus-message 6 "Moved to bookmark")
4619 (search-forward "\n\n" nil t)
4620 (forward-line line)
4621 (point)))))))
4623 (defvar gnus-tmp-internal-hook)
4625 (defun gnus-article-prepare (article &optional all-headers _header)
4626 "Prepare ARTICLE in article mode buffer.
4627 ARTICLE should either be an article number or a Message-ID.
4628 If ARTICLE is an id, HEADER should be the article headers.
4629 If ALL-HEADERS is non-nil, no headers are hidden."
4630 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4631 ;; Make sure we start in a summary buffer.
4632 (unless (derived-mode-p 'gnus-summary-mode)
4633 (set-buffer gnus-summary-buffer))
4634 (setq gnus-summary-buffer (current-buffer))
4635 (let* ((summary-buffer (current-buffer))
4636 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4637 (group gnus-newsgroup-name)
4638 result)
4639 (save-excursion
4640 (gnus-article-setup-buffer)
4641 (set-buffer gnus-article-buffer)
4642 ;; Deactivate active regions.
4643 (when (and (boundp 'transient-mark-mode)
4644 transient-mark-mode)
4645 (setq mark-active nil))
4646 (if (not (setq result (let ((inhibit-read-only t))
4647 (gnus-request-article-this-buffer
4648 article group))))
4649 ;; There is no such article.
4650 (save-excursion
4651 (when (and (numberp article)
4652 (not (memq article gnus-newsgroup-sparse)))
4653 (setq gnus-article-current
4654 (cons gnus-newsgroup-name article))
4655 (set-buffer gnus-summary-buffer)
4656 (setq gnus-current-article article)
4657 (if (and (memq article gnus-newsgroup-undownloaded)
4658 (not (gnus-online (gnus-find-method-for-group
4659 gnus-newsgroup-name))))
4660 (progn
4661 (gnus-summary-set-agent-mark article)
4662 (message "Message marked for downloading"))
4663 (gnus-summary-mark-article article gnus-canceled-mark)
4664 (unless (memq article gnus-newsgroup-sparse)
4665 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4666 (if (or (eq result 'pseudo)
4667 (eq result 'nneething))
4668 (progn
4669 (with-current-buffer summary-buffer
4670 (push article gnus-newsgroup-history)
4671 (setq gnus-last-article gnus-current-article
4672 gnus-current-article 0
4673 gnus-current-headers nil
4674 gnus-article-current nil)
4675 (if (eq result 'nneething)
4676 (gnus-configure-windows 'summary)
4677 (gnus-configure-windows 'article))
4678 (gnus-set-global-variables))
4679 (let ((gnus-article-mime-handle-alist-1
4680 gnus-article-mime-handle-alist))
4681 (gnus-set-mode-line 'article)))
4682 ;; The result from the `request' was an actual article -
4683 ;; or at least some text that is now displayed in the
4684 ;; article buffer.
4685 (when (and (numberp article)
4686 (not (eq article gnus-current-article)))
4687 ;; Seems like a new article has been selected.
4688 ;; `gnus-current-article' must be an article number.
4689 (with-current-buffer summary-buffer
4690 (push article gnus-newsgroup-history)
4691 (setq gnus-last-article gnus-current-article
4692 gnus-current-article article
4693 gnus-current-headers
4694 (gnus-summary-article-header gnus-current-article)
4695 gnus-article-current
4696 (cons gnus-newsgroup-name gnus-current-article))
4697 (unless (vectorp gnus-current-headers)
4698 (setq gnus-current-headers nil))
4699 (gnus-summary-goto-subject gnus-current-article)
4700 (when (gnus-summary-show-thread)
4701 ;; If the summary buffer really was folded, the
4702 ;; previous goto may not actually have gone to
4703 ;; the right article, but the thread root instead.
4704 ;; So we go again.
4705 (gnus-summary-goto-subject gnus-current-article))
4706 (gnus-run-hooks 'gnus-mark-article-hook)
4707 (gnus-set-mode-line 'summary)
4708 (when (gnus-visual-p 'article-highlight 'highlight)
4709 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4710 ;; Set the global newsgroup variables here.
4711 (gnus-set-global-variables)
4712 (setq gnus-have-all-headers
4713 (or all-headers gnus-show-all-headers))))
4714 (save-excursion
4715 (gnus-configure-windows 'article))
4716 (when (or (numberp article)
4717 (stringp article))
4718 (gnus-article-prepare-display)
4719 ;; Do page break.
4720 (goto-char (point-min))
4721 (when gnus-break-pages
4722 (gnus-narrow-to-page)))
4723 (let ((gnus-article-mime-handle-alist-1
4724 gnus-article-mime-handle-alist))
4725 (gnus-set-mode-line 'article))
4726 (article-goto-body)
4727 (unless (bobp)
4728 (forward-line -1))
4729 (set-window-point (get-buffer-window (current-buffer)) (point))
4730 (gnus-configure-windows 'article)
4731 (gnus-run-hooks 'gnus-article-prepare-hook)
4732 t))))))
4734 (defvar gnus-mime-display-attachment-buttons-in-header)
4736 ;;;###autoload
4737 (defun gnus-article-prepare-display ()
4738 "Make the current buffer look like a nice article."
4739 ;; Hooks for getting information from the article.
4740 ;; This hook must be called before being narrowed.
4741 (let ((gnus-article-buffer (current-buffer))
4742 buffer-read-only
4743 (inhibit-read-only t))
4744 (unless (derived-mode-p 'gnus-article-mode)
4745 (gnus-article-mode))
4746 (setq buffer-read-only nil
4747 gnus-article-wash-types nil
4748 gnus-article-image-alist nil)
4749 (gnus-run-hooks 'gnus-tmp-internal-hook)
4750 (when gnus-display-mime-function
4751 (funcall gnus-display-mime-function))
4752 ;; Add attachment buttons to the header.
4753 (when gnus-mime-display-attachment-buttons-in-header
4754 (gnus-mime-buttonize-attachments-in-header))))
4757 ;;; Gnus Sticky Article Mode
4760 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4761 "Mode for sticky articles."
4762 ;; Release bindings that won't work.
4763 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4764 gnus-sticky-article-mode-map)
4765 (substitute-key-definition 'gnus-article-refer-article 'undefined
4766 gnus-sticky-article-mode-map)
4767 (dolist (k '("e" "h" "s" "F" "R"))
4768 (define-key gnus-sticky-article-mode-map k nil))
4769 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4770 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4771 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4772 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4774 (defun gnus-sticky-article (arg)
4775 "Make the current article sticky.
4776 If a prefix ARG is given, ask for a name for this sticky article buffer."
4777 (interactive "P")
4778 (gnus-summary-show-thread)
4779 (gnus-summary-select-article nil nil 'pseudo)
4780 (let (new-art-buf-name)
4781 (gnus-eval-in-buffer-window gnus-article-buffer
4782 (setq new-art-buf-name
4783 (concat
4784 "*Sticky Article: "
4785 (if arg
4786 (read-from-minibuffer "Sticky article buffer name: ")
4787 (gnus-with-article-headers
4788 (gnus-article-goto-header "subject")
4789 (setq new-art-buf-name
4790 (buffer-substring-no-properties
4791 (line-beginning-position) (line-end-position)))
4792 (goto-char (point-min))
4793 (gnus-article-goto-header "from")
4794 (setq new-art-buf-name
4795 (concat
4796 new-art-buf-name ", "
4797 (buffer-substring-no-properties
4798 (line-beginning-position) (line-end-position))))
4799 (goto-char (point-min))
4800 (gnus-article-goto-header "date")
4801 (setq new-art-buf-name
4802 (concat
4803 new-art-buf-name ", "
4804 (buffer-substring-no-properties
4805 (line-beginning-position) (line-end-position))))))
4806 "*"))
4807 (if (and (gnus-buffer-live-p new-art-buf-name)
4808 (with-current-buffer new-art-buf-name
4809 (derived-mode-p 'gnus-sticky-article-mode)))
4810 (switch-to-buffer new-art-buf-name)
4811 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4812 (gnus-sticky-article-mode))
4813 (setq gnus-article-buffer new-art-buf-name))
4814 (gnus-summary-recenter)
4815 (gnus-summary-position-point))
4817 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4818 "Kill the given sticky article BUFFER.
4819 If none is given, assume the current buffer and kill it if it has
4820 `gnus-sticky-article-mode'."
4821 (interactive)
4822 (unless buffer
4823 (setq buffer (current-buffer)))
4824 (with-current-buffer buffer
4825 (when (derived-mode-p 'gnus-sticky-article-mode)
4826 (gnus-kill-buffer buffer))))
4828 (defun gnus-kill-sticky-article-buffers (arg)
4829 "Kill all sticky article buffers.
4830 If a prefix ARG is given, ask for confirmation."
4831 (interactive "P")
4832 (dolist (buf (gnus-buffers))
4833 (with-current-buffer buf
4834 (when (derived-mode-p 'gnus-sticky-article-mode)
4835 (if (not arg)
4836 (gnus-kill-buffer buf)
4837 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4838 (gnus-kill-buffer buf)))))))
4841 ;;; Gnus MIME viewing functions
4844 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4845 "Format of the MIME buttons.
4847 Valid specifiers include:
4848 %t The MIME type
4849 %T MIME type, along with additional info
4850 %n The `name' parameter
4851 %d The description, if any
4852 %l The length of the encoded part
4853 %p The part identifier number
4854 %e Dots if the part isn't displayed
4856 General format specifiers can also be used. See Info node
4857 `(gnus)Formatting Variables'.")
4859 (defvar gnus-tmp-type)
4860 (defvar gnus-tmp-type-long)
4861 (defvar gnus-tmp-name)
4862 (defvar gnus-tmp-description)
4863 (defvar gnus-tmp-id)
4864 (defvar gnus-tmp-length)
4865 (defvar gnus-tmp-dots)
4866 (defvar gnus-tmp-info)
4867 (defvar gnus-tmp-pressed-details)
4869 (defvar gnus-mime-button-line-format-alist
4870 '((?t gnus-tmp-type ?s)
4871 (?T gnus-tmp-type-long ?s)
4872 (?n gnus-tmp-name ?s)
4873 (?d gnus-tmp-description ?s)
4874 (?p gnus-tmp-id ?s)
4875 (?l gnus-tmp-length ?d)
4876 (?e gnus-tmp-dots ?s)))
4878 (defvar gnus-mime-button-commands
4879 '((gnus-article-press-button "\r" "Toggle Display")
4880 (gnus-mime-view-part "v" "View Interactively...")
4881 (gnus-mime-view-part-as-type "t" "View As Type...")
4882 (gnus-mime-view-part-as-charset "C" "View As charset...")
4883 (gnus-mime-save-part "o" "Save...")
4884 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4885 (gnus-mime-replace-part "r" "Replace part")
4886 (gnus-mime-delete-part "d" "Delete part")
4887 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4888 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4889 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4890 (gnus-mime-view-part-externally "e" "View Externally")
4891 (gnus-mime-print-part "p" "Print")
4892 (gnus-mime-pipe-part "|" "Pipe To Command...")
4893 (gnus-mime-action-on-part "." "Take action on the part...")))
4895 (defun gnus-article-mime-part-status ()
4896 (if gnus-article-mime-handle-alist-1
4897 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4898 " (1 part)"
4899 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4900 ""))
4902 (defvar gnus-mime-button-map
4903 (let ((map (make-sparse-keymap)))
4904 (define-key map gnus-mouse-2 'gnus-article-push-button)
4905 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4906 (dolist (c gnus-mime-button-commands)
4907 (define-key map (cadr c) (car c)))
4908 map))
4910 (easy-menu-define
4911 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4912 `("MIME Part"
4913 ,@(mapcar (lambda (c)
4914 (vector (caddr c) (car c) :active t))
4915 gnus-mime-button-commands)))
4917 (defvar gnus-url-button-commands
4918 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4920 (defvar gnus-url-button-map
4921 (let ((map (make-sparse-keymap)))
4922 (dolist (c gnus-url-button-commands)
4923 (define-key map (cadr c) (car c)))
4924 map))
4926 (easy-menu-define
4927 gnus-url-button-menu gnus-url-button-map "URL button menu."
4928 `("Url Button"
4929 ,@(mapcar (lambda (c)
4930 (vector (caddr c) (car c) :active t))
4931 gnus-url-button-commands)))
4933 (defmacro gnus-bind-safe-url-regexp (&rest body)
4934 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4935 `(let ((mm-w3m-safe-url-regexp
4936 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4937 (gnus-buffer-live-p
4938 gnus-article-current-summary))
4939 (with-current-buffer gnus-article-current-summary
4940 gnus-newsgroup-name)
4941 gnus-newsgroup-name)))
4942 (if (cond ((not group)
4943 ;; Maybe we're in a mml-preview buffer
4944 ;; and no group is selected.
4946 ((stringp gnus-safe-html-newsgroups)
4947 (string-match gnus-safe-html-newsgroups group))
4948 ((consp gnus-safe-html-newsgroups)
4949 (member group gnus-safe-html-newsgroups)))
4951 mm-w3m-safe-url-regexp))))
4952 ,@body))
4954 (defun gnus-mime-button-menu (event prefix)
4955 "Construct a context-sensitive menu of MIME commands."
4956 (interactive "e\nP")
4957 (save-window-excursion
4958 (let ((pos (event-start event)))
4959 (select-window (posn-window pos))
4960 (goto-char (posn-point pos))
4961 (gnus-article-check-buffer)
4962 (popup-menu gnus-mime-button-menu nil prefix))))
4964 (defun gnus-mime-view-all-parts (&optional handles)
4965 "View all the MIME parts."
4966 (interactive)
4967 (with-current-buffer gnus-article-buffer
4968 (let ((handles (or handles gnus-article-mime-handles))
4969 (mail-parse-charset gnus-newsgroup-charset)
4970 (mail-parse-ignored-charsets
4971 (with-current-buffer gnus-summary-buffer
4972 gnus-newsgroup-ignored-charsets)))
4973 (when handles
4974 (mm-remove-parts handles)
4975 (goto-char (point-min))
4976 (or (search-forward "\n\n") (goto-char (point-max)))
4977 (let ((inhibit-read-only t))
4978 (delete-region (point) (point-max))
4979 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4981 (defun gnus-article-jump-to-part (n)
4982 "Jump to MIME part N."
4983 (interactive "P")
4984 (let ((parts (with-current-buffer gnus-article-buffer
4985 (length gnus-article-mime-handle-alist))))
4986 (when (zerop parts)
4987 (error "No such part"))
4988 (pop-to-buffer gnus-article-buffer)
4989 (or n
4990 (setq n (if (= parts 1)
4992 (read-number (format "Jump to part (1..%s): " parts)))))
4993 (unless (and (integerp n) (<= n parts) (>= n 1))
4994 (setq n
4995 (progn
4996 (gnus-message 7 "Invalid part `%s', using %s instead."
4997 n parts)
4998 parts)))
4999 (gnus-message 9 "Jumping to part %s." n)
5000 (cond ((>= gnus-auto-select-part 1)
5001 (while (and (<= n parts)
5002 (not (gnus-article-goto-part n)))
5003 (setq n (1+ n))))
5004 ((< gnus-auto-select-part 0)
5005 (while (and (>= n 1)
5006 (not (gnus-article-goto-part n)))
5007 (setq n (1- n))))
5009 (gnus-article-goto-part n)))))
5011 (defvar gnus-mime-buttonized-part-id nil
5012 "ID of a mime part that should be buttonized.
5013 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5015 (eval-when-compile
5016 (defsubst gnus-article-edit-part (handles &optional current-id)
5017 "Edit an article in order to delete a mime part.
5018 This function is exclusively used by `gnus-mime-save-part-and-strip'
5019 and `gnus-mime-delete-part', and not provided at run-time normally."
5020 (gnus-article-edit-article
5021 `(lambda ()
5022 (buffer-disable-undo)
5023 (let ((mail-parse-charset (or gnus-article-charset
5024 ',gnus-newsgroup-charset))
5025 (mail-parse-ignored-charsets
5026 (or gnus-article-ignored-charsets
5027 ',gnus-newsgroup-ignored-charsets))
5028 (mbl mml-buffer-list))
5029 (setq mml-buffer-list nil)
5030 ;; A new text must be inserted before deleting existing ones
5031 ;; at the end so as not to move existing markers of which
5032 ;; the insertion type is t.
5033 (delete-region
5034 (point-min)
5035 (prog1
5036 (goto-char (point-max))
5037 (insert-buffer-substring gnus-original-article-buffer)))
5038 (mime-to-mml ',handles)
5039 (setq gnus-article-mime-handles nil)
5040 (let ((mbl1 mml-buffer-list))
5041 (setq mml-buffer-list mbl)
5042 (set (make-local-variable 'mml-buffer-list) mbl1))
5043 (gnus-make-local-hook 'kill-buffer-hook)
5044 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5045 `(lambda (no-highlight)
5046 (let ((mail-parse-charset (or gnus-article-charset
5047 ',gnus-newsgroup-charset))
5048 (message-options message-options)
5049 (message-options-set-recipient)
5050 (mail-parse-ignored-charsets
5051 (or gnus-article-ignored-charsets
5052 ',gnus-newsgroup-ignored-charsets)))
5053 (mml-to-mime)
5054 (mml-destroy-buffers)
5055 (remove-hook 'kill-buffer-hook
5056 'mml-destroy-buffers t)
5057 (kill-local-variable 'mml-buffer-list))
5058 (gnus-summary-edit-article-done
5059 ,(or (mail-header-references gnus-current-headers) "")
5060 ,(gnus-group-read-only-p)
5061 ,gnus-summary-buffer no-highlight))
5063 ;; Force buttonizing this part.
5064 (let ((gnus-mime-buttonized-part-id current-id))
5065 (gnus-article-edit-done))
5066 (gnus-configure-windows 'article)
5067 (sit-for 0)
5068 (when (and current-id (integerp gnus-auto-select-part))
5069 (gnus-article-jump-to-part
5070 (min (max (+ current-id gnus-auto-select-part) 1)
5071 (with-current-buffer gnus-article-buffer
5072 (length gnus-article-mime-handle-alist)))))))
5074 (defun gnus-mime-replace-part (file)
5075 "Replace MIME part under point with an external body."
5076 ;; Useful if file has already been saved to disk
5077 (interactive
5078 (list
5079 (read-file-name "Replace MIME part with file: "
5080 (or mm-default-directory default-directory)
5081 nil nil)))
5082 (gnus-mime-save-part-and-strip file))
5084 (defun gnus-mime-save-part-and-strip (&optional file)
5085 "Save the MIME part under point then replace it with an external body.
5086 If FILE is given, use it for the external part."
5087 (interactive)
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)
5092 (error "\
5093 The current article has a complicated MIME structure, giving up..."))
5094 (let* ((data (get-text-property (point) 'gnus-data))
5095 (id (get-text-property (point) 'gnus-part))
5096 (handles gnus-article-mime-handles))
5097 (unless file
5098 (setq file
5099 (and data (mm-save-part data "Delete MIME part and save to: "))))
5100 (when file
5101 (with-current-buffer (mm-handle-buffer data)
5102 (erase-buffer)
5103 (insert "Content-Type: " (mm-handle-media-type data))
5104 (mml-insert-parameter-string (cdr (mm-handle-type data))
5105 '(charset))
5106 ;; Add a filename for the sake of saving the part again.
5107 (mml-insert-parameter
5108 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5109 (insert "\n")
5110 (insert "Content-ID: " (message-make-message-id) "\n")
5111 (insert "Content-Transfer-Encoding: binary\n")
5112 (insert "\n"))
5113 (setcdr data
5114 (cdr (mm-make-handle nil
5115 `("message/external-body"
5116 (access-type . "LOCAL-FILE")
5117 (name . ,file)))))
5118 ;; (set-buffer gnus-summary-buffer)
5119 (gnus-article-edit-part handles id))))
5121 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5122 ;; parts...>') but with stripping would be nice.
5124 (defun gnus-mime-delete-part ()
5125 "Delete the MIME part under point.
5126 Replace it with some information about the removed part."
5127 (interactive)
5128 (gnus-article-check-buffer)
5129 (when (gnus-group-read-only-p)
5130 (error "The current group does not support deleting of parts"))
5131 (when (mm-complicated-handles gnus-article-mime-handles)
5132 (error "\
5133 The current article has a complicated MIME structure, giving up..."))
5134 (when (or gnus-expert-user
5135 (gnus-yes-or-no-p "\
5136 Deleting parts may malfunction or destroy the article; continue? "))
5137 (let* ((data (get-text-property (point) 'gnus-data))
5138 (id (get-text-property (point) 'gnus-part))
5139 (handles gnus-article-mime-handles)
5140 (description
5141 (let ((desc (mm-handle-description data)))
5142 (when desc
5143 (mail-decode-encoded-word-string desc))))
5144 (filename (or (mm-handle-filename data) "(none)"))
5145 (type (mm-handle-media-type data)))
5146 (unless data
5147 (error "No MIME part under point"))
5148 (with-current-buffer (mm-handle-buffer data)
5149 (let ((bsize (buffer-size)))
5150 (erase-buffer)
5151 (insert
5152 (concat
5153 ",----\n"
5154 "| The following attachment has been deleted:\n"
5155 "|\n"
5156 "| Type: " type "\n"
5157 "| Filename: " filename "\n"
5158 "| Size (encoded): " (format "%s byte%s\n"
5159 bsize (if (= bsize 1)
5161 "s"))
5162 (when description
5163 (concat "| Description: " description "\n"))
5164 "`----\n"))
5165 (setcdr data
5166 (cdr (mm-make-handle
5167 nil `("text/plain" (charset . gnus-decoded)) nil nil
5168 (list "attachment")
5169 (format "Deleted attachment (%s bytes)" bsize))))))
5170 ;; (set-buffer gnus-summary-buffer)
5171 (gnus-article-edit-part handles id))))
5173 (defun gnus-mime-save-part ()
5174 "Save the MIME part under point."
5175 (interactive)
5176 (gnus-article-check-buffer)
5177 (let ((data (get-text-property (point) 'gnus-data)))
5178 (when data
5179 (mm-save-part data))))
5181 (defun gnus-mime-pipe-part (&optional cmd)
5182 "Pipe the MIME part under point to a process.
5183 Use CMD as the process."
5184 (interactive)
5185 (gnus-article-check-buffer)
5186 (let ((data (get-text-property (point) 'gnus-data)))
5187 (when data
5188 (mm-pipe-part data cmd))))
5190 (defun gnus-mime-view-part ()
5191 "Interactively choose a viewing method for the MIME part under point."
5192 (interactive)
5193 (gnus-article-check-buffer)
5194 (let ((data (get-text-property (point) 'gnus-data)))
5195 (when data
5196 (setq gnus-article-mime-handles
5197 (mm-merge-handles
5198 gnus-article-mime-handles (setq data (copy-sequence data))))
5199 (mm-interactively-view-part data))))
5201 (defun gnus-mime-view-part-as-type-internal ()
5202 (gnus-article-check-buffer)
5203 (let* ((handle (get-text-property (point) 'gnus-data))
5204 (name (or
5205 ;; Content-Type: foo/bar; name=...
5206 (mail-content-type-get (mm-handle-type handle) 'name)
5207 ;; Content-Disposition: attachment; filename=...
5208 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5209 (def-type (and name (mm-default-file-encoding name))))
5210 (or (and def-type (cons def-type 0))
5211 (and handle
5212 (equal (mm-handle-media-supertype handle) "text")
5213 '("text/plain" . 0))
5214 '("application/octet-stream" . 0))))
5216 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5217 "Choose a MIME media type, and view the part as such.
5218 If non-nil, PRED is a predicate to use during completion to limit the
5219 available media-types."
5220 (interactive)
5221 (unless mime-type
5222 (setq mime-type
5223 (let ((default (gnus-mime-view-part-as-type-internal)))
5224 (gnus-completing-read
5225 "View as MIME type"
5226 (if pred
5227 (gnus-remove-if-not pred (mailcap-mime-types))
5228 (mailcap-mime-types))
5229 nil nil nil
5230 (car default)))))
5231 (gnus-article-check-buffer)
5232 (let ((handle (get-text-property (point) 'gnus-data)))
5233 (when handle
5234 (when (equal (mm-handle-media-type handle) "message/external-body")
5235 (unless (mm-handle-cache handle)
5236 (mm-extern-cache-contents handle))
5237 (setq handle (mm-handle-cache handle)))
5238 (setq handle
5239 (mm-make-handle (mm-handle-buffer handle)
5240 (cons mime-type (cdr (mm-handle-type handle)))
5241 (mm-handle-encoding handle)
5242 (mm-handle-undisplayer handle)
5243 (mm-handle-disposition handle)
5244 (mm-handle-description handle)
5246 (mm-handle-id handle)))
5247 (setq gnus-article-mime-handles
5248 (mm-merge-handles gnus-article-mime-handles handle))
5249 (when (mm-handle-displayed-p handle)
5250 (mm-remove-part handle))
5251 (gnus-mm-display-part handle))))
5253 (defun gnus-mime-copy-part (&optional handle arg)
5254 "Put the MIME part under point into a new buffer.
5255 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5256 are decompressed."
5257 (interactive (list nil current-prefix-arg))
5258 (gnus-article-check-buffer)
5259 (unless handle
5260 (setq handle (get-text-property (point) 'gnus-data)))
5261 (when handle
5262 (let ((filename (mm-handle-filename handle))
5263 contents dont-decode charset coding-system)
5264 (mm-with-unibyte-buffer
5265 (mm-insert-part handle)
5266 (setq contents (or (condition-case nil
5267 (mm-decompress-buffer filename nil 'sig)
5268 (error
5269 (setq dont-decode t)
5270 nil))
5271 (buffer-string))))
5272 (setq filename (cond (filename (file-name-nondirectory filename))
5273 (dont-decode "*raw data*")
5274 (t "*decoded*")))
5275 (cond
5276 (dont-decode)
5277 ((not arg)
5278 (unless (setq charset (mail-content-type-get
5279 (mm-handle-type handle) 'charset))
5280 (unless (setq coding-system (mm-with-unibyte-buffer
5281 (insert contents)
5282 (mm-find-buffer-file-coding-system)))
5283 (setq charset gnus-newsgroup-charset))))
5284 ((numberp arg)
5285 (setq charset (or (cdr (assq arg
5286 gnus-summary-show-article-charset-alist))
5287 (mm-read-coding-system "Charset: ")))))
5288 (switch-to-buffer (generate-new-buffer filename))
5289 (if (or coding-system
5290 (and charset
5291 (setq coding-system (mm-charset-to-coding-system
5292 charset nil t))
5293 (not (eq coding-system 'ascii))))
5294 (progn
5295 (mm-enable-multibyte)
5296 (insert (mm-decode-coding-string contents coding-system))
5297 (setq buffer-file-coding-system
5298 (if (boundp 'last-coding-system-used)
5299 (symbol-value 'last-coding-system-used)
5300 coding-system)))
5301 (mm-disable-multibyte)
5302 (insert contents)
5303 (setq buffer-file-coding-system mm-binary-coding-system))
5304 ;; We do it this way to make `normal-mode' set the appropriate mode.
5305 (unwind-protect
5306 (progn
5307 (setq buffer-file-name (expand-file-name filename))
5308 (normal-mode))
5309 (setq buffer-file-name nil))
5310 (goto-char (point-min)))))
5312 (defun gnus-mime-print-part (&optional handle filename)
5313 "Print the MIME part under point."
5314 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5315 (gnus-article-check-buffer)
5316 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5317 (contents (and handle (mm-get-part handle)))
5318 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5319 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5320 (when contents
5321 (if printer
5322 (unwind-protect
5323 (progn
5324 (mm-save-part-to-file handle file)
5325 (call-process shell-file-name nil
5326 (generate-new-buffer " *mm*")
5328 shell-command-switch
5329 (mm-mailcap-command
5330 printer file (mm-handle-type handle))))
5331 (delete-file file))
5332 (with-temp-buffer
5333 (insert contents)
5334 (gnus-print-buffer))
5335 (ps-despool filename)))))
5337 (defun gnus-mime-inline-part (&optional handle arg)
5338 "Insert the MIME part under point into the current buffer.
5339 Compressed files like .gz and .bz2 are decompressed."
5340 (interactive (list nil current-prefix-arg))
5341 (gnus-article-check-buffer)
5342 (let* ((inhibit-read-only t)
5343 (b (point))
5344 (btn ;; position where the MIME button exists
5345 (if handle
5346 (if (eq handle (get-text-property b 'gnus-data))
5348 (article-goto-body)
5349 (or (text-property-any (point) (point-max) 'gnus-data handle)
5350 (text-property-any (point-min) (point) 'gnus-data handle)))
5351 (setq handle (get-text-property b 'gnus-data))
5353 start)
5354 (when handle
5355 (when (= b (prog1
5357 (setq start (next-single-property-change btn 'gnus-data
5358 nil (point-max))
5359 btn (previous-single-property-change start
5360 'gnus-data))))
5361 (setq b btn))
5362 (if (and (not arg) (mm-handle-undisplayer handle))
5363 (progn
5364 (setq b (copy-marker b)
5365 btn (copy-marker btn))
5366 (mm-remove-part handle))
5367 (cond
5368 ((not arg) nil)
5369 ((numberp arg)
5370 (if (mm-handle-undisplayer handle)
5371 (mm-remove-part handle)))
5372 ((mm-handle-undisplayer handle)
5373 (mm-remove-part handle)))
5374 (goto-char start)
5375 (unless (bolp)
5376 ;; This is a header button.
5377 (forward-line 1))
5378 (mm-display-inline handle))
5379 ;; Toggle the button appearance between `[button]...' and `[button]'.
5380 (when (markerp btn)
5381 (setq btn (prog1 (marker-position btn)
5382 (set-marker btn nil))))
5383 (goto-char btn)
5384 (let ((displayed-p (mm-handle-displayed-p handle)))
5385 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5386 (list displayed-p))
5387 (if (featurep 'emacs)
5388 (delete-region
5389 (point)
5390 (next-single-property-change (point) 'gnus-data nil (point-max)))
5391 (let* ((end (next-single-property-change (point) 'gnus-data))
5392 (annots (annotations-at (or end (point-max)))))
5393 (delete-region (point)
5394 (if end
5395 (if annots (1+ end) end)
5396 (point-max)))
5397 (dolist (annot annots)
5398 (set-extent-endpoints annot (point) (point)))))
5399 (setq start (point))
5400 (if (search-backward "\n\n" nil t)
5401 (progn
5402 (goto-char start)
5403 (unless (or displayed-p (eolp))
5404 ;; Add extra newline.
5405 (insert (propertize (buffer-substring (1- start) start)
5406 'gnus-undeletable t))))
5407 ;; We're in the article header.
5408 (delete-char -1)
5409 (dolist (ovl (gnus-overlays-in btn (point)))
5410 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5411 (gnus-overlay-put ovl 'face nil))
5412 (save-restriction
5413 (message-narrow-to-field)
5414 (let ((gnus-treatment-function-alist
5415 '((gnus-treat-highlight-headers
5416 gnus-article-highlight-headers))))
5417 (gnus-treat-article 'head)))))
5418 (when (markerp b)
5419 (setq b (prog1 (marker-position b)
5420 (set-marker b nil))))
5421 (goto-char b))))
5423 (defun gnus-mime-set-charset-parameters (handle charset)
5424 "Set CHARSET to parameters in HANDLE.
5425 CHARSET may either be a string or a symbol."
5426 (unless (stringp charset)
5427 (setq charset (symbol-name charset)))
5428 (if (stringp (car handle))
5429 (dolist (h (cdr handle))
5430 (gnus-mime-set-charset-parameters h charset))
5431 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5432 "message/external-body")
5433 (progn
5434 (unless (mm-handle-cache handle)
5435 (mm-extern-cache-contents handle))
5436 (mm-handle-cache handle))
5437 handle)))
5438 (param (assq 'charset (cdr type))))
5439 (if param
5440 (setcdr param charset)
5441 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5443 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5444 "Insert the MIME part under point into the current buffer using the
5445 specified charset."
5446 (interactive (list nil current-prefix-arg))
5447 (gnus-article-check-buffer)
5448 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5449 (fun (get-text-property (point) 'gnus-callback))
5450 (gnus-newsgroup-ignored-charsets 'gnus-all)
5451 charset form preferred parts)
5452 (when handle
5453 (when (prog1
5454 (and fun
5455 (setq charset
5456 (or (cdr (assq
5458 gnus-summary-show-article-charset-alist))
5459 (mm-read-coding-system "Charset: "))))
5460 (if (mm-handle-undisplayer handle)
5461 (mm-remove-part handle)))
5462 (gnus-mime-set-charset-parameters handle charset)
5463 (when (and (consp (setq form (cdr-safe fun)))
5464 (setq form (ignore-errors
5465 (assq 'gnus-mime-display-alternative form)))
5466 (setq preferred (caddr form))
5467 (progn
5468 (when (eq (car preferred) 'quote)
5469 (setq preferred (cadr preferred)))
5470 (not (equal preferred
5471 (get-text-property (point) 'gnus-data))))
5472 (setq parts (get-text-property (point) 'gnus-part))
5473 (setq parts (cdr (assq parts
5474 gnus-article-mime-handle-alist)))
5475 (equal (mm-handle-media-type parts) "multipart/alternative")
5476 (setq parts (reverse (cdr parts))))
5477 (setcar (cddr form)
5478 (list 'quote (or (cadr (member preferred parts))
5479 (car parts)))))
5480 (funcall fun handle)))))
5482 (defun gnus-mime-view-part-externally (&optional handle)
5483 "View the MIME part under point with an external viewer."
5484 (interactive)
5485 (gnus-article-check-buffer)
5486 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5487 (mm-inlined-types nil)
5488 (mail-parse-charset gnus-newsgroup-charset)
5489 (mail-parse-ignored-charsets
5490 (with-current-buffer gnus-summary-buffer
5491 gnus-newsgroup-ignored-charsets))
5492 (type (mm-handle-media-type handle))
5493 (method (mailcap-mime-info type))
5494 (mm-enable-external t))
5495 (if (not (stringp method))
5496 (gnus-mime-view-part-as-type
5497 nil (lambda (type) (stringp (mailcap-mime-info type))))
5498 (when handle
5499 (mm-display-part handle nil t)))))
5501 (defun gnus-mime-view-part-internally (&optional handle)
5502 "View the MIME part under point with an internal viewer.
5503 If no internal viewer is available, use an external viewer."
5504 (interactive)
5505 (gnus-article-check-buffer)
5506 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5507 (mm-inlined-types '(".*"))
5508 (mm-inline-large-images t)
5509 (mail-parse-charset gnus-newsgroup-charset)
5510 (mail-parse-ignored-charsets
5511 (with-current-buffer gnus-summary-buffer
5512 gnus-newsgroup-ignored-charsets))
5513 (inhibit-read-only t))
5514 (if (not (mm-inlinable-p handle))
5515 (gnus-mime-view-part-as-type
5516 nil (lambda (type) (mm-inlinable-p handle type)))
5517 (when handle
5518 (gnus-bind-safe-url-regexp
5519 (mm-display-part handle nil t))))))
5521 (defun gnus-mime-action-on-part (&optional action)
5522 "Do something with the MIME attachment at \(point\)."
5523 (interactive
5524 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5525 (gnus-article-check-buffer)
5526 (let ((action-pair (assoc action gnus-mime-action-alist)))
5527 (if action-pair
5528 (funcall (cdr action-pair)))))
5530 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5531 "Call FUNCTION on MIME part N.
5532 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5533 If INTERACTIVE, call FUNCTION interactively."
5534 (let (window frame)
5535 ;; Check whether the article is displayed.
5536 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5537 (setq window (get-buffer-window gnus-article-buffer t))
5538 (frame-visible-p (setq frame (window-frame window))))
5539 (error "No article is displayed"))
5540 (with-current-buffer gnus-article-buffer
5541 ;; Check whether the article displays the right contents.
5542 (unless (with-current-buffer gnus-summary-buffer
5543 (eq gnus-current-article (gnus-summary-article-number)))
5544 (error "You should select the right article first"))
5545 (if n
5546 (setq n (prefix-numeric-value n))
5547 (let ((pt (point)))
5548 (setq n (or (get-text-property pt 'gnus-part)
5549 (and (not (bobp))
5550 (get-text-property (1- pt) 'gnus-part))
5551 (get-text-property (prog2
5552 (forward-line 1)
5553 (point)
5554 (goto-char pt))
5555 'gnus-part)
5556 (get-text-property
5557 (or (and (setq pt (previous-single-property-change
5558 pt 'gnus-part))
5559 (1- pt))
5560 (next-single-property-change (point) 'gnus-part)
5561 (point))
5562 'gnus-part)
5563 1))))
5564 ;; Check whether the specified part exists.
5565 (when (> n (length gnus-article-mime-handle-alist))
5566 (error "No such part")))
5567 (unless
5568 (progn
5569 ;; To select the window is needed so that the cursor
5570 ;; might be visible on the MIME button.
5571 (select-window (prog1
5572 window
5573 (setq window (selected-window))
5574 ;; Article may be displayed in the other frame.
5575 (gnus-select-frame-set-input-focus
5576 (prog1
5577 frame
5578 (setq frame (selected-frame))))))
5579 (when (gnus-article-goto-part n)
5580 ;; We point the cursor and the arrow at the MIME button
5581 ;; when the `function' prompt the user for something.
5582 (unless (and (pos-visible-in-window-p)
5583 (> (count-lines (point) (window-end))
5584 (/ (1- (window-height)) 3)))
5585 (recenter (/ (1- (window-height)) 3)))
5586 (let ((cursor-in-non-selected-windows t)
5587 (overlay-arrow-string "=>")
5588 (overlay-arrow-position (point-marker)))
5589 (unwind-protect
5590 (cond
5591 ((and no-handle interactive)
5592 (call-interactively function))
5593 (no-handle
5594 (funcall function))
5595 (interactive
5596 (call-interactively
5597 function (get-text-property (point) 'gnus-data)))
5599 (funcall function
5600 (get-text-property (point) 'gnus-data))))
5601 (set-marker overlay-arrow-position nil)
5602 (unless gnus-auto-select-part
5603 (gnus-select-frame-set-input-focus frame)
5604 (select-window window))))
5606 (if gnus-inhibit-mime-unbuttonizing
5607 ;; This is the default though the program shouldn't reach here.
5608 (error "No such part")
5609 ;; The part which doesn't have the MIME button is selected.
5610 ;; So, we display all the buttons and redo it.
5611 (let ((gnus-inhibit-mime-unbuttonizing t))
5612 (gnus-summary-show-article)
5613 (gnus-article-part-wrapper n function no-handle))))))
5615 (defun gnus-article-pipe-part (n)
5616 "Pipe MIME part N, which is the numerical prefix."
5617 (interactive "P")
5618 (gnus-article-part-wrapper n 'mm-pipe-part))
5620 (defun gnus-article-save-part (n)
5621 "Save MIME part N, which is the numerical prefix."
5622 (interactive "P")
5623 (gnus-article-part-wrapper n 'mm-save-part))
5625 (defun gnus-article-interactively-view-part (n)
5626 "View MIME part N interactively, which is the numerical prefix."
5627 (interactive "P")
5628 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5630 (defun gnus-article-copy-part (n)
5631 "Copy MIME part N, which is the numerical prefix."
5632 (interactive "P")
5633 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5635 (defun gnus-article-view-part-as-charset (n)
5636 "View MIME part N using a specified charset.
5637 N is the numerical prefix."
5638 (interactive "P")
5639 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5641 (defun gnus-article-view-part-externally (n)
5642 "View MIME part N externally, which is the numerical prefix."
5643 (interactive "P")
5644 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5646 (defun gnus-article-inline-part (n)
5647 "Inline MIME part N, which is the numerical prefix."
5648 (interactive "P")
5649 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5651 (defun gnus-article-save-part-and-strip (n)
5652 "Save MIME part N and replace it with an external body.
5653 N is the numerical prefix."
5654 (interactive "P")
5655 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5657 (defun gnus-article-replace-part (n)
5658 "Replace MIME part N with an external body.
5659 N is the numerical prefix."
5660 (interactive "P")
5661 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5663 (defun gnus-article-delete-part (n)
5664 "Delete MIME part N and add some information about the removed part.
5665 N is the numerical prefix."
5666 (interactive "P")
5667 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5669 (defun gnus-article-view-part-as-type (n)
5670 "Choose a MIME media type, and view part N as such.
5671 N is the numerical prefix."
5672 (interactive "P")
5673 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5675 (defun gnus-article-mime-match-handle-first (condition)
5676 (if condition
5677 (let (n)
5678 (dolist (ihandle gnus-article-mime-handle-alist)
5679 (if (and (cond
5680 ((functionp condition)
5681 (funcall condition (cdr ihandle)))
5682 ((eq condition 'undisplayed)
5683 (not (or (mm-handle-undisplayer (cdr ihandle))
5684 (equal (mm-handle-media-type (cdr ihandle))
5685 "multipart/alternative"))))
5686 ((eq condition 'undisplayed-alternative)
5687 (not (mm-handle-undisplayer (cdr ihandle))))
5688 (t t))
5689 (gnus-article-goto-part (car ihandle))
5690 (or (not n) (< (car ihandle) n)))
5691 (setq n (car ihandle))))
5692 (or n 1))
5695 (defun gnus-article-view-part (&optional n)
5696 "View MIME part N, which is the numerical prefix.
5697 If the part is already shown, hide the part. If N is nil, view
5698 all parts."
5699 (interactive "P")
5700 (with-current-buffer gnus-article-buffer
5701 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5702 gnus-article-mime-match-handle-function)))
5703 (when (> n (length gnus-article-mime-handle-alist))
5704 (error "No such part"))
5705 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5706 (when (gnus-article-goto-part n)
5707 (if (equal (car handle) "multipart/alternative")
5708 (progn
5709 (beginning-of-line) ;; Make it toggle subparts
5710 (gnus-article-press-button))
5711 (when (eq (gnus-mm-display-part handle) 'internal)
5712 (gnus-set-window-start)))))))
5714 (defsubst gnus-article-mime-total-parts ()
5715 (if (bufferp (car gnus-article-mime-handles))
5716 1 ;; single part
5717 (1- (length gnus-article-mime-handles))))
5719 (defun gnus-mm-display-part (handle)
5720 "Display HANDLE and fix MIME button."
5721 (let ((id (get-text-property (point) 'gnus-part))
5722 (point (point))
5723 (inhibit-read-only t)
5724 (window (selected-window))
5725 (mail-parse-charset gnus-newsgroup-charset)
5726 (mail-parse-ignored-charsets
5727 (if (gnus-buffer-live-p gnus-summary-buffer)
5728 (with-current-buffer gnus-summary-buffer
5729 gnus-newsgroup-ignored-charsets)
5730 nil))
5731 start retval)
5732 (unwind-protect
5733 (progn
5734 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5735 (when win
5736 (select-window win)
5737 (goto-char point)))
5738 (setq start (next-single-property-change point 'gnus-data
5739 nil (point-max))
5740 point (previous-single-property-change start 'gnus-data))
5741 (if (mm-handle-displayed-p handle)
5742 ;; This will remove the part.
5743 (setq point (copy-marker point)
5744 retval (mm-display-part handle))
5745 (let ((part (or (and (mm-inlinable-p handle)
5746 (mm-inlined-p handle)
5748 (with-temp-buffer
5749 (gnus-bind-safe-url-regexp
5750 (setq retval (mm-display-part handle)))
5751 (unless (zerop (buffer-size))
5752 (buffer-string))))))
5753 (goto-char start)
5754 (unless (bolp)
5755 ;; This is a header button.
5756 (forward-line 1))
5757 (cond ((stringp part)
5758 (save-restriction
5759 (narrow-to-region (point)
5760 (progn
5761 (insert part)
5762 (unless (bolp) (insert "\n"))
5763 (point)))
5764 (gnus-treat-article nil id
5765 (gnus-article-mime-total-parts)
5766 (mm-handle-media-type handle))
5767 (mm-handle-set-undisplayer
5768 handle
5769 `(lambda ()
5770 (let ((inhibit-read-only t))
5771 (delete-region ,(copy-marker (point-min) t)
5772 ,(point-max-marker)))))))
5773 (part
5774 (mm-display-inline handle))))))
5775 (when (markerp point)
5776 (setq point (prog1 (marker-position point)
5777 (set-marker point nil))))
5778 (goto-char point)
5779 ;; Toggle the button appearance between `[button]...' and `[button]'.
5780 (let ((displayed-p (mm-handle-displayed-p handle)))
5781 (gnus-insert-mime-button handle id (list displayed-p))
5782 (if (featurep 'emacs)
5783 (delete-region
5784 (point)
5785 (next-single-property-change (point) 'gnus-data nil (point-max)))
5786 (let* ((end (next-single-property-change (point) 'gnus-data))
5787 (annots (annotations-at (or end (point-max)))))
5788 (delete-region (point)
5789 (if end
5790 (if annots (1+ end) end)
5791 (point-max)))
5792 (dolist (annot annots)
5793 (set-extent-endpoints annot (point) (point)))))
5794 (setq start (point))
5795 (if (search-backward "\n\n" nil t)
5796 (progn
5797 (goto-char start)
5798 (unless (or displayed-p (eolp))
5799 ;; Add extra newline.
5800 (insert (propertize (buffer-substring (1- start) start)
5801 'gnus-undeletable t))))
5802 ;; We're in the article header.
5803 (delete-char -1)
5804 (dolist (ovl (gnus-overlays-in point (point)))
5805 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5806 (gnus-overlay-put ovl 'face nil))
5807 (save-restriction
5808 (message-narrow-to-field)
5809 (let ((gnus-treatment-function-alist
5810 '((gnus-treat-highlight-headers
5811 gnus-article-highlight-headers))))
5812 (gnus-treat-article 'head)))))
5813 (goto-char point)
5814 (if (window-live-p window)
5815 (select-window window)))
5816 retval))
5818 (defun gnus-article-goto-part (n)
5819 "Go to MIME part N."
5820 (when gnus-break-pages
5821 (widen))
5822 (article-goto-body)
5823 (prog1
5824 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5825 ;; There may be header buttons.
5826 (text-property-any (point-min) (point) 'gnus-part n)))
5827 part handle end next handles)
5828 (when start
5829 (goto-char start)
5830 (if (setq handle (get-text-property start 'gnus-data))
5831 start
5832 ;; Go to the displayed subpart, assuming this is
5833 ;; multipart/alternative.
5834 (setq part start
5835 end (point-at-eol))
5836 (while (and (not handle)
5837 part
5838 (< part end)
5839 (setq next (text-property-not-all part end
5840 'gnus-data nil)))
5841 (setq part next
5842 handle (get-text-property part 'gnus-data))
5843 (push (cons handle part) handles)
5844 (unless (mm-handle-displayed-p handle)
5845 (setq handle nil
5846 part (text-property-any part end 'gnus-data nil))))
5847 (unless handle
5848 ;; No subpart is displayed, so we find preferred one.
5849 (setq part
5850 (cdr (assq (mm-preferred-alternative
5851 (nreverse (mapcar 'car handles)))
5852 handles))))
5853 (if part
5854 (goto-char (1+ part))
5855 start))))
5856 (when gnus-break-pages
5857 (gnus-narrow-to-page))))
5859 (defun gnus-insert-mime-button (handle id &optional displayed)
5860 (let ((gnus-tmp-name
5861 (or (mm-handle-filename handle)
5862 (mail-content-type-get (mm-handle-type handle) 'url)
5863 ""))
5864 (gnus-tmp-id id)
5865 (gnus-tmp-type (mm-handle-media-type handle))
5866 (gnus-tmp-description (or (mm-handle-description handle) ""))
5867 (gnus-tmp-dots
5868 (if (if displayed (car displayed)
5869 (mm-handle-displayed-p handle))
5870 "" "..."))
5871 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5872 (buffer-size)))
5873 gnus-tmp-type-long b e)
5874 (when (string-match ".*/" gnus-tmp-name)
5875 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5876 (setq gnus-tmp-type-long (concat gnus-tmp-type
5877 (and (not (equal gnus-tmp-name ""))
5878 (concat "; " gnus-tmp-name))))
5879 (unless (equal gnus-tmp-description "")
5880 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5881 (setq b (point))
5882 (gnus-eval-format
5883 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5884 `(keymap ,gnus-mime-button-map
5885 gnus-callback gnus-mm-display-part
5886 gnus-part ,gnus-tmp-id
5887 article-type annotation
5888 gnus-data ,handle
5889 rear-nonsticky t))
5890 (setq e (if (bolp)
5891 ;; Exclude a newline.
5892 (1- (point))
5893 (point)))
5894 (when gnus-article-button-face
5895 (gnus-overlay-put (gnus-make-overlay b e nil t)
5896 'face gnus-article-button-face))
5897 (widget-convert-button
5898 'link b e
5899 :mime-handle handle
5900 :action 'gnus-widget-press-button
5901 :button-keymap gnus-mime-button-map
5902 :help-echo
5903 (lambda (widget)
5904 ;; Needed to properly clear the message due to a bug in
5905 ;; wid-edit (XEmacs only).
5906 (if (boundp 'help-echo-owns-message)
5907 (setq help-echo-owns-message t))
5908 (format
5909 "%S: %s the MIME part; %S: more options"
5910 (aref gnus-mouse-2 0)
5911 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5912 "hide" "show")
5913 (aref gnus-down-mouse-3 0))))))
5915 (defun gnus-widget-press-button (elems _el)
5916 (goto-char (widget-get elems :from))
5917 (gnus-article-press-button))
5919 (defvar gnus-displaying-mime nil)
5921 (defun gnus-display-mime (&optional ihandles)
5922 "Display the MIME parts."
5923 (save-excursion
5924 (save-selected-window
5925 (let ((window (get-buffer-window gnus-article-buffer))
5926 (point (point)))
5927 (when window
5928 (select-window window)
5929 ;; We have to do this since selecting the window
5930 ;; may change the point. So we set the window point.
5931 (set-window-point window point)))
5932 (let ((handles ihandles)
5933 (inhibit-read-only t))
5934 (cond (handles)
5935 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5936 (when gnus-article-emulate-mime
5937 (mm-uu-dissect-text-parts handles)))
5938 (gnus-article-emulate-mime
5939 (setq handles (mm-uu-dissect))))
5940 (when (and (not ihandles)
5941 (not gnus-displaying-mime))
5942 ;; Top-level call; we clean up.
5943 (when gnus-article-mime-handles
5944 (mm-destroy-parts gnus-article-mime-handles)
5945 (setq gnus-article-mime-handle-alist nil));; A trick.
5946 (setq gnus-article-mime-handles handles)
5947 ;; We allow users to glean info from the handles.
5948 (when gnus-article-mime-part-function
5949 (gnus-mime-part-function handles)))
5950 (if (and handles
5951 (or (not (stringp (car handles)))
5952 (cdr handles)))
5953 (progn
5954 (when (and (not ihandles)
5955 (not gnus-displaying-mime))
5956 ;; Clean up for mime parts.
5957 (article-goto-body)
5958 (delete-region (point) (point-max)))
5959 (let ((gnus-displaying-mime t))
5960 (gnus-mime-display-part handles)))
5961 (save-restriction
5962 (article-goto-body)
5963 (narrow-to-region (point) (point-max))
5964 (gnus-treat-article nil 1 1 "text/plain")
5965 (widen)))
5966 (unless ihandles
5967 ;; Highlight the headers.
5968 (save-excursion
5969 (save-restriction
5970 (article-goto-body)
5971 (narrow-to-region (point-min) (point))
5972 (gnus-article-save-original-date
5973 (gnus-treat-article 'head)))))))
5974 ;; Cope with broken MIME messages.
5975 (goto-char (point-max))
5976 (unless (bolp)
5977 (insert "\n"))))
5979 (defcustom gnus-mime-display-multipart-as-mixed nil
5980 "Display \"multipart\" parts as \"multipart/mixed\".
5982 If t, it overrides nil values of
5983 `gnus-mime-display-multipart-alternative-as-mixed' and
5984 `gnus-mime-display-multipart-related-as-mixed'."
5985 :group 'gnus-article-mime
5986 :type 'boolean)
5988 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5989 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5990 :version "22.1"
5991 :group 'gnus-article-mime
5992 :type 'boolean)
5994 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5995 "Display \"multipart/related\" parts as \"multipart/mixed\".
5997 If displaying \"text/html\" is discouraged \(see
5998 `mm-discouraged-alternatives'\) images or other material inside a
5999 \"multipart/related\" part might be overlooked when this variable is nil."
6000 :version "22.1"
6001 :group 'gnus-article-mime
6002 :type 'boolean)
6004 (defcustom gnus-mime-display-attachment-buttons-in-header t
6005 "Add attachment buttons in the end of the header of an article.
6006 Since MIME attachments tend to be put at the end of an article, we may
6007 overlook them if there is a huge body. This option offers you a copy
6008 of all non-inlinable MIME parts as buttons shown in front of an article.
6009 If nil, don't show those extra buttons."
6010 :version "25.1"
6011 :group 'gnus-article-mime
6012 :type 'boolean)
6014 (defun gnus-mime-display-part (handle)
6015 (cond
6016 ;; Maybe a broken MIME message.
6017 ((null handle))
6018 ;; Single part.
6019 ((not (stringp (car handle)))
6020 (gnus-mime-display-single handle))
6021 ;; User-defined multipart
6022 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6023 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6024 handle))
6025 ;; multipart/alternative
6026 ((and (equal (car handle) "multipart/alternative")
6027 (not (or gnus-mime-display-multipart-as-mixed
6028 gnus-mime-display-multipart-alternative-as-mixed)))
6029 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6030 (push (cons id handle) gnus-article-mime-handle-alist)
6031 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6032 ;; multipart/related
6033 ((and (equal (car handle) "multipart/related")
6034 (not (or gnus-mime-display-multipart-as-mixed
6035 gnus-mime-display-multipart-related-as-mixed)))
6036 (gnus-mime-display-part (cadr handle)))
6037 ((equal (car handle) "multipart/signed")
6038 (gnus-add-wash-type 'signed)
6039 (gnus-mime-display-security handle))
6040 ((equal (car handle) "multipart/encrypted")
6041 (gnus-add-wash-type 'encrypted)
6042 (gnus-mime-display-security handle))
6043 ;; Other multiparts are handled like multipart/mixed.
6045 (gnus-mime-display-mixed (cdr handle)))))
6047 (defun gnus-mime-part-function (handles)
6048 (if (stringp (car handles))
6049 (mapcar 'gnus-mime-part-function (cdr handles))
6050 (funcall gnus-article-mime-part-function handles)))
6052 (defun gnus-mime-display-mixed (handles)
6053 (mapcar 'gnus-mime-display-part handles))
6055 (defun gnus-mime-display-single (handle)
6056 (let ((type (mm-handle-media-type handle))
6057 (ignored gnus-ignored-mime-types)
6058 (not-attachment t)
6059 display text)
6060 (catch 'ignored
6061 (progn
6062 (while ignored
6063 (when (string-match (pop ignored) type)
6064 (throw 'ignored nil)))
6065 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6066 (with-current-buffer gnus-summary-buffer
6067 gnus-inhibit-images)
6068 gnus-inhibit-images)
6069 (string-match "\\`image/" type)))
6070 (setq not-attachment
6071 (and (not (mm-inline-override-p handle))
6072 (or (not (mm-handle-disposition handle))
6073 (equal (car (mm-handle-disposition handle))
6074 "inline")
6075 (mm-attachment-override-p handle))))
6076 (mm-automatic-display-p handle)
6077 (or (and
6078 (mm-inlinable-p handle)
6079 (mm-inlined-p handle))
6080 (mm-automatic-external-display-p type)))
6081 (setq display t)
6082 (when (equal (mm-handle-media-supertype handle) "text")
6083 (setq text t)))
6084 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6085 beg)
6086 (unless id
6087 (setq id (1+ (length gnus-article-mime-handle-alist)))
6088 (push (cons id handle) gnus-article-mime-handle-alist))
6089 (when (and display
6090 (equal (mm-handle-media-supertype handle) "message"))
6091 (insert-char
6093 (cond ((not (bolp)) 2)
6094 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6095 (t 1))))
6096 (when (or (not display)
6097 (not (gnus-unbuttonized-mime-type-p type))
6098 (eq id gnus-mime-buttonized-part-id))
6099 (gnus-insert-mime-button
6100 handle id (list (or display (and not-attachment text)))))
6101 (setq beg (point))
6102 (cond
6103 (display
6104 (let ((mail-parse-charset gnus-newsgroup-charset)
6105 (mail-parse-ignored-charsets
6106 (save-excursion (condition-case ()
6107 (set-buffer gnus-summary-buffer)
6108 (error))
6109 gnus-newsgroup-ignored-charsets)))
6110 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6111 ((and text not-attachment)
6112 (mm-display-inline handle)))
6113 (goto-char (point-max))
6114 (if (string-match "\\`image/" type)
6115 (gnus-article-insert-newline)
6116 (if (prog1
6117 (= (skip-chars-backward "\n") -1)
6118 (unless (eobp) (forward-char 1)))
6119 (gnus-article-insert-newline)
6120 (put-text-property (point) (point-max) 'gnus-undeletable t))
6121 (goto-char (point-max)))
6122 ;; Do highlighting.
6123 (save-excursion
6124 (save-restriction
6125 (narrow-to-region beg (point))
6126 (if (eq handle gnus-article-mime-handles)
6127 ;; The format=flowed case.
6128 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6129 ;; Don't count signature parts that are never displayed.
6130 ;; The part number should be re-calculated supposing this
6131 ;; might be a message/rfc822 part.
6132 (let (handles)
6133 (dolist (part gnus-article-mime-handles)
6134 (unless (or (stringp part)
6135 (equal (car (mm-handle-type part))
6136 "application/pgp-signature"))
6137 (push part handles)))
6138 (gnus-treat-article
6139 nil (length (memq handle handles)) (length handles)
6140 (mm-handle-media-type handle)))))))))))
6142 (defun gnus-unbuttonized-mime-type-p (type)
6143 "Say whether TYPE is to be unbuttonized."
6144 (unless gnus-inhibit-mime-unbuttonizing
6145 (when (catch 'found
6146 (let ((types gnus-unbuttonized-mime-types))
6147 (while types
6148 (when (string-match (pop types) type)
6149 (throw 'found t)))))
6150 (not (catch 'found
6151 (let ((types gnus-buttonized-mime-types))
6152 (while types
6153 (when (string-match (pop types) type)
6154 (throw 'found t)))))))))
6156 (defun gnus-article-insert-newline ()
6157 "Insert a newline, but mark it as undeletable."
6158 (gnus-put-text-property
6159 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6161 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6162 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6163 (ihandles handles)
6164 (point (point))
6165 handle (inhibit-read-only t) from begend not-pref)
6166 (save-window-excursion
6167 (save-restriction
6168 (when ibegend
6169 (narrow-to-region (car ibegend)
6170 (or (cdr ibegend)
6171 (progn
6172 (goto-char (car ibegend))
6173 (forward-line 2)
6174 (point))))
6175 (delete-region (point-min) (point-max))
6176 (mm-remove-parts handles))
6177 (setq begend (list (point-marker)))
6178 ;; Do the toggle.
6179 (unless (setq not-pref (cadr (member preferred ihandles)))
6180 (setq not-pref (car ihandles)))
6181 (when (or ibegend
6182 (not preferred)
6183 (not (gnus-unbuttonized-mime-type-p
6184 "multipart/alternative")))
6185 (gnus-add-text-properties
6186 (setq from (point))
6187 (progn
6188 (insert (format "%d. " id))
6189 (point))
6190 `(gnus-callback
6191 (lambda (handles)
6192 (unless ,(not ibegend)
6193 (setq gnus-article-mime-handle-alist
6194 ',gnus-article-mime-handle-alist))
6195 (gnus-mime-display-alternative
6196 ',ihandles ',not-pref ',begend ,id))
6197 keymap ,gnus-mime-button-map
6198 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6199 face ,gnus-article-button-face
6200 gnus-part ,id
6201 article-type multipart
6202 rear-nonsticky t))
6203 (widget-convert-button 'link from (point)
6204 :action 'gnus-widget-press-button
6205 :button-keymap gnus-widget-button-keymap)
6206 ;; Do the handles
6207 (while (setq handle (pop handles))
6208 (gnus-add-text-properties
6209 (setq from (point))
6210 (progn
6211 (insert (format "(%c) %-18s"
6212 (if (equal handle preferred) ?* ? )
6213 (mm-handle-media-type handle)))
6214 (point))
6215 `(gnus-callback
6216 (lambda (handles)
6217 (unless ,(not ibegend)
6218 (setq gnus-article-mime-handle-alist
6219 ',gnus-article-mime-handle-alist))
6220 (gnus-mime-display-alternative
6221 ',ihandles ',handle ',begend ,id))
6222 keymap ,gnus-mime-button-map
6223 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6224 face ,gnus-article-button-face
6225 gnus-part ,id
6226 gnus-data ,handle
6227 rear-nonsticky t))
6228 (widget-convert-button 'link from (point)
6229 :action 'gnus-widget-press-button
6230 :button-keymap gnus-widget-button-keymap)
6231 (insert " "))
6232 (insert "\n\n"))
6233 (when preferred
6234 (if (stringp (car preferred))
6235 (gnus-display-mime preferred)
6236 (let ((mail-parse-charset gnus-newsgroup-charset)
6237 (mail-parse-ignored-charsets
6238 (with-current-buffer gnus-summary-buffer
6239 gnus-newsgroup-ignored-charsets)))
6240 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6241 ;; Do highlighting.
6242 (save-excursion
6243 (save-restriction
6244 (narrow-to-region (car begend) (point-max))
6245 (gnus-treat-article
6246 nil (length gnus-article-mime-handle-alist)
6247 (gnus-article-mime-total-parts)
6248 (mm-handle-media-type preferred))))))
6249 (goto-char (point-max))
6250 (setcdr begend (point-marker)))))
6251 (when ibegend
6252 (goto-char point)))
6253 ;; Redraw attachment buttons in the header.
6254 (when gnus-mime-display-attachment-buttons-in-header
6255 (gnus-mime-buttonize-attachments-in-header)))
6257 (defconst gnus-article-wash-status-strings
6258 (let ((alist '((cite "c" "Possible hidden citation text"
6259 " " "All citation text visible")
6260 (headers "h" "Hidden headers"
6261 " " "All headers visible.")
6262 (pgp "p" "Encrypted or signed message status hidden"
6263 " " "No hidden encryption nor digital signature status")
6264 (signature "s" "Signature has been hidden"
6265 " " "Signature is visible")
6266 (overstrike "o" "Overstrike (^H) characters applied"
6267 " " "No overstrike characters applied")
6268 (emphasis "e" "/*_Emphasis_*/ characters applied"
6269 " " "No /*_emphasis_*/ characters applied")))
6270 result)
6271 (dolist (entry alist result)
6272 (let ((key (nth 0 entry))
6273 (on (copy-sequence (nth 1 entry)))
6274 (on-help (nth 2 entry))
6275 (off (copy-sequence (nth 3 entry)))
6276 (off-help (nth 4 entry)))
6277 (put-text-property 0 1 'help-echo on-help on)
6278 (put-text-property 0 1 'help-echo off-help off)
6279 (push (list key on off) result))))
6280 "Alist of strings describing wash status in the mode line.
6281 Each entry has the form (KEY ON OF), where the KEY is a symbol
6282 representing the particular washing function, ON is the string to use
6283 in the article mode line when the washing function is active, and OFF
6284 is the string to use when it is inactive.")
6286 (defun gnus-article-wash-status-entry (key value)
6287 (let ((entry (assoc key gnus-article-wash-status-strings)))
6288 (if value (nth 1 entry) (nth 2 entry))))
6290 (defun gnus-article-wash-status ()
6291 "Return a string which display status of article washing."
6292 (with-current-buffer gnus-article-buffer
6293 (let ((cite (memq 'cite gnus-article-wash-types))
6294 (headers (memq 'headers gnus-article-wash-types))
6295 (boring (memq 'boring-headers gnus-article-wash-types))
6296 (pgp (memq 'pgp gnus-article-wash-types))
6297 (pem (memq 'pem gnus-article-wash-types))
6298 (signed (memq 'signed gnus-article-wash-types))
6299 (encrypted (memq 'encrypted gnus-article-wash-types))
6300 (signature (memq 'signature gnus-article-wash-types))
6301 (overstrike (memq 'overstrike gnus-article-wash-types))
6302 (emphasis (memq 'emphasis gnus-article-wash-types)))
6303 (concat
6304 (gnus-article-wash-status-entry 'cite cite)
6305 (gnus-article-wash-status-entry 'headers (or headers boring))
6306 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6307 (gnus-article-wash-status-entry 'signature signature)
6308 (gnus-article-wash-status-entry 'overstrike overstrike)
6309 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6311 (defun gnus-add-wash-type (type)
6312 "Add a washing of TYPE to the current status."
6313 (add-to-list 'gnus-article-wash-types type))
6315 (defun gnus-delete-wash-type (type)
6316 "Add a washing of TYPE to the current status."
6317 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6319 (defun gnus-add-image (category image)
6320 "Add IMAGE of CATEGORY to the list of displayed images."
6321 (let ((entry (assq category gnus-article-image-alist)))
6322 (unless entry
6323 (setq entry (list category))
6324 (push entry gnus-article-image-alist))
6325 (nconc entry (list image))))
6327 (defun gnus-delete-images (category)
6328 "Delete all images in CATEGORY."
6329 (let ((entry (assq category gnus-article-image-alist)))
6330 (dolist (image (cdr entry))
6331 (gnus-remove-image image category))
6332 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6333 (gnus-delete-wash-type category)))
6335 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6337 (defun gnus-article-maybe-hide-headers ()
6338 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6339 Provided for backwards compatibility."
6340 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6341 (not (with-current-buffer gnus-summary-buffer
6342 gnus-have-all-headers)))
6343 (not gnus-inhibit-hiding))
6344 (gnus-article-hide-headers)))
6346 (declare-function shr-put-image "shr" (data alt &optional flags))
6348 (defun gnus-shr-put-image (data alt &optional flags)
6349 "Put image DATA with a string ALT. Enable image to be deleted."
6350 (let ((image (if flags
6351 (shr-put-image data (propertize (or alt "*")
6352 'gnus-image-category 'shr)
6353 flags)
6354 ;; Old `shr-put-image' doesn't take the optional `flags'
6355 ;; argument.
6356 (shr-put-image data (propertize (or alt "*")
6357 'gnus-image-category 'shr)))))
6358 (when image
6359 (gnus-add-image 'shr image))))
6361 (defun gnus-article-mime-handles (&optional alist id all)
6362 (if alist
6363 (let ((i 1) newid flat)
6364 (dolist (handle alist flat)
6365 (setq newid (append id (list i))
6366 i (1+ i))
6367 (if (stringp (car handle))
6368 (setq flat (nconc flat (gnus-article-mime-handles
6369 (cdr handle) newid all)))
6370 (delq (rassq handle all) all)
6371 (setq flat (nconc flat (list (cons newid handle)))))))
6372 (let ((flat (list nil)))
6373 ;; Assume that elements of `gnus-article-mime-handle-alist'
6374 ;; are in the decreasing order, but unnumbered subsidiaries
6375 ;; in each element are in the increasing order.
6376 (dolist (handle (reverse gnus-article-mime-handle-alist))
6377 (if (stringp (cadr handle))
6378 (setq flat (nconc flat (gnus-article-mime-handles
6379 (cddr handle) (list (car handle)) flat)))
6380 (delq (rassq (cdr handle) flat) flat)
6381 (setq flat (nconc flat (list (cons (list (car handle))
6382 (cdr handle)))))))
6383 (setq flat (cdr flat))
6384 (mapc (lambda (handle)
6385 (if (cdar handle)
6386 ;; This is a hidden (i.e. unnumbered) handle.
6387 (progn
6388 (setcar handle
6389 (1+ (caar gnus-article-mime-handle-alist)))
6390 (push handle gnus-article-mime-handle-alist))
6391 (setcar handle (caar handle))))
6392 flat)
6393 flat)))
6395 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6396 "Show attachments as buttons in the end of the header of an article.
6397 This function toggles the display when called interactively. Note that
6398 buttons to be added to the header are only the ones that aren't inlined
6399 in the body. Use `gnus-header-face-alist' to highlight buttons."
6400 (interactive (list t))
6401 (gnus-with-article-buffer
6402 (let ((case-fold-search t) buttons handle type st)
6403 (save-excursion
6404 (save-restriction
6405 (widen)
6406 (article-narrow-to-head)
6407 ;; Header buttons exist?
6408 (while (and (not buttons)
6409 (re-search-forward "^attachments?:[\n ]+" nil t))
6410 (when (get-char-property (match-end 0)
6411 'gnus-button-attachment-extra)
6412 (setq buttons (match-beginning 0))))
6413 (widen)
6414 (when buttons
6415 ;; Delete header buttons.
6416 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6417 (match-beginning 0)
6418 (point-max))))
6419 (unless (and interactive buttons)
6420 ;; Find buttons.
6421 (setq buttons nil)
6422 (dolist (button (gnus-article-mime-handles))
6423 (setq handle (cdr button)
6424 type (mm-handle-media-type handle))
6425 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6426 (with-current-buffer gnus-summary-buffer
6427 gnus-inhibit-images)
6428 gnus-inhibit-images)
6429 (string-match "\\`image/" type))
6430 (mm-inline-override-p handle)
6431 (and (mm-handle-disposition handle)
6432 (not (equal (car (mm-handle-disposition handle))
6433 "inline"))
6434 (not (mm-attachment-override-p handle)))
6435 (not (mm-automatic-display-p handle))
6436 (not (or (and (mm-inlinable-p handle)
6437 (mm-inlined-p handle))
6438 (mm-automatic-external-display-p type))))
6439 (push button buttons)))
6440 (when buttons
6441 ;; Add header buttons.
6442 (article-goto-body)
6443 (forward-line -1)
6444 (narrow-to-region (point) (point))
6445 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6446 (dolist (button (nreverse buttons))
6447 (setq st (point))
6448 (insert " ")
6449 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6450 (gnus-insert-mime-button handle (car button))
6451 (skip-chars-backward "\t\n ")
6452 (delete-region (point) (point-max))
6453 (when (> (current-column) (window-width))
6454 (goto-char st)
6455 (insert "\n")
6456 (end-of-line)))
6457 (insert "\n")
6458 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6459 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6460 (gnus-overlay-put ovl 'face nil))
6461 (let ((gnus-treatment-function-alist
6462 '((gnus-treat-highlight-headers
6463 gnus-article-highlight-headers))))
6464 (gnus-treat-article 'head)))))))))
6466 ;;; Article savers.
6468 (defun gnus-output-to-file (file-name)
6469 "Append the current article to a file named FILE-NAME.
6470 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6471 text and used as the value of the coding cookie which is added to the
6472 top of a file. Otherwise, this function saves a raw article without
6473 the coding cookie."
6474 (let* ((artbuf (current-buffer))
6475 (file-name-coding-system nnmail-pathname-coding-system)
6476 (coding gnus-article-save-coding-system)
6477 (coding-system-for-read (if coding
6478 nil ;; Rely on the coding cookie.
6479 mm-text-coding-system))
6480 (coding-system-for-write (or coding
6481 mm-text-coding-system-for-write
6482 mm-text-coding-system))
6483 (exists (file-exists-p file-name)))
6484 (with-temp-buffer
6485 (when exists
6486 (insert-file-contents file-name)
6487 (goto-char (point-min))
6488 ;; Remove the existing coding cookie.
6489 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6490 (delete-region (match-beginning 0) (match-end 0))))
6491 (goto-char (point-max))
6492 (insert-buffer-substring artbuf)
6493 ;; Append newline at end of the buffer as separator, and then
6494 ;; save it to file.
6495 (goto-char (point-max))
6496 (insert "\n")
6497 (when coding
6498 ;; If the coding system is not suitable to encode the text,
6499 ;; ask a user for a proper one.
6500 (when (fboundp 'select-safe-coding-system)
6501 (setq coding (coding-system-base
6502 (save-window-excursion
6503 (select-safe-coding-system (point-min) (point-max)
6504 coding))))
6505 (setq coding-system-for-write
6506 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6507 coding)))
6508 (goto-char (point-min))
6509 ;; Add the coding cookie.
6510 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6511 coding-system-for-write)))
6512 (if exists
6513 (progn
6514 (write-region (point-min) (point-max) file-name nil 'no-message)
6515 (message "Appended to %s" file-name))
6516 (write-region (point-min) (point-max) file-name))))
6519 (defun gnus-narrow-to-page (&optional arg)
6520 "Narrow the article buffer to a page.
6521 If given a numerical ARG, move forward ARG pages."
6522 (interactive "P")
6523 (setq arg (if arg (prefix-numeric-value arg) 0))
6524 (with-current-buffer gnus-article-buffer
6525 (widen)
6526 ;; Remove any old next/prev buttons.
6527 (when (gnus-visual-p 'page-marker)
6528 (let ((inhibit-read-only t))
6529 (gnus-remove-text-with-property 'gnus-prev)
6530 (gnus-remove-text-with-property 'gnus-next)))
6531 (let (st nd pt)
6532 (when (save-excursion
6533 (cond ((< arg 0)
6534 (if (re-search-backward page-delimiter nil 'move (abs arg))
6535 (prog1
6536 (setq nd (match-beginning 0)
6537 pt nd)
6538 (when (re-search-backward page-delimiter nil t)
6539 (setq st (match-end 0))))
6540 (when (re-search-forward page-delimiter nil t)
6541 (setq nd (match-beginning 0)
6542 pt (point-min)))))
6543 ((> arg 0)
6544 (if (re-search-forward page-delimiter nil 'move arg)
6545 (prog1
6546 (setq st (match-end 0)
6547 pt st)
6548 (when (re-search-forward page-delimiter nil t)
6549 (setq nd (match-beginning 0))))
6550 (when (re-search-backward page-delimiter nil t)
6551 (setq st (match-end 0)
6552 pt (point-max)))))
6554 (when (re-search-backward page-delimiter nil t)
6555 (goto-char (setq st (match-end 0))))
6556 (when (re-search-forward page-delimiter nil t)
6557 (setq nd (match-beginning 0)))
6558 (or st nd))))
6559 (setq gnus-page-broken t)
6560 (when pt (goto-char pt))
6561 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6562 (when (gnus-visual-p 'page-marker)
6563 (save-excursion
6564 (when nd
6565 (goto-char nd)
6566 (gnus-insert-next-page-button))
6567 (when st
6568 (goto-char st)
6569 (gnus-insert-prev-page-button))))))))
6571 ;; Article mode commands
6573 (defun gnus-article-goto-next-page ()
6574 "Show the next page of the article."
6575 (interactive)
6576 (when (gnus-article-next-page)
6577 (goto-char (point-min))
6578 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6581 (defun gnus-article-goto-prev-page ()
6582 "Show the previous page of the article."
6583 (interactive)
6584 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6585 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6586 (gnus-article-prev-page nil)))
6588 ;; This is cleaner but currently breaks `gnus-pick-mode':
6590 ;; (defun gnus-article-goto-next-page ()
6591 ;; "Show the next page of the article."
6592 ;; (interactive)
6593 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6594 ;; (gnus-summary-next-page)))
6596 ;; (defun gnus-article-goto-prev-page ()
6597 ;; "Show the next page of the article."
6598 ;; (interactive)
6599 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6600 ;; (gnus-summary-prev-page)))
6602 (defun gnus-article-next-page (&optional lines)
6603 "Show the next page of the current article.
6604 If end of article, return non-nil. Otherwise return nil.
6605 Argument LINES specifies lines to be scrolled up."
6606 (interactive "p")
6607 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6608 (if (and (not (and gnus-article-over-scroll
6609 (> (count-lines (window-start) (point-max))
6610 (if (featurep 'xemacs)
6611 (or lines (1- (window-height)))
6612 (+ (or lines (1- (window-height))) scroll-margin)))))
6613 (save-excursion
6614 (end-of-line)
6615 (and (pos-visible-in-window-p) ;Not continuation line.
6616 (>= (point) (point-max)))))
6617 ;; Nothing in this page.
6618 (if (or (not gnus-page-broken)
6619 (save-excursion
6620 (save-restriction
6621 (widen)
6622 (forward-line)
6623 (eobp)))) ;Real end-of-buffer?
6624 (progn
6625 (when gnus-article-over-scroll
6626 (gnus-article-next-page-1 lines))
6627 t) ;Nothing more.
6628 (gnus-narrow-to-page 1) ;Go to next page.
6629 nil)
6630 ;; More in this page.
6631 (gnus-article-next-page-1 lines)
6632 nil))
6634 (defun gnus-article-beginning-of-window ()
6635 "Move point to the beginning of the window.
6636 In Emacs, the point is placed at the line number which `scroll-margin'
6637 specifies."
6638 (if (featurep 'xemacs)
6639 (move-to-window-line 0)
6640 ;; There is an obscure bug in Emacs that makes it impossible to
6641 ;; scroll past big pictures in the article buffer. Try to fix
6642 ;; this by adding a sanity check by counting the lines visible.
6643 (when (> (count-lines (window-start) (window-end)) 30)
6644 (move-to-window-line
6645 (min (max 0 scroll-margin)
6646 (max 1 (- (window-height)
6647 (if mode-line-format 1 0)
6648 (if header-line-format 1 0)
6649 2)))))))
6651 (defvar scroll-in-place)
6653 (defun gnus-article-next-page-1 (lines)
6654 (condition-case ()
6655 (let ((scroll-in-place nil)
6656 (auto-window-vscroll nil))
6657 (scroll-up lines))
6658 (end-of-buffer
6659 ;; Long lines may cause an end-of-buffer error.
6660 (goto-char (point-max))))
6661 (gnus-article-beginning-of-window))
6663 (defun gnus-article-prev-page (&optional lines)
6664 "Show previous page of current article.
6665 Argument LINES specifies lines to be scrolled down."
6666 (interactive "p")
6667 (move-to-window-line 0)
6668 (if (and gnus-page-broken
6669 (bobp)
6670 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6671 (progn
6672 (gnus-narrow-to-page -1) ;Go to previous page.
6673 (goto-char (point-max))
6674 (recenter (if gnus-article-over-scroll
6675 (if lines
6676 (max (if (featurep 'xemacs)
6677 lines
6678 (+ lines scroll-margin))
6680 (- (window-height) 2))
6681 -1)))
6682 (prog1
6683 (condition-case ()
6684 (let ((scroll-in-place nil))
6685 (scroll-down lines))
6686 (beginning-of-buffer
6687 (goto-char (point-min))))
6688 (gnus-article-beginning-of-window))))
6690 (defun gnus-article-only-boring-p ()
6691 "Decide whether there is only boring text remaining in the article.
6692 Something \"interesting\" is a word of at least two letters that does
6693 not have a face in `gnus-article-boring-faces'."
6694 (when (and gnus-article-skip-boring
6695 (boundp 'gnus-article-boring-faces)
6696 (symbol-value 'gnus-article-boring-faces))
6697 (save-excursion
6698 (let ((inhibit-point-motion-hooks t))
6699 (catch 'only-boring
6700 (while (re-search-forward "\\b\\w\\w" nil t)
6701 (forward-char -1)
6702 (when (not (gnus-intersection
6703 (gnus-faces-at (point))
6704 (symbol-value 'gnus-article-boring-faces)))
6705 (throw 'only-boring nil)))
6706 (throw 'only-boring t))))))
6708 (defun gnus-article-refer-article ()
6709 "Read article specified by message-id around point."
6710 (interactive)
6711 (save-excursion
6712 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6713 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6714 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6715 (let ((msg-id (concat "<" (match-string 0) ">")))
6716 (set-buffer gnus-summary-buffer)
6717 (gnus-summary-refer-article msg-id))
6718 (error "No references around point"))))
6720 (defun gnus-article-show-summary ()
6721 "Reconfigure windows to show summary buffer."
6722 (interactive)
6723 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6724 (error "There is no summary buffer for this article buffer")
6725 (gnus-article-set-globals)
6726 (gnus-configure-windows 'article)
6727 (gnus-summary-goto-subject gnus-current-article)
6728 (gnus-summary-position-point)))
6730 (defun gnus-article-describe-briefly ()
6731 "Describe article mode commands briefly."
6732 (interactive)
6733 (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")))
6735 (defun gnus-article-check-buffer ()
6736 "Beep if not in an article buffer."
6737 (unless (derived-mode-p 'gnus-article-mode)
6738 (error "Command invoked outside of a Gnus article buffer")))
6740 (defvar gnus-pick-mode)
6742 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6743 "Read a summary buffer key sequence and execute it from the article buffer."
6744 (interactive "P")
6745 (gnus-article-check-buffer)
6746 (let ((nosaves
6747 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6748 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6749 "=" "^" "\M-^" "|"))
6750 (nosave-but-article
6751 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6752 "An" "Ap" [?A (meta return)] [?A delete]))
6753 (nosave-in-article
6754 '("AS" "\C-d"))
6755 keys new-sum-point)
6756 (with-current-buffer gnus-article-current-summary
6757 (let (gnus-pick-mode)
6758 (setq unread-command-events (nconc unread-command-events
6759 (list (or key last-command-event)))
6760 keys (if (featurep 'xemacs)
6761 (events-to-keys (read-key-sequence nil t))
6762 (read-key-sequence nil t)))))
6764 (message "")
6766 (cond
6767 ((eq (aref keys (1- (length keys))) ?\C-h)
6768 (gnus-article-describe-bindings (substring keys 0 -1)))
6769 ((or (member keys nosaves)
6770 (member keys nosave-but-article)
6771 (member keys nosave-in-article))
6772 (let (func)
6773 (save-window-excursion
6774 (pop-to-buffer gnus-article-current-summary)
6775 ;; We disable the pick minor mode commands.
6776 (let (gnus-pick-mode)
6777 (setq func (key-binding keys t))))
6778 (if (or (not func)
6779 (numberp func))
6780 (ding)
6781 (unless (member keys nosave-in-article)
6782 (set-buffer gnus-article-current-summary))
6783 (when (and (symbolp func)
6784 (get func 'disabled))
6785 (error "Function %s disabled" func))
6786 (call-interactively func)
6787 (setq new-sum-point (point)))
6788 (when (member keys nosave-but-article)
6789 (pop-to-buffer gnus-article-buffer))))
6791 ;; These commands should restore window configuration.
6792 (let ((obuf (current-buffer))
6793 (owin (current-window-configuration))
6794 win func in-buffer selected new-sum-start new-sum-hscroll err)
6795 (cond (not-restore-window
6796 (pop-to-buffer gnus-article-current-summary)
6797 (setq win (selected-window)))
6798 ((setq win (get-buffer-window gnus-article-current-summary))
6799 (select-window win))
6801 (let ((summary-buffer gnus-article-current-summary))
6802 (gnus-configure-windows 'article)
6803 (unless (setq win (get-buffer-window summary-buffer 'visible))
6804 (let ((gnus-buffer-configuration
6805 '((article ((vertical 1.0
6806 (summary 0.25 point)
6807 (article 1.0)))))))
6808 (gnus-configure-windows 'article))
6809 (setq win (get-buffer-window summary-buffer 'visible)))
6810 (gnus-select-frame-set-input-focus (window-frame win))
6811 (select-window win))))
6812 (setq in-buffer (current-buffer))
6813 ;; We disable the pick minor mode commands.
6814 (setq func (let (gnus-pick-mode)
6815 (key-binding keys t)))
6816 (when (get func 'disabled)
6817 (error "Function %s disabled" func))
6818 (if (and func
6819 (functionp func)
6820 (condition-case code
6821 (progn
6822 (call-interactively func)
6824 (error
6825 (setq err code)
6826 nil)))
6827 (progn
6828 (when (eq win (selected-window))
6829 (setq new-sum-point (point)
6830 new-sum-start (window-start win)
6831 new-sum-hscroll (window-hscroll win)))
6832 (when (or (eq in-buffer (current-buffer))
6833 (when (eq obuf (current-buffer))
6834 (set-buffer in-buffer)
6836 (setq selected (ignore-errors (gnus-summary-select-article)))
6837 (set-buffer obuf)
6838 (unless not-restore-window
6839 (set-window-configuration owin))
6840 (when (and (eq selected 'old)
6841 new-sum-point)
6842 (set-window-start (get-buffer-window (current-buffer))
6844 (set-window-point (get-buffer-window (current-buffer))
6845 (if (article-goto-body)
6846 (1- (point))
6847 (point))))
6848 (when (and (not not-restore-window)
6849 new-sum-point
6850 (window-live-p win)
6851 (with-current-buffer (window-buffer win)
6852 (derived-mode-p 'gnus-summary-mode)))
6853 (set-window-point win new-sum-point)
6854 (set-window-start win new-sum-start)
6855 (set-window-hscroll win new-sum-hscroll))))
6856 (set-window-configuration owin)
6857 (if err
6858 (signal (car err) (cdr err))
6859 (ding))))))))
6861 (defun gnus-article-read-summary-send-keys ()
6862 (interactive)
6863 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6864 (gnus-article-read-summary-keys)))
6866 (defun gnus-article-describe-key (key)
6867 "Display documentation of the function invoked by KEY.
6868 KEY is a string or a vector."
6869 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6870 (read-key-sequence "Describe key: "))))
6871 (gnus-article-check-buffer)
6872 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6873 gnus-article-read-summary-send-keys))
6874 (with-current-buffer gnus-article-current-summary
6875 (setq unread-command-events
6876 (if (featurep 'xemacs)
6877 (append key nil)
6878 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6879 (list 'meta (- x 128))
6881 key)))
6882 (let ((cursor-in-echo-area t)
6883 gnus-pick-mode)
6884 (describe-key (read-key-sequence nil t))))
6885 (describe-key key)))
6887 (defun gnus-article-describe-key-briefly (key &optional insert)
6888 "Display documentation of the function invoked by KEY.
6889 KEY is a string or a vector."
6890 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6891 (read-key-sequence "Describe key: "))
6892 current-prefix-arg))
6893 (gnus-article-check-buffer)
6894 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6895 gnus-article-read-summary-send-keys))
6896 (with-current-buffer gnus-article-current-summary
6897 (setq unread-command-events
6898 (if (featurep 'xemacs)
6899 (append key nil)
6900 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6901 (list 'meta (- x 128))
6903 key)))
6904 (let ((cursor-in-echo-area t)
6905 gnus-pick-mode)
6906 (describe-key-briefly (read-key-sequence nil t) insert)))
6907 (describe-key-briefly key insert)))
6909 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6910 (defvar gnus-agent-summary-mode)
6911 (defvar gnus-draft-mode)
6912 (defvar help-xref-stack-item)
6913 (defvar help-xref-following)
6915 (defun gnus-article-describe-bindings (&optional prefix)
6916 "Show a list of all defined keys, and their definitions.
6917 The optional argument PREFIX, if non-nil, should be a key sequence;
6918 then we display only bindings that start with that prefix."
6919 (interactive)
6920 (gnus-article-check-buffer)
6921 (let ((keymap (copy-keymap gnus-article-mode-map))
6922 (map (copy-keymap gnus-article-send-map))
6923 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6924 parent agent draft)
6925 (define-key keymap "S" map)
6926 (define-key map [t] nil)
6927 (with-current-buffer gnus-article-current-summary
6928 (set-keymap-parent
6929 keymap
6930 (if (setq parent (keymap-parent gnus-article-mode-map))
6931 (prog1
6932 (setq parent (copy-keymap parent))
6933 (set-keymap-parent parent (current-local-map)))
6934 (current-local-map)))
6935 (set-keymap-parent map (key-binding "S"))
6936 (let (key def gnus-pick-mode)
6937 (while sumkeys
6938 (setq key (pop sumkeys))
6939 (cond ((and (vectorp key) (= (length key) 1)
6940 (consp (setq def (aref key 0)))
6941 (numberp (car def)) (numberp (cdr def)))
6942 (when (< (max (car def) (cdr def)) 128)
6943 (setq sumkeys
6944 (append (mapcar
6945 #'vector
6946 (nreverse (gnus-uncompress-range def)))
6947 sumkeys))))
6948 ((setq def (key-binding key))
6949 (unless (eq def 'undefined)
6950 (define-key keymap key def))))))
6951 (when (boundp 'gnus-agent-summary-mode)
6952 (setq agent gnus-agent-summary-mode))
6953 (when (boundp 'gnus-draft-mode)
6954 (setq draft gnus-draft-mode)))
6955 (with-temp-buffer
6956 (use-local-map keymap)
6957 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6958 (set (make-local-variable 'gnus-draft-mode) draft)
6959 (describe-bindings prefix))
6960 (let ((item `((lambda (prefix)
6961 (with-current-buffer ,(current-buffer)
6962 (gnus-article-describe-bindings prefix)))
6963 ,prefix)))
6964 ;; Loading `help-mode' here is necessary if `describe-bindings'
6965 ;; is replaced with something, e.g. `helm-descbinds'.
6966 (require 'help-mode)
6967 (with-current-buffer (let (help-xref-following) (help-buffer))
6968 (setq help-xref-stack-item item)))))
6970 (defun gnus-article-reply-with-original (&optional wide)
6971 "Start composing a reply mail to the current message.
6972 The text in the region will be yanked. If the region isn't active,
6973 the entire article will be yanked."
6974 (interactive)
6975 (let ((article (cdr gnus-article-current))
6976 contents)
6977 (if (not (gnus-region-active-p))
6978 (with-current-buffer gnus-summary-buffer
6979 (gnus-summary-reply (list (list article)) wide))
6980 (setq contents (buffer-substring (point) (mark t)))
6981 ;; Deactivate active regions.
6982 (when (and (boundp 'transient-mark-mode)
6983 transient-mark-mode)
6984 (setq mark-active nil))
6985 (with-current-buffer gnus-summary-buffer
6986 (gnus-summary-reply
6987 (list (list article contents)) wide)))))
6989 (defun gnus-article-wide-reply-with-original ()
6990 "Start composing a wide reply mail to the current message.
6991 The text in the region will be yanked. If the region isn't active,
6992 the entire article will be yanked."
6993 (interactive)
6994 (gnus-article-reply-with-original t))
6996 (defun gnus-article-followup-with-original ()
6997 "Compose a followup to the current article.
6998 The text in the region will be yanked. If the region isn't active,
6999 the entire article will be yanked."
7000 (interactive)
7001 (let ((article (cdr gnus-article-current))
7002 contents)
7003 (if (not (gnus-region-active-p))
7004 (with-current-buffer gnus-summary-buffer
7005 (gnus-summary-followup (list (list article))))
7006 (setq contents (buffer-substring (point) (mark t)))
7007 ;; Deactivate active regions.
7008 (when (and (boundp 'transient-mark-mode)
7009 transient-mark-mode)
7010 (setq mark-active nil))
7011 (with-current-buffer gnus-summary-buffer
7012 (gnus-summary-followup
7013 (list (list article contents)))))))
7015 (defun gnus-article-hide (&optional arg force)
7016 "Hide all the gruft in the current article.
7017 This means that signatures, cited text and (some) headers will be
7018 hidden.
7019 If given a prefix, show the hidden text instead."
7020 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7021 (gnus-article-hide-headers arg)
7022 (gnus-article-hide-list-identifiers arg)
7023 (gnus-article-hide-citation-maybe arg force)
7024 (gnus-article-hide-signature arg))
7026 (defun gnus-check-group-server ()
7027 ;; Make sure the connection to the server is alive.
7028 (unless (gnus-server-opened
7029 (gnus-find-method-for-group gnus-newsgroup-name))
7030 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7031 (gnus-request-group gnus-newsgroup-name t)))
7033 (eval-when-compile
7034 (autoload 'nneething-get-file-name "nneething"))
7036 (defun gnus-request-article-this-buffer (article group)
7037 "Get an article and insert it into this buffer."
7038 (let (do-update-line sparse-header)
7039 (prog1
7040 (save-excursion
7041 (erase-buffer)
7042 (gnus-kill-all-overlays)
7043 (setq group (or group gnus-newsgroup-name))
7045 ;; Using `gnus-request-article' directly will insert the article into
7046 ;; `nntp-server-buffer' - so we'll save some time by not having to
7047 ;; copy it from the server buffer into the article buffer.
7049 ;; We only request an article by message-id when we do not have the
7050 ;; headers for it, so we'll have to get those.
7051 (when (stringp article)
7052 (gnus-read-header article))
7054 ;; If the article number is negative, that means that this article
7055 ;; doesn't belong in this newsgroup (possibly), so we find its
7056 ;; message-id and request it by id instead of number.
7057 (when (and (numberp article)
7058 gnus-summary-buffer
7059 (get-buffer gnus-summary-buffer)
7060 (gnus-buffer-exists-p gnus-summary-buffer))
7061 (with-current-buffer gnus-summary-buffer
7062 (let ((header (gnus-summary-article-header article)))
7063 (when (< article 0)
7064 (cond
7065 ((memq article gnus-newsgroup-sparse)
7066 ;; This is a sparse gap article.
7067 (setq do-update-line article)
7068 (setq article (mail-header-id header))
7069 (setq sparse-header (gnus-read-header article))
7070 (setq gnus-newsgroup-sparse
7071 (delq article gnus-newsgroup-sparse)))
7072 ((vectorp header)
7073 ;; It's a real article.
7074 (setq article (mail-header-id header)))
7076 ;; It is an extracted pseudo-article.
7077 (setq article 'pseudo)
7078 (gnus-request-pseudo-article header))))
7080 (let ((method (gnus-find-method-for-group
7081 gnus-newsgroup-name)))
7082 (when (and (eq (car method) 'nneething)
7083 (vectorp header))
7084 (let ((dir (nneething-get-file-name
7085 (mail-header-id header))))
7086 (when (and (stringp dir)
7087 (file-directory-p dir))
7088 (setq article 'nneething)
7089 (gnus-group-enter-directory dir))))))))
7091 (cond
7092 ;; Refuse to select canceled articles.
7093 ((and (numberp article)
7094 gnus-summary-buffer
7095 (get-buffer gnus-summary-buffer)
7096 (gnus-buffer-exists-p gnus-summary-buffer)
7097 (eq (cdr (with-current-buffer gnus-summary-buffer
7098 (assq article gnus-newsgroup-reads)))
7099 gnus-canceled-mark))
7100 nil)
7101 ;; We first check `gnus-original-article-buffer'.
7102 ((and (get-buffer gnus-original-article-buffer)
7103 (numberp article)
7104 (with-current-buffer gnus-original-article-buffer
7105 (and (equal (car gnus-original-article) group)
7106 (eq (cdr gnus-original-article) article))))
7107 ;; `insert-buffer-substring' would incorrectly use the
7108 ;; equivalent of string-make-multibyte which amount to decoding
7109 ;; with locale-coding-system, causing failure of
7110 ;; subsequent decoding.
7111 (insert (mm-string-to-multibyte
7112 (with-current-buffer gnus-original-article-buffer
7113 (buffer-substring (point-min) (point-max)))))
7114 'article)
7115 ;; Check the backlog.
7116 ((and gnus-keep-backlog
7117 (gnus-backlog-request-article group article (current-buffer)))
7118 'article)
7119 ;; Check asynchronous pre-fetch.
7120 ((gnus-async-request-fetched-article group article (current-buffer))
7121 (gnus-async-prefetch-next group article gnus-summary-buffer)
7122 (when (and (numberp article) gnus-keep-backlog)
7123 (gnus-backlog-enter-article group article (current-buffer)))
7124 'article)
7125 ;; Check the cache.
7126 ((and gnus-use-cache
7127 (numberp article)
7128 (gnus-cache-request-article article group))
7129 'article)
7130 ;; Check the agent cache.
7131 ((gnus-agent-request-article article group)
7132 'article)
7133 ;; Get the article and put into the article buffer.
7134 ((or (stringp article)
7135 (numberp article))
7136 (let ((gnus-override-method gnus-override-method)
7137 (methods (and (stringp article)
7138 (with-current-buffer gnus-summary-buffer
7139 (gnus-refer-article-methods))))
7140 (backend (car (gnus-find-method-for-group
7141 gnus-newsgroup-name)))
7142 result
7143 (inhibit-read-only t))
7144 (when (and (null gnus-override-method)
7145 methods)
7146 (setq gnus-override-method (pop methods)))
7147 (while (not result)
7148 (erase-buffer)
7149 (gnus-kill-all-overlays)
7150 (let ((gnus-newsgroup-name group))
7151 (gnus-check-group-server))
7152 (cond
7153 ((gnus-request-article article group (current-buffer))
7154 (when (numberp article)
7155 (gnus-async-prefetch-next group article
7156 gnus-summary-buffer)
7157 (when gnus-keep-backlog
7158 (gnus-backlog-enter-article
7159 group article (current-buffer)))
7160 (when (and gnus-agent
7161 (gnus-agent-group-covered-p group))
7162 (gnus-agent-store-article article group)))
7163 (setq result 'article))
7164 (methods
7165 (setq gnus-override-method (pop methods)))
7166 ((not (string-match "^400 "
7167 (nnheader-get-report backend)))
7168 ;; If we get 400 server disconnect, reconnect and
7169 ;; retry; otherwise, assume the article has expired.
7170 (setq result 'done))))
7171 (and (eq result 'article) 'article)))
7172 ;; It was a pseudo.
7173 (t article)))
7175 ;; Associate this article with the current summary buffer.
7176 (setq gnus-article-current-summary gnus-summary-buffer)
7178 ;; Take the article from the original article buffer
7179 ;; and place it in the buffer it's supposed to be in.
7180 (when (and (get-buffer gnus-article-buffer)
7181 (equal (buffer-name (current-buffer))
7182 (buffer-name (get-buffer gnus-article-buffer))))
7183 (save-excursion
7184 (if (get-buffer gnus-original-article-buffer)
7185 (set-buffer gnus-original-article-buffer)
7186 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7187 (buffer-disable-undo)
7188 (setq major-mode 'gnus-original-article-mode)
7189 (setq buffer-read-only t))
7190 (let ((inhibit-read-only t))
7191 (erase-buffer)
7192 (insert-buffer-substring gnus-article-buffer))
7193 (setq gnus-original-article (cons group article)))
7195 ;; Decode charsets.
7196 (run-hooks 'gnus-article-decode-hook)
7197 ;; Mark article as decoded or not.
7198 (setq gnus-article-decoded-p gnus-article-decode-hook))
7200 ;; Update sparse articles.
7201 (when (and do-update-line
7202 (or (numberp article)
7203 (stringp article)))
7204 (let ((buf (current-buffer)))
7205 (set-buffer gnus-summary-buffer)
7206 (gnus-summary-update-article do-update-line sparse-header)
7207 (gnus-summary-goto-subject do-update-line nil t)
7208 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7209 (point))
7210 (set-buffer buf))))))
7212 (defun gnus-block-private-groups (group)
7213 "Allows images in newsgroups to be shown, blocks images in all
7214 other groups."
7215 (if (or (gnus-news-group-p group)
7216 (gnus-member-of-valid 'global group))
7217 ;; Block nothing in news groups.
7219 ;; Block everything anywhere else.
7220 "."))
7222 (defun gnus-blocked-images ()
7223 (if (functionp gnus-blocked-images)
7224 (funcall gnus-blocked-images gnus-newsgroup-name)
7225 gnus-blocked-images))
7228 ;;; Article editing
7231 (defcustom gnus-article-edit-mode-hook nil
7232 "Hook run in article edit mode buffers."
7233 :group 'gnus-article-various
7234 :type 'hook)
7236 (defvar gnus-article-edit-done-function nil)
7238 (defvar gnus-article-edit-mode-map nil)
7240 ;; Should we be using derived.el for this?
7241 (unless gnus-article-edit-mode-map
7242 (setq gnus-article-edit-mode-map (make-keymap))
7243 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7245 (gnus-define-keys gnus-article-edit-mode-map
7246 "\C-c?" describe-mode
7247 "\C-c\C-c" gnus-article-edit-done
7248 "\C-c\C-k" gnus-article-edit-exit
7249 "\C-c\C-f\C-t" message-goto-to
7250 "\C-c\C-f\C-o" message-goto-from
7251 "\C-c\C-f\C-b" message-goto-bcc
7252 ;;"\C-c\C-f\C-w" message-goto-fcc
7253 "\C-c\C-f\C-c" message-goto-cc
7254 "\C-c\C-f\C-s" message-goto-subject
7255 "\C-c\C-f\C-r" message-goto-reply-to
7256 "\C-c\C-f\C-n" message-goto-newsgroups
7257 "\C-c\C-f\C-d" message-goto-distribution
7258 "\C-c\C-f\C-f" message-goto-followup-to
7259 "\C-c\C-f\C-m" message-goto-mail-followup-to
7260 "\C-c\C-f\C-k" message-goto-keywords
7261 "\C-c\C-f\C-u" message-goto-summary
7262 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7263 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7264 "\C-c\C-b" message-goto-body
7265 "\C-c\C-i" message-goto-signature
7267 "\C-c\C-t" message-insert-to
7268 "\C-c\C-n" message-insert-newsgroups
7269 "\C-c\C-o" message-sort-headers
7270 "\C-c\C-e" message-elide-region
7271 "\C-c\C-v" message-delete-not-region
7272 "\C-c\C-z" message-kill-to-signature
7273 "\M-\r" message-newline-and-reformat
7274 "\C-c\C-a" mml-attach-file
7275 "\C-a" message-beginning-of-line
7276 "\t" message-tab
7277 "\M-;" comment-region)
7279 (gnus-define-keys (gnus-article-edit-wash-map
7280 "\C-c\C-w" gnus-article-edit-mode-map)
7281 "f" gnus-article-edit-full-stops))
7283 (easy-menu-define
7284 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7285 '("Field"
7286 ["Fetch To" message-insert-to t]
7287 ["Fetch Newsgroups" message-insert-newsgroups t]
7288 "----"
7289 ["To" message-goto-to t]
7290 ["From" message-goto-from t]
7291 ["Subject" message-goto-subject t]
7292 ["Cc" message-goto-cc t]
7293 ["Reply-To" message-goto-reply-to t]
7294 ["Summary" message-goto-summary t]
7295 ["Keywords" message-goto-keywords t]
7296 ["Newsgroups" message-goto-newsgroups t]
7297 ["Followup-To" message-goto-followup-to t]
7298 ["Mail-Followup-To" message-goto-mail-followup-to t]
7299 ["Distribution" message-goto-distribution t]
7300 ["Body" message-goto-body t]
7301 ["Signature" message-goto-signature t]))
7303 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7304 "Major mode for editing articles.
7305 This is an extended text-mode.
7307 \\{gnus-article-edit-mode-map}"
7308 (make-local-variable 'gnus-article-edit-done-function)
7309 (make-local-variable 'gnus-prev-winconf)
7310 (set (make-local-variable 'font-lock-defaults)
7311 '(message-font-lock-keywords t))
7312 (set (make-local-variable 'mail-header-separator) "")
7313 (set (make-local-variable 'gnus-article-edit-mode) t)
7314 (easy-menu-add message-mode-field-menu message-mode-map)
7315 (mml-mode)
7316 (setq buffer-read-only nil)
7317 (buffer-enable-undo)
7318 (widen))
7320 (defun gnus-article-edit (&optional force)
7321 "Edit the current article.
7322 This will have permanent effect only in mail groups.
7323 If FORCE is non-nil, allow editing of articles even in read-only
7324 groups."
7325 (interactive "P")
7326 (when (and (not force)
7327 (gnus-group-read-only-p))
7328 (error "The current newsgroup does not support article editing"))
7329 (gnus-article-date-original)
7330 (gnus-article-edit-article
7331 'ignore
7332 `(lambda (no-highlight)
7333 'ignore
7334 (gnus-summary-edit-article-done
7335 ,(or (mail-header-references gnus-current-headers) "")
7336 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7338 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7339 "Start editing the contents of the current article buffer."
7340 (let ((winconf (current-window-configuration)))
7341 (set-buffer gnus-article-buffer)
7342 (let ((message-auto-save-directory
7343 ;; Don't associate the article buffer with a draft file.
7344 nil))
7345 (gnus-article-edit-mode))
7346 (funcall start-func)
7347 (set-buffer-modified-p nil)
7348 (gnus-configure-windows 'edit-article)
7349 (setq gnus-article-edit-done-function exit-func)
7350 (setq gnus-prev-winconf winconf)
7351 (unless quiet
7352 (gnus-message 6 "C-c C-c to end edits"))))
7354 (defun gnus-article-edit-done (&optional arg)
7355 "Update the article edits and exit."
7356 (interactive "P")
7357 (let ((func gnus-article-edit-done-function)
7358 (buf (current-buffer))
7359 (start (window-start))
7360 (winconf gnus-prev-winconf))
7361 (widen) ;; Widen it in case that users narrowed the buffer.
7362 (funcall func arg)
7363 (set-buffer buf)
7364 ;; The cache and backlog have to be flushed somewhat.
7365 (when gnus-keep-backlog
7366 (gnus-backlog-remove-article
7367 (car gnus-article-current) (cdr gnus-article-current)))
7368 ;; Flush original article as well.
7369 (gnus-flush-original-article-buffer)
7370 (when gnus-use-cache
7371 (gnus-cache-update-article
7372 (car gnus-article-current) (cdr gnus-article-current)))
7373 ;; We remove all text props from the article buffer.
7374 (kill-all-local-variables)
7375 (set-text-properties (point-min) (point-max) nil)
7376 (gnus-article-mode)
7377 (set-window-configuration winconf)
7378 (set-buffer buf)
7379 (set-window-start (get-buffer-window buf) start)
7380 (set-window-point (get-buffer-window buf) (point)))
7381 (gnus-summary-show-article))
7383 (defun gnus-flush-original-article-buffer ()
7384 (when (get-buffer gnus-original-article-buffer)
7385 (with-current-buffer gnus-original-article-buffer
7386 (setq gnus-original-article nil))))
7388 (defun gnus-article-edit-exit ()
7389 "Exit the article editing without updating."
7390 (interactive)
7391 (when (or (not (buffer-modified-p))
7392 (yes-or-no-p "Article modified; kill anyway? "))
7393 (let ((curbuf (current-buffer))
7394 (p (point))
7395 (window-start (window-start)))
7396 (erase-buffer)
7397 (if (gnus-buffer-live-p gnus-original-article-buffer)
7398 (insert-buffer-substring gnus-original-article-buffer))
7399 (let ((winconf gnus-prev-winconf))
7400 (kill-all-local-variables)
7401 (gnus-article-mode)
7402 (set-window-configuration winconf)
7403 ;; Tippy-toe some to make sure that point remains where it was.
7404 (save-current-buffer
7405 (set-buffer curbuf)
7406 (set-window-start (get-buffer-window (current-buffer)) window-start)
7407 (goto-char p))))
7408 (gnus-summary-show-article)))
7410 (defun gnus-article-edit-full-stops ()
7411 "Interactively repair spacing at end of sentences."
7412 (interactive)
7413 (save-excursion
7414 (goto-char (point-min))
7415 (search-forward-regexp "^$" nil t)
7416 (let ((case-fold-search nil))
7417 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7420 ;;; Article highlights
7423 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7425 ;;; Internal Variables:
7427 (defcustom gnus-button-url-regexp
7428 (concat
7429 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7430 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7431 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7432 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7433 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7434 (punct "!?:;.,"))
7435 (concat
7436 "\\(?:"
7437 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7438 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7439 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7440 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7441 "\\|"
7442 "[" chars punct "]+" "[" chars "]"
7443 "\\)"))
7444 (concat ;; XEmacs 21.4 doesn't support POSIX.
7445 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7446 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7447 "\\)")
7448 "Regular expression that matches URLs."
7449 :version "24.4"
7450 :group 'gnus-article-buttons
7451 :type 'regexp)
7453 (defcustom gnus-button-valid-fqdn-regexp
7454 message-valid-fqdn-regexp
7455 "Regular expression that matches a valid FQDN."
7456 :version "22.1"
7457 :group 'gnus-article-buttons
7458 :type 'regexp)
7460 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7461 (defcustom gnus-button-valid-localpart-regexp
7462 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7463 "Regular expression that matches a localpart of mail addresses or MIDs."
7464 :version "22.1"
7465 :group 'gnus-article-buttons
7466 :type 'regexp)
7468 (defcustom gnus-button-man-handler 'manual-entry
7469 "Function to use for displaying man pages.
7470 The function must take at least one argument with a string naming the
7471 man page."
7472 :version "22.1"
7473 :type '(choice (function-item :tag "Man" manual-entry)
7474 (function-item :tag "Woman" woman)
7475 (function :tag "Other"))
7476 :group 'gnus-article-buttons)
7478 (defcustom gnus-button-mid-or-mail-regexp
7479 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7480 gnus-button-valid-fqdn-regexp
7481 ">?\\)\\b")
7482 "Regular expression that matches a message ID or a mail address."
7483 :version "22.1"
7484 :group 'gnus-article-buttons
7485 :type 'regexp)
7487 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7488 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7489 Strings like this can be either a message ID or a mail address. If it is one
7490 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7491 message ID or a mail address, respectively. If this variable is set to the
7492 symbol `ask', always query the user what do do. If it is a function, this
7493 function will be called with the string as its only argument. The function
7494 must return `mid', `mail', `invalid' or `ask'."
7495 :version "22.1"
7496 :group 'gnus-article-buttons
7497 :type '(choice (function-item :tag "Heuristic function"
7498 gnus-button-mid-or-mail-heuristic)
7499 (const ask)
7500 (const mid)
7501 (const mail)))
7503 (defcustom gnus-button-mid-or-mail-heuristic-alist
7504 '((-10.0 . ".+\\$.+@")
7505 (-10.0 . "#")
7506 (-10.0 . "\\*")
7507 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7508 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7509 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7510 (-1.0 . "^[^a-z]+@")
7512 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7513 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7514 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7515 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7517 (-2.0 . "^[0-9]")
7518 (-1.0 . "^[0-9][0-9]")
7520 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7521 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7522 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7523 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7525 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7526 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7527 ;; "[0-9]{8,}.*\@"
7528 (-3.0
7529 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7530 ;; "[0-9]{12,}.*\@"
7531 ;; compensation for TDMA dated mail addresses:
7532 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7534 (-20.0 . "\\.fsf@") ;; Gnus
7535 (-20.0 . "^slrn")
7536 (-20.0 . "^Pine")
7537 (-20.0 . "^alpine\\.")
7538 (-20.0 . "_-_") ;; Subject change in thread
7540 (-20.0 . "\\.ln@") ;; leafnode
7541 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7542 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7544 ;; (5.0 . "") ;; $local_part_len <= 7
7545 (10.0 . "^[^0-9]+@")
7546 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7547 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7548 (3.0 . "\@stud")
7550 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7552 (0.5 . "^[A-Z][a-z]")
7553 (0.5 . "^[A-Z][a-z][a-z]")
7554 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7555 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7556 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7558 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7559 address. The REGEXP is processed with `case-fold-search' set to nil."
7560 :version "22.1"
7561 :group 'gnus-article-buttons
7562 :type '(repeat (cons (number :tag "Rate")
7563 (regexp :tag "Regexp"))))
7565 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7566 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7567 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7568 address, `ask' if unsure and `invalid' if the string is invalid."
7569 (let ((case-fold-search nil)
7570 (list gnus-button-mid-or-mail-heuristic-alist)
7571 (result 0) rate regexp lpartlen elem)
7572 (setq lpartlen
7573 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7574 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7575 ;; Certain special cases...
7576 (when (string-match
7577 (concat
7578 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7579 "^[0-9]+\\.[0-9]+@compuserve\\|"
7580 "@public\\.gmane\\.org")
7581 mid-or-mail)
7582 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7583 (setq result 'mail))
7584 (when (string-match "@.*@\\| " mid-or-mail)
7585 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7586 (setq result 'invalid))
7587 ;; Nothing more to do, if result is not a number here...
7588 (when (numberp result)
7589 (while list
7590 (setq elem (car list)
7591 rate (car elem)
7592 regexp (cdr elem)
7593 list (cdr list))
7594 (when (string-match regexp mid-or-mail)
7595 (setq result (+ result rate))
7596 (gnus-message
7597 9 "`%s' matched `%s', rate `%s', result `%s'."
7598 mid-or-mail regexp rate result)))
7599 (when (<= lpartlen 7)
7600 (setq result (+ result 5.0))
7601 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7602 mid-or-mail result))
7603 (when (>= lpartlen 12)
7604 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7605 (cond
7606 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7607 ;; Long local part should contain realname if e-mail address,
7608 ;; too many digits: message-id.
7609 ;; $score -= 5.0 + 0.1 * $local_part_len;
7610 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7611 (setq result (+ result rate))
7612 (gnus-message
7613 9 "Many digits in `%s', rate `%s', result `%s'."
7614 mid-or-mail rate result))
7615 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7616 mid-or-mail)
7617 ;; Too few vowels [^aeiouy]{4,}.*\@
7618 (setq result (+ result -5.0))
7619 (gnus-message
7620 9 "Few vowels in `%s', rate `%s', result `%s'."
7621 mid-or-mail -5.0 result))
7623 (setq result (+ result 5.0))
7624 (gnus-message
7625 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7626 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7627 ;; Maybe we should make this a customizable alist: (condition . 'result)
7628 (cond
7629 ((symbolp result) result)
7630 ;; Now convert number into proper results:
7631 ((< result -10.0) 'mid)
7632 ((> result 10.0) 'mail)
7633 (t 'ask))))
7635 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7636 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7637 (url-mid (concat "news" ":" mid-or-mail))
7638 (url-mailto (concat "mailto" ":" mid-or-mail)))
7639 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7640 (when (fboundp pref)
7641 (setq guessed
7642 ;; get rid of surrounding angles...
7643 (funcall pref
7644 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7645 (if (or (eq 'mid guessed) (eq 'mail guessed))
7646 (setq pref guessed)
7647 (setq pref 'ask)))
7648 (if (eq pref 'ask)
7649 (save-window-excursion
7650 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7651 (setq pref 'mail)
7652 (setq pref 'mid))))
7653 (cond ((eq pref 'mid)
7654 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7655 (gnus-button-handle-news url-mid))
7656 ((eq pref 'mail)
7657 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7658 (gnus-url-mailto url-mailto))
7659 (t (gnus-message 3 "Invalid string.")))))
7661 (defun gnus-button-handle-custom (fun arg)
7662 "Call function FUN on argument ARG.
7663 Both FUN and ARG are supposed to be strings. ARG will be passed
7664 as a symbol to FUN."
7665 (funcall (intern fun)
7666 (if (string-match "^customize-apropos" fun)
7668 (intern arg))))
7670 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7672 (defun gnus-button-handle-describe-function (url)
7673 "Call `describe-function' when pushing the corresponding URL button."
7674 (describe-function
7675 (intern
7676 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7678 (defun gnus-button-handle-describe-variable (url)
7679 "Call `describe-variable' when pushing the corresponding URL button."
7680 (describe-variable
7681 (intern
7682 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7684 (defun gnus-button-handle-symbol (url)
7685 "Display help on variable or function.
7686 Calls `describe-variable' or `describe-function'."
7687 (let ((sym (intern url)))
7688 (cond
7689 ((fboundp sym) (describe-function sym))
7690 ((boundp sym) (describe-variable sym))
7691 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7693 (defun gnus-button-handle-describe-key (url)
7694 "Call `describe-key' when pushing the corresponding URL button."
7695 (let* ((key-string
7696 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7697 (keys (ignore-errors (eval `(kbd ,key-string)))))
7698 (if keys
7699 (describe-key keys)
7700 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7702 (defun gnus-button-handle-apropos (url)
7703 "Call `apropos' when pushing the corresponding URL button."
7704 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7706 (defun gnus-button-handle-apropos-command (url)
7707 "Call `apropos' when pushing the corresponding URL button."
7708 (apropos-command
7709 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7711 (defun gnus-button-handle-apropos-variable (url)
7712 "Call `apropos' when pushing the corresponding URL button."
7713 (funcall
7714 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7715 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7717 (defun gnus-button-handle-apropos-documentation (url)
7718 "Call `apropos' when pushing the corresponding URL button."
7719 (funcall
7720 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7721 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7723 (defun gnus-button-handle-library (url)
7724 "Call `locate-library' when pushing the corresponding URL button."
7725 (gnus-message 9 "url=`%s'" url)
7726 (let* ((lib (locate-library url))
7727 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7728 (if (not lib)
7729 (gnus-message 1 "Cannot locale library `%s'." url)
7730 (find-file-read-only file))))
7732 (defcustom gnus-button-man-level 5
7733 "*Integer that says how many man-related buttons Gnus will show.
7734 The higher the number, the more buttons will appear and the more false
7735 positives are possible. Note that you can set this variable local to
7736 specific groups. Setting it higher in Unix groups is probably a good idea.
7737 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7738 how to set variables in specific groups."
7739 :version "22.1"
7740 :group 'gnus-article-buttons
7741 :link '(custom-manual "(gnus)Group Parameters")
7742 :type 'integer)
7744 (defcustom gnus-button-emacs-level 5
7745 "*Integer that says how many emacs-related buttons Gnus will show.
7746 The higher the number, the more buttons will appear and the more false
7747 positives are possible. Note that you can set this variable local to
7748 specific groups. Setting it higher in Emacs or Gnus related groups is
7749 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7750 `gnus-parameters' on how to set variables in specific groups."
7751 :version "22.1"
7752 :group 'gnus-article-buttons
7753 :link '(custom-manual "(gnus)Group Parameters")
7754 :type 'integer)
7756 (defcustom gnus-button-message-level 5
7757 "*Integer that says how many buttons for news or mail messages will appear.
7758 The higher the number, the more buttons will appear and the more false
7759 positives are possible."
7760 ;; mail addresses, MIDs, URLs for news, ...
7761 :version "22.1"
7762 :group 'gnus-article-buttons
7763 :type 'integer)
7765 (defcustom gnus-button-browse-level 5
7766 "*Integer that says how many buttons for browsing will appear.
7767 The higher the number, the more buttons will appear and the more false
7768 positives are possible."
7769 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7770 :version "22.1"
7771 :group 'gnus-article-buttons
7772 :type 'integer)
7774 (defcustom gnus-button-alist
7775 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7776 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7777 ((concat "\\b\\(nntp\\|news\\):\\("
7778 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7779 0 t gnus-button-handle-news 2)
7780 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7781 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7782 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7783 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7784 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7785 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7786 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7787 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7788 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7789 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7790 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7791 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7792 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7793 ;; RFC 2368 (The mailto URL scheme)
7794 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7795 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7796 ("\\bmailto:\\([^ \n\t]+\\)"
7797 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7798 ;; Info Konqueror style <info:/foo/bar baz>.
7799 ;; Must come before " Gnus home-grown style".
7800 ("\\binfo://?\\([^'\">\n\t]+\\)"
7801 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7802 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7803 ("\\binfo://\\([^'\">\n\t ]+\\)"
7804 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7805 ;; Info GNOME style <info:foo#bar_baz>
7806 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7807 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7808 ;; Info KDE style <info:(foo)bar baz>
7809 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7810 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7811 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7812 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7813 ("\\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,]*\\)\\)?"
7814 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7815 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7816 ;; This is custom
7817 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7818 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7819 ;; Emacs help commands
7820 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7821 ;; regexp doesn't match arguments containing ` '.
7822 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7823 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7824 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7825 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7827 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7828 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7829 ;; The following entries may lead to many false positives so don't enable
7830 ;; them by default (use a high button level).
7831 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7832 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7833 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7834 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7835 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7836 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7837 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7838 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7839 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7840 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7841 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7842 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7843 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7844 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7845 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7846 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7847 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7848 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7849 ;; Unlike the other regexps we really have to require quoting
7850 ;; here to determine where it ends.
7851 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7852 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7853 ("<URL: *\\([^\n<>]*\\)>"
7854 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7855 ;; RFC 2396 (2.4.3., delims) ...
7856 ("\"URL: *\\([^\n\"]*\\)\""
7857 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7858 ;; Raw URLs.
7859 (gnus-button-url-regexp
7860 0 (>= gnus-button-browse-level 0) browse-url 0)
7861 ;; man pages
7862 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7863 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7864 gnus-button-handle-man 1)
7865 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7866 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7867 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7868 gnus-button-handle-man 1)
7869 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7870 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7871 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7872 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7873 ;; Recognizing patches to .el files. This is somewhat obscure,
7874 ;; but considering the percentage of Gnus users who hack Emacs
7875 ;; Lisp files...
7876 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7877 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7878 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7879 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7880 ;; MID or mail: To avoid too many false positives we don't try to catch
7881 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7882 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7883 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7884 ;; so that non-ambiguous entries (see above) match first.
7885 (gnus-button-mid-or-mail-regexp
7886 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7887 "*Alist of regexps matching buttons in article bodies.
7889 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7890 REGEXP: is the string (case insensitive) matching text around the button (can
7891 also be Lisp expression evaluating to a string),
7892 BUTTON: is the number of the regexp grouping actually matching the button,
7893 FORM: is a Lisp expression which must eval to true for the button to
7894 be added,
7895 CALLBACK: is the function to call when the user push this button, and each
7896 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7898 CALLBACK can also be a variable, in that case the value of that
7899 variable it the real callback function."
7900 :group 'gnus-article-buttons
7901 :type '(repeat (list (choice regexp variable sexp)
7902 (integer :tag "Button")
7903 (sexp :tag "Form")
7904 (function :tag "Callback")
7905 (repeat :tag "Par"
7906 :inline t
7907 (integer :tag "Regexp group")))))
7908 (put 'gnus-button-alist 'risky-local-variable t)
7910 (defcustom gnus-header-button-alist
7911 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7912 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7913 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7914 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7915 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7916 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7917 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7918 0 (>= gnus-button-browse-level 0) browse-url 0)
7919 ("^Subject:" gnus-button-url-regexp
7920 0 (>= gnus-button-browse-level 0) browse-url 0)
7921 ("^[^:]+:" gnus-button-url-regexp
7922 0 (>= gnus-button-browse-level 0) browse-url 0)
7923 ("^OpenPGP:.*url=" gnus-button-url-regexp
7924 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7925 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7926 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7927 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7928 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7929 "*Alist of headers and regexps to match buttons in article heads.
7931 This alist is very similar to `gnus-button-alist', except that each
7932 alist has an additional HEADER element first in each entry:
7934 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7936 HEADER is a regexp to match a header. For a fuller explanation, see
7937 `gnus-button-alist'."
7938 :group 'gnus-article-buttons
7939 :group 'gnus-article-headers
7940 :type '(repeat (list (regexp :tag "Header")
7941 (choice regexp variable)
7942 (integer :tag "Button")
7943 (sexp :tag "Form")
7944 (function :tag "Callback")
7945 (repeat :tag "Par"
7946 :inline t
7947 (integer :tag "Regexp group")))))
7948 (put 'gnus-header-button-alist 'risky-local-variable t)
7950 ;;; Commands:
7952 (defun gnus-article-push-button (event)
7953 "Check text under the mouse pointer for a callback function.
7954 If the text under the mouse pointer has a `gnus-callback' property,
7955 call it with the value of the `gnus-data' text property."
7956 (interactive "e")
7957 (set-buffer (window-buffer (posn-window (event-start event))))
7958 (let* ((pos (posn-point (event-start event)))
7959 (data (get-text-property pos 'gnus-data))
7960 (fun (get-text-property pos 'gnus-callback)))
7961 (goto-char pos)
7962 (when fun
7963 (funcall fun data))))
7965 (defun gnus-article-press-button ()
7966 "Check text at point for a callback function.
7967 If the text at point has a `gnus-callback' property,
7968 call it with the value of the `gnus-data' text property."
7969 (interactive)
7970 (let ((data (get-text-property (point) 'gnus-data))
7971 (fun (get-text-property (point) 'gnus-callback)))
7972 (when fun
7973 (funcall fun data))))
7975 (defun gnus-article-highlight (&optional force)
7976 "Highlight current article.
7977 This function calls `gnus-article-highlight-headers',
7978 `gnus-article-highlight-citation',
7979 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7980 do the highlighting. See the documentation for those functions."
7981 (interactive (list 'force))
7982 (gnus-article-highlight-headers)
7983 (gnus-article-highlight-citation force)
7984 (gnus-article-highlight-signature)
7985 (gnus-article-add-buttons)
7986 (gnus-article-add-buttons-to-head))
7988 (defun gnus-article-highlight-some (&optional _force)
7989 "Highlight current article.
7990 This function calls `gnus-article-highlight-headers',
7991 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7992 do the highlighting. See the documentation for those functions."
7993 (interactive (list 'force))
7994 (gnus-article-highlight-headers)
7995 (gnus-article-highlight-signature)
7996 (gnus-article-add-buttons))
7998 (defun gnus-article-highlight-headers ()
7999 "Highlight article headers as specified by `gnus-header-face-alist'."
8000 (interactive)
8001 (gnus-with-article-headers
8002 (let (regexp header-face field-face from hpoints fpoints)
8003 (dolist (entry gnus-header-face-alist)
8004 (goto-char (point-min))
8005 (setq regexp (concat "^\\("
8006 (if (string-equal "" (nth 0 entry))
8007 "[^\t ]"
8008 (nth 0 entry))
8009 "\\)")
8010 header-face (nth 1 entry)
8011 field-face (nth 2 entry))
8012 (while (and (re-search-forward regexp nil t)
8013 (not (eobp)))
8014 (beginning-of-line)
8015 (setq from (point))
8016 (unless (search-forward ":" nil t)
8017 (forward-char 1))
8018 (when (and header-face
8019 (not (memq (point) hpoints)))
8020 (push (point) hpoints)
8021 (gnus-put-text-property from (point) 'face header-face))
8022 (when (and field-face
8023 (not (memq (setq from (point)) fpoints)))
8024 (push from fpoints)
8025 (if (re-search-forward "^[^ \t]" nil t)
8026 (forward-char -2)
8027 (goto-char (point-max)))
8028 (gnus-put-text-property from (point) 'face field-face)))))))
8030 (defun gnus-article-highlight-signature ()
8031 "Highlight the signature in an article.
8032 It does this by highlighting everything after
8033 `gnus-signature-separator' using the face `gnus-signature'."
8034 (interactive)
8035 (gnus-with-article-buffer
8036 (let ((inhibit-point-motion-hooks t))
8037 (save-restriction
8038 (when (and gnus-signature-face
8039 (gnus-article-narrow-to-signature))
8040 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8041 'face gnus-signature-face)
8042 (widen)
8043 (gnus-article-search-signature)
8044 (let ((start (match-beginning 0))
8045 (end (set-marker (make-marker) (1+ (match-end 0)))))
8046 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8047 end)))))))
8049 (defun gnus-button-in-region-p (b e prop)
8050 "Say whether PROP exists in the region."
8051 (text-property-not-all b e prop nil))
8053 (defun gnus-article-add-buttons ()
8054 "Find external references in the article and make buttons of them.
8055 \"External references\" are things like Message-IDs and URLs, as
8056 specified by `gnus-button-alist'."
8057 (interactive)
8058 (gnus-with-article-buffer
8059 (let ((inhibit-point-motion-hooks t)
8060 (case-fold-search t)
8061 (alist gnus-button-alist)
8062 beg entry regexp)
8063 ;; We skip the headers.
8064 (article-goto-body)
8065 (setq beg (point))
8066 (while (setq entry (pop alist))
8067 (setq regexp (eval (car entry)))
8068 (goto-char beg)
8069 (while (re-search-forward regexp nil t)
8070 (let ((start (match-beginning (nth 1 entry)))
8071 (end (match-end (nth 1 entry)))
8072 (from (match-beginning 0)))
8073 (when (and (eval (nth 2 entry))
8074 (not (gnus-button-in-region-p
8075 start end 'gnus-callback)))
8076 ;; That optional form returned non-nil, so we add the
8077 ;; button.
8078 (setq from (set-marker (make-marker) from))
8079 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8080 (gnus-article-extend-url-button from start end))
8081 (gnus-article-add-button start end
8082 'gnus-button-push (list from entry))
8083 (gnus-put-text-property
8084 start end
8085 'gnus-string (buffer-substring-no-properties
8086 start end))))))))))
8088 (defun gnus-article-extend-url-button (beg start end)
8089 "Extend url button if url is folded into two or more lines.
8090 Return non-nil if button is extended. BEG is a marker that points to
8091 the beginning position of a text containing url. START and END are
8092 the endpoints of a url button before it is extended. The concatenated
8093 url is put as the `gnus-button-url' overlay property on the button."
8094 (let ((opoint (point))
8095 (points (list start end))
8096 url delim regexp)
8097 (prog1
8098 (when (and (progn
8099 (goto-char end)
8100 (not (looking-at "[\t ]*[\">]")))
8101 (progn
8102 (goto-char start)
8103 (string-match
8104 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8105 (buffer-substring (point-at-bol) start)))
8106 (progn
8107 (setq url (list (buffer-substring start end))
8108 delim (if (match-beginning 1) ">" "\""))
8109 (beginning-of-line)
8110 (setq regexp (concat
8111 (when (and (looking-at
8112 message-cite-prefix-regexp)
8113 (< (match-end 0) start))
8114 (regexp-quote (match-string 0)))
8116 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8117 delim "\\)"))
8118 (while (progn
8119 (forward-line 1)
8120 (and (looking-at regexp)
8121 (prog1
8122 (match-beginning 1)
8123 (push (or (match-string 2)
8124 (match-string 1))
8125 url)
8126 (push (setq end (or (match-end 2)
8127 (match-end 1)))
8128 points)
8129 (push (or (match-beginning 2)
8130 (match-beginning 1))
8131 points)))))
8132 (match-beginning 2)))
8133 (let (gnus-article-mouse-face widget-mouse-face)
8134 (while points
8135 (gnus-article-add-button (pop points) (pop points)
8136 'gnus-button-push
8137 (list beg (assq 'gnus-button-url-regexp
8138 gnus-button-alist)))))
8139 (let ((overlay (gnus-make-overlay start end)))
8140 (gnus-overlay-put overlay 'evaporate t)
8141 (gnus-overlay-put overlay 'gnus-button-url
8142 (list (mapconcat 'identity (nreverse url) "")))
8143 (when gnus-article-mouse-face
8144 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8146 (goto-char opoint))))
8148 ;; Add buttons to the head of an article.
8149 (defun gnus-article-add-buttons-to-head ()
8150 "Add buttons to the head of the article."
8151 (interactive)
8152 (gnus-with-article-headers
8153 (let (beg end)
8154 (dolist (entry gnus-header-button-alist)
8155 ;; Each alist entry.
8156 (goto-char (point-min))
8157 (while (re-search-forward (car entry) nil t)
8158 ;; Each header matching the entry.
8159 (setq beg (match-beginning 0))
8160 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8161 (match-beginning 0))
8162 (point-max)))
8163 (goto-char beg)
8164 (while (re-search-forward (eval (nth 1 entry)) end t)
8165 ;; Each match within a header.
8166 (let* ((entry (cdr entry))
8167 (start (match-beginning (nth 1 entry)))
8168 (end (match-end (nth 1 entry)))
8169 (form (nth 2 entry)))
8170 (goto-char (match-end 0))
8171 (when (eval form)
8172 (gnus-article-add-button
8173 start end (nth 3 entry)
8174 (buffer-substring (match-beginning (nth 4 entry))
8175 (match-end (nth 4 entry)))))))
8176 (goto-char end))))))
8178 ;;; External functions:
8180 (defun gnus-article-add-button (from to fun &optional data text)
8181 "Create a button between FROM and TO with callback FUN and data DATA."
8182 (when gnus-article-button-face
8183 (gnus-overlay-put (gnus-make-overlay from to nil t)
8184 'face gnus-article-button-face))
8185 (gnus-add-text-properties
8186 from to
8187 (nconc (and gnus-article-mouse-face
8188 (list gnus-mouse-face-prop gnus-article-mouse-face))
8189 (list 'gnus-callback fun)
8190 (and data (list 'gnus-data data))))
8191 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8192 :help-echo (or text "Follow the link")
8193 :keymap gnus-url-button-map
8194 :button-keymap gnus-widget-button-keymap))
8196 (defun gnus-article-copy-string ()
8197 "Copy the string in the button to the kill ring."
8198 (interactive)
8199 (gnus-article-check-buffer)
8200 (let ((data (get-text-property (point) 'gnus-string)))
8201 (when data
8202 (with-temp-buffer
8203 (insert data)
8204 (copy-region-as-kill (point-min) (point-max))
8205 (message "Copied %s" data)))))
8207 ;;; Internal functions:
8209 (defun gnus-article-set-globals ()
8210 (with-current-buffer gnus-summary-buffer
8211 (gnus-set-global-variables)))
8213 (defun gnus-signature-toggle (end)
8214 (gnus-with-article-buffer
8215 (let ((inhibit-point-motion-hooks t))
8216 (if (text-property-any end (point-max) 'article-type 'signature)
8217 (progn
8218 (gnus-delete-wash-type 'signature)
8219 (gnus-remove-text-properties-when
8220 'article-type 'signature end (point-max)
8221 (cons 'article-type (cons 'signature
8222 gnus-hidden-properties))))
8223 (gnus-add-wash-type 'signature)
8224 (gnus-add-text-properties-when
8225 'article-type nil end (point-max)
8226 (cons 'article-type (cons 'signature
8227 gnus-hidden-properties)))))
8228 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8229 (gnus-set-mode-line 'article))))
8231 (defun gnus-button-push (marker-and-entry)
8232 ;; Push button starting at MARKER.
8233 (save-excursion
8234 (let* ((marker (car marker-and-entry))
8235 (entry (cadr marker-and-entry))
8236 (regexp (car entry))
8237 (inhibit-point-motion-hooks t))
8238 (goto-char marker)
8239 ;; This is obviously true, or something bad is happening :)
8240 ;; But we need it to have the match-data
8241 (when (looking-at (or (if (symbolp regexp)
8242 (symbol-value regexp)
8243 regexp)))
8244 (let ((fun (nth 3 entry))
8245 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8246 (get-char-property marker 'gnus-button-url))
8247 (mapcar (lambda (group)
8248 (let ((string (match-string group)))
8249 (set-text-properties
8250 0 (length string) nil string)
8251 string))
8252 (nthcdr 4 entry)))))
8254 (cond
8255 ((fboundp fun)
8256 (apply fun args))
8257 ((and (boundp fun)
8258 (fboundp (symbol-value fun)))
8259 (apply (symbol-value fun) args))
8261 (gnus-message 1 "You must define `%S' to use this button"
8262 (cons fun args)))))))))
8264 (defun gnus-parse-news-url (url)
8265 (let (scheme server port group message-id articles)
8266 (with-temp-buffer
8267 (insert url)
8268 (goto-char (point-min))
8269 (when (looking-at "\\([A-Za-z]+\\):")
8270 (setq scheme (match-string 1))
8271 (goto-char (match-end 0)))
8272 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8273 (setq server (match-string 1))
8274 (setq port (if (stringp (match-string 3))
8275 (string-to-number (match-string 3))
8276 (match-string 3)))
8277 (goto-char (match-end 0)))
8279 (cond
8280 ((looking-at "\\(.*@.*\\)")
8281 (setq message-id (match-string 1)))
8282 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8283 (setq group (match-string 1)
8284 articles (split-string (match-string 2) "-")))
8285 ((looking-at "\\([^/]+\\)/?")
8286 (setq group (match-string 1)))
8288 (error "Unknown news URL syntax"))))
8289 (list scheme server port group message-id articles)))
8291 (defvar nntp-port-number)
8293 (defun gnus-button-handle-news (url)
8294 "Fetch a news URL."
8295 (destructuring-bind (_scheme server port group message-id _articles)
8296 (gnus-parse-news-url url)
8297 (cond
8298 (message-id
8299 (with-current-buffer gnus-summary-buffer
8300 (if server
8301 (let ((gnus-refer-article-method
8302 (nconc (list (list 'nntp server))
8303 gnus-refer-article-method))
8304 (nntp-port-number (or port "nntp")))
8305 (gnus-message 7 "Fetching %s with %s"
8306 message-id gnus-refer-article-method)
8307 (gnus-summary-refer-article message-id))
8308 (gnus-summary-refer-article message-id))))
8309 (group
8310 (gnus-button-fetch-group url)))))
8312 (defun gnus-button-patch (library line)
8313 "Visit an Emacs Lisp library LIBRARY on line LINE."
8314 (interactive)
8315 (let ((file (locate-library (file-name-nondirectory library))))
8316 (unless file
8317 (error "Couldn't find library %s" library))
8318 (find-file file)
8319 (goto-char (point-min))
8320 (forward-line (1- (string-to-number line)))))
8322 (defun gnus-button-handle-man (url)
8323 "Fetch a man page."
8324 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8325 (when (eq gnus-button-man-handler 'woman)
8326 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8327 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8328 (funcall gnus-button-man-handler url))
8330 (defun gnus-button-handle-info-url (url)
8331 "Fetch an info URL."
8332 (setq url (mm-subst-char-in-string ?+ ?\ url))
8333 (cond
8334 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8335 (gnus-info-find-node
8336 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8337 "Gnus")
8338 ")" (gnus-url-unhex-string (match-string 2 url)))))
8339 ((string-match "([^)\"]+)[^\"]+" url)
8340 (setq url
8341 (gnus-replace-in-string
8342 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8343 (gnus-info-find-node url))
8344 (t (error "Can't parse %s" url))))
8346 (defun gnus-button-handle-info-url-gnome (url)
8347 "Fetch GNOME style info URL."
8348 (setq url (mm-subst-char-in-string ?_ ?\ url))
8349 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8350 (gnus-info-find-node
8351 (concat "("
8352 (gnus-url-unhex-string
8353 (match-string 1 url))
8355 (or (gnus-url-unhex-string
8356 (match-string 2 url))
8357 "Top")))
8358 (error "Can't parse %s" url)))
8360 (defun gnus-button-handle-info-url-kde (url)
8361 "Fetch KDE style info URL."
8362 (gnus-info-find-node (gnus-url-unhex-string url)))
8364 ;; (info) will autoload info.el
8365 (declare-function Info-menu "info" (menu-item &optional fork))
8366 (declare-function Info-index-next "info" (num))
8368 (defun gnus-button-handle-info-keystrokes (url)
8369 "Call `info' when pushing the corresponding URL button."
8370 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8371 (let (node indx comma)
8372 (if (string-match
8373 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8374 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8375 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8376 "\\(?:[ \t\n,]*\\)\\)?")
8377 url)
8378 (setq node (match-string 2 url)
8379 indx (match-string 3 url))
8380 (error "Can't parse %s" url))
8381 (info)
8382 (Info-directory)
8383 (Info-menu node)
8384 (when (> (length indx) 0)
8385 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8386 "\\([ \t\n,]*\\)")
8387 indx)
8388 (setq comma (match-string 2 indx))
8389 (setq indx (match-string 1 indx))
8390 (Info-index indx)
8391 (when comma
8392 (dotimes (i (with-temp-buffer
8393 (insert comma)
8394 ;; Note: the XEmacs version of `how-many' takes
8395 ;; no optional argument.
8396 (goto-char (point-min))
8397 (how-many ",")))
8398 (Info-index-next 1)))
8399 nil)))
8401 (autoload 'pgg-snarf-keys-region "pgg")
8402 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8403 (declare-function pgg-display-output-buffer "pgg" (start end status))
8405 (defun gnus-button-openpgp (url)
8406 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8407 (with-temp-buffer
8408 (mm-url-insert-file-contents-external url)
8409 (pgg-snarf-keys-region (point-min) (point-max))
8410 (pgg-display-output-buffer nil nil nil)))
8412 (defun gnus-button-message-id (message-id)
8413 "Fetch MESSAGE-ID."
8414 (with-current-buffer gnus-summary-buffer
8415 (gnus-summary-refer-article message-id)))
8417 (defun gnus-button-fetch-group (address &rest _ignore)
8418 "Fetch GROUP specified by ADDRESS."
8419 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8420 address)
8421 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8422 ;; for nntp:// and news://
8423 (setq address (match-string 3 address)))
8424 (if (not (string-match "[:/]" address))
8425 ;; This is just a simple group url.
8426 (gnus-group-read-ephemeral-group address gnus-select-method)
8427 (if (not
8428 (string-match
8429 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8430 address))
8431 (error "Can't parse %s" address)
8432 (gnus-group-read-ephemeral-group
8433 (match-string 4 address)
8434 `(nntp ,(match-string 1 address)
8435 (nntp-address ,(match-string 1 address))
8436 (nntp-port-number ,(if (match-end 3)
8437 (match-string 3 address)
8438 "nntp")))
8439 nil nil nil
8440 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8442 (defun gnus-url-parse-query-string (query &optional downcase)
8443 (let (retval pairs cur key val)
8444 (setq pairs (split-string query "&"))
8445 (while pairs
8446 (setq cur (car pairs)
8447 pairs (cdr pairs))
8448 (if (not (string-match "=" cur))
8449 nil ; Grace
8450 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8451 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8452 (if downcase
8453 (setq key (downcase key)))
8454 (setq cur (assoc key retval))
8455 (if cur
8456 (setcdr cur (cons val (cdr cur)))
8457 (setq retval (cons (list key val) retval)))))
8458 retval))
8460 (defun gnus-url-mailto (url)
8461 ;; Send mail to someone
8462 (setq url (replace-regexp-in-string "\n" " " url))
8463 (when (string-match "mailto:/*\\(.*\\)" url)
8464 (setq url (substring url (match-beginning 1) nil)))
8465 (let* ((args (gnus-url-parse-query-string
8466 (if (string-match "^\\?" url)
8467 (substring url 1)
8468 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8469 (concat "to=" (match-string 1 url) "&"
8470 (match-string 2 url))
8471 (concat "to=" url)))))
8472 (subject (cdr-safe (assoc "subject" args)))
8473 func)
8474 (gnus-msg-mail)
8475 (while args
8476 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8477 (if (fboundp func)
8478 (funcall func)
8479 (message-position-on-field (caar args)))
8480 (insert (gnus-replace-in-string
8481 (mapconcat 'identity (reverse (cdar args)) ", ")
8482 "\r\n" "\n" t))
8483 (setq args (cdr args)))
8484 (if subject
8485 (message-goto-body)
8486 (message-goto-subject))))
8488 (defun gnus-button-embedded-url (address)
8489 "Activate ADDRESS with `browse-url'."
8490 (browse-url (gnus-strip-whitespace address)))
8492 ;;; Next/prev buttons in the article buffer.
8494 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8495 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8497 (defvar gnus-prev-page-map
8498 (let ((map (make-sparse-keymap)))
8499 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8500 (define-key map "\r" 'gnus-button-prev-page)
8501 map))
8503 (defvar gnus-next-page-map
8504 (let ((map (make-sparse-keymap)))
8505 (define-key map gnus-mouse-2 'gnus-button-next-page)
8506 (define-key map "\r" 'gnus-button-next-page)
8507 map))
8509 (defun gnus-insert-prev-page-button ()
8510 (let ((b (point)) e
8511 (inhibit-read-only t))
8512 (gnus-eval-format
8513 gnus-prev-page-line-format nil
8514 `(keymap ,gnus-prev-page-map
8515 gnus-prev t
8516 gnus-callback gnus-article-button-prev-page
8517 article-type annotation))
8518 (setq e (if (bolp)
8519 ;; Exclude a newline.
8520 (1- (point))
8521 (point)))
8522 (when gnus-article-button-face
8523 (gnus-overlay-put (gnus-make-overlay b e nil t)
8524 'face gnus-article-button-face))
8525 (widget-convert-button
8526 'link b e
8527 :action 'gnus-button-prev-page
8528 :button-keymap gnus-prev-page-map)))
8530 (defun gnus-button-next-page (&optional _args _more-args)
8531 "Go to the next page."
8532 (interactive)
8533 (let ((win (selected-window)))
8534 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8535 (gnus-article-next-page)
8536 (select-window win)))
8538 (defun gnus-button-prev-page (&optional _args _more-args)
8539 "Go to the prev page."
8540 (interactive)
8541 (let ((win (selected-window)))
8542 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8543 (gnus-article-prev-page)
8544 (select-window win)))
8546 (defun gnus-insert-next-page-button ()
8547 (let ((b (point)) e
8548 (inhibit-read-only t))
8549 (gnus-eval-format gnus-next-page-line-format nil
8550 `(keymap ,gnus-next-page-map
8551 gnus-next t
8552 gnus-callback gnus-article-button-next-page
8553 article-type annotation))
8554 (setq e (if (bolp)
8555 ;; Exclude a newline.
8556 (1- (point))
8557 (point)))
8558 (when gnus-article-button-face
8559 (gnus-overlay-put (gnus-make-overlay b e nil t)
8560 'face gnus-article-button-face))
8561 (widget-convert-button
8562 'link b e
8563 :action 'gnus-button-next-page
8564 :button-keymap gnus-next-page-map)))
8566 (defun gnus-article-button-next-page (_arg)
8567 "Go to the next page."
8568 (interactive "P")
8569 (let ((win (selected-window)))
8570 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8571 (gnus-article-next-page)
8572 (select-window win)))
8574 (defun gnus-article-button-prev-page (_arg)
8575 "Go to the prev page."
8576 (interactive "P")
8577 (let ((win (selected-window)))
8578 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8579 (gnus-article-prev-page)
8580 (select-window win)))
8582 (defvar gnus-decode-header-methods
8583 '(mail-decode-encoded-word-region)
8584 "List of methods used to decode headers.
8586 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8587 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8588 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8589 whose names match REGEXP.
8591 For example:
8592 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8593 mail-decode-encoded-word-region
8594 (\"chinese\" . rfc1843-decode-region))
8597 (defvar gnus-decode-header-methods-cache nil)
8599 (defun gnus-multi-decode-header (start end)
8600 "Apply the functions from `gnus-encoded-word-methods' that match."
8601 (unless (and gnus-decode-header-methods-cache
8602 (eq gnus-newsgroup-name
8603 (car gnus-decode-header-methods-cache)))
8604 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8605 (dolist (x gnus-decode-header-methods)
8606 (if (symbolp x)
8607 (nconc gnus-decode-header-methods-cache (list x))
8608 (if (and gnus-newsgroup-name
8609 (string-match (car x) gnus-newsgroup-name))
8610 (nconc gnus-decode-header-methods-cache
8611 (list (cdr x)))))))
8612 (let ((xlist gnus-decode-header-methods-cache))
8613 (pop xlist)
8614 (save-restriction
8615 (narrow-to-region start end)
8616 (while xlist
8617 (funcall (pop xlist) (point-min) (point-max))))))
8620 ;;; Treatment top-level handling.
8623 (defvar gnus-inhibit-article-treatments nil)
8625 ;; Dynamic variables.
8626 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8627 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8628 (defvar gnus-treat-type)
8629 (defvar gnus-treat-condition)
8630 (defvar gnus-treat-length)
8632 (defun gnus-treat-article (condition
8633 &optional part-num total type)
8634 (let ((gnus-treat-condition condition)
8635 (part-number part-num)
8636 (total-parts total)
8637 (gnus-treat-type type)
8638 (gnus-treat-length (- (point-max) (point-min)))
8639 (alist gnus-treatment-function-alist)
8640 (article-goto-body-goes-to-point-min-p t)
8641 (treated-type
8642 (or (not type)
8643 (catch 'found
8644 (let ((list gnus-article-treat-types))
8645 (while list
8646 (when (string-match (pop list) type)
8647 (throw 'found t)))))))
8648 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8649 val)
8650 (gnus-run-hooks 'gnus-part-display-hook)
8651 (dolist (elem alist)
8652 (setq val
8653 (save-excursion
8654 (when (gnus-buffer-live-p gnus-summary-buffer)
8655 (set-buffer gnus-summary-buffer))
8656 (symbol-value (car elem))))
8657 (when (and (or (consp val)
8658 treated-type)
8659 (or (not gnus-inhibit-article-treatments)
8660 (eq gnus-treat-condition 'head))
8661 (gnus-treat-predicate val)
8662 (or (not (get (car elem) 'highlight))
8663 highlightp))
8664 (save-restriction
8665 (funcall (cadr elem)))))))
8667 (defun gnus-treat-predicate (val)
8668 (cond
8669 ((null val)
8670 nil)
8671 (gnus-treat-condition
8672 (eq gnus-treat-condition val))
8673 ((and (listp val)
8674 (stringp (car val)))
8675 (apply 'gnus-or (mapcar `(lambda (s)
8676 (string-match s ,(or gnus-newsgroup-name "")))
8677 val)))
8678 ((listp val)
8679 (let ((pred (pop val)))
8680 (cond
8681 ((eq pred 'or)
8682 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8683 ((eq pred 'and)
8684 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8685 ((eq pred 'not)
8686 (not (gnus-treat-predicate (car val))))
8687 ((eq pred 'typep)
8688 (equal (car val) gnus-treat-type))
8689 ((functionp pred)
8690 (funcall pred))
8692 (error "%S is not a valid predicate" pred)))))
8693 ((eq val t)
8695 ((eq val 'head)
8696 nil)
8697 ((eq val 'first)
8698 (eq part-number 1))
8699 ((eq val 'last)
8700 (eq part-number total-parts))
8701 ((numberp val)
8702 (< gnus-treat-length val))
8704 (error "%S is not a valid value" val))))
8706 (defun gnus-article-encrypt-body (protocol &optional n)
8707 "Encrypt the article body."
8708 (interactive
8709 (list
8710 (or gnus-article-encrypt-protocol
8711 (gnus-completing-read "Encrypt protocol"
8712 (mapcar 'car gnus-article-encrypt-protocol-alist)
8714 current-prefix-arg))
8715 ;; User might hit `K E' instead of `K e', so prompt once.
8716 (when (and gnus-article-encrypt-protocol
8717 gnus-novice-user)
8718 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8719 (error "Encrypt aborted")))
8720 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8721 (unless func
8722 (error "Can't find the encrypt protocol %s" protocol))
8723 (if (member gnus-newsgroup-name '("nndraft:delayed"
8724 "nndraft:drafts"
8725 "nndraft:queue"))
8726 (error "Can't encrypt the article in group %s"
8727 gnus-newsgroup-name))
8728 (gnus-summary-iterate n
8729 (with-current-buffer gnus-summary-buffer
8730 (let ((mail-parse-charset gnus-newsgroup-charset)
8731 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8732 (summary-buffer gnus-summary-buffer)
8733 references point)
8734 (gnus-set-global-variables)
8735 (when (gnus-group-read-only-p)
8736 (error "The current newsgroup does not support article encrypt"))
8737 (gnus-summary-show-article t)
8738 (setq references
8739 (or (mail-header-references gnus-current-headers) ""))
8740 (set-buffer gnus-article-buffer)
8741 (let* ((inhibit-read-only t)
8742 (headers
8743 (mapcar (lambda (field)
8744 (and (save-restriction
8745 (message-narrow-to-head)
8746 (goto-char (point-min))
8747 (search-forward field nil t))
8748 (prog2
8749 (message-narrow-to-field)
8750 (buffer-string)
8751 (delete-region (point-min) (point-max))
8752 (widen))))
8753 '("Content-Type:" "Content-Transfer-Encoding:"
8754 "Content-Disposition:"))))
8755 (message-narrow-to-head)
8756 (message-remove-header "MIME-Version")
8757 (goto-char (point-max))
8758 (setq point (point))
8759 (insert (apply 'concat headers))
8760 (widen)
8761 (narrow-to-region point (point-max))
8762 (let ((message-options message-options))
8763 (message-options-set 'message-sender user-mail-address)
8764 (message-options-set 'message-recipients user-mail-address)
8765 (message-options-set 'message-sign-encrypt 'not)
8766 (funcall func))
8767 (goto-char (point-min))
8768 (insert "MIME-Version: 1.0\n")
8769 (widen)
8770 (gnus-summary-edit-article-done
8771 references nil summary-buffer t))
8772 (when gnus-keep-backlog
8773 (gnus-backlog-remove-article
8774 (car gnus-article-current) (cdr gnus-article-current)))
8775 (gnus-flush-original-article-buffer)
8776 (when gnus-use-cache
8777 (gnus-cache-update-article
8778 (car gnus-article-current) (cdr gnus-article-current))))))))
8780 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8781 "The following specs can be used:
8782 %t The security MIME type
8783 %i Additional info
8784 %d Details
8785 %D Details if button is pressed")
8787 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8788 "The following specs can be used:
8789 %t The security MIME type
8790 %i Additional info
8791 %d Details
8792 %D Details if button is pressed")
8794 (defvar gnus-mime-security-button-line-format-alist
8795 '((?t gnus-tmp-type ?s)
8796 (?i gnus-tmp-info ?s)
8797 (?d gnus-tmp-details ?s)
8798 (?D gnus-tmp-pressed-details ?s)))
8800 (defvar gnus-mime-security-button-commands
8801 '((gnus-article-press-button "\r" "Show Detail")
8802 (undefined "v")
8803 (undefined "t")
8804 (undefined "C")
8805 (gnus-mime-security-save-part "o" "Save...")
8806 (undefined "\C-o")
8807 (undefined "r")
8808 (undefined "d")
8809 (undefined "c")
8810 (undefined "i")
8811 (undefined "E")
8812 (undefined "e")
8813 (undefined "p")
8814 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8815 (undefined ".")))
8817 (defvar gnus-mime-security-button-map
8818 (let ((map (make-sparse-keymap)))
8819 (define-key map gnus-mouse-2 'gnus-article-push-button)
8820 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8821 (dolist (c gnus-mime-security-button-commands)
8822 (define-key map (cadr c) (car c)))
8823 map))
8825 (easy-menu-define
8826 gnus-mime-security-button-menu gnus-mime-security-button-map
8827 "Security button menu."
8828 `("Security Part"
8829 ,@(delq nil
8830 (mapcar (lambda (c)
8831 (unless (eq (car c) 'undefined)
8832 (vector (caddr c) (car c) :active t)))
8833 gnus-mime-security-button-commands))))
8835 (defun gnus-mime-security-button-menu (event prefix)
8836 "Construct a context-sensitive menu of security commands."
8837 (interactive "e\nP")
8838 (save-window-excursion
8839 (let ((pos (event-start event)))
8840 (select-window (posn-window pos))
8841 (goto-char (posn-point pos))
8842 (gnus-article-check-buffer)
8843 (popup-menu gnus-mime-security-button-menu nil prefix))))
8845 (defvar gnus-mime-security-details-buffer nil)
8847 (defvar gnus-mime-security-button-pressed nil)
8849 (defvar gnus-mime-security-show-details-inline t
8850 "If non-nil, show details in the article buffer.")
8852 (defun gnus-mime-security-verify-or-decrypt (handle)
8853 (mm-remove-parts (cdr handle))
8854 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8855 point (inhibit-read-only t))
8856 (if region
8857 (goto-char (car region)))
8858 (setq point (point))
8859 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8860 (let* ((mm-verify-option 'known)
8861 (mm-decrypt-option 'known)
8862 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8863 (unless (eq nparts (cdr handle))
8864 (mm-destroy-parts (cdr handle))
8865 (setcdr handle nparts))))
8866 (gnus-mime-display-security handle)
8867 (when region
8868 (delete-region (point) (cdr region))
8869 (set-marker (car region) nil)
8870 (set-marker (cdr region) nil))
8871 (goto-char point)))
8873 (defun gnus-mime-security-show-details (handle)
8874 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8875 (if (not details)
8876 (gnus-message 5 "No details.")
8877 (if gnus-mime-security-show-details-inline
8878 (let ((gnus-mime-security-button-pressed
8879 (not (get-text-property (point) 'gnus-mime-details)))
8880 (gnus-mime-security-button-line-format
8881 (get-text-property (point) 'gnus-line-format))
8882 (inhibit-read-only t))
8883 (forward-char -1)
8884 (while (eq (get-text-property (point) 'gnus-line-format)
8885 gnus-mime-security-button-line-format)
8886 (forward-char -1))
8887 (forward-char)
8888 (save-restriction
8889 (narrow-to-region (point) (point))
8890 (gnus-insert-mime-security-button handle))
8891 (delete-region (point)
8892 (or (text-property-not-all
8893 (point) (point-max)
8894 'gnus-line-format
8895 gnus-mime-security-button-line-format)
8896 (point-max))))
8897 ;; Not inlined.
8898 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8899 (with-current-buffer gnus-mime-security-details-buffer
8900 (erase-buffer)
8902 (setq gnus-mime-security-details-buffer
8903 (gnus-get-buffer-create "*MIME Security Details*")))
8904 (with-current-buffer gnus-mime-security-details-buffer
8905 (insert details)
8906 (goto-char (point-min)))
8907 (pop-to-buffer gnus-mime-security-details-buffer)))))
8909 (defun gnus-mime-security-press-button (handle)
8910 (save-excursion
8911 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8912 (gnus-mime-security-show-details handle)
8913 (gnus-mime-security-verify-or-decrypt handle))))
8915 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8916 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8917 (gnus-tmp-type
8918 (concat
8919 (or (nth 2 (assoc protocol mm-verify-function-alist))
8920 (nth 2 (assoc protocol mm-decrypt-function-alist))
8921 "Unknown")
8922 (if (equal (car handle) "multipart/signed")
8923 " Signed" " Encrypted")
8924 " Part"))
8925 (gnus-tmp-info
8926 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8927 "Undecided"))
8928 (gnus-tmp-details
8929 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8930 gnus-tmp-pressed-details
8931 b e)
8932 (setq gnus-tmp-details
8933 (if gnus-tmp-details
8934 (concat "\n" gnus-tmp-details)
8935 ""))
8936 (setq gnus-tmp-pressed-details
8937 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8938 (unless (bolp)
8939 (insert "\n"))
8940 (setq b (point))
8941 (gnus-eval-format
8942 gnus-mime-security-button-line-format
8943 gnus-mime-security-button-line-format-alist
8944 `(keymap ,gnus-mime-security-button-map
8945 gnus-callback gnus-mime-security-press-button
8946 gnus-line-format ,gnus-mime-security-button-line-format
8947 gnus-mime-details ,gnus-mime-security-button-pressed
8948 article-type annotation
8949 gnus-data ,handle))
8950 (setq e (if (bolp)
8951 ;; Exclude a newline.
8952 (1- (point))
8953 (point)))
8954 (when gnus-article-button-face
8955 (gnus-overlay-put (gnus-make-overlay b e nil t)
8956 'face gnus-article-button-face))
8957 (widget-convert-button
8958 'link b e
8959 :mime-handle handle
8960 :action 'gnus-widget-press-button
8961 :button-keymap gnus-mime-security-button-map
8962 :help-echo
8963 (lambda (_widget)
8964 ;; Needed to properly clear the message due to a bug in
8965 ;; wid-edit (XEmacs only).
8966 (when (boundp 'help-echo-owns-message)
8967 (setq help-echo-owns-message t))
8968 (format
8969 "%S: show detail; %S: more options"
8970 (aref gnus-mouse-2 0)
8971 (aref gnus-down-mouse-3 0))))))
8973 (defun gnus-mime-display-security (handle)
8974 (save-restriction
8975 (narrow-to-region (point) (point))
8976 (unless (gnus-unbuttonized-mime-type-p (car handle))
8977 (gnus-insert-mime-security-button handle))
8978 (gnus-mime-display-part (cadr handle))
8979 (unless (bolp)
8980 (insert "\n"))
8981 (unless (gnus-unbuttonized-mime-type-p (car handle))
8982 (let ((gnus-mime-security-button-line-format
8983 gnus-mime-security-button-end-line-format))
8984 (gnus-insert-mime-security-button handle)))
8985 (mm-set-handle-multipart-parameter
8986 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8987 (goto-char (point-max))))
8989 (defun gnus-mime-security-run-function (function)
8990 "Run FUNCTION with the security part under point."
8991 (gnus-article-check-buffer)
8992 (let ((data (get-text-property (point) 'gnus-data))
8993 buffer handle)
8994 (when (and (stringp (car-safe data))
8995 (setq buffer (mm-handle-multipart-original-buffer data))
8996 (setq handle (cadr data)))
8997 (if (bufferp (mm-handle-buffer handle))
8998 (progn
8999 (setq handle (cons buffer (copy-sequence (cdr handle))))
9000 (mm-handle-set-undisplayer handle nil))
9001 (setq handle (mm-make-handle
9002 buffer
9003 (mm-handle-multipart-ctl-parameter handle 'protocol)
9004 nil nil nil nil nil nil)))
9005 (funcall function handle))))
9007 (defun gnus-mime-security-save-part ()
9008 "Save the security part under point."
9009 (interactive)
9010 (gnus-mime-security-run-function 'mm-save-part))
9012 (defun gnus-mime-security-pipe-part ()
9013 "Pipe the security part under point to a process."
9014 (interactive)
9015 (gnus-mime-security-run-function 'mm-pipe-part))
9017 (gnus-ems-redefine)
9019 (provide 'gnus-art)
9021 (run-hooks 'gnus-art-load-hook)
9023 ;;; gnus-art.el ends here