]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
Merge from emacs-24; up to 2014-04-04T23:31:02Z!joaotavora@gmail.com
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
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)
45
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")
53
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
58
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
63
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
68
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
74
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
79
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
84
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
89
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
94
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
99
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
104
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
109
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
114
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)
166
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)
182
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)
192
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:
196
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)
218
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)
228
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)
238
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.
247
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)
255
256 (defcustom gnus-hidden-properties '(invisible t intangible t)
257 "Property list to use for hiding text."
258 :type 'sexp
259 :group 'gnus-article-hiding)
260
261 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
262 ;; frames in a session.
263 (defcustom gnus-article-x-face-command
264 (if (featurep 'xemacs)
265 (if (or (gnus-image-type-available-p 'xface)
266 (gnus-image-type-available-p 'pbm))
267 'gnus-display-x-face-in-from
268 "{ echo \
269 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
270 ; uncompface; } | icontopbm | ee -")
271 (if (gnus-image-type-available-p 'pbm)
272 'gnus-display-x-face-in-from
273 "{ echo \
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | display -"))
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
281 function)
282 :version "21.1"
283 :group 'gnus-picon
284 :group 'gnus-article-washing)
285
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
290
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
293 For example,
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295 :version "21.1"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
298
299 (gnus-define-group-parameter
300 banner
301 :variable-document
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
304 :parameter-type
305 '(choice :tag "Banner"
306 :value nil
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
309 regexp
310 (const :tag "None" nil))
311 :parameter-document
312 "If non-nil, specify how to remove `banners' from articles.
313
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
319
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
327
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
329 "
330 :type '(repeat
331 (cons
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
336 regexp
337 (const :tag "None" nil))))
338 :version "22.1"
339 :group 'gnus-article-washing)
340
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342 `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345 ,@body))
346
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
351 2
352 (if (nth 1 value) 2 3)
353 (nth 2 value))
354 value)))
355
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
361 "\\'"))
362 pattern)
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
365 (= (nth 2 value) 2)
366 (nth 3 value))
367 value))))
368
369 (defcustom gnus-emphasis-alist
370 (let ((types
371 '(("\\*" "\\*" bold nil 2)
372 ("_" "_" underline)
373 ("/" "/" italic)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
378 (nconc
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
382 (or (nth 3 spec) 2)
383 (or (nth 4 spec) 3)
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385 types))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
396
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
398
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
404 :type
405 '(repeat
406 (menu-choice
407 :format "%[Customizing Style%]\n%v"
408 :indent 2
409 (group :tag "Default"
410 :value ("" 0 0 default)
411 :value-create
412 (lambda (widget)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
415 :args))
416 :value)))
417 (if (not (eq (nth 2 value) 'default))
418 (widget-put
419 widget
420 :value
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
423 regexp
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
426 face)
427 (group :tag "Simple"
428 :value (("_" . "_") nil default)
429 (cons :format "%v"
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
434 face)))
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440 value)))
441 :group 'gnus-article-emphasis)
442
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448 :version "21.1"
449 :group 'gnus-article-emphasis
450 :type 'regexp)
451
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
455
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
459
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
463
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
467
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
475
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
492
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
496
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
503
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509 :group 'gnus-article-saving
510 :type 'boolean)
511
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
524
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
534 :type 'regexp)
535
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favorite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
541
542 Gnus provides the following functions:
543
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
553
554 The symbol of each function may have the following properties:
555
556 * :decode
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
561
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
584 (function)))
585
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
592
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
595 commands including:
596
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
601
602 and the functions to which you may set `gnus-default-article-saver':
603
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
608
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
614 :type `(choice
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
617 ,@(delq nil
618 (mapcar
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
625
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
630 :type 'function)
631
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
637
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
642 :type 'function)
643
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
647 LAST-FILE."
648 :group 'gnus-article-saving
649 :type 'function)
650
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
658
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
661
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
664 non-nil.
665
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evalled in the same buffer.
670
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
677 (sexp :value nil))))
678
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
683 :type 'regexp
684 :group 'gnus-article-various)
685
686 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
689
690 The following additional specs are available:
691
692 %w The article washing status.
693 %m The number of MIME parts in the article."
694 :version "24.1"
695 :type 'string
696 :group 'gnus-article-various)
697
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
700 :type 'hook
701 :group 'gnus-article-various)
702
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
709
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
714
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
719
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
726
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
729
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
734
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
737
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
742
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
745
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
750
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
757
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
767
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
775 (t
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
783
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
791 (t
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
799
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
807 (t
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
817
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
825 (t
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
833
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
841 (t
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
848
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
855
856 An alist of the form (HEADER NAME CONTENT).
857
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
860
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
874
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
878 (png . nil)))
879 "Alist of image types and properties applied to Face and X-Face images.
880 Here are examples:
881
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
886
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
891
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
899
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
905 :type 'hook)
906
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
910 :type 'function)
911
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
914
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
917
918 (defvar gnus-article-dumbquotes-map
919 '((?\200 "EUR")
920 (?\202 ",")
921 (?\203 "f")
922 (?\204 ",,")
923 (?\205 "...")
924 (?\213 "<")
925 (?\214 "OE")
926 (?\221 "`")
927 (?\222 "'")
928 (?\223 "``")
929 (?\224 "\"")
930 (?\225 "*")
931 (?\226 "-")
932 (?\227 "--")
933 (?\230 "~")
934 (?\231 "(TM)")
935 (?\233 ">")
936 (?\234 "oe")
937 (?\264 "'"))
938 "Table for MS-to-Latin1 translation.")
939
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
945
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :version "21.1"
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
953
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :version "22.1"
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
965
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
971 :version "22.1"
972 :group 'gnus-article-mime
973 :type 'boolean)
974
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
979 :version "22.1"
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
982 string))
983
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "/usr/share/picons")
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :version "22.1"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
994 :group 'gnus-picon)
995
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1002 installed))
1003
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1010 function))
1011
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1014 :version "21.1"
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1017
1018 (defcustom gnus-article-date-headers '(combined-lapsed)
1019 "A list of Date header formats to display.
1020 Valid formats are `ut' (universal time), `local' (local time
1021 zone), `english' (readable English), `lapsed' (elapsed time),
1022 `combined-lapsed' (both the original date and the elapsed time),
1023 `original' (the original date header), `iso8601' (ISO8601
1024 format), and `user-defined' (a user-defined format defined by the
1025 `gnus-article-time-format' variable).
1026
1027 You have as many date headers as you want in the article buffer.
1028 Some of these headers are updated automatically. See
1029 `gnus-article-update-date-headers' for details."
1030 :version "24.1"
1031 :group 'gnus-article-headers
1032 :type '(set
1033 (const :tag "Universal time (UT)" ut)
1034 (const :tag "Local time zone" local)
1035 (const :tag "Readable English" english)
1036 (const :tag "Elapsed time" lapsed)
1037 (const :tag "Original and elapsed time" combined-lapsed)
1038 (const :tag "Original date header" original)
1039 (const :tag "ISO8601 format" iso8601)
1040 (const :tag "User-defined" user-defined)))
1041
1042 (defcustom gnus-article-update-date-headers nil
1043 "A number that says how often to update the date header (in seconds).
1044 If nil, don't update it at all."
1045 :version "24.1"
1046 :group 'gnus-article-headers
1047 :type '(choice
1048 (item :tag "Don't update" :value nil)
1049 integer))
1050
1051 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1052 "Function called with a MIME handle as the argument.
1053 This is meant for people who want to view first matched part.
1054 For `undisplayed-alternative' (default), the first undisplayed
1055 part or alternative part is used. For `undisplayed', the first
1056 undisplayed part is used. For a function, the first part which
1057 the function return t is used. For nil, the first part is
1058 used."
1059 :version "21.1"
1060 :group 'gnus-article-mime
1061 :type '(choice
1062 (item :tag "first" :value nil)
1063 (item :tag "undisplayed" :value undisplayed)
1064 (item :tag "undisplayed or alternative"
1065 :value undisplayed-alternative)
1066 (function)))
1067
1068 (defcustom gnus-mime-action-alist
1069 '(("save to file" . gnus-mime-save-part)
1070 ("save and strip" . gnus-mime-save-part-and-strip)
1071 ("replace with file" . gnus-mime-replace-part)
1072 ("delete part" . gnus-mime-delete-part)
1073 ("display as text" . gnus-mime-inline-part)
1074 ("view the part" . gnus-mime-view-part)
1075 ("pipe to command" . gnus-mime-pipe-part)
1076 ("toggle display" . gnus-article-press-button)
1077 ("toggle display" . gnus-article-view-part-as-charset)
1078 ("view as type" . gnus-mime-view-part-as-type)
1079 ("view internally" . gnus-mime-view-part-internally)
1080 ("view externally" . gnus-mime-view-part-externally))
1081 "An alist of actions that run on the MIME attachment."
1082 :group 'gnus-article-mime
1083 :type '(repeat (cons (string :tag "name")
1084 (function))))
1085
1086 (defcustom gnus-auto-select-part 1
1087 "Advance to next MIME part when deleting or stripping parts.
1088
1089 When 0, point will be placed on the same part as before. When
1090 positive (negative), move point forward (backwards) this many
1091 parts. When nil, redisplay article."
1092 :version "23.1" ;; No Gnus
1093 :group 'gnus-article-mime
1094 :type '(choice (const nil :tag "Redisplay article.")
1095 (const 1 :tag "Next part.")
1096 (const 0 :tag "Current part.")
1097 integer))
1098
1099 ;;;
1100 ;;; The treatment variables
1101 ;;;
1102
1103 (defvar gnus-part-display-hook nil
1104 "Hook called on parts that are to receive treatment.")
1105
1106 (defvar gnus-article-treat-custom
1107 '(choice (const :tag "Off" nil)
1108 (const :tag "On" t)
1109 (const :tag "Header" head)
1110 (const :tag "First" first)
1111 (const :tag "Last" last)
1112 (integer :tag "Less")
1113 (repeat :tag "Groups" regexp)
1114 (sexp :tag "Predicate")))
1115
1116 (defvar gnus-article-treat-head-custom
1117 '(choice (const :tag "Off" nil)
1118 (const :tag "Header" head)))
1119
1120 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1121 "text/x-patch" "text/html")
1122 "Part types eligible for treatment.")
1123
1124 (defvar gnus-inhibit-treatment nil
1125 "Whether to inhibit treatment.")
1126
1127 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1128 "Highlight the signature.
1129 Valid values are nil, t, `head', `first', `last', an integer or a
1130 predicate. See Info node `(gnus)Customizing Articles'."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134 (put 'gnus-treat-highlight-signature 'highlight t)
1135
1136 (defcustom gnus-treat-buttonize 100000
1137 "Add buttons.
1138 Valid values are nil, t, `head', `first', `last', an integer or a
1139 predicate. See Info node `(gnus)Customizing Articles'."
1140 :group 'gnus-article-treat
1141 :link '(custom-manual "(gnus)Customizing Articles")
1142 :type gnus-article-treat-custom)
1143 (put 'gnus-treat-buttonize 'highlight t)
1144
1145 (defcustom gnus-treat-buttonize-head 'head
1146 "Add buttons to the head.
1147 Valid values are nil, t, `head', `first', `last', an integer or a
1148 predicate. See Info node `(gnus)Customizing Articles'."
1149 :group 'gnus-article-treat
1150 :link '(custom-manual "(gnus)Customizing Articles")
1151 :type gnus-article-treat-head-custom)
1152 (put 'gnus-treat-buttonize-head 'highlight t)
1153
1154 (defcustom gnus-treat-date 'head
1155 "Display dates according to the `gnus-article-date-headers' variable.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate. See Info node `(gnus)Customizing Articles'."
1158 :version "24.1"
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1162
1163 (defcustom gnus-treat-emphasize 50000
1164 "Emphasize text.
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-custom)
1170 (put 'gnus-treat-emphasize 'highlight t)
1171
1172 (defcustom gnus-treat-strip-cr nil
1173 "Remove carriage returns.
1174 Valid values are nil, t, `head', `first', `last', an integer or a
1175 predicate. See Info node `(gnus)Customizing Articles'."
1176 :version "22.1"
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-custom)
1180
1181 (defcustom gnus-treat-unsplit-urls nil
1182 "Remove newlines from within URLs.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1185 :version "22.1"
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1189
1190 (defcustom gnus-treat-leading-whitespace nil
1191 "Remove leading whitespace in headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :version "22.1"
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1198
1199 (defcustom gnus-treat-hide-headers 'head
1200 "Hide headers.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1206
1207 (defcustom gnus-treat-hide-boring-headers nil
1208 "Hide boring headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1214
1215 (defcustom gnus-treat-hide-signature nil
1216 "Hide the signature.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1222
1223 (defcustom gnus-treat-fill-article nil
1224 "Fill the article.
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1230
1231 (defcustom gnus-treat-hide-citation nil
1232 "Hide cited text.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'.
1235
1236 See `gnus-article-highlight-citation' for variables used to
1237 control what it hides."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1241
1242 (defcustom gnus-treat-hide-citation-maybe nil
1243 "Hide cited text according to certain conditions.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'.
1246
1247 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1248 how to control what it hides."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1252
1253 (defcustom gnus-treat-strip-list-identifiers 'head
1254 "Strip list identifiers from `gnus-list-identifiers`.
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :version "21.1"
1258 :group 'gnus-article-treat
1259 :link '(custom-manual "(gnus)Customizing Articles")
1260 :type gnus-article-treat-custom)
1261
1262 (gnus-define-group-parameter
1263 list-identifier
1264 :variable-document
1265 "Alist of regexps and correspondent identifiers."
1266 :variable-group gnus-article-washing
1267 :parameter-type
1268 '(choice :tag "Identifier"
1269 :value nil
1270 (symbol :tag "Item in `gnus-list-identifiers'" none)
1271 regexp
1272 (const :tag "None" nil))
1273 :parameter-document
1274 "If non-nil, specify how to remove `identifiers' from articles' subject.
1275
1276 Any symbol is used to look up a regular expression to match the
1277 banner in `gnus-list-identifiers'. A string is used as a regular
1278 expression to match the identifier directly.")
1279
1280 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1281 "Gnus 5.10 (Emacs 22.1)")
1282
1283 (defcustom gnus-treat-strip-pem nil
1284 "Strip PEM signatures.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1287 :group 'gnus-article-treat
1288 :link '(custom-manual "(gnus)Customizing Articles")
1289 :type gnus-article-treat-custom)
1290
1291 (defcustom gnus-treat-strip-banner t
1292 "Strip banners from articles.
1293 The banner to be stripped is specified in the `banner' group parameter.
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-custom)
1299
1300 (defcustom gnus-treat-highlight-headers 'head
1301 "Highlight the headers.
1302 Valid values are nil, t, `head', `first', `last', an integer or a
1303 predicate. See Info node `(gnus)Customizing Articles'."
1304 :group 'gnus-article-treat
1305 :link '(custom-manual "(gnus)Customizing Articles")
1306 :type gnus-article-treat-head-custom)
1307 (put 'gnus-treat-highlight-headers 'highlight t)
1308
1309 (defcustom gnus-treat-highlight-citation t
1310 "Highlight cited text.
1311 Valid values are nil, t, `head', `first', `last', an integer or a
1312 predicate. See Info node `(gnus)Customizing Articles'."
1313 :group 'gnus-article-treat
1314 :link '(custom-manual "(gnus)Customizing Articles")
1315 :type gnus-article-treat-custom)
1316 (put 'gnus-treat-highlight-citation 'highlight t)
1317
1318 (defcustom gnus-treat-strip-headers-in-body t
1319 "Strip the X-No-Archive header line from the beginning of the body.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1322 :version "21.1"
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-custom)
1326
1327 (defcustom gnus-treat-strip-trailing-blank-lines nil
1328 "Strip trailing blank lines.
1329 Valid values are nil, t, `head', `first', `last', an integer or a
1330 predicate. See Info node `(gnus)Customizing Articles'.
1331
1332 When set to t, it also strips trailing blanks in all MIME parts.
1333 Consider to use `last' instead."
1334 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :type gnus-article-treat-custom)
1337
1338 (defcustom gnus-treat-strip-leading-blank-lines nil
1339 "Strip leading blank lines.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles'.
1342
1343 When set to t, it also strips trailing blanks in all MIME parts."
1344 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :type gnus-article-treat-custom)
1347
1348 (defcustom gnus-treat-strip-multiple-blank-lines nil
1349 "Strip multiple blank lines.
1350 Valid values are nil, t, `head', `first', `last', an integer or a
1351 predicate. See Info node `(gnus)Customizing Articles'."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1355
1356 (defcustom gnus-treat-unfold-headers 'head
1357 "Unfold folded header lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'."
1360 :version "22.1"
1361 :group 'gnus-article-treat
1362 :link '(custom-manual "(gnus)Customizing Articles")
1363 :type gnus-article-treat-custom)
1364
1365 (defcustom gnus-article-unfold-long-headers nil
1366 "If non-nil, allow unfolding headers even if the header is long.
1367 If it is a regexp, only long headers matching this regexp are unfolded.
1368 If it is t, all long headers are unfolded.
1369
1370 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1371 :version "23.1" ;; No Gnus
1372 :group 'gnus-article-treat
1373 :type '(choice (const nil)
1374 (const :tag "all" t)
1375 (regexp)))
1376
1377 (defcustom gnus-treat-fold-headers nil
1378 "Fold headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles'."
1381 :version "22.1"
1382 :group 'gnus-article-treat
1383 :link '(custom-manual "(gnus)Customizing Articles")
1384 :type gnus-article-treat-custom)
1385
1386 (defcustom gnus-treat-fold-newsgroups 'head
1387 "Fold the Newsgroups and Followup-To headers.
1388 Valid values are nil, t, `head', `first', `last', an integer or a
1389 predicate. See Info node `(gnus)Customizing Articles'."
1390 :version "22.1"
1391 :group 'gnus-article-treat
1392 :link '(custom-manual "(gnus)Customizing Articles")
1393 :type gnus-article-treat-custom)
1394
1395 (defcustom gnus-treat-overstrike t
1396 "Treat overstrike highlighting.
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1399 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :type gnus-article-treat-custom)
1402 (put 'gnus-treat-overstrike 'highlight t)
1403
1404 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1405 "Treat ANSI SGR control sequences.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1408 :group 'gnus-article-treat
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :type gnus-article-treat-custom)
1411
1412 (make-obsolete-variable 'gnus-treat-display-xface
1413 'gnus-treat-display-x-face "Emacs 22.1")
1414
1415 (defcustom gnus-treat-display-x-face
1416 (and (not noninteractive)
1417 (gnus-image-type-available-p 'xbm)
1418 (if (featurep 'xemacs)
1419 (featurep 'xface)
1420 (condition-case nil
1421 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1422 (executable-find "icontopbm"))
1423 ;; shell-command-to-string may signal an error, e.g. if
1424 ;; shell-file-name is not found.
1425 (error nil)))
1426 'head)
1427 "Display X-Face headers.
1428 Valid values are nil and `head'.
1429 See Info node `(gnus)Customizing Articles' and Info node
1430 `(gnus)X-Face' for details."
1431 :group 'gnus-article-treat
1432 :version "21.1"
1433 :link '(custom-manual "(gnus)Customizing Articles")
1434 :link '(custom-manual "(gnus)X-Face")
1435 :type gnus-article-treat-head-custom
1436 :set (lambda (symbol value)
1437 (set-default
1438 symbol
1439 (cond ((or (boundp symbol) (get symbol 'saved-value))
1440 value)
1441 ((boundp 'gnus-treat-display-xface)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (default-value 'gnus-treat-display-xface))
1446 ((get 'gnus-treat-display-xface 'saved-value)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1451 (t
1452 value)))))
1453 (put 'gnus-treat-display-x-face 'highlight t)
1454
1455 (defcustom gnus-treat-display-face
1456 (and (not noninteractive)
1457 (gnus-image-type-available-p 'png)
1458 'head)
1459 "Display Face headers.
1460 Valid values are nil, t, `head', `first', `last', an integer or a
1461 predicate. See Info node `(gnus)Customizing Articles' and Info
1462 node `(gnus)Face' for details."
1463 :group 'gnus-article-treat
1464 :version "22.1"
1465 :link '(custom-manual "(gnus)Customizing Articles")
1466 :link '(custom-manual "(gnus)X-Face")
1467 :type gnus-article-treat-head-custom)
1468 (put 'gnus-treat-display-face 'highlight t)
1469
1470 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1471 "Display smileys.
1472 Valid values are nil, t, `head', `first', `last', an integer or a
1473 predicate. See Info node `(gnus)Customizing Articles' and Info
1474 node `(gnus)Smileys' for details."
1475 :group 'gnus-article-treat
1476 :version "21.1"
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Smileys")
1479 :type gnus-article-treat-custom)
1480 (put 'gnus-treat-display-smileys 'highlight t)
1481
1482 (defcustom gnus-treat-from-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1485 'head nil)
1486 "Display picons in the From header.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1490 :version "22.1"
1491 :group 'gnus-article-treat
1492 :group 'gnus-picon
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-from-picon 'highlight t)
1497
1498 (defcustom gnus-treat-mail-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1501 'head nil)
1502 "Display picons in To and Cc headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1506 :version "22.1"
1507 :group 'gnus-article-treat
1508 :group 'gnus-picon
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-mail-picon 'highlight t)
1513
1514 (defcustom gnus-treat-newsgroups-picon
1515 (if (and (gnus-image-type-available-p 'xpm)
1516 (gnus-picons-installed-p))
1517 'head nil)
1518 "Display picons in the Newsgroups and Followup-To headers.
1519 Valid values are nil, t, `head', `first', `last', an integer or a
1520 predicate. See Info node `(gnus)Customizing Articles' and Info
1521 node `(gnus)Picons' for details."
1522 :version "22.1"
1523 :group 'gnus-article-treat
1524 :group 'gnus-picon
1525 :link '(custom-manual "(gnus)Customizing Articles")
1526 :link '(custom-manual "(gnus)Picons")
1527 :type gnus-article-treat-head-custom)
1528 (put 'gnus-treat-newsgroups-picon 'highlight t)
1529
1530 (defcustom gnus-treat-from-gravatar nil
1531 "Display gravatars in the From header.
1532 Valid values are nil, t, `head', `first', `last', an integer or a
1533 predicate. See Info node `(gnus)Customizing Articles' and Info
1534 node `(gnus)Gravatars' for details."
1535 :version "24.1"
1536 :group 'gnus-article-treat
1537 :group 'gnus-gravatar
1538 :link '(custom-manual "(gnus)Customizing Articles")
1539 :link '(custom-manual "(gnus)Gravatars")
1540 :type gnus-article-treat-head-custom)
1541 (put 'gnus-treat-from-gravatar 'highlight t)
1542
1543 (defcustom gnus-treat-mail-gravatar nil
1544 "Display gravatars in To and Cc headers.
1545 Valid values are nil, t, `head', `first', `last', an integer or a
1546 predicate. See Info node `(gnus)Customizing Articles' and Info
1547 node `(gnus)Gravatars' for details."
1548 :version "24.1"
1549 :group 'gnus-article-treat
1550 :group 'gnus-gravatar
1551 :link '(custom-manual "(gnus)Customizing Articles")
1552 :link '(custom-manual "(gnus)Gravatars")
1553 :type gnus-article-treat-head-custom)
1554 (put 'gnus-treat-mail-gravatar 'highlight t)
1555
1556 (defcustom gnus-treat-body-boundary
1557 (if (or gnus-treat-newsgroups-picon
1558 gnus-treat-mail-picon
1559 gnus-treat-from-picon
1560 gnus-treat-from-gravatar
1561 gnus-treat-mail-gravatar)
1562 ;; If there's much decoration, the user might prefer a boundary.
1563 'head
1564 nil)
1565 "Draw a boundary at the end of the headers.
1566 Valid values are nil and `head'.
1567 See Info node `(gnus)Customizing Articles' for details."
1568 :version "22.1"
1569 :group 'gnus-article-treat
1570 :link '(custom-manual "(gnus)Customizing Articles")
1571 :type gnus-article-treat-head-custom)
1572
1573 (defcustom gnus-treat-capitalize-sentences nil
1574 "Capitalize sentence-starting words.
1575 Valid values are nil, t, `head', `first', `last', an integer or a
1576 predicate. See Info node `(gnus)Customizing Articles'."
1577 :version "21.1"
1578 :group 'gnus-article-treat
1579 :link '(custom-manual "(gnus)Customizing Articles")
1580 :type gnus-article-treat-custom)
1581
1582 (defcustom gnus-treat-wash-html nil
1583 "Format as HTML.
1584 Valid values are nil, t, `head', `first', `last', an integer or a
1585 predicate. See Info node `(gnus)Customizing Articles'."
1586 :version "22.1"
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-custom)
1590
1591 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1592 "Fill long lines.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1595 :version "24.1"
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1599
1600 (defcustom gnus-treat-x-pgp-sig nil
1601 "Verify X-PGP-Sig.
1602 To automatically treat X-PGP-Sig, set it to head.
1603 Valid values are nil, t, `head', `first', `last', an integer or a
1604 predicate. See Info node `(gnus)Customizing Articles'."
1605 :version "22.1"
1606 :group 'gnus-article-treat
1607 :group 'mime-security
1608 :link '(custom-manual "(gnus)Customizing Articles")
1609 :type gnus-article-treat-custom)
1610
1611 (defvar gnus-article-encrypt-protocol-alist
1612 '(("PGP" . mml2015-self-encrypt)))
1613
1614 ;; Set to nil if more than one protocol added to
1615 ;; gnus-article-encrypt-protocol-alist.
1616 (defcustom gnus-article-encrypt-protocol "PGP"
1617 "The protocol used for encrypt articles.
1618 It is a string, such as \"PGP\". If nil, ask user."
1619 :version "22.1"
1620 :type 'string
1621 :group 'mime-security)
1622
1623 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1624 (mm-coding-system-p 'utf-8)
1625 (executable-find idna-program))
1626 "Whether IDNA decoding of headers is used when viewing messages.
1627 This requires GNU Libidn, and by default only enabled if it is found."
1628 :version "22.1"
1629 :group 'gnus-article-headers
1630 :type 'boolean)
1631
1632 (defcustom gnus-article-over-scroll nil
1633 "If non-nil, allow scrolling the article buffer even when there no more text."
1634 :version "22.1"
1635 :group 'gnus-article
1636 :type 'boolean)
1637
1638 (defcustom gnus-inhibit-images nil
1639 "Non-nil means inhibit displaying of images inline in the article body."
1640 :version "24.1"
1641 :group 'gnus-article
1642 :type 'boolean)
1643
1644 (defcustom gnus-blocked-images 'gnus-block-private-groups
1645 "Images that have URLs matching this regexp will be blocked.
1646 This can also be a function to be evaluated. If so, it will be
1647 called with the group name as the parameter, and should return a
1648 regexp."
1649 :version "24.1"
1650 :group 'gnus-art
1651 :type '(choice regexp function))
1652
1653 ;;; Internal variables
1654
1655 (defvar gnus-english-month-names
1656 '("January" "February" "March" "April" "May" "June" "July" "August"
1657 "September" "October" "November" "December"))
1658
1659 (defvar article-goto-body-goes-to-point-min-p nil)
1660 (defvar gnus-article-wash-types nil)
1661 (defvar gnus-article-emphasis-alist nil)
1662 (defvar gnus-article-image-alist nil)
1663
1664 (defvar gnus-article-mime-handle-alist-1 nil)
1665 (defvar gnus-treatment-function-alist
1666 '((gnus-treat-strip-cr gnus-article-remove-cr)
1667 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1668 (gnus-treat-strip-banner gnus-article-strip-banner)
1669 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1670 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1671 (gnus-treat-buttonize gnus-article-add-buttons)
1672 (gnus-treat-fill-article gnus-article-fill-cited-article)
1673 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1674 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1675 (gnus-treat-display-x-face gnus-article-display-x-face)
1676 (gnus-treat-display-face gnus-article-display-face)
1677 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1678 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1679 (gnus-treat-hide-signature gnus-article-hide-signature)
1680 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1681 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1682 (gnus-treat-from-picon gnus-treat-from-picon)
1683 (gnus-treat-mail-picon gnus-treat-mail-picon)
1684 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1685 (gnus-treat-strip-pem gnus-article-hide-pem)
1686 (gnus-treat-date gnus-article-treat-date)
1687 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1688 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1689 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1690 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1691 (gnus-treat-strip-trailing-blank-lines
1692 gnus-article-remove-trailing-blank-lines)
1693 (gnus-treat-strip-leading-blank-lines
1694 gnus-article-strip-leading-blank-lines)
1695 (gnus-treat-strip-multiple-blank-lines
1696 gnus-article-strip-multiple-blank-lines)
1697 (gnus-treat-overstrike gnus-article-treat-overstrike)
1698 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1699 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1700 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1701 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1702 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1703 (gnus-treat-display-smileys gnus-treat-smiley)
1704 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1705 (gnus-treat-wash-html gnus-article-wash-html)
1706 (gnus-treat-emphasize gnus-article-emphasize)
1707 (gnus-treat-hide-citation gnus-article-hide-citation)
1708 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1709 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1710 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1711
1712 (defvar gnus-article-mime-handle-alist nil)
1713 (defvar article-lapsed-timer nil)
1714 (defvar gnus-article-current-summary nil)
1715
1716 (defvar gnus-article-mode-syntax-table
1717 (let ((table (copy-syntax-table text-mode-syntax-table)))
1718 ;; This causes the citation match run O(2^n).
1719 ;; (modify-syntax-entry ?- "w" table)
1720 (modify-syntax-entry ?> ")<" table)
1721 (modify-syntax-entry ?< "(>" table)
1722 ;; make M-. in article buffers work for `foo' strings
1723 (modify-syntax-entry ?' " " table)
1724 (modify-syntax-entry ?` " " table)
1725 table)
1726 "Syntax table used in article mode buffers.
1727 Initialized from `text-mode-syntax-table.")
1728
1729 (defvar gnus-save-article-buffer nil)
1730
1731 (defvar gnus-number-of-articles-to-be-saved nil)
1732
1733 (defvar gnus-inhibit-hiding nil)
1734
1735 (defvar gnus-article-edit-mode nil)
1736
1737 ;;; Macros for dealing with the article buffer.
1738
1739 (defmacro gnus-with-article-headers (&rest forms)
1740 `(with-current-buffer gnus-article-buffer
1741 (save-restriction
1742 (let ((inhibit-read-only t)
1743 (inhibit-point-motion-hooks t)
1744 (case-fold-search t))
1745 (article-narrow-to-head)
1746 ,@forms))))
1747
1748 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1749 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1750
1751 (defmacro gnus-with-article-buffer (&rest forms)
1752 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1753 (with-current-buffer gnus-article-buffer
1754 (let ((inhibit-read-only t))
1755 ,@forms))))
1756
1757 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1759
1760 (defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1763
1764 (defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1766 (gnus-add-text-properties-when 'article-type nil b e props)
1767 (when (memq 'intangible props)
1768 (put-text-property
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
1771
1772 (defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1778
1779 (defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
1781 (gnus-add-wash-type type)
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1784
1785 (defun gnus-article-unhide-text-type (b e type)
1786 "Unhide text of TYPE between B and E."
1787 (gnus-delete-wash-type type)
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1793
1794 (defun gnus-article-delete-text-of-type (type)
1795 "Delete text of TYPE in the current buffer."
1796 (save-excursion
1797 (let ((b (point-min)))
1798 (if (eq type 'multipart)
1799 ;; Remove MIME buttons associated with multipart/alternative parts.
1800 (progn
1801 (goto-char b)
1802 (while (if (get-text-property (point) 'gnus-part)
1803 (setq b (point))
1804 (when (setq b (next-single-property-change (point)
1805 'gnus-part))
1806 (goto-char b)
1807 t))
1808 (end-of-line)
1809 (skip-chars-forward "\n")
1810 (when (eq (get-text-property b 'article-type) 'multipart)
1811 (delete-region b (point)))))
1812 (while (setq b (text-property-any b (point-max) 'article-type type))
1813 (delete-region
1814 b (or (text-property-not-all b (point-max) 'article-type type)
1815 (point-max))))))))
1816
1817 (defun gnus-article-delete-invisible-text ()
1818 "Delete all invisible text in the current buffer."
1819 (save-excursion
1820 (let ((b (point-min)))
1821 (while (setq b (text-property-any b (point-max) 'invisible t))
1822 (delete-region
1823 b (or (text-property-not-all b (point-max) 'invisible t)
1824 (point-max)))))))
1825
1826 (defsubst gnus-article-header-rank ()
1827 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1828 (let ((list gnus-sorted-header-list)
1829 (i 1))
1830 (while list
1831 (if (looking-at (car list))
1832 (setq list nil)
1833 (setq list (cdr list))
1834 (incf i)))
1835 i))
1836
1837 (defun article-hide-headers (&optional arg delete)
1838 "Hide unwanted headers and possibly sort them as well."
1839 (interactive)
1840 ;; This function might be inhibited.
1841 (unless gnus-inhibit-hiding
1842 (let ((inhibit-read-only t)
1843 (case-fold-search t)
1844 (max (1+ (length gnus-sorted-header-list)))
1845 (inhibit-point-motion-hooks t)
1846 (cur (current-buffer))
1847 ignored visible beg)
1848 (save-excursion
1849 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1850 ;; group parameters, so we should go to the summary buffer.
1851 (when (prog1
1852 (condition-case nil
1853 (progn (set-buffer gnus-summary-buffer) t)
1854 (error nil))
1855 (setq ignored (when (not gnus-visible-headers)
1856 (cond ((stringp gnus-ignored-headers)
1857 gnus-ignored-headers)
1858 ((listp gnus-ignored-headers)
1859 (mapconcat 'identity
1860 gnus-ignored-headers
1861 "\\|"))))
1862 visible (cond ((stringp gnus-visible-headers)
1863 gnus-visible-headers)
1864 ((and gnus-visible-headers
1865 (listp gnus-visible-headers))
1866 (mapconcat 'identity
1867 gnus-visible-headers
1868 "\\|")))))
1869 (set-buffer cur))
1870 (save-restriction
1871 ;; First we narrow to just the headers.
1872 (article-narrow-to-head)
1873 ;; Hide any "From " lines at the beginning of (mail) articles.
1874 (while (looking-at "From ")
1875 (forward-line 1))
1876 (unless (bobp)
1877 (delete-region (point-min) (point)))
1878 ;; Then treat the rest of the header lines.
1879 ;; Then we use the two regular expressions
1880 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1881 ;; select which header lines is to remain visible in the
1882 ;; article buffer.
1883 (while (re-search-forward "^[^ \t:]*:" nil t)
1884 (beginning-of-line)
1885 ;; Mark the rank of the header.
1886 (put-text-property
1887 (point) (1+ (point)) 'message-rank
1888 (if (or (and visible (looking-at visible))
1889 (and ignored
1890 (not (looking-at ignored))))
1891 (gnus-article-header-rank)
1892 (+ 2 max)))
1893 (forward-line 1))
1894 (message-sort-headers-1)
1895 (when (setq beg (text-property-any
1896 (point-min) (point-max) 'message-rank (+ 2 max)))
1897 ;; We delete the unwanted headers.
1898 (gnus-add-wash-type 'headers)
1899 (add-text-properties (point-min) (+ 5 (point-min))
1900 '(article-type headers dummy-invisible t))
1901 (delete-region beg (point-max))))))))
1902
1903 (defun article-hide-boring-headers (&optional arg)
1904 "Toggle hiding of headers that aren't very interesting.
1905 If given a negative prefix, always show; if given a positive prefix,
1906 always hide."
1907 (interactive (gnus-article-hidden-arg))
1908 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1909 (not gnus-show-all-headers))
1910 (save-excursion
1911 (save-restriction
1912 (let ((inhibit-read-only t)
1913 (inhibit-point-motion-hooks t))
1914 (article-narrow-to-head)
1915 (dolist (elem gnus-boring-article-headers)
1916 (goto-char (point-min))
1917 (cond
1918 ;; Hide empty headers.
1919 ((eq elem 'empty)
1920 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1921 (forward-line -1)
1922 (gnus-article-hide-text-type
1923 (point-at-bol)
1924 (progn
1925 (end-of-line)
1926 (if (re-search-forward "^[^ \t]" nil t)
1927 (match-beginning 0)
1928 (point-max)))
1929 'boring-headers)))
1930 ;; Hide boring Newsgroups header.
1931 ((eq elem 'newsgroups)
1932 (when (gnus-string-equal
1933 (gnus-fetch-field "newsgroups")
1934 (gnus-group-real-name
1935 (if (boundp 'gnus-newsgroup-name)
1936 gnus-newsgroup-name
1937 "")))
1938 (gnus-article-hide-header "newsgroups")))
1939 ((eq elem 'to-address)
1940 (let ((to (message-fetch-field "to"))
1941 (to-address
1942 (gnus-parameter-to-address
1943 (if (boundp 'gnus-newsgroup-name)
1944 gnus-newsgroup-name ""))))
1945 (when (and to to-address
1946 (ignore-errors
1947 (gnus-string-equal
1948 ;; only one address in To
1949 (nth 1 (mail-extract-address-components to))
1950 to-address)))
1951 (gnus-article-hide-header "to"))))
1952 ((eq elem 'to-list)
1953 (let ((to (message-fetch-field "to"))
1954 (to-list
1955 (gnus-parameter-to-list
1956 (if (boundp 'gnus-newsgroup-name)
1957 gnus-newsgroup-name ""))))
1958 (when (and to to-list
1959 (ignore-errors
1960 (gnus-string-equal
1961 ;; only one address in To
1962 (nth 1 (mail-extract-address-components to))
1963 to-list)))
1964 (gnus-article-hide-header "to"))))
1965 ((eq elem 'cc-list)
1966 (let ((cc (message-fetch-field "cc"))
1967 (to-list
1968 (gnus-parameter-to-list
1969 (if (boundp 'gnus-newsgroup-name)
1970 gnus-newsgroup-name ""))))
1971 (when (and cc to-list
1972 (ignore-errors
1973 (gnus-string-equal
1974 ;; only one address in CC
1975 (nth 1 (mail-extract-address-components cc))
1976 to-list)))
1977 (gnus-article-hide-header "cc"))))
1978 ((eq elem 'followup-to)
1979 (when (gnus-string-equal
1980 (message-fetch-field "followup-to")
1981 (message-fetch-field "newsgroups"))
1982 (gnus-article-hide-header "followup-to")))
1983 ((eq elem 'reply-to)
1984 (if (gnus-group-find-parameter
1985 gnus-newsgroup-name 'broken-reply-to)
1986 (gnus-article-hide-header "reply-to")
1987 (let ((from (message-fetch-field "from"))
1988 (reply-to (message-fetch-field "reply-to")))
1989 (when
1990 (and
1991 from reply-to
1992 (ignore-errors
1993 (equal
1994 (sort (mapcar
1995 (lambda (x) (downcase (cadr x)))
1996 (mail-extract-address-components from t))
1997 'string<)
1998 (sort (mapcar
1999 (lambda (x) (downcase (cadr x)))
2000 (mail-extract-address-components reply-to t))
2001 'string<))))
2002 (gnus-article-hide-header "reply-to")))))
2003 ((eq elem 'date)
2004 (let ((date (with-current-buffer gnus-original-article-buffer
2005 ;; If date in `gnus-article-buffer' is localized
2006 ;; (`gnus-treat-date-user-defined'),
2007 ;; `days-between' might fail.
2008 (message-fetch-field "date"))))
2009 (when (and date
2010 (< (days-between (current-time-string) date)
2011 4))
2012 (gnus-article-hide-header "date"))))
2013 ((eq elem 'long-to)
2014 (let ((to (message-fetch-field "to"))
2015 (cc (message-fetch-field "cc")))
2016 (when (> (length to) 1024)
2017 (gnus-article-hide-header "to"))
2018 (when (> (length cc) 1024)
2019 (gnus-article-hide-header "cc"))))
2020 ((eq elem 'many-to)
2021 (let ((to-count 0)
2022 (cc-count 0))
2023 (goto-char (point-min))
2024 (while (re-search-forward "^to:" nil t)
2025 (setq to-count (1+ to-count)))
2026 (when (> to-count 1)
2027 (while (> to-count 0)
2028 (goto-char (point-min))
2029 (save-restriction
2030 (re-search-forward "^to:" nil nil to-count)
2031 (forward-line -1)
2032 (narrow-to-region (point) (point-max))
2033 (gnus-article-hide-header "to"))
2034 (setq to-count (1- to-count))))
2035 (goto-char (point-min))
2036 (while (re-search-forward "^cc:" nil t)
2037 (setq cc-count (1+ cc-count)))
2038 (when (> cc-count 1)
2039 (while (> cc-count 0)
2040 (goto-char (point-min))
2041 (save-restriction
2042 (re-search-forward "^cc:" nil nil cc-count)
2043 (forward-line -1)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "cc"))
2046 (setq cc-count (1- cc-count)))))))))))))
2047
2048 (defun gnus-article-hide-header (header)
2049 (save-excursion
2050 (goto-char (point-min))
2051 (when (re-search-forward (concat "^" header ":") nil t)
2052 (gnus-article-hide-text-type
2053 (point-at-bol)
2054 (progn
2055 (end-of-line)
2056 (if (re-search-forward "^[^ \t]" nil t)
2057 (match-beginning 0)
2058 (point-max)))
2059 'boring-headers))))
2060
2061 (defvar gnus-article-normalized-header-length 40
2062 "Length of normalized headers.")
2063
2064 (defun article-normalize-headers ()
2065 "Make all header lines 40 characters long."
2066 (interactive)
2067 (let ((inhibit-read-only t)
2068 column)
2069 (save-excursion
2070 (save-restriction
2071 (article-narrow-to-head)
2072 (while (not (eobp))
2073 (cond
2074 ((< (setq column (- (point-at-eol) (point)))
2075 gnus-article-normalized-header-length)
2076 (end-of-line)
2077 (insert (make-string
2078 (- gnus-article-normalized-header-length column)
2079 ? )))
2080 ((> column gnus-article-normalized-header-length)
2081 (gnus-put-text-property
2082 (progn
2083 (forward-char gnus-article-normalized-header-length)
2084 (point))
2085 (point-at-eol)
2086 'invisible t))
2087 (t
2088 ;; Do nothing.
2089 ))
2090 (forward-line 1))))))
2091
2092 (defun article-treat-dumbquotes ()
2093 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2094 Note that this function guesses whether a character is a sm*rtq**t* or
2095 not, so it should only be used interactively.
2096
2097 Sm*rtq**t*s are M****s***'s unilateral extension to the
2098 iso-8859-1 character map in an attempt to provide more quoting
2099 characters. If you see something like \\222 or \\264 where
2100 you're expecting some kind of apostrophe or quotation mark, then
2101 try this wash."
2102 (interactive)
2103 (article-translate-strings gnus-article-dumbquotes-map))
2104
2105 (defvar org-entities)
2106
2107 (defun article-treat-non-ascii ()
2108 "Translate many Unicode characters into their ASCII equivalents."
2109 (interactive)
2110 (require 'org-entities)
2111 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2112 (dolist (elem org-entities)
2113 (when (and (listp elem)
2114 (= (length (nth 6 elem)) 1))
2115 (if (featurep 'xemacs)
2116 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2117 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t)
2121 replace props)
2122 (while (not (eobp))
2123 (if (not (setq replace (if (featurep 'xemacs)
2124 (get-char-table (following-char) table)
2125 (aref table (following-char)))))
2126 (forward-char 1)
2127 (if (prog1
2128 (setq props (text-properties-at (point)))
2129 (delete-char 1))
2130 (add-text-properties (point) (progn (insert replace) (point))
2131 props)
2132 (insert replace)))))))))
2133
2134 (defun article-translate-strings (map)
2135 "Translate all string in the body of the article according to MAP.
2136 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2137 (save-excursion
2138 (when (article-goto-body)
2139 (let ((inhibit-read-only t))
2140 (dolist (elem map)
2141 (let ((from (car elem))
2142 (to (cadr elem)))
2143 (save-excursion
2144 (if (stringp from)
2145 (while (search-forward from nil t)
2146 (replace-match to))
2147 (while (not (eobp))
2148 (if (eq (following-char) from)
2149 (progn
2150 (delete-char 1)
2151 (insert to))
2152 (forward-char 1)))))))))))
2153
2154 (defun article-treat-overstrike ()
2155 "Translate overstrikes into bold text."
2156 (interactive)
2157 (save-excursion
2158 (when (article-goto-body)
2159 (let ((inhibit-read-only t))
2160 (while (search-forward "\b" nil t)
2161 (let ((next (char-after))
2162 (previous (char-after (- (point) 2))))
2163 ;; We do the boldification/underlining by hiding the
2164 ;; overstrikes and putting the proper text property
2165 ;; on the letters.
2166 (cond
2167 ((eq next previous)
2168 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2169 (put-text-property (point) (1+ (point)) 'face 'bold))
2170 ((eq next ?_)
2171 (gnus-article-hide-text-type
2172 (1- (point)) (1+ (point)) 'overstrike)
2173 (put-text-property
2174 (- (point) 2) (1- (point)) 'face 'underline))
2175 ((eq previous ?_)
2176 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2177 (put-text-property
2178 (point) (1+ (point)) 'face 'underline)))))))))
2179
2180 (defun article-treat-ansi-sequences ()
2181 "Translate ANSI SGR control sequences into overlays or extents."
2182 (interactive)
2183 (save-excursion
2184 (when (article-goto-body)
2185 (let ((inhibit-read-only t))
2186 (ansi-color-apply-on-region (point) (point-max))))))
2187
2188 (defun gnus-article-treat-unfold-headers ()
2189 "Unfold folded message headers.
2190 Only the headers that fit into the current window width will be
2191 unfolded."
2192 (interactive)
2193 (gnus-with-article-headers
2194 (let (length)
2195 (while (not (eobp))
2196 (save-restriction
2197 (mail-header-narrow-to-field)
2198 (let* ((header (buffer-string))
2199 (unfoldable
2200 (or (equal gnus-article-unfold-long-headers t)
2201 (and (stringp gnus-article-unfold-long-headers)
2202 (string-match gnus-article-unfold-long-headers
2203 header)))))
2204 (with-temp-buffer
2205 (insert header)
2206 (goto-char (point-min))
2207 (while (re-search-forward "\n[\t ]" nil t)
2208 (replace-match " " t t)))
2209 (setq length (- (point-max) (point-min) 1))
2210 (when (or unfoldable
2211 (< length (window-width)))
2212 (while (re-search-forward "\n[\t ]" nil t)
2213 (replace-match " " t t))))
2214 (goto-char (point-max)))))))
2215
2216 (defun gnus-article-treat-fold-headers ()
2217 "Fold message headers."
2218 (interactive)
2219 (gnus-with-article-headers
2220 (while (not (eobp))
2221 (save-restriction
2222 (mail-header-narrow-to-field)
2223 (mail-header-fold-field)
2224 (goto-char (point-max))))))
2225
2226 (defun gnus-treat-smiley ()
2227 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2228 (interactive)
2229 (gnus-with-article-buffer
2230 (if (memq 'smiley gnus-article-wash-types)
2231 (gnus-delete-images 'smiley)
2232 (article-goto-body)
2233 (let ((images (smiley-region (point) (point-max))))
2234 (when images
2235 (gnus-add-wash-type 'smiley)
2236 (dolist (image images)
2237 (gnus-add-image 'smiley image)))))))
2238
2239 (defun gnus-article-remove-images ()
2240 "Remove all images from the article buffer."
2241 (interactive)
2242 (gnus-with-article-buffer
2243 (save-restriction
2244 (widen)
2245 (dolist (elem gnus-article-image-alist)
2246 (gnus-delete-images (car elem))))))
2247
2248 (autoload 'w3m-toggle-inline-images "w3m")
2249
2250 (defun gnus-article-show-images ()
2251 "Show any images that are in the HTML-rendered article buffer.
2252 This only works if the article in question is HTML."
2253 (interactive)
2254 (gnus-with-article-buffer
2255 (save-restriction
2256 (widen)
2257 (if (eq mm-text-html-renderer 'w3m)
2258 (let ((mm-inline-text-html-with-images nil))
2259 (w3m-toggle-inline-images))
2260 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2261 'image-displayer))
2262 (destructuring-bind (start end function) region
2263 (funcall function (get-text-property start 'image-url)
2264 start end)))))))
2265
2266 (defun gnus-article-treat-fold-newsgroups ()
2267 "Unfold folded message headers.
2268 Only the headers that fit into the current window width will be
2269 unfolded."
2270 (interactive)
2271 (gnus-with-article-headers
2272 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2273 (save-restriction
2274 (mail-header-narrow-to-field)
2275 (while (re-search-forward ", *" nil t)
2276 (replace-match ", " t t))
2277 (mail-header-fold-field)
2278 (goto-char (point-max))))))
2279
2280 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2281 "Value of `truncate-lines' in Gnus Article buffer.
2282 Valid values are nil, t, `head', `first', `last', an integer or a
2283 predicate. See Info node `(gnus)Customizing Articles'."
2284 :version "23.1" ;; No Gnus
2285 :group 'gnus-article
2286 ;; :link '(custom-manual "(gnus)Customizing Articles")
2287 :type 'boolean)
2288
2289 (defun gnus-article-toggle-truncate-lines (&optional arg)
2290 "Toggle whether to fold or truncate long lines in article the buffer.
2291 If ARG is non-nil and not a number, toggle
2292 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2293 long lines if and only if arg is positive."
2294 (interactive "P")
2295 (cond
2296 ((and (numberp arg) (> arg 0))
2297 (setq gnus-article-truncate-lines t))
2298 ((numberp arg)
2299 (setq gnus-article-truncate-lines nil))
2300 (arg
2301 (setq gnus-article-truncate-lines
2302 (not gnus-article-truncate-lines))))
2303 (gnus-with-article-buffer
2304 (cond
2305 ((and (numberp arg) (> arg 0))
2306 (setq truncate-lines nil))
2307 ((numberp arg)
2308 (setq truncate-lines t)))
2309 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2310 ;; `toggle-truncate-lines' needs an argument.
2311 (toggle-truncate-lines)))
2312
2313 (defun gnus-article-treat-body-boundary ()
2314 "Place a boundary line at the end of the headers."
2315 (interactive)
2316 (when (and gnus-body-boundary-delimiter
2317 (> (length gnus-body-boundary-delimiter) 0))
2318 (gnus-with-article-headers
2319 (goto-char (point-max))
2320 (let ((start (point)))
2321 (insert "X-Boundary: ")
2322 (gnus-add-text-properties start (point) '(invisible t intangible t))
2323 (insert (let (str (max (window-width)))
2324 (if (featurep 'xemacs)
2325 (setq max (1- max)))
2326 (while (>= max (length str))
2327 (setq str (concat str gnus-body-boundary-delimiter)))
2328 (substring str 0 max))
2329 "\n")
2330 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2331
2332 (defun article-fill-long-lines ()
2333 "Fill lines that are wider than the window width."
2334 (interactive)
2335 (save-excursion
2336 (let ((inhibit-read-only t)
2337 (width (window-width (get-buffer-window (current-buffer)))))
2338 (save-restriction
2339 (article-goto-body)
2340 (let ((adaptive-fill-mode nil)) ;Why? -sm
2341 (while (not (eobp))
2342 (end-of-line)
2343 (when (>= (current-column) (min fill-column width))
2344 (narrow-to-region (min (1+ (point)) (point-max))
2345 (point-at-bol))
2346 (let ((goback (point-marker)))
2347 (fill-paragraph nil)
2348 (goto-char (marker-position goback)))
2349 (widen))
2350 (forward-line 1)))))))
2351
2352 (defun article-capitalize-sentences ()
2353 "Capitalize the first word in each sentence."
2354 (interactive)
2355 (save-excursion
2356 (let ((inhibit-read-only t)
2357 (paragraph-start "^[\n\^L]"))
2358 (article-goto-body)
2359 (while (not (eobp))
2360 (capitalize-word 1)
2361 (forward-sentence)))))
2362
2363 (defun article-remove-cr ()
2364 "Remove trailing CRs and then translate remaining CRs into LFs."
2365 (interactive)
2366 (save-excursion
2367 (let ((inhibit-read-only t))
2368 (goto-char (point-min))
2369 (while (re-search-forward "\r+$" nil t)
2370 (replace-match "" t t))
2371 (goto-char (point-min))
2372 (while (search-forward "\r" nil t)
2373 (replace-match "\n" t t)))))
2374
2375 (defun article-remove-trailing-blank-lines ()
2376 "Remove all trailing blank lines from the article."
2377 (interactive)
2378 (save-excursion
2379 (let ((inhibit-read-only t))
2380 (goto-char (point-max))
2381 (delete-region
2382 (point)
2383 (progn
2384 (while (and (not (bobp))
2385 (looking-at "^[ \t]*$")
2386 (not (gnus-annotation-in-region-p
2387 (point) (point-at-eol))))
2388 (forward-line -1))
2389 (forward-line 1)
2390 (point))))))
2391
2392 (defvar gnus-face-properties-alist)
2393
2394 (defun article-display-face (&optional force)
2395 "Display any Face headers in the header."
2396 (interactive (list 'force))
2397 (let ((wash-face-p buffer-read-only))
2398 (gnus-with-article-headers
2399 ;; When displaying parts, this function can be called several times on
2400 ;; the same article, without any intended toggle semantic (as typing `W
2401 ;; D d' would have). So face deletion must occur only when we come from
2402 ;; an interactive command, that is when the *Article* buffer is
2403 ;; read-only.
2404 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2405 (gnus-delete-images 'face)
2406 (let ((from (message-fetch-field "from"))
2407 face faces)
2408 (save-current-buffer
2409 (when (and wash-face-p
2410 (gnus-buffer-live-p gnus-original-article-buffer)
2411 (not (re-search-forward "^Face:[\t ]*" nil t)))
2412 (set-buffer gnus-original-article-buffer))
2413 (save-restriction
2414 (mail-narrow-to-head)
2415 (when (or force
2416 ;; Check whether this face is censored.
2417 (not (and gnus-article-x-face-too-ugly
2418 (or from
2419 (setq from (message-fetch-field "from")))
2420 (string-match gnus-article-x-face-too-ugly
2421 from))))
2422 (while (gnus-article-goto-header "Face")
2423 (push (mail-header-field-value) faces)))))
2424 (when faces
2425 (goto-char (point-min))
2426 (let (png image)
2427 (unless (setq from (gnus-article-goto-header "from"))
2428 (insert "From:")
2429 (setq from (point))
2430 (insert " [no `from' set]\n"))
2431 (while faces
2432 (when (setq png (gnus-convert-face-to-png (pop faces)))
2433 (setq image
2434 (apply 'gnus-create-image png 'png t
2435 (cdr (assq 'png gnus-face-properties-alist))))
2436 (goto-char from)
2437 (when image
2438 (gnus-add-wash-type 'face)
2439 (gnus-add-image 'face image)
2440 (gnus-put-image image nil 'face)))))))))))
2441
2442 (defun article-display-x-face (&optional force)
2443 "Look for an X-Face header and display it if present."
2444 (interactive (list 'force))
2445 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2446 (gnus-with-article-headers
2447 ;; Delete the old process, if any.
2448 (when (process-status "article-x-face")
2449 (delete-process "article-x-face"))
2450 ;; See the comment in `article-display-face'.
2451 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2452 ;; We have already displayed X-Faces, so we remove them
2453 ;; instead.
2454 (gnus-delete-images 'xface)
2455 ;; Display X-Faces.
2456 (let ((from (message-fetch-field "from"))
2457 x-faces face)
2458 (save-current-buffer
2459 (when (and wash-face-p
2460 (gnus-buffer-live-p gnus-original-article-buffer)
2461 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2462 ;; If type `W f', use gnus-original-article-buffer,
2463 ;; otherwise use the current buffer because displaying
2464 ;; RFC822 parts calls this function too.
2465 (set-buffer gnus-original-article-buffer))
2466 (save-restriction
2467 (mail-narrow-to-head)
2468 (and gnus-article-x-face-command
2469 (or force
2470 ;; Check whether this face is censored.
2471 (not (and gnus-article-x-face-too-ugly
2472 (or from
2473 (setq from (message-fetch-field "from")))
2474 (string-match gnus-article-x-face-too-ugly
2475 from))))
2476 (while (gnus-article-goto-header "X-Face")
2477 (push (mail-header-field-value) x-faces)))))
2478 (when x-faces
2479 ;; We display the face.
2480 (cond ((functionp gnus-article-x-face-command)
2481 ;; The command is a lisp function, so we call it.
2482 (mapc gnus-article-x-face-command x-faces))
2483 ((stringp gnus-article-x-face-command)
2484 ;; The command is a string, so we interpret the command
2485 ;; as a, well, command, and fork it off.
2486 (let ((process-connection-type nil))
2487 (gnus-set-process-query-on-exit-flag
2488 (start-process
2489 "article-x-face" nil shell-file-name
2490 shell-command-switch gnus-article-x-face-command)
2491 nil)
2492 ;; Sending multiple EOFs to xv doesn't work,
2493 ;; so we only do a single external face.
2494 (with-temp-buffer
2495 (insert (car x-faces))
2496 (process-send-region "article-x-face"
2497 (point-min) (point-max)))
2498 (process-send-eof "article-x-face")))
2499 (t
2500 (error "`%s' set to `%s' is not a function"
2501 gnus-article-x-face-command
2502 'gnus-article-x-face-command)))))))))
2503
2504 (defun article-decode-mime-words ()
2505 "Decode all MIME-encoded words in the article."
2506 (interactive)
2507 (gnus-with-article-buffer
2508 (let ((inhibit-point-motion-hooks t)
2509 (mail-parse-charset gnus-newsgroup-charset)
2510 (mail-parse-ignored-charsets
2511 (with-current-buffer gnus-summary-buffer
2512 gnus-newsgroup-ignored-charsets)))
2513 (mail-decode-encoded-word-region (point-min) (point-max)))))
2514
2515 (defun article-decode-charset (&optional prompt)
2516 "Decode charset-encoded text in the article.
2517 If PROMPT (the prefix), prompt for a coding system to use."
2518 (interactive "P")
2519 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2520 (inhibit-read-only t)
2521 (mail-parse-charset gnus-newsgroup-charset)
2522 (mail-parse-ignored-charsets
2523 (save-excursion (condition-case nil
2524 (set-buffer gnus-summary-buffer)
2525 (error))
2526 gnus-newsgroup-ignored-charsets))
2527 ct cte ctl charset format)
2528 (save-excursion
2529 (save-restriction
2530 (article-narrow-to-head)
2531 (setq ct (message-fetch-field "Content-Type" t)
2532 cte (message-fetch-field "Content-Transfer-Encoding" t)
2533 ctl (and ct (mail-header-parse-content-type ct))
2534 charset (cond
2535 (prompt
2536 (mm-read-coding-system "Charset to decode: "))
2537 (ctl
2538 (mail-content-type-get ctl 'charset)))
2539 format (and ctl (mail-content-type-get ctl 'format)))
2540 (when cte
2541 (setq cte (mail-header-strip cte)))
2542 (if (and ctl (not (string-match "/" (car ctl))))
2543 (setq ctl nil))
2544 (goto-char (point-max)))
2545 (forward-line 1)
2546 (save-restriction
2547 (narrow-to-region (point) (point-max))
2548 (when (and (eq mail-parse-charset 'gnus-decoded)
2549 (eq (mm-body-7-or-8) '8bit))
2550 ;; The text code could have been decoded.
2551 (setq charset mail-parse-charset))
2552 (when (and (or (not ctl)
2553 (equal (car ctl) "text/plain"))
2554 (not format)) ;; article with format will decode later.
2555 (mm-decode-body
2556 charset (and cte (intern (downcase
2557 (gnus-strip-whitespace cte))))
2558 (car ctl)))))))
2559
2560 (defun article-decode-encoded-words ()
2561 "Remove encoded-word encoding from headers."
2562 (let ((inhibit-point-motion-hooks t)
2563 (mail-parse-charset gnus-newsgroup-charset)
2564 (mail-parse-ignored-charsets
2565 (save-excursion (condition-case nil
2566 (set-buffer gnus-summary-buffer)
2567 (error))
2568 gnus-newsgroup-ignored-charsets))
2569 (inhibit-read-only t)
2570 end start)
2571 (goto-char (point-min))
2572 (when (search-forward "\n\n" nil 'move)
2573 (forward-line -1))
2574 (setq end (point))
2575 (while (not (bobp))
2576 (while (progn
2577 (forward-line -1)
2578 (and (not (bobp))
2579 (memq (char-after) '(?\t ? )))))
2580 (setq start (point))
2581 (if (looking-at "\
2582 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2583 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2584 (funcall gnus-decode-address-function start end)
2585 (funcall gnus-decode-header-function start end))
2586 (goto-char (setq end start)))))
2587
2588 (defun article-decode-group-name ()
2589 "Decode group names in Newsgroups, Followup-To and Xref headers."
2590 (let ((inhibit-point-motion-hooks t)
2591 (inhibit-read-only t)
2592 (method (gnus-find-method-for-group gnus-newsgroup-name))
2593 regexp)
2594 (when (and (or gnus-group-name-charset-method-alist
2595 gnus-group-name-charset-group-alist)
2596 (gnus-buffer-live-p gnus-original-article-buffer))
2597 (save-restriction
2598 (article-narrow-to-head)
2599 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2600 (with-current-buffer gnus-original-article-buffer
2601 (goto-char (point-min)))
2602 (setq regexp (concat "^" header
2603 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2604 (while (re-search-forward regexp nil t)
2605 (replace-match (save-match-data
2606 (gnus-decode-newsgroups
2607 ;; XXX how to use data in article buffer?
2608 (with-current-buffer gnus-original-article-buffer
2609 (re-search-forward regexp nil t)
2610 (match-string 1))
2611 gnus-newsgroup-name method))
2612 t t nil 1))
2613 (goto-char (point-min)))))))
2614
2615 (autoload 'idna-to-unicode "idna")
2616
2617 (defun article-decode-idna-rhs ()
2618 "Decode IDNA strings in RHS in various headers in current buffer.
2619 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2620 Mail-Reply-To: and Mail-Followup-To:."
2621 (when gnus-use-idna
2622 (save-restriction
2623 (let ((inhibit-point-motion-hooks t)
2624 (inhibit-read-only t))
2625 (article-narrow-to-head)
2626 (goto-char (point-min))
2627 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2628 (let (ace unicode)
2629 (when (save-match-data
2630 (and (setq ace (match-string 1))
2631 (save-excursion
2632 (and (re-search-backward "^[^ \t]" nil t)
2633 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2634 (setq unicode (idna-to-unicode ace))))
2635 (unless (string= ace unicode)
2636 (replace-match unicode nil nil nil 1)))))))))
2637
2638 (defun article-de-quoted-unreadable (&optional force read-charset)
2639 "Translate a quoted-printable-encoded article.
2640 If FORCE, decode the article whether it is marked as quoted-printable
2641 or not.
2642 If READ-CHARSET, ask for a coding system."
2643 (interactive (list 'force current-prefix-arg))
2644 (save-excursion
2645 (let ((inhibit-read-only t) type charset)
2646 (if (gnus-buffer-live-p gnus-original-article-buffer)
2647 (with-current-buffer gnus-original-article-buffer
2648 (setq type
2649 (gnus-fetch-field "content-transfer-encoding"))
2650 (let* ((ct (gnus-fetch-field "content-type"))
2651 (ctl (and ct (mail-header-parse-content-type ct))))
2652 (setq charset (and ctl
2653 (mail-content-type-get ctl 'charset)))
2654 (if (stringp charset)
2655 (setq charset (intern (downcase charset)))))))
2656 (if read-charset
2657 (setq charset (mm-read-coding-system "Charset: " charset)))
2658 (unless charset
2659 (setq charset gnus-newsgroup-charset))
2660 (when (or force
2661 (and type (let ((case-fold-search t))
2662 (string-match "quoted-printable" type))))
2663 (article-goto-body)
2664 (quoted-printable-decode-region
2665 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2666
2667 (defun article-de-base64-unreadable (&optional force read-charset)
2668 "Translate a base64 article.
2669 If FORCE, decode the article whether it is marked as base64 not.
2670 If READ-CHARSET, ask for a coding system."
2671 (interactive (list 'force current-prefix-arg))
2672 (save-excursion
2673 (let ((inhibit-read-only t) type charset)
2674 (if (gnus-buffer-live-p gnus-original-article-buffer)
2675 (with-current-buffer gnus-original-article-buffer
2676 (setq type
2677 (gnus-fetch-field "content-transfer-encoding"))
2678 (let* ((ct (gnus-fetch-field "content-type"))
2679 (ctl (and ct (mail-header-parse-content-type ct))))
2680 (setq charset (and ctl
2681 (mail-content-type-get ctl 'charset)))
2682 (if (stringp charset)
2683 (setq charset (intern (downcase charset)))))))
2684 (if read-charset
2685 (setq charset (mm-read-coding-system "Charset: " charset)))
2686 (unless charset
2687 (setq charset gnus-newsgroup-charset))
2688 (when (or force
2689 (and type (let ((case-fold-search t))
2690 (string-match "base64" type))))
2691 (article-goto-body)
2692 (save-restriction
2693 (narrow-to-region (point) (point-max))
2694 (base64-decode-region (point-min) (point-max))
2695 (mm-decode-coding-region
2696 (point-min) (point-max)
2697 (mm-charset-to-coding-system charset nil t)))))))
2698
2699 (eval-when-compile
2700 (require 'rfc1843))
2701
2702 (defun article-decode-HZ ()
2703 "Translate a HZ-encoded article."
2704 (interactive)
2705 (require 'rfc1843)
2706 (save-excursion
2707 (let ((inhibit-read-only t))
2708 (rfc1843-decode-region (point-min) (point-max)))))
2709
2710 (defun article-unsplit-urls ()
2711 "Remove the newlines that some other mailers insert into URLs."
2712 (interactive)
2713 (save-excursion
2714 (let ((inhibit-read-only t))
2715 (goto-char (point-min))
2716 (while (re-search-forward
2717 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2718 (replace-match "\\1\\3" t)))
2719 (when (gmm-called-interactively-p 'any)
2720 (gnus-treat-article nil))))
2721
2722 (defun article-wash-html ()
2723 "Format an HTML article."
2724 (interactive)
2725 (let ((handles nil)
2726 (buffer-read-only nil))
2727 (when (gnus-buffer-live-p gnus-original-article-buffer)
2728 (with-current-buffer gnus-original-article-buffer
2729 (setq handles (mm-dissect-buffer t t))))
2730 (article-goto-body)
2731 (delete-region (point) (point-max))
2732 (mm-enable-multibyte)
2733 (mm-inline-text-html handles)))
2734
2735 (defvar gnus-article-browse-html-temp-list nil
2736 "List of temporary files created by `gnus-article-browse-html-parts'.
2737 Internal variable.")
2738
2739 (defcustom gnus-article-browse-delete-temp 'ask
2740 "What to do with temporary files from `gnus-article-browse-html-parts'.
2741 If nil, don't delete temporary files. If it is t, delete them on
2742 exit from the summary buffer. If it is the symbol `file', query
2743 on each file, if it is `ask' ask once when exiting from the
2744 summary buffer."
2745 :group 'gnus-article
2746 :version "23.1" ;; No Gnus
2747 :type '(choice (const :tag "Don't delete" nil)
2748 (const :tag "Don't ask" t)
2749 (const :tag "Ask" ask)
2750 (const :tag "Ask for each file" file)))
2751
2752 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2753
2754 (defun gnus-article-browse-delete-temp-files (&optional how)
2755 "Delete temp-files created by `gnus-article-browse-html-parts'."
2756 (when (and gnus-article-browse-html-temp-list
2757 (progn
2758 (or how (setq how gnus-article-browse-delete-temp))
2759 (if (eq how 'ask)
2760 (let ((files (length gnus-article-browse-html-temp-list)))
2761 (or (gnus-y-or-n-p
2762 (if (= files 1)
2763 "Delete the temporary HTML file? "
2764 (format "Delete all %s temporary HTML files? "
2765 files)))
2766 (setq gnus-article-browse-html-temp-list nil)))
2767 how)))
2768 (dolist (file gnus-article-browse-html-temp-list)
2769 (cond ((file-directory-p file)
2770 (when (or (not (eq how 'file))
2771 (gnus-y-or-n-p
2772 (format
2773 "Delete temporary HTML file(s) in directory `%s'? "
2774 (file-name-as-directory file))))
2775 (gnus-delete-directory file)))
2776 ((file-exists-p file)
2777 (when (or (not (eq how 'file))
2778 (gnus-y-or-n-p
2779 (format "Delete temporary HTML file `%s'? " file)))
2780 (delete-file file)))))
2781 ;; Also remove file from the list when not deleted or if file doesn't
2782 ;; exist anymore.
2783 (setq gnus-article-browse-html-temp-list nil))
2784 gnus-article-browse-html-temp-list)
2785
2786 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2787 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2788 Return file name."
2789 (save-match-data
2790 (let (file type)
2791 (catch 'found
2792 (dolist (handle handles)
2793 (cond
2794 ((not (listp handle)))
2795 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2796 ;; may create.
2797 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2798 ((equal (mm-handle-media-supertype handle) "multipart")
2799 (when (setq file (gnus-article-browse-html-save-cid-content
2800 cid handle directory))
2801 (throw 'found file)))
2802 ((equal (concat "<" cid ">") (mm-handle-id handle))
2803 (setq file
2804 (expand-file-name
2805 (or (mm-handle-filename handle)
2806 (concat
2807 (make-temp-name "cid")
2808 (car (rassoc (car (mm-handle-type handle))
2809 mailcap-mime-extensions))))
2810 directory))
2811 (mm-save-part-to-file handle file)
2812 (throw 'found file))))))))
2813
2814 (defun gnus-article-browse-html-parts (list &optional header)
2815 "View all \"text/html\" parts from LIST.
2816 Recurse into multiparts. The optional HEADER that should be a decoded
2817 message header will be added to the bodies of the \"text/html\" parts."
2818 ;; Internal function used by `gnus-article-browse-html-article'.
2819 (let (type file charset content cid-dir tmp-file showed)
2820 ;; Find and show the html-parts.
2821 (dolist (handle list)
2822 ;; If HTML, show it:
2823 (cond ((not (listp handle)))
2824 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2825 (and (equal (car type) "message/external-body")
2826 (or header
2827 (setq file (mm-handle-filename handle)))
2828 (or (mm-handle-cache handle)
2829 (condition-case code
2830 (progn (mm-extern-cache-contents handle) t)
2831 (error
2832 (gnus-message 3 "%s" (error-message-string code))
2833 (when (>= gnus-verbose 3) (sit-for 2))
2834 nil)))
2835 (progn
2836 (setq handle (mm-handle-cache handle)
2837 type (mm-handle-type handle))
2838 (equal (car type) "text/html"))))
2839 (setq charset (mail-content-type-get type 'charset)
2840 content (mm-get-part handle))
2841 (with-temp-buffer
2842 (if (eq charset 'gnus-decoded)
2843 (mm-enable-multibyte)
2844 (mm-disable-multibyte))
2845 (insert content)
2846 ;; resolve cid contents
2847 (let ((case-fold-search t)
2848 cid-file)
2849 (goto-char (point-min))
2850 (while (re-search-forward "\
2851 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2852 nil t)
2853 (unless cid-dir
2854 (setq cid-dir (mm-make-temp-file "cid" t))
2855 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2856 (setq file nil
2857 content nil)
2858 (when (setq cid-file
2859 (gnus-article-browse-html-save-cid-content
2860 (match-string 2)
2861 (with-current-buffer gnus-article-buffer
2862 gnus-article-mime-handles)
2863 cid-dir))
2864 (when (eq system-type 'cygwin)
2865 (setq cid-file
2866 (concat "/" (substring
2867 (with-output-to-string
2868 (call-process "cygpath" nil
2869 standard-output
2870 nil "-m" cid-file))
2871 0 -1))))
2872 (replace-match (concat "file://" cid-file)
2873 nil nil nil 1))))
2874 (unless content (setq content (buffer-string))))
2875 (when (or charset header (not file))
2876 (setq tmp-file (mm-make-temp-file
2877 ;; Do we need to care for 8.3 filenames?
2878 "mm-" nil ".html")))
2879 ;; Add a meta html tag to specify charset and a header.
2880 (cond
2881 (header
2882 (let (title eheader body hcharset coding)
2883 (with-temp-buffer
2884 (mm-enable-multibyte)
2885 (setq case-fold-search t)
2886 (insert header "\n")
2887 (setq title (message-fetch-field "subject"))
2888 (goto-char (point-min))
2889 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2890 nil t)
2891 (replace-match (cond ((match-beginning 1) "&lt;")
2892 ((match-beginning 2) "&gt;")
2893 ((match-beginning 3) "&amp;")
2894 (t "<br>\n"))))
2895 (goto-char (point-min))
2896 (while (re-search-forward "^[\t ]+" nil t)
2897 (dotimes (i (prog1
2898 (current-column)
2899 (delete-region (match-beginning 0)
2900 (match-end 0))))
2901 (insert "&nbsp;")))
2902 (goto-char (point-min))
2903 (insert "<div align=\"left\">\n")
2904 (goto-char (point-max))
2905 (insert "</div>\n<hr>\n")
2906 ;; We have to examine charset one by one since
2907 ;; charset specified in parts might be different.
2908 (if (eq charset 'gnus-decoded)
2909 (setq charset 'utf-8
2910 eheader (mm-encode-coding-string (buffer-string)
2911 charset)
2912 title (when title
2913 (mm-encode-coding-string title charset))
2914 body (mm-encode-coding-string content charset))
2915 (setq hcharset (mm-find-mime-charset-region (point-min)
2916 (point-max)))
2917 (cond ((= (length hcharset) 1)
2918 (setq hcharset (car hcharset)
2919 coding (mm-charset-to-coding-system
2920 hcharset nil t)))
2921 ((> (length hcharset) 1)
2922 (setq hcharset 'utf-8
2923 coding hcharset)))
2924 (if coding
2925 (if charset
2926 (progn
2927 (setq body
2928 (mm-charset-to-coding-system charset
2929 nil t))
2930 (if (eq coding body)
2931 (setq eheader (mm-encode-coding-string
2932 (buffer-string) coding)
2933 title (when title
2934 (mm-encode-coding-string
2935 title coding))
2936 body content)
2937 (setq charset 'utf-8
2938 eheader (mm-encode-coding-string
2939 (buffer-string) charset)
2940 title (when title
2941 (mm-encode-coding-string
2942 title charset))
2943 body (mm-encode-coding-string
2944 (mm-decode-coding-string
2945 content body)
2946 charset))))
2947 (setq charset hcharset
2948 eheader (mm-encode-coding-string
2949 (buffer-string) coding)
2950 title (when title
2951 (mm-encode-coding-string
2952 title coding))
2953 body content))
2954 (setq eheader (mm-string-as-unibyte (buffer-string))
2955 body content)))
2956 (erase-buffer)
2957 (mm-disable-multibyte)
2958 (insert body)
2959 (when charset
2960 (mm-add-meta-html-tag handle charset t))
2961 (when title
2962 (goto-char (point-min))
2963 (unless (search-forward "<title>" nil t)
2964 (re-search-forward "<head>\\s-*" nil t)
2965 (insert "<title>" title "</title>\n")))
2966 (goto-char (point-min))
2967 (or (re-search-forward
2968 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2969 (re-search-forward
2970 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2971 (insert eheader)
2972 (mm-write-region (point-min) (point-max)
2973 tmp-file nil nil nil 'binary t))))
2974 (charset
2975 (mm-with-unibyte-buffer
2976 (insert (if (eq charset 'gnus-decoded)
2977 (mm-encode-coding-string content
2978 (setq charset 'utf-8))
2979 content))
2980 (if (or (mm-add-meta-html-tag handle charset)
2981 (not file))
2982 (mm-write-region (point-min) (point-max)
2983 tmp-file nil nil nil 'binary t)
2984 (setq tmp-file nil))))
2985 (tmp-file
2986 (mm-save-part-to-file handle tmp-file)))
2987 (when tmp-file
2988 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2989 (add-hook 'gnus-summary-prepare-exit-hook
2990 'gnus-article-browse-delete-temp-files)
2991 (add-hook 'gnus-exit-gnus-hook
2992 (lambda ()
2993 (gnus-article-browse-delete-temp-files t)))
2994 ;; FIXME: Warn if there's an <img> tag?
2995 (browse-url-of-file (or tmp-file (expand-file-name file)))
2996 (setq showed t))
2997 ;; If multipart, recurse
2998 ((equal (mm-handle-media-supertype handle) "multipart")
2999 (when (gnus-article-browse-html-parts handle header)
3000 (setq showed t)))
3001 ((equal (mm-handle-media-type handle) "message/rfc822")
3002 (mm-with-multibyte-buffer
3003 (mm-insert-part handle)
3004 (setq handle (mm-dissect-buffer t t))
3005 (when (and (bufferp (car handle))
3006 (stringp (car (mm-handle-type handle))))
3007 (setq handle (list handle)))
3008 (when header
3009 (article-decode-encoded-words)
3010 (let ((gnus-visible-headers
3011 (or (get 'gnus-visible-headers 'standard-value)
3012 gnus-visible-headers)))
3013 (article-hide-headers))
3014 (goto-char (point-min))
3015 (search-forward "\n\n" nil 'move)
3016 (skip-chars-backward "\t\n ")
3017 (setq header (buffer-substring (point-min) (point)))))
3018 (when (prog1
3019 (gnus-article-browse-html-parts handle header)
3020 (mm-destroy-parts handle))
3021 (setq showed t)))))
3022 showed))
3023
3024 (defun gnus-article-browse-html-article (&optional arg)
3025 "View \"text/html\" parts of the current article with a WWW browser.
3026 Inline images embedded in a message using the cid scheme, as they are
3027 generally considered to be safe, will be processed properly.
3028 The message header is added to the beginning of every html part unless
3029 the prefix argument ARG is given.
3030
3031 Warning: Spammers use links to images (using the http scheme) in HTML
3032 articles to verify whether you have read the message. As
3033 `gnus-article-browse-html-article' passes the HTML content to the
3034 browser without eliminating these \"web bugs\" you should only
3035 use it for mails from trusted senders.
3036
3037 If you always want to display HTML parts in the browser, set
3038 `mm-text-html-renderer' to nil.
3039
3040 This command creates temporary files to pass HTML contents including
3041 images if any to the browser, and deletes them when exiting the group
3042 \(if you want)."
3043 ;; Cf. `mm-w3m-safe-url-regexp'
3044 (interactive "P")
3045 (if arg
3046 (gnus-summary-show-article)
3047 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3048 gnus-visible-headers))
3049 ;; As we insert a <hr>, there's no need for the body boundary.
3050 (gnus-treat-body-boundary nil))
3051 (gnus-summary-show-article)))
3052 (with-current-buffer gnus-article-buffer
3053 (let ((header (unless arg
3054 (save-restriction
3055 (widen)
3056 (buffer-substring-no-properties
3057 (goto-char (point-min))
3058 (if (search-forward "\n\n" nil t)
3059 (match-beginning 0)
3060 (goto-char (point-max))
3061 (skip-chars-backward "\t\n ")
3062 (point))))))
3063 parts)
3064 (set-buffer gnus-original-article-buffer)
3065 (setq parts (mm-dissect-buffer t t))
3066 ;; If singlepart, enforce a list.
3067 (when (and (bufferp (car parts))
3068 (stringp (car (mm-handle-type parts))))
3069 (setq parts (list parts)))
3070 ;; Process the list
3071 (unless (gnus-article-browse-html-parts parts header)
3072 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3073 (mm-destroy-parts parts)
3074 (unless arg
3075 (gnus-summary-show-article)))))
3076
3077 (defun article-hide-list-identifiers ()
3078 "Remove list identifies from the Subject header.
3079 The `gnus-list-identifiers' variable specifies what to do."
3080 (interactive)
3081 (let ((inhibit-point-motion-hooks t)
3082 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3083 (inhibit-read-only t))
3084 (when regexp
3085 (save-excursion
3086 (save-restriction
3087 (article-narrow-to-head)
3088 (goto-char (point-min))
3089 (while (re-search-forward
3090 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3091 nil t)
3092 (delete-region (match-beginning 2) (match-end 0))
3093 (beginning-of-line))
3094 (when (re-search-forward
3095 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3096 (delete-region (match-beginning 1) (match-end 1))))))))
3097
3098 (defun article-hide-pem (&optional arg)
3099 "Toggle hiding of any PEM headers and signatures in the current article.
3100 If given a negative prefix, always show; if given a positive prefix,
3101 always hide."
3102 (interactive (gnus-article-hidden-arg))
3103 (unless (gnus-article-check-hidden-text 'pem arg)
3104 (save-excursion
3105 (let ((inhibit-read-only t) end)
3106 (goto-char (point-min))
3107 ;; Hide the horrendously ugly "header".
3108 (when (and (search-forward
3109 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3110 nil t)
3111 (setq end (1+ (match-beginning 0))))
3112 (gnus-add-wash-type 'pem)
3113 (gnus-article-hide-text-type
3114 end
3115 (if (search-forward "\n\n" nil t)
3116 (match-end 0)
3117 (point-max))
3118 'pem)
3119 ;; Hide the trailer as well
3120 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3121 nil t)
3122 (gnus-article-hide-text-type
3123 (match-beginning 0) (match-end 0) 'pem)))))))
3124
3125 (defun article-strip-banner ()
3126 "Strip the banners specified by the `banner' group parameter and by
3127 `gnus-article-address-banner-alist'."
3128 (interactive)
3129 (save-excursion
3130 (save-restriction
3131 (let ((inhibit-point-motion-hooks t))
3132 (when (gnus-parameter-banner gnus-newsgroup-name)
3133 (article-really-strip-banner
3134 (gnus-parameter-banner gnus-newsgroup-name)))
3135 (when gnus-article-address-banner-alist
3136 ;; Note that the From header is decoded here, so it is
3137 ;; required that the *-extract-address-components function
3138 ;; supports non-ASCII text.
3139 (let ((from (save-restriction
3140 (widen)
3141 (article-narrow-to-head)
3142 (mail-fetch-field "from"))))
3143 (when (and from
3144 (setq from
3145 (cadr (funcall gnus-extract-address-components
3146 from))))
3147 (catch 'found
3148 (dolist (pair gnus-article-address-banner-alist)
3149 (when (string-match (car pair) from)
3150 (throw 'found
3151 (article-really-strip-banner (cdr pair)))))))))))))
3152
3153 (defun article-really-strip-banner (banner)
3154 "Strip the banner specified by the argument."
3155 (save-excursion
3156 (save-restriction
3157 (let ((inhibit-point-motion-hooks t)
3158 (gnus-signature-limit nil)
3159 (inhibit-read-only t))
3160 (article-goto-body)
3161 (cond
3162 ((eq banner 'signature)
3163 (when (gnus-article-narrow-to-signature)
3164 (widen)
3165 (forward-line -1)
3166 (delete-region (point) (point-max))))
3167 ((symbolp banner)
3168 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3169 (while (re-search-forward banner nil t)
3170 (delete-region (match-beginning 0) (match-end 0)))))
3171 ((stringp banner)
3172 (while (re-search-forward banner nil t)
3173 (delete-region (match-beginning 0) (match-end 0)))))))))
3174
3175 (defun article-babel ()
3176 "Translate article using an online translation service."
3177 (interactive)
3178 (require 'babel)
3179 (gnus-with-article-buffer
3180 (when (article-goto-body)
3181 (let* ((start (point))
3182 (end (point-max))
3183 (orig (buffer-substring start end))
3184 (trans (babel-as-string orig)))
3185 (save-restriction
3186 (narrow-to-region start end)
3187 (delete-region start end)
3188 (insert trans))))))
3189
3190 (defun article-hide-signature (&optional arg)
3191 "Hide the signature in the current article.
3192 If given a negative prefix, always show; if given a positive prefix,
3193 always hide."
3194 (interactive (gnus-article-hidden-arg))
3195 (unless (gnus-article-check-hidden-text 'signature arg)
3196 (save-excursion
3197 (save-restriction
3198 (let ((inhibit-read-only t))
3199 (when (gnus-article-narrow-to-signature)
3200 (gnus-article-hide-text-type
3201 (point-min) (point-max) 'signature))))))
3202 (gnus-set-mode-line 'article))
3203
3204 (defun article-strip-headers-in-body ()
3205 "Strip offensive headers from bodies."
3206 (interactive)
3207 (save-excursion
3208 (article-goto-body)
3209 (let ((case-fold-search t))
3210 (when (looking-at "x-no-archive:")
3211 (gnus-delete-line)))))
3212
3213 (defun article-strip-leading-blank-lines ()
3214 "Remove all blank lines from the beginning of the article."
3215 (interactive)
3216 (save-excursion
3217 (let ((inhibit-point-motion-hooks t)
3218 (inhibit-read-only t))
3219 (when (article-goto-body)
3220 (while (and (not (eobp))
3221 (looking-at "[ \t]*$"))
3222 (gnus-delete-line))))))
3223
3224 (defun article-narrow-to-head ()
3225 "Narrow the buffer to the head of the message.
3226 Point is left at the beginning of the narrowed-to region."
3227 (narrow-to-region
3228 (goto-char (point-min))
3229 (cond
3230 ;; Absolutely no headers displayed.
3231 ((looking-at "\n")
3232 (point))
3233 ;; Normal headers.
3234 ((search-forward "\n\n" nil 1)
3235 (1- (point)))
3236 ;; Nothing but headers.
3237 (t
3238 (point-max))))
3239 (goto-char (point-min)))
3240
3241 (defun article-goto-body ()
3242 "Place point at the start of the body."
3243 (goto-char (point-min))
3244 (cond
3245 ;; This variable is only bound when dealing with separate
3246 ;; MIME body parts.
3247 (article-goto-body-goes-to-point-min-p
3248 t)
3249 ((search-forward "\n\n" nil t)
3250 t)
3251 (t
3252 (goto-char (point-max))
3253 nil)))
3254
3255 (defun article-strip-multiple-blank-lines ()
3256 "Replace consecutive blank lines with one empty line."
3257 (interactive)
3258 (save-excursion
3259 (let ((inhibit-point-motion-hooks t)
3260 (inhibit-read-only t))
3261 ;; First make all blank lines empty.
3262 (article-goto-body)
3263 (while (re-search-forward "^[ \t]+$" nil t)
3264 (unless (gnus-annotation-in-region-p
3265 (match-beginning 0) (match-end 0))
3266 (replace-match "" nil t)))
3267 ;; Then replace multiple empty lines with a single empty line.
3268 (article-goto-body)
3269 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3270 (unless (gnus-annotation-in-region-p
3271 (match-beginning 0) (match-end 0))
3272 (delete-region (match-beginning 1) (match-end 1)))))))
3273
3274 (defun article-strip-leading-space ()
3275 "Remove all white space from the beginning of the lines in the article."
3276 (interactive)
3277 (save-excursion
3278 (let ((inhibit-point-motion-hooks t)
3279 (inhibit-read-only t))
3280 (article-goto-body)
3281 (while (re-search-forward "^[ \t]+" nil t)
3282 (replace-match "" t t)))))
3283
3284 (defun article-strip-trailing-space ()
3285 "Remove all white space from the end of the lines in the article."
3286 (interactive)
3287 (save-excursion
3288 (let ((inhibit-point-motion-hooks t)
3289 (inhibit-read-only t))
3290 (article-goto-body)
3291 (while (re-search-forward "[ \t]+$" nil t)
3292 (replace-match "" t t)))))
3293
3294 (defun article-strip-blank-lines ()
3295 "Strip leading, trailing and multiple blank lines."
3296 (interactive)
3297 (article-strip-leading-blank-lines)
3298 (article-remove-trailing-blank-lines)
3299 (article-strip-multiple-blank-lines))
3300
3301 (defun article-strip-all-blank-lines ()
3302 "Strip all blank lines."
3303 (interactive)
3304 (save-excursion
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3307 (article-goto-body)
3308 (while (re-search-forward "^[ \t]*\n" nil t)
3309 (replace-match "" t t)))))
3310
3311 (defun gnus-article-narrow-to-signature ()
3312 "Narrow to the signature; return t if a signature is found, else nil."
3313 (let ((inhibit-point-motion-hooks t))
3314 (when (gnus-article-search-signature)
3315 (forward-line 1)
3316 ;; Check whether we have some limits to what we consider
3317 ;; to be a signature.
3318 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3319 (list gnus-signature-limit)))
3320 limit limited)
3321 (while (setq limit (pop limits))
3322 (if (or (and (integerp limit)
3323 (< (- (point-max) (point)) limit))
3324 (and (floatp limit)
3325 (< (count-lines (point) (point-max)) limit))
3326 (and (functionp limit)
3327 (funcall limit))
3328 (and (stringp limit)
3329 (not (re-search-forward limit nil t))))
3330 () ; This limit did not succeed.
3331 (setq limited t
3332 limits nil)))
3333 (unless limited
3334 (narrow-to-region (point) (point-max))
3335 t)))))
3336
3337 (defun gnus-article-search-signature ()
3338 "Search the current buffer for the signature separator.
3339 Put point at the beginning of the signature separator."
3340 (let ((cur (point)))
3341 (goto-char (point-max))
3342 (if (if (stringp gnus-signature-separator)
3343 (re-search-backward gnus-signature-separator nil t)
3344 (let ((seps gnus-signature-separator))
3345 (while (and seps
3346 (not (re-search-backward (car seps) nil t)))
3347 (pop seps))
3348 seps))
3349 t
3350 (goto-char cur)
3351 nil)))
3352
3353 (defun gnus-article-hidden-arg ()
3354 "Return the current prefix arg as a number, or 0 if no prefix."
3355 (list (if current-prefix-arg
3356 (prefix-numeric-value current-prefix-arg)
3357 0)))
3358
3359 (defun gnus-article-check-hidden-text (type arg)
3360 "Return nil if hiding is necessary.
3361 Arg can be nil or a number. nil and positive means hide, negative
3362 means show, 0 means toggle."
3363 (save-excursion
3364 (save-restriction
3365 (let ((hide (gnus-article-hidden-text-p type)))
3366 (cond
3367 ((or (null arg)
3368 (> arg 0))
3369 nil)
3370 ((< arg 0)
3371 (gnus-article-show-hidden-text type)
3372 t)
3373 (t
3374 (if (eq hide 'hidden)
3375 (progn
3376 (gnus-article-show-hidden-text type)
3377 t)
3378 nil)))))))
3379
3380 (defun gnus-article-hidden-text-p (type)
3381 "Say whether the current buffer contains hidden text of type TYPE."
3382 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3383 (while (and pos
3384 (not (get-text-property pos 'invisible))
3385 (not (get-text-property pos 'dummy-invisible)))
3386 (setq pos
3387 (text-property-any (1+ pos) (point-max) 'article-type type)))
3388 (if pos
3389 'hidden
3390 nil)))
3391
3392 (defun gnus-article-show-hidden-text (type &optional dummy)
3393 "Show all hidden text of type TYPE.
3394 Originally it is hide instead of DUMMY."
3395 (let ((inhibit-read-only t)
3396 (inhibit-point-motion-hooks t))
3397 (gnus-remove-text-properties-when
3398 'article-type type
3399 (point-min) (point-max)
3400 (cons 'article-type (cons type
3401 gnus-hidden-properties)))
3402 (gnus-delete-wash-type type)))
3403
3404 (defconst article-time-units
3405 `((year . ,(* 365.25 24 60 60))
3406 (week . ,(* 7 24 60 60))
3407 (day . ,(* 24 60 60))
3408 (hour . ,(* 60 60))
3409 (minute . 60)
3410 (second . 1))
3411 "Mapping from time units to seconds.")
3412
3413 (defun gnus-article-forward-header ()
3414 "Move point to the start of the next header.
3415 If the current header is a continuation header, this can be several
3416 lines forward."
3417 (let ((ended nil))
3418 (while (not ended)
3419 (forward-line 1)
3420 (if (looking-at "[ \t]+[^ \t]")
3421 (forward-line 1)
3422 (setq ended t)))))
3423
3424 (defun article-treat-date ()
3425 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3426 (with-current-buffer gnus-summary-buffer
3427 gnus-article-date-headers)
3428 gnus-article-date-headers)
3429 t))
3430
3431 (defun article-date-ut (&optional type highlight date-position)
3432 "Convert DATE date to TYPE in the current article.
3433 The default type is `ut'. See `gnus-article-date-headers' for
3434 possible values."
3435 (interactive (list 'ut t))
3436 (let* ((case-fold-search t)
3437 (inhibit-read-only t)
3438 (inhibit-point-motion-hooks t)
3439 (first t)
3440 (visible-date (mail-fetch-field "Date"))
3441 pos date bface eface)
3442 (save-excursion
3443 (if date-position
3444 (progn
3445 (goto-char date-position)
3446 (setq date (get-text-property (point) 'original-date))
3447 (when (looking-at "[^:]+:[\t ]*")
3448 (setq bface (get-text-property (match-beginning 0) 'face)
3449 eface (get-text-property (match-end 0) 'face)))
3450 (delete-region (point)
3451 (progn
3452 (gnus-article-forward-header)
3453 (point)))
3454 (article-transform-date date type bface eface))
3455 (save-restriction
3456 (widen)
3457 (goto-char (point-min))
3458 (while (or (get-text-property (setq pos (point)) 'original-date)
3459 (and (setq pos (next-single-property-change
3460 (point) 'original-date))
3461 (goto-char pos)))
3462 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3463 (1+ (match-beginning 0))
3464 (point-max)))
3465 (while (setq pos (text-property-not-all pos (point-max)
3466 'gnus-date-type nil))
3467 (setq date (get-text-property pos 'original-date))
3468 (goto-char pos)
3469 (when (looking-at "[^:]+:[\t ]*")
3470 (setq bface (get-text-property (match-beginning 0) 'face)
3471 eface (get-text-property (match-end 0) 'face)))
3472 (delete-region pos (or (text-property-any pos (point-max)
3473 'gnus-date-type nil)
3474 (point-max))))
3475 (unless date ;; the 1st time
3476 (goto-char (point-min))
3477 (while (re-search-forward "^Date:[\t ]*" nil t)
3478 (setq date (get-text-property (match-beginning 0)
3479 'original-date)
3480 bface (get-text-property (match-beginning 0) 'face)
3481 eface (get-text-property (match-end 0) 'face))
3482 (delete-region (point-at-bol) (progn
3483 (gnus-article-forward-header)
3484 (point)))))
3485 (when (and (not date)
3486 visible-date)
3487 (setq date visible-date))
3488 (when date
3489 (article-transform-date date type bface eface))
3490 (goto-char (point-max))
3491 (widen)))))))
3492
3493 (defun article-transform-date (date type bface eface)
3494 (dolist (this-type (cond
3495 ((null type)
3496 (list 'ut))
3497 ((atom type)
3498 (list type))
3499 (t
3500 type)))
3501 (goto-char
3502 (prog1
3503 (point)
3504 (add-text-properties
3505 (point)
3506 (progn
3507 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3508 (point))
3509 (list 'original-date date 'gnus-date-type this-type))))
3510 ;; Do highlighting.
3511 (when (looking-at
3512 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3513 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3514 (when (match-beginning 2)
3515 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3516 (while (and (zerop (forward-line 1))
3517 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3518 (when (match-beginning 1)
3519 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3520
3521 (defun article-make-date-line (date type)
3522 "Return a DATE line of TYPE."
3523 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3524 combined-lapsed))
3525 (error "Unknown conversion type: %s" type))
3526 (condition-case ()
3527 (let ((time (ignore-errors (date-to-time date))))
3528 (cond
3529 ;; Convert to the local timezone.
3530 ((eq type 'local)
3531 (concat "Date: " (message-make-date time)))
3532 ;; Convert to Universal Time.
3533 ((eq type 'ut)
3534 (concat "Date: "
3535 (substring
3536 (message-make-date
3537 (let* ((e (parse-time-string date))
3538 (tm (apply 'encode-time e))
3539 (ms (car tm))
3540 (ls (- (cadr tm) (car (current-time-zone time)))))
3541 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3542 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3543 (t (list ms ls)))))
3544 0 -5)
3545 "UT"))
3546 ;; Get the original date from the article.
3547 ((eq type 'original)
3548 (concat "Date: " (if (string-match "\n+$" date)
3549 (substring date 0 (match-beginning 0))
3550 date)))
3551 ;; Let the user define the format.
3552 ((eq type 'user-defined)
3553 (let ((format (or (condition-case nil
3554 (with-current-buffer gnus-summary-buffer
3555 gnus-article-time-format)
3556 (error nil))
3557 gnus-article-time-format)))
3558 (if (functionp format)
3559 (funcall format time)
3560 (concat "Date: " (format-time-string format time)))))
3561 ;; ISO 8601.
3562 ((eq type 'iso8601)
3563 (let ((tz (car (current-time-zone time))))
3564 (concat
3565 "Date: "
3566 (format-time-string "%Y%m%dT%H%M%S" time)
3567 (format "%s%02d%02d"
3568 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3569 (/ (% (abs tz) 3600) 60)))))
3570 ;; Do a lapsed format.
3571 ((eq type 'lapsed)
3572 (concat "Date: " (article-lapsed-string time)))
3573 ;; A combined date/lapsed format.
3574 ((eq type 'combined-lapsed)
3575 (let ((date-string (article-make-date-line date 'original))
3576 (segments 3)
3577 lapsed-string)
3578 (while (and
3579 time
3580 (setq lapsed-string
3581 (concat " (" (article-lapsed-string time segments) ")"))
3582 (> (+ (length date-string)
3583 (length lapsed-string))
3584 (+ fill-column 6))
3585 (> segments 0))
3586 (setq segments (1- segments)))
3587 (if (> segments 0)
3588 (concat date-string lapsed-string)
3589 date-string)))
3590 ;; Display the date in proper English
3591 ((eq type 'english)
3592 (let ((dtime (decode-time time)))
3593 (concat
3594 "Date: the "
3595 (number-to-string (nth 3 dtime))
3596 (let ((digit (% (nth 3 dtime) 10)))
3597 (cond
3598 ((memq (nth 3 dtime) '(11 12 13)) "th")
3599 ((= digit 1) "st")
3600 ((= digit 2) "nd")
3601 ((= digit 3) "rd")
3602 (t "th")))
3603 " of "
3604 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3605 " "
3606 (number-to-string (nth 5 dtime))
3607 " at "
3608 (format "%02d" (nth 2 dtime))
3609 ":"
3610 (format "%02d" (nth 1 dtime)))))))
3611 (foo
3612 (format "Date: %s (from Gnus)" date))))
3613
3614 (defun article-lapsed-string (time &optional max-segments)
3615 ;; If the date is seriously mangled, the timezone functions are
3616 ;; liable to bug out, so we ignore all errors.
3617 (let* ((now (current-time))
3618 (real-time (subtract-time now time))
3619 (real-sec (and real-time
3620 (+ (* (float (car real-time)) 65536)
3621 (cadr real-time))))
3622 (sec (and real-time (abs real-sec)))
3623 (segments 0)
3624 num prev)
3625 (unless max-segments
3626 (setq max-segments (length article-time-units)))
3627 (cond
3628 ((null real-time)
3629 "Unknown")
3630 ((zerop sec)
3631 "Now")
3632 (t
3633 (concat
3634 ;; This is a bit convoluted, but basically we go
3635 ;; through the time units for years, weeks, etc,
3636 ;; and divide things to see whether that results
3637 ;; in positive answers.
3638 (mapconcat
3639 (lambda (unit)
3640 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3641 (>= segments max-segments))
3642 ;; The (remaining) seconds are too few to
3643 ;; be divided into this time unit.
3644 ""
3645 ;; It's big enough, so we output it.
3646 (setq sec (- sec (* num (cdr unit))))
3647 (prog1
3648 (concat (if prev ", " "") (int-to-string
3649 (floor num))
3650 " " (symbol-name (car unit))
3651 (if (> num 1) "s" ""))
3652 (setq prev t
3653 segments (1+ segments)))))
3654 article-time-units "")
3655 ;; If dates are odd, then it might appear like the
3656 ;; article was sent in the future.
3657 (if (> real-sec 0)
3658 " ago"
3659 " in the future"))))))
3660
3661 (defun article-date-local (&optional highlight)
3662 "Convert the current article date to the local timezone."
3663 (interactive (list t))
3664 (article-date-ut 'local highlight))
3665
3666 (defun article-date-english (&optional highlight)
3667 "Convert the current article date to something that is proper English."
3668 (interactive (list t))
3669 (article-date-ut 'english highlight))
3670
3671 (defun article-date-original (&optional highlight)
3672 "Convert the current article date to what it was originally.
3673 This is only useful if you have used some other date conversion
3674 function and want to see what the date was before converting."
3675 (interactive (list t))
3676 (article-date-ut 'original highlight))
3677
3678 (defun article-date-lapsed (&optional highlight)
3679 "Convert the current article date to time lapsed since it was sent."
3680 (interactive (list t))
3681 (article-date-ut 'lapsed highlight))
3682
3683 (defun article-date-combined-lapsed (&optional highlight)
3684 "Convert the current article date to time lapsed since it was sent."
3685 (interactive (list t))
3686 (article-date-ut 'combined-lapsed highlight))
3687
3688 (defun article-update-date-lapsed ()
3689 "Function to be run from a timer to update the lapsed time line."
3690 (save-match-data
3691 (let ((buffer (current-buffer)))
3692 (ignore-errors
3693 (walk-windows
3694 (lambda (w)
3695 (set-buffer (window-buffer w))
3696 (when (derived-mode-p 'gnus-article-mode)
3697 (let ((old-line (count-lines (point-min) (point)))
3698 (old-column (- (point) (line-beginning-position)))
3699 (window-start (window-start w))
3700 (pos (point-min))
3701 type next end)
3702 (while (setq pos (text-property-not-all pos (point-max)
3703 'gnus-date-type nil))
3704 (setq next (or (next-single-property-change pos
3705 'gnus-date-type)
3706 (point-max)))
3707 (setq type (get-text-property pos 'gnus-date-type))
3708 (when (memq type '(lapsed combined-lapsed user-defined))
3709 (article-date-ut type t pos)
3710 (setq end (or (next-single-property-change pos
3711 'gnus-date-type)
3712 (point-max)))
3713 (when window-start
3714 (if (/= window-start next)
3715 (setq window-start nil)
3716 (set-window-start w end)))
3717 (setq next end))
3718 (setq pos next))
3719 (goto-char (point-min))
3720 (when (> old-column 0)
3721 (setq old-line (1- old-line)))
3722 (forward-line old-line)
3723 (end-of-line)
3724 (when (> (current-column) old-column)
3725 (beginning-of-line)
3726 (forward-char old-column)))))
3727 nil 'visible))
3728 (set-buffer buffer))))
3729
3730 (defun gnus-start-date-timer (&optional n)
3731 "Start a timer to update the Date headers in the article buffers.
3732 The numerical prefix says how frequently (in seconds) the function
3733 is to run."
3734 (interactive "p")
3735 (unless n
3736 (setq n 1))
3737 (gnus-stop-date-timer)
3738 (setq article-lapsed-timer
3739 (run-at-time 1 n 'article-update-date-lapsed)))
3740
3741 (defun gnus-stop-date-timer ()
3742 "Stop the Date timer."
3743 (interactive)
3744 (when article-lapsed-timer
3745 (nnheader-cancel-timer article-lapsed-timer)
3746 (setq article-lapsed-timer nil)))
3747
3748 (defun article-date-user (&optional highlight)
3749 "Convert the current article date to the user-defined format.
3750 This format is defined by the `gnus-article-time-format' variable."
3751 (interactive (list t))
3752 (article-date-ut 'user highlight))
3753
3754 (defun article-date-iso8601 (&optional highlight)
3755 "Convert the current article date to ISO8601."
3756 (interactive (list t))
3757 (article-date-ut 'iso8601 highlight))
3758
3759 (defmacro gnus-article-save-original-date (&rest forms)
3760 "Save the original date as a text property and evaluate FORMS."
3761 `(let* ((case-fold-search t)
3762 (start (progn
3763 (goto-char (point-min))
3764 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3765 (not (bolp)))
3766 (match-end 0))))
3767 (date (when (and start
3768 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3769 nil t))
3770 (buffer-substring-no-properties start
3771 (match-beginning 0)))))
3772 (goto-char (point-max))
3773 (skip-chars-backward "\n")
3774 (put-text-property (point-min) (point) 'original-date date)
3775 ,@forms
3776 (goto-char (point-max))
3777 (skip-chars-backward "\n")
3778 (put-text-property (point-min) (point) 'original-date date)))
3779
3780 ;; (defun article-show-all ()
3781 ;; "Show all hidden text in the article buffer."
3782 ;; (interactive)
3783 ;; (save-excursion
3784 ;; (let ((inhibit-read-only t))
3785 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3786
3787 (defun article-remove-leading-whitespace ()
3788 "Remove excessive whitespace from all headers."
3789 (interactive)
3790 (save-excursion
3791 (save-restriction
3792 (let ((inhibit-read-only t))
3793 (article-narrow-to-head)
3794 (goto-char (point-min))
3795 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3796 (delete-region (match-beginning 1) (match-end 1)))))))
3797
3798 (defun article-emphasize (&optional arg)
3799 "Emphasize text according to `gnus-emphasis-alist'."
3800 (interactive (gnus-article-hidden-arg))
3801 (unless (gnus-article-check-hidden-text 'emphasis arg)
3802 (save-excursion
3803 (let ((alist (or
3804 (condition-case nil
3805 (with-current-buffer gnus-summary-buffer
3806 gnus-article-emphasis-alist)
3807 (error))
3808 gnus-emphasis-alist))
3809 (inhibit-read-only t)
3810 (props (append '(article-type emphasis)
3811 gnus-hidden-properties))
3812 regexp elem beg invisible visible face)
3813 (article-goto-body)
3814 (setq beg (point))
3815 (while (setq elem (pop alist))
3816 (goto-char beg)
3817 (setq regexp (car elem)
3818 invisible (nth 1 elem)
3819 visible (nth 2 elem)
3820 face (nth 3 elem))
3821 (while (re-search-forward regexp nil t)
3822 (when (and (match-beginning visible) (match-beginning invisible))
3823 (gnus-article-hide-text
3824 (match-beginning invisible) (match-end invisible) props)
3825 (gnus-article-unhide-text-type
3826 (match-beginning visible) (match-end visible) 'emphasis)
3827 (gnus-put-overlay-excluding-newlines
3828 (match-beginning visible) (match-end visible) 'face face)
3829 (gnus-add-wash-type 'emphasis)
3830 (goto-char (match-end invisible)))))))))
3831
3832 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3833 "Setup newsgroup emphasis alist."
3834 (unless gnus-article-emphasis-alist
3835 (let ((name (and gnus-newsgroup-name
3836 (gnus-group-real-name gnus-newsgroup-name))))
3837 (make-local-variable 'gnus-article-emphasis-alist)
3838 (setq gnus-article-emphasis-alist
3839 (nconc
3840 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3841 (while (setq elem (pop alist))
3842 (when (and name (string-match (car elem) name))
3843 (setq alist nil
3844 highlight (copy-sequence (cdr elem)))))
3845 highlight)
3846 (copy-sequence highlight-words)
3847 (if gnus-newsgroup-name
3848 (copy-sequence (gnus-group-find-parameter
3849 gnus-newsgroup-name 'highlight-words t)))
3850 gnus-emphasis-alist)))))
3851
3852 (defvar gnus-summary-article-menu)
3853 (defvar gnus-summary-post-menu)
3854
3855 ;;; Saving functions.
3856
3857 (defun gnus-article-save (save-buffer file &optional num)
3858 "Save the currently selected article."
3859 (when (or (get gnus-default-article-saver :headers)
3860 (not gnus-save-all-headers))
3861 ;; Remove headers according to `gnus-saved-headers' or the value
3862 ;; of the `:headers' property that the saver function might have.
3863 (let ((gnus-visible-headers
3864 (or (symbol-value (get gnus-default-article-saver :headers))
3865 gnus-saved-headers gnus-visible-headers))
3866 ;; Ignore group parameter. See `article-hide-headers'.
3867 (gnus-summary-buffer nil))
3868 (with-current-buffer save-buffer
3869 (article-hide-headers 1 t))))
3870 (save-window-excursion
3871 (if (not gnus-default-article-saver)
3872 (error "No default saver is defined")
3873 ;; !!! Magic! The saving functions all save
3874 ;; `gnus-save-article-buffer' (or so they think), but we
3875 ;; bind that variable to our save-buffer.
3876 (set-buffer gnus-article-buffer)
3877 (let* ((gnus-save-article-buffer save-buffer)
3878 (filename
3879 (cond
3880 ((not gnus-prompt-before-saving) 'default)
3881 ((eq gnus-prompt-before-saving 'always) nil)
3882 (t file)))
3883 (gnus-number-of-articles-to-be-saved
3884 (when (eq gnus-prompt-before-saving t)
3885 num))) ; Magic
3886 (set-buffer gnus-article-current-summary)
3887 (funcall gnus-default-article-saver filename)))))
3888
3889 (defun gnus-read-save-file-name (prompt &optional filename
3890 function group headers variable
3891 dir-var)
3892 (let ((default-name
3893 (funcall function group headers (symbol-value variable)))
3894 result)
3895 (setq result
3896 (expand-file-name
3897 (cond
3898 ((eq filename 'default)
3899 default-name)
3900 ((eq filename t)
3901 default-name)
3902 (filename filename)
3903 (t
3904 (when (symbol-value dir-var)
3905 (setq default-name (expand-file-name
3906 (file-name-nondirectory default-name)
3907 (symbol-value dir-var))))
3908 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3909 (prompt
3910 (format prompt
3911 (if (and gnus-number-of-articles-to-be-saved
3912 (> gnus-number-of-articles-to-be-saved 1))
3913 (format "these %d articles"
3914 gnus-number-of-articles-to-be-saved)
3915 "this article")))
3916 (file
3917 ;; Let the split methods have their say.
3918 (cond
3919 ;; No split name was found.
3920 ((null split-name)
3921 (read-file-name
3922 (concat prompt " (default "
3923 (file-name-nondirectory default-name) "): ")
3924 (file-name-directory default-name)
3925 default-name))
3926 ;; A single group name is returned.
3927 ((stringp split-name)
3928 (setq default-name
3929 (funcall function split-name headers
3930 (symbol-value variable)))
3931 (read-file-name
3932 (concat prompt " (default "
3933 (file-name-nondirectory default-name) "): ")
3934 (file-name-directory default-name)
3935 default-name))
3936 ;; A single split name was found
3937 ((= 1 (length split-name))
3938 (let* ((name (expand-file-name
3939 (car split-name)
3940 gnus-article-save-directory))
3941 (dir (cond ((file-directory-p name)
3942 (file-name-as-directory name))
3943 ((file-exists-p name) name)
3944 (t gnus-article-save-directory))))
3945 (read-file-name
3946 (concat prompt " (default " name "): ")
3947 dir name)))
3948 ;; A list of splits was found.
3949 (t
3950 (setq split-name (nreverse split-name))
3951 (let (result)
3952 (let ((file-name-history
3953 (nconc split-name file-name-history)))
3954 (setq result
3955 (expand-file-name
3956 (read-file-name
3957 (concat prompt " (`M-p' for defaults): ")
3958 gnus-article-save-directory
3959 (car split-name))
3960 gnus-article-save-directory)))
3961 (car (push result file-name-history)))))))
3962 ;; Create the directory.
3963 (gnus-make-directory (file-name-directory file))
3964 ;; If we have read a directory, we append the default file name.
3965 (when (file-directory-p file)
3966 (setq file (expand-file-name (file-name-nondirectory
3967 default-name)
3968 (file-name-as-directory file))))
3969 ;; Possibly translate some characters.
3970 (nnheader-translate-file-chars file))))))
3971 (gnus-make-directory (file-name-directory result))
3972 (when variable
3973 (set variable result))
3974 (when dir-var
3975 (set dir-var (file-name-directory result)))
3976 result))
3977
3978 (defun gnus-article-archive-name (group)
3979 "Return the first instance of an \"Archive-name\" in the current buffer."
3980 (let ((case-fold-search t))
3981 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3982 (nnheader-concat gnus-article-save-directory
3983 (match-string 1)))))
3984
3985 (defun gnus-article-nndoc-name (group)
3986 "If GROUP is an nndoc group, return the name of the parent group."
3987 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3988 (gnus-group-get-parameter group 'save-article-group)))
3989
3990 (defun gnus-summary-save-in-rmail (&optional filename)
3991 "Append this article to Rmail file.
3992 Optional argument FILENAME specifies file name.
3993 Directory to save to is default to `gnus-article-save-directory'."
3994 (setq filename (gnus-read-save-file-name
3995 "Save %s in rmail file" filename
3996 gnus-rmail-save-name gnus-newsgroup-name
3997 gnus-current-headers 'gnus-newsgroup-last-rmail))
3998 (with-current-buffer gnus-save-article-buffer
3999 (save-excursion
4000 (save-restriction
4001 (widen)
4002 ;; Note that unlike gnus-summary-save-in-mail, there is no
4003 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4004 ;; not use Babyl.
4005 (gnus-output-to-rmail filename))))
4006 filename)
4007
4008 (defun gnus-summary-save-in-mail (&optional filename)
4009 "Append this article to Unix mail 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 Unix mail file" filename
4014 gnus-mail-save-name gnus-newsgroup-name
4015 gnus-current-headers 'gnus-newsgroup-last-mail))
4016 (with-current-buffer gnus-save-article-buffer
4017 (save-excursion
4018 (save-restriction
4019 (widen)
4020 (if (and (file-readable-p filename)
4021 (file-regular-p filename)
4022 (mail-file-babyl-p filename))
4023 (gnus-output-to-rmail filename)
4024 (gnus-output-to-mail filename)))))
4025 filename)
4026
4027 (put 'gnus-summary-save-in-file :decode t)
4028 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4029 (defun gnus-summary-save-in-file (&optional filename overwrite)
4030 "Append this article to file.
4031 Optional argument FILENAME specifies file name.
4032 Directory to save to is default to `gnus-article-save-directory'."
4033 (setq filename (gnus-read-save-file-name
4034 "Save %s in file" filename
4035 gnus-file-save-name gnus-newsgroup-name
4036 gnus-current-headers 'gnus-newsgroup-last-file))
4037 (with-current-buffer gnus-save-article-buffer
4038 (save-excursion
4039 (save-restriction
4040 (widen)
4041 (when (and overwrite
4042 (file-exists-p filename))
4043 (delete-file filename))
4044 (gnus-output-to-file filename))))
4045 filename)
4046
4047 (put 'gnus-summary-write-to-file :decode t)
4048 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4049 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4050 (defun gnus-summary-write-to-file (&optional filename)
4051 "Write this article to a file, overwriting it if the file exists.
4052 Optional argument FILENAME specifies file name.
4053 The directory to save in defaults to `gnus-article-save-directory'."
4054 (setq filename (gnus-read-save-file-name
4055 "Save %s in file" filename
4056 gnus-file-save-name gnus-newsgroup-name
4057 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4058 (gnus-summary-save-in-file filename t))
4059
4060 (put 'gnus-summary-save-body-in-file :decode t)
4061 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4062 "Append this article body to a file.
4063 Optional argument FILENAME specifies file name.
4064 The directory to save in defaults to `gnus-article-save-directory'."
4065 (setq filename (gnus-read-save-file-name
4066 "Save %s body in file" filename
4067 gnus-file-save-name gnus-newsgroup-name
4068 gnus-current-headers 'gnus-newsgroup-last-file))
4069 (with-current-buffer gnus-save-article-buffer
4070 (save-excursion
4071 (save-restriction
4072 (widen)
4073 (when (article-goto-body)
4074 (narrow-to-region (point) (point-max)))
4075 (when (and overwrite
4076 (file-exists-p filename))
4077 (delete-file filename))
4078 (gnus-output-to-file filename))))
4079 filename)
4080
4081 (put 'gnus-summary-write-body-to-file :decode t)
4082 (put 'gnus-summary-write-body-to-file
4083 :function 'gnus-summary-save-body-in-file)
4084 (defun gnus-summary-write-body-to-file (&optional filename)
4085 "Write this article body to a file, overwriting it if the file exists.
4086 Optional argument FILENAME specifies file name.
4087 The directory to save in defaults to `gnus-article-save-directory'."
4088 (setq filename (gnus-read-save-file-name
4089 "Save %s body in file" filename
4090 gnus-file-save-name gnus-newsgroup-name
4091 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4092 (gnus-summary-save-body-in-file filename t))
4093
4094 (put 'gnus-summary-save-in-pipe :decode t)
4095 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4096 (defun gnus-summary-save-in-pipe (&optional command raw)
4097 "Pipe this article to subprocess COMMAND.
4098 Valid values for COMMAND include:
4099 a string
4100 The executable command name and possibly arguments.
4101 nil
4102 You will be prompted for the command in the minibuffer.
4103 the symbol `default'
4104 It will be replaced with the command which the variable
4105 `gnus-summary-pipe-output-default-command' holds or the command
4106 last used for saving.
4107 Non-nil value for RAW overrides `:decode' and `:headers' properties
4108 and the raw article including all headers will be piped."
4109 (let ((article (gnus-summary-article-number))
4110 (decode (unless raw
4111 (get 'gnus-summary-save-in-pipe :decode)))
4112 save-buffer default)
4113 (if article
4114 (if (vectorp (gnus-summary-article-header article))
4115 (save-current-buffer
4116 (gnus-summary-select-article decode decode nil article)
4117 (insert-buffer-substring
4118 (prog1
4119 (if decode
4120 gnus-article-buffer
4121 gnus-original-article-buffer)
4122 (setq save-buffer
4123 (nnheader-set-temp-buffer " *Gnus Save*"))))
4124 ;; Remove unwanted headers.
4125 (when (and (not raw)
4126 (or (get 'gnus-summary-save-in-pipe :headers)
4127 (not gnus-save-all-headers)))
4128 (let ((gnus-visible-headers
4129 (or (symbol-value (get 'gnus-summary-save-in-pipe
4130 :headers))
4131 gnus-saved-headers gnus-visible-headers))
4132 (gnus-summary-buffer nil))
4133 (article-hide-headers 1 t))))
4134 (error "%d is not a real article" article))
4135 (error "No article to pipe"))
4136 (setq default (or gnus-summary-pipe-output-default-command
4137 gnus-last-shell-command))
4138 (unless (stringp command)
4139 (setq command
4140 (if (and (eq command 'default) default)
4141 default
4142 (gnus-read-shell-command "Shell command on this article: "
4143 default))))
4144 (when (string-equal command "")
4145 (if default
4146 (setq command default)
4147 (error "A command is required")))
4148 (with-current-buffer save-buffer
4149 (save-restriction
4150 (widen)
4151 (shell-command-on-region (point-min) (point-max) command nil)))
4152 (gnus-kill-buffer save-buffer))
4153 (setq gnus-summary-pipe-output-default-command command))
4154
4155 (defun gnus-summary-pipe-to-muttprint (&optional command)
4156 "Pipe this article to muttprint."
4157 (unless (stringp command)
4158 (setq command (read-string
4159 "Print using command: " gnus-summary-muttprint-program
4160 nil gnus-summary-muttprint-program)))
4161 (let ((gnus-summary-pipe-output-default-command
4162 gnus-summary-pipe-output-default-command))
4163 (gnus-summary-save-in-pipe command))
4164 (setq gnus-summary-muttprint-program command))
4165
4166 ;;; Article file names when saving.
4167
4168 (defun gnus-capitalize-newsgroup (newsgroup)
4169 "Capitalize NEWSGROUP name."
4170 (when (not (zerop (length newsgroup)))
4171 (concat (char-to-string (upcase (aref newsgroup 0)))
4172 (substring newsgroup 1))))
4173
4174 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4175 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4176 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4177 Otherwise, it is like ~/News/news/group/num."
4178 (let ((default
4179 (expand-file-name
4180 (concat (if (gnus-use-long-file-name 'not-save)
4181 (gnus-capitalize-newsgroup newsgroup)
4182 (gnus-newsgroup-directory-form newsgroup))
4183 "/" (int-to-string (mail-header-number headers)))
4184 gnus-article-save-directory)))
4185 (if (and last-file
4186 (string-equal (file-name-directory default)
4187 (file-name-directory last-file))
4188 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4189 default
4190 (or last-file default))))
4191
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
4195 ~/News/news.group/num. 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 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))))
4209
4210 (defun gnus-plain-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. Otherwise, it is like ~/News/news/group/news."
4214 (or last-file
4215 (expand-file-name
4216 (if (gnus-use-long-file-name 'not-save)
4217 newsgroup
4218 (file-relative-name
4219 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4220 default-directory))
4221 gnus-article-save-directory)))
4222
4223 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4224 "Generate file name from sender."
4225 (let ((from (mail-header-from headers)))
4226 (expand-file-name
4227 (if (and from (string-match "\\([^ <]+\\)@" from))
4228 (match-string 1 from)
4229 "nobody")
4230 gnus-article-save-directory)))
4231
4232 (defun article-verify-x-pgp-sig ()
4233 "Verify X-PGP-Sig."
4234 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4235 (interactive)
4236 (if (gnus-buffer-live-p gnus-original-article-buffer)
4237 (let ((sig (with-current-buffer gnus-original-article-buffer
4238 (gnus-fetch-field "X-PGP-Sig")))
4239 items info headers)
4240 (when (and sig
4241 mml2015-use
4242 (mml2015-clear-verify-function))
4243 (with-temp-buffer
4244 (insert-buffer-substring gnus-original-article-buffer)
4245 (setq items (split-string sig))
4246 (message-narrow-to-head)
4247 (let ((inhibit-point-motion-hooks t)
4248 (case-fold-search t))
4249 ;; Don't verify multiple headers.
4250 (setq headers (mapconcat (lambda (header)
4251 (concat header ": "
4252 (mail-fetch-field header)
4253 "\n"))
4254 (split-string (nth 1 items) ",") "")))
4255 (delete-region (point-min) (point-max))
4256 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4257 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4258 (insert headers)
4259 (widen)
4260 (forward-line)
4261 (while (not (eobp))
4262 (if (looking-at "^-")
4263 (insert "- "))
4264 (forward-line))
4265 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4266 (insert "Version: " (car items) "\n\n")
4267 (insert (mapconcat 'identity (cddr items) "\n"))
4268 (insert "\n-----END PGP SIGNATURE-----\n")
4269 (let ((mm-security-handle (list (format "multipart/signed"))))
4270 (mml2015-clean-buffer)
4271 (let ((coding-system-for-write (or gnus-newsgroup-charset
4272 'iso-8859-1)))
4273 (funcall (mml2015-clear-verify-function)))
4274 (setq info
4275 (or (mm-handle-multipart-ctl-parameter
4276 mm-security-handle 'gnus-details)
4277 (mm-handle-multipart-ctl-parameter
4278 mm-security-handle 'gnus-info)))))
4279 (when info
4280 (let ((inhibit-read-only t) bface eface)
4281 (save-restriction
4282 (message-narrow-to-head)
4283 (goto-char (point-max))
4284 (forward-line -1)
4285 (setq bface (get-text-property (point-at-bol) 'face)
4286 eface (get-text-property (1- (point-at-eol)) 'face))
4287 (message-remove-header "X-Gnus-PGP-Verify")
4288 (if (re-search-forward "^X-PGP-Sig:" nil t)
4289 (forward-line)
4290 (goto-char (point-max)))
4291 (narrow-to-region (point) (point))
4292 (insert "X-Gnus-PGP-Verify: " info "\n")
4293 (goto-char (point-min))
4294 (forward-line)
4295 (while (not (eobp))
4296 (if (not (looking-at "^[ \t]"))
4297 (insert " "))
4298 (forward-line))
4299 ;; Do highlighting.
4300 (goto-char (point-min))
4301 (when (looking-at "\\([^:]+\\): *")
4302 (put-text-property (match-beginning 1) (1+ (match-end 1))
4303 'face bface)
4304 (put-text-property (match-end 0) (point-max)
4305 'face eface)))))))))
4306
4307 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4308
4309 (defun article-verify-cancel-lock ()
4310 "Verify Cancel-Lock header."
4311 (interactive)
4312 (if (gnus-buffer-live-p gnus-original-article-buffer)
4313 (canlock-verify gnus-original-article-buffer)))
4314
4315 (eval-and-compile
4316 (mapc
4317 (lambda (func)
4318 (let (afunc gfunc)
4319 (if (consp func)
4320 (setq afunc (car func)
4321 gfunc (cdr func))
4322 (setq afunc func
4323 gfunc (intern (format "gnus-%s" func))))
4324 (defalias gfunc
4325 (when (fboundp afunc)
4326 `(lambda (&optional interactive &rest args)
4327 ,(documentation afunc t)
4328 (interactive (list t))
4329 (with-current-buffer gnus-article-buffer
4330 (if interactive
4331 (call-interactively ',afunc)
4332 (apply ',afunc args))))))))
4333 '(article-hide-headers
4334 article-verify-x-pgp-sig
4335 article-verify-cancel-lock
4336 article-hide-boring-headers
4337 article-treat-overstrike
4338 article-treat-ansi-sequences
4339 article-fill-long-lines
4340 article-capitalize-sentences
4341 article-remove-cr
4342 article-remove-leading-whitespace
4343 article-display-x-face
4344 article-display-face
4345 article-de-quoted-unreadable
4346 article-de-base64-unreadable
4347 article-decode-HZ
4348 article-wash-html
4349 article-unsplit-urls
4350 article-hide-list-identifiers
4351 article-strip-banner
4352 article-babel
4353 article-hide-pem
4354 article-hide-signature
4355 article-strip-headers-in-body
4356 article-remove-trailing-blank-lines
4357 article-strip-leading-blank-lines
4358 article-strip-multiple-blank-lines
4359 article-strip-leading-space
4360 article-strip-trailing-space
4361 article-strip-blank-lines
4362 article-strip-all-blank-lines
4363 article-date-local
4364 article-date-english
4365 article-date-iso8601
4366 article-date-original
4367 article-treat-date
4368 article-date-ut
4369 article-decode-mime-words
4370 article-decode-charset
4371 article-decode-encoded-words
4372 article-date-user
4373 article-date-lapsed
4374 article-date-combined-lapsed
4375 article-emphasize
4376 article-treat-dumbquotes
4377 article-treat-non-ascii
4378 article-normalize-headers
4379 ;;(article-show-all . gnus-article-show-all-headers)
4380 )))
4381 \f
4382 ;;;
4383 ;;; Gnus article mode
4384 ;;;
4385
4386 (put 'gnus-article-mode 'mode-class 'special)
4387
4388 (set-keymap-parent gnus-article-mode-map widget-keymap)
4389
4390 (gnus-define-keys gnus-article-mode-map
4391 " " gnus-article-goto-next-page
4392 [?\S-\ ] gnus-article-goto-prev-page
4393 "\177" gnus-article-goto-prev-page
4394 [delete] gnus-article-goto-prev-page
4395 "\C-c^" gnus-article-refer-article
4396 "h" gnus-article-show-summary
4397 "s" gnus-article-show-summary
4398 "\C-c\C-m" gnus-article-mail
4399 "?" gnus-article-describe-briefly
4400 "<" beginning-of-buffer
4401 ">" end-of-buffer
4402 "\C-c\C-i" gnus-info-find-node
4403 "\C-c\C-b" gnus-bug
4404 "R" gnus-article-reply-with-original
4405 "F" gnus-article-followup-with-original
4406 "\C-hk" gnus-article-describe-key
4407 "\C-hc" gnus-article-describe-key-briefly
4408 "\C-hb" gnus-article-describe-bindings
4409
4410 "e" gnus-article-read-summary-keys
4411 "\C-d" gnus-article-read-summary-keys
4412 "\M-*" gnus-article-read-summary-keys
4413 "\M-#" gnus-article-read-summary-keys
4414 "\M-^" gnus-article-read-summary-keys
4415 "\M-g" gnus-article-read-summary-keys)
4416
4417 (substitute-key-definition
4418 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4419
4420 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4421 "W" gnus-article-wide-reply-with-original)
4422 (if (featurep 'xemacs)
4423 (set-keymap-default-binding gnus-article-send-map
4424 'gnus-article-read-summary-send-keys)
4425 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4426
4427 (defun gnus-article-make-menu-bar ()
4428 (unless (boundp 'gnus-article-commands-menu)
4429 (gnus-summary-make-menu-bar))
4430 (unless (boundp 'gnus-article-article-menu)
4431 (easy-menu-define
4432 gnus-article-article-menu gnus-article-mode-map ""
4433 '("Article"
4434 ["Scroll forwards" gnus-article-goto-next-page t]
4435 ["Scroll backwards" gnus-article-goto-prev-page t]
4436 ["Show summary" gnus-article-show-summary t]
4437 ["Fetch Message-ID at point" gnus-article-refer-article t]
4438 ["Mail to address at point" gnus-article-mail t]
4439 ["Send a bug report" gnus-bug t]))
4440
4441 (easy-menu-define
4442 gnus-article-treatment-menu gnus-article-mode-map ""
4443 ;; Fixme: this should use :active (and maybe :visible).
4444 '("Treatment"
4445 ["Hide headers" gnus-article-hide-headers t]
4446 ["Hide signature" gnus-article-hide-signature t]
4447 ["Hide citation" gnus-article-hide-citation t]
4448 ["Treat overstrike" gnus-article-treat-overstrike t]
4449 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4450 ["Remove carriage return" gnus-article-remove-cr t]
4451 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4452 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4453 ["Remove base64" gnus-article-de-base64-unreadable t]
4454 ["Treat html" gnus-article-wash-html t]
4455 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4456 ["Decode HZ" gnus-article-decode-HZ t]))
4457
4458 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4459
4460 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4461
4462 (gnus-run-hooks 'gnus-article-menu-hook)))
4463
4464 (defvar bookmark-make-record-function)
4465 (defvar shr-put-image-function)
4466
4467 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4468 "Major mode for displaying an article.
4469
4470 All normal editing commands are switched off.
4471
4472 The following commands are available in addition to all summary mode
4473 commands:
4474 \\<gnus-article-mode-map>
4475 \\[gnus-article-next-page]\t Scroll the article one page forwards
4476 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4477 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4478 \\[gnus-article-show-summary]\t Display the summary buffer
4479 \\[gnus-article-mail]\t Send a reply to the address near point
4480 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4481 \\[gnus-info-find-node]\t Go to the Gnus info node"
4482 (gnus-simplify-mode-line)
4483 (make-local-variable 'minor-mode-alist)
4484 (when (gnus-visual-p 'article-menu 'menu)
4485 (gnus-article-make-menu-bar)
4486 (when gnus-summary-tool-bar-map
4487 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4488 (gnus-update-format-specifications nil 'article-mode)
4489 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4490 (set (make-local-variable 'gnus-page-broken) nil)
4491 (make-local-variable 'gnus-article-current-summary)
4492 (make-local-variable 'gnus-article-mime-handles)
4493 (make-local-variable 'gnus-article-decoded-p)
4494 (make-local-variable 'gnus-article-mime-handle-alist)
4495 (make-local-variable 'gnus-article-wash-types)
4496 (make-local-variable 'gnus-article-image-alist)
4497 (make-local-variable 'gnus-article-charset)
4498 (make-local-variable 'gnus-article-ignored-charsets)
4499 (set (make-local-variable 'bookmark-make-record-function)
4500 'gnus-summary-bookmark-make-record)
4501 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4502 ;; face.
4503 (set (make-local-variable 'nobreak-char-display) nil)
4504 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4505 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4506 (setq cursor-in-non-selected-windows nil)
4507 (gnus-set-default-directory)
4508 (buffer-disable-undo)
4509 (setq buffer-read-only t
4510 show-trailing-whitespace nil)
4511 (mm-enable-multibyte))
4512
4513 (defun gnus-article-setup-buffer ()
4514 "Initialize the article buffer."
4515 (let* ((name (if gnus-single-article-buffer "*Article*"
4516 (concat "*Article "
4517 (gnus-group-decoded-name gnus-newsgroup-name)
4518 "*")))
4519 (original
4520 (progn (string-match "\\*Article" name)
4521 (concat " *Original Article"
4522 (substring name (match-end 0))))))
4523 (setq gnus-article-buffer name)
4524 (setq gnus-original-article-buffer original)
4525 (setq gnus-article-mime-handle-alist nil)
4526 (with-current-buffer gnus-summary-buffer
4527 ;; This might be a variable local to the summary buffer.
4528 (unless gnus-single-article-buffer
4529 (setq gnus-article-buffer name)
4530 (setq gnus-original-article-buffer original)
4531 (gnus-set-global-variables)))
4532 (gnus-article-setup-highlight-words)
4533 ;; Init original article buffer.
4534 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4535 (mm-enable-multibyte)
4536 (setq major-mode 'gnus-original-article-mode)
4537 (make-local-variable 'gnus-original-article))
4538 (if (and (get-buffer name)
4539 (with-current-buffer name
4540 (if gnus-article-edit-mode
4541 (if (y-or-n-p "Article mode edit in progress; discard? ")
4542 (progn
4543 (set-buffer-modified-p nil)
4544 (gnus-kill-buffer name)
4545 (message "")
4546 nil)
4547 (error "Action aborted"))
4548 t)))
4549 (let ((summary gnus-summary-buffer))
4550 (with-current-buffer name
4551 (set (make-local-variable 'gnus-article-edit-mode) nil)
4552 (gnus-article-stop-animations)
4553 (when gnus-article-mime-handles
4554 (mm-destroy-parts gnus-article-mime-handles)
4555 (setq gnus-article-mime-handles nil))
4556 ;; Set it to nil in article-buffer!
4557 (setq gnus-article-mime-handle-alist nil)
4558 (buffer-disable-undo)
4559 (setq buffer-read-only t)
4560 (unless (derived-mode-p 'gnus-article-mode)
4561 (gnus-article-mode))
4562 (set (make-local-variable 'gnus-summary-buffer) summary)
4563 (setq truncate-lines gnus-article-truncate-lines)
4564 (current-buffer)))
4565 (let ((summary gnus-summary-buffer))
4566 (with-current-buffer (gnus-get-buffer-create name)
4567 (gnus-article-mode)
4568 (setq truncate-lines gnus-article-truncate-lines)
4569 (set (make-local-variable 'gnus-summary-buffer) summary)
4570 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4571 (when article-lapsed-timer
4572 (gnus-stop-date-timer))
4573 (when gnus-article-update-date-headers
4574 (gnus-start-date-timer gnus-article-update-date-headers))
4575 (current-buffer))))))
4576
4577 (defun gnus-article-stop-animations ()
4578 (dolist (timer (and (boundp 'timer-list)
4579 timer-list))
4580 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4581 (cancel-timer timer))))
4582
4583 (defun gnus-stop-downloads ()
4584 (when (boundp 'url-queue)
4585 (set (intern "url-queue" obarray) nil)))
4586
4587 ;; Set article window start at LINE, where LINE is the number of lines
4588 ;; from the head of the article.
4589 (defun gnus-article-set-window-start (&optional line)
4590 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4591 (when article-window
4592 (set-window-start
4593 article-window
4594 (with-current-buffer gnus-article-buffer
4595 (goto-char (point-min))
4596 (if (not line)
4597 (point-min)
4598 (gnus-message 6 "Moved to bookmark")
4599 (search-forward "\n\n" nil t)
4600 (forward-line line)
4601 (point)))))))
4602
4603 (defun gnus-article-prepare (article &optional all-headers header)
4604 "Prepare ARTICLE in article mode buffer.
4605 ARTICLE should either be an article number or a Message-ID.
4606 If ARTICLE is an id, HEADER should be the article headers.
4607 If ALL-HEADERS is non-nil, no headers are hidden."
4608 (save-excursion
4609 ;; Make sure we start in a summary buffer.
4610 (unless (derived-mode-p 'gnus-summary-mode)
4611 (set-buffer gnus-summary-buffer))
4612 (setq gnus-summary-buffer (current-buffer))
4613 (let* ((gnus-article (if header (mail-header-number header) article))
4614 (summary-buffer (current-buffer))
4615 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4616 (group gnus-newsgroup-name)
4617 result)
4618 (save-excursion
4619 (gnus-article-setup-buffer)
4620 (set-buffer gnus-article-buffer)
4621 ;; Deactivate active regions.
4622 (when (and (boundp 'transient-mark-mode)
4623 transient-mark-mode)
4624 (setq mark-active nil))
4625 (if (not (setq result (let ((inhibit-read-only t))
4626 (gnus-request-article-this-buffer
4627 article group))))
4628 ;; There is no such article.
4629 (save-excursion
4630 (when (and (numberp article)
4631 (not (memq article gnus-newsgroup-sparse)))
4632 (setq gnus-article-current
4633 (cons gnus-newsgroup-name article))
4634 (set-buffer gnus-summary-buffer)
4635 (setq gnus-current-article article)
4636 (if (and (memq article gnus-newsgroup-undownloaded)
4637 (not (gnus-online (gnus-find-method-for-group
4638 gnus-newsgroup-name))))
4639 (progn
4640 (gnus-summary-set-agent-mark article)
4641 (message "Message marked for downloading"))
4642 (gnus-summary-mark-article article gnus-canceled-mark)
4643 (unless (memq article gnus-newsgroup-sparse)
4644 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4645 (if (or (eq result 'pseudo)
4646 (eq result 'nneething))
4647 (progn
4648 (with-current-buffer summary-buffer
4649 (push article gnus-newsgroup-history)
4650 (setq gnus-last-article gnus-current-article
4651 gnus-current-article 0
4652 gnus-current-headers nil
4653 gnus-article-current nil)
4654 (if (eq result 'nneething)
4655 (gnus-configure-windows 'summary)
4656 (gnus-configure-windows 'article))
4657 (gnus-set-global-variables))
4658 (let ((gnus-article-mime-handle-alist-1
4659 gnus-article-mime-handle-alist))
4660 (gnus-set-mode-line 'article)))
4661 ;; The result from the `request' was an actual article -
4662 ;; or at least some text that is now displayed in the
4663 ;; article buffer.
4664 (when (and (numberp article)
4665 (not (eq article gnus-current-article)))
4666 ;; Seems like a new article has been selected.
4667 ;; `gnus-current-article' must be an article number.
4668 (with-current-buffer summary-buffer
4669 (push article gnus-newsgroup-history)
4670 (setq gnus-last-article gnus-current-article
4671 gnus-current-article article
4672 gnus-current-headers
4673 (gnus-summary-article-header gnus-current-article)
4674 gnus-article-current
4675 (cons gnus-newsgroup-name gnus-current-article))
4676 (unless (vectorp gnus-current-headers)
4677 (setq gnus-current-headers nil))
4678 (gnus-summary-goto-subject gnus-current-article)
4679 (when (gnus-summary-show-thread)
4680 ;; If the summary buffer really was folded, the
4681 ;; previous goto may not actually have gone to
4682 ;; the right article, but the thread root instead.
4683 ;; So we go again.
4684 (gnus-summary-goto-subject gnus-current-article))
4685 (gnus-run-hooks 'gnus-mark-article-hook)
4686 (gnus-set-mode-line 'summary)
4687 (when (gnus-visual-p 'article-highlight 'highlight)
4688 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4689 ;; Set the global newsgroup variables here.
4690 (gnus-set-global-variables)
4691 (setq gnus-have-all-headers
4692 (or all-headers gnus-show-all-headers))))
4693 (save-excursion
4694 (gnus-configure-windows 'article))
4695 (when (or (numberp article)
4696 (stringp article))
4697 (gnus-article-prepare-display)
4698 ;; Do page break.
4699 (goto-char (point-min))
4700 (when gnus-break-pages
4701 (gnus-narrow-to-page)))
4702 (let ((gnus-article-mime-handle-alist-1
4703 gnus-article-mime-handle-alist))
4704 (gnus-set-mode-line 'article))
4705 (article-goto-body)
4706 (unless (bobp)
4707 (forward-line -1))
4708 (set-window-point (get-buffer-window (current-buffer)) (point))
4709 (gnus-configure-windows 'article)
4710 (gnus-run-hooks 'gnus-article-prepare-hook)
4711 t))))))
4712
4713 ;;;###autoload
4714 (defun gnus-article-prepare-display ()
4715 "Make the current buffer look like a nice article."
4716 ;; Hooks for getting information from the article.
4717 ;; This hook must be called before being narrowed.
4718 (let ((gnus-article-buffer (current-buffer))
4719 buffer-read-only
4720 (inhibit-read-only t))
4721 (unless (derived-mode-p 'gnus-article-mode)
4722 (gnus-article-mode))
4723 (setq buffer-read-only nil
4724 gnus-article-wash-types nil
4725 gnus-article-image-alist nil)
4726 (gnus-run-hooks 'gnus-tmp-internal-hook)
4727 (when gnus-display-mime-function
4728 (funcall gnus-display-mime-function))
4729 ;; Add attachment buttons to the header.
4730 (when gnus-mime-display-attachment-buttons-in-header
4731 (gnus-mime-buttonize-attachments-in-header))))
4732
4733 ;;;
4734 ;;; Gnus Sticky Article Mode
4735 ;;;
4736
4737 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4738 "Mode for sticky articles."
4739 ;; Release bindings that won't work.
4740 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4741 gnus-sticky-article-mode-map)
4742 (substitute-key-definition 'gnus-article-refer-article 'undefined
4743 gnus-sticky-article-mode-map)
4744 (dolist (k '("e" "h" "s" "F" "R"))
4745 (define-key gnus-sticky-article-mode-map k nil))
4746 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4747 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4748 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4749 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4750
4751 (defun gnus-sticky-article (arg)
4752 "Make the current article sticky.
4753 If a prefix ARG is given, ask for a name for this sticky article buffer."
4754 (interactive "P")
4755 (gnus-summary-show-thread)
4756 (gnus-summary-select-article nil nil 'pseudo)
4757 (let (new-art-buf-name)
4758 (gnus-eval-in-buffer-window gnus-article-buffer
4759 (setq new-art-buf-name
4760 (concat
4761 "*Sticky Article: "
4762 (if arg
4763 (read-from-minibuffer "Sticky article buffer name: ")
4764 (gnus-with-article-headers
4765 (gnus-article-goto-header "subject")
4766 (setq new-art-buf-name
4767 (buffer-substring-no-properties
4768 (line-beginning-position) (line-end-position)))
4769 (goto-char (point-min))
4770 (gnus-article-goto-header "from")
4771 (setq new-art-buf-name
4772 (concat
4773 new-art-buf-name ", "
4774 (buffer-substring-no-properties
4775 (line-beginning-position) (line-end-position))))
4776 (goto-char (point-min))
4777 (gnus-article-goto-header "date")
4778 (setq new-art-buf-name
4779 (concat
4780 new-art-buf-name ", "
4781 (buffer-substring-no-properties
4782 (line-beginning-position) (line-end-position))))))
4783 "*"))
4784 (if (and (gnus-buffer-live-p new-art-buf-name)
4785 (with-current-buffer new-art-buf-name
4786 (derived-mode-p 'gnus-sticky-article-mode)))
4787 (switch-to-buffer new-art-buf-name)
4788 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4789 (gnus-sticky-article-mode))
4790 (setq gnus-article-buffer new-art-buf-name))
4791 (gnus-summary-recenter)
4792 (gnus-summary-position-point))
4793
4794 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4795 "Kill the given sticky article BUFFER.
4796 If none is given, assume the current buffer and kill it if it has
4797 `gnus-sticky-article-mode'."
4798 (interactive)
4799 (unless buffer
4800 (setq buffer (current-buffer)))
4801 (with-current-buffer buffer
4802 (when (derived-mode-p 'gnus-sticky-article-mode)
4803 (gnus-kill-buffer buffer))))
4804
4805 (defun gnus-kill-sticky-article-buffers (arg)
4806 "Kill all sticky article buffers.
4807 If a prefix ARG is given, ask for confirmation."
4808 (interactive "P")
4809 (dolist (buf (gnus-buffers))
4810 (with-current-buffer buf
4811 (when (derived-mode-p 'gnus-sticky-article-mode)
4812 (if (not arg)
4813 (gnus-kill-buffer buf)
4814 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4815 (gnus-kill-buffer buf)))))))
4816
4817 ;;;
4818 ;;; Gnus MIME viewing functions
4819 ;;;
4820
4821 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4822 "Format of the MIME buttons.
4823
4824 Valid specifiers include:
4825 %t The MIME type
4826 %T MIME type, along with additional info
4827 %n The `name' parameter
4828 %d The description, if any
4829 %l The length of the encoded part
4830 %p The part identifier number
4831 %e Dots if the part isn't displayed
4832
4833 General format specifiers can also be used. See Info node
4834 `(gnus)Formatting Variables'.")
4835
4836 (defvar gnus-mime-button-line-format-alist
4837 '((?t gnus-tmp-type ?s)
4838 (?T gnus-tmp-type-long ?s)
4839 (?n gnus-tmp-name ?s)
4840 (?d gnus-tmp-description ?s)
4841 (?p gnus-tmp-id ?s)
4842 (?l gnus-tmp-length ?d)
4843 (?e gnus-tmp-dots ?s)))
4844
4845 (defvar gnus-mime-button-commands
4846 '((gnus-article-press-button "\r" "Toggle Display")
4847 (gnus-mime-view-part "v" "View Interactively...")
4848 (gnus-mime-view-part-as-type "t" "View As Type...")
4849 (gnus-mime-view-part-as-charset "C" "View As charset...")
4850 (gnus-mime-save-part "o" "Save...")
4851 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4852 (gnus-mime-replace-part "r" "Replace part")
4853 (gnus-mime-delete-part "d" "Delete part")
4854 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4855 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4856 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4857 (gnus-mime-view-part-externally "e" "View Externally")
4858 (gnus-mime-print-part "p" "Print")
4859 (gnus-mime-pipe-part "|" "Pipe To Command...")
4860 (gnus-mime-action-on-part "." "Take action on the part...")))
4861
4862 (defun gnus-article-mime-part-status ()
4863 (if gnus-article-mime-handle-alist-1
4864 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4865 " (1 part)"
4866 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4867 ""))
4868
4869 (defvar gnus-mime-button-map
4870 (let ((map (make-sparse-keymap)))
4871 (define-key map gnus-mouse-2 'gnus-article-push-button)
4872 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4873 (dolist (c gnus-mime-button-commands)
4874 (define-key map (cadr c) (car c)))
4875 map))
4876
4877 (easy-menu-define
4878 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4879 `("MIME Part"
4880 ,@(mapcar (lambda (c)
4881 (vector (caddr c) (car c) :active t))
4882 gnus-mime-button-commands)))
4883
4884 (defvar gnus-url-button-commands
4885 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4886
4887 (defvar gnus-url-button-map
4888 (let ((map (make-sparse-keymap)))
4889 (dolist (c gnus-url-button-commands)
4890 (define-key map (cadr c) (car c)))
4891 map))
4892
4893 (easy-menu-define
4894 gnus-url-button-menu gnus-url-button-map "URL button menu."
4895 `("Url Button"
4896 ,@(mapcar (lambda (c)
4897 (vector (caddr c) (car c) :active t))
4898 gnus-url-button-commands)))
4899
4900 (defmacro gnus-bind-safe-url-regexp (&rest body)
4901 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4902 `(let ((mm-w3m-safe-url-regexp
4903 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4904 (gnus-buffer-live-p
4905 gnus-article-current-summary))
4906 (with-current-buffer gnus-article-current-summary
4907 gnus-newsgroup-name)
4908 gnus-newsgroup-name)))
4909 (if (cond ((not group)
4910 ;; Maybe we're in a mml-preview buffer
4911 ;; and no group is selected.
4912 t)
4913 ((stringp gnus-safe-html-newsgroups)
4914 (string-match gnus-safe-html-newsgroups group))
4915 ((consp gnus-safe-html-newsgroups)
4916 (member group gnus-safe-html-newsgroups)))
4917 nil
4918 mm-w3m-safe-url-regexp))))
4919 ,@body))
4920
4921 (defun gnus-mime-button-menu (event prefix)
4922 "Construct a context-sensitive menu of MIME commands."
4923 (interactive "e\nP")
4924 (save-window-excursion
4925 (let ((pos (event-start event)))
4926 (select-window (posn-window pos))
4927 (goto-char (posn-point pos))
4928 (gnus-article-check-buffer)
4929 (popup-menu gnus-mime-button-menu nil prefix))))
4930
4931 (defun gnus-mime-view-all-parts (&optional handles)
4932 "View all the MIME parts."
4933 (interactive)
4934 (with-current-buffer gnus-article-buffer
4935 (let ((handles (or handles gnus-article-mime-handles))
4936 (mail-parse-charset gnus-newsgroup-charset)
4937 (mail-parse-ignored-charsets
4938 (with-current-buffer gnus-summary-buffer
4939 gnus-newsgroup-ignored-charsets)))
4940 (when handles
4941 (mm-remove-parts handles)
4942 (goto-char (point-min))
4943 (or (search-forward "\n\n") (goto-char (point-max)))
4944 (let ((inhibit-read-only t))
4945 (delete-region (point) (point-max))
4946 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4947
4948 (defun gnus-article-jump-to-part (n)
4949 "Jump to MIME part N."
4950 (interactive "P")
4951 (let ((parts (with-current-buffer gnus-article-buffer
4952 (length gnus-article-mime-handle-alist))))
4953 (when (zerop parts)
4954 (error "No such part"))
4955 (pop-to-buffer gnus-article-buffer)
4956 (or n
4957 (setq n (if (= parts 1)
4958 1
4959 (read-number (format "Jump to part (1..%s): " parts)))))
4960 (unless (and (integerp n) (<= n parts) (>= n 1))
4961 (setq n
4962 (progn
4963 (gnus-message 7 "Invalid part `%s', using %s instead."
4964 n parts)
4965 parts)))
4966 (gnus-message 9 "Jumping to part %s." n)
4967 (cond ((>= gnus-auto-select-part 1)
4968 (while (and (<= n parts)
4969 (not (gnus-article-goto-part n)))
4970 (setq n (1+ n))))
4971 ((< gnus-auto-select-part 0)
4972 (while (and (>= n 1)
4973 (not (gnus-article-goto-part n)))
4974 (setq n (1- n))))
4975 (t
4976 (gnus-article-goto-part n)))))
4977
4978 (defvar gnus-mime-buttonized-part-id nil
4979 "ID of a mime part that should be buttonized.
4980 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4981
4982 (eval-when-compile
4983 (defsubst gnus-article-edit-part (handles &optional current-id)
4984 "Edit an article in order to delete a mime part.
4985 This function is exclusively used by `gnus-mime-save-part-and-strip'
4986 and `gnus-mime-delete-part', and not provided at run-time normally."
4987 (gnus-article-edit-article
4988 `(lambda ()
4989 (buffer-disable-undo)
4990 (erase-buffer)
4991 (let ((mail-parse-charset (or gnus-article-charset
4992 ',gnus-newsgroup-charset))
4993 (mail-parse-ignored-charsets
4994 (or gnus-article-ignored-charsets
4995 ',gnus-newsgroup-ignored-charsets))
4996 (mbl mml-buffer-list))
4997 (setq mml-buffer-list nil)
4998 (insert-buffer-substring gnus-original-article-buffer)
4999 (mime-to-mml ',handles)
5000 (setq gnus-article-mime-handles nil)
5001 (let ((mbl1 mml-buffer-list))
5002 (setq mml-buffer-list mbl)
5003 (set (make-local-variable 'mml-buffer-list) mbl1))
5004 (gnus-make-local-hook 'kill-buffer-hook)
5005 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5006 `(lambda (no-highlight)
5007 (let ((mail-parse-charset (or gnus-article-charset
5008 ',gnus-newsgroup-charset))
5009 (message-options message-options)
5010 (message-options-set-recipient)
5011 (mail-parse-ignored-charsets
5012 (or gnus-article-ignored-charsets
5013 ',gnus-newsgroup-ignored-charsets)))
5014 (mml-to-mime)
5015 (mml-destroy-buffers)
5016 (remove-hook 'kill-buffer-hook
5017 'mml-destroy-buffers t)
5018 (kill-local-variable 'mml-buffer-list))
5019 (gnus-summary-edit-article-done
5020 ,(or (mail-header-references gnus-current-headers) "")
5021 ,(gnus-group-read-only-p)
5022 ,gnus-summary-buffer no-highlight))
5023 t)
5024 ;; Force buttonizing this part.
5025 (let ((gnus-mime-buttonized-part-id current-id))
5026 (gnus-article-edit-done))
5027 (gnus-configure-windows 'article)
5028 (when (and current-id (integerp gnus-auto-select-part))
5029 (gnus-article-jump-to-part
5030 (min (max (+ current-id gnus-auto-select-part) 1)
5031 (with-current-buffer gnus-article-buffer
5032 (length gnus-article-mime-handle-alist)))))))
5033
5034 (defun gnus-mime-replace-part (file)
5035 "Replace MIME part under point with an external body."
5036 ;; Useful if file has already been saved to disk
5037 (interactive
5038 (list
5039 (read-file-name "Replace MIME part with file: "
5040 (or mm-default-directory default-directory)
5041 nil nil)))
5042 (gnus-mime-save-part-and-strip file))
5043
5044 (defun gnus-mime-save-part-and-strip (&optional file)
5045 "Save the MIME part under point then replace it with an external body.
5046 If FILE is given, use it for the external part."
5047 (interactive)
5048 (gnus-article-check-buffer)
5049 (when (gnus-group-read-only-p)
5050 (error "The current group does not support deleting of parts"))
5051 (when (mm-complicated-handles gnus-article-mime-handles)
5052 (error "\
5053 The current article has a complicated MIME structure, giving up..."))
5054 (let* ((data (get-text-property (point) 'gnus-data))
5055 (id (get-text-property (point) 'gnus-part))
5056 param
5057 (handles gnus-article-mime-handles))
5058 (unless file
5059 (setq file
5060 (and data (mm-save-part data "Delete MIME part and save to: "))))
5061 (when file
5062 (with-current-buffer (mm-handle-buffer data)
5063 (erase-buffer)
5064 (insert "Content-Type: " (mm-handle-media-type data))
5065 (mml-insert-parameter-string (cdr (mm-handle-type data))
5066 '(charset))
5067 ;; Add a filename for the sake of saving the part again.
5068 (mml-insert-parameter
5069 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5070 (insert "\n")
5071 (insert "Content-ID: " (message-make-message-id) "\n")
5072 (insert "Content-Transfer-Encoding: binary\n")
5073 (insert "\n"))
5074 (setcdr data
5075 (cdr (mm-make-handle nil
5076 `("message/external-body"
5077 (access-type . "LOCAL-FILE")
5078 (name . ,file)))))
5079 ;; (set-buffer gnus-summary-buffer)
5080 (gnus-article-edit-part handles id))))
5081
5082 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5083 ;; parts...>') but with stripping would be nice.
5084
5085 (defun gnus-mime-delete-part ()
5086 "Delete the MIME part under point.
5087 Replace it with some information about the removed part."
5088 (interactive)
5089 (gnus-article-check-buffer)
5090 (when (gnus-group-read-only-p)
5091 (error "The current group does not support deleting of parts"))
5092 (when (mm-complicated-handles gnus-article-mime-handles)
5093 (error "\
5094 The current article has a complicated MIME structure, giving up..."))
5095 (when (or gnus-expert-user
5096 (gnus-yes-or-no-p "\
5097 Deleting parts may malfunction or destroy the article; continue? "))
5098 (let* ((data (get-text-property (point) 'gnus-data))
5099 (id (get-text-property (point) 'gnus-part))
5100 (handles gnus-article-mime-handles)
5101 (description
5102 (let ((desc (mm-handle-description data)))
5103 (when desc
5104 (mail-decode-encoded-word-string desc))))
5105 (filename (or (mm-handle-filename data) "(none)"))
5106 (type (mm-handle-media-type data)))
5107 (unless data
5108 (error "No MIME part under point"))
5109 (with-current-buffer (mm-handle-buffer data)
5110 (let ((bsize (buffer-size)))
5111 (erase-buffer)
5112 (insert
5113 (concat
5114 ",----\n"
5115 "| The following attachment has been deleted:\n"
5116 "|\n"
5117 "| Type: " type "\n"
5118 "| Filename: " filename "\n"
5119 "| Size (encoded): " (format "%s byte%s\n"
5120 bsize (if (= bsize 1)
5121 ""
5122 "s"))
5123 (when description
5124 (concat "| Description: " description "\n"))
5125 "`----\n"))
5126 (setcdr data
5127 (cdr (mm-make-handle
5128 nil `("text/plain" (charset . gnus-decoded)) nil nil
5129 (list "attachment")
5130 (format "Deleted attachment (%s bytes)" bsize))))))
5131 ;; (set-buffer gnus-summary-buffer)
5132 (gnus-article-edit-part handles id))))
5133
5134 (defun gnus-mime-save-part ()
5135 "Save the MIME part under point."
5136 (interactive)
5137 (gnus-article-check-buffer)
5138 (let ((data (get-text-property (point) 'gnus-data)))
5139 (when data
5140 (mm-save-part data))))
5141
5142 (defun gnus-mime-pipe-part (&optional cmd)
5143 "Pipe the MIME part under point to a process.
5144 Use CMD as the process."
5145 (interactive)
5146 (gnus-article-check-buffer)
5147 (let ((data (get-text-property (point) 'gnus-data)))
5148 (when data
5149 (mm-pipe-part data cmd))))
5150
5151 (defun gnus-mime-view-part ()
5152 "Interactively choose a viewing method for the MIME part under point."
5153 (interactive)
5154 (gnus-article-check-buffer)
5155 (let ((data (get-text-property (point) 'gnus-data)))
5156 (when data
5157 (setq gnus-article-mime-handles
5158 (mm-merge-handles
5159 gnus-article-mime-handles (setq data (copy-sequence data))))
5160 (mm-interactively-view-part data))))
5161
5162 (defun gnus-mime-view-part-as-type-internal ()
5163 (gnus-article-check-buffer)
5164 (let* ((handle (get-text-property (point) 'gnus-data))
5165 (name (or
5166 ;; Content-Type: foo/bar; name=...
5167 (mail-content-type-get (mm-handle-type handle) 'name)
5168 ;; Content-Disposition: attachment; filename=...
5169 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5170 (def-type (and name (mm-default-file-encoding name))))
5171 (or (and def-type (cons def-type 0))
5172 (and handle
5173 (equal (mm-handle-media-supertype handle) "text")
5174 '("text/plain" . 0))
5175 '("application/octet-stream" . 0))))
5176
5177 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5178 "Choose a MIME media type, and view the part as such.
5179 If non-nil, PRED is a predicate to use during completion to limit the
5180 available media-types."
5181 (interactive)
5182 (unless mime-type
5183 (setq mime-type
5184 (let ((default (gnus-mime-view-part-as-type-internal)))
5185 (gnus-completing-read
5186 "View as MIME type"
5187 (if pred
5188 (gnus-remove-if-not pred (mailcap-mime-types))
5189 (mailcap-mime-types))
5190 nil nil nil
5191 (car default)))))
5192 (gnus-article-check-buffer)
5193 (let ((handle (get-text-property (point) 'gnus-data)))
5194 (when handle
5195 (when (equal (mm-handle-media-type handle) "message/external-body")
5196 (unless (mm-handle-cache handle)
5197 (mm-extern-cache-contents handle))
5198 (setq handle (mm-handle-cache handle)))
5199 (setq handle
5200 (mm-make-handle (mm-handle-buffer handle)
5201 (cons mime-type (cdr (mm-handle-type handle)))
5202 (mm-handle-encoding handle)
5203 (mm-handle-undisplayer handle)
5204 (mm-handle-disposition handle)
5205 (mm-handle-description handle)
5206 nil
5207 (mm-handle-id handle)))
5208 (setq gnus-article-mime-handles
5209 (mm-merge-handles gnus-article-mime-handles handle))
5210 (when (mm-handle-displayed-p handle)
5211 (mm-remove-part handle))
5212 (gnus-mm-display-part handle))))
5213
5214 (defun gnus-mime-copy-part (&optional handle arg)
5215 "Put the MIME part under point into a new buffer.
5216 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5217 are decompressed."
5218 (interactive (list nil current-prefix-arg))
5219 (gnus-article-check-buffer)
5220 (unless handle
5221 (setq handle (get-text-property (point) 'gnus-data)))
5222 (when handle
5223 (let ((filename (mm-handle-filename handle))
5224 contents dont-decode charset coding-system)
5225 (mm-with-unibyte-buffer
5226 (mm-insert-part handle)
5227 (setq contents (or (condition-case nil
5228 (mm-decompress-buffer filename nil 'sig)
5229 (error
5230 (setq dont-decode t)
5231 nil))
5232 (buffer-string))))
5233 (setq filename (cond (filename (file-name-nondirectory filename))
5234 (dont-decode "*raw data*")
5235 (t "*decoded*")))
5236 (cond
5237 (dont-decode)
5238 ((not arg)
5239 (unless (setq charset (mail-content-type-get
5240 (mm-handle-type handle) 'charset))
5241 (unless (setq coding-system (mm-with-unibyte-buffer
5242 (insert contents)
5243 (mm-find-buffer-file-coding-system)))
5244 (setq charset gnus-newsgroup-charset))))
5245 ((numberp arg)
5246 (setq charset (or (cdr (assq arg
5247 gnus-summary-show-article-charset-alist))
5248 (mm-read-coding-system "Charset: ")))))
5249 (switch-to-buffer (generate-new-buffer filename))
5250 (if (or coding-system
5251 (and charset
5252 (setq coding-system (mm-charset-to-coding-system
5253 charset nil t))
5254 (not (eq coding-system 'ascii))))
5255 (progn
5256 (mm-enable-multibyte)
5257 (insert (mm-decode-coding-string contents coding-system))
5258 (setq buffer-file-coding-system
5259 (if (boundp 'last-coding-system-used)
5260 (symbol-value 'last-coding-system-used)
5261 coding-system)))
5262 (mm-disable-multibyte)
5263 (insert contents)
5264 (setq buffer-file-coding-system mm-binary-coding-system))
5265 ;; We do it this way to make `normal-mode' set the appropriate mode.
5266 (unwind-protect
5267 (progn
5268 (setq buffer-file-name (expand-file-name filename))
5269 (normal-mode))
5270 (setq buffer-file-name nil))
5271 (goto-char (point-min)))))
5272
5273 (defun gnus-mime-print-part (&optional handle filename)
5274 "Print the MIME part under point."
5275 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5276 (gnus-article-check-buffer)
5277 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5278 (contents (and handle (mm-get-part handle)))
5279 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5280 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5281 (when contents
5282 (if printer
5283 (unwind-protect
5284 (progn
5285 (mm-save-part-to-file handle file)
5286 (call-process shell-file-name nil
5287 (generate-new-buffer " *mm*")
5288 nil
5289 shell-command-switch
5290 (mm-mailcap-command
5291 printer file (mm-handle-type handle))))
5292 (delete-file file))
5293 (with-temp-buffer
5294 (insert contents)
5295 (gnus-print-buffer))
5296 (ps-despool filename)))))
5297
5298 (defun gnus-mime-inline-part (&optional handle arg)
5299 "Insert the MIME part under point into the current buffer.
5300 Compressed files like .gz and .bz2 are decompressed."
5301 (interactive (list nil current-prefix-arg))
5302 (gnus-article-check-buffer)
5303 (unless handle
5304 (setq handle (get-text-property (point) 'gnus-data)))
5305 (when handle
5306 (let ((b (point))
5307 (inhibit-read-only t)
5308 contents charset coding-system)
5309 (if (and (not arg) (mm-handle-undisplayer handle))
5310 (mm-remove-part handle)
5311 (mm-with-unibyte-buffer
5312 (mm-insert-part handle)
5313 (setq contents
5314 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5315 (buffer-string))))
5316 (cond
5317 ((not arg)
5318 (unless (setq charset (mail-content-type-get
5319 (mm-handle-type handle) 'charset))
5320 (unless (setq coding-system
5321 (mm-with-unibyte-buffer
5322 (insert contents)
5323 (mm-find-buffer-file-coding-system)))
5324 (setq charset gnus-newsgroup-charset))))
5325 ((numberp arg)
5326 (if (mm-handle-undisplayer handle)
5327 (mm-remove-part handle))
5328 (setq charset
5329 (or (cdr (assq arg
5330 gnus-summary-show-article-charset-alist))
5331 (mm-read-coding-system "Charset: "))))
5332 ((mm-handle-undisplayer handle)
5333 (mm-remove-part handle)))
5334 (forward-line 1)
5335 (mm-display-inline handle)
5336 (goto-char b)))))
5337
5338 (defun gnus-mime-set-charset-parameters (handle charset)
5339 "Set CHARSET to parameters in HANDLE.
5340 CHARSET may either be a string or a symbol."
5341 (unless (stringp charset)
5342 (setq charset (symbol-name charset)))
5343 (if (stringp (car handle))
5344 (dolist (h (cdr handle))
5345 (gnus-mime-set-charset-parameters h charset))
5346 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5347 "message/external-body")
5348 (progn
5349 (unless (mm-handle-cache handle)
5350 (mm-extern-cache-contents handle))
5351 (mm-handle-cache handle))
5352 handle)))
5353 (param (assq 'charset (cdr type))))
5354 (if param
5355 (setcdr param charset)
5356 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5357
5358 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5359 "Insert the MIME part under point into the current buffer using the
5360 specified charset."
5361 (interactive (list nil current-prefix-arg))
5362 (gnus-article-check-buffer)
5363 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5364 (fun (get-text-property (point) 'gnus-callback))
5365 (gnus-newsgroup-ignored-charsets 'gnus-all)
5366 charset form preferred parts)
5367 (when handle
5368 (when (prog1
5369 (and fun
5370 (setq charset
5371 (or (cdr (assq
5372 arg
5373 gnus-summary-show-article-charset-alist))
5374 (mm-read-coding-system "Charset: "))))
5375 (if (mm-handle-undisplayer handle)
5376 (mm-remove-part handle)))
5377 (gnus-mime-set-charset-parameters handle charset)
5378 (when (and (consp (setq form (cdr-safe fun)))
5379 (setq form (ignore-errors
5380 (assq 'gnus-mime-display-alternative form)))
5381 (setq preferred (caddr form))
5382 (progn
5383 (when (eq (car preferred) 'quote)
5384 (setq preferred (cadr preferred)))
5385 (not (equal preferred
5386 (get-text-property (point) 'gnus-data))))
5387 (setq parts (get-text-property (point) 'gnus-part))
5388 (setq parts (cdr (assq parts
5389 gnus-article-mime-handle-alist)))
5390 (equal (mm-handle-media-type parts) "multipart/alternative")
5391 (setq parts (reverse (cdr parts))))
5392 (setcar (cddr form)
5393 (list 'quote (or (cadr (member preferred parts))
5394 (car parts)))))
5395 (funcall fun handle)))))
5396
5397 (defun gnus-mime-view-part-externally (&optional handle)
5398 "View the MIME part under point with an external viewer."
5399 (interactive)
5400 (gnus-article-check-buffer)
5401 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5402 (mm-user-display-methods nil)
5403 (mm-inlined-types nil)
5404 (mail-parse-charset gnus-newsgroup-charset)
5405 (mail-parse-ignored-charsets
5406 (with-current-buffer gnus-summary-buffer
5407 gnus-newsgroup-ignored-charsets))
5408 (type (mm-handle-media-type handle))
5409 (method (mailcap-mime-info type))
5410 (mm-enable-external t))
5411 (if (not (stringp method))
5412 (gnus-mime-view-part-as-type
5413 nil (lambda (type) (stringp (mailcap-mime-info type))))
5414 (when handle
5415 (mm-display-part handle nil t)))))
5416
5417 (defun gnus-mime-view-part-internally (&optional handle)
5418 "View the MIME part under point with an internal viewer.
5419 If no internal viewer is available, use an external viewer."
5420 (interactive)
5421 (gnus-article-check-buffer)
5422 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5423 (mm-inlined-types '(".*"))
5424 (mm-inline-large-images t)
5425 (mail-parse-charset gnus-newsgroup-charset)
5426 (mail-parse-ignored-charsets
5427 (with-current-buffer gnus-summary-buffer
5428 gnus-newsgroup-ignored-charsets))
5429 (inhibit-read-only t))
5430 (if (not (mm-inlinable-p handle))
5431 (gnus-mime-view-part-as-type
5432 nil (lambda (type) (mm-inlinable-p handle type)))
5433 (when handle
5434 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5435
5436 (defun gnus-mime-action-on-part (&optional action)
5437 "Do something with the MIME attachment at \(point\)."
5438 (interactive
5439 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5440 (gnus-article-check-buffer)
5441 (let ((action-pair (assoc action gnus-mime-action-alist)))
5442 (if action-pair
5443 (funcall (cdr action-pair)))))
5444
5445 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5446 "Call FUNCTION on MIME part N.
5447 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5448 If INTERACTIVE, call FUNCTION interactively."
5449 (let (window frame)
5450 ;; Check whether the article is displayed.
5451 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5452 (setq window (get-buffer-window gnus-article-buffer t))
5453 (frame-visible-p (setq frame (window-frame window))))
5454 (error "No article is displayed"))
5455 (with-current-buffer gnus-article-buffer
5456 ;; Check whether the article displays the right contents.
5457 (unless (with-current-buffer gnus-summary-buffer
5458 (eq gnus-current-article (gnus-summary-article-number)))
5459 (error "You should select the right article first"))
5460 (if n
5461 (setq n (prefix-numeric-value n))
5462 (let ((pt (point)))
5463 (setq n (or (get-text-property pt 'gnus-part)
5464 (and (not (bobp))
5465 (get-text-property (1- pt) 'gnus-part))
5466 (get-text-property (prog2
5467 (forward-line 1)
5468 (point)
5469 (goto-char pt))
5470 'gnus-part)
5471 (get-text-property
5472 (or (and (setq pt (previous-single-property-change
5473 pt 'gnus-part))
5474 (1- pt))
5475 (next-single-property-change (point) 'gnus-part)
5476 (point))
5477 'gnus-part)
5478 1))))
5479 ;; Check whether the specified part exists.
5480 (when (> n (length gnus-article-mime-handle-alist))
5481 (error "No such part")))
5482 (unless
5483 (progn
5484 ;; To select the window is needed so that the cursor
5485 ;; might be visible on the MIME button.
5486 (select-window (prog1
5487 window
5488 (setq window (selected-window))
5489 ;; Article may be displayed in the other frame.
5490 (gnus-select-frame-set-input-focus
5491 (prog1
5492 frame
5493 (setq frame (selected-frame))))))
5494 (when (gnus-article-goto-part n)
5495 ;; We point the cursor and the arrow at the MIME button
5496 ;; when the `function' prompt the user for something.
5497 (unless (and (pos-visible-in-window-p)
5498 (> (count-lines (point) (window-end))
5499 (/ (1- (window-height)) 3)))
5500 (recenter (/ (1- (window-height)) 3)))
5501 (let ((cursor-in-non-selected-windows t)
5502 (overlay-arrow-string "=>")
5503 (overlay-arrow-position (point-marker)))
5504 (unwind-protect
5505 (cond
5506 ((and no-handle interactive)
5507 (call-interactively function))
5508 (no-handle
5509 (funcall function))
5510 (interactive
5511 (call-interactively
5512 function (get-text-property (point) 'gnus-data)))
5513 (t
5514 (funcall function
5515 (get-text-property (point) 'gnus-data))))
5516 (set-marker overlay-arrow-position nil)
5517 (unless gnus-auto-select-part
5518 (gnus-select-frame-set-input-focus frame)
5519 (select-window window))))
5520 t))
5521 (if gnus-inhibit-mime-unbuttonizing
5522 ;; This is the default though the program shouldn't reach here.
5523 (error "No such part")
5524 ;; The part which doesn't have the MIME button is selected.
5525 ;; So, we display all the buttons and redo it.
5526 (let ((gnus-inhibit-mime-unbuttonizing t))
5527 (gnus-summary-show-article)
5528 (gnus-article-part-wrapper n function no-handle))))))
5529
5530 (defun gnus-article-pipe-part (n)
5531 "Pipe MIME part N, which is the numerical prefix."
5532 (interactive "P")
5533 (gnus-article-part-wrapper n 'mm-pipe-part))
5534
5535 (defun gnus-article-save-part (n)
5536 "Save MIME part N, which is the numerical prefix."
5537 (interactive "P")
5538 (gnus-article-part-wrapper n 'mm-save-part))
5539
5540 (defun gnus-article-interactively-view-part (n)
5541 "View MIME part N interactively, which is the numerical prefix."
5542 (interactive "P")
5543 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5544
5545 (defun gnus-article-copy-part (n)
5546 "Copy MIME part N, which is the numerical prefix."
5547 (interactive "P")
5548 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5549
5550 (defun gnus-article-view-part-as-charset (n)
5551 "View MIME part N using a specified charset.
5552 N is the numerical prefix."
5553 (interactive "P")
5554 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5555
5556 (defun gnus-article-view-part-externally (n)
5557 "View MIME part N externally, which is the numerical prefix."
5558 (interactive "P")
5559 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5560
5561 (defun gnus-article-inline-part (n)
5562 "Inline MIME part N, which is the numerical prefix."
5563 (interactive "P")
5564 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5565
5566 (defun gnus-article-save-part-and-strip (n)
5567 "Save MIME part N and replace it with an external body.
5568 N is the numerical prefix."
5569 (interactive "P")
5570 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5571
5572 (defun gnus-article-replace-part (n)
5573 "Replace MIME part N with an external body.
5574 N is the numerical prefix."
5575 (interactive "P")
5576 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5577
5578 (defun gnus-article-delete-part (n)
5579 "Delete MIME part N and add some information about the removed part.
5580 N is the numerical prefix."
5581 (interactive "P")
5582 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5583
5584 (defun gnus-article-view-part-as-type (n)
5585 "Choose a MIME media type, and view part N as such.
5586 N is the numerical prefix."
5587 (interactive "P")
5588 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5589
5590 (defun gnus-article-mime-match-handle-first (condition)
5591 (if condition
5592 (let (n)
5593 (dolist (ihandle gnus-article-mime-handle-alist)
5594 (if (and (cond
5595 ((functionp condition)
5596 (funcall condition (cdr ihandle)))
5597 ((eq condition 'undisplayed)
5598 (not (or (mm-handle-undisplayer (cdr ihandle))
5599 (equal (mm-handle-media-type (cdr ihandle))
5600 "multipart/alternative"))))
5601 ((eq condition 'undisplayed-alternative)
5602 (not (mm-handle-undisplayer (cdr ihandle))))
5603 (t t))
5604 (gnus-article-goto-part (car ihandle))
5605 (or (not n) (< (car ihandle) n)))
5606 (setq n (car ihandle))))
5607 (or n 1))
5608 1))
5609
5610 (defun gnus-article-view-part (&optional n)
5611 "View MIME part N, which is the numerical prefix.
5612 If the part is already shown, hide the part. If N is nil, view
5613 all parts."
5614 (interactive "P")
5615 (with-current-buffer gnus-article-buffer
5616 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5617 gnus-article-mime-match-handle-function)))
5618 (when (> n (length gnus-article-mime-handle-alist))
5619 (error "No such part"))
5620 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5621 (when (gnus-article-goto-part n)
5622 (if (equal (car handle) "multipart/alternative")
5623 (progn
5624 (beginning-of-line) ;; Make it toggle subparts
5625 (gnus-article-press-button))
5626 (when (eq (gnus-mm-display-part handle) 'internal)
5627 (gnus-set-window-start)))))))
5628
5629 (defsubst gnus-article-mime-total-parts ()
5630 (if (bufferp (car gnus-article-mime-handles))
5631 1 ;; single part
5632 (1- (length gnus-article-mime-handles))))
5633
5634 (defun gnus-mm-display-part (handle)
5635 "Display HANDLE and fix MIME button."
5636 (let ((id (get-text-property (point) 'gnus-part))
5637 (point (point))
5638 (inhibit-read-only t))
5639 (forward-line 1)
5640 (prog1
5641 (let ((window (selected-window))
5642 (mail-parse-charset gnus-newsgroup-charset)
5643 (mail-parse-ignored-charsets
5644 (if (gnus-buffer-live-p gnus-summary-buffer)
5645 (with-current-buffer gnus-summary-buffer
5646 gnus-newsgroup-ignored-charsets)
5647 nil)))
5648 (save-excursion
5649 (unwind-protect
5650 (let ((win (gnus-get-buffer-window (current-buffer) t))
5651 (beg (point)))
5652 (when win
5653 (select-window win))
5654 (goto-char point)
5655 (forward-line)
5656 (if (mm-handle-displayed-p handle)
5657 ;; This will remove the part.
5658 (mm-display-part handle)
5659 (save-window-excursion
5660 (save-restriction
5661 (narrow-to-region (point)
5662 (if (eobp) (point) (1+ (point))))
5663 (gnus-bind-safe-url-regexp (mm-display-part handle))
5664 ;; We narrow to the part itself and
5665 ;; then call the treatment functions.
5666 (goto-char (point-min))
5667 (forward-line 1)
5668 (narrow-to-region (point) (point-max))
5669 (gnus-treat-article
5670 nil id
5671 (gnus-article-mime-total-parts)
5672 (mm-handle-media-type handle))))))
5673 (if (window-live-p window)
5674 (select-window window))))))))
5675
5676 (defun gnus-article-goto-part (n)
5677 "Go to MIME part N."
5678 (when gnus-break-pages
5679 (widen))
5680 (article-goto-body)
5681 (prog1
5682 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5683 ;; There may be header buttons.
5684 (text-property-any (point-min) (point) 'gnus-part n)))
5685 part handle end next handles)
5686 (when start
5687 (goto-char start)
5688 (if (setq handle (get-text-property start 'gnus-data))
5689 start
5690 ;; Go to the displayed subpart, assuming this is
5691 ;; multipart/alternative.
5692 (setq part start
5693 end (point-at-eol))
5694 (while (and (not handle)
5695 part
5696 (< part end)
5697 (setq next (text-property-not-all part end
5698 'gnus-data nil)))
5699 (setq part next
5700 handle (get-text-property part 'gnus-data))
5701 (push (cons handle part) handles)
5702 (unless (mm-handle-displayed-p handle)
5703 (setq handle nil
5704 part (text-property-any part end 'gnus-data nil))))
5705 (unless handle
5706 ;; No subpart is displayed, so we find preferred one.
5707 (setq part
5708 (cdr (assq (mm-preferred-alternative
5709 (nreverse (mapcar 'car handles)))
5710 handles))))
5711 (if part
5712 (goto-char (1+ part))
5713 start))))
5714 (when gnus-break-pages
5715 (gnus-narrow-to-page))))
5716
5717 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5718 (let ((gnus-tmp-name
5719 (or (mm-handle-filename handle)
5720 (mail-content-type-get (mm-handle-type handle) 'url)
5721 ""))
5722 (gnus-tmp-type (mm-handle-media-type handle))
5723 (gnus-tmp-description (or (mm-handle-description handle) ""))
5724 (gnus-tmp-dots
5725 (if (if displayed (car displayed)
5726 (mm-handle-displayed-p handle))
5727 "" "..."))
5728 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5729 (buffer-size)))
5730 gnus-tmp-type-long b e)
5731 (when (string-match ".*/" gnus-tmp-name)
5732 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5733 (setq gnus-tmp-type-long (concat gnus-tmp-type
5734 (and (not (equal gnus-tmp-name ""))
5735 (concat "; " gnus-tmp-name))))
5736 (unless (equal gnus-tmp-description "")
5737 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5738 (setq b (point))
5739 (gnus-eval-format
5740 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5741 `(keymap ,gnus-mime-button-map
5742 gnus-callback gnus-mm-display-part
5743 gnus-part ,gnus-tmp-id
5744 article-type annotation
5745 gnus-data ,handle
5746 rear-nonsticky t))
5747 (setq e (if (bolp)
5748 ;; Exclude a newline.
5749 (1- (point))
5750 (point)))
5751 (when gnus-article-button-face
5752 (gnus-overlay-put (gnus-make-overlay b e nil t)
5753 'face gnus-article-button-face))
5754 (widget-convert-button
5755 'link b e
5756 :mime-handle handle
5757 :action 'gnus-widget-press-button
5758 :button-keymap gnus-mime-button-map
5759 :help-echo
5760 (lambda (widget)
5761 ;; Needed to properly clear the message due to a bug in
5762 ;; wid-edit (XEmacs only).
5763 (if (boundp 'help-echo-owns-message)
5764 (setq help-echo-owns-message t))
5765 (format
5766 "%S: %s the MIME part; %S: more options"
5767 (aref gnus-mouse-2 0)
5768 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5769 "hide" "show")
5770 (aref gnus-down-mouse-3 0))))))
5771
5772 (defun gnus-widget-press-button (elems el)
5773 (goto-char (widget-get elems :from))
5774 (gnus-article-press-button))
5775
5776 (defvar gnus-displaying-mime nil)
5777
5778 (defun gnus-display-mime (&optional ihandles)
5779 "Display the MIME parts."
5780 (save-excursion
5781 (save-selected-window
5782 (let ((window (get-buffer-window gnus-article-buffer))
5783 (point (point)))
5784 (when window
5785 (select-window window)
5786 ;; We have to do this since selecting the window
5787 ;; may change the point. So we set the window point.
5788 (set-window-point window point)))
5789 (let ((handles ihandles)
5790 (inhibit-read-only t)
5791 handle)
5792 (cond (handles)
5793 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5794 (when gnus-article-emulate-mime
5795 (mm-uu-dissect-text-parts handles)))
5796 (gnus-article-emulate-mime
5797 (setq handles (mm-uu-dissect))))
5798 (when (and (not ihandles)
5799 (not gnus-displaying-mime))
5800 ;; Top-level call; we clean up.
5801 (when gnus-article-mime-handles
5802 (mm-destroy-parts gnus-article-mime-handles)
5803 (setq gnus-article-mime-handle-alist nil));; A trick.
5804 (setq gnus-article-mime-handles handles)
5805 ;; We allow users to glean info from the handles.
5806 (when gnus-article-mime-part-function
5807 (gnus-mime-part-function handles)))
5808 (if (and handles
5809 (or (not (stringp (car handles)))
5810 (cdr handles)))
5811 (progn
5812 (when (and (not ihandles)
5813 (not gnus-displaying-mime))
5814 ;; Clean up for mime parts.
5815 (article-goto-body)
5816 (delete-region (point) (point-max)))
5817 (let ((gnus-displaying-mime t))
5818 (gnus-mime-display-part handles)))
5819 (save-restriction
5820 (article-goto-body)
5821 (narrow-to-region (point) (point-max))
5822 (gnus-treat-article nil 1 1 "text/plain")
5823 (widen)))
5824 (unless ihandles
5825 ;; Highlight the headers.
5826 (save-excursion
5827 (save-restriction
5828 (article-goto-body)
5829 (narrow-to-region (point-min) (point))
5830 (gnus-article-save-original-date
5831 (gnus-treat-article 'head)))))))
5832 ;; Cope with broken MIME messages.
5833 (goto-char (point-max))
5834 (unless (bolp)
5835 (insert "\n"))))
5836
5837 (defcustom gnus-mime-display-multipart-as-mixed nil
5838 "Display \"multipart\" parts as \"multipart/mixed\".
5839
5840 If t, it overrides nil values of
5841 `gnus-mime-display-multipart-alternative-as-mixed' and
5842 `gnus-mime-display-multipart-related-as-mixed'."
5843 :group 'gnus-article-mime
5844 :type 'boolean)
5845
5846 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5847 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5848 :version "22.1"
5849 :group 'gnus-article-mime
5850 :type 'boolean)
5851
5852 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5853 "Display \"multipart/related\" parts as \"multipart/mixed\".
5854
5855 If displaying \"text/html\" is discouraged \(see
5856 `mm-discouraged-alternatives'\) images or other material inside a
5857 \"multipart/related\" part might be overlooked when this variable is nil."
5858 :version "22.1"
5859 :group 'gnus-article-mime
5860 :type 'boolean)
5861
5862 (defcustom gnus-mime-display-attachment-buttons-in-header t
5863 "Add attachment buttons in the end of the header of an article.
5864 Since MIME attachments tend to be put at the end of an article, we may
5865 overlook them if there is a huge body. This option offers you a copy
5866 of all non-inlinable MIME parts as buttons shown in front of an article.
5867 If nil, don't show those extra buttons."
5868 :version "24.5"
5869 :group 'gnus-article
5870 :type 'boolean)
5871
5872 (defun gnus-mime-display-part (handle)
5873 (cond
5874 ;; Maybe a broken MIME message.
5875 ((null handle))
5876 ;; Single part.
5877 ((not (stringp (car handle)))
5878 (gnus-mime-display-single handle))
5879 ;; User-defined multipart
5880 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5881 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5882 handle))
5883 ;; multipart/alternative
5884 ((and (equal (car handle) "multipart/alternative")
5885 (not (or gnus-mime-display-multipart-as-mixed
5886 gnus-mime-display-multipart-alternative-as-mixed)))
5887 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5888 (push (cons id handle) gnus-article-mime-handle-alist)
5889 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5890 ;; multipart/related
5891 ((and (equal (car handle) "multipart/related")
5892 (not (or gnus-mime-display-multipart-as-mixed
5893 gnus-mime-display-multipart-related-as-mixed)))
5894 (gnus-mime-display-part (cadr handle)))
5895 ((equal (car handle) "multipart/signed")
5896 (gnus-add-wash-type 'signed)
5897 (gnus-mime-display-security handle))
5898 ((equal (car handle) "multipart/encrypted")
5899 (gnus-add-wash-type 'encrypted)
5900 (gnus-mime-display-security handle))
5901 ;; Other multiparts are handled like multipart/mixed.
5902 (t
5903 (gnus-mime-display-mixed (cdr handle)))))
5904
5905 (defun gnus-mime-part-function (handles)
5906 (if (stringp (car handles))
5907 (mapcar 'gnus-mime-part-function (cdr handles))
5908 (funcall gnus-article-mime-part-function handles)))
5909
5910 (defun gnus-mime-display-mixed (handles)
5911 (mapcar 'gnus-mime-display-part handles))
5912
5913 (defun gnus-mime-display-single (handle)
5914 (let ((type (mm-handle-media-type handle))
5915 (ignored gnus-ignored-mime-types)
5916 (not-attachment t)
5917 (move nil)
5918 display text)
5919 (catch 'ignored
5920 (progn
5921 (while ignored
5922 (when (string-match (pop ignored) type)
5923 (throw 'ignored nil)))
5924 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5925 (with-current-buffer gnus-summary-buffer
5926 gnus-inhibit-images)
5927 gnus-inhibit-images)
5928 (string-match "\\`image/" type)))
5929 (setq not-attachment
5930 (and (not (mm-inline-override-p handle))
5931 (or (not (mm-handle-disposition handle))
5932 (equal (car (mm-handle-disposition handle))
5933 "inline")
5934 (mm-attachment-override-p handle))))
5935 (mm-automatic-display-p handle)
5936 (or (and
5937 (mm-inlinable-p handle)
5938 (mm-inlined-p handle))
5939 (mm-automatic-external-display-p type)))
5940 (setq display t)
5941 (when (equal (mm-handle-media-supertype handle) "text")
5942 (setq text t)))
5943 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5944 beg)
5945 (push (cons id handle) gnus-article-mime-handle-alist)
5946 (when (and display
5947 (equal (mm-handle-media-supertype handle) "message"))
5948 (insert-char
5949 ?\n
5950 (cond ((not (bolp)) 2)
5951 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5952 (t 1))))
5953 (when (or (not display)
5954 (not (gnus-unbuttonized-mime-type-p type))
5955 (eq id gnus-mime-buttonized-part-id))
5956 (gnus-insert-mime-button
5957 handle id (list (or display (and not-attachment text))))
5958 (gnus-article-insert-newline)
5959 ;; Remember modify the number of forward lines.
5960 (setq move t))
5961 (setq beg (point))
5962 (cond
5963 (display
5964 (when move
5965 (forward-line -1)
5966 (setq beg (point)))
5967 (let ((mail-parse-charset gnus-newsgroup-charset)
5968 (mail-parse-ignored-charsets
5969 (save-excursion (condition-case ()
5970 (set-buffer gnus-summary-buffer)
5971 (error))
5972 gnus-newsgroup-ignored-charsets)))
5973 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5974 (goto-char (point-max)))
5975 ((and text not-attachment)
5976 (when move
5977 (forward-line -1)
5978 (setq beg (point)))
5979 (gnus-article-insert-newline)
5980 (mm-display-inline handle)
5981 (goto-char (point-max))))
5982 ;; Do highlighting.
5983 (save-excursion
5984 (save-restriction
5985 (narrow-to-region beg (point))
5986 (if (eq handle gnus-article-mime-handles)
5987 ;; The format=flowed case.
5988 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5989 ;; Don't count signature parts that are never displayed.
5990 ;; The part number should be re-calculated supposing this
5991 ;; might be a message/rfc822 part.
5992 (let (handles)
5993 (dolist (part gnus-article-mime-handles)
5994 (unless (or (stringp part)
5995 (equal (car (mm-handle-type part))
5996 "application/pgp-signature"))
5997 (push part handles)))
5998 (gnus-treat-article
5999 nil (length (memq handle handles)) (length handles)
6000 (mm-handle-media-type handle)))))))))))
6001
6002 (defun gnus-unbuttonized-mime-type-p (type)
6003 "Say whether TYPE is to be unbuttonized."
6004 (unless gnus-inhibit-mime-unbuttonizing
6005 (when (catch 'found
6006 (let ((types gnus-unbuttonized-mime-types))
6007 (while types
6008 (when (string-match (pop types) type)
6009 (throw 'found t)))))
6010 (not (catch 'found
6011 (let ((types gnus-buttonized-mime-types))
6012 (while types
6013 (when (string-match (pop types) type)
6014 (throw 'found t)))))))))
6015
6016 (defun gnus-article-insert-newline ()
6017 "Insert a newline, but mark it as undeletable."
6018 (gnus-put-text-property
6019 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6020
6021 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6022 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6023 (ihandles handles)
6024 (point (point))
6025 handle (inhibit-read-only t) from props begend not-pref)
6026 (save-window-excursion
6027 (save-restriction
6028 (when ibegend
6029 (narrow-to-region (car ibegend)
6030 (or (cdr ibegend)
6031 (progn
6032 (goto-char (car ibegend))
6033 (forward-line 2)
6034 (point))))
6035 (delete-region (point-min) (point-max))
6036 (mm-remove-parts handles))
6037 (setq begend (list (point-marker)))
6038 ;; Do the toggle.
6039 (unless (setq not-pref (cadr (member preferred ihandles)))
6040 (setq not-pref (car ihandles)))
6041 (when (or ibegend
6042 (not preferred)
6043 (not (gnus-unbuttonized-mime-type-p
6044 "multipart/alternative")))
6045 (gnus-add-text-properties
6046 (setq from (point))
6047 (progn
6048 (insert (format "%d. " id))
6049 (point))
6050 `(gnus-callback
6051 (lambda (handles)
6052 (unless ,(not ibegend)
6053 (setq gnus-article-mime-handle-alist
6054 ',gnus-article-mime-handle-alist))
6055 (gnus-mime-display-alternative
6056 ',ihandles ',not-pref ',begend ,id))
6057 keymap ,gnus-mime-button-map
6058 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6059 face ,gnus-article-button-face
6060 gnus-part ,id
6061 article-type multipart
6062 rear-nonsticky t))
6063 (widget-convert-button 'link from (point)
6064 :action 'gnus-widget-press-button
6065 :button-keymap gnus-widget-button-keymap)
6066 ;; Do the handles
6067 (while (setq handle (pop handles))
6068 (gnus-add-text-properties
6069 (setq from (point))
6070 (progn
6071 (insert (format "(%c) %-18s"
6072 (if (equal handle preferred) ?* ? )
6073 (mm-handle-media-type handle)))
6074 (point))
6075 `(gnus-callback
6076 (lambda (handles)
6077 (unless ,(not ibegend)
6078 (setq gnus-article-mime-handle-alist
6079 ',gnus-article-mime-handle-alist))
6080 (gnus-mime-display-alternative
6081 ',ihandles ',handle ',begend ,id))
6082 keymap ,gnus-mime-button-map
6083 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6084 face ,gnus-article-button-face
6085 gnus-part ,id
6086 gnus-data ,handle
6087 rear-nonsticky t))
6088 (widget-convert-button 'link from (point)
6089 :action 'gnus-widget-press-button
6090 :button-keymap gnus-widget-button-keymap)
6091 (insert " "))
6092 (insert "\n\n"))
6093 (when preferred
6094 (if (stringp (car preferred))
6095 (gnus-display-mime preferred)
6096 (let ((mail-parse-charset gnus-newsgroup-charset)
6097 (mail-parse-ignored-charsets
6098 (with-current-buffer gnus-summary-buffer
6099 gnus-newsgroup-ignored-charsets)))
6100 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6101 ;; Do highlighting.
6102 (save-excursion
6103 (save-restriction
6104 (narrow-to-region (car begend) (point-max))
6105 (gnus-treat-article
6106 nil (length gnus-article-mime-handle-alist)
6107 (gnus-article-mime-total-parts)
6108 (mm-handle-media-type preferred))))))
6109 (goto-char (point-max))
6110 (setcdr begend (point-marker)))))
6111 (when ibegend
6112 (goto-char point)))
6113 ;; Redraw attachment buttons in the header.
6114 (when gnus-mime-display-attachment-buttons-in-header
6115 (gnus-mime-buttonize-attachments-in-header)))
6116
6117 (defconst gnus-article-wash-status-strings
6118 (let ((alist '((cite "c" "Possible hidden citation text"
6119 " " "All citation text visible")
6120 (headers "h" "Hidden headers"
6121 " " "All headers visible.")
6122 (pgp "p" "Encrypted or signed message status hidden"
6123 " " "No hidden encryption nor digital signature status")
6124 (signature "s" "Signature has been hidden"
6125 " " "Signature is visible")
6126 (overstrike "o" "Overstrike (^H) characters applied"
6127 " " "No overstrike characters applied")
6128 (emphasis "e" "/*_Emphasis_*/ characters applied"
6129 " " "No /*_emphasis_*/ characters applied")))
6130 result)
6131 (dolist (entry alist result)
6132 (let ((key (nth 0 entry))
6133 (on (copy-sequence (nth 1 entry)))
6134 (on-help (nth 2 entry))
6135 (off (copy-sequence (nth 3 entry)))
6136 (off-help (nth 4 entry)))
6137 (put-text-property 0 1 'help-echo on-help on)
6138 (put-text-property 0 1 'help-echo off-help off)
6139 (push (list key on off) result))))
6140 "Alist of strings describing wash status in the mode line.
6141 Each entry has the form (KEY ON OF), where the KEY is a symbol
6142 representing the particular washing function, ON is the string to use
6143 in the article mode line when the washing function is active, and OFF
6144 is the string to use when it is inactive.")
6145
6146 (defun gnus-article-wash-status-entry (key value)
6147 (let ((entry (assoc key gnus-article-wash-status-strings)))
6148 (if value (nth 1 entry) (nth 2 entry))))
6149
6150 (defun gnus-article-wash-status ()
6151 "Return a string which display status of article washing."
6152 (with-current-buffer gnus-article-buffer
6153 (let ((cite (memq 'cite gnus-article-wash-types))
6154 (headers (memq 'headers gnus-article-wash-types))
6155 (boring (memq 'boring-headers gnus-article-wash-types))
6156 (pgp (memq 'pgp gnus-article-wash-types))
6157 (pem (memq 'pem gnus-article-wash-types))
6158 (signed (memq 'signed gnus-article-wash-types))
6159 (encrypted (memq 'encrypted gnus-article-wash-types))
6160 (signature (memq 'signature gnus-article-wash-types))
6161 (overstrike (memq 'overstrike gnus-article-wash-types))
6162 (emphasis (memq 'emphasis gnus-article-wash-types)))
6163 (concat
6164 (gnus-article-wash-status-entry 'cite cite)
6165 (gnus-article-wash-status-entry 'headers (or headers boring))
6166 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6167 (gnus-article-wash-status-entry 'signature signature)
6168 (gnus-article-wash-status-entry 'overstrike overstrike)
6169 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6170
6171 (defun gnus-add-wash-type (type)
6172 "Add a washing of TYPE to the current status."
6173 (add-to-list 'gnus-article-wash-types type))
6174
6175 (defun gnus-delete-wash-type (type)
6176 "Add a washing of TYPE to the current status."
6177 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6178
6179 (defun gnus-add-image (category image)
6180 "Add IMAGE of CATEGORY to the list of displayed images."
6181 (let ((entry (assq category gnus-article-image-alist)))
6182 (unless entry
6183 (setq entry (list category))
6184 (push entry gnus-article-image-alist))
6185 (nconc entry (list image))))
6186
6187 (defun gnus-delete-images (category)
6188 "Delete all images in CATEGORY."
6189 (let ((entry (assq category gnus-article-image-alist)))
6190 (dolist (image (cdr entry))
6191 (gnus-remove-image image category))
6192 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6193 (gnus-delete-wash-type category)))
6194
6195 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6196
6197 (defun gnus-article-maybe-hide-headers ()
6198 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6199 Provided for backwards compatibility."
6200 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6201 (not (with-current-buffer gnus-summary-buffer
6202 gnus-have-all-headers)))
6203 (not gnus-inhibit-hiding))
6204 (gnus-article-hide-headers)))
6205
6206 (declare-function shr-put-image "shr" (data alt &optional flags))
6207
6208 (defun gnus-shr-put-image (data alt &optional flags)
6209 "Put image DATA with a string ALT. Enable image to be deleted."
6210 (let ((image (if flags
6211 (shr-put-image data (propertize (or alt "*")
6212 'gnus-image-category 'shr)
6213 flags)
6214 ;; Old `shr-put-image' doesn't take the optional `flags'
6215 ;; argument.
6216 (shr-put-image data (propertize (or alt "*")
6217 'gnus-image-category 'shr)))))
6218 (when image
6219 (gnus-add-image 'shr image))))
6220
6221 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6222 "Show attachments as buttons in the end of the header of an article.
6223 This function toggles the display when called interactively. Note that
6224 buttons to be added to the header are only the ones that aren't inlined
6225 in the body. Use `gnus-header-face-alist' to highlight buttons."
6226 (interactive (list t))
6227 (gnus-with-article-buffer
6228 (gmm-labels
6229 ;; Function that returns a flattened version of
6230 ;; `gnus-article-mime-handle-alist'.
6231 ((flattened-alist
6232 (&optional alist id all)
6233 (if alist
6234 (let ((i 1) newid flat)
6235 (dolist (handle alist flat)
6236 (setq newid (append id (list i))
6237 i (1+ i))
6238 (if (stringp (car handle))
6239 (setq flat (nconc flat (flattened-alist (cdr handle)
6240 newid all)))
6241 (delq (rassq handle all) all)
6242 (setq flat (nconc flat (list (cons newid handle)))))))
6243 (let ((flat (list nil)))
6244 ;; Assume that elements of `gnus-article-mime-handle-alist'
6245 ;; are in the decreasing order, but unnumbered subsidiaries
6246 ;; in each element are in the increasing order.
6247 (dolist (handle (reverse gnus-article-mime-handle-alist))
6248 (if (stringp (cadr handle))
6249 (setq flat (nconc flat (flattened-alist (cddr handle)
6250 (list (car handle))
6251 flat)))
6252 (delq (rassq (cdr handle) flat) flat)
6253 (setq flat (nconc flat (list (cons (list (car handle))
6254 (cdr handle)))))))
6255 (setq flat (cdr flat))
6256 (mapc (lambda (handle)
6257 (if (cdar handle)
6258 ;; This is a hidden (i.e. unnumbered) handle.
6259 (progn
6260 (setcar handle
6261 (1+ (caar gnus-article-mime-handle-alist)))
6262 (push handle gnus-article-mime-handle-alist))
6263 (setcar handle (caar handle))))
6264 flat)
6265 flat))))
6266 (let ((case-fold-search t) buttons st)
6267 (save-excursion
6268 (save-restriction
6269 (widen)
6270 (article-narrow-to-head)
6271 ;; Header buttons exist?
6272 (while (and (not buttons)
6273 (re-search-forward "^attachments?:[\n ]+" nil t))
6274 (when (get-char-property (match-end 0)
6275 'gnus-button-attachment-extra)
6276 (setq buttons (match-beginning 0))))
6277 (widen)
6278 (when buttons
6279 ;; Delete header buttons.
6280 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6281 (match-beginning 0)
6282 (point-max))))
6283 (unless (and interactive buttons)
6284 ;; Find buttons.
6285 (setq buttons nil)
6286 (dolist (handle (flattened-alist))
6287 (when (and (not (stringp (cadr handle)))
6288 (or (equal (car (mm-handle-disposition
6289 (cdr handle)))
6290 "attachment")
6291 (not (and (mm-inlinable-p (cdr handle))
6292 (mm-inlined-p (cdr handle))))))
6293 (push handle buttons)))
6294 (when buttons
6295 ;; Add header buttons.
6296 (article-goto-body)
6297 (forward-line -1)
6298 (narrow-to-region (point) (point))
6299 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6300 (dolist (button (nreverse buttons))
6301 (setq st (point))
6302 (insert " ")
6303 (gnus-insert-mime-button (cdr button) (car button))
6304 (skip-chars-backward "\t\n ")
6305 (delete-region (point) (point-max))
6306 (when (> (current-column) (window-width))
6307 (goto-char st)
6308 (insert "\n")
6309 (end-of-line)))
6310 (insert "\n")
6311 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6312 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6313 (gnus-overlay-put ovl 'face nil))
6314 (let ((gnus-treatment-function-alist
6315 '((gnus-treat-highlight-headers
6316 gnus-article-highlight-headers))))
6317 (gnus-treat-article 'head))))))))))
6318
6319 ;;; Article savers.
6320
6321 (defun gnus-output-to-file (file-name)
6322 "Append the current article to a file named FILE-NAME.
6323 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6324 text and used as the value of the coding cookie which is added to the
6325 top of a file. Otherwise, this function saves a raw article without
6326 the coding cookie."
6327 (let* ((artbuf (current-buffer))
6328 (file-name-coding-system nnmail-pathname-coding-system)
6329 (coding gnus-article-save-coding-system)
6330 (coding-system-for-read (if coding
6331 nil ;; Rely on the coding cookie.
6332 mm-text-coding-system))
6333 (coding-system-for-write (or coding
6334 mm-text-coding-system-for-write
6335 mm-text-coding-system))
6336 (exists (file-exists-p file-name)))
6337 (with-temp-buffer
6338 (when exists
6339 (insert-file-contents file-name)
6340 (goto-char (point-min))
6341 ;; Remove the existing coding cookie.
6342 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6343 (delete-region (match-beginning 0) (match-end 0))))
6344 (goto-char (point-max))
6345 (insert-buffer-substring artbuf)
6346 ;; Append newline at end of the buffer as separator, and then
6347 ;; save it to file.
6348 (goto-char (point-max))
6349 (insert "\n")
6350 (when coding
6351 ;; If the coding system is not suitable to encode the text,
6352 ;; ask a user for a proper one.
6353 (when (fboundp 'select-safe-coding-system)
6354 (setq coding (coding-system-base
6355 (save-window-excursion
6356 (select-safe-coding-system (point-min) (point-max)
6357 coding))))
6358 (setq coding-system-for-write
6359 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6360 coding)))
6361 (goto-char (point-min))
6362 ;; Add the coding cookie.
6363 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6364 coding-system-for-write)))
6365 (if exists
6366 (progn
6367 (write-region (point-min) (point-max) file-name nil 'no-message)
6368 (message "Appended to %s" file-name))
6369 (write-region (point-min) (point-max) file-name))))
6370 t)
6371
6372 (defun gnus-narrow-to-page (&optional arg)
6373 "Narrow the article buffer to a page.
6374 If given a numerical ARG, move forward ARG pages."
6375 (interactive "P")
6376 (setq arg (if arg (prefix-numeric-value arg) 0))
6377 (with-current-buffer gnus-article-buffer
6378 (widen)
6379 ;; Remove any old next/prev buttons.
6380 (when (gnus-visual-p 'page-marker)
6381 (let ((inhibit-read-only t))
6382 (gnus-remove-text-with-property 'gnus-prev)
6383 (gnus-remove-text-with-property 'gnus-next)))
6384 (let (st nd pt)
6385 (when (save-excursion
6386 (cond ((< arg 0)
6387 (if (re-search-backward page-delimiter nil 'move (abs arg))
6388 (prog1
6389 (setq nd (match-beginning 0)
6390 pt nd)
6391 (when (re-search-backward page-delimiter nil t)
6392 (setq st (match-end 0))))
6393 (when (re-search-forward page-delimiter nil t)
6394 (setq nd (match-beginning 0)
6395 pt (point-min)))))
6396 ((> arg 0)
6397 (if (re-search-forward page-delimiter nil 'move arg)
6398 (prog1
6399 (setq st (match-end 0)
6400 pt st)
6401 (when (re-search-forward page-delimiter nil t)
6402 (setq nd (match-beginning 0))))
6403 (when (re-search-backward page-delimiter nil t)
6404 (setq st (match-end 0)
6405 pt (point-max)))))
6406 (t
6407 (when (re-search-backward page-delimiter nil t)
6408 (goto-char (setq st (match-end 0))))
6409 (when (re-search-forward page-delimiter nil t)
6410 (setq nd (match-beginning 0)))
6411 (or st nd))))
6412 (setq gnus-page-broken t)
6413 (when pt (goto-char pt))
6414 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6415 (when (gnus-visual-p 'page-marker)
6416 (save-excursion
6417 (when nd
6418 (goto-char nd)
6419 (gnus-insert-next-page-button))
6420 (when st
6421 (goto-char st)
6422 (gnus-insert-prev-page-button))))))))
6423
6424 ;; Article mode commands
6425
6426 (defun gnus-article-goto-next-page ()
6427 "Show the next page of the article."
6428 (interactive)
6429 (when (gnus-article-next-page)
6430 (goto-char (point-min))
6431 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6432
6433
6434 (defun gnus-article-goto-prev-page ()
6435 "Show the previous page of the article."
6436 (interactive)
6437 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6438 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6439 (gnus-article-prev-page nil)))
6440
6441 ;; This is cleaner but currently breaks `gnus-pick-mode':
6442 ;;
6443 ;; (defun gnus-article-goto-next-page ()
6444 ;; "Show the next page of the article."
6445 ;; (interactive)
6446 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6447 ;; (gnus-summary-next-page)))
6448 ;;
6449 ;; (defun gnus-article-goto-prev-page ()
6450 ;; "Show the next page of the article."
6451 ;; (interactive)
6452 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6453 ;; (gnus-summary-prev-page)))
6454
6455 (defun gnus-article-next-page (&optional lines)
6456 "Show the next page of the current article.
6457 If end of article, return non-nil. Otherwise return nil.
6458 Argument LINES specifies lines to be scrolled up."
6459 (interactive "p")
6460 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6461 (if (and (not (and gnus-article-over-scroll
6462 (> (count-lines (window-start) (point-max))
6463 (if (featurep 'xemacs)
6464 (or lines (1- (window-height)))
6465 (+ (or lines (1- (window-height))) scroll-margin)))))
6466 (save-excursion
6467 (end-of-line)
6468 (and (pos-visible-in-window-p) ;Not continuation line.
6469 (>= (point) (point-max)))))
6470 ;; Nothing in this page.
6471 (if (or (not gnus-page-broken)
6472 (save-excursion
6473 (save-restriction
6474 (widen)
6475 (forward-line)
6476 (eobp)))) ;Real end-of-buffer?
6477 (progn
6478 (when gnus-article-over-scroll
6479 (gnus-article-next-page-1 lines))
6480 t) ;Nothing more.
6481 (gnus-narrow-to-page 1) ;Go to next page.
6482 nil)
6483 ;; More in this page.
6484 (gnus-article-next-page-1 lines)
6485 nil))
6486
6487 (defun gnus-article-beginning-of-window ()
6488 "Move point to the beginning of the window.
6489 In Emacs, the point is placed at the line number which `scroll-margin'
6490 specifies."
6491 (if (featurep 'xemacs)
6492 (move-to-window-line 0)
6493 ;; There is an obscure bug in Emacs that makes it impossible to
6494 ;; scroll past big pictures in the article buffer. Try to fix
6495 ;; this by adding a sanity check by counting the lines visible.
6496 (when (> (count-lines (window-start) (window-end)) 30)
6497 (move-to-window-line
6498 (min (max 0 scroll-margin)
6499 (max 1 (- (window-height)
6500 (if mode-line-format 1 0)
6501 (if header-line-format 1 0)
6502 2)))))))
6503
6504 (defun gnus-article-next-page-1 (lines)
6505 (condition-case ()
6506 (let ((scroll-in-place nil)
6507 (auto-window-vscroll nil))
6508 (scroll-up lines))
6509 (end-of-buffer
6510 ;; Long lines may cause an end-of-buffer error.
6511 (goto-char (point-max))))
6512 (gnus-article-beginning-of-window))
6513
6514 (defun gnus-article-prev-page (&optional lines)
6515 "Show previous page of current article.
6516 Argument LINES specifies lines to be scrolled down."
6517 (interactive "p")
6518 (move-to-window-line 0)
6519 (if (and gnus-page-broken
6520 (bobp)
6521 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6522 (progn
6523 (gnus-narrow-to-page -1) ;Go to previous page.
6524 (goto-char (point-max))
6525 (recenter (if gnus-article-over-scroll
6526 (if lines
6527 (max (if (featurep 'xemacs)
6528 lines
6529 (+ lines scroll-margin))
6530 3)
6531 (- (window-height) 2))
6532 -1)))
6533 (prog1
6534 (condition-case ()
6535 (let ((scroll-in-place nil))
6536 (scroll-down lines))
6537 (beginning-of-buffer
6538 (goto-char (point-min))))
6539 (gnus-article-beginning-of-window))))
6540
6541 (defun gnus-article-only-boring-p ()
6542 "Decide whether there is only boring text remaining in the article.
6543 Something \"interesting\" is a word of at least two letters that does
6544 not have a face in `gnus-article-boring-faces'."
6545 (when (and gnus-article-skip-boring
6546 (boundp 'gnus-article-boring-faces)
6547 (symbol-value 'gnus-article-boring-faces))
6548 (save-excursion
6549 (let ((inhibit-point-motion-hooks t))
6550 (catch 'only-boring
6551 (while (re-search-forward "\\b\\w\\w" nil t)
6552 (forward-char -1)
6553 (when (not (gnus-intersection
6554 (gnus-faces-at (point))
6555 (symbol-value 'gnus-article-boring-faces)))
6556 (throw 'only-boring nil)))
6557 (throw 'only-boring t))))))
6558
6559 (defun gnus-article-refer-article ()
6560 "Read article specified by message-id around point."
6561 (interactive)
6562 (save-excursion
6563 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6564 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6565 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6566 (let ((msg-id (concat "<" (match-string 0) ">")))
6567 (set-buffer gnus-summary-buffer)
6568 (gnus-summary-refer-article msg-id))
6569 (error "No references around point"))))
6570
6571 (defun gnus-article-show-summary ()
6572 "Reconfigure windows to show summary buffer."
6573 (interactive)
6574 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6575 (error "There is no summary buffer for this article buffer")
6576 (gnus-article-set-globals)
6577 (gnus-configure-windows 'article)
6578 (gnus-summary-goto-subject gnus-current-article)
6579 (gnus-summary-position-point)))
6580
6581 (defun gnus-article-describe-briefly ()
6582 "Describe article mode commands briefly."
6583 (interactive)
6584 (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")))
6585
6586 (defun gnus-article-check-buffer ()
6587 "Beep if not in an article buffer."
6588 (unless (derived-mode-p 'gnus-article-mode)
6589 (error "Command invoked outside of a Gnus article buffer")))
6590
6591 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6592 "Read a summary buffer key sequence and execute it from the article buffer."
6593 (interactive "P")
6594 (gnus-article-check-buffer)
6595 (let ((nosaves
6596 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6597 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6598 "=" "^" "\M-^" "|"))
6599 (nosave-but-article
6600 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6601 "An" "Ap" [?A (meta return)] [?A delete]))
6602 (nosave-in-article
6603 '("AS" "\C-d"))
6604 (up-to-top
6605 '("n" "Gn" "p" "Gp"))
6606 keys new-sum-point)
6607 (with-current-buffer gnus-article-current-summary
6608 (let (gnus-pick-mode)
6609 (setq unread-command-events (nconc unread-command-events
6610 (list (or key last-command-event)))
6611 keys (if (featurep 'xemacs)
6612 (events-to-keys (read-key-sequence nil t))
6613 (read-key-sequence nil t)))))
6614
6615 (message "")
6616
6617 (cond
6618 ((eq (aref keys (1- (length keys))) ?\C-h)
6619 (gnus-article-describe-bindings (substring keys 0 -1)))
6620 ((or (member keys nosaves)
6621 (member keys nosave-but-article)
6622 (member keys nosave-in-article))
6623 (let (func)
6624 (save-window-excursion
6625 (pop-to-buffer gnus-article-current-summary)
6626 ;; We disable the pick minor mode commands.
6627 (let (gnus-pick-mode)
6628 (setq func (key-binding keys t))))
6629 (if (or (not func)
6630 (numberp func))
6631 (ding)
6632 (unless (member keys nosave-in-article)
6633 (set-buffer gnus-article-current-summary))
6634 (when (and (symbolp func)
6635 (get func 'disabled))
6636 (error "Function %s disabled" func))
6637 (call-interactively func)
6638 (setq new-sum-point (point)))
6639 (when (member keys nosave-but-article)
6640 (pop-to-buffer gnus-article-buffer))))
6641 (t
6642 ;; These commands should restore window configuration.
6643 (let ((obuf (current-buffer))
6644 (owin (current-window-configuration))
6645 win func in-buffer selected new-sum-start new-sum-hscroll err)
6646 (cond (not-restore-window
6647 (pop-to-buffer gnus-article-current-summary)
6648 (setq win (selected-window)))
6649 ((setq win (get-buffer-window gnus-article-current-summary))
6650 (select-window win))
6651 (t
6652 (let ((summary-buffer gnus-article-current-summary))
6653 (gnus-configure-windows 'article)
6654 (unless (setq win (get-buffer-window summary-buffer 'visible))
6655 (let ((gnus-buffer-configuration
6656 '((article ((vertical 1.0
6657 (summary 0.25 point)
6658 (article 1.0)))))))
6659 (gnus-configure-windows 'article))
6660 (setq win (get-buffer-window summary-buffer 'visible)))
6661 (gnus-select-frame-set-input-focus (window-frame win))
6662 (select-window win))))
6663 (setq in-buffer (current-buffer))
6664 ;; We disable the pick minor mode commands.
6665 (setq func (let (gnus-pick-mode)
6666 (key-binding keys t)))
6667 (when (get func 'disabled)
6668 (error "Function %s disabled" func))
6669 (if (and func
6670 (functionp func)
6671 (condition-case code
6672 (progn
6673 (call-interactively func)
6674 t)
6675 (error
6676 (setq err code)
6677 nil)))
6678 (progn
6679 (when (eq win (selected-window))
6680 (setq new-sum-point (point)
6681 new-sum-start (window-start win)
6682 new-sum-hscroll (window-hscroll win)))
6683 (when (or (eq in-buffer (current-buffer))
6684 (when (eq obuf (current-buffer))
6685 (set-buffer in-buffer)
6686 t))
6687 (setq selected (gnus-summary-select-article))
6688 (set-buffer obuf)
6689 (unless not-restore-window
6690 (set-window-configuration owin))
6691 (when (and (eq selected 'old)
6692 new-sum-point)
6693 (set-window-start (get-buffer-window (current-buffer))
6694 1)
6695 (set-window-point (get-buffer-window (current-buffer))
6696 (if (article-goto-body)
6697 (1- (point))
6698 (point))))
6699 (when (and (not not-restore-window)
6700 new-sum-point
6701 (window-live-p win)
6702 (with-current-buffer (window-buffer win)
6703 (derived-mode-p 'gnus-summary-mode)))
6704 (set-window-point win new-sum-point)
6705 (set-window-start win new-sum-start)
6706 (set-window-hscroll win new-sum-hscroll))))
6707 (set-window-configuration owin)
6708 (if err
6709 (signal (car err) (cdr err))
6710 (ding))))))))
6711
6712 (defun gnus-article-read-summary-send-keys ()
6713 (interactive)
6714 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6715 (gnus-article-read-summary-keys)))
6716
6717 (defun gnus-article-describe-key (key)
6718 "Display documentation of the function invoked by KEY.
6719 KEY is a string or a vector."
6720 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6721 (read-key-sequence "Describe key: "))))
6722 (gnus-article-check-buffer)
6723 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6724 gnus-article-read-summary-send-keys))
6725 (with-current-buffer gnus-article-current-summary
6726 (setq unread-command-events
6727 (if (featurep 'xemacs)
6728 (append key nil)
6729 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6730 (list 'meta (- x 128))
6731 x))
6732 key)))
6733 (let ((cursor-in-echo-area t)
6734 gnus-pick-mode)
6735 (describe-key (read-key-sequence nil t))))
6736 (describe-key key)))
6737
6738 (defun gnus-article-describe-key-briefly (key &optional insert)
6739 "Display documentation of the function invoked by KEY.
6740 KEY is a string or a vector."
6741 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6742 (read-key-sequence "Describe key: "))
6743 current-prefix-arg))
6744 (gnus-article-check-buffer)
6745 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6746 gnus-article-read-summary-send-keys))
6747 (with-current-buffer gnus-article-current-summary
6748 (setq unread-command-events
6749 (if (featurep 'xemacs)
6750 (append key nil)
6751 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6752 (list 'meta (- x 128))
6753 x))
6754 key)))
6755 (let ((cursor-in-echo-area t)
6756 gnus-pick-mode)
6757 (describe-key-briefly (read-key-sequence nil t) insert)))
6758 (describe-key-briefly key insert)))
6759
6760 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6761 (defvar gnus-agent-summary-mode)
6762 (defvar gnus-draft-mode)
6763 (defvar help-xref-stack-item)
6764
6765 (defun gnus-article-describe-bindings (&optional prefix)
6766 "Show a list of all defined keys, and their definitions.
6767 The optional argument PREFIX, if non-nil, should be a key sequence;
6768 then we display only bindings that start with that prefix."
6769 (interactive)
6770 (gnus-article-check-buffer)
6771 (let ((keymap (copy-keymap gnus-article-mode-map))
6772 (map (copy-keymap gnus-article-send-map))
6773 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6774 parent agent draft)
6775 (define-key keymap "S" map)
6776 (define-key map [t] nil)
6777 (with-current-buffer gnus-article-current-summary
6778 (set-keymap-parent
6779 keymap
6780 (if (setq parent (keymap-parent gnus-article-mode-map))
6781 (prog1
6782 (setq parent (copy-keymap parent))
6783 (set-keymap-parent parent (current-local-map)))
6784 (current-local-map)))
6785 (set-keymap-parent map (key-binding "S"))
6786 (let (key def gnus-pick-mode)
6787 (while sumkeys
6788 (setq key (pop sumkeys))
6789 (cond ((and (vectorp key) (= (length key) 1)
6790 (consp (setq def (aref key 0)))
6791 (numberp (car def)) (numberp (cdr def)))
6792 (when (< (max (car def) (cdr def)) 128)
6793 (setq sumkeys
6794 (append (mapcar
6795 #'vector
6796 (nreverse (gnus-uncompress-range def)))
6797 sumkeys))))
6798 ((setq def (key-binding key))
6799 (unless (eq def 'undefined)
6800 (define-key keymap key def))))))
6801 (when (boundp 'gnus-agent-summary-mode)
6802 (setq agent gnus-agent-summary-mode))
6803 (when (boundp 'gnus-draft-mode)
6804 (setq draft gnus-draft-mode)))
6805 (with-temp-buffer
6806 (use-local-map keymap)
6807 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6808 (set (make-local-variable 'gnus-draft-mode) draft)
6809 (describe-bindings prefix))
6810 (let ((item `((lambda (prefix)
6811 (with-current-buffer ,(current-buffer)
6812 (gnus-article-describe-bindings prefix)))
6813 ,prefix)))
6814 ;; Loading `help-mode' here is necessary if `describe-bindings'
6815 ;; is replaced with something, e.g. `helm-descbinds'.
6816 (require 'help-mode)
6817 (with-current-buffer (let (help-xref-following) (help-buffer))
6818 (setq help-xref-stack-item item)))))
6819
6820 (defun gnus-article-reply-with-original (&optional wide)
6821 "Start composing a reply mail to the current message.
6822 The text in the region will be yanked. If the region isn't active,
6823 the entire article will be yanked."
6824 (interactive)
6825 (let ((article (cdr gnus-article-current))
6826 contents)
6827 (if (not (gnus-region-active-p))
6828 (with-current-buffer gnus-summary-buffer
6829 (gnus-summary-reply (list (list article)) wide))
6830 (setq contents (buffer-substring (point) (mark t)))
6831 ;; Deactivate active regions.
6832 (when (and (boundp 'transient-mark-mode)
6833 transient-mark-mode)
6834 (setq mark-active nil))
6835 (with-current-buffer gnus-summary-buffer
6836 (gnus-summary-reply
6837 (list (list article contents)) wide)))))
6838
6839 (defun gnus-article-wide-reply-with-original ()
6840 "Start composing a wide reply mail to the current message.
6841 The text in the region will be yanked. If the region isn't active,
6842 the entire article will be yanked."
6843 (interactive)
6844 (gnus-article-reply-with-original t))
6845
6846 (defun gnus-article-followup-with-original ()
6847 "Compose a followup to the current article.
6848 The text in the region will be yanked. If the region isn't active,
6849 the entire article will be yanked."
6850 (interactive)
6851 (let ((article (cdr gnus-article-current))
6852 contents)
6853 (if (not (gnus-region-active-p))
6854 (with-current-buffer gnus-summary-buffer
6855 (gnus-summary-followup (list (list article))))
6856 (setq contents (buffer-substring (point) (mark t)))
6857 ;; Deactivate active regions.
6858 (when (and (boundp 'transient-mark-mode)
6859 transient-mark-mode)
6860 (setq mark-active nil))
6861 (with-current-buffer gnus-summary-buffer
6862 (gnus-summary-followup
6863 (list (list article contents)))))))
6864
6865 (defun gnus-article-hide (&optional arg force)
6866 "Hide all the gruft in the current article.
6867 This means that signatures, cited text and (some) headers will be
6868 hidden.
6869 If given a prefix, show the hidden text instead."
6870 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6871 (gnus-article-hide-headers arg)
6872 (gnus-article-hide-list-identifiers arg)
6873 (gnus-article-hide-citation-maybe arg force)
6874 (gnus-article-hide-signature arg))
6875
6876 (defun gnus-check-group-server ()
6877 ;; Make sure the connection to the server is alive.
6878 (unless (gnus-server-opened
6879 (gnus-find-method-for-group gnus-newsgroup-name))
6880 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6881 (gnus-request-group gnus-newsgroup-name t)))
6882
6883 (eval-when-compile
6884 (autoload 'nneething-get-file-name "nneething"))
6885
6886 (defun gnus-request-article-this-buffer (article group)
6887 "Get an article and insert it into this buffer."
6888 (let (do-update-line sparse-header)
6889 (prog1
6890 (save-excursion
6891 (erase-buffer)
6892 (gnus-kill-all-overlays)
6893 (setq group (or group gnus-newsgroup-name))
6894
6895 ;; Using `gnus-request-article' directly will insert the article into
6896 ;; `nntp-server-buffer' - so we'll save some time by not having to
6897 ;; copy it from the server buffer into the article buffer.
6898
6899 ;; We only request an article by message-id when we do not have the
6900 ;; headers for it, so we'll have to get those.
6901 (when (stringp article)
6902 (gnus-read-header article))
6903
6904 ;; If the article number is negative, that means that this article
6905 ;; doesn't belong in this newsgroup (possibly), so we find its
6906 ;; message-id and request it by id instead of number.
6907 (when (and (numberp article)
6908 gnus-summary-buffer
6909 (get-buffer gnus-summary-buffer)
6910 (gnus-buffer-exists-p gnus-summary-buffer))
6911 (with-current-buffer gnus-summary-buffer
6912 (let ((header (gnus-summary-article-header article)))
6913 (when (< article 0)
6914 (cond
6915 ((memq article gnus-newsgroup-sparse)
6916 ;; This is a sparse gap article.
6917 (setq do-update-line article)
6918 (setq article (mail-header-id header))
6919 (setq sparse-header (gnus-read-header article))
6920 (setq gnus-newsgroup-sparse
6921 (delq article gnus-newsgroup-sparse)))
6922 ((vectorp header)
6923 ;; It's a real article.
6924 (setq article (mail-header-id header)))
6925 (t
6926 ;; It is an extracted pseudo-article.
6927 (setq article 'pseudo)
6928 (gnus-request-pseudo-article header))))
6929
6930 (let ((method (gnus-find-method-for-group
6931 gnus-newsgroup-name)))
6932 (when (and (eq (car method) 'nneething)
6933 (vectorp header))
6934 (let ((dir (nneething-get-file-name
6935 (mail-header-id header))))
6936 (when (and (stringp dir)
6937 (file-directory-p dir))
6938 (setq article 'nneething)
6939 (gnus-group-enter-directory dir))))))))
6940
6941 (cond
6942 ;; Refuse to select canceled articles.
6943 ((and (numberp article)
6944 gnus-summary-buffer
6945 (get-buffer gnus-summary-buffer)
6946 (gnus-buffer-exists-p gnus-summary-buffer)
6947 (eq (cdr (with-current-buffer gnus-summary-buffer
6948 (assq article gnus-newsgroup-reads)))
6949 gnus-canceled-mark))
6950 nil)
6951 ;; We first check `gnus-original-article-buffer'.
6952 ((and (get-buffer gnus-original-article-buffer)
6953 (numberp article)
6954 (with-current-buffer gnus-original-article-buffer
6955 (and (equal (car gnus-original-article) group)
6956 (eq (cdr gnus-original-article) article))))
6957 ;; `insert-buffer-substring' would incorrectly use the
6958 ;; equivalent of string-make-multibyte which amount to decoding
6959 ;; with locale-coding-system, causing failure of
6960 ;; subsequent decoding.
6961 (insert (mm-string-to-multibyte
6962 (with-current-buffer gnus-original-article-buffer
6963 (buffer-substring (point-min) (point-max)))))
6964 'article)
6965 ;; Check the backlog.
6966 ((and gnus-keep-backlog
6967 (gnus-backlog-request-article group article (current-buffer)))
6968 'article)
6969 ;; Check asynchronous pre-fetch.
6970 ((gnus-async-request-fetched-article group article (current-buffer))
6971 (gnus-async-prefetch-next group article gnus-summary-buffer)
6972 (when (and (numberp article) gnus-keep-backlog)
6973 (gnus-backlog-enter-article group article (current-buffer)))
6974 'article)
6975 ;; Check the cache.
6976 ((and gnus-use-cache
6977 (numberp article)
6978 (gnus-cache-request-article article group))
6979 'article)
6980 ;; Check the agent cache.
6981 ((gnus-agent-request-article article group)
6982 'article)
6983 ;; Get the article and put into the article buffer.
6984 ((or (stringp article)
6985 (numberp article))
6986 (let ((gnus-override-method gnus-override-method)
6987 (methods (and (stringp article)
6988 (with-current-buffer gnus-summary-buffer
6989 (gnus-refer-article-methods))))
6990 (backend (car (gnus-find-method-for-group
6991 gnus-newsgroup-name)))
6992 result
6993 (inhibit-read-only t))
6994 (when (and (null gnus-override-method)
6995 methods)
6996 (setq gnus-override-method (pop methods)))
6997 (while (not result)
6998 (erase-buffer)
6999 (gnus-kill-all-overlays)
7000 (let ((gnus-newsgroup-name group))
7001 (gnus-check-group-server))
7002 (cond
7003 ((gnus-request-article article group (current-buffer))
7004 (when (numberp article)
7005 (gnus-async-prefetch-next group article
7006 gnus-summary-buffer)
7007 (when gnus-keep-backlog
7008 (gnus-backlog-enter-article
7009 group article (current-buffer)))
7010 (when (and gnus-agent
7011 (gnus-agent-group-covered-p group))
7012 (gnus-agent-store-article article group)))
7013 (setq result 'article))
7014 (methods
7015 (setq gnus-override-method (pop methods)))
7016 ((not (string-match "^400 "
7017 (nnheader-get-report backend)))
7018 ;; If we get 400 server disconnect, reconnect and
7019 ;; retry; otherwise, assume the article has expired.
7020 (setq result 'done))))
7021 (and (eq result 'article) 'article)))
7022 ;; It was a pseudo.
7023 (t article)))
7024
7025 ;; Associate this article with the current summary buffer.
7026 (setq gnus-article-current-summary gnus-summary-buffer)
7027
7028 ;; Take the article from the original article buffer
7029 ;; and place it in the buffer it's supposed to be in.
7030 (when (and (get-buffer gnus-article-buffer)
7031 (equal (buffer-name (current-buffer))
7032 (buffer-name (get-buffer gnus-article-buffer))))
7033 (save-excursion
7034 (if (get-buffer gnus-original-article-buffer)
7035 (set-buffer gnus-original-article-buffer)
7036 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7037 (buffer-disable-undo)
7038 (setq major-mode 'gnus-original-article-mode)
7039 (setq buffer-read-only t))
7040 (let ((inhibit-read-only t))
7041 (erase-buffer)
7042 (insert-buffer-substring gnus-article-buffer))
7043 (setq gnus-original-article (cons group article)))
7044
7045 ;; Decode charsets.
7046 (run-hooks 'gnus-article-decode-hook)
7047 ;; Mark article as decoded or not.
7048 (setq gnus-article-decoded-p gnus-article-decode-hook))
7049
7050 ;; Update sparse articles.
7051 (when (and do-update-line
7052 (or (numberp article)
7053 (stringp article)))
7054 (let ((buf (current-buffer)))
7055 (set-buffer gnus-summary-buffer)
7056 (gnus-summary-update-article do-update-line sparse-header)
7057 (gnus-summary-goto-subject do-update-line nil t)
7058 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7059 (point))
7060 (set-buffer buf))))))
7061
7062 (defun gnus-block-private-groups (group)
7063 (if (or (gnus-news-group-p group)
7064 (gnus-member-of-valid 'global group))
7065 ;; Block nothing in news groups.
7066 nil
7067 ;; Block everything anywhere else.
7068 "."))
7069
7070 (defun gnus-blocked-images ()
7071 (if (functionp gnus-blocked-images)
7072 (funcall gnus-blocked-images gnus-newsgroup-name)
7073 gnus-blocked-images))
7074
7075 ;;;
7076 ;;; Article editing
7077 ;;;
7078
7079 (defcustom gnus-article-edit-mode-hook nil
7080 "Hook run in article edit mode buffers."
7081 :group 'gnus-article-various
7082 :type 'hook)
7083
7084 (defvar gnus-article-edit-done-function nil)
7085
7086 (defvar gnus-article-edit-mode-map nil)
7087
7088 ;; Should we be using derived.el for this?
7089 (unless gnus-article-edit-mode-map
7090 (setq gnus-article-edit-mode-map (make-keymap))
7091 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7092
7093 (gnus-define-keys gnus-article-edit-mode-map
7094 "\C-c?" describe-mode
7095 "\C-c\C-c" gnus-article-edit-done
7096 "\C-c\C-k" gnus-article-edit-exit
7097 "\C-c\C-f\C-t" message-goto-to
7098 "\C-c\C-f\C-o" message-goto-from
7099 "\C-c\C-f\C-b" message-goto-bcc
7100 ;;"\C-c\C-f\C-w" message-goto-fcc
7101 "\C-c\C-f\C-c" message-goto-cc
7102 "\C-c\C-f\C-s" message-goto-subject
7103 "\C-c\C-f\C-r" message-goto-reply-to
7104 "\C-c\C-f\C-n" message-goto-newsgroups
7105 "\C-c\C-f\C-d" message-goto-distribution
7106 "\C-c\C-f\C-f" message-goto-followup-to
7107 "\C-c\C-f\C-m" message-goto-mail-followup-to
7108 "\C-c\C-f\C-k" message-goto-keywords
7109 "\C-c\C-f\C-u" message-goto-summary
7110 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7111 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7112 "\C-c\C-b" message-goto-body
7113 "\C-c\C-i" message-goto-signature
7114
7115 "\C-c\C-t" message-insert-to
7116 "\C-c\C-n" message-insert-newsgroups
7117 "\C-c\C-o" message-sort-headers
7118 "\C-c\C-e" message-elide-region
7119 "\C-c\C-v" message-delete-not-region
7120 "\C-c\C-z" message-kill-to-signature
7121 "\M-\r" message-newline-and-reformat
7122 "\C-c\C-a" mml-attach-file
7123 "\C-a" message-beginning-of-line
7124 "\t" message-tab
7125 "\M-;" comment-region)
7126
7127 (gnus-define-keys (gnus-article-edit-wash-map
7128 "\C-c\C-w" gnus-article-edit-mode-map)
7129 "f" gnus-article-edit-full-stops))
7130
7131 (easy-menu-define
7132 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7133 '("Field"
7134 ["Fetch To" message-insert-to t]
7135 ["Fetch Newsgroups" message-insert-newsgroups t]
7136 "----"
7137 ["To" message-goto-to t]
7138 ["From" message-goto-from t]
7139 ["Subject" message-goto-subject t]
7140 ["Cc" message-goto-cc t]
7141 ["Reply-To" message-goto-reply-to t]
7142 ["Summary" message-goto-summary t]
7143 ["Keywords" message-goto-keywords t]
7144 ["Newsgroups" message-goto-newsgroups t]
7145 ["Followup-To" message-goto-followup-to t]
7146 ["Mail-Followup-To" message-goto-mail-followup-to t]
7147 ["Distribution" message-goto-distribution t]
7148 ["Body" message-goto-body t]
7149 ["Signature" message-goto-signature t]))
7150
7151 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7152 "Major mode for editing articles.
7153 This is an extended text-mode.
7154
7155 \\{gnus-article-edit-mode-map}"
7156 (make-local-variable 'gnus-article-edit-done-function)
7157 (make-local-variable 'gnus-prev-winconf)
7158 (set (make-local-variable 'font-lock-defaults)
7159 '(message-font-lock-keywords t))
7160 (set (make-local-variable 'mail-header-separator) "")
7161 (set (make-local-variable 'gnus-article-edit-mode) t)
7162 (easy-menu-add message-mode-field-menu message-mode-map)
7163 (mml-mode)
7164 (setq buffer-read-only nil)
7165 (buffer-enable-undo)
7166 (widen))
7167
7168 (defun gnus-article-edit (&optional force)
7169 "Edit the current article.
7170 This will have permanent effect only in mail groups.
7171 If FORCE is non-nil, allow editing of articles even in read-only
7172 groups."
7173 (interactive "P")
7174 (when (and (not force)
7175 (gnus-group-read-only-p))
7176 (error "The current newsgroup does not support article editing"))
7177 (gnus-article-date-original)
7178 (gnus-article-edit-article
7179 'ignore
7180 `(lambda (no-highlight)
7181 'ignore
7182 (gnus-summary-edit-article-done
7183 ,(or (mail-header-references gnus-current-headers) "")
7184 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7185
7186 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7187 "Start editing the contents of the current article buffer."
7188 (let ((winconf (current-window-configuration)))
7189 (set-buffer gnus-article-buffer)
7190 (let ((message-auto-save-directory
7191 ;; Don't associate the article buffer with a draft file.
7192 nil))
7193 (gnus-article-edit-mode))
7194 (funcall start-func)
7195 (set-buffer-modified-p nil)
7196 (gnus-configure-windows 'edit-article)
7197 (setq gnus-article-edit-done-function exit-func)
7198 (setq gnus-prev-winconf winconf)
7199 (unless quiet
7200 (gnus-message 6 "C-c C-c to end edits"))))
7201
7202 (defun gnus-article-edit-done (&optional arg)
7203 "Update the article edits and exit."
7204 (interactive "P")
7205 (let ((func gnus-article-edit-done-function)
7206 (buf (current-buffer))
7207 (start (window-start))
7208 (p (point))
7209 (winconf gnus-prev-winconf))
7210 (widen) ;; Widen it in case that users narrowed the buffer.
7211 (funcall func arg)
7212 (set-buffer buf)
7213 ;; The cache and backlog have to be flushed somewhat.
7214 (when gnus-keep-backlog
7215 (gnus-backlog-remove-article
7216 (car gnus-article-current) (cdr gnus-article-current)))
7217 ;; Flush original article as well.
7218 (gnus-flush-original-article-buffer)
7219 (when gnus-use-cache
7220 (gnus-cache-update-article
7221 (car gnus-article-current) (cdr gnus-article-current)))
7222 ;; We remove all text props from the article buffer.
7223 (kill-all-local-variables)
7224 (set-text-properties (point-min) (point-max) nil)
7225 (gnus-article-mode)
7226 (set-window-configuration winconf)
7227 (set-buffer buf)
7228 (set-window-start (get-buffer-window buf) start)
7229 (set-window-point (get-buffer-window buf) (point)))
7230 (gnus-summary-show-article))
7231
7232 (defun gnus-flush-original-article-buffer ()
7233 (when (get-buffer gnus-original-article-buffer)
7234 (with-current-buffer gnus-original-article-buffer
7235 (setq gnus-original-article nil))))
7236
7237 (defun gnus-article-edit-exit ()
7238 "Exit the article editing without updating."
7239 (interactive)
7240 (when (or (not (buffer-modified-p))
7241 (yes-or-no-p "Article modified; kill anyway? "))
7242 (let ((curbuf (current-buffer))
7243 (p (point))
7244 (window-start (window-start)))
7245 (erase-buffer)
7246 (if (gnus-buffer-live-p gnus-original-article-buffer)
7247 (insert-buffer-substring gnus-original-article-buffer))
7248 (let ((winconf gnus-prev-winconf))
7249 (kill-all-local-variables)
7250 (gnus-article-mode)
7251 (set-window-configuration winconf)
7252 ;; Tippy-toe some to make sure that point remains where it was.
7253 (save-current-buffer
7254 (set-buffer curbuf)
7255 (set-window-start (get-buffer-window (current-buffer)) window-start)
7256 (goto-char p))))
7257 (gnus-summary-show-article)))
7258
7259 (defun gnus-article-edit-full-stops ()
7260 "Interactively repair spacing at end of sentences."
7261 (interactive)
7262 (save-excursion
7263 (goto-char (point-min))
7264 (search-forward-regexp "^$" nil t)
7265 (let ((case-fold-search nil))
7266 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7267
7268 ;;;
7269 ;;; Article highlights
7270 ;;;
7271
7272 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7273
7274 ;;; Internal Variables:
7275
7276 (defcustom gnus-button-url-regexp
7277 (concat
7278 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7279 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7280 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7281 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7282 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7283 (punct "!?:;.,"))
7284 (concat
7285 "\\(?:"
7286 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7287 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7288 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7289 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7290 "\\|"
7291 "[" chars punct "]+" "[" chars "]"
7292 "\\)"))
7293 (concat ;; XEmacs 21.4 doesn't support POSIX.
7294 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7295 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7296 "\\)")
7297 "Regular expression that matches URLs."
7298 :version "24.4"
7299 :group 'gnus-article-buttons
7300 :type 'regexp)
7301
7302 (defcustom gnus-button-valid-fqdn-regexp
7303 message-valid-fqdn-regexp
7304 "Regular expression that matches a valid FQDN."
7305 :version "22.1"
7306 :group 'gnus-article-buttons
7307 :type 'regexp)
7308
7309 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7310 (defcustom gnus-button-valid-localpart-regexp
7311 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7312 "Regular expression that matches a localpart of mail addresses or MIDs."
7313 :version "22.1"
7314 :group 'gnus-article-buttons
7315 :type 'regexp)
7316
7317 (defcustom gnus-button-man-handler 'manual-entry
7318 "Function to use for displaying man pages.
7319 The function must take at least one argument with a string naming the
7320 man page."
7321 :version "22.1"
7322 :type '(choice (function-item :tag "Man" manual-entry)
7323 (function-item :tag "Woman" woman)
7324 (function :tag "Other"))
7325 :group 'gnus-article-buttons)
7326
7327 (defcustom gnus-button-mid-or-mail-regexp
7328 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7329 gnus-button-valid-fqdn-regexp
7330 ">?\\)\\b")
7331 "Regular expression that matches a message ID or a mail address."
7332 :version "22.1"
7333 :group 'gnus-article-buttons
7334 :type 'regexp)
7335
7336 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7337 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7338 Strings like this can be either a message ID or a mail address. If it is one
7339 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7340 message ID or a mail address, respectively. If this variable is set to the
7341 symbol `ask', always query the user what do do. If it is a function, this
7342 function will be called with the string as its only argument. The function
7343 must return `mid', `mail', `invalid' or `ask'."
7344 :version "22.1"
7345 :group 'gnus-article-buttons
7346 :type '(choice (function-item :tag "Heuristic function"
7347 gnus-button-mid-or-mail-heuristic)
7348 (const ask)
7349 (const mid)
7350 (const mail)))
7351
7352 (defcustom gnus-button-mid-or-mail-heuristic-alist
7353 '((-10.0 . ".+\\$.+@")
7354 (-10.0 . "#")
7355 (-10.0 . "\\*")
7356 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7357 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7358 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7359 (-1.0 . "^[^a-z]+@")
7360 ;;
7361 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7362 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7363 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7364 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7365 ;;
7366 (-2.0 . "^[0-9]")
7367 (-1.0 . "^[0-9][0-9]")
7368 ;;
7369 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7370 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7371 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7372 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7373 ;;
7374 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7375 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7376 ;; "[0-9]{8,}.*\@"
7377 (-3.0
7378 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7379 ;; "[0-9]{12,}.*\@"
7380 ;; compensation for TDMA dated mail addresses:
7381 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7382 ;;
7383 (-20.0 . "\\.fsf@") ;; Gnus
7384 (-20.0 . "^slrn")
7385 (-20.0 . "^Pine")
7386 (-20.0 . "^alpine\\.")
7387 (-20.0 . "_-_") ;; Subject change in thread
7388 ;;
7389 (-20.0 . "\\.ln@") ;; leafnode
7390 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7391 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7392 ;;
7393 ;; (5.0 . "") ;; $local_part_len <= 7
7394 (10.0 . "^[^0-9]+@")
7395 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7396 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7397 (3.0 . "\@stud")
7398 ;;
7399 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7400 ;;
7401 (0.5 . "^[A-Z][a-z]")
7402 (0.5 . "^[A-Z][a-z][a-z]")
7403 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7404 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7405 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7406
7407 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7408 address. The REGEXP is processed with `case-fold-search' set to nil."
7409 :version "22.1"
7410 :group 'gnus-article-buttons
7411 :type '(repeat (cons (number :tag "Rate")
7412 (regexp :tag "Regexp"))))
7413
7414 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7415 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7416 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7417 address, `ask' if unsure and `invalid' if the string is invalid."
7418 (let ((case-fold-search nil)
7419 (list gnus-button-mid-or-mail-heuristic-alist)
7420 (result 0) rate regexp lpartlen elem)
7421 (setq lpartlen
7422 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7423 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7424 ;; Certain special cases...
7425 (when (string-match
7426 (concat
7427 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7428 "^[0-9]+\\.[0-9]+@compuserve\\|"
7429 "@public\\.gmane\\.org")
7430 mid-or-mail)
7431 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7432 (setq result 'mail))
7433 (when (string-match "@.*@\\| " mid-or-mail)
7434 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7435 (setq result 'invalid))
7436 ;; Nothing more to do, if result is not a number here...
7437 (when (numberp result)
7438 (while list
7439 (setq elem (car list)
7440 rate (car elem)
7441 regexp (cdr elem)
7442 list (cdr list))
7443 (when (string-match regexp mid-or-mail)
7444 (setq result (+ result rate))
7445 (gnus-message
7446 9 "`%s' matched `%s', rate `%s', result `%s'."
7447 mid-or-mail regexp rate result)))
7448 (when (<= lpartlen 7)
7449 (setq result (+ result 5.0))
7450 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7451 mid-or-mail result))
7452 (when (>= lpartlen 12)
7453 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7454 (cond
7455 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7456 ;; Long local part should contain realname if e-mail address,
7457 ;; too many digits: message-id.
7458 ;; $score -= 5.0 + 0.1 * $local_part_len;
7459 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7460 (setq result (+ result rate))
7461 (gnus-message
7462 9 "Many digits in `%s', rate `%s', result `%s'."
7463 mid-or-mail rate result))
7464 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7465 mid-or-mail)
7466 ;; Too few vowels [^aeiouy]{4,}.*\@
7467 (setq result (+ result -5.0))
7468 (gnus-message
7469 9 "Few vowels in `%s', rate `%s', result `%s'."
7470 mid-or-mail -5.0 result))
7471 (t
7472 (setq result (+ result 5.0))
7473 (gnus-message
7474 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7475 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7476 ;; Maybe we should make this a customizable alist: (condition . 'result)
7477 (cond
7478 ((symbolp result) result)
7479 ;; Now convert number into proper results:
7480 ((< result -10.0) 'mid)
7481 ((> result 10.0) 'mail)
7482 (t 'ask))))
7483
7484 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7485 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7486 (url-mid (concat "news" ":" mid-or-mail))
7487 (url-mailto (concat "mailto" ":" mid-or-mail)))
7488 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7489 (when (fboundp pref)
7490 (setq guessed
7491 ;; get rid of surrounding angles...
7492 (funcall pref
7493 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7494 (if (or (eq 'mid guessed) (eq 'mail guessed))
7495 (setq pref guessed)
7496 (setq pref 'ask)))
7497 (if (eq pref 'ask)
7498 (save-window-excursion
7499 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7500 (setq pref 'mail)
7501 (setq pref 'mid))))
7502 (cond ((eq pref 'mid)
7503 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7504 (gnus-button-handle-news url-mid))
7505 ((eq pref 'mail)
7506 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7507 (gnus-url-mailto url-mailto))
7508 (t (gnus-message 3 "Invalid string.")))))
7509
7510 (defun gnus-button-handle-custom (fun arg)
7511 "Call function FUN on argument ARG.
7512 Both FUN and ARG are supposed to be strings. ARG will be passed
7513 as a symbol to FUN."
7514 (funcall (intern fun)
7515 (if (string-match "^customize-apropos" fun)
7516 arg
7517 (intern arg))))
7518
7519 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7520
7521 (defun gnus-button-handle-describe-function (url)
7522 "Call `describe-function' when pushing the corresponding URL button."
7523 (describe-function
7524 (intern
7525 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7526
7527 (defun gnus-button-handle-describe-variable (url)
7528 "Call `describe-variable' when pushing the corresponding URL button."
7529 (describe-variable
7530 (intern
7531 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7532
7533 (defun gnus-button-handle-symbol (url)
7534 "Display help on variable or function.
7535 Calls `describe-variable' or `describe-function'."
7536 (let ((sym (intern url)))
7537 (cond
7538 ((fboundp sym) (describe-function sym))
7539 ((boundp sym) (describe-variable sym))
7540 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7541
7542 (defun gnus-button-handle-describe-key (url)
7543 "Call `describe-key' when pushing the corresponding URL button."
7544 (let* ((key-string
7545 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7546 (keys (ignore-errors (eval `(kbd ,key-string)))))
7547 (if keys
7548 (describe-key keys)
7549 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7550
7551 (defun gnus-button-handle-apropos (url)
7552 "Call `apropos' when pushing the corresponding URL button."
7553 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7554
7555 (defun gnus-button-handle-apropos-command (url)
7556 "Call `apropos' when pushing the corresponding URL button."
7557 (apropos-command
7558 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7559
7560 (defun gnus-button-handle-apropos-variable (url)
7561 "Call `apropos' when pushing the corresponding URL button."
7562 (funcall
7563 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7564 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7565
7566 (defun gnus-button-handle-apropos-documentation (url)
7567 "Call `apropos' when pushing the corresponding URL button."
7568 (funcall
7569 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7570 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7571
7572 (defun gnus-button-handle-library (url)
7573 "Call `locate-library' when pushing the corresponding URL button."
7574 (gnus-message 9 "url=`%s'" url)
7575 (let* ((lib (locate-library url))
7576 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7577 (if (not lib)
7578 (gnus-message 1 "Cannot locale library `%s'." url)
7579 (find-file-read-only file))))
7580
7581 (defcustom gnus-button-man-level 5
7582 "*Integer that says how many man-related buttons Gnus will show.
7583 The higher the number, the more buttons will appear and the more false
7584 positives are possible. Note that you can set this variable local to
7585 specific groups. Setting it higher in Unix groups is probably a good idea.
7586 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7587 how to set variables in specific groups."
7588 :version "22.1"
7589 :group 'gnus-article-buttons
7590 :link '(custom-manual "(gnus)Group Parameters")
7591 :type 'integer)
7592
7593 (defcustom gnus-button-emacs-level 5
7594 "*Integer that says how many emacs-related buttons Gnus will show.
7595 The higher the number, the more buttons will appear and the more false
7596 positives are possible. Note that you can set this variable local to
7597 specific groups. Setting it higher in Emacs or Gnus related groups is
7598 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7599 `gnus-parameters' on how to set variables in specific groups."
7600 :version "22.1"
7601 :group 'gnus-article-buttons
7602 :link '(custom-manual "(gnus)Group Parameters")
7603 :type 'integer)
7604
7605 (defcustom gnus-button-message-level 5
7606 "*Integer that says how many buttons for news or mail messages will appear.
7607 The higher the number, the more buttons will appear and the more false
7608 positives are possible."
7609 ;; mail addresses, MIDs, URLs for news, ...
7610 :version "22.1"
7611 :group 'gnus-article-buttons
7612 :type 'integer)
7613
7614 (defcustom gnus-button-browse-level 5
7615 "*Integer that says how many buttons for browsing will appear.
7616 The higher the number, the more buttons will appear and the more false
7617 positives are possible."
7618 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7619 :version "22.1"
7620 :group 'gnus-article-buttons
7621 :type 'integer)
7622
7623 (defcustom gnus-button-alist
7624 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7625 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7626 ((concat "\\b\\(nntp\\|news\\):\\("
7627 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7628 0 t gnus-button-handle-news 2)
7629 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7630 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7631 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7632 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7633 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7634 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7635 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7636 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7637 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7638 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7639 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7640 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7641 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7642 ;; RFC 2368 (The mailto URL scheme)
7643 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7644 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7645 ("\\bmailto:\\([^ \n\t]+\\)"
7646 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7647 ;; Info Konqueror style <info:/foo/bar baz>.
7648 ;; Must come before " Gnus home-grown style".
7649 ("\\binfo://?\\([^'\">\n\t]+\\)"
7650 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7651 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7652 ("\\binfo://\\([^'\">\n\t ]+\\)"
7653 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7654 ;; Info GNOME style <info:foo#bar_baz>
7655 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7656 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7657 ;; Info KDE style <info:(foo)bar baz>
7658 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7659 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7660 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7661 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7662 ("\\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,]*\\)\\)?"
7663 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7664 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7665 ;; This is custom
7666 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7667 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7668 ;; Emacs help commands
7669 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7670 ;; regexp doesn't match arguments containing ` '.
7671 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7672 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7673 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7674 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7675 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7676 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7677 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7678 ;; The following entries may lead to many false positives so don't enable
7679 ;; them by default (use a high button level).
7680 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7681 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7682 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7683 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7684 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7685 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7686 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7687 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7688 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7689 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7690 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7691 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7692 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7693 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7694 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7695 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7696 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7697 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7698 ;; Unlike the other regexps we really have to require quoting
7699 ;; here to determine where it ends.
7700 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7701 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7702 ("<URL: *\\([^\n<>]*\\)>"
7703 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7704 ;; RFC 2396 (2.4.3., delims) ...
7705 ("\"URL: *\\([^\n\"]*\\)\""
7706 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7707 ;; Raw URLs.
7708 (gnus-button-url-regexp
7709 0 (>= gnus-button-browse-level 0) browse-url 0)
7710 ;; man pages
7711 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7712 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7713 gnus-button-handle-man 1)
7714 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7715 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7716 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7717 gnus-button-handle-man 1)
7718 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7719 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7720 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7721 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7722 ;; Recognizing patches to .el files. This is somewhat obscure,
7723 ;; but considering the percentage of Gnus users who hack Emacs
7724 ;; Lisp files...
7725 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7726 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7727 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7728 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7729 ;; MID or mail: To avoid too many false positives we don't try to catch
7730 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7731 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7732 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7733 ;; so that non-ambiguous entries (see above) match first.
7734 (gnus-button-mid-or-mail-regexp
7735 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7736 "*Alist of regexps matching buttons in article bodies.
7737
7738 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7739 REGEXP: is the string (case insensitive) matching text around the button (can
7740 also be Lisp expression evaluating to a string),
7741 BUTTON: is the number of the regexp grouping actually matching the button,
7742 FORM: is a Lisp expression which must eval to true for the button to
7743 be added,
7744 CALLBACK: is the function to call when the user push this button, and each
7745 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7746
7747 CALLBACK can also be a variable, in that case the value of that
7748 variable it the real callback function."
7749 :group 'gnus-article-buttons
7750 :type '(repeat (list (choice regexp variable sexp)
7751 (integer :tag "Button")
7752 (sexp :tag "Form")
7753 (function :tag "Callback")
7754 (repeat :tag "Par"
7755 :inline t
7756 (integer :tag "Regexp group")))))
7757 (put 'gnus-button-alist 'risky-local-variable t)
7758
7759 (defcustom gnus-header-button-alist
7760 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7761 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7762 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7763 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7764 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7765 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7766 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7767 0 (>= gnus-button-browse-level 0) browse-url 0)
7768 ("^Subject:" gnus-button-url-regexp
7769 0 (>= gnus-button-browse-level 0) browse-url 0)
7770 ("^[^:]+:" gnus-button-url-regexp
7771 0 (>= gnus-button-browse-level 0) browse-url 0)
7772 ("^OpenPGP:.*url=" gnus-button-url-regexp
7773 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7774 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7775 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7776 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7777 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7778 "*Alist of headers and regexps to match buttons in article heads.
7779
7780 This alist is very similar to `gnus-button-alist', except that each
7781 alist has an additional HEADER element first in each entry:
7782
7783 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7784
7785 HEADER is a regexp to match a header. For a fuller explanation, see
7786 `gnus-button-alist'."
7787 :group 'gnus-article-buttons
7788 :group 'gnus-article-headers
7789 :type '(repeat (list (regexp :tag "Header")
7790 (choice regexp variable)
7791 (integer :tag "Button")
7792 (sexp :tag "Form")
7793 (function :tag "Callback")
7794 (repeat :tag "Par"
7795 :inline t
7796 (integer :tag "Regexp group")))))
7797 (put 'gnus-header-button-alist 'risky-local-variable t)
7798
7799 ;;; Commands:
7800
7801 (defun gnus-article-push-button (event)
7802 "Check text under the mouse pointer for a callback function.
7803 If the text under the mouse pointer has a `gnus-callback' property,
7804 call it with the value of the `gnus-data' text property."
7805 (interactive "e")
7806 (set-buffer (window-buffer (posn-window (event-start event))))
7807 (let* ((pos (posn-point (event-start event)))
7808 (data (get-text-property pos 'gnus-data))
7809 (fun (get-text-property pos 'gnus-callback)))
7810 (goto-char pos)
7811 (when fun
7812 (funcall fun data))))
7813
7814 (defun gnus-article-press-button ()
7815 "Check text at point for a callback function.
7816 If the text at point has a `gnus-callback' property,
7817 call it with the value of the `gnus-data' text property."
7818 (interactive)
7819 (let ((data (get-text-property (point) 'gnus-data))
7820 (fun (get-text-property (point) 'gnus-callback)))
7821 (when fun
7822 (funcall fun data))))
7823
7824 (defun gnus-article-highlight (&optional force)
7825 "Highlight current article.
7826 This function calls `gnus-article-highlight-headers',
7827 `gnus-article-highlight-citation',
7828 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7829 do the highlighting. See the documentation for those functions."
7830 (interactive (list 'force))
7831 (gnus-article-highlight-headers)
7832 (gnus-article-highlight-citation force)
7833 (gnus-article-highlight-signature)
7834 (gnus-article-add-buttons)
7835 (gnus-article-add-buttons-to-head))
7836
7837 (defun gnus-article-highlight-some (&optional force)
7838 "Highlight current article.
7839 This function calls `gnus-article-highlight-headers',
7840 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7841 do the highlighting. See the documentation for those functions."
7842 (interactive (list 'force))
7843 (gnus-article-highlight-headers)
7844 (gnus-article-highlight-signature)
7845 (gnus-article-add-buttons))
7846
7847 (defun gnus-article-highlight-headers ()
7848 "Highlight article headers as specified by `gnus-header-face-alist'."
7849 (interactive)
7850 (gnus-with-article-headers
7851 (let (regexp header-face field-face from hpoints fpoints)
7852 (dolist (entry gnus-header-face-alist)
7853 (goto-char (point-min))
7854 (setq regexp (concat "^\\("
7855 (if (string-equal "" (nth 0 entry))
7856 "[^\t ]"
7857 (nth 0 entry))
7858 "\\)")
7859 header-face (nth 1 entry)
7860 field-face (nth 2 entry))
7861 (while (and (re-search-forward regexp nil t)
7862 (not (eobp)))
7863 (beginning-of-line)
7864 (setq from (point))
7865 (unless (search-forward ":" nil t)
7866 (forward-char 1))
7867 (when (and header-face
7868 (not (memq (point) hpoints)))
7869 (push (point) hpoints)
7870 (gnus-put-text-property from (point) 'face header-face))
7871 (when (and field-face
7872 (not (memq (setq from (point)) fpoints)))
7873 (push from fpoints)
7874 (if (re-search-forward "^[^ \t]" nil t)
7875 (forward-char -2)
7876 (goto-char (point-max)))
7877 (gnus-put-text-property from (point) 'face field-face)))))))
7878
7879 (defun gnus-article-highlight-signature ()
7880 "Highlight the signature in an article.
7881 It does this by highlighting everything after
7882 `gnus-signature-separator' using the face `gnus-signature'."
7883 (interactive)
7884 (gnus-with-article-buffer
7885 (let ((inhibit-point-motion-hooks t))
7886 (save-restriction
7887 (when (and gnus-signature-face
7888 (gnus-article-narrow-to-signature))
7889 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7890 'face gnus-signature-face)
7891 (widen)
7892 (gnus-article-search-signature)
7893 (let ((start (match-beginning 0))
7894 (end (set-marker (make-marker) (1+ (match-end 0)))))
7895 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7896 end)))))))
7897
7898 (defun gnus-button-in-region-p (b e prop)
7899 "Say whether PROP exists in the region."
7900 (text-property-not-all b e prop nil))
7901
7902 (defun gnus-article-add-buttons ()
7903 "Find external references in the article and make buttons of them.
7904 \"External references\" are things like Message-IDs and URLs, as
7905 specified by `gnus-button-alist'."
7906 (interactive)
7907 (gnus-with-article-buffer
7908 (let ((inhibit-point-motion-hooks t)
7909 (case-fold-search t)
7910 (alist gnus-button-alist)
7911 beg entry regexp)
7912 ;; We skip the headers.
7913 (article-goto-body)
7914 (setq beg (point))
7915 (while (setq entry (pop alist))
7916 (setq regexp (eval (car entry)))
7917 (goto-char beg)
7918 (while (re-search-forward regexp nil t)
7919 (let ((start (match-beginning (nth 1 entry)))
7920 (end (match-end (nth 1 entry)))
7921 (from (match-beginning 0)))
7922 (when (and (eval (nth 2 entry))
7923 (not (gnus-button-in-region-p
7924 start end 'gnus-callback)))
7925 ;; That optional form returned non-nil, so we add the
7926 ;; button.
7927 (setq from (set-marker (make-marker) from))
7928 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7929 (gnus-article-extend-url-button from start end))
7930 (gnus-article-add-button start end
7931 'gnus-button-push (list from entry))
7932 (gnus-put-text-property
7933 start end
7934 'gnus-string (buffer-substring-no-properties
7935 start end))))))))))
7936
7937 (defun gnus-article-extend-url-button (beg start end)
7938 "Extend url button if url is folded into two or more lines.
7939 Return non-nil if button is extended. BEG is a marker that points to
7940 the beginning position of a text containing url. START and END are
7941 the endpoints of a url button before it is extended. The concatenated
7942 url is put as the `gnus-button-url' overlay property on the button."
7943 (let ((opoint (point))
7944 (points (list start end))
7945 url delim regexp)
7946 (prog1
7947 (when (and (progn
7948 (goto-char end)
7949 (not (looking-at "[\t ]*[\">]")))
7950 (progn
7951 (goto-char start)
7952 (string-match
7953 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7954 (buffer-substring (point-at-bol) start)))
7955 (progn
7956 (setq url (list (buffer-substring start end))
7957 delim (if (match-beginning 1) ">" "\""))
7958 (beginning-of-line)
7959 (setq regexp (concat
7960 (when (and (looking-at
7961 message-cite-prefix-regexp)
7962 (< (match-end 0) start))
7963 (regexp-quote (match-string 0)))
7964 "\
7965 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7966 delim "\\)"))
7967 (while (progn
7968 (forward-line 1)
7969 (and (looking-at regexp)
7970 (prog1
7971 (match-beginning 1)
7972 (push (or (match-string 2)
7973 (match-string 1))
7974 url)
7975 (push (setq end (or (match-end 2)
7976 (match-end 1)))
7977 points)
7978 (push (or (match-beginning 2)
7979 (match-beginning 1))
7980 points)))))
7981 (match-beginning 2)))
7982 (let (gnus-article-mouse-face widget-mouse-face)
7983 (while points
7984 (gnus-article-add-button (pop points) (pop points)
7985 'gnus-button-push
7986 (list beg (assq 'gnus-button-url-regexp
7987 gnus-button-alist)))))
7988 (let ((overlay (gnus-make-overlay start end)))
7989 (gnus-overlay-put overlay 'evaporate t)
7990 (gnus-overlay-put overlay 'gnus-button-url
7991 (list (mapconcat 'identity (nreverse url) "")))
7992 (when gnus-article-mouse-face
7993 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7994 t)
7995 (goto-char opoint))))
7996
7997 ;; Add buttons to the head of an article.
7998 (defun gnus-article-add-buttons-to-head ()
7999 "Add buttons to the head of the article."
8000 (interactive)
8001 (gnus-with-article-headers
8002 (let (beg end)
8003 (dolist (entry gnus-header-button-alist)
8004 ;; Each alist entry.
8005 (goto-char (point-min))
8006 (while (re-search-forward (car entry) nil t)
8007 ;; Each header matching the entry.
8008 (setq beg (match-beginning 0))
8009 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8010 (match-beginning 0))
8011 (point-max)))
8012 (goto-char beg)
8013 (while (re-search-forward (eval (nth 1 entry)) end t)
8014 ;; Each match within a header.
8015 (let* ((entry (cdr entry))
8016 (start (match-beginning (nth 1 entry)))
8017 (end (match-end (nth 1 entry)))
8018 (form (nth 2 entry)))
8019 (goto-char (match-end 0))
8020 (when (eval form)
8021 (gnus-article-add-button
8022 start end (nth 3 entry)
8023 (buffer-substring (match-beginning (nth 4 entry))
8024 (match-end (nth 4 entry)))))))
8025 (goto-char end))))))
8026
8027 ;;; External functions:
8028
8029 (defun gnus-article-add-button (from to fun &optional data text)
8030 "Create a button between FROM and TO with callback FUN and data DATA."
8031 (when gnus-article-button-face
8032 (gnus-overlay-put (gnus-make-overlay from to nil t)
8033 'face gnus-article-button-face))
8034 (gnus-add-text-properties
8035 from to
8036 (nconc (and gnus-article-mouse-face
8037 (list gnus-mouse-face-prop gnus-article-mouse-face))
8038 (list 'gnus-callback fun)
8039 (and data (list 'gnus-data data))))
8040 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8041 :help-echo (or text "Follow the link")
8042 :keymap gnus-url-button-map
8043 :button-keymap gnus-widget-button-keymap))
8044
8045 (defun gnus-article-copy-string ()
8046 "Copy the string in the button to the kill ring."
8047 (interactive)
8048 (gnus-article-check-buffer)
8049 (let ((data (get-text-property (point) 'gnus-string)))
8050 (when data
8051 (with-temp-buffer
8052 (insert data)
8053 (copy-region-as-kill (point-min) (point-max))
8054 (message "Copied %s" data)))))
8055
8056 ;;; Internal functions:
8057
8058 (defun gnus-article-set-globals ()
8059 (with-current-buffer gnus-summary-buffer
8060 (gnus-set-global-variables)))
8061
8062 (defun gnus-signature-toggle (end)
8063 (gnus-with-article-buffer
8064 (let ((inhibit-point-motion-hooks t))
8065 (if (text-property-any end (point-max) 'article-type 'signature)
8066 (progn
8067 (gnus-delete-wash-type 'signature)
8068 (gnus-remove-text-properties-when
8069 'article-type 'signature end (point-max)
8070 (cons 'article-type (cons 'signature
8071 gnus-hidden-properties))))
8072 (gnus-add-wash-type 'signature)
8073 (gnus-add-text-properties-when
8074 'article-type nil end (point-max)
8075 (cons 'article-type (cons 'signature
8076 gnus-hidden-properties)))))
8077 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8078 (gnus-set-mode-line 'article))))
8079
8080 (defun gnus-button-push (marker-and-entry)
8081 ;; Push button starting at MARKER.
8082 (save-excursion
8083 (let* ((marker (car marker-and-entry))
8084 (entry (cadr marker-and-entry))
8085 (regexp (car entry))
8086 (inhibit-point-motion-hooks t))
8087 (goto-char marker)
8088 ;; This is obviously true, or something bad is happening :)
8089 ;; But we need it to have the match-data
8090 (when (looking-at (or (if (symbolp regexp)
8091 (symbol-value regexp)
8092 regexp)))
8093 (let ((fun (nth 3 entry))
8094 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8095 (get-char-property marker 'gnus-button-url))
8096 (mapcar (lambda (group)
8097 (let ((string (match-string group)))
8098 (set-text-properties
8099 0 (length string) nil string)
8100 string))
8101 (nthcdr 4 entry)))))
8102
8103 (cond
8104 ((fboundp fun)
8105 (apply fun args))
8106 ((and (boundp fun)
8107 (fboundp (symbol-value fun)))
8108 (apply (symbol-value fun) args))
8109 (t
8110 (gnus-message 1 "You must define `%S' to use this button"
8111 (cons fun args)))))))))
8112
8113 (defun gnus-parse-news-url (url)
8114 (let (scheme server port group message-id articles)
8115 (with-temp-buffer
8116 (insert url)
8117 (goto-char (point-min))
8118 (when (looking-at "\\([A-Za-z]+\\):")
8119 (setq scheme (match-string 1))
8120 (goto-char (match-end 0)))
8121 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8122 (setq server (match-string 1))
8123 (setq port (if (stringp (match-string 3))
8124 (string-to-number (match-string 3))
8125 (match-string 3)))
8126 (goto-char (match-end 0)))
8127
8128 (cond
8129 ((looking-at "\\(.*@.*\\)")
8130 (setq message-id (match-string 1)))
8131 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8132 (setq group (match-string 1)
8133 articles (split-string (match-string 2) "-")))
8134 ((looking-at "\\([^/]+\\)/?")
8135 (setq group (match-string 1)))
8136 (t
8137 (error "Unknown news URL syntax"))))
8138 (list scheme server port group message-id articles)))
8139
8140 (defun gnus-button-handle-news (url)
8141 "Fetch a news URL."
8142 (destructuring-bind (scheme server port group message-id articles)
8143 (gnus-parse-news-url url)
8144 (cond
8145 (message-id
8146 (with-current-buffer gnus-summary-buffer
8147 (if server
8148 (let ((gnus-refer-article-method
8149 (nconc (list (list 'nntp server))
8150 gnus-refer-article-method))
8151 (nntp-port-number (or port "nntp")))
8152 (gnus-message 7 "Fetching %s with %s"
8153 message-id gnus-refer-article-method)
8154 (gnus-summary-refer-article message-id))
8155 (gnus-summary-refer-article message-id))))
8156 (group
8157 (gnus-button-fetch-group url)))))
8158
8159 (defun gnus-button-patch (library line)
8160 "Visit an Emacs Lisp library LIBRARY on line LINE."
8161 (interactive)
8162 (let ((file (locate-library (file-name-nondirectory library))))
8163 (unless file
8164 (error "Couldn't find library %s" library))
8165 (find-file file)
8166 (goto-char (point-min))
8167 (forward-line (1- (string-to-number line)))))
8168
8169 (defun gnus-button-handle-man (url)
8170 "Fetch a man page."
8171 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8172 (when (eq gnus-button-man-handler 'woman)
8173 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8174 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8175 (funcall gnus-button-man-handler url))
8176
8177 (defun gnus-button-handle-info-url (url)
8178 "Fetch an info URL."
8179 (setq url (mm-subst-char-in-string ?+ ?\ url))
8180 (cond
8181 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8182 (gnus-info-find-node
8183 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8184 "Gnus")
8185 ")" (gnus-url-unhex-string (match-string 2 url)))))
8186 ((string-match "([^)\"]+)[^\"]+" url)
8187 (setq url
8188 (gnus-replace-in-string
8189 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8190 (gnus-info-find-node url))
8191 (t (error "Can't parse %s" url))))
8192
8193 (defun gnus-button-handle-info-url-gnome (url)
8194 "Fetch GNOME style info URL."
8195 (setq url (mm-subst-char-in-string ?_ ?\ url))
8196 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8197 (gnus-info-find-node
8198 (concat "("
8199 (gnus-url-unhex-string
8200 (match-string 1 url))
8201 ")"
8202 (or (gnus-url-unhex-string
8203 (match-string 2 url))
8204 "Top")))
8205 (error "Can't parse %s" url)))
8206
8207 (defun gnus-button-handle-info-url-kde (url)
8208 "Fetch KDE style info URL."
8209 (gnus-info-find-node (gnus-url-unhex-string url)))
8210
8211 ;; (info) will autoload info.el
8212 (declare-function Info-menu "info" (menu-item &optional fork))
8213 (declare-function Info-index-next "info" (num))
8214
8215 (defun gnus-button-handle-info-keystrokes (url)
8216 "Call `info' when pushing the corresponding URL button."
8217 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8218 (let (node indx comma)
8219 (if (string-match
8220 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8221 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8222 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8223 "\\(?:[ \t\n,]*\\)\\)?")
8224 url)
8225 (setq node (match-string 2 url)
8226 indx (match-string 3 url))
8227 (error "Can't parse %s" url))
8228 (info)
8229 (Info-directory)
8230 (Info-menu node)
8231 (when (> (length indx) 0)
8232 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8233 "\\([ \t\n,]*\\)")
8234 indx)
8235 (setq comma (match-string 2 indx))
8236 (setq indx (match-string 1 indx))
8237 (Info-index indx)
8238 (when comma
8239 (dotimes (i (with-temp-buffer
8240 (insert comma)
8241 ;; Note: the XEmacs version of `how-many' takes
8242 ;; no optional argument.
8243 (goto-char (point-min))
8244 (how-many ",")))
8245 (Info-index-next 1)))
8246 nil)))
8247
8248 (autoload 'pgg-snarf-keys-region "pgg")
8249 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8250 (declare-function pgg-display-output-buffer "pgg" (start end status))
8251
8252 (defun gnus-button-openpgp (url)
8253 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8254 (with-temp-buffer
8255 (mm-url-insert-file-contents-external url)
8256 (pgg-snarf-keys-region (point-min) (point-max))
8257 (pgg-display-output-buffer nil nil nil)))
8258
8259 (defun gnus-button-message-id (message-id)
8260 "Fetch MESSAGE-ID."
8261 (with-current-buffer gnus-summary-buffer
8262 (gnus-summary-refer-article message-id)))
8263
8264 (defun gnus-button-fetch-group (address &rest ignore)
8265 "Fetch GROUP specified by ADDRESS."
8266 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8267 address)
8268 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8269 ;; for nntp:// and news://
8270 (setq address (match-string 3 address)))
8271 (if (not (string-match "[:/]" address))
8272 ;; This is just a simple group url.
8273 (gnus-group-read-ephemeral-group address gnus-select-method)
8274 (if (not
8275 (string-match
8276 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8277 address))
8278 (error "Can't parse %s" address)
8279 (gnus-group-read-ephemeral-group
8280 (match-string 4 address)
8281 `(nntp ,(match-string 1 address)
8282 (nntp-address ,(match-string 1 address))
8283 (nntp-port-number ,(if (match-end 3)
8284 (match-string 3 address)
8285 "nntp")))
8286 nil nil nil
8287 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8288
8289 (defun gnus-url-parse-query-string (query &optional downcase)
8290 (let (retval pairs cur key val)
8291 (setq pairs (split-string query "&"))
8292 (while pairs
8293 (setq cur (car pairs)
8294 pairs (cdr pairs))
8295 (if (not (string-match "=" cur))
8296 nil ; Grace
8297 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8298 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8299 (if downcase
8300 (setq key (downcase key)))
8301 (setq cur (assoc key retval))
8302 (if cur
8303 (setcdr cur (cons val (cdr cur)))
8304 (setq retval (cons (list key val) retval)))))
8305 retval))
8306
8307 (defun gnus-url-mailto (url)
8308 ;; Send mail to someone
8309 (setq url (replace-regexp-in-string "\n" " " url))
8310 (when (string-match "mailto:/*\\(.*\\)" url)
8311 (setq url (substring url (match-beginning 1) nil)))
8312 (let (to args subject func)
8313 (setq args (gnus-url-parse-query-string
8314 (if (string-match "^\\?" url)
8315 (substring url 1)
8316 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8317 (concat "to=" (match-string 1 url) "&"
8318 (match-string 2 url))
8319 (concat "to=" url))))
8320 subject (cdr-safe (assoc "subject" args)))
8321 (gnus-msg-mail)
8322 (while args
8323 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8324 (if (fboundp func)
8325 (funcall func)
8326 (message-position-on-field (caar args)))
8327 (insert (gnus-replace-in-string
8328 (mapconcat 'identity (reverse (cdar args)) ", ")
8329 "\r\n" "\n" t))
8330 (setq args (cdr args)))
8331 (if subject
8332 (message-goto-body)
8333 (message-goto-subject))))
8334
8335 (defun gnus-button-embedded-url (address)
8336 "Activate ADDRESS with `browse-url'."
8337 (browse-url (gnus-strip-whitespace address)))
8338
8339 ;;; Next/prev buttons in the article buffer.
8340
8341 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8342 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8343
8344 (defvar gnus-prev-page-map
8345 (let ((map (make-sparse-keymap)))
8346 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8347 (define-key map "\r" 'gnus-button-prev-page)
8348 map))
8349
8350 (defvar gnus-next-page-map
8351 (let ((map (make-sparse-keymap)))
8352 (define-key map gnus-mouse-2 'gnus-button-next-page)
8353 (define-key map "\r" 'gnus-button-next-page)
8354 map))
8355
8356 (defun gnus-insert-prev-page-button ()
8357 (let ((b (point)) e
8358 (inhibit-read-only t))
8359 (gnus-eval-format
8360 gnus-prev-page-line-format nil
8361 `(keymap ,gnus-prev-page-map
8362 gnus-prev t
8363 gnus-callback gnus-article-button-prev-page
8364 article-type annotation))
8365 (setq e (if (bolp)
8366 ;; Exclude a newline.
8367 (1- (point))
8368 (point)))
8369 (when gnus-article-button-face
8370 (gnus-overlay-put (gnus-make-overlay b e nil t)
8371 'face gnus-article-button-face))
8372 (widget-convert-button
8373 'link b e
8374 :action 'gnus-button-prev-page
8375 :button-keymap gnus-prev-page-map)))
8376
8377 (defun gnus-button-next-page (&optional args more-args)
8378 "Go to the next page."
8379 (interactive)
8380 (let ((win (selected-window)))
8381 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8382 (gnus-article-next-page)
8383 (select-window win)))
8384
8385 (defun gnus-button-prev-page (&optional args more-args)
8386 "Go to the prev page."
8387 (interactive)
8388 (let ((win (selected-window)))
8389 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8390 (gnus-article-prev-page)
8391 (select-window win)))
8392
8393 (defun gnus-insert-next-page-button ()
8394 (let ((b (point)) e
8395 (inhibit-read-only t))
8396 (gnus-eval-format gnus-next-page-line-format nil
8397 `(keymap ,gnus-next-page-map
8398 gnus-next t
8399 gnus-callback gnus-article-button-next-page
8400 article-type annotation))
8401 (setq e (if (bolp)
8402 ;; Exclude a newline.
8403 (1- (point))
8404 (point)))
8405 (when gnus-article-button-face
8406 (gnus-overlay-put (gnus-make-overlay b e nil t)
8407 'face gnus-article-button-face))
8408 (widget-convert-button
8409 'link b e
8410 :action 'gnus-button-next-page
8411 :button-keymap gnus-next-page-map)))
8412
8413 (defun gnus-article-button-next-page (arg)
8414 "Go to the next page."
8415 (interactive "P")
8416 (let ((win (selected-window)))
8417 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8418 (gnus-article-next-page)
8419 (select-window win)))
8420
8421 (defun gnus-article-button-prev-page (arg)
8422 "Go to the prev page."
8423 (interactive "P")
8424 (let ((win (selected-window)))
8425 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8426 (gnus-article-prev-page)
8427 (select-window win)))
8428
8429 (defvar gnus-decode-header-methods
8430 '(mail-decode-encoded-word-region)
8431 "List of methods used to decode headers.
8432
8433 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8434 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8435 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8436 whose names match REGEXP.
8437
8438 For example:
8439 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8440 mail-decode-encoded-word-region
8441 (\"chinese\" . rfc1843-decode-region))
8442 ")
8443
8444 (defvar gnus-decode-header-methods-cache nil)
8445
8446 (defun gnus-multi-decode-header (start end)
8447 "Apply the functions from `gnus-encoded-word-methods' that match."
8448 (unless (and gnus-decode-header-methods-cache
8449 (eq gnus-newsgroup-name
8450 (car gnus-decode-header-methods-cache)))
8451 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8452 (dolist (x gnus-decode-header-methods)
8453 (if (symbolp x)
8454 (nconc gnus-decode-header-methods-cache (list x))
8455 (if (and gnus-newsgroup-name
8456 (string-match (car x) gnus-newsgroup-name))
8457 (nconc gnus-decode-header-methods-cache
8458 (list (cdr x)))))))
8459 (let ((xlist gnus-decode-header-methods-cache))
8460 (pop xlist)
8461 (save-restriction
8462 (narrow-to-region start end)
8463 (while xlist
8464 (funcall (pop xlist) (point-min) (point-max))))))
8465
8466 ;;;
8467 ;;; Treatment top-level handling.
8468 ;;;
8469
8470 (defvar gnus-inhibit-article-treatments nil)
8471
8472 (defun gnus-treat-article (gnus-treat-condition
8473 &optional part-number total-parts gnus-treat-type)
8474 (let ((gnus-treat-length (- (point-max) (point-min)))
8475 (alist gnus-treatment-function-alist)
8476 (article-goto-body-goes-to-point-min-p t)
8477 (treated-type
8478 (or (not gnus-treat-type)
8479 (catch 'found
8480 (let ((list gnus-article-treat-types))
8481 (while list
8482 (when (string-match (pop list) gnus-treat-type)
8483 (throw 'found t)))))))
8484 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8485 val elem)
8486 (gnus-run-hooks 'gnus-part-display-hook)
8487 (dolist (elem alist)
8488 (setq val
8489 (save-excursion
8490 (when (gnus-buffer-live-p gnus-summary-buffer)
8491 (set-buffer gnus-summary-buffer))
8492 (symbol-value (car elem))))
8493 (when (and (or (consp val)
8494 treated-type)
8495 (or (not gnus-inhibit-article-treatments)
8496 (eq gnus-treat-condition 'head))
8497 (gnus-treat-predicate val)
8498 (or (not (get (car elem) 'highlight))
8499 highlightp))
8500 (save-restriction
8501 (funcall (cadr elem)))))))
8502
8503 ;; Dynamic variables.
8504 (defvar part-number)
8505 (defvar total-parts)
8506 (defvar gnus-treat-type)
8507 (defvar gnus-treat-condition)
8508 (defvar gnus-treat-length)
8509
8510 (defun gnus-treat-predicate (val)
8511 (cond
8512 ((null val)
8513 nil)
8514 (gnus-treat-condition
8515 (eq gnus-treat-condition val))
8516 ((and (listp val)
8517 (stringp (car val)))
8518 (apply 'gnus-or (mapcar `(lambda (s)
8519 (string-match s ,(or gnus-newsgroup-name "")))
8520 val)))
8521 ((listp val)
8522 (let ((pred (pop val)))
8523 (cond
8524 ((eq pred 'or)
8525 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8526 ((eq pred 'and)
8527 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8528 ((eq pred 'not)
8529 (not (gnus-treat-predicate (car val))))
8530 ((eq pred 'typep)
8531 (equal (car val) gnus-treat-type))
8532 ((functionp pred)
8533 (funcall pred))
8534 (t
8535 (error "%S is not a valid predicate" pred)))))
8536 ((eq val t)
8537 t)
8538 ((eq val 'head)
8539 nil)
8540 ((eq val 'first)
8541 (eq part-number 1))
8542 ((eq val 'last)
8543 (eq part-number total-parts))
8544 ((numberp val)
8545 (< gnus-treat-length val))
8546 (t
8547 (error "%S is not a valid value" val))))
8548
8549 (defun gnus-article-encrypt-body (protocol &optional n)
8550 "Encrypt the article body."
8551 (interactive
8552 (list
8553 (or gnus-article-encrypt-protocol
8554 (gnus-completing-read "Encrypt protocol"
8555 (mapcar 'car gnus-article-encrypt-protocol-alist)
8556 t))
8557 current-prefix-arg))
8558 ;; User might hit `K E' instead of `K e', so prompt once.
8559 (when (and gnus-article-encrypt-protocol
8560 gnus-novice-user)
8561 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8562 (error "Encrypt aborted")))
8563 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8564 (unless func
8565 (error "Can't find the encrypt protocol %s" protocol))
8566 (if (member gnus-newsgroup-name '("nndraft:delayed"
8567 "nndraft:drafts"
8568 "nndraft:queue"))
8569 (error "Can't encrypt the article in group %s"
8570 gnus-newsgroup-name))
8571 (gnus-summary-iterate n
8572 (with-current-buffer gnus-summary-buffer
8573 (let ((mail-parse-charset gnus-newsgroup-charset)
8574 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8575 (summary-buffer gnus-summary-buffer)
8576 references point)
8577 (gnus-set-global-variables)
8578 (when (gnus-group-read-only-p)
8579 (error "The current newsgroup does not support article encrypt"))
8580 (gnus-summary-show-article t)
8581 (setq references
8582 (or (mail-header-references gnus-current-headers) ""))
8583 (set-buffer gnus-article-buffer)
8584 (let* ((inhibit-read-only t)
8585 (headers
8586 (mapcar (lambda (field)
8587 (and (save-restriction
8588 (message-narrow-to-head)
8589 (goto-char (point-min))
8590 (search-forward field nil t))
8591 (prog2
8592 (message-narrow-to-field)
8593 (buffer-string)
8594 (delete-region (point-min) (point-max))
8595 (widen))))
8596 '("Content-Type:" "Content-Transfer-Encoding:"
8597 "Content-Disposition:"))))
8598 (message-narrow-to-head)
8599 (message-remove-header "MIME-Version")
8600 (goto-char (point-max))
8601 (setq point (point))
8602 (insert (apply 'concat headers))
8603 (widen)
8604 (narrow-to-region point (point-max))
8605 (let ((message-options message-options))
8606 (message-options-set 'message-sender user-mail-address)
8607 (message-options-set 'message-recipients user-mail-address)
8608 (message-options-set 'message-sign-encrypt 'not)
8609 (funcall func))
8610 (goto-char (point-min))
8611 (insert "MIME-Version: 1.0\n")
8612 (widen)
8613 (gnus-summary-edit-article-done
8614 references nil summary-buffer t))
8615 (when gnus-keep-backlog
8616 (gnus-backlog-remove-article
8617 (car gnus-article-current) (cdr gnus-article-current)))
8618 (gnus-flush-original-article-buffer)
8619 (when gnus-use-cache
8620 (gnus-cache-update-article
8621 (car gnus-article-current) (cdr gnus-article-current))))))))
8622
8623 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8624 "The following specs can be used:
8625 %t The security MIME type
8626 %i Additional info
8627 %d Details
8628 %D Details if button is pressed")
8629
8630 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8631 "The following specs can be used:
8632 %t The security MIME type
8633 %i Additional info
8634 %d Details
8635 %D Details if button is pressed")
8636
8637 (defvar gnus-mime-security-button-line-format-alist
8638 '((?t gnus-tmp-type ?s)
8639 (?i gnus-tmp-info ?s)
8640 (?d gnus-tmp-details ?s)
8641 (?D gnus-tmp-pressed-details ?s)))
8642
8643 (defvar gnus-mime-security-button-commands
8644 '((gnus-article-press-button "\r" "Show Detail")
8645 (undefined "v")
8646 (undefined "t")
8647 (undefined "C")
8648 (gnus-mime-security-save-part "o" "Save...")
8649 (undefined "\C-o")
8650 (undefined "r")
8651 (undefined "d")
8652 (undefined "c")
8653 (undefined "i")
8654 (undefined "E")
8655 (undefined "e")
8656 (undefined "p")
8657 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8658 (undefined ".")))
8659
8660 (defvar gnus-mime-security-button-map
8661 (let ((map (make-sparse-keymap)))
8662 (define-key map gnus-mouse-2 'gnus-article-push-button)
8663 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8664 (dolist (c gnus-mime-security-button-commands)
8665 (define-key map (cadr c) (car c)))
8666 map))
8667
8668 (easy-menu-define
8669 gnus-mime-security-button-menu gnus-mime-security-button-map
8670 "Security button menu."
8671 `("Security Part"
8672 ,@(delq nil
8673 (mapcar (lambda (c)
8674 (unless (eq (car c) 'undefined)
8675 (vector (caddr c) (car c) :active t)))
8676 gnus-mime-security-button-commands))))
8677
8678 (defun gnus-mime-security-button-menu (event prefix)
8679 "Construct a context-sensitive menu of security commands."
8680 (interactive "e\nP")
8681 (save-window-excursion
8682 (let ((pos (event-start event)))
8683 (select-window (posn-window pos))
8684 (goto-char (posn-point pos))
8685 (gnus-article-check-buffer)
8686 (popup-menu gnus-mime-security-button-menu nil prefix))))
8687
8688 (defvar gnus-mime-security-details-buffer nil)
8689
8690 (defvar gnus-mime-security-button-pressed nil)
8691
8692 (defvar gnus-mime-security-show-details-inline t
8693 "If non-nil, show details in the article buffer.")
8694
8695 (defun gnus-mime-security-verify-or-decrypt (handle)
8696 (mm-remove-parts (cdr handle))
8697 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8698 point (inhibit-read-only t))
8699 (if region
8700 (goto-char (car region)))
8701 (setq point (point))
8702 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8703 (let* ((mm-verify-option 'known)
8704 (mm-decrypt-option 'known)
8705 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8706 (unless (eq nparts (cdr handle))
8707 (mm-destroy-parts (cdr handle))
8708 (setcdr handle nparts))))
8709 (gnus-mime-display-security handle)
8710 (when region
8711 (delete-region (point) (cdr region))
8712 (set-marker (car region) nil)
8713 (set-marker (cdr region) nil))
8714 (goto-char point)))
8715
8716 (defun gnus-mime-security-show-details (handle)
8717 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8718 (if (not details)
8719 (gnus-message 5 "No details.")
8720 (if gnus-mime-security-show-details-inline
8721 (let ((gnus-mime-security-button-pressed
8722 (not (get-text-property (point) 'gnus-mime-details)))
8723 (gnus-mime-security-button-line-format
8724 (get-text-property (point) 'gnus-line-format))
8725 (inhibit-read-only t))
8726 (forward-char -1)
8727 (while (eq (get-text-property (point) 'gnus-line-format)
8728 gnus-mime-security-button-line-format)
8729 (forward-char -1))
8730 (forward-char)
8731 (save-restriction
8732 (narrow-to-region (point) (point))
8733 (gnus-insert-mime-security-button handle))
8734 (delete-region (point)
8735 (or (text-property-not-all
8736 (point) (point-max)
8737 'gnus-line-format
8738 gnus-mime-security-button-line-format)
8739 (point-max))))
8740 ;; Not inlined.
8741 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8742 (with-current-buffer gnus-mime-security-details-buffer
8743 (erase-buffer)
8744 t)
8745 (setq gnus-mime-security-details-buffer
8746 (gnus-get-buffer-create "*MIME Security Details*")))
8747 (with-current-buffer gnus-mime-security-details-buffer
8748 (insert details)
8749 (goto-char (point-min)))
8750 (pop-to-buffer gnus-mime-security-details-buffer)))))
8751
8752 (defun gnus-mime-security-press-button (handle)
8753 (save-excursion
8754 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8755 (gnus-mime-security-show-details handle)
8756 (gnus-mime-security-verify-or-decrypt handle))))
8757
8758 (defun gnus-insert-mime-security-button (handle &optional displayed)
8759 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8760 (gnus-tmp-type
8761 (concat
8762 (or (nth 2 (assoc protocol mm-verify-function-alist))
8763 (nth 2 (assoc protocol mm-decrypt-function-alist))
8764 "Unknown")
8765 (if (equal (car handle) "multipart/signed")
8766 " Signed" " Encrypted")
8767 " Part"))
8768 (gnus-tmp-info
8769 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8770 "Undecided"))
8771 (gnus-tmp-details
8772 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8773 gnus-tmp-pressed-details
8774 b e)
8775 (setq gnus-tmp-details
8776 (if gnus-tmp-details
8777 (concat "\n" gnus-tmp-details)
8778 ""))
8779 (setq gnus-tmp-pressed-details
8780 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8781 (unless (bolp)
8782 (insert "\n"))
8783 (setq b (point))
8784 (gnus-eval-format
8785 gnus-mime-security-button-line-format
8786 gnus-mime-security-button-line-format-alist
8787 `(keymap ,gnus-mime-security-button-map
8788 gnus-callback gnus-mime-security-press-button
8789 gnus-line-format ,gnus-mime-security-button-line-format
8790 gnus-mime-details ,gnus-mime-security-button-pressed
8791 article-type annotation
8792 gnus-data ,handle))
8793 (setq e (if (bolp)
8794 ;; Exclude a newline.
8795 (1- (point))
8796 (point)))
8797 (when gnus-article-button-face
8798 (gnus-overlay-put (gnus-make-overlay b e nil t)
8799 'face gnus-article-button-face))
8800 (widget-convert-button
8801 'link b e
8802 :mime-handle handle
8803 :action 'gnus-widget-press-button
8804 :button-keymap gnus-mime-security-button-map
8805 :help-echo
8806 (lambda (widget)
8807 ;; Needed to properly clear the message due to a bug in
8808 ;; wid-edit (XEmacs only).
8809 (when (boundp 'help-echo-owns-message)
8810 (setq help-echo-owns-message t))
8811 (format
8812 "%S: show detail; %S: more options"
8813 (aref gnus-mouse-2 0)
8814 (aref gnus-down-mouse-3 0))))))
8815
8816 (defun gnus-mime-display-security (handle)
8817 (save-restriction
8818 (narrow-to-region (point) (point))
8819 (unless (gnus-unbuttonized-mime-type-p (car handle))
8820 (gnus-insert-mime-security-button handle))
8821 (gnus-mime-display-part (cadr handle))
8822 (unless (bolp)
8823 (insert "\n"))
8824 (unless (gnus-unbuttonized-mime-type-p (car handle))
8825 (let ((gnus-mime-security-button-line-format
8826 gnus-mime-security-button-end-line-format))
8827 (gnus-insert-mime-security-button handle)))
8828 (mm-set-handle-multipart-parameter
8829 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8830 (goto-char (point-max))))
8831
8832 (defun gnus-mime-security-run-function (function)
8833 "Run FUNCTION with the security part under point."
8834 (gnus-article-check-buffer)
8835 (let ((data (get-text-property (point) 'gnus-data))
8836 buffer handle)
8837 (when (and (stringp (car-safe data))
8838 (setq buffer (mm-handle-multipart-original-buffer data))
8839 (setq handle (cadr data)))
8840 (if (bufferp (mm-handle-buffer handle))
8841 (progn
8842 (setq handle (cons buffer (copy-sequence (cdr handle))))
8843 (mm-handle-set-undisplayer handle nil))
8844 (setq handle (mm-make-handle
8845 buffer
8846 (mm-handle-multipart-ctl-parameter handle 'protocol)
8847 nil nil nil nil nil nil)))
8848 (funcall function handle))))
8849
8850 (defun gnus-mime-security-save-part ()
8851 "Save the security part under point."
8852 (interactive)
8853 (gnus-mime-security-run-function 'mm-save-part))
8854
8855 (defun gnus-mime-security-pipe-part ()
8856 "Pipe the security part under point to a process."
8857 (interactive)
8858 (gnus-mime-security-run-function 'mm-pipe-part))
8859
8860 (gnus-ems-redefine)
8861
8862 (provide 'gnus-art)
8863
8864 (run-hooks 'gnus-art-load-hook)
8865
8866 ;;; gnus-art.el ends here