Merge from gnus--rel--5.10
[bpt/emacs.git] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31 (require 'cl)
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map))
34
35 (require 'gnus)
36 (require 'gnus-sum)
37 (require 'gnus-spec)
38 (require 'gnus-int)
39 (require 'gnus-win)
40 (require 'mm-bodies)
41 (require 'mail-parse)
42 (require 'mm-decode)
43 (require 'mm-view)
44 (require 'wid-edit)
45 (require 'mm-uu)
46 (require 'message)
47
48 (autoload 'gnus-msg-mail "gnus-msg" nil t)
49 (autoload 'gnus-button-mailto "gnus-msg")
50 (autoload 'gnus-button-reply "gnus-msg" nil t)
51 (autoload 'parse-time-string "parse-time" nil nil)
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 "*All headers that start with this regexp will be hidden.
158 This variable can also be a list of regexps of headers to be ignored.
159 If `gnus-visible-headers' is non-nil, this variable will be ignored."
160 :type '(choice :custom-show nil
161 regexp
162 (repeat regexp))
163 :group 'gnus-article-hiding)
164
165 (defcustom gnus-visible-headers
166 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
167 "*All headers that do not match this regexp will be hidden.
168 This variable can also be a list of regexp of headers to remain visible.
169 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
170 :type '(repeat :value-to-internal (lambda (widget value)
171 (custom-split-regexp-maybe value))
172 :match (lambda (widget value)
173 (or (stringp value)
174 (widget-editable-list-match widget value)))
175 regexp)
176 :group 'gnus-article-hiding)
177
178 (defcustom gnus-sorted-header-list
179 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
180 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
181 "*This variable is a list of regular expressions.
182 If it is non-nil, headers that match the regular expressions will
183 be placed first in the article buffer in the sequence specified by
184 this list."
185 :type '(repeat regexp)
186 :group 'gnus-article-hiding)
187
188 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
189 "Headers that are only to be displayed if they have interesting data.
190 Possible values in this list are:
191
192 'empty Headers with no content.
193 'newsgroups Newsgroup identical to Gnus group.
194 'to-address To identical to To-address.
195 'to-list To identical to To-list.
196 'cc-list CC identical to To-list.
197 'followup-to Followup-to identical to Newsgroups.
198 'reply-to Reply-to identical to From.
199 'date Date less than four days old.
200 'long-to To and/or Cc longer than 1024 characters.
201 'many-to Multiple To and/or Cc."
202 :type '(set (const :tag "Headers with no content." empty)
203 (const :tag "Newsgroups identical to Gnus group." newsgroups)
204 (const :tag "To identical to To-address." to-address)
205 (const :tag "To identical to To-list." to-list)
206 (const :tag "CC identical to To-list." cc-list)
207 (const :tag "Followup-to identical to Newsgroups." followup-to)
208 (const :tag "Reply-to identical to From." reply-to)
209 (const :tag "Date less than four days old." date)
210 (const :tag "To and/or Cc longer than 1024 characters." long-to)
211 (const :tag "Multiple To and/or Cc headers." many-to))
212 :group 'gnus-article-hiding)
213
214 (defcustom gnus-article-skip-boring nil
215 "Skip over text that is not worth reading.
216 By default, if you set this t, then Gnus will display citations and
217 signatures, but will never scroll down to show you a page consisting
218 only of boring text. Boring text is controlled by
219 `gnus-article-boring-faces'."
220 :version "22.1"
221 :type 'boolean
222 :group 'gnus-article-hiding)
223
224 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
225 "Regexp matching signature separator.
226 This can also be a list of regexps. In that case, it will be checked
227 from head to tail looking for a separator. Searches will be done from
228 the end of the buffer."
229 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
230 (regexp)
231 (repeat :tag "List of regexp" regexp))
232 :group 'gnus-article-signature)
233
234 (defcustom gnus-signature-limit nil
235 "Provide a limit to what is considered a signature.
236 If it is a number, no signature may not be longer (in characters) than
237 that number. If it is a floating point number, no signature may be
238 longer (in lines) than that number. If it is a function, the function
239 will be called without any parameters, and if it returns nil, there is
240 no signature in the buffer. If it is a string, it will be used as a
241 regexp. If it matches, the text in question is not a signature."
242 :type '(choice (const nil)
243 (integer :value 200)
244 (number :value 4.0)
245 (function :value fun)
246 (regexp :value ".*"))
247 :group 'gnus-article-signature)
248
249 (defcustom gnus-hidden-properties '(invisible t intangible t)
250 "Property list to use for hiding text."
251 :type 'sexp
252 :group 'gnus-article-hiding)
253
254 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
255 ;; frames in a session.
256 (defcustom gnus-article-x-face-command
257 (if (featurep 'xemacs)
258 (if (or (gnus-image-type-available-p 'xface)
259 (gnus-image-type-available-p 'pbm))
260 'gnus-display-x-face-in-from
261 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
262 (if (gnus-image-type-available-p 'pbm)
263 'gnus-display-x-face-in-from
264 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
265 display -"))
266 "*String or function to be executed to display an X-Face header.
267 If it is a string, the command will be executed in a sub-shell
268 asynchronously. The compressed face will be piped to this command."
269 :type `(choice string
270 (function-item gnus-display-x-face-in-from)
271 function)
272 :version "21.1"
273 :group 'gnus-picon
274 :group 'gnus-article-washing)
275
276 (defcustom gnus-article-x-face-too-ugly nil
277 "Regexp matching posters whose face shouldn't be shown automatically."
278 :type '(choice regexp (const nil))
279 :group 'gnus-article-washing)
280
281 (defcustom gnus-article-banner-alist nil
282 "Banner alist for stripping.
283 For example,
284 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
285 :version "21.1"
286 :type '(repeat (cons symbol regexp))
287 :group 'gnus-article-washing)
288
289 (gnus-define-group-parameter
290 banner
291 :variable-document
292 "Alist of regexps (to match group names) and banner."
293 :variable-group gnus-article-washing
294 :parameter-type
295 '(choice :tag "Banner"
296 :value nil
297 (const :tag "Remove signature" signature)
298 (symbol :tag "Item in `gnus-article-banner-alist'" none)
299 regexp
300 (const :tag "None" nil))
301 :parameter-document
302 "If non-nil, specify how to remove `banners' from articles.
303
304 Symbol `signature' means to remove signatures delimited by
305 `gnus-signature-separator'. Any other symbol is used to look up a
306 regular expression to match the banner in `gnus-article-banner-alist'.
307 A string is used as a regular expression to match the banner
308 directly.")
309
310 (defcustom gnus-article-address-banner-alist nil
311 "Alist of mail addresses and banners.
312 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
313 to match a mail address in the From: header, BANNER is one of a symbol
314 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
315 If ADDRESS matches author's mail address, it will remove things like
316 advertisements. For example:
317
318 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
319 "
320 :type '(repeat
321 (cons
322 (regexp :tag "Address")
323 (choice :tag "Banner" :value nil
324 (const :tag "Remove signature" signature)
325 (symbol :tag "Item in `gnus-article-banner-alist'" none)
326 regexp
327 (const :tag "None" nil))))
328 :version "22.1"
329 :group 'gnus-article-washing)
330
331 (defmacro gnus-emphasis-custom-with-format (&rest body)
332 `(let ((format "\
333 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
334 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
335 ,@body))
336
337 (defun gnus-emphasis-custom-value-to-external (value)
338 (gnus-emphasis-custom-with-format
339 (if (consp (car value))
340 (list (format format (car (car value)) (cdr (car value)))
341 2
342 (if (nth 1 value) 2 3)
343 (nth 2 value))
344 value)))
345
346 (defun gnus-emphasis-custom-value-to-internal (value)
347 (gnus-emphasis-custom-with-format
348 (let ((regexp (concat "\\`"
349 (format (regexp-quote format)
350 "\\([^()]+\\)" "\\([^()]+\\)")
351 "\\'"))
352 pattern)
353 (if (string-match regexp (setq pattern (car value)))
354 (list (cons (match-string 1 pattern) (match-string 2 pattern))
355 (= (nth 2 value) 2)
356 (nth 3 value))
357 value))))
358
359 (defcustom gnus-emphasis-alist
360 (let ((types
361 '(("\\*" "\\*" bold nil 2)
362 ("_" "_" underline)
363 ("/" "/" italic)
364 ("_/" "/_" underline-italic)
365 ("_\\*" "\\*_" underline-bold)
366 ("\\*/" "/\\*" bold-italic)
367 ("_\\*/" "/\\*_" underline-bold-italic))))
368 (nconc
369 (gnus-emphasis-custom-with-format
370 (mapcar (lambda (spec)
371 (list (format format (car spec) (cadr spec))
372 (or (nth 3 spec) 2)
373 (or (nth 4 spec) 3)
374 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
375 types))
376 '(;; I've never seen anyone use this strikethru convention whereas I've
377 ;; several times seen it triggered by normal text. --Stef
378 ;; Miles suggests that this form is sometimes used but for italics,
379 ;; so maybe we should map it to `italic'.
380 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
381 ;; 2 3 gnus-emphasis-strikethru)
382 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
383 2 3 gnus-emphasis-underline))))
384 "*Alist that says how to fontify certain phrases.
385 Each item looks like this:
386
387 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
388
389 The first element is a regular expression to be matched. The second
390 is a number that says what regular expression grouping used to find
391 the entire emphasized word. The third is a number that says what
392 regexp grouping should be displayed and highlighted. The fourth
393 is the face used for highlighting."
394 :type
395 '(repeat
396 (menu-choice
397 :format "%[Customizing Style%]\n%v"
398 :indent 2
399 (group :tag "Default"
400 :value ("" 0 0 default)
401 :value-create
402 (lambda (widget)
403 (let ((value (widget-get
404 (cadr (widget-get (widget-get widget :parent)
405 :args))
406 :value)))
407 (if (not (eq (nth 2 value) 'default))
408 (widget-put
409 widget
410 :value
411 (gnus-emphasis-custom-value-to-external value))))
412 (widget-group-value-create widget))
413 regexp
414 (integer :format "Match group: %v")
415 (integer :format "Emphasize group: %v")
416 face)
417 (group :tag "Simple"
418 :value (("_" . "_") nil default)
419 (cons :format "%v"
420 (regexp :format "Start regexp: %v")
421 (regexp :format "End regexp: %v"))
422 (boolean :format "Show start and end patterns: %[%v%]\n"
423 :on " On " :off " Off ")
424 face)))
425 :get (lambda (symbol)
426 (mapcar 'gnus-emphasis-custom-value-to-internal
427 (default-value symbol)))
428 :set (lambda (symbol value)
429 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
430 value)))
431 :group 'gnus-article-emphasis)
432
433 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
434 "A regexp to describe whitespace which should not be emphasized.
435 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
436 The former avoids underlining of leading and trailing whitespace,
437 and the latter avoids underlining any whitespace at all."
438 :version "21.1"
439 :group 'gnus-article-emphasis
440 :type 'regexp)
441
442 (defface gnus-emphasis-bold '((t (:bold t)))
443 "Face used for displaying strong emphasized text (*word*)."
444 :group 'gnus-article-emphasis)
445
446 (defface gnus-emphasis-italic '((t (:italic t)))
447 "Face used for displaying italic emphasized text (/word/)."
448 :group 'gnus-article-emphasis)
449
450 (defface gnus-emphasis-underline '((t (:underline t)))
451 "Face used for displaying underlined emphasized text (_word_)."
452 :group 'gnus-article-emphasis)
453
454 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
455 "Face used for displaying underlined bold emphasized text (_*word*_)."
456 :group 'gnus-article-emphasis)
457
458 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
459 "Face used for displaying underlined italic emphasized text (_/word/_)."
460 :group 'gnus-article-emphasis)
461
462 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
463 "Face used for displaying bold italic emphasized text (/*word*/)."
464 :group 'gnus-article-emphasis)
465
466 (defface gnus-emphasis-underline-bold-italic
467 '((t (:bold t :italic t :underline t)))
468 "Face used for displaying underlined bold italic emphasized text.
469 Example: (_/*word*/_)."
470 :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
473 '((t (:strikethru t)))
474 '((t (:strike-through t))))
475 "Face used for displaying strike-through text (-word-)."
476 :group 'gnus-article-emphasis)
477
478 (defface gnus-emphasis-highlight-words
479 '((t (:background "black" :foreground "yellow")))
480 "Face used for displaying highlighted words."
481 :group 'gnus-article-emphasis)
482
483 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
484 "Format for display of Date headers in article bodies.
485 See `format-time-string' for the possible values.
486
487 The variable can also be function, which should return a complete Date
488 header. The function is called with one argument, the time, which can
489 be fed to `format-time-string'."
490 :type '(choice string symbol)
491 :link '(custom-manual "(gnus)Article Date")
492 :group 'gnus-article-washing)
493
494 (defcustom gnus-save-all-headers t
495 "*If non-nil, don't remove any headers before saving.
496 This will be overridden by the `:headers' property that the symbol of
497 the saver function, which is specified by `gnus-default-article-saver',
498 might have."
499 :group 'gnus-article-saving
500 :type 'boolean)
501
502 (defcustom gnus-prompt-before-saving 'always
503 "*This variable says how much prompting is to be done when saving articles.
504 If it is nil, no prompting will be done, and the articles will be
505 saved to the default files. If this variable is `always', each and
506 every article that is saved will be preceded by a prompt, even when
507 saving large batches of articles. If this variable is neither nil not
508 `always', there the user will be prompted once for a file name for
509 each invocation of the saving commands."
510 :group 'gnus-article-saving
511 :type '(choice (item always)
512 (item :tag "never" nil)
513 (sexp :tag "once" :format "%t\n" :value t)))
514
515 (defcustom gnus-saved-headers gnus-visible-headers
516 "Headers to keep if `gnus-save-all-headers' is nil.
517 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
518 If that variable is nil, however, all headers that match this regexp
519 will be kept while the rest will be deleted before saving. This and
520 `gnus-save-all-headers' will be overridden by the `:headers' property
521 that the symbol of the saver function, which is specified by
522 `gnus-default-article-saver', might have."
523 :group 'gnus-article-saving
524 :type 'regexp)
525
526 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
527 "A function to save articles in your favourite format.
528 The function will be called by way of the `gnus-summary-save-article'
529 command, and friends such as `gnus-summary-save-article-rmail'.
530
531 Gnus provides the following functions:
532
533 * gnus-summary-save-in-rmail (Rmail format)
534 * gnus-summary-save-in-mail (Unix mail format)
535 * gnus-summary-save-in-folder (MH folder)
536 * gnus-summary-save-in-file (article format)
537 * gnus-summary-save-body-in-file (article body)
538 * gnus-summary-save-in-vm (use VM's folder format)
539 * gnus-summary-write-to-file (article format -- overwrite)
540 * gnus-summary-write-body-to-file (article body -- overwrite)
541
542 The symbol of each function may have the following properties:
543
544 * :decode
545 The value non-nil means save decoded articles. This is meaningful
546 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
547 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
548
549 * :function
550 The value specifies an alternative function which appends, not
551 overwrites, articles to a file. This implies that when saving many
552 articles at a time, `gnus-prompt-before-saving' is bound to t and all
553 articles are saved in a single file. This is meaningful only with
554 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
555
556 * :headers
557 The value specifies the symbol of a variable of which the value
558 specifies headers to be saved. If it is omitted,
559 `gnus-save-all-headers' and `gnus-saved-headers' control what
560 headers should be saved."
561 :group 'gnus-article-saving
562 :type '(radio (function-item gnus-summary-save-in-rmail)
563 (function-item gnus-summary-save-in-mail)
564 (function-item gnus-summary-save-in-folder)
565 (function-item gnus-summary-save-in-file)
566 (function-item gnus-summary-save-body-in-file)
567 (function-item gnus-summary-save-in-vm)
568 (function-item gnus-summary-write-to-file)
569 (function-item gnus-summary-write-body-to-file)
570 (function)))
571
572 (defcustom gnus-article-save-coding-system
573 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
574 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
575 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
576 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
577 "Coding system used to save decoded articles to a file.
578
579 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
580 which can safely encode any characters in text. This is used by the
581 commands including:
582
583 * gnus-summary-save-article-file
584 * gnus-summary-save-article-body-file
585 * gnus-summary-write-article-file
586 * gnus-summary-write-article-body-file
587
588 and the functions to which you may set `gnus-default-article-saver':
589
590 * gnus-summary-save-in-file
591 * gnus-summary-save-body-in-file
592 * gnus-summary-write-to-file
593 * gnus-summary-write-body-to-file
594
595 Those commands and functions save just text displayed in the article
596 buffer to a file if the value of this variable is non-nil. Note that
597 buttonized MIME parts will be lost in a saved file in that case.
598 Otherwise, raw articles will be saved."
599 :group 'gnus-article-saving
600 :type `(choice
601 :format "%{%t%}:\n %[Value Menu%] %v"
602 (const :tag "Save raw articles" nil)
603 ,@(delq nil
604 (mapcar
605 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
606 '((const :tag "UTF-8" utf-8)
607 (const :tag "iso-2022-7bit" iso-2022-7bit)
608 (const :tag "Emacs internal" emacs-mule)
609 (const :tag "escape-quoted" escape-quoted))))
610 (symbol :tag "Coding system")))
611
612 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
613 "A function generating a file name to save articles in Rmail format.
614 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
615 :group 'gnus-article-saving
616 :type 'function)
617
618 (defcustom gnus-mail-save-name 'gnus-plain-save-name
619 "A function generating a file name to save articles in Unix mail format.
620 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
621 :group 'gnus-article-saving
622 :type 'function)
623
624 (defcustom gnus-folder-save-name 'gnus-folder-save-name
625 "A function generating a file name to save articles in MH folder.
626 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
627 :group 'gnus-article-saving
628 :type 'function)
629
630 (defcustom gnus-file-save-name 'gnus-numeric-save-name
631 "A function generating a file name to save articles in article format.
632 The function is called with NEWSGROUP, HEADERS, and optional
633 LAST-FILE."
634 :group 'gnus-article-saving
635 :type 'function)
636
637 (defcustom gnus-split-methods
638 '((gnus-article-archive-name)
639 (gnus-article-nndoc-name))
640 "*Variable used to suggest where articles are to be saved.
641 For instance, if you would like to save articles related to Gnus in
642 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
643 you could set this variable to something like:
644
645 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
646 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
647
648 This variable is an alist where the where the key is the match and the
649 value is a list of possible files to save in if the match is non-nil.
650
651 If the match is a string, it is used as a regexp match on the
652 article. If the match is a symbol, that symbol will be funcalled
653 from the buffer of the article to be saved with the newsgroup as the
654 parameter. If it is a list, it will be evaled in the same buffer.
655
656 If this form or function returns a string, this string will be used as
657 a possible file name; and if it returns a non-nil list, that list will
658 be used as possible file names."
659 :group 'gnus-article-saving
660 :type '(repeat (choice (list :value (fun) function)
661 (cons :value ("" "") regexp (repeat string))
662 (sexp :value nil))))
663
664 (defcustom gnus-page-delimiter "^\^L"
665 "*Regexp describing what to use as article page delimiters.
666 The default value is \"^\^L\", which is a form linefeed at the
667 beginning of a line."
668 :type 'regexp
669 :group 'gnus-article-various)
670
671 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
672 "*The format specification for the article mode line.
673 See `gnus-summary-mode-line-format' for a closer description.
674
675 The following additional specs are available:
676
677 %w The article washing status.
678 %m The number of MIME parts in the article."
679 :type 'string
680 :group 'gnus-article-various)
681
682 (defcustom gnus-article-mode-hook nil
683 "*A hook for Gnus article mode."
684 :type 'hook
685 :group 'gnus-article-various)
686
687 (when (featurep 'xemacs)
688 ;; Extracted from gnus-xmas-define in order to preserve user settings
689 (when (fboundp 'turn-off-scroll-in-place)
690 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
691 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
692 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
693
694 (defcustom gnus-article-menu-hook nil
695 "*Hook run after the creation of the article mode menu."
696 :type 'hook
697 :group 'gnus-article-various)
698
699 (defcustom gnus-article-prepare-hook nil
700 "*A hook called after an article has been prepared in the article buffer."
701 :type 'hook
702 :group 'gnus-article-various)
703
704 (make-obsolete-variable 'gnus-article-hide-pgp-hook
705 "This variable is obsolete in Gnus 5.10.")
706
707 (defcustom gnus-article-button-face 'bold
708 "Face used for highlighting buttons in the article buffer.
709
710 An article button is a piece of text that you can activate by pressing
711 `RET' or `mouse-2' above it."
712 :type 'face
713 :group 'gnus-article-buttons)
714
715 (defcustom gnus-article-mouse-face 'highlight
716 "Face used for mouse highlighting in the article buffer.
717
718 Article buttons will be displayed in this face when the cursor is
719 above them."
720 :type 'face
721 :group 'gnus-article-buttons)
722
723 (defcustom gnus-signature-face 'gnus-signature
724 "Face used for highlighting a signature in the article buffer.
725 Obsolete; use the face `gnus-signature' for customizations instead."
726 :type 'face
727 :group 'gnus-article-highlight
728 :group 'gnus-article-signature)
729
730 (defface gnus-signature
731 '((t
732 (:italic t)))
733 "Face used for highlighting a signature in the article buffer."
734 :group 'gnus-article-highlight
735 :group 'gnus-article-signature)
736 ;; backward-compatibility alias
737 (put 'gnus-signature-face 'face-alias 'gnus-signature)
738
739 (defface gnus-header-from
740 '((((class color)
741 (background dark))
742 (:foreground "spring green"))
743 (((class color)
744 (background light))
745 (:foreground "red3"))
746 (t
747 (:italic t)))
748 "Face used for displaying from headers."
749 :group 'gnus-article-headers
750 :group 'gnus-article-highlight)
751 ;; backward-compatibility alias
752 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
753
754 (defface gnus-header-subject
755 '((((class color)
756 (background dark))
757 (:foreground "SeaGreen3"))
758 (((class color)
759 (background light))
760 (:foreground "red4"))
761 (t
762 (:bold t :italic t)))
763 "Face used for displaying subject headers."
764 :group 'gnus-article-headers
765 :group 'gnus-article-highlight)
766 ;; backward-compatibility alias
767 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
768
769 (defface gnus-header-newsgroups
770 '((((class color)
771 (background dark))
772 (:foreground "yellow" :italic t))
773 (((class color)
774 (background light))
775 (:foreground "MidnightBlue" :italic t))
776 (t
777 (:italic t)))
778 "Face used for displaying newsgroups headers.
779 In the default setup this face is only used for crossposted
780 articles."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
785
786 (defface gnus-header-name
787 '((((class color)
788 (background dark))
789 (:foreground "SeaGreen"))
790 (((class color)
791 (background light))
792 (:foreground "maroon"))
793 (t
794 (:bold t)))
795 "Face used for displaying header names."
796 :group 'gnus-article-headers
797 :group 'gnus-article-highlight)
798 ;; backward-compatibility alias
799 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
800
801 (defface gnus-header-content
802 '((((class color)
803 (background dark))
804 (:foreground "forest green" :italic t))
805 (((class color)
806 (background light))
807 (:foreground "indianred4" :italic t))
808 (t
809 (:italic t))) "Face used for displaying header content."
810 :group 'gnus-article-headers
811 :group 'gnus-article-highlight)
812 ;; backward-compatibility alias
813 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
814
815 (defcustom gnus-header-face-alist
816 '(("From" nil gnus-header-from)
817 ("Subject" nil gnus-header-subject)
818 ("Newsgroups:.*," nil gnus-header-newsgroups)
819 ("" gnus-header-name gnus-header-content))
820 "*Controls highlighting of article headers.
821
822 An alist of the form (HEADER NAME CONTENT).
823
824 HEADER is a regular expression which should match the name of a
825 header and NAME and CONTENT are either face names or nil.
826
827 The name of each header field will be displayed using the face
828 specified by the first element in the list where HEADER matches
829 the header name and NAME is non-nil. Similarly, the content will
830 be displayed by the first non-nil matching CONTENT face."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight
833 :type '(repeat (list (regexp :tag "Header")
834 (choice :tag "Name"
835 (item :tag "skip" nil)
836 (face :value default))
837 (choice :tag "Content"
838 (item :tag "skip" nil)
839 (face :value default)))))
840
841 (defcustom gnus-article-decode-hook
842 '(article-decode-charset article-decode-encoded-words
843 article-decode-group-name article-decode-idna-rhs)
844 "*Hook run to decode charsets in articles."
845 :group 'gnus-article-headers
846 :type 'hook)
847
848 (defcustom gnus-display-mime-function 'gnus-display-mime
849 "Function to display MIME articles."
850 :group 'gnus-article-mime
851 :type 'function)
852
853 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
854 "Function used to decode headers.")
855
856 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
857 "Function used to decode addresses.")
858
859 (defvar gnus-article-dumbquotes-map
860 '(("\200" "EUR")
861 ("\202" ",")
862 ("\203" "f")
863 ("\204" ",,")
864 ("\205" "...")
865 ("\213" "<")
866 ("\214" "OE")
867 ("\221" "`")
868 ("\222" "'")
869 ("\223" "``")
870 ("\224" "\"")
871 ("\225" "*")
872 ("\226" "-")
873 ("\227" "--")
874 ("\230" "~")
875 ("\231" "(TM)")
876 ("\233" ">")
877 ("\234" "oe")
878 ("\264" "'"))
879 "Table for MS-to-Latin1 translation.")
880
881 (defcustom gnus-ignored-mime-types nil
882 "List of MIME types that should be ignored by Gnus."
883 :version "21.1"
884 :group 'gnus-article-mime
885 :type '(repeat regexp))
886
887 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
888 "List of MIME types that should not be given buttons when rendered inline.
889 See also `gnus-buttonized-mime-types' which may override this variable.
890 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
891 :version "21.1"
892 :group 'gnus-article-mime
893 :type '(repeat regexp))
894
895 (defcustom gnus-buttonized-mime-types nil
896 "List of MIME types that should be given buttons when rendered inline.
897 If set, this variable overrides `gnus-unbuttonized-mime-types'.
898 To see e.g. security buttons you could set this to
899 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
900 this list to display radio buttons that allow you to choose one of two
901 media types those mails include. See also `mm-discouraged-alternatives'.
902 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
903 :version "22.1"
904 :group 'gnus-article-mime
905 :type '(repeat regexp))
906
907 (defcustom gnus-inhibit-mime-unbuttonizing nil
908 "If non-nil, all MIME parts get buttons.
909 When nil (the default value), then some MIME parts do not get buttons,
910 as described by the variables `gnus-buttonized-mime-types' and
911 `gnus-unbuttonized-mime-types'."
912 :version "22.1"
913 :group 'gnus-article-mime
914 :type 'boolean)
915
916 (defcustom gnus-body-boundary-delimiter "_"
917 "String used to delimit header and body.
918 This variable is used by `gnus-article-treat-body-boundary' which can
919 be controlled by `gnus-treat-body-boundary'."
920 :version "22.1"
921 :group 'gnus-article-various
922 :type '(choice (item :tag "None" :value nil)
923 string))
924
925 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
926 "/usr/share/picons")
927 "Defines the location of the faces database.
928 For information on obtaining this database of pretty pictures, please
929 see http://www.cs.indiana.edu/picons/ftp/index.html"
930 :version "22.1"
931 :type '(repeat directory)
932 :link '(url-link :tag "download"
933 "http://www.cs.indiana.edu/picons/ftp/index.html")
934 :link '(custom-manual "(gnus)Picons")
935 :group 'gnus-picon)
936
937 (defun gnus-picons-installed-p ()
938 "Say whether picons are installed on your machine."
939 (let ((installed nil))
940 (dolist (database gnus-picon-databases)
941 (when (file-exists-p database)
942 (setq installed t)))
943 installed))
944
945 (defcustom gnus-article-mime-part-function nil
946 "Function called with a MIME handle as the argument.
947 This is meant for people who want to do something automatic based
948 on parts -- for instance, adding Vcard info to a database."
949 :group 'gnus-article-mime
950 :type '(choice (const nil)
951 function))
952
953 (defcustom gnus-mime-multipart-functions nil
954 "An alist of MIME types to functions to display them."
955 :version "21.1"
956 :group 'gnus-article-mime
957 :type 'alist)
958
959 (defcustom gnus-article-date-lapsed-new-header nil
960 "Whether the X-Sent and Date headers can coexist.
961 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
962 either replace the old \"Date:\" header (if this variable is nil), or
963 be added below it (otherwise)."
964 :version "21.1"
965 :group 'gnus-article-headers
966 :type 'boolean)
967
968 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
969 "Function called with a MIME handle as the argument.
970 This is meant for people who want to view first matched part.
971 For `undisplayed-alternative' (default), the first undisplayed
972 part or alternative part is used. For `undisplayed', the first
973 undisplayed part is used. For a function, the first part which
974 the function return t is used. For nil, the first part is
975 used."
976 :version "21.1"
977 :group 'gnus-article-mime
978 :type '(choice
979 (item :tag "first" :value nil)
980 (item :tag "undisplayed" :value undisplayed)
981 (item :tag "undisplayed or alternative"
982 :value undisplayed-alternative)
983 (function)))
984
985 (defcustom gnus-mime-action-alist
986 '(("save to file" . gnus-mime-save-part)
987 ("save and strip" . gnus-mime-save-part-and-strip)
988 ("delete part" . gnus-mime-delete-part)
989 ("display as text" . gnus-mime-inline-part)
990 ("view the part" . gnus-mime-view-part)
991 ("pipe to command" . gnus-mime-pipe-part)
992 ("toggle display" . gnus-article-press-button)
993 ("toggle display" . gnus-article-view-part-as-charset)
994 ("view as type" . gnus-mime-view-part-as-type)
995 ("view internally" . gnus-mime-view-part-internally)
996 ("view externally" . gnus-mime-view-part-externally))
997 "An alist of actions that run on the MIME attachment."
998 :group 'gnus-article-mime
999 :type '(repeat (cons (string :tag "name")
1000 (function))))
1001
1002 ;;;
1003 ;;; The treatment variables
1004 ;;;
1005
1006 (defvar gnus-part-display-hook nil
1007 "Hook called on parts that are to receive treatment.")
1008
1009 (defvar gnus-article-treat-custom
1010 '(choice (const :tag "Off" nil)
1011 (const :tag "On" t)
1012 (const :tag "Header" head)
1013 (const :tag "Last" last)
1014 (integer :tag "Less")
1015 (repeat :tag "Groups" regexp)
1016 (sexp :tag "Predicate")))
1017
1018 (defvar gnus-article-treat-head-custom
1019 '(choice (const :tag "Off" nil)
1020 (const :tag "Header" head)))
1021
1022 (defvar gnus-article-treat-types '("text/plain")
1023 "Parts to treat.")
1024
1025 (defvar gnus-inhibit-treatment nil
1026 "Whether to inhibit treatment.")
1027
1028 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1029 "Highlight the signature.
1030 Valid values are nil, t, `head', `last', an integer or a predicate.
1031 See Info node `(gnus)Customizing Articles'."
1032 :group 'gnus-article-treat
1033 :link '(custom-manual "(gnus)Customizing Articles")
1034 :type gnus-article-treat-custom)
1035 (put 'gnus-treat-highlight-signature 'highlight t)
1036
1037 (defcustom gnus-treat-buttonize 100000
1038 "Add buttons.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See Info node `(gnus)Customizing Articles'."
1041 :group 'gnus-article-treat
1042 :link '(custom-manual "(gnus)Customizing Articles")
1043 :type gnus-article-treat-custom)
1044 (put 'gnus-treat-buttonize 'highlight t)
1045
1046 (defcustom gnus-treat-buttonize-head 'head
1047 "Add buttons to the head.
1048 Valid values are nil, t, `head', `last', an integer or a predicate.
1049 See Info node `(gnus)Customizing Articles' for details."
1050 :group 'gnus-article-treat
1051 :link '(custom-manual "(gnus)Customizing Articles")
1052 :type gnus-article-treat-head-custom)
1053 (put 'gnus-treat-buttonize-head 'highlight t)
1054
1055 (defcustom gnus-treat-emphasize
1056 (and (or window-system
1057 (featurep 'xemacs)
1058 (>= (string-to-number emacs-version) 21))
1059 50000)
1060 "Emphasize text.
1061 Valid values are nil, t, `head', `last', an integer or a predicate.
1062 See Info node `(gnus)Customizing Articles' for details."
1063 :group 'gnus-article-treat
1064 :link '(custom-manual "(gnus)Customizing Articles")
1065 :type gnus-article-treat-custom)
1066 (put 'gnus-treat-emphasize 'highlight t)
1067
1068 (defcustom gnus-treat-strip-cr nil
1069 "Remove carriage returns.
1070 Valid values are nil, t, `head', `last', an integer or a predicate.
1071 See Info node `(gnus)Customizing Articles' for details."
1072 :version "22.1"
1073 :group 'gnus-article-treat
1074 :link '(custom-manual "(gnus)Customizing Articles")
1075 :type gnus-article-treat-custom)
1076
1077 (defcustom gnus-treat-unsplit-urls nil
1078 "Remove newlines from within URLs.
1079 Valid values are nil, t, `head', `last', an integer or a predicate.
1080 See Info node `(gnus)Customizing Articles' for details."
1081 :version "22.1"
1082 :group 'gnus-article-treat
1083 :link '(custom-manual "(gnus)Customizing Articles")
1084 :type gnus-article-treat-custom)
1085
1086 (defcustom gnus-treat-leading-whitespace nil
1087 "Remove leading whitespace in headers.
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See Info node `(gnus)Customizing Articles' for details."
1090 :version "22.1"
1091 :group 'gnus-article-treat
1092 :link '(custom-manual "(gnus)Customizing Articles")
1093 :type gnus-article-treat-custom)
1094
1095 (defcustom gnus-treat-hide-headers 'head
1096 "Hide headers.
1097 Valid values are nil, t, `head', `last', an integer or a predicate.
1098 See Info node `(gnus)Customizing Articles' for details."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-head-custom)
1102
1103 (defcustom gnus-treat-hide-boring-headers nil
1104 "Hide boring headers.
1105 Valid values are nil, t, `head', `last', an integer or a predicate.
1106 See Info node `(gnus)Customizing Articles' for details."
1107 :group 'gnus-article-treat
1108 :link '(custom-manual "(gnus)Customizing Articles")
1109 :type gnus-article-treat-head-custom)
1110
1111 (defcustom gnus-treat-hide-signature nil
1112 "Hide the signature.
1113 Valid values are nil, t, `head', `last', an integer or a predicate.
1114 See Info node `(gnus)Customizing Articles' for details."
1115 :group 'gnus-article-treat
1116 :link '(custom-manual "(gnus)Customizing Articles")
1117 :type gnus-article-treat-custom)
1118
1119 (defcustom gnus-treat-fill-article nil
1120 "Fill the article.
1121 Valid values are nil, t, `head', `last', an integer or a predicate.
1122 See Info node `(gnus)Customizing Articles' for details."
1123 :group 'gnus-article-treat
1124 :link '(custom-manual "(gnus)Customizing Articles")
1125 :type gnus-article-treat-custom)
1126
1127 (defcustom gnus-treat-hide-citation nil
1128 "Hide cited text.
1129 Valid values are nil, t, `head', `last', an integer or a predicate.
1130 See Info node `(gnus)Customizing Articles' for details."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134
1135 (defcustom gnus-treat-hide-citation-maybe nil
1136 "Hide cited text.
1137 Valid values are nil, t, `head', `last', an integer or a predicate.
1138 See Info node `(gnus)Customizing Articles' for details."
1139 :group 'gnus-article-treat
1140 :link '(custom-manual "(gnus)Customizing Articles")
1141 :type gnus-article-treat-custom)
1142
1143 (defcustom gnus-treat-strip-list-identifiers 'head
1144 "Strip list identifiers from `gnus-list-identifiers`.
1145 Valid values are nil, t, `head', `last', an integer or a predicate.
1146 See Info node `(gnus)Customizing Articles' for details."
1147 :version "21.1"
1148 :group 'gnus-article-treat
1149 :link '(custom-manual "(gnus)Customizing Articles")
1150 :type gnus-article-treat-custom)
1151
1152 (make-obsolete-variable 'gnus-treat-strip-pgp
1153 "This option is obsolete in Gnus 5.10.")
1154
1155 (defcustom gnus-treat-strip-pem nil
1156 "Strip PEM signatures.
1157 Valid values are nil, t, `head', `last', an integer or a predicate.
1158 See Info node `(gnus)Customizing Articles' for details."
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-custom)
1162
1163 (defcustom gnus-treat-strip-banner t
1164 "Strip banners from articles.
1165 The banner to be stripped is specified in the `banner' group parameter.
1166 Valid values are nil, t, `head', `last', an integer or a predicate.
1167 See Info node `(gnus)Customizing Articles' for details."
1168 :group 'gnus-article-treat
1169 :link '(custom-manual "(gnus)Customizing Articles")
1170 :type gnus-article-treat-custom)
1171
1172 (defcustom gnus-treat-highlight-headers 'head
1173 "Highlight the headers.
1174 Valid values are nil, t, `head', `last', an integer or a predicate.
1175 See Info node `(gnus)Customizing Articles' for details."
1176 :group 'gnus-article-treat
1177 :link '(custom-manual "(gnus)Customizing Articles")
1178 :type gnus-article-treat-head-custom)
1179 (put 'gnus-treat-highlight-headers 'highlight t)
1180
1181 (defcustom gnus-treat-highlight-citation t
1182 "Highlight cited text.
1183 Valid values are nil, t, `head', `last', an integer or a predicate.
1184 See Info node `(gnus)Customizing Articles' for details."
1185 :group 'gnus-article-treat
1186 :link '(custom-manual "(gnus)Customizing Articles")
1187 :type gnus-article-treat-custom)
1188 (put 'gnus-treat-highlight-citation 'highlight t)
1189
1190 (defcustom gnus-treat-date-ut nil
1191 "Display the Date in UT (GMT).
1192 Valid values are nil, t, `head', `last', an integer or a predicate.
1193 See Info node `(gnus)Customizing Articles' for details."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-head-custom)
1197
1198 (defcustom gnus-treat-date-local nil
1199 "Display the Date in the local timezone.
1200 Valid values are nil, t, `head', `last', an integer or a predicate.
1201 See Info node `(gnus)Customizing Articles' for details."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-head-custom)
1205
1206 (defcustom gnus-treat-date-english nil
1207 "Display the Date in a format that can be read aloud in English.
1208 Valid values are nil, t, `head', `last', an integer or a predicate.
1209 See Info node `(gnus)Customizing Articles' for details."
1210 :version "22.1"
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1214
1215 (defcustom gnus-treat-date-lapsed nil
1216 "Display the Date header in a way that says how much time has elapsed.
1217 Valid values are nil, t, `head', `last', an integer or a predicate.
1218 See Info node `(gnus)Customizing Articles' for details."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-head-custom)
1222
1223 (defcustom gnus-treat-date-original nil
1224 "Display the date in the original timezone.
1225 Valid values are nil, t, `head', `last', an integer or a predicate.
1226 See Info node `(gnus)Customizing Articles' for details."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-head-custom)
1230
1231 (defcustom gnus-treat-date-iso8601 nil
1232 "Display the date in the ISO8601 format.
1233 Valid values are nil, t, `head', `last', an integer or a predicate.
1234 See Info node `(gnus)Customizing Articles' for details."
1235 :version "21.1"
1236 :group 'gnus-article-treat
1237 :link '(custom-manual "(gnus)Customizing Articles")
1238 :type gnus-article-treat-head-custom)
1239
1240 (defcustom gnus-treat-date-user-defined nil
1241 "Display the date in a user-defined format.
1242 The format is defined by the `gnus-article-time-format' variable.
1243 Valid values are nil, t, `head', `last', an integer or a predicate.
1244 See Info node `(gnus)Customizing Articles' for details."
1245 :group 'gnus-article-treat
1246 :link '(custom-manual "(gnus)Customizing Articles")
1247 :type gnus-article-treat-head-custom)
1248
1249 (defcustom gnus-treat-strip-headers-in-body t
1250 "Strip the X-No-Archive header line from the beginning of the body.
1251 Valid values are nil, t, `head', `last', an integer or a predicate.
1252 See Info node `(gnus)Customizing Articles' for details."
1253 :version "21.1"
1254 :group 'gnus-article-treat
1255 :link '(custom-manual "(gnus)Customizing Articles")
1256 :type gnus-article-treat-custom)
1257
1258 (defcustom gnus-treat-strip-trailing-blank-lines nil
1259 "Strip trailing blank lines.
1260 Valid values are nil, t, `head', `last', an integer or a predicate.
1261 See Info node `(gnus)Customizing Articles' for details.
1262
1263 When set to t, it also strips trailing blanks in all MIME parts.
1264 Consider to use `last' instead."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-custom)
1268
1269 (defcustom gnus-treat-strip-leading-blank-lines nil
1270 "Strip leading blank lines.
1271 Valid values are nil, t, `head', `last', an integer or a predicate.
1272 See Info node `(gnus)Customizing Articles' for details.
1273
1274 When set to t, it also strips trailing blanks in all MIME parts."
1275 :group 'gnus-article-treat
1276 :link '(custom-manual "(gnus)Customizing Articles")
1277 :type gnus-article-treat-custom)
1278
1279 (defcustom gnus-treat-strip-multiple-blank-lines nil
1280 "Strip multiple blank lines.
1281 Valid values are nil, t, `head', `last', an integer or a predicate.
1282 See Info node `(gnus)Customizing Articles' for details."
1283 :group 'gnus-article-treat
1284 :link '(custom-manual "(gnus)Customizing Articles")
1285 :type gnus-article-treat-custom)
1286
1287 (defcustom gnus-treat-unfold-headers 'head
1288 "Unfold folded header lines.
1289 Valid values are nil, t, `head', `last', an integer or a predicate.
1290 See Info node `(gnus)Customizing Articles' for details."
1291 :version "22.1"
1292 :group 'gnus-article-treat
1293 :link '(custom-manual "(gnus)Customizing Articles")
1294 :type gnus-article-treat-custom)
1295
1296 (defcustom gnus-treat-fold-headers nil
1297 "Fold headers.
1298 Valid values are nil, t, `head', `last', an integer or a predicate.
1299 See Info node `(gnus)Customizing Articles' for details."
1300 :version "22.1"
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-custom)
1304
1305 (defcustom gnus-treat-fold-newsgroups 'head
1306 "Fold the Newsgroups and Followup-To headers.
1307 Valid values are nil, t, `head', `last', an integer or a predicate.
1308 See Info node `(gnus)Customizing Articles' for details."
1309 :version "22.1"
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-custom)
1313
1314 (defcustom gnus-treat-overstrike t
1315 "Treat overstrike highlighting.
1316 Valid values are nil, t, `head', `last', an integer or a predicate.
1317 See Info node `(gnus)Customizing Articles' for details."
1318 :group 'gnus-article-treat
1319 :link '(custom-manual "(gnus)Customizing Articles")
1320 :type gnus-article-treat-custom)
1321 (put 'gnus-treat-overstrike 'highlight t)
1322
1323 (make-obsolete-variable 'gnus-treat-display-xface
1324 'gnus-treat-display-x-face)
1325
1326 (defcustom gnus-treat-display-x-face
1327 (and (not noninteractive)
1328 (or (and (fboundp 'image-type-available-p)
1329 (image-type-available-p 'xbm)
1330 (string-match "^0x" (shell-command-to-string "uncompface"))
1331 (executable-find "icontopbm"))
1332 (and (featurep 'xemacs)
1333 (featurep 'xface)))
1334 'head)
1335 "Display X-Face headers.
1336 Valid values are nil, t, `head', `last', an integer or a predicate.
1337 See Info node `(gnus)Customizing Articles' and Info node
1338 `(gnus)X-Face' for details."
1339 :group 'gnus-article-treat
1340 :version "21.1"
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :link '(custom-manual "(gnus)X-Face")
1343 :type gnus-article-treat-head-custom
1344 :set (lambda (symbol value)
1345 (set-default
1346 symbol
1347 (cond ((or (boundp symbol) (get symbol 'saved-value))
1348 value)
1349 ((boundp 'gnus-treat-display-xface)
1350 (message "\
1351 ** gnus-treat-display-xface is an obsolete variable;\
1352 use gnus-treat-display-x-face instead")
1353 (default-value 'gnus-treat-display-xface))
1354 ((get 'gnus-treat-display-xface 'saved-value)
1355 (message "\
1356 ** gnus-treat-display-xface is an obsolete variable;\
1357 use gnus-treat-display-x-face instead")
1358 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1359 (t
1360 value)))))
1361 (put 'gnus-treat-display-x-face 'highlight t)
1362
1363 (defcustom gnus-treat-display-face
1364 (and (not noninteractive)
1365 (or (and (fboundp 'image-type-available-p)
1366 (image-type-available-p 'png))
1367 (and (featurep 'xemacs)
1368 (featurep 'png)))
1369 'head)
1370 "Display Face headers.
1371 Valid values are nil, t, `head', `last', an integer or a predicate.
1372 See Info node `(gnus)Customizing Articles' and Info node
1373 `(gnus)X-Face' for details."
1374 :group 'gnus-article-treat
1375 :version "22.1"
1376 :link '(custom-manual "(gnus)Customizing Articles")
1377 :link '(custom-manual "(gnus)X-Face")
1378 :type gnus-article-treat-head-custom)
1379 (put 'gnus-treat-display-face 'highlight t)
1380
1381 (defcustom gnus-treat-display-smileys
1382 (if (or (and (featurep 'xemacs)
1383 (featurep 'xpm))
1384 (and (fboundp 'image-type-available-p)
1385 (image-type-available-p 'pbm)))
1386 t nil)
1387 "Display smileys.
1388 Valid values are nil, t, `head', `last', an integer or a predicate.
1389 See Info node `(gnus)Customizing Articles' and Info node
1390 `(gnus)Smileys' for details."
1391 :group 'gnus-article-treat
1392 :version "21.1"
1393 :link '(custom-manual "(gnus)Customizing Articles")
1394 :link '(custom-manual "(gnus)Smileys")
1395 :type gnus-article-treat-custom)
1396 (put 'gnus-treat-display-smileys 'highlight t)
1397
1398 (defcustom gnus-treat-from-picon
1399 (if (and (gnus-image-type-available-p 'xpm)
1400 (gnus-picons-installed-p))
1401 'head nil)
1402 "Display picons in the From header.
1403 Valid values are nil, t, `head', `last', an integer or a predicate.
1404 See Info node `(gnus)Customizing Articles' and Info node
1405 `(gnus)Picons' for details."
1406 :version "22.1"
1407 :group 'gnus-article-treat
1408 :group 'gnus-picon
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :link '(custom-manual "(gnus)Picons")
1411 :type gnus-article-treat-head-custom)
1412 (put 'gnus-treat-from-picon 'highlight t)
1413
1414 (defcustom gnus-treat-mail-picon
1415 (if (and (gnus-image-type-available-p 'xpm)
1416 (gnus-picons-installed-p))
1417 'head nil)
1418 "Display picons in To and Cc headers.
1419 Valid values are nil, t, `head', `last', an integer or a predicate.
1420 See Info node `(gnus)Customizing Articles' and Info node
1421 `(gnus)Picons' for details."
1422 :version "22.1"
1423 :group 'gnus-article-treat
1424 :group 'gnus-picon
1425 :link '(custom-manual "(gnus)Customizing Articles")
1426 :link '(custom-manual "(gnus)Picons")
1427 :type gnus-article-treat-head-custom)
1428 (put 'gnus-treat-mail-picon 'highlight t)
1429
1430 (defcustom gnus-treat-newsgroups-picon
1431 (if (and (gnus-image-type-available-p 'xpm)
1432 (gnus-picons-installed-p))
1433 'head nil)
1434 "Display picons in the Newsgroups and Followup-To headers.
1435 Valid values are nil, t, `head', `last', an integer or a predicate.
1436 See Info node `(gnus)Customizing Articles' and Info node
1437 `(gnus)Picons' for details."
1438 :version "22.1"
1439 :group 'gnus-article-treat
1440 :group 'gnus-picon
1441 :link '(custom-manual "(gnus)Customizing Articles")
1442 :link '(custom-manual "(gnus)Picons")
1443 :type gnus-article-treat-head-custom)
1444 (put 'gnus-treat-newsgroups-picon 'highlight t)
1445
1446 (defcustom gnus-treat-body-boundary
1447 (if (or gnus-treat-newsgroups-picon
1448 gnus-treat-mail-picon
1449 gnus-treat-from-picon)
1450 'head nil)
1451 "Draw a boundary at the end of the headers.
1452 Valid values are nil and `head'.
1453 See Info node `(gnus)Customizing Articles' for details."
1454 :version "22.1"
1455 :group 'gnus-article-treat
1456 :link '(custom-manual "(gnus)Customizing Articles")
1457 :type gnus-article-treat-head-custom)
1458
1459 (defcustom gnus-treat-capitalize-sentences nil
1460 "Capitalize sentence-starting words.
1461 Valid values are nil, t, `head', `last', an integer or a predicate.
1462 See Info node `(gnus)Customizing Articles' for details."
1463 :version "21.1"
1464 :group 'gnus-article-treat
1465 :link '(custom-manual "(gnus)Customizing Articles")
1466 :type gnus-article-treat-custom)
1467
1468 (defcustom gnus-treat-wash-html nil
1469 "Format as HTML.
1470 Valid values are nil, t, `head', `last', an integer or a predicate.
1471 See Info node `(gnus)Customizing Articles' for details."
1472 :version "22.1"
1473 :group 'gnus-article-treat
1474 :link '(custom-manual "(gnus)Customizing Articles")
1475 :type gnus-article-treat-custom)
1476
1477 (defcustom gnus-treat-fill-long-lines nil
1478 "Fill long lines.
1479 Valid values are nil, t, `head', `last', an integer or a predicate.
1480 See Info node `(gnus)Customizing Articles' for details."
1481 :group 'gnus-article-treat
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :type gnus-article-treat-custom)
1484
1485 (defcustom gnus-treat-play-sounds nil
1486 "Play sounds.
1487 Valid values are nil, t, `head', `last', an integer or a predicate.
1488 See Info node `(gnus)Customizing Articles' for details."
1489 :version "21.1"
1490 :group 'gnus-article-treat
1491 :link '(custom-manual "(gnus)Customizing Articles")
1492 :type gnus-article-treat-custom)
1493
1494 (defcustom gnus-treat-translate nil
1495 "Translate articles from one language to another.
1496 Valid values are nil, t, `head', `last', an integer or a predicate.
1497 See Info node `(gnus)Customizing Articles' for details."
1498 :version "21.1"
1499 :group 'gnus-article-treat
1500 :link '(custom-manual "(gnus)Customizing Articles")
1501 :type gnus-article-treat-custom)
1502
1503 (defcustom gnus-treat-x-pgp-sig nil
1504 "Verify X-PGP-Sig.
1505 To automatically treat X-PGP-Sig, set it to head.
1506 Valid values are nil, t, `head', `last', an integer or a predicate.
1507 See Info node `(gnus)Customizing Articles' for details."
1508 :version "22.1"
1509 :group 'gnus-article-treat
1510 :group 'mime-security
1511 :link '(custom-manual "(gnus)Customizing Articles")
1512 :type gnus-article-treat-custom)
1513
1514 (defvar gnus-article-encrypt-protocol-alist
1515 '(("PGP" . mml2015-self-encrypt)))
1516
1517 ;; Set to nil if more than one protocol added to
1518 ;; gnus-article-encrypt-protocol-alist.
1519 (defcustom gnus-article-encrypt-protocol "PGP"
1520 "The protocol used for encrypt articles.
1521 It is a string, such as \"PGP\". If nil, ask user."
1522 :version "22.1"
1523 :type 'string
1524 :group 'mime-security)
1525
1526 (defvar gnus-article-wash-function nil
1527 "Function used for converting HTML into text.")
1528
1529 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1530 (mm-coding-system-p 'utf-8)
1531 (executable-find idna-program))
1532 "Whether IDNA decoding of headers is used when viewing messages.
1533 This requires GNU Libidn, and by default only enabled if it is found."
1534 :version "22.1"
1535 :group 'gnus-article-headers
1536 :type 'boolean)
1537
1538 (defcustom gnus-article-over-scroll nil
1539 "If non-nil, allow scrolling the article buffer even when there no more text."
1540 :version "22.1"
1541 :group 'gnus-article
1542 :type 'boolean)
1543
1544 ;;; Internal variables
1545
1546 (defvar gnus-english-month-names
1547 '("January" "February" "March" "April" "May" "June" "July" "August"
1548 "September" "October" "November" "December"))
1549
1550 (defvar article-goto-body-goes-to-point-min-p nil)
1551 (defvar gnus-article-wash-types nil)
1552 (defvar gnus-article-emphasis-alist nil)
1553 (defvar gnus-article-image-alist nil)
1554
1555 (defvar gnus-article-mime-handle-alist-1 nil)
1556 (defvar gnus-treatment-function-alist
1557 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1558 (gnus-treat-strip-banner gnus-article-strip-banner)
1559 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1560 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1561 (gnus-treat-buttonize gnus-article-add-buttons)
1562 (gnus-treat-fill-article gnus-article-fill-cited-article)
1563 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1564 (gnus-treat-strip-cr gnus-article-remove-cr)
1565 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1566 (gnus-treat-date-ut gnus-article-date-ut)
1567 (gnus-treat-date-local gnus-article-date-local)
1568 (gnus-treat-date-english gnus-article-date-english)
1569 (gnus-treat-date-original gnus-article-date-original)
1570 (gnus-treat-date-user-defined gnus-article-date-user)
1571 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1572 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1573 (gnus-treat-display-x-face gnus-article-display-x-face)
1574 (gnus-treat-display-face gnus-article-display-face)
1575 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1576 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1577 (gnus-treat-hide-signature gnus-article-hide-signature)
1578 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1579 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1580 (gnus-treat-strip-pem gnus-article-hide-pem)
1581 (gnus-treat-from-picon gnus-treat-from-picon)
1582 (gnus-treat-mail-picon gnus-treat-mail-picon)
1583 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1584 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1585 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1586 (gnus-treat-strip-trailing-blank-lines
1587 gnus-article-remove-trailing-blank-lines)
1588 (gnus-treat-strip-leading-blank-lines
1589 gnus-article-strip-leading-blank-lines)
1590 (gnus-treat-strip-multiple-blank-lines
1591 gnus-article-strip-multiple-blank-lines)
1592 (gnus-treat-overstrike gnus-article-treat-overstrike)
1593 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1594 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1595 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1596 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1597 (gnus-treat-display-smileys gnus-treat-smiley)
1598 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1599 (gnus-treat-wash-html gnus-article-wash-html)
1600 (gnus-treat-emphasize gnus-article-emphasize)
1601 (gnus-treat-hide-citation gnus-article-hide-citation)
1602 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1603 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1604 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1605 (gnus-treat-play-sounds gnus-earcon-display)))
1606
1607 (defvar gnus-article-mime-handle-alist nil)
1608 (defvar article-lapsed-timer nil)
1609 (defvar gnus-article-current-summary nil)
1610
1611 (defvar gnus-article-mode-syntax-table
1612 (let ((table (copy-syntax-table text-mode-syntax-table)))
1613 ;; This causes the citation match run O(2^n).
1614 ;; (modify-syntax-entry ?- "w" table)
1615 (modify-syntax-entry ?> ")<" table)
1616 (modify-syntax-entry ?< "(>" table)
1617 ;; make M-. in article buffers work for `foo' strings
1618 (modify-syntax-entry ?' " " table)
1619 (modify-syntax-entry ?` " " table)
1620 table)
1621 "Syntax table used in article mode buffers.
1622 Initialized from `text-mode-syntax-table.")
1623
1624 (defvar gnus-save-article-buffer nil)
1625
1626 (defvar gnus-article-mode-line-format-alist
1627 (nconc '((?w (gnus-article-wash-status) ?s)
1628 (?m (gnus-article-mime-part-status) ?s))
1629 gnus-summary-mode-line-format-alist))
1630
1631 (defvar gnus-number-of-articles-to-be-saved nil)
1632
1633 (defvar gnus-inhibit-hiding nil)
1634
1635 (defvar gnus-article-edit-mode nil)
1636
1637 ;;; Macros for dealing with the article buffer.
1638
1639 (defmacro gnus-with-article-headers (&rest forms)
1640 `(save-excursion
1641 (set-buffer gnus-article-buffer)
1642 (save-restriction
1643 (let ((inhibit-read-only t)
1644 (inhibit-point-motion-hooks t)
1645 (case-fold-search t))
1646 (article-narrow-to-head)
1647 ,@forms))))
1648
1649 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1650 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1651
1652 (defmacro gnus-with-article-buffer (&rest forms)
1653 `(save-excursion
1654 (set-buffer gnus-article-buffer)
1655 (let ((inhibit-read-only t))
1656 ,@forms)))
1657
1658 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1659 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1660
1661 (defun gnus-article-goto-header (header)
1662 "Go to HEADER, which is a regular expression."
1663 (re-search-forward (concat "^\\(" header "\\):") nil t))
1664
1665 (defsubst gnus-article-hide-text (b e props)
1666 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1667 (gnus-add-text-properties-when 'article-type nil b e props)
1668 (when (memq 'intangible props)
1669 (put-text-property
1670 (max (1- b) (point-min))
1671 b 'intangible (cddr (memq 'intangible props)))))
1672
1673 (defsubst gnus-article-unhide-text (b e)
1674 "Remove hidden text properties from region between B and E."
1675 (remove-text-properties b e gnus-hidden-properties)
1676 (when (memq 'intangible gnus-hidden-properties)
1677 (put-text-property (max (1- b) (point-min))
1678 b 'intangible nil)))
1679
1680 (defun gnus-article-hide-text-type (b e type)
1681 "Hide text of TYPE between B and E."
1682 (gnus-add-wash-type type)
1683 (gnus-article-hide-text
1684 b e (cons 'article-type (cons type gnus-hidden-properties))))
1685
1686 (defun gnus-article-unhide-text-type (b e type)
1687 "Unhide text of TYPE between B and E."
1688 (gnus-delete-wash-type type)
1689 (remove-text-properties
1690 b e (cons 'article-type (cons type gnus-hidden-properties)))
1691 (when (memq 'intangible gnus-hidden-properties)
1692 (put-text-property (max (1- b) (point-min))
1693 b 'intangible nil)))
1694
1695 (defun gnus-article-hide-text-of-type (type)
1696 "Hide text of TYPE in the current buffer."
1697 (save-excursion
1698 (let ((b (point-min))
1699 (e (point-max)))
1700 (while (setq b (text-property-any b e 'article-type type))
1701 (add-text-properties b (incf b) gnus-hidden-properties)))))
1702
1703 (defun gnus-article-delete-text-of-type (type)
1704 "Delete text of TYPE in the current buffer."
1705 (save-excursion
1706 (let ((b (point-min)))
1707 (if (eq type 'multipart)
1708 ;; Remove MIME buttons associated with multipart/alternative parts.
1709 (progn
1710 (goto-char b)
1711 (while (if (get-text-property (point) 'gnus-part)
1712 (setq b (point))
1713 (when (setq b (next-single-property-change (point)
1714 'gnus-part))
1715 (goto-char b)
1716 t))
1717 (end-of-line)
1718 (skip-chars-forward "\n")
1719 (when (eq (get-text-property b 'article-type) 'multipart)
1720 (delete-region b (point)))))
1721 (while (setq b (text-property-any b (point-max) 'article-type type))
1722 (delete-region
1723 b (or (text-property-not-all b (point-max) 'article-type type)
1724 (point-max))))))))
1725
1726 (defun gnus-article-delete-invisible-text ()
1727 "Delete all invisible text in the current buffer."
1728 (save-excursion
1729 (let ((b (point-min)))
1730 (while (setq b (text-property-any b (point-max) 'invisible t))
1731 (delete-region
1732 b (or (text-property-not-all b (point-max) 'invisible t)
1733 (point-max)))))))
1734
1735 (defun gnus-article-text-type-exists-p (type)
1736 "Say whether any text of type TYPE exists in the buffer."
1737 (text-property-any (point-min) (point-max) 'article-type type))
1738
1739 (defsubst gnus-article-header-rank ()
1740 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1741 (let ((list gnus-sorted-header-list)
1742 (i 1))
1743 (while list
1744 (if (looking-at (car list))
1745 (setq list nil)
1746 (setq list (cdr list))
1747 (incf i)))
1748 i))
1749
1750 (defun article-hide-headers (&optional arg delete)
1751 "Hide unwanted headers and possibly sort them as well."
1752 (interactive)
1753 ;; This function might be inhibited.
1754 (unless gnus-inhibit-hiding
1755 (let ((inhibit-read-only nil)
1756 (case-fold-search t)
1757 (max (1+ (length gnus-sorted-header-list)))
1758 (inhibit-point-motion-hooks t)
1759 (cur (current-buffer))
1760 ignored visible beg)
1761 (save-excursion
1762 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1763 ;; group parameters, so we should go to the summary buffer.
1764 (when (prog1
1765 (condition-case nil
1766 (progn (set-buffer gnus-summary-buffer) t)
1767 (error nil))
1768 (setq ignored (when (not gnus-visible-headers)
1769 (cond ((stringp gnus-ignored-headers)
1770 gnus-ignored-headers)
1771 ((listp gnus-ignored-headers)
1772 (mapconcat 'identity
1773 gnus-ignored-headers
1774 "\\|"))))
1775 visible (cond ((stringp gnus-visible-headers)
1776 gnus-visible-headers)
1777 ((and gnus-visible-headers
1778 (listp gnus-visible-headers))
1779 (mapconcat 'identity
1780 gnus-visible-headers
1781 "\\|")))))
1782 (set-buffer cur))
1783 (save-restriction
1784 ;; First we narrow to just the headers.
1785 (article-narrow-to-head)
1786 ;; Hide any "From " lines at the beginning of (mail) articles.
1787 (while (looking-at "From ")
1788 (forward-line 1))
1789 (unless (bobp)
1790 (delete-region (point-min) (point)))
1791 ;; Then treat the rest of the header lines.
1792 ;; Then we use the two regular expressions
1793 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1794 ;; select which header lines is to remain visible in the
1795 ;; article buffer.
1796 (while (re-search-forward "^[^ \t:]*:" nil t)
1797 (beginning-of-line)
1798 ;; Mark the rank of the header.
1799 (put-text-property
1800 (point) (1+ (point)) 'message-rank
1801 (if (or (and visible (looking-at visible))
1802 (and ignored
1803 (not (looking-at ignored))))
1804 (gnus-article-header-rank)
1805 (+ 2 max)))
1806 (forward-line 1))
1807 (message-sort-headers-1)
1808 (when (setq beg (text-property-any
1809 (point-min) (point-max) 'message-rank (+ 2 max)))
1810 ;; We delete the unwanted headers.
1811 (gnus-add-wash-type 'headers)
1812 (add-text-properties (point-min) (+ 5 (point-min))
1813 '(article-type headers dummy-invisible t))
1814 (delete-region beg (point-max))))))))
1815
1816 (defun article-hide-boring-headers (&optional arg)
1817 "Toggle hiding of headers that aren't very interesting.
1818 If given a negative prefix, always show; if given a positive prefix,
1819 always hide."
1820 (interactive (gnus-article-hidden-arg))
1821 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1822 (not gnus-show-all-headers))
1823 (save-excursion
1824 (save-restriction
1825 (let ((inhibit-read-only t)
1826 (list gnus-boring-article-headers)
1827 (inhibit-point-motion-hooks t)
1828 elem)
1829 (article-narrow-to-head)
1830 (while list
1831 (setq elem (pop list))
1832 (goto-char (point-min))
1833 (cond
1834 ;; Hide empty headers.
1835 ((eq elem 'empty)
1836 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1837 (forward-line -1)
1838 (gnus-article-hide-text-type
1839 (gnus-point-at-bol)
1840 (progn
1841 (end-of-line)
1842 (if (re-search-forward "^[^ \t]" nil t)
1843 (match-beginning 0)
1844 (point-max)))
1845 'boring-headers)))
1846 ;; Hide boring Newsgroups header.
1847 ((eq elem 'newsgroups)
1848 (when (gnus-string-equal
1849 (gnus-fetch-field "newsgroups")
1850 (gnus-group-real-name
1851 (if (boundp 'gnus-newsgroup-name)
1852 gnus-newsgroup-name
1853 "")))
1854 (gnus-article-hide-header "newsgroups")))
1855 ((eq elem 'to-address)
1856 (let ((to (message-fetch-field "to"))
1857 (to-address
1858 (gnus-parameter-to-address
1859 (if (boundp 'gnus-newsgroup-name)
1860 gnus-newsgroup-name ""))))
1861 (when (and to to-address
1862 (ignore-errors
1863 (gnus-string-equal
1864 ;; only one address in To
1865 (nth 1 (mail-extract-address-components to))
1866 to-address)))
1867 (gnus-article-hide-header "to"))))
1868 ((eq elem 'to-list)
1869 (let ((to (message-fetch-field "to"))
1870 (to-list
1871 (gnus-parameter-to-list
1872 (if (boundp 'gnus-newsgroup-name)
1873 gnus-newsgroup-name ""))))
1874 (when (and to to-list
1875 (ignore-errors
1876 (gnus-string-equal
1877 ;; only one address in To
1878 (nth 1 (mail-extract-address-components to))
1879 to-list)))
1880 (gnus-article-hide-header "to"))))
1881 ((eq elem 'cc-list)
1882 (let ((cc (message-fetch-field "cc"))
1883 (to-list
1884 (gnus-parameter-to-list
1885 (if (boundp 'gnus-newsgroup-name)
1886 gnus-newsgroup-name ""))))
1887 (when (and cc to-list
1888 (ignore-errors
1889 (gnus-string-equal
1890 ;; only one address in CC
1891 (nth 1 (mail-extract-address-components cc))
1892 to-list)))
1893 (gnus-article-hide-header "cc"))))
1894 ((eq elem 'followup-to)
1895 (when (gnus-string-equal
1896 (message-fetch-field "followup-to")
1897 (message-fetch-field "newsgroups"))
1898 (gnus-article-hide-header "followup-to")))
1899 ((eq elem 'reply-to)
1900 (if (gnus-group-find-parameter
1901 gnus-newsgroup-name 'broken-reply-to)
1902 (gnus-article-hide-header "reply-to")
1903 (let ((from (message-fetch-field "from"))
1904 (reply-to (message-fetch-field "reply-to")))
1905 (when
1906 (and
1907 from reply-to
1908 (ignore-errors
1909 (equal
1910 (sort (mapcar
1911 (lambda (x) (downcase (cadr x)))
1912 (mail-extract-address-components from t))
1913 'string<)
1914 (sort (mapcar
1915 (lambda (x) (downcase (cadr x)))
1916 (mail-extract-address-components reply-to t))
1917 'string<))))
1918 (gnus-article-hide-header "reply-to")))))
1919 ((eq elem 'date)
1920 (let ((date (message-fetch-field "date")))
1921 (when (and date
1922 (< (days-between (current-time-string) date)
1923 4))
1924 (gnus-article-hide-header "date"))))
1925 ((eq elem 'long-to)
1926 (let ((to (message-fetch-field "to"))
1927 (cc (message-fetch-field "cc")))
1928 (when (> (length to) 1024)
1929 (gnus-article-hide-header "to"))
1930 (when (> (length cc) 1024)
1931 (gnus-article-hide-header "cc"))))
1932 ((eq elem 'many-to)
1933 (let ((to-count 0)
1934 (cc-count 0))
1935 (goto-char (point-min))
1936 (while (re-search-forward "^to:" nil t)
1937 (setq to-count (1+ to-count)))
1938 (when (> to-count 1)
1939 (while (> to-count 0)
1940 (goto-char (point-min))
1941 (save-restriction
1942 (re-search-forward "^to:" nil nil to-count)
1943 (forward-line -1)
1944 (narrow-to-region (point) (point-max))
1945 (gnus-article-hide-header "to"))
1946 (setq to-count (1- to-count))))
1947 (goto-char (point-min))
1948 (while (re-search-forward "^cc:" nil t)
1949 (setq cc-count (1+ cc-count)))
1950 (when (> cc-count 1)
1951 (while (> cc-count 0)
1952 (goto-char (point-min))
1953 (save-restriction
1954 (re-search-forward "^cc:" nil nil cc-count)
1955 (forward-line -1)
1956 (narrow-to-region (point) (point-max))
1957 (gnus-article-hide-header "cc"))
1958 (setq cc-count (1- cc-count)))))))))))))
1959
1960 (defun gnus-article-hide-header (header)
1961 (save-excursion
1962 (goto-char (point-min))
1963 (when (re-search-forward (concat "^" header ":") nil t)
1964 (gnus-article-hide-text-type
1965 (gnus-point-at-bol)
1966 (progn
1967 (end-of-line)
1968 (if (re-search-forward "^[^ \t]" nil t)
1969 (match-beginning 0)
1970 (point-max)))
1971 'boring-headers))))
1972
1973 (defvar gnus-article-normalized-header-length 40
1974 "Length of normalized headers.")
1975
1976 (defun article-normalize-headers ()
1977 "Make all header lines 40 characters long."
1978 (interactive)
1979 (let ((inhibit-read-only t)
1980 column)
1981 (save-excursion
1982 (save-restriction
1983 (article-narrow-to-head)
1984 (while (not (eobp))
1985 (cond
1986 ((< (setq column (- (gnus-point-at-eol) (point)))
1987 gnus-article-normalized-header-length)
1988 (end-of-line)
1989 (insert (make-string
1990 (- gnus-article-normalized-header-length column)
1991 ? )))
1992 ((> column gnus-article-normalized-header-length)
1993 (gnus-put-text-property
1994 (progn
1995 (forward-char gnus-article-normalized-header-length)
1996 (point))
1997 (gnus-point-at-eol)
1998 'invisible t))
1999 (t
2000 ;; Do nothing.
2001 ))
2002 (forward-line 1))))))
2003
2004 (defun article-treat-dumbquotes ()
2005 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2006 Note that this function guesses whether a character is a sm*rtq**t* or
2007 not, so it should only be used interactively.
2008
2009 Sm*rtq**t*s are M****s***'s unilateral extension to the
2010 iso-8859-1 character map in an attempt to provide more quoting
2011 characters. If you see something like \\222 or \\264 where
2012 you're expecting some kind of apostrophe or quotation mark, then
2013 try this wash."
2014 (interactive)
2015 (article-translate-strings gnus-article-dumbquotes-map))
2016
2017 (defun article-translate-characters (from to)
2018 "Translate all characters in the body of the article according to FROM and TO.
2019 FROM is a string of characters to translate from; to is a string of
2020 characters to translate to."
2021 (save-excursion
2022 (when (article-goto-body)
2023 (let ((inhibit-read-only t)
2024 (x (make-string 225 ?x))
2025 (i -1))
2026 (while (< (incf i) (length x))
2027 (aset x i i))
2028 (setq i 0)
2029 (while (< i (length from))
2030 (aset x (aref from i) (aref to i))
2031 (incf i))
2032 (translate-region (point) (point-max) x)))))
2033
2034 (defun article-translate-strings (map)
2035 "Translate all string in the body of the article according to MAP.
2036 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2037 (save-excursion
2038 (when (article-goto-body)
2039 (let ((inhibit-read-only t)
2040 elem)
2041 (while (setq elem (pop map))
2042 (save-excursion
2043 (while (search-forward (car elem) nil t)
2044 (replace-match (cadr elem)))))))))
2045
2046 (defun article-treat-overstrike ()
2047 "Translate overstrikes into bold text."
2048 (interactive)
2049 (save-excursion
2050 (when (article-goto-body)
2051 (let ((inhibit-read-only t))
2052 (while (search-forward "\b" nil t)
2053 (let ((next (char-after))
2054 (previous (char-after (- (point) 2))))
2055 ;; We do the boldification/underlining by hiding the
2056 ;; overstrikes and putting the proper text property
2057 ;; on the letters.
2058 (cond
2059 ((eq next previous)
2060 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2061 (put-text-property (point) (1+ (point)) 'face 'bold))
2062 ((eq next ?_)
2063 (gnus-article-hide-text-type
2064 (1- (point)) (1+ (point)) 'overstrike)
2065 (put-text-property
2066 (- (point) 2) (1- (point)) 'face 'underline))
2067 ((eq previous ?_)
2068 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2069 (put-text-property
2070 (point) (1+ (point)) 'face 'underline)))))))))
2071
2072 (defun gnus-article-treat-unfold-headers ()
2073 "Unfold folded message headers.
2074 Only the headers that fit into the current window width will be
2075 unfolded."
2076 (interactive)
2077 (gnus-with-article-headers
2078 (let (length)
2079 (while (not (eobp))
2080 (save-restriction
2081 (mail-header-narrow-to-field)
2082 (let ((header (buffer-string)))
2083 (with-temp-buffer
2084 (insert header)
2085 (goto-char (point-min))
2086 (while (re-search-forward "\n[\t ]" nil t)
2087 (replace-match " " t t)))
2088 (setq length (- (point-max) (point-min) 1)))
2089 (when (< length (window-width))
2090 (while (re-search-forward "\n[\t ]" nil t)
2091 (replace-match " " t t)))
2092 (goto-char (point-max)))))))
2093
2094 (defun gnus-article-treat-fold-headers ()
2095 "Fold message headers."
2096 (interactive)
2097 (gnus-with-article-headers
2098 (while (not (eobp))
2099 (save-restriction
2100 (mail-header-narrow-to-field)
2101 (mail-header-fold-field)
2102 (goto-char (point-max))))))
2103
2104 (defun gnus-treat-smiley ()
2105 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2106 (interactive)
2107 (gnus-with-article-buffer
2108 (if (memq 'smiley gnus-article-wash-types)
2109 (gnus-delete-images 'smiley)
2110 (article-goto-body)
2111 (let ((images (smiley-region (point) (point-max))))
2112 (when images
2113 (gnus-add-wash-type 'smiley)
2114 (dolist (image images)
2115 (gnus-add-image 'smiley image)))))))
2116
2117 (defun gnus-article-remove-images ()
2118 "Remove all images from the article buffer."
2119 (interactive)
2120 (gnus-with-article-buffer
2121 (dolist (elem gnus-article-image-alist)
2122 (gnus-delete-images (car elem)))))
2123
2124 (defun gnus-article-treat-fold-newsgroups ()
2125 "Unfold folded message headers.
2126 Only the headers that fit into the current window width will be
2127 unfolded."
2128 (interactive)
2129 (gnus-with-article-headers
2130 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2131 (save-restriction
2132 (mail-header-narrow-to-field)
2133 (while (re-search-forward ", *" nil t)
2134 (replace-match ", " t t))
2135 (mail-header-fold-field)
2136 (goto-char (point-max))))))
2137
2138 (defun gnus-article-treat-body-boundary ()
2139 "Place a boundary line at the end of the headers."
2140 (interactive)
2141 (when (and gnus-body-boundary-delimiter
2142 (> (length gnus-body-boundary-delimiter) 0))
2143 (gnus-with-article-headers
2144 (goto-char (point-max))
2145 (let ((start (point)))
2146 (insert "X-Boundary: ")
2147 (gnus-add-text-properties start (point) '(invisible t intangible t))
2148 (insert (let (str)
2149 (while (>= (1- (window-width)) (length str))
2150 (setq str (concat str gnus-body-boundary-delimiter)))
2151 (substring str 0 (1- (window-width))))
2152 "\n")
2153 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2154
2155 (defun article-fill-long-lines ()
2156 "Fill lines that are wider than the window width."
2157 (interactive)
2158 (save-excursion
2159 (let ((inhibit-read-only t)
2160 (width (window-width (get-buffer-window (current-buffer)))))
2161 (save-restriction
2162 (article-goto-body)
2163 (let ((adaptive-fill-mode nil)) ;Why? -sm
2164 (while (not (eobp))
2165 (end-of-line)
2166 (when (>= (current-column) (min fill-column width))
2167 (narrow-to-region (min (1+ (point)) (point-max))
2168 (gnus-point-at-bol))
2169 (let ((goback (point-marker)))
2170 (fill-paragraph nil)
2171 (goto-char (marker-position goback)))
2172 (widen))
2173 (forward-line 1)))))))
2174
2175 (defun article-capitalize-sentences ()
2176 "Capitalize the first word in each sentence."
2177 (interactive)
2178 (save-excursion
2179 (let ((inhibit-read-only t)
2180 (paragraph-start "^[\n\^L]"))
2181 (article-goto-body)
2182 (while (not (eobp))
2183 (capitalize-word 1)
2184 (forward-sentence)))))
2185
2186 (defun article-remove-cr ()
2187 "Remove trailing CRs and then translate remaining CRs into LFs."
2188 (interactive)
2189 (save-excursion
2190 (let ((inhibit-read-only t))
2191 (goto-char (point-min))
2192 (while (re-search-forward "\r+$" nil t)
2193 (replace-match "" t t))
2194 (goto-char (point-min))
2195 (while (search-forward "\r" nil t)
2196 (replace-match "\n" t t)))))
2197
2198 (defun article-remove-trailing-blank-lines ()
2199 "Remove all trailing blank lines from the article."
2200 (interactive)
2201 (save-excursion
2202 (let ((inhibit-read-only t))
2203 (goto-char (point-max))
2204 (delete-region
2205 (point)
2206 (progn
2207 (while (and (not (bobp))
2208 (looking-at "^[ \t]*$")
2209 (not (gnus-annotation-in-region-p
2210 (point) (gnus-point-at-eol))))
2211 (forward-line -1))
2212 (forward-line 1)
2213 (point))))))
2214
2215 (defun article-display-face ()
2216 "Display any Face headers in the header."
2217 (interactive)
2218 (let ((wash-face-p buffer-read-only))
2219 (gnus-with-article-headers
2220 ;; When displaying parts, this function can be called several times on
2221 ;; the same article, without any intended toggle semantic (as typing `W
2222 ;; D d' would have). So face deletion must occur only when we come from
2223 ;; an interactive command, that is when the *Article* buffer is
2224 ;; read-only.
2225 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2226 (gnus-delete-images 'face)
2227 (let (face faces from)
2228 (save-current-buffer
2229 (when (and wash-face-p
2230 (gnus-buffer-live-p gnus-original-article-buffer)
2231 (not (re-search-forward "^Face:[\t ]*" nil t)))
2232 (set-buffer gnus-original-article-buffer))
2233 (save-restriction
2234 (mail-narrow-to-head)
2235 (while (gnus-article-goto-header "Face")
2236 (push (mail-header-field-value) faces))))
2237 (when faces
2238 (goto-char (point-min))
2239 (let ((from (gnus-article-goto-header "from"))
2240 png image)
2241 (unless from
2242 (insert "From:")
2243 (setq from (point))
2244 (insert "[no `from' set]\n"))
2245 (while faces
2246 (when (setq png (gnus-convert-face-to-png (pop faces)))
2247 (setq image (gnus-create-image png 'png t))
2248 (goto-char from)
2249 (gnus-add-wash-type 'face)
2250 (gnus-add-image 'face image)
2251 (gnus-put-image image nil 'face))))))))))
2252
2253 (defun article-display-x-face (&optional force)
2254 "Look for an X-Face header and display it if present."
2255 (interactive (list 'force))
2256 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2257 (gnus-with-article-headers
2258 ;; Delete the old process, if any.
2259 (when (process-status "article-x-face")
2260 (delete-process "article-x-face"))
2261 ;; See the comment in `article-display-face'.
2262 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2263 ;; We have already displayed X-Faces, so we remove them
2264 ;; instead.
2265 (gnus-delete-images 'xface)
2266 ;; Display X-Faces.
2267 (let (x-faces from face)
2268 (save-current-buffer
2269 (when (and wash-face-p
2270 (gnus-buffer-live-p gnus-original-article-buffer)
2271 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2272 ;; If type `W f', use gnus-original-article-buffer,
2273 ;; otherwise use the current buffer because displaying
2274 ;; RFC822 parts calls this function too.
2275 (set-buffer gnus-original-article-buffer))
2276 (save-restriction
2277 (mail-narrow-to-head)
2278 (while (gnus-article-goto-header "X-Face")
2279 (push (mail-header-field-value) x-faces))
2280 (setq from (message-fetch-field "from"))))
2281 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2282 ;; single external face.
2283 (when (stringp gnus-article-x-face-command)
2284 (setq x-faces (list (car x-faces))))
2285 (when (and x-faces
2286 gnus-article-x-face-command
2287 (or force
2288 ;; Check whether this face is censored.
2289 (not gnus-article-x-face-too-ugly)
2290 (and from
2291 (not (string-match gnus-article-x-face-too-ugly
2292 from)))))
2293 (while (setq face (pop x-faces))
2294 ;; We display the face.
2295 (cond ((stringp gnus-article-x-face-command)
2296 ;; The command is a string, so we interpret the command
2297 ;; as a, well, command, and fork it off.
2298 (let ((process-connection-type nil))
2299 (gnus-set-process-query-on-exit-flag
2300 (start-process
2301 "article-x-face" nil shell-file-name
2302 shell-command-switch gnus-article-x-face-command)
2303 nil)
2304 (with-temp-buffer
2305 (insert face)
2306 (process-send-region "article-x-face"
2307 (point-min) (point-max)))
2308 (process-send-eof "article-x-face")))
2309 ((functionp gnus-article-x-face-command)
2310 ;; The command is a lisp function, so we call it.
2311 (funcall gnus-article-x-face-command face))
2312 (t
2313 (error "%s is not a function"
2314 gnus-article-x-face-command))))))))))
2315
2316 (defun article-decode-mime-words ()
2317 "Decode all MIME-encoded words in the article."
2318 (interactive)
2319 (save-excursion
2320 (set-buffer gnus-article-buffer)
2321 (let ((inhibit-point-motion-hooks t)
2322 (inhibit-read-only t)
2323 (mail-parse-charset gnus-newsgroup-charset)
2324 (mail-parse-ignored-charsets
2325 (save-excursion (set-buffer gnus-summary-buffer)
2326 gnus-newsgroup-ignored-charsets)))
2327 (mail-decode-encoded-word-region (point-min) (point-max)))))
2328
2329 (defun article-decode-charset (&optional prompt)
2330 "Decode charset-encoded text in the article.
2331 If PROMPT (the prefix), prompt for a coding system to use."
2332 (interactive "P")
2333 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2334 (inhibit-read-only t)
2335 (mail-parse-charset gnus-newsgroup-charset)
2336 (mail-parse-ignored-charsets
2337 (save-excursion (condition-case nil
2338 (set-buffer gnus-summary-buffer)
2339 (error))
2340 gnus-newsgroup-ignored-charsets))
2341 ct cte ctl charset format)
2342 (save-excursion
2343 (save-restriction
2344 (article-narrow-to-head)
2345 (setq ct (message-fetch-field "Content-Type" t)
2346 cte (message-fetch-field "Content-Transfer-Encoding" t)
2347 ctl (and ct (mail-header-parse-content-type ct))
2348 charset (cond
2349 (prompt
2350 (mm-read-coding-system "Charset to decode: "))
2351 (ctl
2352 (mail-content-type-get ctl 'charset)))
2353 format (and ctl (mail-content-type-get ctl 'format)))
2354 (when cte
2355 (setq cte (mail-header-strip cte)))
2356 (if (and ctl (not (string-match "/" (car ctl))))
2357 (setq ctl nil))
2358 (goto-char (point-max)))
2359 (forward-line 1)
2360 (save-restriction
2361 (narrow-to-region (point) (point-max))
2362 (when (and (eq mail-parse-charset 'gnus-decoded)
2363 (eq (mm-body-7-or-8) '8bit))
2364 ;; The text code could have been decoded.
2365 (setq charset mail-parse-charset))
2366 (when (and (or (not ctl)
2367 (equal (car ctl) "text/plain"))
2368 (not format)) ;; article with format will decode later.
2369 (mm-decode-body
2370 charset (and cte (intern (downcase
2371 (gnus-strip-whitespace cte))))
2372 (car ctl)))))))
2373
2374 (defun article-decode-encoded-words ()
2375 "Remove encoded-word encoding from headers."
2376 (let ((inhibit-point-motion-hooks t)
2377 (mail-parse-charset gnus-newsgroup-charset)
2378 (mail-parse-ignored-charsets
2379 (save-excursion (condition-case nil
2380 (set-buffer gnus-summary-buffer)
2381 (error))
2382 gnus-newsgroup-ignored-charsets))
2383 (inhibit-read-only t)
2384 start)
2385 (save-restriction
2386 (article-narrow-to-head)
2387 (while (not (eobp))
2388 (setq start (point))
2389 (if (prog1
2390 (looking-at "\
2391 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2392 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2393 (while (progn
2394 (forward-line)
2395 (if (eobp)
2396 nil
2397 (memq (char-after) '(?\t ? ))))))
2398 (funcall gnus-decode-address-function start (point))
2399 (funcall gnus-decode-header-function start (point)))))))
2400
2401 (defun article-decode-group-name ()
2402 "Decode group names in `Newsgroups:'."
2403 (let ((inhibit-point-motion-hooks t)
2404 (inhibit-read-only t)
2405 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2406 (when (and (or gnus-group-name-charset-method-alist
2407 gnus-group-name-charset-group-alist)
2408 (gnus-buffer-live-p gnus-original-article-buffer))
2409 (save-restriction
2410 (article-narrow-to-head)
2411 (with-current-buffer gnus-original-article-buffer
2412 (goto-char (point-min)))
2413 (while (re-search-forward
2414 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2415 (replace-match (save-match-data
2416 (gnus-decode-newsgroups
2417 ;; XXX how to use data in article buffer?
2418 (with-current-buffer gnus-original-article-buffer
2419 (re-search-forward
2420 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2421 nil t)
2422 (match-string 1))
2423 gnus-newsgroup-name method))
2424 t t nil 1))
2425 (goto-char (point-min))
2426 (with-current-buffer gnus-original-article-buffer
2427 (goto-char (point-min)))
2428 (while (re-search-forward
2429 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2430 (replace-match (save-match-data
2431 (gnus-decode-newsgroups
2432 ;; XXX how to use data in article buffer?
2433 (with-current-buffer gnus-original-article-buffer
2434 (re-search-forward
2435 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2436 nil t)
2437 (match-string 1))
2438 gnus-newsgroup-name method))
2439 t t nil 1))))))
2440
2441 (autoload 'idna-to-unicode "idna")
2442
2443 (defun article-decode-idna-rhs ()
2444 "Decode IDNA strings in RHS in various headers in current buffer.
2445 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2446 Mail-Reply-To: and Mail-Followup-To:."
2447 (when gnus-use-idna
2448 (save-restriction
2449 (let ((inhibit-point-motion-hooks t)
2450 (inhibit-read-only t))
2451 (article-narrow-to-head)
2452 (goto-char (point-min))
2453 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2454 (let (ace unicode)
2455 (when (save-match-data
2456 (and (setq ace (match-string 1))
2457 (save-excursion
2458 (and (re-search-backward "^[^ \t]" nil t)
2459 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2460 (setq unicode (idna-to-unicode ace))))
2461 (unless (string= ace unicode)
2462 (replace-match unicode nil nil nil 1)))))))))
2463
2464 (defun article-de-quoted-unreadable (&optional force read-charset)
2465 "Translate a quoted-printable-encoded article.
2466 If FORCE, decode the article whether it is marked as quoted-printable
2467 or not.
2468 If READ-CHARSET, ask for a coding system."
2469 (interactive (list 'force current-prefix-arg))
2470 (save-excursion
2471 (let ((inhibit-read-only t) type charset)
2472 (if (gnus-buffer-live-p gnus-original-article-buffer)
2473 (with-current-buffer gnus-original-article-buffer
2474 (setq type
2475 (gnus-fetch-field "content-transfer-encoding"))
2476 (let* ((ct (gnus-fetch-field "content-type"))
2477 (ctl (and ct (mail-header-parse-content-type ct))))
2478 (setq charset (and ctl
2479 (mail-content-type-get ctl 'charset)))
2480 (if (stringp charset)
2481 (setq charset (intern (downcase charset)))))))
2482 (if read-charset
2483 (setq charset (mm-read-coding-system "Charset: " charset)))
2484 (unless charset
2485 (setq charset gnus-newsgroup-charset))
2486 (when (or force
2487 (and type (let ((case-fold-search t))
2488 (string-match "quoted-printable" type))))
2489 (article-goto-body)
2490 (quoted-printable-decode-region
2491 (point) (point-max) (mm-charset-to-coding-system charset))))))
2492
2493 (defun article-de-base64-unreadable (&optional force read-charset)
2494 "Translate a base64 article.
2495 If FORCE, decode the article whether it is marked as base64 not.
2496 If READ-CHARSET, ask for a coding system."
2497 (interactive (list 'force current-prefix-arg))
2498 (save-excursion
2499 (let ((inhibit-read-only t) type charset)
2500 (if (gnus-buffer-live-p gnus-original-article-buffer)
2501 (with-current-buffer gnus-original-article-buffer
2502 (setq type
2503 (gnus-fetch-field "content-transfer-encoding"))
2504 (let* ((ct (gnus-fetch-field "content-type"))
2505 (ctl (and ct (mail-header-parse-content-type ct))))
2506 (setq charset (and ctl
2507 (mail-content-type-get ctl 'charset)))
2508 (if (stringp charset)
2509 (setq charset (intern (downcase charset)))))))
2510 (if read-charset
2511 (setq charset (mm-read-coding-system "Charset: " charset)))
2512 (unless charset
2513 (setq charset gnus-newsgroup-charset))
2514 (when (or force
2515 (and type (let ((case-fold-search t))
2516 (string-match "base64" type))))
2517 (article-goto-body)
2518 (save-restriction
2519 (narrow-to-region (point) (point-max))
2520 (base64-decode-region (point-min) (point-max))
2521 (mm-decode-coding-region
2522 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2523
2524 (eval-when-compile
2525 (require 'rfc1843))
2526
2527 (defun article-decode-HZ ()
2528 "Translate a HZ-encoded article."
2529 (interactive)
2530 (require 'rfc1843)
2531 (save-excursion
2532 (let ((inhibit-read-only t))
2533 (rfc1843-decode-region (point-min) (point-max)))))
2534
2535 (defun article-unsplit-urls ()
2536 "Remove the newlines that some other mailers insert into URLs."
2537 (interactive)
2538 (save-excursion
2539 (let ((inhibit-read-only t))
2540 (goto-char (point-min))
2541 (while (re-search-forward
2542 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2543 (replace-match "\\1\\3" t)))
2544 (when (interactive-p)
2545 (gnus-treat-article nil))))
2546
2547
2548 (defun article-wash-html (&optional read-charset)
2549 "Format an HTML article.
2550 If READ-CHARSET, ask for a coding system. If it is a number, the
2551 charset defined in `gnus-summary-show-article-charset-alist' is used."
2552 (interactive "P")
2553 (save-excursion
2554 (let ((inhibit-read-only t)
2555 charset)
2556 (if read-charset
2557 (if (or (and (numberp read-charset)
2558 (setq charset
2559 (cdr
2560 (assq read-charset
2561 gnus-summary-show-article-charset-alist))))
2562 (setq charset (mm-read-coding-system "Charset: ")))
2563 (let ((gnus-summary-show-article-charset-alist
2564 (list (cons 1 charset))))
2565 (with-current-buffer gnus-summary-buffer
2566 (gnus-summary-show-article 1)))
2567 (error "No charset is given"))
2568 (when (gnus-buffer-live-p gnus-original-article-buffer)
2569 (with-current-buffer gnus-original-article-buffer
2570 (let* ((ct (gnus-fetch-field "content-type"))
2571 (ctl (and ct (mail-header-parse-content-type ct))))
2572 (setq charset (and ctl
2573 (mail-content-type-get ctl 'charset)))
2574 (when (stringp charset)
2575 (setq charset (intern (downcase charset)))))))
2576 (unless charset
2577 (setq charset gnus-newsgroup-charset)))
2578 (article-goto-body)
2579 (save-window-excursion
2580 (save-restriction
2581 (narrow-to-region (point) (point-max))
2582 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2583 (entry (assq func mm-text-html-washer-alist)))
2584 (when entry
2585 (setq func (cdr entry)))
2586 (cond
2587 ((functionp func)
2588 (funcall func))
2589 (t
2590 (apply (car func) (cdr func))))))))))
2591
2592 (defun gnus-article-wash-html-with-w3 ()
2593 "Wash the current buffer with w3."
2594 (mm-setup-w3)
2595 (let ((w3-strict-width (window-width))
2596 (url-standalone-mode t)
2597 (url-gateway-unplugged t)
2598 (w3-honor-stylesheets nil))
2599 (condition-case ()
2600 (w3-region (point-min) (point-max))
2601 (error))))
2602
2603 (defun gnus-article-wash-html-with-w3m ()
2604 "Wash the current buffer with emacs-w3m."
2605 (mm-setup-w3m)
2606 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2607 w3m-force-redisplay)
2608 (w3m-region (point-min) (point-max)))
2609 (when (and mm-inline-text-html-with-w3m-keymap
2610 (boundp 'w3m-minor-mode-map)
2611 w3m-minor-mode-map)
2612 (add-text-properties
2613 (point-min) (point-max)
2614 (list 'keymap w3m-minor-mode-map
2615 ;; Put the mark meaning this part was rendered by emacs-w3m.
2616 'mm-inline-text-html-with-w3m t))))
2617
2618 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2619
2620 (defun gnus-article-wash-html-with-w3m-standalone ()
2621 "Wash the current buffer with w3m."
2622 (if (mm-w3m-standalone-supports-m17n-p)
2623 (progn
2624 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2625 ;; The default.
2626 (setq charset 'iso-8859-1))
2627 (let ((coding-system-for-write charset)
2628 (coding-system-for-read charset))
2629 (call-process-region
2630 (point-min) (point-max)
2631 "w3m" t t nil "-dump" "-T" "text/html"
2632 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2633 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2634
2635 (defun article-hide-list-identifiers ()
2636 "Remove list identifies from the Subject header.
2637 The `gnus-list-identifiers' variable specifies what to do."
2638 (interactive)
2639 (let ((inhibit-point-motion-hooks t)
2640 (regexp (if (consp gnus-list-identifiers)
2641 (mapconcat 'identity gnus-list-identifiers " *\\|")
2642 gnus-list-identifiers))
2643 (inhibit-read-only t))
2644 (when regexp
2645 (save-excursion
2646 (save-restriction
2647 (article-narrow-to-head)
2648 (goto-char (point-min))
2649 (while (re-search-forward
2650 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2651 nil t)
2652 (delete-region (match-beginning 2) (match-end 0))
2653 (beginning-of-line))
2654 (when (re-search-forward
2655 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2656 (delete-region (match-beginning 1) (match-end 1))))))))
2657
2658 (defun article-hide-pem (&optional arg)
2659 "Toggle hiding of any PEM headers and signatures in the current article.
2660 If given a negative prefix, always show; if given a positive prefix,
2661 always hide."
2662 (interactive (gnus-article-hidden-arg))
2663 (unless (gnus-article-check-hidden-text 'pem arg)
2664 (save-excursion
2665 (let ((inhibit-read-only t) end)
2666 (goto-char (point-min))
2667 ;; Hide the horrendously ugly "header".
2668 (when (and (search-forward
2669 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2670 nil t)
2671 (setq end (1+ (match-beginning 0))))
2672 (gnus-add-wash-type 'pem)
2673 (gnus-article-hide-text-type
2674 end
2675 (if (search-forward "\n\n" nil t)
2676 (match-end 0)
2677 (point-max))
2678 'pem)
2679 ;; Hide the trailer as well
2680 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2681 nil t)
2682 (gnus-article-hide-text-type
2683 (match-beginning 0) (match-end 0) 'pem)))))))
2684
2685 (defun article-strip-banner ()
2686 "Strip the banners specified by the `banner' group parameter and by
2687 `gnus-article-address-banner-alist'."
2688 (interactive)
2689 (save-excursion
2690 (save-restriction
2691 (let ((inhibit-point-motion-hooks t))
2692 (when (gnus-parameter-banner gnus-newsgroup-name)
2693 (article-really-strip-banner
2694 (gnus-parameter-banner gnus-newsgroup-name)))
2695 (when gnus-article-address-banner-alist
2696 ;; Note that the From header is decoded here, so it is
2697 ;; required that the *-extract-address-components function
2698 ;; supports non-ASCII text.
2699 (let ((from (save-restriction
2700 (widen)
2701 (article-narrow-to-head)
2702 (mail-fetch-field "from"))))
2703 (when (and from
2704 (setq from
2705 (cadr (funcall gnus-extract-address-components
2706 from))))
2707 (catch 'found
2708 (dolist (pair gnus-article-address-banner-alist)
2709 (when (string-match (car pair) from)
2710 (throw 'found
2711 (article-really-strip-banner (cdr pair)))))))))))))
2712
2713 (defun article-really-strip-banner (banner)
2714 "Strip the banner specified by the argument."
2715 (save-excursion
2716 (save-restriction
2717 (let ((inhibit-point-motion-hooks t)
2718 (gnus-signature-limit nil)
2719 (inhibit-read-only t))
2720 (article-goto-body)
2721 (cond
2722 ((eq banner 'signature)
2723 (when (gnus-article-narrow-to-signature)
2724 (widen)
2725 (forward-line -1)
2726 (delete-region (point) (point-max))))
2727 ((symbolp banner)
2728 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2729 (while (re-search-forward banner nil t)
2730 (delete-region (match-beginning 0) (match-end 0)))))
2731 ((stringp banner)
2732 (while (re-search-forward banner nil t)
2733 (delete-region (match-beginning 0) (match-end 0)))))))))
2734
2735 (defun article-babel ()
2736 "Translate article using an online translation service."
2737 (interactive)
2738 (require 'babel)
2739 (save-excursion
2740 (set-buffer gnus-article-buffer)
2741 (when (article-goto-body)
2742 (let* ((inhibit-read-only t)
2743 (start (point))
2744 (end (point-max))
2745 (orig (buffer-substring start end))
2746 (trans (babel-as-string orig)))
2747 (save-restriction
2748 (narrow-to-region start end)
2749 (delete-region start end)
2750 (insert trans))))))
2751
2752 (defun article-hide-signature (&optional arg)
2753 "Hide the signature in the current article.
2754 If given a negative prefix, always show; if given a positive prefix,
2755 always hide."
2756 (interactive (gnus-article-hidden-arg))
2757 (unless (gnus-article-check-hidden-text 'signature arg)
2758 (save-excursion
2759 (save-restriction
2760 (let ((inhibit-read-only t))
2761 (when (gnus-article-narrow-to-signature)
2762 (gnus-article-hide-text-type
2763 (point-min) (point-max) 'signature))))))
2764 (gnus-set-mode-line 'article))
2765
2766 (defun article-strip-headers-in-body ()
2767 "Strip offensive headers from bodies."
2768 (interactive)
2769 (save-excursion
2770 (article-goto-body)
2771 (let ((case-fold-search t))
2772 (when (looking-at "x-no-archive:")
2773 (gnus-delete-line)))))
2774
2775 (defun article-strip-leading-blank-lines ()
2776 "Remove all blank lines from the beginning of the article."
2777 (interactive)
2778 (save-excursion
2779 (let ((inhibit-point-motion-hooks t)
2780 (inhibit-read-only t))
2781 (when (article-goto-body)
2782 (while (and (not (eobp))
2783 (looking-at "[ \t]*$"))
2784 (gnus-delete-line))))))
2785
2786 (defun article-narrow-to-head ()
2787 "Narrow the buffer to the head of the message.
2788 Point is left at the beginning of the narrowed-to region."
2789 (narrow-to-region
2790 (goto-char (point-min))
2791 (if (search-forward "\n\n" nil 1)
2792 (1- (point))
2793 (point-max)))
2794 (goto-char (point-min)))
2795
2796 (defun article-goto-body ()
2797 "Place point at the start of the body."
2798 (goto-char (point-min))
2799 (cond
2800 ;; This variable is only bound when dealing with separate
2801 ;; MIME body parts.
2802 (article-goto-body-goes-to-point-min-p
2803 t)
2804 ((search-forward "\n\n" nil t)
2805 t)
2806 (t
2807 (goto-char (point-max))
2808 nil)))
2809
2810 (defun article-strip-multiple-blank-lines ()
2811 "Replace consecutive blank lines with one empty line."
2812 (interactive)
2813 (save-excursion
2814 (let ((inhibit-point-motion-hooks t)
2815 (inhibit-read-only t))
2816 ;; First make all blank lines empty.
2817 (article-goto-body)
2818 (while (re-search-forward "^[ \t]+$" nil t)
2819 (unless (gnus-annotation-in-region-p
2820 (match-beginning 0) (match-end 0))
2821 (replace-match "" nil t)))
2822 ;; Then replace multiple empty lines with a single empty line.
2823 (article-goto-body)
2824 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2825 (unless (gnus-annotation-in-region-p
2826 (match-beginning 0) (match-end 0))
2827 (delete-region (match-beginning 1) (match-end 1)))))))
2828
2829 (defun article-strip-leading-space ()
2830 "Remove all white space from the beginning of the lines in the article."
2831 (interactive)
2832 (save-excursion
2833 (let ((inhibit-point-motion-hooks t)
2834 (inhibit-read-only t))
2835 (article-goto-body)
2836 (while (re-search-forward "^[ \t]+" nil t)
2837 (replace-match "" t t)))))
2838
2839 (defun article-strip-trailing-space ()
2840 "Remove all white space from the end of the lines in the article."
2841 (interactive)
2842 (save-excursion
2843 (let ((inhibit-point-motion-hooks t)
2844 (inhibit-read-only t))
2845 (article-goto-body)
2846 (while (re-search-forward "[ \t]+$" nil t)
2847 (replace-match "" t t)))))
2848
2849 (defun article-strip-blank-lines ()
2850 "Strip leading, trailing and multiple blank lines."
2851 (interactive)
2852 (article-strip-leading-blank-lines)
2853 (article-remove-trailing-blank-lines)
2854 (article-strip-multiple-blank-lines))
2855
2856 (defun article-strip-all-blank-lines ()
2857 "Strip all blank lines."
2858 (interactive)
2859 (save-excursion
2860 (let ((inhibit-point-motion-hooks t)
2861 (inhibit-read-only t))
2862 (article-goto-body)
2863 (while (re-search-forward "^[ \t]*\n" nil t)
2864 (replace-match "" t t)))))
2865
2866 (defun gnus-article-narrow-to-signature ()
2867 "Narrow to the signature; return t if a signature is found, else nil."
2868 (let ((inhibit-point-motion-hooks t))
2869 (when (gnus-article-search-signature)
2870 (forward-line 1)
2871 ;; Check whether we have some limits to what we consider
2872 ;; to be a signature.
2873 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2874 (list gnus-signature-limit)))
2875 limit limited)
2876 (while (setq limit (pop limits))
2877 (if (or (and (integerp limit)
2878 (< (- (point-max) (point)) limit))
2879 (and (floatp limit)
2880 (< (count-lines (point) (point-max)) limit))
2881 (and (functionp limit)
2882 (funcall limit))
2883 (and (stringp limit)
2884 (not (re-search-forward limit nil t))))
2885 () ; This limit did not succeed.
2886 (setq limited t
2887 limits nil)))
2888 (unless limited
2889 (narrow-to-region (point) (point-max))
2890 t)))))
2891
2892 (defun gnus-article-search-signature ()
2893 "Search the current buffer for the signature separator.
2894 Put point at the beginning of the signature separator."
2895 (let ((cur (point)))
2896 (goto-char (point-max))
2897 (if (if (stringp gnus-signature-separator)
2898 (re-search-backward gnus-signature-separator nil t)
2899 (let ((seps gnus-signature-separator))
2900 (while (and seps
2901 (not (re-search-backward (car seps) nil t)))
2902 (pop seps))
2903 seps))
2904 t
2905 (goto-char cur)
2906 nil)))
2907
2908 (defun gnus-article-hidden-arg ()
2909 "Return the current prefix arg as a number, or 0 if no prefix."
2910 (list (if current-prefix-arg
2911 (prefix-numeric-value current-prefix-arg)
2912 0)))
2913
2914 (defun gnus-article-check-hidden-text (type arg)
2915 "Return nil if hiding is necessary.
2916 Arg can be nil or a number. nil and positive means hide, negative
2917 means show, 0 means toggle."
2918 (save-excursion
2919 (save-restriction
2920 (let ((hide (gnus-article-hidden-text-p type)))
2921 (cond
2922 ((or (null arg)
2923 (> arg 0))
2924 nil)
2925 ((< arg 0)
2926 (gnus-article-show-hidden-text type)
2927 t)
2928 (t
2929 (if (eq hide 'hidden)
2930 (progn
2931 (gnus-article-show-hidden-text type)
2932 t)
2933 nil)))))))
2934
2935 (defun gnus-article-hidden-text-p (type)
2936 "Say whether the current buffer contains hidden text of type TYPE."
2937 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2938 (while (and pos
2939 (not (get-text-property pos 'invisible))
2940 (not (get-text-property pos 'dummy-invisible)))
2941 (setq pos
2942 (text-property-any (1+ pos) (point-max) 'article-type type)))
2943 (if pos
2944 'hidden
2945 nil)))
2946
2947 (defun gnus-article-show-hidden-text (type &optional dummy)
2948 "Show all hidden text of type TYPE.
2949 Originally it is hide instead of DUMMY."
2950 (let ((inhibit-read-only t)
2951 (inhibit-point-motion-hooks t))
2952 (gnus-remove-text-properties-when
2953 'article-type type
2954 (point-min) (point-max)
2955 (cons 'article-type (cons type
2956 gnus-hidden-properties)))
2957 (gnus-delete-wash-type type)))
2958
2959 (defconst article-time-units
2960 `((year . ,(* 365.25 24 60 60))
2961 (week . ,(* 7 24 60 60))
2962 (day . ,(* 24 60 60))
2963 (hour . ,(* 60 60))
2964 (minute . 60)
2965 (second . 1))
2966 "Mapping from time units to seconds.")
2967
2968 (defun gnus-article-forward-header ()
2969 "Move point to the start of the next header.
2970 If the current header is a continuation header, this can be several
2971 lines forward."
2972 (let ((ended nil))
2973 (while (not ended)
2974 (forward-line 1)
2975 (if (looking-at "[ \t]+[^ \t]")
2976 (forward-line 1)
2977 (setq ended t)))))
2978
2979 (defun article-date-ut (&optional type highlight)
2980 "Convert DATE date to universal time in the current article.
2981 If TYPE is `local', convert to local time; if it is `lapsed', output
2982 how much time has lapsed since DATE. For `lapsed', the value of
2983 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2984 should replace the \"Date:\" one, or should be added below it."
2985 (interactive (list 'ut t))
2986 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2987 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2988 tdate-regexp)
2989 ((eq type 'lapsed)
2990 "^X-Sent:[ \t]")
2991 (article-lapsed-timer
2992 "^Date:[ \t]")
2993 (t
2994 tdate-regexp)))
2995 (case-fold-search t)
2996 (inhibit-read-only t)
2997 (inhibit-point-motion-hooks t)
2998 pos date bface eface)
2999 (save-excursion
3000 (save-restriction
3001 (widen)
3002 (goto-char (point-min))
3003 (while (or (setq date (get-text-property (setq pos (point))
3004 'original-date))
3005 (when (setq pos (next-single-property-change
3006 (point) 'original-date))
3007 (setq date (get-text-property pos 'original-date))
3008 t))
3009 (narrow-to-region pos (or (text-property-any pos (point-max)
3010 'original-date nil)
3011 (point-max)))
3012 (goto-char (point-min))
3013 (when (re-search-forward tdate-regexp nil t)
3014 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3015 eface (get-text-property (1- (gnus-point-at-eol)) 'face)))
3016 (goto-char (point-min))
3017 (setq pos nil)
3018 ;; Delete any old Date headers.
3019 (while (re-search-forward date-regexp nil t)
3020 (if pos
3021 (delete-region (gnus-point-at-bol)
3022 (progn
3023 (gnus-article-forward-header)
3024 (point)))
3025 (delete-region (gnus-point-at-bol)
3026 (progn
3027 (gnus-article-forward-header)
3028 (forward-char -1)
3029 (point)))
3030 (setq pos (point))))
3031 (when (and (not pos)
3032 (re-search-forward tdate-regexp nil t))
3033 (forward-line 1))
3034 (gnus-goto-char pos)
3035 (insert (article-make-date-line date (or type 'ut)))
3036 (unless pos
3037 (insert "\n")
3038 (forward-line -1))
3039 ;; Do highlighting.
3040 (beginning-of-line)
3041 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3042 (put-text-property (match-beginning 1) (1+ (match-end 1))
3043 'face bface)
3044 (put-text-property (match-beginning 2) (match-end 2)
3045 'face eface))
3046 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3047 (goto-char (point-max))
3048 (widen))))))
3049
3050 (defun article-make-date-line (date type)
3051 "Return a DATE line of TYPE."
3052 (unless (memq type '(local ut original user iso8601 lapsed english))
3053 (error "Unknown conversion type: %s" type))
3054 (condition-case ()
3055 (let ((time (date-to-time date)))
3056 (cond
3057 ;; Convert to the local timezone.
3058 ((eq type 'local)
3059 (let ((tz (car (current-time-zone time))))
3060 (format "Date: %s %s%02d%02d" (current-time-string time)
3061 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3062 (/ (% (abs tz) 3600) 60))))
3063 ;; Convert to Universal Time.
3064 ((eq type 'ut)
3065 (concat "Date: "
3066 (current-time-string
3067 (let* ((e (parse-time-string date))
3068 (tm (apply 'encode-time e))
3069 (ms (car tm))
3070 (ls (- (cadr tm) (car (current-time-zone time)))))
3071 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3072 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3073 (t (list ms ls)))))
3074 " UT"))
3075 ;; Get the original date from the article.
3076 ((eq type 'original)
3077 (concat "Date: " (if (string-match "\n+$" date)
3078 (substring date 0 (match-beginning 0))
3079 date)))
3080 ;; Let the user define the format.
3081 ((eq type 'user)
3082 (let ((format (or (condition-case nil
3083 (with-current-buffer gnus-summary-buffer
3084 gnus-article-time-format)
3085 (error nil))
3086 gnus-article-time-format)))
3087 (if (functionp format)
3088 (funcall format time)
3089 (concat "Date: " (format-time-string format time)))))
3090 ;; ISO 8601.
3091 ((eq type 'iso8601)
3092 (let ((tz (car (current-time-zone time))))
3093 (concat
3094 "Date: "
3095 (format-time-string "%Y%m%dT%H%M%S" time)
3096 (format "%s%02d%02d"
3097 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3098 (/ (% (abs tz) 3600) 60)))))
3099 ;; Do an X-Sent lapsed format.
3100 ((eq type 'lapsed)
3101 ;; If the date is seriously mangled, the timezone functions are
3102 ;; liable to bug out, so we ignore all errors.
3103 (let* ((now (current-time))
3104 (real-time (subtract-time now time))
3105 (real-sec (and real-time
3106 (+ (* (float (car real-time)) 65536)
3107 (cadr real-time))))
3108 (sec (and real-time (abs real-sec)))
3109 num prev)
3110 (cond
3111 ((null real-time)
3112 "X-Sent: Unknown")
3113 ((zerop sec)
3114 "X-Sent: Now")
3115 (t
3116 (concat
3117 "X-Sent: "
3118 ;; This is a bit convoluted, but basically we go
3119 ;; through the time units for years, weeks, etc,
3120 ;; and divide things to see whether that results
3121 ;; in positive answers.
3122 (mapconcat
3123 (lambda (unit)
3124 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3125 ;; The (remaining) seconds are too few to
3126 ;; be divided into this time unit.
3127 ""
3128 ;; It's big enough, so we output it.
3129 (setq sec (- sec (* num (cdr unit))))
3130 (prog1
3131 (concat (if prev ", " "") (int-to-string
3132 (floor num))
3133 " " (symbol-name (car unit))
3134 (if (> num 1) "s" ""))
3135 (setq prev t))))
3136 article-time-units "")
3137 ;; If dates are odd, then it might appear like the
3138 ;; article was sent in the future.
3139 (if (> real-sec 0)
3140 " ago"
3141 " in the future"))))))
3142 ;; Display the date in proper English
3143 ((eq type 'english)
3144 (let ((dtime (decode-time time)))
3145 (concat
3146 "Date: the "
3147 (number-to-string (nth 3 dtime))
3148 (let ((digit (% (nth 3 dtime) 10)))
3149 (cond
3150 ((memq (nth 3 dtime) '(11 12 13)) "th")
3151 ((= digit 1) "st")
3152 ((= digit 2) "nd")
3153 ((= digit 3) "rd")
3154 (t "th")))
3155 " of "
3156 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3157 " "
3158 (number-to-string (nth 5 dtime))
3159 " at "
3160 (format "%02d" (nth 2 dtime))
3161 ":"
3162 (format "%02d" (nth 1 dtime)))))))
3163 (error
3164 (format "Date: %s (from Gnus)" date))))
3165
3166 (defun article-date-local (&optional highlight)
3167 "Convert the current article date to the local timezone."
3168 (interactive (list t))
3169 (article-date-ut 'local highlight))
3170
3171 (defun article-date-english (&optional highlight)
3172 "Convert the current article date to something that is proper English."
3173 (interactive (list t))
3174 (article-date-ut 'english highlight))
3175
3176 (defun article-date-original (&optional highlight)
3177 "Convert the current article date to what it was originally.
3178 This is only useful if you have used some other date conversion
3179 function and want to see what the date was before converting."
3180 (interactive (list t))
3181 (article-date-ut 'original highlight))
3182
3183 (defun article-date-lapsed (&optional highlight)
3184 "Convert the current article date to time lapsed since it was sent."
3185 (interactive (list t))
3186 (article-date-ut 'lapsed highlight))
3187
3188 (defun article-update-date-lapsed ()
3189 "Function to be run from a timer to update the lapsed time line."
3190 (save-match-data
3191 (let (deactivate-mark)
3192 (save-excursion
3193 (ignore-errors
3194 (walk-windows
3195 (lambda (w)
3196 (set-buffer (window-buffer w))
3197 (when (eq major-mode 'gnus-article-mode)
3198 (let ((mark (point-marker)))
3199 (goto-char (point-min))
3200 (when (re-search-forward "^X-Sent:" nil t)
3201 (article-date-lapsed t))
3202 (goto-char (marker-position mark))
3203 (move-marker mark nil))))
3204 nil 'visible))))))
3205
3206 (defun gnus-start-date-timer (&optional n)
3207 "Start a timer to update the X-Sent header in the article buffers.
3208 The numerical prefix says how frequently (in seconds) the function
3209 is to run."
3210 (interactive "p")
3211 (unless n
3212 (setq n 1))
3213 (gnus-stop-date-timer)
3214 (setq article-lapsed-timer
3215 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
3216
3217 (defun gnus-stop-date-timer ()
3218 "Stop the X-Sent timer."
3219 (interactive)
3220 (when article-lapsed-timer
3221 (nnheader-cancel-timer article-lapsed-timer)
3222 (setq article-lapsed-timer nil)))
3223
3224 (defun article-date-user (&optional highlight)
3225 "Convert the current article date to the user-defined format.
3226 This format is defined by the `gnus-article-time-format' variable."
3227 (interactive (list t))
3228 (article-date-ut 'user highlight))
3229
3230 (defun article-date-iso8601 (&optional highlight)
3231 "Convert the current article date to ISO8601."
3232 (interactive (list t))
3233 (article-date-ut 'iso8601 highlight))
3234
3235 (defmacro gnus-article-save-original-date (&rest forms)
3236 "Save the original date as a text property and evaluate FORMS."
3237 `(let* ((case-fold-search t)
3238 (start (progn
3239 (goto-char (point-min))
3240 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3241 (not (bolp)))
3242 (match-end 0))))
3243 (date (when (and start
3244 (re-search-forward "[\t ]*\n\\([^\t ]\\|\\'\\)"
3245 nil t))
3246 (buffer-substring-no-properties start
3247 (match-beginning 0)))))
3248 (goto-char (point-max))
3249 (skip-chars-backward "\n")
3250 (put-text-property (point-min) (point) 'original-date date)
3251 ,@forms
3252 (goto-char (point-max))
3253 (skip-chars-backward "\n")
3254 (put-text-property (point-min) (point) 'original-date date)))
3255
3256 ;; (defun article-show-all ()
3257 ;; "Show all hidden text in the article buffer."
3258 ;; (interactive)
3259 ;; (save-excursion
3260 ;; (let ((inhibit-read-only t))
3261 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3262
3263 (defun article-remove-leading-whitespace ()
3264 "Remove excessive whitespace from all headers."
3265 (interactive)
3266 (save-excursion
3267 (save-restriction
3268 (let ((inhibit-read-only t))
3269 (article-narrow-to-head)
3270 (goto-char (point-min))
3271 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3272 (delete-region (match-beginning 1) (match-end 1)))))))
3273
3274 (defun article-emphasize (&optional arg)
3275 "Emphasize text according to `gnus-emphasis-alist'."
3276 (interactive (gnus-article-hidden-arg))
3277 (unless (gnus-article-check-hidden-text 'emphasis arg)
3278 (save-excursion
3279 (let ((alist (or
3280 (condition-case nil
3281 (with-current-buffer gnus-summary-buffer
3282 gnus-article-emphasis-alist)
3283 (error))
3284 gnus-emphasis-alist))
3285 (inhibit-read-only t)
3286 (props (append '(article-type emphasis)
3287 gnus-hidden-properties))
3288 regexp elem beg invisible visible face)
3289 (article-goto-body)
3290 (setq beg (point))
3291 (while (setq elem (pop alist))
3292 (goto-char beg)
3293 (setq regexp (car elem)
3294 invisible (nth 1 elem)
3295 visible (nth 2 elem)
3296 face (nth 3 elem))
3297 (while (re-search-forward regexp nil t)
3298 (when (and (match-beginning visible) (match-beginning invisible))
3299 (gnus-article-hide-text
3300 (match-beginning invisible) (match-end invisible) props)
3301 (gnus-article-unhide-text-type
3302 (match-beginning visible) (match-end visible) 'emphasis)
3303 (gnus-put-overlay-excluding-newlines
3304 (match-beginning visible) (match-end visible) 'face face)
3305 (gnus-add-wash-type 'emphasis)
3306 (goto-char (match-end invisible)))))))))
3307
3308 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3309 "Setup newsgroup emphasis alist."
3310 (unless gnus-article-emphasis-alist
3311 (let ((name (and gnus-newsgroup-name
3312 (gnus-group-real-name gnus-newsgroup-name))))
3313 (make-local-variable 'gnus-article-emphasis-alist)
3314 (setq gnus-article-emphasis-alist
3315 (nconc
3316 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3317 (while (setq elem (pop alist))
3318 (when (and name (string-match (car elem) name))
3319 (setq alist nil
3320 highlight (copy-sequence (cdr elem)))))
3321 highlight)
3322 (copy-sequence highlight-words)
3323 (if gnus-newsgroup-name
3324 (copy-sequence (gnus-group-find-parameter
3325 gnus-newsgroup-name 'highlight-words t)))
3326 gnus-emphasis-alist)))))
3327
3328 (eval-when-compile
3329 (defvar gnus-summary-article-menu)
3330 (defvar gnus-summary-post-menu))
3331
3332 ;;; Saving functions.
3333
3334 (defun gnus-article-save (save-buffer file &optional num)
3335 "Save the currently selected article."
3336 (when (or (get gnus-default-article-saver :headers)
3337 (not gnus-save-all-headers))
3338 ;; Remove headers according to `gnus-saved-headers' or the value
3339 ;; of the `:headers' property that the saver function might have.
3340 (let ((gnus-visible-headers
3341 (or (symbol-value (get gnus-default-article-saver :headers))
3342 gnus-saved-headers gnus-visible-headers))
3343 (gnus-article-buffer save-buffer))
3344 (save-excursion
3345 (set-buffer save-buffer)
3346 (article-hide-headers 1 t))))
3347 (save-window-excursion
3348 (if (not gnus-default-article-saver)
3349 (error "No default saver is defined")
3350 ;; !!! Magic! The saving functions all save
3351 ;; `gnus-save-article-buffer' (or so they think), but we
3352 ;; bind that variable to our save-buffer.
3353 (set-buffer gnus-article-buffer)
3354 (let* ((gnus-save-article-buffer save-buffer)
3355 (filename
3356 (cond
3357 ((not gnus-prompt-before-saving) 'default)
3358 ((eq gnus-prompt-before-saving 'always) nil)
3359 (t file)))
3360 (gnus-number-of-articles-to-be-saved
3361 (when (eq gnus-prompt-before-saving t)
3362 num))) ; Magic
3363 (set-buffer gnus-article-current-summary)
3364 (funcall gnus-default-article-saver filename)))))
3365
3366 (defun gnus-read-save-file-name (prompt &optional filename
3367 function group headers variable
3368 dir-var)
3369 (let ((default-name
3370 (funcall function group headers (symbol-value variable)))
3371 result)
3372 (setq result
3373 (expand-file-name
3374 (cond
3375 ((eq filename 'default)
3376 default-name)
3377 ((eq filename t)
3378 default-name)
3379 (filename filename)
3380 (t
3381 (when (symbol-value dir-var)
3382 (setq default-name (expand-file-name
3383 (file-name-nondirectory default-name)
3384 (symbol-value dir-var))))
3385 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3386 (prompt
3387 (format prompt
3388 (if (and gnus-number-of-articles-to-be-saved
3389 (> gnus-number-of-articles-to-be-saved 1))
3390 (format "these %d articles"
3391 gnus-number-of-articles-to-be-saved)
3392 "this article")))
3393 (file
3394 ;; Let the split methods have their say.
3395 (cond
3396 ;; No split name was found.
3397 ((null split-name)
3398 (read-file-name
3399 (concat prompt " (default "
3400 (file-name-nondirectory default-name) "): ")
3401 (file-name-directory default-name)
3402 default-name))
3403 ;; A single group name is returned.
3404 ((stringp split-name)
3405 (setq default-name
3406 (funcall function split-name headers
3407 (symbol-value variable)))
3408 (read-file-name
3409 (concat prompt " (default "
3410 (file-name-nondirectory default-name) "): ")
3411 (file-name-directory default-name)
3412 default-name))
3413 ;; A single split name was found
3414 ((= 1 (length split-name))
3415 (let* ((name (expand-file-name
3416 (car split-name)
3417 gnus-article-save-directory))
3418 (dir (cond ((file-directory-p name)
3419 (file-name-as-directory name))
3420 ((file-exists-p name) name)
3421 (t gnus-article-save-directory))))
3422 (read-file-name
3423 (concat prompt " (default " name "): ")
3424 dir name)))
3425 ;; A list of splits was found.
3426 (t
3427 (setq split-name (nreverse split-name))
3428 (let (result)
3429 (let ((file-name-history
3430 (nconc split-name file-name-history)))
3431 (setq result
3432 (expand-file-name
3433 (read-file-name
3434 (concat prompt " (`M-p' for defaults): ")
3435 gnus-article-save-directory
3436 (car split-name))
3437 gnus-article-save-directory)))
3438 (car (push result file-name-history)))))))
3439 ;; Create the directory.
3440 (gnus-make-directory (file-name-directory file))
3441 ;; If we have read a directory, we append the default file name.
3442 (when (file-directory-p file)
3443 (setq file (expand-file-name (file-name-nondirectory
3444 default-name)
3445 (file-name-as-directory file))))
3446 ;; Possibly translate some characters.
3447 (nnheader-translate-file-chars file))))))
3448 (gnus-make-directory (file-name-directory result))
3449 (when variable
3450 (set variable result))
3451 (when dir-var
3452 (set dir-var (file-name-directory result)))
3453 result))
3454
3455 (defun gnus-article-archive-name (group)
3456 "Return the first instance of an \"Archive-name\" in the current buffer."
3457 (let ((case-fold-search t))
3458 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3459 (nnheader-concat gnus-article-save-directory
3460 (match-string 1)))))
3461
3462 (defun gnus-article-nndoc-name (group)
3463 "If GROUP is an nndoc group, return the name of the parent group."
3464 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3465 (gnus-group-get-parameter group 'save-article-group)))
3466
3467 (defun gnus-summary-save-in-rmail (&optional filename)
3468 "Append this article to Rmail file.
3469 Optional argument FILENAME specifies file name.
3470 Directory to save to is default to `gnus-article-save-directory'."
3471 (setq filename (gnus-read-save-file-name
3472 "Save %s in rmail file" filename
3473 gnus-rmail-save-name gnus-newsgroup-name
3474 gnus-current-headers 'gnus-newsgroup-last-rmail))
3475 (gnus-eval-in-buffer-window gnus-save-article-buffer
3476 (save-excursion
3477 (save-restriction
3478 (widen)
3479 (gnus-output-to-rmail filename))))
3480 filename)
3481
3482 (defun gnus-summary-save-in-mail (&optional filename)
3483 "Append this article to Unix mail file.
3484 Optional argument FILENAME specifies file name.
3485 Directory to save to is default to `gnus-article-save-directory'."
3486 (setq filename (gnus-read-save-file-name
3487 "Save %s in Unix mail file" filename
3488 gnus-mail-save-name gnus-newsgroup-name
3489 gnus-current-headers 'gnus-newsgroup-last-mail))
3490 (gnus-eval-in-buffer-window gnus-save-article-buffer
3491 (save-excursion
3492 (save-restriction
3493 (widen)
3494 (if (and (file-readable-p filename)
3495 (file-regular-p filename)
3496 (mail-file-babyl-p filename))
3497 (rmail-output-to-rmail-file filename t)
3498 (gnus-output-to-mail filename)))))
3499 filename)
3500
3501 (put 'gnus-summary-save-in-file :decode t)
3502 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3503 (defun gnus-summary-save-in-file (&optional filename overwrite)
3504 "Append this article to file.
3505 Optional argument FILENAME specifies file name.
3506 Directory to save to is default to `gnus-article-save-directory'."
3507 (setq filename (gnus-read-save-file-name
3508 "Save %s in file" filename
3509 gnus-file-save-name gnus-newsgroup-name
3510 gnus-current-headers 'gnus-newsgroup-last-file))
3511 (gnus-eval-in-buffer-window gnus-save-article-buffer
3512 (save-excursion
3513 (save-restriction
3514 (widen)
3515 (when (and overwrite
3516 (file-exists-p filename))
3517 (delete-file filename))
3518 (gnus-output-to-file filename))))
3519 filename)
3520
3521 (put 'gnus-summary-write-to-file :decode t)
3522 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3523 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3524 (defun gnus-summary-write-to-file (&optional filename)
3525 "Write this article to a file, overwriting it if the file exists.
3526 Optional argument FILENAME specifies file name.
3527 The directory to save in defaults to `gnus-article-save-directory'."
3528 (setq filename (gnus-read-save-file-name
3529 "Save %s in file" filename
3530 gnus-file-save-name gnus-newsgroup-name
3531 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3532 (gnus-summary-save-in-file filename t))
3533
3534 (put 'gnus-summary-save-body-in-file :decode t)
3535 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3536 "Append this article body to a file.
3537 Optional argument FILENAME specifies file name.
3538 The directory to save in defaults to `gnus-article-save-directory'."
3539 (setq filename (gnus-read-save-file-name
3540 "Save %s body in file" filename
3541 gnus-file-save-name gnus-newsgroup-name
3542 gnus-current-headers 'gnus-newsgroup-last-file))
3543 (gnus-eval-in-buffer-window gnus-save-article-buffer
3544 (save-excursion
3545 (save-restriction
3546 (widen)
3547 (when (article-goto-body)
3548 (narrow-to-region (point) (point-max)))
3549 (when (and overwrite
3550 (file-exists-p filename))
3551 (delete-file filename))
3552 (gnus-output-to-file filename))))
3553 filename)
3554
3555 (put 'gnus-summary-write-body-to-file :decode t)
3556 (put 'gnus-summary-write-body-to-file
3557 :function 'gnus-summary-save-body-in-file)
3558 (defun gnus-summary-write-body-to-file (&optional filename)
3559 "Write this article body to a file, overwriting it if the file exists.
3560 Optional argument FILENAME specifies file name.
3561 The directory to save in defaults to `gnus-article-save-directory'."
3562 (setq filename (gnus-read-save-file-name
3563 "Save %s body in file" filename
3564 gnus-file-save-name gnus-newsgroup-name
3565 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3566 (gnus-summary-save-body-in-file filename t))
3567
3568 (defun gnus-summary-save-in-pipe (&optional command)
3569 "Pipe this article to subprocess."
3570 (setq command
3571 (cond ((and (eq command 'default)
3572 gnus-last-shell-command)
3573 gnus-last-shell-command)
3574 ((stringp command)
3575 command)
3576 (t (read-string
3577 (format
3578 "Shell command on %s: "
3579 (if (and gnus-number-of-articles-to-be-saved
3580 (> gnus-number-of-articles-to-be-saved 1))
3581 (format "these %d articles"
3582 gnus-number-of-articles-to-be-saved)
3583 "this article"))
3584 gnus-last-shell-command))))
3585 (when (string-equal command "")
3586 (if gnus-last-shell-command
3587 (setq command gnus-last-shell-command)
3588 (error "A command is required")))
3589 (gnus-eval-in-buffer-window gnus-article-buffer
3590 (save-restriction
3591 (widen)
3592 (shell-command-on-region (point-min) (point-max) command nil)))
3593 (setq gnus-last-shell-command command))
3594
3595 (defmacro gnus-read-string (prompt &optional initial-contents history
3596 default-value)
3597 "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3598 (if (and (featurep 'xemacs)
3599 (< emacs-minor-version 2))
3600 `(read-string ,prompt ,initial-contents ,history)
3601 `(read-string ,prompt ,initial-contents ,history ,default-value)))
3602
3603 (defun gnus-summary-pipe-to-muttprint (&optional command)
3604 "Pipe this article to muttprint."
3605 (setq command (gnus-read-string
3606 "Print using command: " gnus-summary-muttprint-program
3607 nil gnus-summary-muttprint-program))
3608 (gnus-summary-save-in-pipe command))
3609
3610 ;;; Article file names when saving.
3611
3612 (defun gnus-capitalize-newsgroup (newsgroup)
3613 "Capitalize NEWSGROUP name."
3614 (when (not (zerop (length newsgroup)))
3615 (concat (char-to-string (upcase (aref newsgroup 0)))
3616 (substring newsgroup 1))))
3617
3618 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3619 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3620 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3621 Otherwise, it is like ~/News/news/group/num."
3622 (let ((default
3623 (expand-file-name
3624 (concat (if (gnus-use-long-file-name 'not-save)
3625 (gnus-capitalize-newsgroup newsgroup)
3626 (gnus-newsgroup-directory-form newsgroup))
3627 "/" (int-to-string (mail-header-number headers)))
3628 gnus-article-save-directory)))
3629 (if (and last-file
3630 (string-equal (file-name-directory default)
3631 (file-name-directory last-file))
3632 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3633 default
3634 (or last-file default))))
3635
3636 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3637 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3638 If variable `gnus-use-long-file-name' is non-nil, it is
3639 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3640 (let ((default
3641 (expand-file-name
3642 (concat (if (gnus-use-long-file-name 'not-save)
3643 newsgroup
3644 (gnus-newsgroup-directory-form newsgroup))
3645 "/" (int-to-string (mail-header-number headers)))
3646 gnus-article-save-directory)))
3647 (if (and last-file
3648 (string-equal (file-name-directory default)
3649 (file-name-directory last-file))
3650 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3651 default
3652 (or last-file default))))
3653
3654 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3655 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3656 If variable `gnus-use-long-file-name' is non-nil, it is
3657 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3658 (or last-file
3659 (expand-file-name
3660 (if (gnus-use-long-file-name 'not-save)
3661 newsgroup
3662 (file-relative-name
3663 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3664 default-directory))
3665 gnus-article-save-directory)))
3666
3667 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3668 "Generate file name from sender."
3669 (let ((from (mail-header-from headers)))
3670 (expand-file-name
3671 (if (and from (string-match "\\([^ <]+\\)@" from))
3672 (match-string 1 from)
3673 "nobody")
3674 gnus-article-save-directory)))
3675
3676 (defun article-verify-x-pgp-sig ()
3677 "Verify X-PGP-Sig."
3678 (interactive)
3679 (if (gnus-buffer-live-p gnus-original-article-buffer)
3680 (let ((sig (with-current-buffer gnus-original-article-buffer
3681 (gnus-fetch-field "X-PGP-Sig")))
3682 items info headers)
3683 (when (and sig
3684 mml2015-use
3685 (mml2015-clear-verify-function))
3686 (with-temp-buffer
3687 (insert-buffer-substring gnus-original-article-buffer)
3688 (setq items (split-string sig))
3689 (message-narrow-to-head)
3690 (let ((inhibit-point-motion-hooks t)
3691 (case-fold-search t))
3692 ;; Don't verify multiple headers.
3693 (setq headers (mapconcat (lambda (header)
3694 (concat header ": "
3695 (mail-fetch-field header)
3696 "\n"))
3697 (split-string (nth 1 items) ",") "")))
3698 (delete-region (point-min) (point-max))
3699 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3700 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3701 (insert headers)
3702 (widen)
3703 (forward-line)
3704 (while (not (eobp))
3705 (if (looking-at "^-")
3706 (insert "- "))
3707 (forward-line))
3708 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3709 (insert "Version: " (car items) "\n\n")
3710 (insert (mapconcat 'identity (cddr items) "\n"))
3711 (insert "\n-----END PGP SIGNATURE-----\n")
3712 (let ((mm-security-handle (list (format "multipart/signed"))))
3713 (mml2015-clean-buffer)
3714 (let ((coding-system-for-write (or gnus-newsgroup-charset
3715 'iso-8859-1)))
3716 (funcall (mml2015-clear-verify-function)))
3717 (setq info
3718 (or (mm-handle-multipart-ctl-parameter
3719 mm-security-handle 'gnus-details)
3720 (mm-handle-multipart-ctl-parameter
3721 mm-security-handle 'gnus-info)))))
3722 (when info
3723 (let ((inhibit-read-only t) bface eface)
3724 (save-restriction
3725 (message-narrow-to-head)
3726 (goto-char (point-max))
3727 (forward-line -1)
3728 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3729 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3730 (message-remove-header "X-Gnus-PGP-Verify")
3731 (if (re-search-forward "^X-PGP-Sig:" nil t)
3732 (forward-line)
3733 (goto-char (point-max)))
3734 (narrow-to-region (point) (point))
3735 (insert "X-Gnus-PGP-Verify: " info "\n")
3736 (goto-char (point-min))
3737 (forward-line)
3738 (while (not (eobp))
3739 (if (not (looking-at "^[ \t]"))
3740 (insert " "))
3741 (forward-line))
3742 ;; Do highlighting.
3743 (goto-char (point-min))
3744 (when (looking-at "\\([^:]+\\): *")
3745 (put-text-property (match-beginning 1) (1+ (match-end 1))
3746 'face bface)
3747 (put-text-property (match-end 0) (point-max)
3748 'face eface)))))))))
3749
3750 (defun article-verify-cancel-lock ()
3751 "Verify Cancel-Lock header."
3752 (interactive)
3753 (if (gnus-buffer-live-p gnus-original-article-buffer)
3754 (canlock-verify gnus-original-article-buffer)))
3755
3756 (eval-and-compile
3757 (mapcar
3758 (lambda (func)
3759 (let (afunc gfunc)
3760 (if (consp func)
3761 (setq afunc (car func)
3762 gfunc (cdr func))
3763 (setq afunc func
3764 gfunc (intern (format "gnus-%s" func))))
3765 (defalias gfunc
3766 (when (fboundp afunc)
3767 `(lambda (&optional interactive &rest args)
3768 ,(documentation afunc t)
3769 (interactive (list t))
3770 (save-excursion
3771 (set-buffer gnus-article-buffer)
3772 (if interactive
3773 (call-interactively ',afunc)
3774 (apply ',afunc args))))))))
3775 '(article-hide-headers
3776 article-verify-x-pgp-sig
3777 article-verify-cancel-lock
3778 article-hide-boring-headers
3779 article-treat-overstrike
3780 article-fill-long-lines
3781 article-capitalize-sentences
3782 article-remove-cr
3783 article-remove-leading-whitespace
3784 article-display-x-face
3785 article-display-face
3786 article-de-quoted-unreadable
3787 article-de-base64-unreadable
3788 article-decode-HZ
3789 article-wash-html
3790 article-unsplit-urls
3791 article-hide-list-identifiers
3792 article-strip-banner
3793 article-babel
3794 article-hide-pem
3795 article-hide-signature
3796 article-strip-headers-in-body
3797 article-remove-trailing-blank-lines
3798 article-strip-leading-blank-lines
3799 article-strip-multiple-blank-lines
3800 article-strip-leading-space
3801 article-strip-trailing-space
3802 article-strip-blank-lines
3803 article-strip-all-blank-lines
3804 article-date-local
3805 article-date-english
3806 article-date-iso8601
3807 article-date-original
3808 article-date-ut
3809 article-decode-mime-words
3810 article-decode-charset
3811 article-decode-encoded-words
3812 article-date-user
3813 article-date-lapsed
3814 article-emphasize
3815 article-treat-dumbquotes
3816 article-normalize-headers
3817 ;; (article-show-all . gnus-article-show-all-headers)
3818 )))
3819 \f
3820 ;;;
3821 ;;; Gnus article mode
3822 ;;;
3823
3824 (put 'gnus-article-mode 'mode-class 'special)
3825
3826 (set-keymap-parent gnus-article-mode-map widget-keymap)
3827
3828 (gnus-define-keys gnus-article-mode-map
3829 " " gnus-article-goto-next-page
3830 "\177" gnus-article-goto-prev-page
3831 [delete] gnus-article-goto-prev-page
3832 [backspace] gnus-article-goto-prev-page
3833 "\C-c^" gnus-article-refer-article
3834 "h" gnus-article-show-summary
3835 "s" gnus-article-show-summary
3836 "\C-c\C-m" gnus-article-mail
3837 "?" gnus-article-describe-briefly
3838 "e" gnus-summary-edit-article
3839 "<" beginning-of-buffer
3840 ">" end-of-buffer
3841 "\C-c\C-i" gnus-info-find-node
3842 "\C-c\C-b" gnus-bug
3843 "R" gnus-article-reply-with-original
3844 "F" gnus-article-followup-with-original
3845 "\C-hk" gnus-article-describe-key
3846 "\C-hc" gnus-article-describe-key-briefly
3847
3848 "\C-d" gnus-article-read-summary-keys
3849 "\M-*" gnus-article-read-summary-keys
3850 "\M-#" gnus-article-read-summary-keys
3851 "\M-^" gnus-article-read-summary-keys
3852 "\M-g" gnus-article-read-summary-keys)
3853
3854 (substitute-key-definition
3855 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3856
3857 (defun gnus-article-make-menu-bar ()
3858 (unless (boundp 'gnus-article-commands-menu)
3859 (gnus-summary-make-menu-bar))
3860 (gnus-turn-off-edit-menu 'article)
3861 (unless (boundp 'gnus-article-article-menu)
3862 (easy-menu-define
3863 gnus-article-article-menu gnus-article-mode-map ""
3864 '("Article"
3865 ["Scroll forwards" gnus-article-goto-next-page t]
3866 ["Scroll backwards" gnus-article-goto-prev-page t]
3867 ["Show summary" gnus-article-show-summary t]
3868 ["Fetch Message-ID at point" gnus-article-refer-article t]
3869 ["Mail to address at point" gnus-article-mail t]
3870 ["Send a bug report" gnus-bug t]))
3871
3872 (easy-menu-define
3873 gnus-article-treatment-menu gnus-article-mode-map ""
3874 ;; Fixme: this should use :active (and maybe :visible).
3875 '("Treatment"
3876 ["Hide headers" gnus-article-hide-headers t]
3877 ["Hide signature" gnus-article-hide-signature t]
3878 ["Hide citation" gnus-article-hide-citation t]
3879 ["Treat overstrike" gnus-article-treat-overstrike t]
3880 ["Remove carriage return" gnus-article-remove-cr t]
3881 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3882 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3883 ["Remove base64" gnus-article-de-base64-unreadable t]
3884 ["Treat html" gnus-article-wash-html t]
3885 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3886 ["Decode HZ" gnus-article-decode-HZ t]))
3887
3888 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3889
3890 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3891
3892 (gnus-run-hooks 'gnus-article-menu-hook)))
3893
3894 (defun gnus-article-mode ()
3895 "Major mode for displaying an article.
3896
3897 All normal editing commands are switched off.
3898
3899 The following commands are available in addition to all summary mode
3900 commands:
3901 \\<gnus-article-mode-map>
3902 \\[gnus-article-next-page]\t Scroll the article one page forwards
3903 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3904 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3905 \\[gnus-article-show-summary]\t Display the summary buffer
3906 \\[gnus-article-mail]\t Send a reply to the address near point
3907 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3908 \\[gnus-info-find-node]\t Go to the Gnus info node"
3909 (interactive)
3910 (kill-all-local-variables)
3911 (gnus-simplify-mode-line)
3912 (setq mode-name "Article")
3913 (setq major-mode 'gnus-article-mode)
3914 (make-local-variable 'minor-mode-alist)
3915 (use-local-map gnus-article-mode-map)
3916 (when (gnus-visual-p 'article-menu 'menu)
3917 (gnus-article-make-menu-bar)
3918 (when gnus-summary-tool-bar-map
3919 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3920 (gnus-update-format-specifications nil 'article-mode)
3921 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3922 (set (make-local-variable 'gnus-page-broken) nil)
3923 (make-local-variable 'gnus-button-marker-list)
3924 (make-local-variable 'gnus-article-current-summary)
3925 (make-local-variable 'gnus-article-mime-handles)
3926 (make-local-variable 'gnus-article-decoded-p)
3927 (make-local-variable 'gnus-article-mime-handle-alist)
3928 (make-local-variable 'gnus-article-wash-types)
3929 (make-local-variable 'gnus-article-image-alist)
3930 (make-local-variable 'gnus-article-charset)
3931 (make-local-variable 'gnus-article-ignored-charsets)
3932 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3933 (set (make-local-variable 'nobreak-char-display) nil)
3934 (setq cursor-in-non-selected-windows nil)
3935 (gnus-set-default-directory)
3936 (buffer-disable-undo)
3937 (setq buffer-read-only t)
3938 (set-syntax-table gnus-article-mode-syntax-table)
3939 (mm-enable-multibyte)
3940 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3941
3942 (defun gnus-article-setup-buffer ()
3943 "Initialize the article buffer."
3944 (let* ((name (if gnus-single-article-buffer "*Article*"
3945 (concat "*Article " gnus-newsgroup-name "*")))
3946 (original
3947 (progn (string-match "\\*Article" name)
3948 (concat " *Original Article"
3949 (substring name (match-end 0))))))
3950 (setq gnus-article-buffer name)
3951 (setq gnus-original-article-buffer original)
3952 (setq gnus-article-mime-handle-alist nil)
3953 ;; This might be a variable local to the summary buffer.
3954 (unless gnus-single-article-buffer
3955 (save-excursion
3956 (set-buffer gnus-summary-buffer)
3957 (setq gnus-article-buffer name)
3958 (setq gnus-original-article-buffer original)
3959 (gnus-set-global-variables)))
3960 (gnus-article-setup-highlight-words)
3961 ;; Init original article buffer.
3962 (save-excursion
3963 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3964 (mm-enable-multibyte)
3965 (setq major-mode 'gnus-original-article-mode)
3966 (make-local-variable 'gnus-original-article))
3967 (if (and (get-buffer name)
3968 (with-current-buffer name
3969 (if gnus-article-edit-mode
3970 (if (y-or-n-p "Article mode edit in progress; discard? ")
3971 (progn
3972 (set-buffer-modified-p nil)
3973 (gnus-kill-buffer name)
3974 (message "")
3975 nil)
3976 (error "Action aborted"))
3977 t)))
3978 (save-excursion
3979 (set-buffer name)
3980 (set (make-local-variable 'gnus-article-edit-mode) nil)
3981 (when gnus-article-mime-handles
3982 (mm-destroy-parts gnus-article-mime-handles)
3983 (setq gnus-article-mime-handles nil))
3984 ;; Set it to nil in article-buffer!
3985 (setq gnus-article-mime-handle-alist nil)
3986 (buffer-disable-undo)
3987 (setq buffer-read-only t)
3988 ;; This list just keeps growing if we don't reset it.
3989 (setq gnus-button-marker-list nil)
3990 (unless (eq major-mode 'gnus-article-mode)
3991 (gnus-article-mode))
3992 (current-buffer))
3993 (save-excursion
3994 (set-buffer (gnus-get-buffer-create name))
3995 (gnus-article-mode)
3996 (make-local-variable 'gnus-summary-buffer)
3997 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3998 (current-buffer)))))
3999
4000 ;; Set article window start at LINE, where LINE is the number of lines
4001 ;; from the head of the article.
4002 (defun gnus-article-set-window-start (&optional line)
4003 (set-window-start
4004 (gnus-get-buffer-window gnus-article-buffer t)
4005 (save-excursion
4006 (set-buffer gnus-article-buffer)
4007 (goto-char (point-min))
4008 (if (not line)
4009 (point-min)
4010 (gnus-message 6 "Moved to bookmark")
4011 (search-forward "\n\n" nil t)
4012 (forward-line line)
4013 (point)))))
4014
4015 (defun gnus-article-prepare (article &optional all-headers header)
4016 "Prepare ARTICLE in article mode buffer.
4017 ARTICLE should either be an article number or a Message-ID.
4018 If ARTICLE is an id, HEADER should be the article headers.
4019 If ALL-HEADERS is non-nil, no headers are hidden."
4020 (save-excursion
4021 ;; Make sure we start in a summary buffer.
4022 (unless (eq major-mode 'gnus-summary-mode)
4023 (set-buffer gnus-summary-buffer))
4024 (setq gnus-summary-buffer (current-buffer))
4025 (let* ((gnus-article (if header (mail-header-number header) article))
4026 (summary-buffer (current-buffer))
4027 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4028 (group gnus-newsgroup-name)
4029 result)
4030 (save-excursion
4031 (gnus-article-setup-buffer)
4032 (set-buffer gnus-article-buffer)
4033 ;; Deactivate active regions.
4034 (when (and (boundp 'transient-mark-mode)
4035 transient-mark-mode)
4036 (setq mark-active nil))
4037 (if (not (setq result (let ((inhibit-read-only t))
4038 (gnus-request-article-this-buffer
4039 article group))))
4040 ;; There is no such article.
4041 (save-excursion
4042 (when (and (numberp article)
4043 (not (memq article gnus-newsgroup-sparse)))
4044 (setq gnus-article-current
4045 (cons gnus-newsgroup-name article))
4046 (set-buffer gnus-summary-buffer)
4047 (setq gnus-current-article article)
4048 (if (and (memq article gnus-newsgroup-undownloaded)
4049 (not (gnus-online (gnus-find-method-for-group
4050 gnus-newsgroup-name))))
4051 (progn
4052 (gnus-summary-set-agent-mark article)
4053 (message "Message marked for downloading"))
4054 (gnus-summary-mark-article article gnus-canceled-mark)
4055 (unless (memq article gnus-newsgroup-sparse)
4056 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4057 (if (or (eq result 'pseudo)
4058 (eq result 'nneething))
4059 (progn
4060 (save-excursion
4061 (set-buffer summary-buffer)
4062 (push article gnus-newsgroup-history)
4063 (setq gnus-last-article gnus-current-article
4064 gnus-current-article 0
4065 gnus-current-headers nil
4066 gnus-article-current nil)
4067 (if (eq result 'nneething)
4068 (gnus-configure-windows 'summary)
4069 (gnus-configure-windows 'article))
4070 (gnus-set-global-variables))
4071 (let ((gnus-article-mime-handle-alist-1
4072 gnus-article-mime-handle-alist))
4073 (gnus-set-mode-line 'article)))
4074 ;; The result from the `request' was an actual article -
4075 ;; or at least some text that is now displayed in the
4076 ;; article buffer.
4077 (when (and (numberp article)
4078 (not (eq article gnus-current-article)))
4079 ;; Seems like a new article has been selected.
4080 ;; `gnus-current-article' must be an article number.
4081 (save-excursion
4082 (set-buffer summary-buffer)
4083 (push article gnus-newsgroup-history)
4084 (setq gnus-last-article gnus-current-article
4085 gnus-current-article article
4086 gnus-current-headers
4087 (gnus-summary-article-header gnus-current-article)
4088 gnus-article-current
4089 (cons gnus-newsgroup-name gnus-current-article))
4090 (unless (vectorp gnus-current-headers)
4091 (setq gnus-current-headers nil))
4092 (gnus-summary-goto-subject gnus-current-article)
4093 (when (gnus-summary-show-thread)
4094 ;; If the summary buffer really was folded, the
4095 ;; previous goto may not actually have gone to
4096 ;; the right article, but the thread root instead.
4097 ;; So we go again.
4098 (gnus-summary-goto-subject gnus-current-article))
4099 (gnus-run-hooks 'gnus-mark-article-hook)
4100 (gnus-set-mode-line 'summary)
4101 (when (gnus-visual-p 'article-highlight 'highlight)
4102 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4103 ;; Set the global newsgroup variables here.
4104 (gnus-set-global-variables)
4105 (setq gnus-have-all-headers
4106 (or all-headers gnus-show-all-headers))))
4107 (save-excursion
4108 (gnus-configure-windows 'article))
4109 (when (or (numberp article)
4110 (stringp article))
4111 (gnus-article-prepare-display)
4112 ;; Do page break.
4113 (goto-char (point-min))
4114 (when gnus-break-pages
4115 (gnus-narrow-to-page)))
4116 (let ((gnus-article-mime-handle-alist-1
4117 gnus-article-mime-handle-alist))
4118 (gnus-set-mode-line 'article))
4119 (article-goto-body)
4120 (unless (bobp)
4121 (forward-line -1))
4122 (set-window-point (get-buffer-window (current-buffer)) (point))
4123 (gnus-configure-windows 'article)
4124 t))))))
4125
4126 ;;;###autoload
4127 (defun gnus-article-prepare-display ()
4128 "Make the current buffer look like a nice article."
4129 ;; Hooks for getting information from the article.
4130 ;; This hook must be called before being narrowed.
4131 (let ((gnus-article-buffer (current-buffer))
4132 buffer-read-only
4133 (inhibit-read-only t))
4134 (unless (eq major-mode 'gnus-article-mode)
4135 (gnus-article-mode))
4136 (setq buffer-read-only nil
4137 gnus-article-wash-types nil
4138 gnus-article-image-alist nil)
4139 (gnus-run-hooks 'gnus-tmp-internal-hook)
4140 (when gnus-display-mime-function
4141 (funcall gnus-display-mime-function))
4142 (gnus-run-hooks 'gnus-article-prepare-hook)))
4143
4144 ;;;
4145 ;;; Gnus MIME viewing functions
4146 ;;;
4147
4148 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4149 "Format of the MIME buttons.
4150
4151 Valid specifiers include:
4152 %t The MIME type
4153 %T MIME type, along with additional info
4154 %n The `name' parameter
4155 %d The description, if any
4156 %l The length of the encoded part
4157 %p The part identifier number
4158 %e Dots if the part isn't displayed
4159
4160 General format specifiers can also be used. See Info node
4161 `(gnus)Formatting Variables'.")
4162
4163 (defvar gnus-mime-button-line-format-alist
4164 '((?t gnus-tmp-type ?s)
4165 (?T gnus-tmp-type-long ?s)
4166 (?n gnus-tmp-name ?s)
4167 (?d gnus-tmp-description ?s)
4168 (?p gnus-tmp-id ?s)
4169 (?l gnus-tmp-length ?d)
4170 (?e gnus-tmp-dots ?s)))
4171
4172 (defvar gnus-mime-button-commands
4173 '((gnus-article-press-button "\r" "Toggle Display")
4174 (gnus-mime-view-part "v" "View Interactively...")
4175 (gnus-mime-view-part-as-type "t" "View As Type...")
4176 (gnus-mime-view-part-as-charset "C" "View As charset...")
4177 (gnus-mime-save-part "o" "Save...")
4178 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4179 (gnus-mime-delete-part "d" "Delete part")
4180 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4181 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4182 (gnus-mime-view-part-internally "E" "View Internally")
4183 (gnus-mime-view-part-externally "e" "View Externally")
4184 (gnus-mime-print-part "p" "Print")
4185 (gnus-mime-pipe-part "|" "Pipe To Command...")
4186 (gnus-mime-action-on-part "." "Take action on the part...")))
4187
4188 (defun gnus-article-mime-part-status ()
4189 (if gnus-article-mime-handle-alist-1
4190 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4191 " (1 part)"
4192 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4193 ""))
4194
4195 (defvar gnus-mime-button-map
4196 (let ((map (make-sparse-keymap)))
4197 (unless (>= (string-to-number emacs-version) 21)
4198 ;; XEmacs doesn't care.
4199 (set-keymap-parent map gnus-article-mode-map))
4200 (define-key map gnus-mouse-2 'gnus-article-push-button)
4201 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4202 (dolist (c gnus-mime-button-commands)
4203 (define-key map (cadr c) (car c)))
4204 map))
4205
4206 (easy-menu-define
4207 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4208 `("MIME Part"
4209 ,@(mapcar (lambda (c)
4210 (vector (caddr c) (car c) :enable t))
4211 gnus-mime-button-commands)))
4212
4213 (eval-when-compile
4214 (define-compiler-macro popup-menu (&whole form
4215 menu &optional position prefix)
4216 (if (and (fboundp 'popup-menu)
4217 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4218 form
4219 ;; Gnus is probably running under Emacs 20.
4220 `(let* ((menu (cdr ,menu))
4221 (response (x-popup-menu
4222 t (list (car menu)
4223 (cons "" (mapcar (lambda (c)
4224 (cons (caddr c) (car c)))
4225 (cdr menu)))))))
4226 (if response
4227 (call-interactively (nth 3 (assq response menu))))))))
4228
4229 (defun gnus-mime-button-menu (event prefix)
4230 "Construct a context-sensitive menu of MIME commands."
4231 (interactive "e\nP")
4232 (save-window-excursion
4233 (let ((pos (event-start event)))
4234 (select-window (posn-window pos))
4235 (goto-char (posn-point pos))
4236 (gnus-article-check-buffer)
4237 (popup-menu gnus-mime-button-menu nil prefix))))
4238
4239 (defun gnus-mime-view-all-parts (&optional handles)
4240 "View all the MIME parts."
4241 (interactive)
4242 (save-current-buffer
4243 (set-buffer gnus-article-buffer)
4244 (let ((handles (or handles gnus-article-mime-handles))
4245 (mail-parse-charset gnus-newsgroup-charset)
4246 (mail-parse-ignored-charsets
4247 (with-current-buffer gnus-summary-buffer
4248 gnus-newsgroup-ignored-charsets)))
4249 (when handles
4250 (mm-remove-parts handles)
4251 (goto-char (point-min))
4252 (or (search-forward "\n\n") (goto-char (point-max)))
4253 (let ((inhibit-read-only t))
4254 (delete-region (point) (point-max))
4255 (mm-display-parts handles))))))
4256
4257 (defun gnus-mime-save-part-and-strip ()
4258 "Save the MIME part under point then replace it with an external body."
4259 (interactive)
4260 (gnus-article-check-buffer)
4261 (when (gnus-group-read-only-p)
4262 (error "The current group does not support deleting of parts"))
4263 (when (mm-complicated-handles gnus-article-mime-handles)
4264 (error "\
4265 The current article has a complicated MIME structure, giving up..."))
4266 (when (gnus-yes-or-no-p "\
4267 Deleting parts may malfunction or destroy the article; continue? ")
4268 (let* ((data (get-text-property (point) 'gnus-data))
4269 file param
4270 (handles gnus-article-mime-handles))
4271 (setq file (and data (mm-save-part data)))
4272 (when file
4273 (with-current-buffer (mm-handle-buffer data)
4274 (erase-buffer)
4275 (insert "Content-Type: " (mm-handle-media-type data))
4276 (mml-insert-parameter-string (cdr (mm-handle-type data))
4277 '(charset))
4278 ;; Add a filename for the sake of saving the part again.
4279 (mml-insert-parameter
4280 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4281 (insert "\n")
4282 (insert "Content-ID: " (message-make-message-id) "\n")
4283 (insert "Content-Transfer-Encoding: binary\n")
4284 (insert "\n"))
4285 (setcdr data
4286 (cdr (mm-make-handle nil
4287 `("message/external-body"
4288 (access-type . "LOCAL-FILE")
4289 (name . ,file)))))
4290 (set-buffer gnus-summary-buffer)
4291 (gnus-article-edit-article
4292 `(lambda ()
4293 (erase-buffer)
4294 (let ((mail-parse-charset (or gnus-article-charset
4295 ',gnus-newsgroup-charset))
4296 (mail-parse-ignored-charsets
4297 (or gnus-article-ignored-charsets
4298 ',gnus-newsgroup-ignored-charsets))
4299 (mbl mml-buffer-list))
4300 (setq mml-buffer-list nil)
4301 (insert-buffer-substring gnus-original-article-buffer)
4302 (mime-to-mml ',handles)
4303 (setq gnus-article-mime-handles nil)
4304 (let ((mbl1 mml-buffer-list))
4305 (setq mml-buffer-list mbl)
4306 (set (make-local-variable 'mml-buffer-list) mbl1))
4307 (gnus-make-local-hook 'kill-buffer-hook)
4308 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4309 `(lambda (no-highlight)
4310 (let ((mail-parse-charset (or gnus-article-charset
4311 ',gnus-newsgroup-charset))
4312 (message-options message-options)
4313 (message-options-set-recipient)
4314 (mail-parse-ignored-charsets
4315 (or gnus-article-ignored-charsets
4316 ',gnus-newsgroup-ignored-charsets)))
4317 (mml-to-mime)
4318 (mml-destroy-buffers)
4319 (remove-hook 'kill-buffer-hook
4320 'mml-destroy-buffers t)
4321 (kill-local-variable 'mml-buffer-list))
4322 (gnus-summary-edit-article-done
4323 ,(or (mail-header-references gnus-current-headers) "")
4324 ,(gnus-group-read-only-p)
4325 ,gnus-summary-buffer no-highlight)))))))
4326
4327 (defun gnus-mime-delete-part ()
4328 "Delete the MIME part under point.
4329 Replace it with some information about the removed part."
4330 (interactive)
4331 (gnus-article-check-buffer)
4332 (when (gnus-group-read-only-p)
4333 (error "The current group does not support deleting of parts"))
4334 (when (mm-complicated-handles gnus-article-mime-handles)
4335 (error "\
4336 The current article has a complicated MIME structure, giving up..."))
4337 (when (gnus-yes-or-no-p "\
4338 Deleting parts may malfunction or destroy the article; continue? ")
4339 (let* ((data (get-text-property (point) 'gnus-data))
4340 (handles gnus-article-mime-handles)
4341 (none "(none)")
4342 (description
4343 (mail-decode-encoded-word-string (or (mm-handle-description data)
4344 none)))
4345 (filename
4346 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4347 none))
4348 (type (mm-handle-media-type data)))
4349 (unless data
4350 (error "No MIME part under point"))
4351 (with-current-buffer (mm-handle-buffer data)
4352 (let ((bsize (format "%s" (buffer-size))))
4353 (erase-buffer)
4354 (insert
4355 (concat
4356 ",----\n"
4357 "| The following attachment has been deleted:\n"
4358 "|\n"
4359 "| Type: " type "\n"
4360 "| Filename: " filename "\n"
4361 "| Size (encoded): " bsize " Byte\n"
4362 "| Description: " description "\n"
4363 "`----\n"))
4364 (setcdr data
4365 (cdr (mm-make-handle
4366 nil `("text/plain") nil nil
4367 (list "attachment")
4368 (format "Deleted attachment (%s bytes)" bsize))))))
4369 (set-buffer gnus-summary-buffer)
4370 ;; FIXME: maybe some of the following code (borrowed from
4371 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4372 (gnus-article-edit-article
4373 `(lambda ()
4374 (erase-buffer)
4375 (let ((mail-parse-charset (or gnus-article-charset
4376 ',gnus-newsgroup-charset))
4377 (mail-parse-ignored-charsets
4378 (or gnus-article-ignored-charsets
4379 ',gnus-newsgroup-ignored-charsets))
4380 (mbl mml-buffer-list))
4381 (setq mml-buffer-list nil)
4382 (insert-buffer-substring gnus-original-article-buffer)
4383 (mime-to-mml ',handles)
4384 (setq gnus-article-mime-handles nil)
4385 (let ((mbl1 mml-buffer-list))
4386 (setq mml-buffer-list mbl)
4387 (set (make-local-variable 'mml-buffer-list) mbl1))
4388 (gnus-make-local-hook 'kill-buffer-hook)
4389 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4390 `(lambda (no-highlight)
4391 (let ((mail-parse-charset (or gnus-article-charset
4392 ',gnus-newsgroup-charset))
4393 (message-options message-options)
4394 (message-options-set-recipient)
4395 (mail-parse-ignored-charsets
4396 (or gnus-article-ignored-charsets
4397 ',gnus-newsgroup-ignored-charsets)))
4398 (mml-to-mime)
4399 (mml-destroy-buffers)
4400 (remove-hook 'kill-buffer-hook
4401 'mml-destroy-buffers t)
4402 (kill-local-variable 'mml-buffer-list))
4403 (gnus-summary-edit-article-done
4404 ,(or (mail-header-references gnus-current-headers) "")
4405 ,(gnus-group-read-only-p)
4406 ,gnus-summary-buffer no-highlight)))))
4407 ;; Not in `gnus-mime-save-part-and-strip':
4408 (gnus-article-edit-done)
4409 (gnus-summary-expand-window)
4410 (gnus-summary-show-article))
4411
4412 (defun gnus-mime-save-part ()
4413 "Save the MIME part under point."
4414 (interactive)
4415 (gnus-article-check-buffer)
4416 (let ((data (get-text-property (point) 'gnus-data)))
4417 (when data
4418 (mm-save-part data))))
4419
4420 (defun gnus-mime-pipe-part ()
4421 "Pipe the MIME part under point to a process."
4422 (interactive)
4423 (gnus-article-check-buffer)
4424 (let ((data (get-text-property (point) 'gnus-data)))
4425 (when data
4426 (mm-pipe-part data))))
4427
4428 (defun gnus-mime-view-part ()
4429 "Interactively choose a viewing method for the MIME part under point."
4430 (interactive)
4431 (gnus-article-check-buffer)
4432 (let ((data (get-text-property (point) 'gnus-data)))
4433 (when data
4434 (setq gnus-article-mime-handles
4435 (mm-merge-handles
4436 gnus-article-mime-handles (setq data (copy-sequence data))))
4437 (mm-interactively-view-part data))))
4438
4439 (defun gnus-mime-view-part-as-type-internal ()
4440 (gnus-article-check-buffer)
4441 (let* ((handle (get-text-property (point) 'gnus-data))
4442 (name (or
4443 ;; Content-Type: foo/bar; name=...
4444 (mail-content-type-get (mm-handle-type handle) 'name)
4445 ;; Content-Disposition: attachment; filename=...
4446 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4447 (def-type (and name (mm-default-file-encoding name))))
4448 (and def-type (cons def-type 0))))
4449
4450 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4451 "Choose a MIME media type, and view the part as such.
4452 If non-nil, PRED is a predicate to use during completion to limit the
4453 available media-types."
4454 (interactive)
4455 (unless mime-type
4456 (setq mime-type
4457 (let ((default (gnus-mime-view-part-as-type-internal)))
4458 (completing-read
4459 (format "View as MIME type (default %s): "
4460 (car default))
4461 (mapcar #'list (mailcap-mime-types))
4462 pred nil nil nil
4463 (car default)))))
4464 (gnus-article-check-buffer)
4465 (let ((handle (get-text-property (point) 'gnus-data)))
4466 (when handle
4467 (when (equal (mm-handle-media-type handle) "message/external-body")
4468 (unless (mm-handle-cache handle)
4469 (mm-extern-cache-contents handle))
4470 (setq handle (mm-handle-cache handle)))
4471 (setq handle
4472 (mm-make-handle (mm-handle-buffer handle)
4473 (cons mime-type (cdr (mm-handle-type handle)))
4474 (mm-handle-encoding handle)
4475 (mm-handle-undisplayer handle)
4476 (mm-handle-disposition handle)
4477 (mm-handle-description handle)
4478 nil
4479 (mm-handle-id handle)))
4480 (setq gnus-article-mime-handles
4481 (mm-merge-handles gnus-article-mime-handles handle))
4482 (gnus-mm-display-part handle))))
4483
4484 (eval-when-compile
4485 (require 'jka-compr))
4486
4487 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4488 ;; emacs can do that itself.
4489 ;;
4490 (defun gnus-mime-jka-compr-maybe-uncompress ()
4491 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4492 The uncompress method used is derived from `buffer-file-name'."
4493 (when (and (fboundp 'jka-compr-installed-p)
4494 (jka-compr-installed-p))
4495 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4496 (when info
4497 (let ((basename (file-name-nondirectory buffer-file-name))
4498 (args (jka-compr-info-uncompress-args info))
4499 (prog (jka-compr-info-uncompress-program info))
4500 (message (jka-compr-info-uncompress-message info))
4501 (err-file (jka-compr-make-temp-name)))
4502 (if message
4503 (message "%s %s..." message basename))
4504 (unwind-protect
4505 (unless (memq (apply 'call-process-region
4506 (point-min) (point-max)
4507 prog
4508 t (list t err-file) nil
4509 args)
4510 jka-compr-acceptable-retval-list)
4511 (jka-compr-error prog args basename message err-file))
4512 (jka-compr-delete-temp-file err-file)))))))
4513
4514 (defun gnus-mime-copy-part (&optional handle)
4515 "Put the MIME part under point into a new buffer.
4516 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4517 are decompressed."
4518 (interactive)
4519 (gnus-article-check-buffer)
4520 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4521 (contents (and handle (mm-get-part handle)))
4522 (base (and handle
4523 (file-name-nondirectory
4524 (or
4525 (mail-content-type-get (mm-handle-type handle) 'name)
4526 (mail-content-type-get (mm-handle-disposition handle)
4527 'filename)
4528 "*decoded*"))))
4529 (buffer (and base (generate-new-buffer base))))
4530 (when contents
4531 (switch-to-buffer buffer)
4532 (insert contents)
4533 ;; We do it this way to make `normal-mode' set the appropriate mode.
4534 (unwind-protect
4535 (progn
4536 (setq buffer-file-name (expand-file-name base))
4537 (gnus-mime-jka-compr-maybe-uncompress)
4538 (normal-mode))
4539 (setq buffer-file-name nil))
4540 (goto-char (point-min)))))
4541
4542 (defun gnus-mime-print-part (&optional handle filename)
4543 "Print the MIME part under point."
4544 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4545 (gnus-article-check-buffer)
4546 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4547 (contents (and handle (mm-get-part handle)))
4548 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4549 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4550 (when contents
4551 (if printer
4552 (unwind-protect
4553 (progn
4554 (mm-save-part-to-file handle file)
4555 (call-process shell-file-name nil
4556 (generate-new-buffer " *mm*")
4557 nil
4558 shell-command-switch
4559 (mm-mailcap-command
4560 printer file (mm-handle-type handle))))
4561 (delete-file file))
4562 (with-temp-buffer
4563 (insert contents)
4564 (gnus-print-buffer))
4565 (ps-despool filename)))))
4566
4567 (defun gnus-mime-inline-part (&optional handle arg)
4568 "Insert the MIME part under point into the current buffer."
4569 (interactive (list nil current-prefix-arg))
4570 (gnus-article-check-buffer)
4571 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4572 contents charset
4573 (b (point))
4574 (inhibit-read-only t))
4575 (when handle
4576 (if (and (not arg) (mm-handle-undisplayer handle))
4577 (mm-remove-part handle)
4578 (setq contents (mm-get-part handle))
4579 (cond
4580 ((not arg)
4581 (setq charset (or (mail-content-type-get
4582 (mm-handle-type handle) 'charset)
4583 gnus-newsgroup-charset)))
4584 ((numberp arg)
4585 (if (mm-handle-undisplayer handle)
4586 (mm-remove-part handle))
4587 (setq charset
4588 (or (cdr (assq arg
4589 gnus-summary-show-article-charset-alist))
4590 (mm-read-coding-system "Charset: "))))
4591 (t
4592 (if (mm-handle-undisplayer handle)
4593 (mm-remove-part handle))))
4594 (forward-line 2)
4595 (mm-insert-inline
4596 handle
4597 (if (and charset
4598 (setq charset (mm-charset-to-coding-system
4599 charset))
4600 (not (eq charset 'ascii)))
4601 (mm-decode-coding-string contents charset)
4602 (mm-string-to-multibyte contents)))
4603 (goto-char b)))))
4604
4605 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4606 "Insert the MIME part under point into the current buffer using the
4607 specified charset."
4608 (interactive (list nil current-prefix-arg))
4609 (gnus-article-check-buffer)
4610 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4611 (fun (get-text-property (point) 'gnus-callback))
4612 (gnus-newsgroup-ignored-charsets 'gnus-all)
4613 gnus-newsgroup-charset type charset)
4614 (when handle
4615 (if (mm-handle-undisplayer handle)
4616 (mm-remove-part handle))
4617 (when fun
4618 (setq gnus-newsgroup-charset
4619 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4620 (mm-read-coding-system "Charset: ")))
4621 ;; Strip the charset parameter from `handle'.
4622 (setq type (mm-handle-type
4623 (if (equal (mm-handle-media-type handle)
4624 "message/external-body")
4625 (progn
4626 (unless (mm-handle-cache handle)
4627 (mm-extern-cache-contents handle))
4628 (mm-handle-cache handle))
4629 handle))
4630 charset (assq 'charset (cdr type)))
4631 (delq charset type)
4632 (funcall fun handle)))))
4633
4634 (defun gnus-mime-view-part-externally (&optional handle)
4635 "View the MIME part under point with an external viewer."
4636 (interactive)
4637 (gnus-article-check-buffer)
4638 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4639 (mm-user-display-methods nil)
4640 (mm-inlined-types nil)
4641 (mail-parse-charset gnus-newsgroup-charset)
4642 (mail-parse-ignored-charsets
4643 (with-current-buffer gnus-summary-buffer
4644 gnus-newsgroup-ignored-charsets))
4645 (type (mm-handle-media-type handle))
4646 (method (mailcap-mime-info type))
4647 (mm-enable-external t))
4648 (if (not (stringp method))
4649 (gnus-mime-view-part-as-type
4650 nil (lambda (type) (stringp (mailcap-mime-info type))))
4651 (when handle
4652 (if (mm-handle-undisplayer handle)
4653 (mm-remove-part handle)
4654 (mm-display-part handle))))))
4655
4656 (defun gnus-mime-view-part-internally (&optional handle)
4657 "View the MIME part under point with an internal viewer.
4658 If no internal viewer is available, use an external viewer."
4659 (interactive)
4660 (gnus-article-check-buffer)
4661 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4662 (mm-inlined-types '(".*"))
4663 (mm-inline-large-images t)
4664 (mail-parse-charset gnus-newsgroup-charset)
4665 (mail-parse-ignored-charsets
4666 (with-current-buffer gnus-summary-buffer
4667 gnus-newsgroup-ignored-charsets))
4668 (inhibit-read-only t))
4669 (if (not (mm-inlinable-p handle))
4670 (gnus-mime-view-part-as-type
4671 nil (lambda (type) (mm-inlinable-p handle type)))
4672 (when handle
4673 (if (mm-handle-undisplayer handle)
4674 (mm-remove-part handle)
4675 (mm-display-part handle))))))
4676
4677 (defun gnus-mime-action-on-part (&optional action)
4678 "Do something with the MIME attachment at \(point\)."
4679 (interactive
4680 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4681 (gnus-article-check-buffer)
4682 (let ((action-pair (assoc action gnus-mime-action-alist)))
4683 (if action-pair
4684 (funcall (cdr action-pair)))))
4685
4686 (defun gnus-article-part-wrapper (n function)
4687 (save-current-buffer
4688 (set-buffer gnus-article-buffer)
4689 (when (> n (length gnus-article-mime-handle-alist))
4690 (error "No such part"))
4691 (gnus-article-goto-part n)
4692 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4693 (funcall function handle))))
4694
4695 (defun gnus-article-pipe-part (n)
4696 "Pipe MIME part N, which is the numerical prefix."
4697 (interactive "p")
4698 (gnus-article-part-wrapper n 'mm-pipe-part))
4699
4700 (defun gnus-article-save-part (n)
4701 "Save MIME part N, which is the numerical prefix."
4702 (interactive "p")
4703 (gnus-article-part-wrapper n 'mm-save-part))
4704
4705 (defun gnus-article-interactively-view-part (n)
4706 "View MIME part N interactively, which is the numerical prefix."
4707 (interactive "p")
4708 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4709
4710 (defun gnus-article-copy-part (n)
4711 "Copy MIME part N, which is the numerical prefix."
4712 (interactive "p")
4713 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4714
4715 (defun gnus-article-view-part-as-charset (n)
4716 "View MIME part N using a specified charset.
4717 N is the numerical prefix."
4718 (interactive "p")
4719 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4720
4721 (defun gnus-article-view-part-externally (n)
4722 "View MIME part N externally, which is the numerical prefix."
4723 (interactive "p")
4724 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4725
4726 (defun gnus-article-inline-part (n)
4727 "Inline MIME part N, which is the numerical prefix."
4728 (interactive "p")
4729 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4730
4731 (defun gnus-article-mime-match-handle-first (condition)
4732 (if condition
4733 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4734 (while (setq ihandle (pop alist))
4735 (if (and (cond
4736 ((functionp condition)
4737 (funcall condition (cdr ihandle)))
4738 ((eq condition 'undisplayed)
4739 (not (or (mm-handle-undisplayer (cdr ihandle))
4740 (equal (mm-handle-media-type (cdr ihandle))
4741 "multipart/alternative"))))
4742 ((eq condition 'undisplayed-alternative)
4743 (not (mm-handle-undisplayer (cdr ihandle))))
4744 (t t))
4745 (gnus-article-goto-part (car ihandle))
4746 (or (not n) (< (car ihandle) n)))
4747 (setq n (car ihandle))))
4748 (or n 1))
4749 1))
4750
4751 (defun gnus-article-view-part (&optional n)
4752 "View MIME part N, which is the numerical prefix."
4753 (interactive "P")
4754 (save-current-buffer
4755 (set-buffer gnus-article-buffer)
4756 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4757 gnus-article-mime-match-handle-function)))
4758 (when (> n (length gnus-article-mime-handle-alist))
4759 (error "No such part"))
4760 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4761 (when (gnus-article-goto-part n)
4762 (if (equal (car handle) "multipart/alternative")
4763 (gnus-article-press-button)
4764 (when (eq (gnus-mm-display-part handle) 'internal)
4765 (gnus-set-window-start)))))))
4766
4767 (defsubst gnus-article-mime-total-parts ()
4768 (if (bufferp (car gnus-article-mime-handles))
4769 1 ;; single part
4770 (1- (length gnus-article-mime-handles))))
4771
4772 (defun gnus-mm-display-part (handle)
4773 "Display HANDLE and fix MIME button."
4774 (let ((id (get-text-property (point) 'gnus-part))
4775 (point (point))
4776 (inhibit-read-only t))
4777 (forward-line 1)
4778 (prog1
4779 (let ((window (selected-window))
4780 (mail-parse-charset gnus-newsgroup-charset)
4781 (mail-parse-ignored-charsets
4782 (if (gnus-buffer-live-p gnus-summary-buffer)
4783 (save-excursion
4784 (set-buffer gnus-summary-buffer)
4785 gnus-newsgroup-ignored-charsets)
4786 nil)))
4787 (save-excursion
4788 (unwind-protect
4789 (let ((win (gnus-get-buffer-window (current-buffer) t))
4790 (beg (point)))
4791 (when win
4792 (select-window win))
4793 (goto-char point)
4794 (forward-line)
4795 (if (mm-handle-displayed-p handle)
4796 ;; This will remove the part.
4797 (mm-display-part handle)
4798 (save-restriction
4799 (narrow-to-region (point)
4800 (if (eobp) (point) (1+ (point))))
4801 (mm-display-part handle)
4802 ;; We narrow to the part itself and
4803 ;; then call the treatment functions.
4804 (goto-char (point-min))
4805 (forward-line 1)
4806 (narrow-to-region (point) (point-max))
4807 (gnus-treat-article
4808 nil id
4809 (gnus-article-mime-total-parts)
4810 (mm-handle-media-type handle)))))
4811 (if (window-live-p window)
4812 (select-window window)))))
4813 (goto-char point)
4814 (gnus-delete-line)
4815 (gnus-insert-mime-button
4816 handle id (list (mm-handle-displayed-p handle)))
4817 (goto-char point))))
4818
4819 (defun gnus-article-goto-part (n)
4820 "Go to MIME part N."
4821 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4822
4823 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4824 (let ((gnus-tmp-name
4825 (or (mail-content-type-get (mm-handle-type handle) 'name)
4826 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4827 (mail-content-type-get (mm-handle-type handle) 'url)
4828 ""))
4829 (gnus-tmp-type (mm-handle-media-type handle))
4830 (gnus-tmp-description
4831 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4832 "")))
4833 (gnus-tmp-dots
4834 (if (if displayed (car displayed)
4835 (mm-handle-displayed-p handle))
4836 "" "..."))
4837 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4838 (buffer-size)))
4839 gnus-tmp-type-long b e)
4840 (when (string-match ".*/" gnus-tmp-name)
4841 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4842 (setq gnus-tmp-type-long (concat gnus-tmp-type
4843 (and (not (equal gnus-tmp-name ""))
4844 (concat "; " gnus-tmp-name))))
4845 (unless (equal gnus-tmp-description "")
4846 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4847 (unless (bolp)
4848 (insert "\n"))
4849 (setq b (point))
4850 (gnus-eval-format
4851 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4852 `(,@(gnus-local-map-property gnus-mime-button-map)
4853 gnus-callback gnus-mm-display-part
4854 gnus-part ,gnus-tmp-id
4855 article-type annotation
4856 gnus-data ,handle))
4857 (setq e (if (bolp)
4858 ;; Exclude a newline.
4859 (1- (point))
4860 (point)))
4861 (widget-convert-button
4862 'link b e
4863 :mime-handle handle
4864 :action 'gnus-widget-press-button
4865 :button-keymap gnus-mime-button-map
4866 :help-echo
4867 (lambda (widget/window &optional overlay pos)
4868 ;; Needed to properly clear the message due to a bug in
4869 ;; wid-edit (XEmacs only).
4870 (if (boundp 'help-echo-owns-message)
4871 (setq help-echo-owns-message t))
4872 (format
4873 "%S: %s the MIME part; %S: more options"
4874 (aref gnus-mouse-2 0)
4875 ;; XEmacs will get a single widget arg; Emacs 21 will get
4876 ;; window, overlay, position.
4877 (if (mm-handle-displayed-p
4878 (if overlay
4879 (with-current-buffer (gnus-overlay-buffer overlay)
4880 (widget-get (widget-at (gnus-overlay-start overlay))
4881 :mime-handle))
4882 (widget-get widget/window :mime-handle)))
4883 "hide" "show")
4884 (aref gnus-down-mouse-3 0))))))
4885
4886 (defun gnus-widget-press-button (elems el)
4887 (goto-char (widget-get elems :from))
4888 (gnus-article-press-button))
4889
4890 (defvar gnus-displaying-mime nil)
4891
4892 (defun gnus-display-mime (&optional ihandles)
4893 "Display the MIME parts."
4894 (save-excursion
4895 (save-selected-window
4896 (let ((window (get-buffer-window gnus-article-buffer))
4897 (point (point)))
4898 (when window
4899 (select-window window)
4900 ;; We have to do this since selecting the window
4901 ;; may change the point. So we set the window point.
4902 (set-window-point window point)))
4903 (let ((handles ihandles)
4904 (inhibit-read-only t)
4905 handle)
4906 (cond (handles)
4907 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4908 (when gnus-article-emulate-mime
4909 (mm-uu-dissect-text-parts handles)))
4910 (gnus-article-emulate-mime
4911 (setq handles (mm-uu-dissect))))
4912 (when (and (not ihandles)
4913 (not gnus-displaying-mime))
4914 ;; Top-level call; we clean up.
4915 (when gnus-article-mime-handles
4916 (mm-destroy-parts gnus-article-mime-handles)
4917 (setq gnus-article-mime-handle-alist nil));; A trick.
4918 (setq gnus-article-mime-handles handles)
4919 ;; We allow users to glean info from the handles.
4920 (when gnus-article-mime-part-function
4921 (gnus-mime-part-function handles)))
4922 (if (and handles
4923 (or (not (stringp (car handles)))
4924 (cdr handles)))
4925 (progn
4926 (when (and (not ihandles)
4927 (not gnus-displaying-mime))
4928 ;; Clean up for mime parts.
4929 (article-goto-body)
4930 (delete-region (point) (point-max)))
4931 (let ((gnus-displaying-mime t))
4932 (gnus-mime-display-part handles)))
4933 (save-restriction
4934 (article-goto-body)
4935 (narrow-to-region (point) (point-max))
4936 (gnus-treat-article nil 1 1)
4937 (widen)))
4938 (unless ihandles
4939 ;; Highlight the headers.
4940 (save-excursion
4941 (save-restriction
4942 (article-goto-body)
4943 (narrow-to-region (point-min) (point))
4944 (gnus-article-save-original-date
4945 (gnus-treat-article 'head)))))))
4946 ;; Cope with broken MIME messages.
4947 (goto-char (point-max))
4948 (unless (bolp)
4949 (insert "\n"))))
4950
4951 (defcustom gnus-mime-display-multipart-as-mixed nil
4952 "Display \"multipart\" parts as \"multipart/mixed\".
4953
4954 If t, it overrides nil values of
4955 `gnus-mime-display-multipart-alternative-as-mixed' and
4956 `gnus-mime-display-multipart-related-as-mixed'."
4957 :group 'gnus-article-mime
4958 :type 'boolean)
4959
4960 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4961 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4962 :version "22.1"
4963 :group 'gnus-article-mime
4964 :type 'boolean)
4965
4966 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4967 "Display \"multipart/related\" parts as \"multipart/mixed\".
4968
4969 If displaying \"text/html\" is discouraged \(see
4970 `mm-discouraged-alternatives'\) images or other material inside a
4971 \"multipart/related\" part might be overlooked when this variable is nil."
4972 :version "22.1"
4973 :group 'gnus-article-mime
4974 :type 'boolean)
4975
4976 (defun gnus-mime-display-part (handle)
4977 (cond
4978 ;; Maybe a broken MIME message.
4979 ((null handle))
4980 ;; Single part.
4981 ((not (stringp (car handle)))
4982 (gnus-mime-display-single handle))
4983 ;; User-defined multipart
4984 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4985 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4986 handle))
4987 ;; multipart/alternative
4988 ((and (equal (car handle) "multipart/alternative")
4989 (not (or gnus-mime-display-multipart-as-mixed
4990 gnus-mime-display-multipart-alternative-as-mixed)))
4991 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4992 (push (cons id handle) gnus-article-mime-handle-alist)
4993 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4994 ;; multipart/related
4995 ((and (equal (car handle) "multipart/related")
4996 (not (or gnus-mime-display-multipart-as-mixed
4997 gnus-mime-display-multipart-related-as-mixed)))
4998 ;;;!!!We should find the start part, but we just default
4999 ;;;!!!to the first part.
5000 ;;(gnus-mime-display-part (cadr handle))
5001 ;;;!!! Most multipart/related is an HTML message plus images.
5002 ;;;!!! Unfortunately we are unable to let W3 display those
5003 ;;;!!! included images, so we just display it as a mixed multipart.
5004 ;;(gnus-mime-display-mixed (cdr handle))
5005 ;;;!!! No, w3 can display everything just fine.
5006 (gnus-mime-display-part (cadr handle)))
5007 ((equal (car handle) "multipart/signed")
5008 (gnus-add-wash-type 'signed)
5009 (gnus-mime-display-security handle))
5010 ((equal (car handle) "multipart/encrypted")
5011 (gnus-add-wash-type 'encrypted)
5012 (gnus-mime-display-security handle))
5013 ;; Other multiparts are handled like multipart/mixed.
5014 (t
5015 (gnus-mime-display-mixed (cdr handle)))))
5016
5017 (defun gnus-mime-part-function (handles)
5018 (if (stringp (car handles))
5019 (mapcar 'gnus-mime-part-function (cdr handles))
5020 (funcall gnus-article-mime-part-function handles)))
5021
5022 (defun gnus-mime-display-mixed (handles)
5023 (mapcar 'gnus-mime-display-part handles))
5024
5025 (defun gnus-mime-display-single (handle)
5026 (let ((type (mm-handle-media-type handle))
5027 (ignored gnus-ignored-mime-types)
5028 (not-attachment t)
5029 (move nil)
5030 display text)
5031 (catch 'ignored
5032 (progn
5033 (while ignored
5034 (when (string-match (pop ignored) type)
5035 (throw 'ignored nil)))
5036 (if (and (setq not-attachment
5037 (and (not (mm-inline-override-p handle))
5038 (or (not (mm-handle-disposition handle))
5039 (equal (car (mm-handle-disposition handle))
5040 "inline")
5041 (mm-attachment-override-p handle))))
5042 (mm-automatic-display-p handle)
5043 (or (and
5044 (mm-inlinable-p handle)
5045 (mm-inlined-p handle))
5046 (mm-automatic-external-display-p type)))
5047 (setq display t)
5048 (when (equal (mm-handle-media-supertype handle) "text")
5049 (setq text t)))
5050 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5051 beg)
5052 (push (cons id handle) gnus-article-mime-handle-alist)
5053 (when (and display
5054 (equal (mm-handle-media-supertype handle) "message"))
5055 (insert-char
5056 ?\n
5057 (cond ((not (bolp)) 2)
5058 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5059 (t 1))))
5060 (when (or (not display)
5061 (not (gnus-unbuttonized-mime-type-p type)))
5062 (gnus-insert-mime-button
5063 handle id (list (or display (and not-attachment text))))
5064 (gnus-article-insert-newline)
5065 ;; Remember modify the number of forward lines.
5066 (setq move t))
5067 (setq beg (point))
5068 (cond
5069 (display
5070 (when move
5071 (forward-line -1)
5072 (setq beg (point)))
5073 (let ((mail-parse-charset gnus-newsgroup-charset)
5074 (mail-parse-ignored-charsets
5075 (save-excursion (condition-case ()
5076 (set-buffer gnus-summary-buffer)
5077 (error))
5078 gnus-newsgroup-ignored-charsets)))
5079 (mm-display-part handle t))
5080 (goto-char (point-max)))
5081 ((and text not-attachment)
5082 (when move
5083 (forward-line -1)
5084 (setq beg (point)))
5085 (gnus-article-insert-newline)
5086 (mm-insert-inline
5087 handle
5088 (let ((charset (mail-content-type-get (mm-handle-type handle)
5089 'charset)))
5090 (cond ((not charset)
5091 (mm-string-as-multibyte (mm-get-part handle)))
5092 ((eq charset 'gnus-decoded)
5093 (with-current-buffer (mm-handle-buffer handle)
5094 (buffer-string)))
5095 (t
5096 (mm-decode-string (mm-get-part handle) charset)))))
5097 (goto-char (point-max))))
5098 ;; Do highlighting.
5099 (save-excursion
5100 (save-restriction
5101 (narrow-to-region beg (point))
5102 (gnus-treat-article
5103 nil id
5104 (gnus-article-mime-total-parts)
5105 (mm-handle-media-type handle)))))))))
5106
5107 (defun gnus-unbuttonized-mime-type-p (type)
5108 "Say whether TYPE is to be unbuttonized."
5109 (unless gnus-inhibit-mime-unbuttonizing
5110 (when (catch 'found
5111 (let ((types gnus-unbuttonized-mime-types))
5112 (while types
5113 (when (string-match (pop types) type)
5114 (throw 'found t)))))
5115 (not (catch 'found
5116 (let ((types gnus-buttonized-mime-types))
5117 (while types
5118 (when (string-match (pop types) type)
5119 (throw 'found t)))))))))
5120
5121 (defun gnus-article-insert-newline ()
5122 "Insert a newline, but mark it as undeletable."
5123 (gnus-put-text-property
5124 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5125
5126 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5127 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5128 (ihandles handles)
5129 (point (point))
5130 handle (inhibit-read-only t) from props begend not-pref)
5131 (save-window-excursion
5132 (save-restriction
5133 (when ibegend
5134 (narrow-to-region (car ibegend)
5135 (or (cdr ibegend)
5136 (progn
5137 (goto-char (car ibegend))
5138 (forward-line 2)
5139 (point))))
5140 (delete-region (point-min) (point-max))
5141 (mm-remove-parts handles))
5142 (setq begend (list (point-marker)))
5143 ;; Do the toggle.
5144 (unless (setq not-pref (cadr (member preferred ihandles)))
5145 (setq not-pref (car ihandles)))
5146 (when (or ibegend
5147 (not preferred)
5148 (not (gnus-unbuttonized-mime-type-p
5149 "multipart/alternative")))
5150 (gnus-add-text-properties
5151 (setq from (point))
5152 (progn
5153 (insert (format "%d. " id))
5154 (point))
5155 `(gnus-callback
5156 (lambda (handles)
5157 (unless ,(not ibegend)
5158 (setq gnus-article-mime-handle-alist
5159 ',gnus-article-mime-handle-alist))
5160 (gnus-mime-display-alternative
5161 ',ihandles ',not-pref ',begend ,id))
5162 ,@(gnus-local-map-property gnus-mime-button-map)
5163 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5164 face ,gnus-article-button-face
5165 gnus-part ,id
5166 article-type multipart))
5167 (widget-convert-button 'link from (point)
5168 :action 'gnus-widget-press-button
5169 :button-keymap gnus-widget-button-keymap)
5170 ;; Do the handles
5171 (while (setq handle (pop handles))
5172 (gnus-add-text-properties
5173 (setq from (point))
5174 (progn
5175 (insert (format "(%c) %-18s"
5176 (if (equal handle preferred) ?* ? )
5177 (mm-handle-media-type handle)))
5178 (point))
5179 `(gnus-callback
5180 (lambda (handles)
5181 (unless ,(not ibegend)
5182 (setq gnus-article-mime-handle-alist
5183 ',gnus-article-mime-handle-alist))
5184 (gnus-mime-display-alternative
5185 ',ihandles ',handle ',begend ,id))
5186 ,@(gnus-local-map-property gnus-mime-button-map)
5187 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5188 face ,gnus-article-button-face
5189 gnus-part ,id
5190 gnus-data ,handle))
5191 (widget-convert-button 'link from (point)
5192 :action 'gnus-widget-press-button
5193 :button-keymap gnus-widget-button-keymap)
5194 (insert " "))
5195 (insert "\n\n"))
5196 (when preferred
5197 (if (stringp (car preferred))
5198 (gnus-display-mime preferred)
5199 (let ((mail-parse-charset gnus-newsgroup-charset)
5200 (mail-parse-ignored-charsets
5201 (save-excursion (set-buffer gnus-summary-buffer)
5202 gnus-newsgroup-ignored-charsets)))
5203 (mm-display-part preferred)
5204 ;; Do highlighting.
5205 (save-excursion
5206 (save-restriction
5207 (narrow-to-region (car begend) (point-max))
5208 (gnus-treat-article
5209 nil (length gnus-article-mime-handle-alist)
5210 (gnus-article-mime-total-parts)
5211 (mm-handle-media-type handle))))))
5212 (goto-char (point-max))
5213 (setcdr begend (point-marker)))))
5214 (when ibegend
5215 (goto-char point))))
5216
5217 (defconst gnus-article-wash-status-strings
5218 (let ((alist '((cite "c" "Possible hidden citation text"
5219 " " "All citation text visible")
5220 (headers "h" "Hidden headers"
5221 " " "All headers visible.")
5222 (pgp "p" "Encrypted or signed message status hidden"
5223 " " "No hidden encryption nor digital signature status")
5224 (signature "s" "Signature has been hidden"
5225 " " "Signature is visible")
5226 (overstrike "o" "Overstrike (^H) characters applied"
5227 " " "No overstrike characters applied")
5228 (emphasis "e" "/*_Emphasis_*/ characters applied"
5229 " " "No /*_emphasis_*/ characters applied")))
5230 result)
5231 (dolist (entry alist result)
5232 (let ((key (nth 0 entry))
5233 (on (copy-sequence (nth 1 entry)))
5234 (on-help (nth 2 entry))
5235 (off (copy-sequence (nth 3 entry)))
5236 (off-help (nth 4 entry)))
5237 (put-text-property 0 1 'help-echo on-help on)
5238 (put-text-property 0 1 'help-echo off-help off)
5239 (push (list key on off) result))))
5240 "Alist of strings describing wash status in the mode line.
5241 Each entry has the form (KEY ON OF), where the KEY is a symbol
5242 representing the particular washing function, ON is the string to use
5243 in the article mode line when the washing function is active, and OFF
5244 is the string to use when it is inactive.")
5245
5246 (defun gnus-article-wash-status-entry (key value)
5247 (let ((entry (assoc key gnus-article-wash-status-strings)))
5248 (if value (nth 1 entry) (nth 2 entry))))
5249
5250 (defun gnus-article-wash-status ()
5251 "Return a string which display status of article washing."
5252 (save-excursion
5253 (set-buffer gnus-article-buffer)
5254 (let ((cite (memq 'cite gnus-article-wash-types))
5255 (headers (memq 'headers gnus-article-wash-types))
5256 (boring (memq 'boring-headers gnus-article-wash-types))
5257 (pgp (memq 'pgp gnus-article-wash-types))
5258 (pem (memq 'pem gnus-article-wash-types))
5259 (signed (memq 'signed gnus-article-wash-types))
5260 (encrypted (memq 'encrypted gnus-article-wash-types))
5261 (signature (memq 'signature gnus-article-wash-types))
5262 (overstrike (memq 'overstrike gnus-article-wash-types))
5263 (emphasis (memq 'emphasis gnus-article-wash-types)))
5264 (concat
5265 (gnus-article-wash-status-entry 'cite cite)
5266 (gnus-article-wash-status-entry 'headers (or headers boring))
5267 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5268 (gnus-article-wash-status-entry 'signature signature)
5269 (gnus-article-wash-status-entry 'overstrike overstrike)
5270 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5271
5272 (defun gnus-add-wash-type (type)
5273 "Add a washing of TYPE to the current status."
5274 (add-to-list 'gnus-article-wash-types type))
5275
5276 (defun gnus-delete-wash-type (type)
5277 "Add a washing of TYPE to the current status."
5278 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5279
5280 (defun gnus-add-image (category image)
5281 "Add IMAGE of CATEGORY to the list of displayed images."
5282 (let ((entry (assq category gnus-article-image-alist)))
5283 (unless entry
5284 (setq entry (list category))
5285 (push entry gnus-article-image-alist))
5286 (nconc entry (list image))))
5287
5288 (defun gnus-delete-images (category)
5289 "Delete all images in CATEGORY."
5290 (let ((entry (assq category gnus-article-image-alist)))
5291 (dolist (image (cdr entry))
5292 (gnus-remove-image image category))
5293 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5294 (gnus-delete-wash-type category)))
5295
5296 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5297
5298 (defun gnus-article-maybe-hide-headers ()
5299 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5300 Provided for backwards compatibility."
5301 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5302 (not (save-excursion (set-buffer gnus-summary-buffer)
5303 gnus-have-all-headers)))
5304 (not gnus-inhibit-hiding))
5305 (gnus-article-hide-headers)))
5306
5307 ;;; Article savers.
5308
5309 (defun gnus-output-to-file (file-name)
5310 "Append the current article to a file named FILE-NAME.
5311 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5312 text and used as the value of the coding cookie which is added to the
5313 top of a file. Otherwise, this function saves a raw article without
5314 the coding cookie."
5315 (let* ((artbuf (current-buffer))
5316 (file-name-coding-system nnmail-pathname-coding-system)
5317 (coding gnus-article-save-coding-system)
5318 (coding-system-for-read (if coding
5319 nil ;; Rely on the coding cookie.
5320 mm-text-coding-system))
5321 (coding-system-for-write (or coding
5322 mm-text-coding-system-for-write
5323 mm-text-coding-system))
5324 (exists (file-exists-p file-name)))
5325 (with-temp-buffer
5326 (when exists
5327 (insert-file-contents file-name)
5328 (goto-char (point-min))
5329 ;; Remove the existing coding cookie.
5330 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5331 (delete-region (match-beginning 0) (match-end 0))))
5332 (goto-char (point-max))
5333 (insert-buffer-substring artbuf)
5334 ;; Append newline at end of the buffer as separator, and then
5335 ;; save it to file.
5336 (goto-char (point-max))
5337 (insert "\n")
5338 (when coding
5339 ;; If the coding system is not suitable to encode the text,
5340 ;; ask a user for a proper one.
5341 (when (fboundp 'select-safe-coding-system)
5342 (setq coding (coding-system-base
5343 (save-window-excursion
5344 (select-safe-coding-system (point-min) (point-max)
5345 coding))))
5346 (setq coding-system-for-write
5347 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5348 coding)))
5349 (goto-char (point-min))
5350 ;; Add the coding cookie.
5351 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5352 coding-system-for-write)))
5353 (if exists
5354 (progn
5355 (write-region (point-min) (point-max) file-name nil 'no-message)
5356 (message "Appended to %s" file-name))
5357 (write-region (point-min) (point-max) file-name))))
5358 t)
5359
5360 (defun gnus-narrow-to-page (&optional arg)
5361 "Narrow the article buffer to a page.
5362 If given a numerical ARG, move forward ARG pages."
5363 (interactive "P")
5364 (setq arg (if arg (prefix-numeric-value arg) 0))
5365 (save-excursion
5366 (set-buffer gnus-article-buffer)
5367 (goto-char (point-min))
5368 (widen)
5369 ;; Remove any old next/prev buttons.
5370 (when (gnus-visual-p 'page-marker)
5371 (let ((inhibit-read-only t))
5372 (gnus-remove-text-with-property 'gnus-prev)
5373 (gnus-remove-text-with-property 'gnus-next)))
5374 (if
5375 (cond ((< arg 0)
5376 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5377 ((> arg 0)
5378 (re-search-forward page-delimiter nil 'move arg)))
5379 (goto-char (match-end 0))
5380 (save-excursion
5381 (goto-char (point-min))
5382 (setq gnus-page-broken
5383 (and (re-search-forward page-delimiter nil t) t))))
5384 (when gnus-page-broken
5385 (narrow-to-region
5386 (point)
5387 (if (re-search-forward page-delimiter nil 'move)
5388 (match-beginning 0)
5389 (point)))
5390 (when (and (gnus-visual-p 'page-marker)
5391 (> (point-min) (save-restriction (widen) (point-min))))
5392 (save-excursion
5393 (goto-char (point-min))
5394 (gnus-insert-prev-page-button)))
5395 (when (and (gnus-visual-p 'page-marker)
5396 (< (point-max) (save-restriction (widen) (point-max))))
5397 (save-excursion
5398 (goto-char (point-max))
5399 (gnus-insert-next-page-button))))))
5400
5401 ;; Article mode commands
5402
5403 (defun gnus-article-goto-next-page ()
5404 "Show the next page of the article."
5405 (interactive)
5406 (when (gnus-article-next-page)
5407 (goto-char (point-min))
5408 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5409
5410
5411 (defun gnus-article-goto-prev-page ()
5412 "Show the previous page of the article."
5413 (interactive)
5414 (if (bobp)
5415 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5416 (gnus-article-prev-page nil)))
5417
5418 ;; This is cleaner but currently breaks `gnus-pick-mode':
5419 ;;
5420 ;; (defun gnus-article-goto-next-page ()
5421 ;; "Show the next page of the article."
5422 ;; (interactive)
5423 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5424 ;; (gnus-summary-next-page)))
5425 ;;
5426 ;; (defun gnus-article-goto-prev-page ()
5427 ;; "Show the next page of the article."
5428 ;; (interactive)
5429 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5430 ;; (gnus-summary-prev-page)))
5431
5432 (defun gnus-article-next-page (&optional lines)
5433 "Show the next page of the current article.
5434 If end of article, return non-nil. Otherwise return nil.
5435 Argument LINES specifies lines to be scrolled up."
5436 (interactive "p")
5437 (move-to-window-line -1)
5438 (if (save-excursion
5439 (end-of-line)
5440 (and (pos-visible-in-window-p) ;Not continuation line.
5441 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5442 ;; Nothing in this page.
5443 (if (or (not gnus-page-broken)
5444 (save-excursion
5445 (save-restriction
5446 (widen)
5447 (forward-line)
5448 (eobp)))) ;Real end-of-buffer?
5449 (progn
5450 (when gnus-article-over-scroll
5451 (gnus-article-next-page-1 lines))
5452 t) ;Nothing more.
5453 (gnus-narrow-to-page 1) ;Go to next page.
5454 nil)
5455 ;; More in this page.
5456 (gnus-article-next-page-1 lines)
5457 nil))
5458
5459 (defmacro gnus-article-beginning-of-window ()
5460 "Move point to the beginning of the window.
5461 In Emacs, the point is placed at the line number which `scroll-margin'
5462 specifies."
5463 (if (featurep 'xemacs)
5464 '(move-to-window-line 0)
5465 '(move-to-window-line
5466 (min (max 0 scroll-margin)
5467 (max 1 (- (window-height)
5468 (if mode-line-format 1 0)
5469 (if (and (boundp 'header-line-format)
5470 (symbol-value 'header-line-format))
5471 1 0)))))))
5472
5473 (defun gnus-article-next-page-1 (lines)
5474 (when (and (not (featurep 'xemacs))
5475 (numberp lines)
5476 (> lines 0)
5477 (numberp (symbol-value 'scroll-margin))
5478 (> (symbol-value 'scroll-margin) 0))
5479 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5480 ;; too many number of lines if `scroll-margin' is set as two or greater.
5481 (setq lines (min lines
5482 (max 0 (- (count-lines (window-start) (point-max))
5483 (symbol-value 'scroll-margin))))))
5484 (condition-case ()
5485 (let ((scroll-in-place nil))
5486 (scroll-up lines))
5487 (end-of-buffer
5488 ;; Long lines may cause an end-of-buffer error.
5489 (goto-char (point-max))))
5490 (gnus-article-beginning-of-window))
5491
5492 (defun gnus-article-prev-page (&optional lines)
5493 "Show previous page of current article.
5494 Argument LINES specifies lines to be scrolled down."
5495 (interactive "p")
5496 (move-to-window-line 0)
5497 (if (and gnus-page-broken
5498 (bobp)
5499 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5500 (progn
5501 (gnus-narrow-to-page -1) ;Go to previous page.
5502 (goto-char (point-max))
5503 (recenter -1))
5504 (prog1
5505 (condition-case ()
5506 (let ((scroll-in-place nil))
5507 (scroll-down lines))
5508 (beginning-of-buffer
5509 (goto-char (point-min))))
5510 (gnus-article-beginning-of-window))))
5511
5512 (defun gnus-article-only-boring-p ()
5513 "Decide whether there is only boring text remaining in the article.
5514 Something \"interesting\" is a word of at least two letters that does
5515 not have a face in `gnus-article-boring-faces'."
5516 (when (and gnus-article-skip-boring
5517 (boundp 'gnus-article-boring-faces)
5518 (symbol-value 'gnus-article-boring-faces))
5519 (save-excursion
5520 (let ((inhibit-point-motion-hooks t))
5521 (catch 'only-boring
5522 (while (re-search-forward "\\b\\w\\w" nil t)
5523 (forward-char -1)
5524 (when (not (gnus-intersection
5525 (gnus-faces-at (point))
5526 (symbol-value 'gnus-article-boring-faces)))
5527 (throw 'only-boring nil)))
5528 (throw 'only-boring t))))))
5529
5530 (defun gnus-article-refer-article ()
5531 "Read article specified by message-id around point."
5532 (interactive)
5533 (save-excursion
5534 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5535 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5536 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5537 (let ((msg-id (concat "<" (match-string 0) ">")))
5538 (set-buffer gnus-summary-buffer)
5539 (gnus-summary-refer-article msg-id))
5540 (error "No references around point"))))
5541
5542 (defun gnus-article-show-summary ()
5543 "Reconfigure windows to show summary buffer."
5544 (interactive)
5545 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5546 (error "There is no summary buffer for this article buffer")
5547 (gnus-article-set-globals)
5548 (gnus-configure-windows 'article)
5549 (gnus-summary-goto-subject gnus-current-article)
5550 (gnus-summary-position-point)))
5551
5552 (defun gnus-article-describe-briefly ()
5553 "Describe article mode commands briefly."
5554 (interactive)
5555 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
5556
5557 (defun gnus-article-summary-command ()
5558 "Execute the last keystroke in the summary buffer."
5559 (interactive)
5560 (let ((obuf (current-buffer))
5561 (owin (current-window-configuration))
5562 func)
5563 (switch-to-buffer gnus-article-current-summary 'norecord)
5564 (setq func (lookup-key (current-local-map) (this-command-keys)))
5565 (call-interactively func)
5566 (set-buffer obuf)
5567 (set-window-configuration owin)
5568 (set-window-point (get-buffer-window (current-buffer)) (point))))
5569
5570 (defun gnus-article-summary-command-nosave ()
5571 "Execute the last keystroke in the summary buffer."
5572 (interactive)
5573 (let (func)
5574 (pop-to-buffer gnus-article-current-summary 'norecord)
5575 (setq func (lookup-key (current-local-map) (this-command-keys)))
5576 (call-interactively func)))
5577
5578 (defun gnus-article-check-buffer ()
5579 "Beep if not in an article buffer."
5580 (unless (equal major-mode 'gnus-article-mode)
5581 (error "Command invoked outside of a Gnus article buffer")))
5582
5583 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5584 "Read a summary buffer key sequence and execute it from the article buffer."
5585 (interactive "P")
5586 (gnus-article-check-buffer)
5587 (let ((nosaves
5588 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5589 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5590 "=" "^" "\M-^" "|"))
5591 (nosave-but-article
5592 '("A\r"))
5593 (nosave-in-article
5594 '("\C-d"))
5595 (up-to-top
5596 '("n" "Gn" "p" "Gp"))
5597 keys new-sum-point)
5598 (save-excursion
5599 (set-buffer gnus-article-current-summary)
5600 (let (gnus-pick-mode)
5601 (push (or key last-command-event) unread-command-events)
5602 (setq keys (if (featurep 'xemacs)
5603 (events-to-keys (read-key-sequence nil))
5604 (read-key-sequence nil)))))
5605
5606 (message "")
5607
5608 (if (or (member keys nosaves)
5609 (member keys nosave-but-article)
5610 (member keys nosave-in-article))
5611 (let (func)
5612 (save-window-excursion
5613 (pop-to-buffer gnus-article-current-summary 'norecord)
5614 ;; We disable the pick minor mode commands.
5615 (let (gnus-pick-mode)
5616 (setq func (lookup-key (current-local-map) keys))))
5617 (if (or (not func)
5618 (numberp func))
5619 (ding)
5620 (unless (member keys nosave-in-article)
5621 (set-buffer gnus-article-current-summary))
5622 (call-interactively func)
5623 (setq new-sum-point (point)))
5624 (when (member keys nosave-but-article)
5625 (pop-to-buffer gnus-article-buffer 'norecord)))
5626 ;; These commands should restore window configuration.
5627 (let ((obuf (current-buffer))
5628 (owin (current-window-configuration))
5629 (opoint (point))
5630 win func in-buffer selected new-sum-start new-sum-hscroll)
5631 (cond (not-restore-window
5632 (pop-to-buffer gnus-article-current-summary 'norecord))
5633 ((setq win (get-buffer-window gnus-article-current-summary))
5634 (select-window win))
5635 (t
5636 (switch-to-buffer gnus-article-current-summary 'norecord)))
5637 (setq in-buffer (current-buffer))
5638 ;; We disable the pick minor mode commands.
5639 (if (and (setq func (let (gnus-pick-mode)
5640 (lookup-key (current-local-map) keys)))
5641 (functionp func))
5642 (progn
5643 (call-interactively func)
5644 (when (eq win (selected-window))
5645 (setq new-sum-point (point)
5646 new-sum-start (window-start win)
5647 new-sum-hscroll (window-hscroll win)))
5648 (when (eq in-buffer (current-buffer))
5649 (setq selected (gnus-summary-select-article))
5650 (set-buffer obuf)
5651 (unless not-restore-window
5652 (set-window-configuration owin))
5653 (when (eq selected 'old)
5654 (article-goto-body)
5655 (set-window-start (get-buffer-window (current-buffer))
5656 1)
5657 (set-window-point (get-buffer-window (current-buffer))
5658 (point)))
5659 (when (and (not not-restore-window)
5660 new-sum-point)
5661 (set-window-point win new-sum-point)
5662 (set-window-start win new-sum-start)
5663 (set-window-hscroll win new-sum-hscroll))))
5664 (set-window-configuration owin)
5665 (ding))))))
5666
5667 (defun gnus-article-describe-key (key)
5668 "Display documentation of the function invoked by KEY. KEY is a string."
5669 (interactive "kDescribe key: ")
5670 (gnus-article-check-buffer)
5671 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5672 (save-excursion
5673 (set-buffer gnus-article-current-summary)
5674 (let (gnus-pick-mode)
5675 (if (featurep 'xemacs)
5676 (progn
5677 (push (elt key 0) unread-command-events)
5678 (setq key (events-to-keys
5679 (read-key-sequence "Describe key: "))))
5680 (setq unread-command-events
5681 (mapcar
5682 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5683 (string-to-list key)))
5684 (setq key (read-key-sequence "Describe key: "))))
5685 (describe-key key))
5686 (describe-key key)))
5687
5688 (defun gnus-article-describe-key-briefly (key &optional insert)
5689 "Display documentation of the function invoked by KEY. KEY is a string."
5690 (interactive "kDescribe key: \nP")
5691 (gnus-article-check-buffer)
5692 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5693 (save-excursion
5694 (set-buffer gnus-article-current-summary)
5695 (let (gnus-pick-mode)
5696 (if (featurep 'xemacs)
5697 (progn
5698 (push (elt key 0) unread-command-events)
5699 (setq key (events-to-keys
5700 (read-key-sequence "Describe key: "))))
5701 (setq unread-command-events
5702 (mapcar
5703 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5704 (string-to-list key)))
5705 (setq key (read-key-sequence "Describe key: "))))
5706 (describe-key-briefly key insert))
5707 (describe-key-briefly key insert)))
5708
5709 (defun gnus-article-reply-with-original (&optional wide)
5710 "Start composing a reply mail to the current message.
5711 The text in the region will be yanked. If the region isn't active,
5712 the entire article will be yanked."
5713 (interactive "P")
5714 (let ((article (cdr gnus-article-current))
5715 contents)
5716 (if (not (gnus-mark-active-p))
5717 (with-current-buffer gnus-summary-buffer
5718 (gnus-summary-reply (list (list article)) wide))
5719 (setq contents (buffer-substring (point) (mark t)))
5720 ;; Deactivate active regions.
5721 (when (and (boundp 'transient-mark-mode)
5722 transient-mark-mode)
5723 (setq mark-active nil))
5724 (with-current-buffer gnus-summary-buffer
5725 (gnus-summary-reply
5726 (list (list article contents)) wide)))))
5727
5728 (defun gnus-article-followup-with-original ()
5729 "Compose a followup to the current article.
5730 The text in the region will be yanked. If the region isn't active,
5731 the entire article will be yanked."
5732 (interactive)
5733 (let ((article (cdr gnus-article-current))
5734 contents)
5735 (if (not (gnus-mark-active-p))
5736 (with-current-buffer gnus-summary-buffer
5737 (gnus-summary-followup (list (list article))))
5738 (setq contents (buffer-substring (point) (mark t)))
5739 ;; Deactivate active regions.
5740 (when (and (boundp 'transient-mark-mode)
5741 transient-mark-mode)
5742 (setq mark-active nil))
5743 (with-current-buffer gnus-summary-buffer
5744 (gnus-summary-followup
5745 (list (list article contents)))))))
5746
5747 (defun gnus-article-hide (&optional arg force)
5748 "Hide all the gruft in the current article.
5749 This means that signatures, cited text and (some) headers will be
5750 hidden.
5751 If given a prefix, show the hidden text instead."
5752 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5753 (gnus-article-hide-headers arg)
5754 (gnus-article-hide-list-identifiers arg)
5755 (gnus-article-hide-citation-maybe arg force)
5756 (gnus-article-hide-signature arg))
5757
5758 (defun gnus-article-maybe-highlight ()
5759 "Do some article highlighting if article highlighting is requested."
5760 (when (gnus-visual-p 'article-highlight 'highlight)
5761 (gnus-article-highlight-some)))
5762
5763 (defun gnus-check-group-server ()
5764 ;; Make sure the connection to the server is alive.
5765 (unless (gnus-server-opened
5766 (gnus-find-method-for-group gnus-newsgroup-name))
5767 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5768 (gnus-request-group gnus-newsgroup-name t)))
5769
5770 (eval-when-compile
5771 (autoload 'nneething-get-file-name "nneething"))
5772
5773 (defun gnus-request-article-this-buffer (article group)
5774 "Get an article and insert it into this buffer."
5775 (let (do-update-line sparse-header)
5776 (prog1
5777 (save-excursion
5778 (erase-buffer)
5779 (gnus-kill-all-overlays)
5780 (setq group (or group gnus-newsgroup-name))
5781
5782 ;; Using `gnus-request-article' directly will insert the article into
5783 ;; `nntp-server-buffer' - so we'll save some time by not having to
5784 ;; copy it from the server buffer into the article buffer.
5785
5786 ;; We only request an article by message-id when we do not have the
5787 ;; headers for it, so we'll have to get those.
5788 (when (stringp article)
5789 (gnus-read-header article))
5790
5791 ;; If the article number is negative, that means that this article
5792 ;; doesn't belong in this newsgroup (possibly), so we find its
5793 ;; message-id and request it by id instead of number.
5794 (when (and (numberp article)
5795 gnus-summary-buffer
5796 (get-buffer gnus-summary-buffer)
5797 (gnus-buffer-exists-p gnus-summary-buffer))
5798 (save-excursion
5799 (set-buffer gnus-summary-buffer)
5800 (let ((header (gnus-summary-article-header article)))
5801 (when (< article 0)
5802 (cond
5803 ((memq article gnus-newsgroup-sparse)
5804 ;; This is a sparse gap article.
5805 (setq do-update-line article)
5806 (setq article (mail-header-id header))
5807 (setq sparse-header (gnus-read-header article))
5808 (setq gnus-newsgroup-sparse
5809 (delq article gnus-newsgroup-sparse)))
5810 ((vectorp header)
5811 ;; It's a real article.
5812 (setq article (mail-header-id header)))
5813 (t
5814 ;; It is an extracted pseudo-article.
5815 (setq article 'pseudo)
5816 (gnus-request-pseudo-article header))))
5817
5818 (let ((method (gnus-find-method-for-group
5819 gnus-newsgroup-name)))
5820 (when (and (eq (car method) 'nneething)
5821 (vectorp header))
5822 (let ((dir (nneething-get-file-name
5823 (mail-header-id header))))
5824 (when (and (stringp dir)
5825 (file-directory-p dir))
5826 (setq article 'nneething)
5827 (gnus-group-enter-directory dir))))))))
5828
5829 (cond
5830 ;; Refuse to select canceled articles.
5831 ((and (numberp article)
5832 gnus-summary-buffer
5833 (get-buffer gnus-summary-buffer)
5834 (gnus-buffer-exists-p gnus-summary-buffer)
5835 (eq (cdr (save-excursion
5836 (set-buffer gnus-summary-buffer)
5837 (assq article gnus-newsgroup-reads)))
5838 gnus-canceled-mark))
5839 nil)
5840 ;; We first check `gnus-original-article-buffer'.
5841 ((and (get-buffer gnus-original-article-buffer)
5842 (numberp article)
5843 (save-excursion
5844 (set-buffer gnus-original-article-buffer)
5845 (and (equal (car gnus-original-article) group)
5846 (eq (cdr gnus-original-article) article))))
5847 (insert-buffer-substring gnus-original-article-buffer)
5848 'article)
5849 ;; Check the backlog.
5850 ((and gnus-keep-backlog
5851 (gnus-backlog-request-article group article (current-buffer)))
5852 'article)
5853 ;; Check asynchronous pre-fetch.
5854 ((gnus-async-request-fetched-article group article (current-buffer))
5855 (gnus-async-prefetch-next group article gnus-summary-buffer)
5856 (when (and (numberp article) gnus-keep-backlog)
5857 (gnus-backlog-enter-article group article (current-buffer)))
5858 'article)
5859 ;; Check the cache.
5860 ((and gnus-use-cache
5861 (numberp article)
5862 (gnus-cache-request-article article group))
5863 'article)
5864 ;; Check the agent cache.
5865 ((gnus-agent-request-article article group)
5866 'article)
5867 ;; Get the article and put into the article buffer.
5868 ((or (stringp article)
5869 (numberp article))
5870 (let ((gnus-override-method gnus-override-method)
5871 (methods (and (stringp article)
5872 gnus-refer-article-method))
5873 (backend (car (gnus-find-method-for-group
5874 gnus-newsgroup-name)))
5875 result
5876 (inhibit-read-only t))
5877 (if (or (not (listp methods))
5878 (and (symbolp (car methods))
5879 (assq (car methods) nnoo-definition-alist)))
5880 (setq methods (list methods)))
5881 (when (and (null gnus-override-method)
5882 methods)
5883 (setq gnus-override-method (pop methods)))
5884 (while (not result)
5885 (when (eq gnus-override-method 'current)
5886 (setq gnus-override-method
5887 (with-current-buffer gnus-summary-buffer
5888 gnus-current-select-method)))
5889 (erase-buffer)
5890 (gnus-kill-all-overlays)
5891 (let ((gnus-newsgroup-name group))
5892 (gnus-check-group-server))
5893 (cond
5894 ((gnus-request-article article group (current-buffer))
5895 (when (numberp article)
5896 (gnus-async-prefetch-next group article
5897 gnus-summary-buffer)
5898 (when gnus-keep-backlog
5899 (gnus-backlog-enter-article
5900 group article (current-buffer))))
5901 (setq result 'article))
5902 (methods
5903 (setq gnus-override-method (pop methods)))
5904 ((not (string-match "^400 "
5905 (nnheader-get-report backend)))
5906 ;; If we get 400 server disconnect, reconnect and
5907 ;; retry; otherwise, assume the article has expired.
5908 (setq result 'done))))
5909 (and (eq result 'article) 'article)))
5910 ;; It was a pseudo.
5911 (t article)))
5912
5913 ;; Associate this article with the current summary buffer.
5914 (setq gnus-article-current-summary gnus-summary-buffer)
5915
5916 ;; Take the article from the original article buffer
5917 ;; and place it in the buffer it's supposed to be in.
5918 (when (and (get-buffer gnus-article-buffer)
5919 (equal (buffer-name (current-buffer))
5920 (buffer-name (get-buffer gnus-article-buffer))))
5921 (save-excursion
5922 (if (get-buffer gnus-original-article-buffer)
5923 (set-buffer gnus-original-article-buffer)
5924 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5925 (buffer-disable-undo)
5926 (setq major-mode 'gnus-original-article-mode)
5927 (setq buffer-read-only t))
5928 (let ((inhibit-read-only t))
5929 (erase-buffer)
5930 (insert-buffer-substring gnus-article-buffer))
5931 (setq gnus-original-article (cons group article)))
5932
5933 ;; Decode charsets.
5934 (run-hooks 'gnus-article-decode-hook)
5935 ;; Mark article as decoded or not.
5936 (setq gnus-article-decoded-p gnus-article-decode-hook))
5937
5938 ;; Update sparse articles.
5939 (when (and do-update-line
5940 (or (numberp article)
5941 (stringp article)))
5942 (let ((buf (current-buffer)))
5943 (set-buffer gnus-summary-buffer)
5944 (gnus-summary-update-article do-update-line sparse-header)
5945 (gnus-summary-goto-subject do-update-line nil t)
5946 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5947 (point))
5948 (set-buffer buf))))))
5949
5950 ;;;
5951 ;;; Article editing
5952 ;;;
5953
5954 (defcustom gnus-article-edit-mode-hook nil
5955 "Hook run in article edit mode buffers."
5956 :group 'gnus-article-various
5957 :type 'hook)
5958
5959 (defvar gnus-article-edit-done-function nil)
5960
5961 (defvar gnus-article-edit-mode-map nil)
5962 (defvar gnus-article-edit-mode nil)
5963
5964 ;; Should we be using derived.el for this?
5965 (unless gnus-article-edit-mode-map
5966 (setq gnus-article-edit-mode-map (make-keymap))
5967 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5968
5969 (gnus-define-keys gnus-article-edit-mode-map
5970 "\C-c?" describe-mode
5971 "\C-c\C-c" gnus-article-edit-done
5972 "\C-c\C-k" gnus-article-edit-exit
5973 "\C-c\C-f\C-t" message-goto-to
5974 "\C-c\C-f\C-o" message-goto-from
5975 "\C-c\C-f\C-b" message-goto-bcc
5976 ;;"\C-c\C-f\C-w" message-goto-fcc
5977 "\C-c\C-f\C-c" message-goto-cc
5978 "\C-c\C-f\C-s" message-goto-subject
5979 "\C-c\C-f\C-r" message-goto-reply-to
5980 "\C-c\C-f\C-n" message-goto-newsgroups
5981 "\C-c\C-f\C-d" message-goto-distribution
5982 "\C-c\C-f\C-f" message-goto-followup-to
5983 "\C-c\C-f\C-m" message-goto-mail-followup-to
5984 "\C-c\C-f\C-k" message-goto-keywords
5985 "\C-c\C-f\C-u" message-goto-summary
5986 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5987 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5988 "\C-c\C-b" message-goto-body
5989 "\C-c\C-i" message-goto-signature
5990
5991 "\C-c\C-t" message-insert-to
5992 "\C-c\C-n" message-insert-newsgroups
5993 "\C-c\C-o" message-sort-headers
5994 "\C-c\C-e" message-elide-region
5995 "\C-c\C-v" message-delete-not-region
5996 "\C-c\C-z" message-kill-to-signature
5997 "\M-\r" message-newline-and-reformat
5998 "\C-c\C-a" mml-attach-file
5999 "\C-a" message-beginning-of-line
6000 "\t" message-tab
6001 "\M-;" comment-region)
6002
6003 (gnus-define-keys (gnus-article-edit-wash-map
6004 "\C-c\C-w" gnus-article-edit-mode-map)
6005 "f" gnus-article-edit-full-stops))
6006
6007 (easy-menu-define
6008 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6009 '("Field"
6010 ["Fetch To" message-insert-to t]
6011 ["Fetch Newsgroups" message-insert-newsgroups t]
6012 "----"
6013 ["To" message-goto-to t]
6014 ["From" message-goto-from t]
6015 ["Subject" message-goto-subject t]
6016 ["Cc" message-goto-cc t]
6017 ["Reply-To" message-goto-reply-to t]
6018 ["Summary" message-goto-summary t]
6019 ["Keywords" message-goto-keywords t]
6020 ["Newsgroups" message-goto-newsgroups t]
6021 ["Followup-To" message-goto-followup-to t]
6022 ["Mail-Followup-To" message-goto-mail-followup-to t]
6023 ["Distribution" message-goto-distribution t]
6024 ["Body" message-goto-body t]
6025 ["Signature" message-goto-signature t]))
6026
6027 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6028 "Major mode for editing articles.
6029 This is an extended text-mode.
6030
6031 \\{gnus-article-edit-mode-map}"
6032 (make-local-variable 'gnus-article-edit-done-function)
6033 (make-local-variable 'gnus-prev-winconf)
6034 (set (make-local-variable 'font-lock-defaults)
6035 '(message-font-lock-keywords t))
6036 (set (make-local-variable 'mail-header-separator) "")
6037 (set (make-local-variable 'gnus-article-edit-mode) t)
6038 (easy-menu-add message-mode-field-menu message-mode-map)
6039 (mml-mode)
6040 (setq buffer-read-only nil)
6041 (buffer-enable-undo)
6042 (widen))
6043
6044 (defun gnus-article-edit (&optional force)
6045 "Edit the current article.
6046 This will have permanent effect only in mail groups.
6047 If FORCE is non-nil, allow editing of articles even in read-only
6048 groups."
6049 (interactive "P")
6050 (when (and (not force)
6051 (gnus-group-read-only-p))
6052 (error "The current newsgroup does not support article editing"))
6053 (gnus-article-date-original)
6054 (gnus-article-edit-article
6055 'ignore
6056 `(lambda (no-highlight)
6057 'ignore
6058 (gnus-summary-edit-article-done
6059 ,(or (mail-header-references gnus-current-headers) "")
6060 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6061
6062 (defun gnus-article-edit-article (start-func exit-func)
6063 "Start editing the contents of the current article buffer."
6064 (let ((winconf (current-window-configuration)))
6065 (set-buffer gnus-article-buffer)
6066 (let ((message-auto-save-directory
6067 ;; Don't associate the article buffer with a draft file.
6068 nil))
6069 (gnus-article-edit-mode))
6070 (funcall start-func)
6071 (set-buffer-modified-p nil)
6072 (gnus-configure-windows 'edit-article)
6073 (setq gnus-article-edit-done-function exit-func)
6074 (setq gnus-prev-winconf winconf)
6075 (gnus-message 6 "C-c C-c to end edits")))
6076
6077 (defun gnus-article-edit-done (&optional arg)
6078 "Update the article edits and exit."
6079 (interactive "P")
6080 (let ((func gnus-article-edit-done-function)
6081 (buf (current-buffer))
6082 (start (window-start))
6083 (p (point))
6084 (winconf gnus-prev-winconf))
6085 (widen) ;; Widen it in case that users narrowed the buffer.
6086 (funcall func arg)
6087 (set-buffer buf)
6088 ;; The cache and backlog have to be flushed somewhat.
6089 (when gnus-keep-backlog
6090 (gnus-backlog-remove-article
6091 (car gnus-article-current) (cdr gnus-article-current)))
6092 ;; Flush original article as well.
6093 (save-excursion
6094 (when (get-buffer gnus-original-article-buffer)
6095 (set-buffer gnus-original-article-buffer)
6096 (setq gnus-original-article nil)))
6097 (when gnus-use-cache
6098 (gnus-cache-update-article
6099 (car gnus-article-current) (cdr gnus-article-current)))
6100 ;; We remove all text props from the article buffer.
6101 (kill-all-local-variables)
6102 (gnus-set-text-properties (point-min) (point-max) nil)
6103 (gnus-article-mode)
6104 (set-window-configuration winconf)
6105 (set-buffer buf)
6106 (set-window-start (get-buffer-window buf) start)
6107 (set-window-point (get-buffer-window buf) (point)))
6108 (gnus-summary-show-article))
6109
6110 (defun gnus-article-edit-exit ()
6111 "Exit the article editing without updating."
6112 (interactive)
6113 (when (or (not (buffer-modified-p))
6114 (yes-or-no-p "Article modified; kill anyway? "))
6115 (let ((curbuf (current-buffer))
6116 (p (point))
6117 (window-start (window-start)))
6118 (erase-buffer)
6119 (if (gnus-buffer-live-p gnus-original-article-buffer)
6120 (insert-buffer-substring gnus-original-article-buffer))
6121 (let ((winconf gnus-prev-winconf))
6122 (kill-all-local-variables)
6123 (gnus-article-mode)
6124 (set-window-configuration winconf)
6125 ;; Tippy-toe some to make sure that point remains where it was.
6126 (save-current-buffer
6127 (set-buffer curbuf)
6128 (set-window-start (get-buffer-window (current-buffer)) window-start)
6129 (goto-char p))))
6130 (gnus-summary-show-article)))
6131
6132 (defun gnus-article-edit-full-stops ()
6133 "Interactively repair spacing at end of sentences."
6134 (interactive)
6135 (save-excursion
6136 (goto-char (point-min))
6137 (search-forward-regexp "^$" nil t)
6138 (let ((case-fold-search nil))
6139 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6140
6141 ;;;
6142 ;;; Article highlights
6143 ;;;
6144
6145 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6146
6147 ;;; Internal Variables:
6148
6149 (defcustom gnus-button-url-regexp
6150 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6151 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
6152 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
6153 "Regular expression that matches URLs."
6154 :group 'gnus-article-buttons
6155 :type 'regexp)
6156
6157 (defcustom gnus-button-valid-fqdn-regexp
6158 message-valid-fqdn-regexp
6159 "Regular expression that matches a valid FQDN."
6160 :version "22.1"
6161 :group 'gnus-article-buttons
6162 :type 'regexp)
6163
6164 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6165 (defcustom gnus-button-valid-localpart-regexp
6166 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6167 "Regular expression that matches a localpart of mail addresses or MIDs."
6168 :version "22.1"
6169 :group 'gnus-article-buttons
6170 :type 'regexp)
6171
6172 (defcustom gnus-button-man-handler 'manual-entry
6173 "Function to use for displaying man pages.
6174 The function must take at least one argument with a string naming the
6175 man page."
6176 :version "22.1"
6177 :type '(choice (function-item :tag "Man" manual-entry)
6178 (function-item :tag "Woman" woman)
6179 (function :tag "Other"))
6180 :group 'gnus-article-buttons)
6181
6182 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6183 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6184 If the default site is too slow, try to find a CTAN mirror, see
6185 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6186 the variable `gnus-button-handle-ctan'."
6187 :version "22.1"
6188 :group 'gnus-article-buttons
6189 :link '(custom-manual "(gnus)Group Parameters")
6190 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6191 (const "http://tug.ctan.org/tex-archive/")
6192 (const "http://www.dante.de/CTAN/")
6193 (string :tag "Other")))
6194
6195 (defcustom gnus-button-ctan-handler 'browse-url
6196 "Function to use for displaying CTAN links.
6197 The function must take one argument, the string naming the URL."
6198 :version "22.1"
6199 :type '(choice (function-item :tag "Browse Url" browse-url)
6200 (function :tag "Other"))
6201 :group 'gnus-article-buttons)
6202
6203 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6204 "Bogus strings removed from CTAN URLs."
6205 :version "22.1"
6206 :group 'gnus-article-buttons
6207 :type '(choice (const "^/?tex-archive/\\|/")
6208 (regexp :tag "Other")))
6209
6210 (defcustom gnus-button-ctan-directory-regexp
6211 (regexp-opt
6212 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6213 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6214 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6215 "tds" "tools" "usergrps" "web") t)
6216 "Regular expression for ctan directories.
6217 It should match all directories in the top level of `gnus-ctan-url'."
6218 :version "22.1"
6219 :group 'gnus-article-buttons
6220 :type 'regexp)
6221
6222 (defcustom gnus-button-mid-or-mail-regexp
6223 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6224 gnus-button-valid-fqdn-regexp
6225 ">?\\)\\b")
6226 "Regular expression that matches a message ID or a mail address."
6227 :version "22.1"
6228 :group 'gnus-article-buttons
6229 :type 'regexp)
6230
6231 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6232 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6233 Strings like this can be either a message ID or a mail address. If it is one
6234 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6235 message ID or a mail address, respectively. If this variable is set to the
6236 symbol `ask', always query the user what do do. If it is a function, this
6237 function will be called with the string as it's only argument. The function
6238 must return `mid', `mail', `invalid' or `ask'."
6239 :version "22.1"
6240 :group 'gnus-article-buttons
6241 :type '(choice (function-item :tag "Heuristic function"
6242 gnus-button-mid-or-mail-heuristic)
6243 (const ask)
6244 (const mid)
6245 (const mail)))
6246
6247 (defcustom gnus-button-mid-or-mail-heuristic-alist
6248 '((-10.0 . ".+\\$.+@")
6249 (-10.0 . "#")
6250 (-10.0 . "\\*")
6251 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6252 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6253 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6254 (-1.0 . "^[^a-z]+@")
6255 ;;
6256 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6257 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6258 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6259 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6260 ;;
6261 (-2.0 . "^[0-9]")
6262 (-1.0 . "^[0-9][0-9]")
6263 ;;
6264 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6265 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6266 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6267 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6268 ;;
6269 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6270 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6271 ;; "[0-9]{8,}.*\@"
6272 (-3.0
6273 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6274 ;; "[0-9]{12,}.*\@"
6275 ;; compensation for TDMA dated mail addresses:
6276 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6277 ;;
6278 (-20.0 . "\\.fsf@") ;; Gnus
6279 (-20.0 . "^slrn")
6280 (-20.0 . "^Pine")
6281 (-20.0 . "_-_") ;; Subject change in thread
6282 ;;
6283 (-20.0 . "\\.ln@") ;; leafnode
6284 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6285 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6286 ;;
6287 ;; (5.0 . "") ;; $local_part_len <= 7
6288 (10.0 . "^[^0-9]+@")
6289 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6290 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6291 (3.0 . "\@stud")
6292 ;;
6293 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6294 ;;
6295 (0.5 . "^[A-Z][a-z]")
6296 (0.5 . "^[A-Z][a-z][a-z]")
6297 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6298 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6299 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6300
6301 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6302 address. The REGEXP is processed with `case-fold-search' set to nil."
6303 :version "22.1"
6304 :group 'gnus-article-buttons
6305 :type '(repeat (cons (number :tag "Rate")
6306 (regexp :tag "Regexp"))))
6307
6308 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6309 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6310 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6311 address, `ask' if unsure and `invalid' if the string is invalid."
6312 (let ((case-fold-search nil)
6313 (list gnus-button-mid-or-mail-heuristic-alist)
6314 (result 0) rate regexp lpartlen elem)
6315 (setq lpartlen
6316 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6317 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6318 ;; Certain special cases...
6319 (when (string-match
6320 (concat
6321 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6322 "^[0-9]+\\.[0-9]+@compuserve\\|"
6323 "@public\\.gmane\\.org")
6324 mid-or-mail)
6325 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6326 (setq result 'mail))
6327 (when (string-match "@.*@\\| " mid-or-mail)
6328 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6329 (setq result 'invalid))
6330 ;; Nothing more to do, if result is not a number here...
6331 (when (numberp result)
6332 (while list
6333 (setq elem (car list)
6334 rate (car elem)
6335 regexp (cdr elem)
6336 list (cdr list))
6337 (when (string-match regexp mid-or-mail)
6338 (setq result (+ result rate))
6339 (gnus-message
6340 9 "`%s' matched `%s', rate `%s', result `%s'."
6341 mid-or-mail regexp rate result)))
6342 (when (<= lpartlen 7)
6343 (setq result (+ result 5.0))
6344 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6345 mid-or-mail result))
6346 (when (>= lpartlen 12)
6347 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6348 (cond
6349 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6350 ;; Long local part should contain realname if e-mail address,
6351 ;; too many digits: message-id.
6352 ;; $score -= 5.0 + 0.1 * $local_part_len;
6353 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6354 (setq result (+ result rate))
6355 (gnus-message
6356 9 "Many digits in `%s', rate `%s', result `%s'."
6357 mid-or-mail rate result))
6358 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6359 mid-or-mail)
6360 ;; Too few vowels [^aeiouy]{4,}.*\@
6361 (setq result (+ result -5.0))
6362 (gnus-message
6363 9 "Few vowels in `%s', rate `%s', result `%s'."
6364 mid-or-mail -5.0 result))
6365 (t
6366 (setq result (+ result 5.0))
6367 (gnus-message
6368 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6369 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6370 ;; Maybe we should make this a customizable alist: (condition . 'result)
6371 (cond
6372 ((symbolp result) result)
6373 ;; Now convert number into proper results:
6374 ((< result -10.0) 'mid)
6375 ((> result 10.0) 'mail)
6376 (t 'ask))))
6377
6378 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6379 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6380 (url-mid (concat "news" ":" mid-or-mail))
6381 (url-mailto (concat "mailto" ":" mid-or-mail)))
6382 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6383 (when (fboundp pref)
6384 (setq guessed
6385 ;; get rid of surrounding angles...
6386 (funcall pref
6387 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6388 (if (or (eq 'mid guessed) (eq 'mail guessed))
6389 (setq pref guessed)
6390 (setq pref 'ask)))
6391 (if (eq pref 'ask)
6392 (save-window-excursion
6393 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6394 (setq pref 'mail)
6395 (setq pref 'mid))))
6396 (cond ((eq pref 'mid)
6397 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6398 (gnus-button-handle-news url-mid))
6399 ((eq pref 'mail)
6400 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6401 (gnus-url-mailto url-mailto))
6402 (t (gnus-message 3 "Invalid string.")))))
6403
6404 (defun gnus-button-handle-custom (url)
6405 "Follow a Custom URL."
6406 (customize-apropos (gnus-url-unhex-string url)))
6407
6408 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6409
6410 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6411 ;; stuff?
6412
6413 (defun gnus-button-handle-describe-function (url)
6414 "Call `describe-function' when pushing the corresponding URL button."
6415 (describe-function
6416 (intern
6417 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6418
6419 (defun gnus-button-handle-describe-variable (url)
6420 "Call `describe-variable' when pushing the corresponding URL button."
6421 (describe-variable
6422 (intern
6423 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6424
6425 (defun gnus-button-handle-symbol (url)
6426 "Display help on variable or function.
6427 Calls `describe-variable' or `describe-function'."
6428 (let ((sym (intern url)))
6429 (cond
6430 ((fboundp sym) (describe-function sym))
6431 ((boundp sym) (describe-variable sym))
6432 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6433
6434 (defun gnus-button-handle-describe-key (url)
6435 "Call `describe-key' when pushing the corresponding URL button."
6436 (let* ((key-string
6437 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6438 (keys (ignore-errors (eval `(kbd ,key-string)))))
6439 (if keys
6440 (describe-key keys)
6441 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6442
6443 (defun gnus-button-handle-apropos (url)
6444 "Call `apropos' when pushing the corresponding URL button."
6445 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6446
6447 (defun gnus-button-handle-apropos-command (url)
6448 "Call `apropos' when pushing the corresponding URL button."
6449 (apropos-command
6450 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6451
6452 (defun gnus-button-handle-apropos-variable (url)
6453 "Call `apropos' when pushing the corresponding URL button."
6454 (funcall
6455 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6456 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6457
6458 (defun gnus-button-handle-apropos-documentation (url)
6459 "Call `apropos' when pushing the corresponding URL button."
6460 (funcall
6461 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6462 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6463
6464 (defun gnus-button-handle-library (url)
6465 "Call `locate-library' when pushing the corresponding URL button."
6466 (gnus-message 9 "url=`%s'" url)
6467 (let* ((lib (locate-library url))
6468 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6469 (if (not lib)
6470 (gnus-message 1 "Cannot locale library `%s'." url)
6471 (find-file-read-only file))))
6472
6473 (defun gnus-button-handle-ctan (url)
6474 "Call `browse-url' when pushing a CTAN URL button."
6475 (funcall
6476 gnus-button-ctan-handler
6477 (concat
6478 gnus-ctan-url
6479 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6480
6481 (defcustom gnus-button-tex-level 5
6482 "*Integer that says how many TeX-related buttons Gnus will show.
6483 The higher the number, the more buttons will appear and the more false
6484 positives are possible. Note that you can set this variable local to
6485 specific groups. Setting it higher in TeX groups is probably a good idea.
6486 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6487 how to set variables in specific groups."
6488 :version "22.1"
6489 :group 'gnus-article-buttons
6490 :link '(custom-manual "(gnus)Group Parameters")
6491 :type 'integer)
6492
6493 (defcustom gnus-button-man-level 5
6494 "*Integer that says how many man-related buttons Gnus will show.
6495 The higher the number, the more buttons will appear and the more false
6496 positives are possible. Note that you can set this variable local to
6497 specific groups. Setting it higher in Unix groups is probably a good idea.
6498 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6499 how to set variables in specific groups."
6500 :version "22.1"
6501 :group 'gnus-article-buttons
6502 :link '(custom-manual "(gnus)Group Parameters")
6503 :type 'integer)
6504
6505 (defcustom gnus-button-emacs-level 5
6506 "*Integer that says how many emacs-related buttons Gnus will show.
6507 The higher the number, the more buttons will appear and the more false
6508 positives are possible. Note that you can set this variable local to
6509 specific groups. Setting it higher in Emacs or Gnus related groups is
6510 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6511 `gnus-parameters' on how to set variables in specific groups."
6512 :version "22.1"
6513 :group 'gnus-article-buttons
6514 :link '(custom-manual "(gnus)Group Parameters")
6515 :type 'integer)
6516
6517 (defcustom gnus-button-message-level 5
6518 "*Integer that says how many buttons for news or mail messages will appear.
6519 The higher the number, the more buttons will appear and the more false
6520 positives are possible."
6521 ;; mail addresses, MIDs, URLs for news, ...
6522 :version "22.1"
6523 :group 'gnus-article-buttons
6524 :type 'integer)
6525
6526 (defcustom gnus-button-browse-level 5
6527 "*Integer that says how many buttons for browsing will appear.
6528 The higher the number, the more buttons will appear and the more false
6529 positives are possible."
6530 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6531 :version "22.1"
6532 :group 'gnus-article-buttons
6533 :type 'integer)
6534
6535 (defcustom gnus-button-alist
6536 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6537 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6538 ((concat "\\b\\(nntp\\|news\\):\\("
6539 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6540 0 t gnus-button-handle-news 2)
6541 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6542 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6543 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6544 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6545 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6546 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6547 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6548 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6549 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6550 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6551 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6552 ;; RFC 2368 (The mailto URL scheme)
6553 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6554 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6555 ("\\bmailto:\\([^ \n\t]+\\)"
6556 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6557 ;; CTAN
6558 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6559 gnus-button-ctan-directory-regexp
6560 "[^][>)!;:,'\n\t ]+\\)")
6561 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6562 ((concat "\\btex-archive/\\("
6563 gnus-button-ctan-directory-regexp
6564 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6565 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6566 ((concat
6567 "\\b\\("
6568 gnus-button-ctan-directory-regexp
6569 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6570 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6571 ;; This is info (home-grown style) <info://foo/bar+baz>
6572 ("\\binfo://\\([^'\">\n\t ]+\\)"
6573 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6574 ;; Info GNOME style <info:foo#bar_baz>
6575 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6576 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6577 ;; Info KDE style <info:(foo)bar baz>
6578 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6579 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6580 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6581 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6582 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6583 ;; Info links like `C-h i d m CC Mode RET'
6584 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6585 ;; This is custom
6586 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6587 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6588 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6589 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6590 ;; Emacs help commands
6591 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6592 ;; regexp doesn't match arguments containing ` '.
6593 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6594 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6595 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6596 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6597 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6598 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6599 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6600 ;; The following entries may lead to many false positives so don't enable
6601 ;; them by default (use a high button level).
6602 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6603 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6604 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6605 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6606 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6607 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6608 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6609 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6610 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6611 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6612 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6613 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6614 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6615 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6616 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6617 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6618 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6619 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6620 ;; Unlike the other regexps we really have to require quoting
6621 ;; here to determine where it ends.
6622 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6623 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6624 ("<URL: *\\([^<>]*\\)>"
6625 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6626 ;; RFC 2396 (2.4.3., delims) ...
6627 ("\"URL: *\\([^\"]*\\)\""
6628 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6629 ;; RFC 2396 (2.4.3., delims) ...
6630 ("\"URL: *\\([^\"]*\\)\""
6631 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6632 ;; Raw URLs.
6633 (gnus-button-url-regexp
6634 0 (>= gnus-button-browse-level 0) browse-url 0)
6635 ;; man pages
6636 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6637 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6638 gnus-button-handle-man 1)
6639 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6640 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6641 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6642 gnus-button-handle-man 1)
6643 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6644 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6645 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6646 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6647 ;; MID or mail: To avoid too many false positives we don't try to catch
6648 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6649 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6650 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6651 ;; so that non-ambiguous entries (see above) match first.
6652 (gnus-button-mid-or-mail-regexp
6653 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6654 "*Alist of regexps matching buttons in article bodies.
6655
6656 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6657 REGEXP: is the string (case insensitive) matching text around the button (can
6658 also be Lisp expression evaluating to a string),
6659 BUTTON: is the number of the regexp grouping actually matching the button,
6660 FORM: is a Lisp expression which must eval to true for the button to
6661 be added,
6662 CALLBACK: is the function to call when the user push this button, and each
6663 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6664
6665 CALLBACK can also be a variable, in that case the value of that
6666 variable it the real callback function."
6667 :group 'gnus-article-buttons
6668 :type '(repeat (list (choice regexp variable sexp)
6669 (integer :tag "Button")
6670 (sexp :tag "Form")
6671 (function :tag "Callback")
6672 (repeat :tag "Par"
6673 :inline t
6674 (integer :tag "Regexp group")))))
6675
6676 (defcustom gnus-header-button-alist
6677 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6678 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6679 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6680 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6681 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6682 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6683 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6684 0 (>= gnus-button-browse-level 0) browse-url 0)
6685 ("^Subject:" gnus-button-url-regexp
6686 0 (>= gnus-button-browse-level 0) browse-url 0)
6687 ("^[^:]+:" gnus-button-url-regexp
6688 0 (>= gnus-button-browse-level 0) browse-url 0)
6689 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6690 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6691 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6692 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6693 "*Alist of headers and regexps to match buttons in article heads.
6694
6695 This alist is very similar to `gnus-button-alist', except that each
6696 alist has an additional HEADER element first in each entry:
6697
6698 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6699
6700 HEADER is a regexp to match a header. For a fuller explanation, see
6701 `gnus-button-alist'."
6702 :group 'gnus-article-buttons
6703 :group 'gnus-article-headers
6704 :type '(repeat (list (regexp :tag "Header")
6705 (choice regexp variable)
6706 (integer :tag "Button")
6707 (sexp :tag "Form")
6708 (function :tag "Callback")
6709 (repeat :tag "Par"
6710 :inline t
6711 (integer :tag "Regexp group")))))
6712
6713 (defvar gnus-button-regexp nil)
6714 (defvar gnus-button-marker-list nil)
6715 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6716
6717 (defvar gnus-button-last nil)
6718 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6719
6720 ;;; Commands:
6721
6722 (defun gnus-article-push-button (event)
6723 "Check text under the mouse pointer for a callback function.
6724 If the text under the mouse pointer has a `gnus-callback' property,
6725 call it with the value of the `gnus-data' text property."
6726 (interactive "e")
6727 (set-buffer (window-buffer (posn-window (event-start event))))
6728 (let* ((pos (posn-point (event-start event)))
6729 (data (get-text-property pos 'gnus-data))
6730 (fun (get-text-property pos 'gnus-callback)))
6731 (goto-char pos)
6732 (when fun
6733 (funcall fun data))))
6734
6735 (defun gnus-article-press-button ()
6736 "Check text at point for a callback function.
6737 If the text at point has a `gnus-callback' property,
6738 call it with the value of the `gnus-data' text property."
6739 (interactive)
6740 (let ((data (get-text-property (point) 'gnus-data))
6741 (fun (get-text-property (point) 'gnus-callback)))
6742 (when fun
6743 (funcall fun data))))
6744
6745 (defun gnus-article-highlight (&optional force)
6746 "Highlight current article.
6747 This function calls `gnus-article-highlight-headers',
6748 `gnus-article-highlight-citation',
6749 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6750 do the highlighting. See the documentation for those functions."
6751 (interactive (list 'force))
6752 (gnus-article-highlight-headers)
6753 (gnus-article-highlight-citation force)
6754 (gnus-article-highlight-signature)
6755 (gnus-article-add-buttons force)
6756 (gnus-article-add-buttons-to-head))
6757
6758 (defun gnus-article-highlight-some (&optional force)
6759 "Highlight current article.
6760 This function calls `gnus-article-highlight-headers',
6761 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6762 do the highlighting. See the documentation for those functions."
6763 (interactive (list 'force))
6764 (gnus-article-highlight-headers)
6765 (gnus-article-highlight-signature)
6766 (gnus-article-add-buttons))
6767
6768 (defun gnus-article-highlight-headers ()
6769 "Highlight article headers as specified by `gnus-header-face-alist'."
6770 (interactive)
6771 (save-excursion
6772 (set-buffer gnus-article-buffer)
6773 (save-restriction
6774 (let ((alist gnus-header-face-alist)
6775 (inhibit-read-only t)
6776 (case-fold-search t)
6777 (inhibit-point-motion-hooks t)
6778 entry regexp header-face field-face from hpoints fpoints)
6779 (article-narrow-to-head)
6780 (while (setq entry (pop alist))
6781 (goto-char (point-min))
6782 (setq regexp (concat "^\\("
6783 (if (string-equal "" (nth 0 entry))
6784 "[^\t ]"
6785 (nth 0 entry))
6786 "\\)")
6787 header-face (nth 1 entry)
6788 field-face (nth 2 entry))
6789 (while (and (re-search-forward regexp nil t)
6790 (not (eobp)))
6791 (beginning-of-line)
6792 (setq from (point))
6793 (unless (search-forward ":" nil t)
6794 (forward-char 1))
6795 (when (and header-face
6796 (not (memq (point) hpoints)))
6797 (push (point) hpoints)
6798 (gnus-put-text-property from (point) 'face header-face))
6799 (when (and field-face
6800 (not (memq (setq from (point)) fpoints)))
6801 (push from fpoints)
6802 (if (re-search-forward "^[^ \t]" nil t)
6803 (forward-char -2)
6804 (goto-char (point-max)))
6805 (gnus-put-text-property from (point) 'face field-face))))))))
6806
6807 (defun gnus-article-highlight-signature ()
6808 "Highlight the signature in an article.
6809 It does this by highlighting everything after
6810 `gnus-signature-separator' using the face `gnus-signature'."
6811 (interactive)
6812 (save-excursion
6813 (set-buffer gnus-article-buffer)
6814 (let ((inhibit-read-only t)
6815 (inhibit-point-motion-hooks t))
6816 (save-restriction
6817 (when (and gnus-signature-face
6818 (gnus-article-narrow-to-signature))
6819 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6820 'face gnus-signature-face)
6821 (widen)
6822 (gnus-article-search-signature)
6823 (let ((start (match-beginning 0))
6824 (end (set-marker (make-marker) (1+ (match-end 0)))))
6825 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6826 end)))))))
6827
6828 (defun gnus-button-in-region-p (b e prop)
6829 "Say whether PROP exists in the region."
6830 (text-property-not-all b e prop nil))
6831
6832 (defun gnus-article-add-buttons (&optional force)
6833 "Find external references in the article and make buttons of them.
6834 \"External references\" are things like Message-IDs and URLs, as
6835 specified by `gnus-button-alist'."
6836 (interactive (list 'force))
6837 (save-excursion
6838 (set-buffer gnus-article-buffer)
6839 (let ((inhibit-read-only t)
6840 (inhibit-point-motion-hooks t)
6841 (case-fold-search t)
6842 (alist gnus-button-alist)
6843 beg entry regexp)
6844 ;; Remove all old markers.
6845 (let (marker entry new-list)
6846 (while (setq marker (pop gnus-button-marker-list))
6847 (if (or (< marker (point-min)) (>= marker (point-max)))
6848 (push marker new-list)
6849 (goto-char marker)
6850 (when (setq entry (gnus-button-entry))
6851 (put-text-property (match-beginning (nth 1 entry))
6852 (match-end (nth 1 entry))
6853 'gnus-callback nil))
6854 (set-marker marker nil)))
6855 (setq gnus-button-marker-list new-list))
6856 ;; We skip the headers.
6857 (article-goto-body)
6858 (setq beg (point))
6859 (while (setq entry (pop alist))
6860 (setq regexp (eval (car entry)))
6861 (goto-char beg)
6862 (while (re-search-forward regexp nil t)
6863 (let* ((start (and entry (match-beginning (nth 1 entry))))
6864 (end (and entry (match-end (nth 1 entry))))
6865 (from (match-beginning 0)))
6866 (when (and (or (eq t (nth 2 entry))
6867 (eval (nth 2 entry)))
6868 (not (gnus-button-in-region-p
6869 start end 'gnus-callback)))
6870 ;; That optional form returned non-nil, so we add the
6871 ;; button.
6872 (gnus-article-add-button
6873 start end 'gnus-button-push
6874 (car (push (set-marker (make-marker) from)
6875 gnus-button-marker-list))))))))))
6876
6877 ;; Add buttons to the head of an article.
6878 (defun gnus-article-add-buttons-to-head ()
6879 "Add buttons to the head of the article."
6880 (interactive)
6881 (save-excursion
6882 (set-buffer gnus-article-buffer)
6883 (save-restriction
6884 (let ((inhibit-read-only t)
6885 (inhibit-point-motion-hooks t)
6886 (case-fold-search t)
6887 (alist gnus-header-button-alist)
6888 entry beg end)
6889 (article-narrow-to-head)
6890 (while alist
6891 ;; Each alist entry.
6892 (setq entry (car alist)
6893 alist (cdr alist))
6894 (goto-char (point-min))
6895 (while (re-search-forward (car entry) nil t)
6896 ;; Each header matching the entry.
6897 (setq beg (match-beginning 0))
6898 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6899 (match-beginning 0))
6900 (point-max)))
6901 (goto-char beg)
6902 (while (re-search-forward (eval (nth 1 entry)) end t)
6903 ;; Each match within a header.
6904 (let* ((entry (cdr entry))
6905 (start (match-beginning (nth 1 entry)))
6906 (end (match-end (nth 1 entry)))
6907 (form (nth 2 entry)))
6908 (goto-char (match-end 0))
6909 (when (eval form)
6910 (gnus-article-add-button
6911 start end (nth 3 entry)
6912 (buffer-substring (match-beginning (nth 4 entry))
6913 (match-end (nth 4 entry)))))))
6914 (goto-char end)))))))
6915
6916 ;;; External functions:
6917
6918 (defun gnus-article-add-button (from to fun &optional data)
6919 "Create a button between FROM and TO with callback FUN and data DATA."
6920 (when gnus-article-button-face
6921 (gnus-overlay-put (gnus-make-overlay from to)
6922 'face gnus-article-button-face))
6923 (gnus-add-text-properties
6924 from to
6925 (nconc (and gnus-article-mouse-face
6926 (list gnus-mouse-face-prop gnus-article-mouse-face))
6927 (list 'gnus-callback fun)
6928 (and data (list 'gnus-data data))))
6929 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6930 :button-keymap gnus-widget-button-keymap))
6931
6932 ;;; Internal functions:
6933
6934 (defun gnus-article-set-globals ()
6935 (save-excursion
6936 (set-buffer gnus-summary-buffer)
6937 (gnus-set-global-variables)))
6938
6939 (defun gnus-signature-toggle (end)
6940 (save-excursion
6941 (set-buffer gnus-article-buffer)
6942 (let ((inhibit-read-only t)
6943 (inhibit-point-motion-hooks t))
6944 (if (text-property-any end (point-max) 'article-type 'signature)
6945 (progn
6946 (gnus-delete-wash-type 'signature)
6947 (gnus-remove-text-properties-when
6948 'article-type 'signature end (point-max)
6949 (cons 'article-type (cons 'signature
6950 gnus-hidden-properties))))
6951 (gnus-add-wash-type 'signature)
6952 (gnus-add-text-properties-when
6953 'article-type nil end (point-max)
6954 (cons 'article-type (cons 'signature
6955 gnus-hidden-properties)))))
6956 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6957 (gnus-set-mode-line 'article))))
6958
6959 (defun gnus-button-entry ()
6960 ;; Return the first entry in `gnus-button-alist' matching this place.
6961 (let ((alist gnus-button-alist)
6962 (entry nil))
6963 (while alist
6964 (setq entry (pop alist))
6965 (if (looking-at (eval (car entry)))
6966 (setq alist nil)
6967 (setq entry nil)))
6968 entry))
6969
6970 (defun gnus-button-push (marker)
6971 ;; Push button starting at MARKER.
6972 (save-excursion
6973 (goto-char marker)
6974 (let* ((entry (gnus-button-entry))
6975 (inhibit-point-motion-hooks t)
6976 (fun (nth 3 entry))
6977 (args (mapcar (lambda (group)
6978 (let ((string (match-string group)))
6979 (gnus-set-text-properties
6980 0 (length string) nil string)
6981 string))
6982 (nthcdr 4 entry))))
6983 (cond
6984 ((fboundp fun)
6985 (apply fun args))
6986 ((and (boundp fun)
6987 (fboundp (symbol-value fun)))
6988 (apply (symbol-value fun) args))
6989 (t
6990 (gnus-message 1 "You must define `%S' to use this button"
6991 (cons fun args)))))))
6992
6993 (defun gnus-parse-news-url (url)
6994 (let (scheme server port group message-id articles)
6995 (with-temp-buffer
6996 (insert url)
6997 (goto-char (point-min))
6998 (when (looking-at "\\([A-Za-z]+\\):")
6999 (setq scheme (match-string 1))
7000 (goto-char (match-end 0)))
7001 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7002 (setq server (match-string 1))
7003 (setq port (if (stringp (match-string 3))
7004 (string-to-number (match-string 3))
7005 (match-string 3)))
7006 (goto-char (match-end 0)))
7007
7008 (cond
7009 ((looking-at "\\(.*@.*\\)")
7010 (setq message-id (match-string 1)))
7011 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7012 (setq group (match-string 1)
7013 articles (split-string (match-string 2) "-")))
7014 ((looking-at "\\([^/]+\\)/?")
7015 (setq group (match-string 1)))
7016 (t
7017 (error "Unknown news URL syntax"))))
7018 (list scheme server port group message-id articles)))
7019
7020 (defun gnus-button-handle-news (url)
7021 "Fetch a news URL."
7022 (destructuring-bind (scheme server port group message-id articles)
7023 (gnus-parse-news-url url)
7024 (cond
7025 (message-id
7026 (save-excursion
7027 (set-buffer gnus-summary-buffer)
7028 (if server
7029 (let ((gnus-refer-article-method
7030 (nconc (list (list 'nntp server))
7031 gnus-refer-article-method))
7032 (nntp-port-number (or port "nntp")))
7033 (gnus-message 7 "Fetching %s with %s"
7034 message-id gnus-refer-article-method)
7035 (gnus-summary-refer-article message-id))
7036 (gnus-summary-refer-article message-id))))
7037 (group
7038 (gnus-button-fetch-group url)))))
7039
7040 (defun gnus-button-handle-man (url)
7041 "Fetch a man page."
7042 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7043 (when (eq gnus-button-man-handler 'woman)
7044 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7045 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7046 (funcall gnus-button-man-handler url))
7047
7048 (defun gnus-button-handle-info-url (url)
7049 "Fetch an info URL."
7050 (setq url (mm-subst-char-in-string ?+ ?\ url))
7051 (cond
7052 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7053 (gnus-info-find-node
7054 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7055 "Gnus")
7056 ")" (gnus-url-unhex-string (match-string 2 url)))))
7057 ((string-match "([^)\"]+)[^\"]+" url)
7058 (setq url
7059 (gnus-replace-in-string
7060 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7061 (gnus-info-find-node url))
7062 (t (error "Can't parse %s" url))))
7063
7064 (defun gnus-button-handle-info-url-gnome (url)
7065 "Fetch GNOME style info URL."
7066 (setq url (mm-subst-char-in-string ?_ ?\ url))
7067 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7068 (gnus-info-find-node
7069 (concat "("
7070 (gnus-url-unhex-string
7071 (match-string 1 url))
7072 ")"
7073 (or (gnus-url-unhex-string
7074 (match-string 2 url))
7075 "Top")))
7076 (error "Can't parse %s" url)))
7077
7078 (defun gnus-button-handle-info-url-kde (url)
7079 "Fetch KDE style info URL."
7080 (gnus-info-find-node (gnus-url-unhex-string url)))
7081
7082 (defun gnus-button-handle-info-keystrokes (url)
7083 "Call `info' when pushing the corresponding URL button."
7084 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7085 (info)
7086 (Info-directory)
7087 (Info-menu url))
7088
7089 (defun gnus-button-message-id (message-id)
7090 "Fetch MESSAGE-ID."
7091 (save-excursion
7092 (set-buffer gnus-summary-buffer)
7093 (gnus-summary-refer-article message-id)))
7094
7095 (defun gnus-button-fetch-group (address)
7096 "Fetch GROUP specified by ADDRESS."
7097 (if (not (string-match "[:/]" address))
7098 ;; This is just a simple group url.
7099 (gnus-group-read-ephemeral-group address gnus-select-method)
7100 (if (not
7101 (string-match
7102 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7103 address))
7104 (error "Can't parse %s" address)
7105 (gnus-group-read-ephemeral-group
7106 (match-string 4 address)
7107 `(nntp ,(match-string 1 address)
7108 (nntp-address ,(match-string 1 address))
7109 (nntp-port-number ,(if (match-end 3)
7110 (match-string 3 address)
7111 "nntp")))
7112 nil nil nil
7113 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7114
7115 (defun gnus-url-parse-query-string (query &optional downcase)
7116 (let (retval pairs cur key val)
7117 (setq pairs (split-string query "&"))
7118 (while pairs
7119 (setq cur (car pairs)
7120 pairs (cdr pairs))
7121 (if (not (string-match "=" cur))
7122 nil ; Grace
7123 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7124 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7125 (if downcase
7126 (setq key (downcase key)))
7127 (setq cur (assoc key retval))
7128 (if cur
7129 (setcdr cur (cons val (cdr cur)))
7130 (setq retval (cons (list key val) retval)))))
7131 retval))
7132
7133 (defun gnus-url-mailto (url)
7134 ;; Send mail to someone
7135 (when (string-match "mailto:/*\\(.*\\)" url)
7136 (setq url (substring url (match-beginning 1) nil)))
7137 (let (to args subject func)
7138 (setq args (gnus-url-parse-query-string
7139 (if (string-match "^\\?" url)
7140 (substring url 1)
7141 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7142 (concat "to=" (match-string 1 url) "&"
7143 (match-string 2 url))
7144 (concat "to=" url)))
7145 t)
7146 subject (cdr-safe (assoc "subject" args)))
7147 (gnus-msg-mail)
7148 (while args
7149 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7150 (if (fboundp func)
7151 (funcall func)
7152 (message-position-on-field (caar args)))
7153 (insert (gnus-replace-in-string
7154 (mapconcat 'identity (reverse (cdar args)) ", ")
7155 "\r\n" "\n" t))
7156 (setq args (cdr args)))
7157 (if subject
7158 (message-goto-body)
7159 (message-goto-subject))))
7160
7161 (defun gnus-button-embedded-url (address)
7162 "Activate ADDRESS with `browse-url'."
7163 (browse-url (gnus-strip-whitespace address)))
7164
7165 ;;; Next/prev buttons in the article buffer.
7166
7167 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7168 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7169
7170 (defvar gnus-prev-page-map
7171 (let ((map (make-sparse-keymap)))
7172 (unless (>= emacs-major-version 21)
7173 ;; XEmacs doesn't care.
7174 (set-keymap-parent map gnus-article-mode-map))
7175 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7176 (define-key map "\r" 'gnus-button-prev-page)
7177 map))
7178
7179 (defvar gnus-next-page-map
7180 (let ((map (make-sparse-keymap)))
7181 (unless (>= emacs-major-version 21)
7182 ;; XEmacs doesn't care.
7183 (set-keymap-parent map gnus-article-mode-map))
7184 (define-key map gnus-mouse-2 'gnus-button-next-page)
7185 (define-key map "\r" 'gnus-button-next-page)
7186 map))
7187
7188 (defun gnus-insert-prev-page-button ()
7189 (let ((b (point))
7190 (inhibit-read-only t))
7191 (gnus-eval-format
7192 gnus-prev-page-line-format nil
7193 `(,@(gnus-local-map-property gnus-prev-page-map)
7194 gnus-prev t
7195 gnus-callback gnus-article-button-prev-page
7196 article-type annotation))
7197 (widget-convert-button
7198 'link b (if (bolp)
7199 ;; Exclude a newline.
7200 (1- (point))
7201 (point))
7202 :action 'gnus-button-prev-page
7203 :button-keymap gnus-prev-page-map)))
7204
7205 (defun gnus-button-next-page (&optional args more-args)
7206 "Go to the next page."
7207 (interactive)
7208 (let ((win (selected-window)))
7209 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7210 (gnus-article-next-page)
7211 (select-window win)))
7212
7213 (defun gnus-button-prev-page (&optional args more-args)
7214 "Go to the prev page."
7215 (interactive)
7216 (let ((win (selected-window)))
7217 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7218 (gnus-article-prev-page)
7219 (select-window win)))
7220
7221 (defun gnus-insert-next-page-button ()
7222 (let ((b (point))
7223 (inhibit-read-only t))
7224 (gnus-eval-format gnus-next-page-line-format nil
7225 `(,@(gnus-local-map-property gnus-next-page-map)
7226 gnus-next t
7227 gnus-callback gnus-article-button-next-page
7228 article-type annotation))
7229 (widget-convert-button
7230 'link b (if (bolp)
7231 ;; Exclude a newline.
7232 (1- (point))
7233 (point))
7234 :action 'gnus-button-next-page
7235 :button-keymap gnus-next-page-map)))
7236
7237 (defun gnus-article-button-next-page (arg)
7238 "Go to the next page."
7239 (interactive "P")
7240 (let ((win (selected-window)))
7241 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7242 (gnus-article-next-page)
7243 (select-window win)))
7244
7245 (defun gnus-article-button-prev-page (arg)
7246 "Go to the prev page."
7247 (interactive "P")
7248 (let ((win (selected-window)))
7249 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7250 (gnus-article-prev-page)
7251 (select-window win)))
7252
7253 (defvar gnus-decode-header-methods
7254 '(mail-decode-encoded-word-region)
7255 "List of methods used to decode headers.
7256
7257 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7258 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7259 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7260 whose names match REGEXP.
7261
7262 For example:
7263 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7264 mail-decode-encoded-word-region
7265 (\"chinese\" . rfc1843-decode-region))
7266 ")
7267
7268 (defvar gnus-decode-header-methods-cache nil)
7269
7270 (defun gnus-multi-decode-header (start end)
7271 "Apply the functions from `gnus-encoded-word-methods' that match."
7272 (unless (and gnus-decode-header-methods-cache
7273 (eq gnus-newsgroup-name
7274 (car gnus-decode-header-methods-cache)))
7275 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7276 (mapcar (lambda (x)
7277 (if (symbolp x)
7278 (nconc gnus-decode-header-methods-cache (list x))
7279 (if (and gnus-newsgroup-name
7280 (string-match (car x) gnus-newsgroup-name))
7281 (nconc gnus-decode-header-methods-cache
7282 (list (cdr x))))))
7283 gnus-decode-header-methods))
7284 (let ((xlist gnus-decode-header-methods-cache))
7285 (pop xlist)
7286 (save-restriction
7287 (narrow-to-region start end)
7288 (while xlist
7289 (funcall (pop xlist) (point-min) (point-max))))))
7290
7291 ;;;
7292 ;;; Treatment top-level handling.
7293 ;;;
7294
7295 (defun gnus-treat-article (condition &optional part-number total-parts type)
7296 (let ((length (- (point-max) (point-min)))
7297 (alist gnus-treatment-function-alist)
7298 (article-goto-body-goes-to-point-min-p t)
7299 (treated-type
7300 (or (not type)
7301 (catch 'found
7302 (let ((list gnus-article-treat-types))
7303 (while list
7304 (when (string-match (pop list) type)
7305 (throw 'found t)))))))
7306 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7307 val elem)
7308 (gnus-run-hooks 'gnus-part-display-hook)
7309 (dolist (elem alist)
7310 (setq val
7311 (save-excursion
7312 (when (gnus-buffer-live-p gnus-summary-buffer)
7313 (set-buffer gnus-summary-buffer))
7314 (symbol-value (car elem))))
7315 (when (and (or (consp val)
7316 treated-type)
7317 (gnus-treat-predicate val)
7318 (or (not (get (car elem) 'highlight))
7319 highlightp))
7320 (save-restriction
7321 (funcall (cadr elem)))))))
7322
7323 ;; Dynamic variables.
7324 (eval-when-compile
7325 (defvar part-number)
7326 (defvar total-parts)
7327 (defvar type)
7328 (defvar condition)
7329 (defvar length))
7330
7331 (defun gnus-treat-predicate (val)
7332 (cond
7333 ((null val)
7334 nil)
7335 (condition
7336 (eq condition val))
7337 ((and (listp val)
7338 (stringp (car val)))
7339 (apply 'gnus-or (mapcar `(lambda (s)
7340 (string-match s ,(or gnus-newsgroup-name "")))
7341 val)))
7342 ((listp val)
7343 (let ((pred (pop val)))
7344 (cond
7345 ((eq pred 'or)
7346 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7347 ((eq pred 'and)
7348 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7349 ((eq pred 'not)
7350 (not (gnus-treat-predicate (car val))))
7351 ((eq pred 'typep)
7352 (equal (car val) type))
7353 (t
7354 (error "%S is not a valid predicate" pred)))))
7355 ((eq val t)
7356 t)
7357 ((eq val 'head)
7358 nil)
7359 ((eq val 'last)
7360 (eq part-number total-parts))
7361 ((numberp val)
7362 (< length val))
7363 (t
7364 (error "%S is not a valid value" val))))
7365
7366 (defun gnus-article-encrypt-body (protocol &optional n)
7367 "Encrypt the article body."
7368 (interactive
7369 (list
7370 (or gnus-article-encrypt-protocol
7371 (completing-read "Encrypt protocol: "
7372 gnus-article-encrypt-protocol-alist
7373 nil t))
7374 current-prefix-arg))
7375 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7376 (unless func
7377 (error "Can't find the encrypt protocol %s" protocol))
7378 (if (member gnus-newsgroup-name '("nndraft:delayed"
7379 "nndraft:drafts"
7380 "nndraft:queue"))
7381 (error "Can't encrypt the article in group %s"
7382 gnus-newsgroup-name))
7383 (gnus-summary-iterate n
7384 (save-excursion
7385 (set-buffer gnus-summary-buffer)
7386 (let ((mail-parse-charset gnus-newsgroup-charset)
7387 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7388 (summary-buffer gnus-summary-buffer)
7389 references point)
7390 (gnus-set-global-variables)
7391 (when (gnus-group-read-only-p)
7392 (error "The current newsgroup does not support article encrypt"))
7393 (gnus-summary-show-article t)
7394 (setq references
7395 (or (mail-header-references gnus-current-headers) ""))
7396 (set-buffer gnus-article-buffer)
7397 (let* ((inhibit-read-only t)
7398 (headers
7399 (mapcar (lambda (field)
7400 (and (save-restriction
7401 (message-narrow-to-head)
7402 (goto-char (point-min))
7403 (search-forward field nil t))
7404 (prog2
7405 (message-narrow-to-field)
7406 (buffer-string)
7407 (delete-region (point-min) (point-max))
7408 (widen))))
7409 '("Content-Type:" "Content-Transfer-Encoding:"
7410 "Content-Disposition:"))))
7411 (message-narrow-to-head)
7412 (message-remove-header "MIME-Version")
7413 (goto-char (point-max))
7414 (setq point (point))
7415 (insert (apply 'concat headers))
7416 (widen)
7417 (narrow-to-region point (point-max))
7418 (let ((message-options message-options))
7419 (message-options-set 'message-sender user-mail-address)
7420 (message-options-set 'message-recipients user-mail-address)
7421 (message-options-set 'message-sign-encrypt 'not)
7422 (funcall func))
7423 (goto-char (point-min))
7424 (insert "MIME-Version: 1.0\n")
7425 (widen)
7426 (gnus-summary-edit-article-done
7427 references nil summary-buffer t))
7428 (when gnus-keep-backlog
7429 (gnus-backlog-remove-article
7430 (car gnus-article-current) (cdr gnus-article-current)))
7431 (save-excursion
7432 (when (get-buffer gnus-original-article-buffer)
7433 (set-buffer gnus-original-article-buffer)
7434 (setq gnus-original-article nil)))
7435 (when gnus-use-cache
7436 (gnus-cache-update-article
7437 (car gnus-article-current) (cdr gnus-article-current))))))))
7438
7439 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7440 "The following specs can be used:
7441 %t The security MIME type
7442 %i Additional info
7443 %d Details
7444 %D Details if button is pressed")
7445
7446 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7447 "The following specs can be used:
7448 %t The security MIME type
7449 %i Additional info
7450 %d Details
7451 %D Details if button is pressed")
7452
7453 (defvar gnus-mime-security-button-line-format-alist
7454 '((?t gnus-tmp-type ?s)
7455 (?i gnus-tmp-info ?s)
7456 (?d gnus-tmp-details ?s)
7457 (?D gnus-tmp-pressed-details ?s)))
7458
7459 (defvar gnus-mime-security-button-map
7460 (let ((map (make-sparse-keymap)))
7461 (unless (>= (string-to-number emacs-version) 21)
7462 (set-keymap-parent map gnus-article-mode-map))
7463 (define-key map gnus-mouse-2 'gnus-article-push-button)
7464 (define-key map "\r" 'gnus-article-press-button)
7465 map))
7466
7467 (defvar gnus-mime-security-details-buffer nil)
7468
7469 (defvar gnus-mime-security-button-pressed nil)
7470
7471 (defvar gnus-mime-security-show-details-inline t
7472 "If non-nil, show details in the article buffer.")
7473
7474 (defun gnus-mime-security-verify-or-decrypt (handle)
7475 (mm-remove-parts (cdr handle))
7476 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7477 point (inhibit-read-only t))
7478 (if region
7479 (goto-char (car region)))
7480 (save-restriction
7481 (narrow-to-region (point) (point))
7482 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7483 (let* ((mm-verify-option 'known)
7484 (mm-decrypt-option 'known)
7485 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7486 (unless (eq nparts (cdr handle))
7487 (mm-destroy-parts (cdr handle))
7488 (setcdr handle nparts))))
7489 (setq point (point))
7490 (gnus-mime-display-security handle)
7491 (goto-char (point-max)))
7492 (when region
7493 (delete-region (point) (cdr region))
7494 (set-marker (car region) nil)
7495 (set-marker (cdr region) nil))
7496 (goto-char point)))
7497
7498 (defun gnus-mime-security-show-details (handle)
7499 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7500 (if (not details)
7501 (gnus-message 5 "No details.")
7502 (if gnus-mime-security-show-details-inline
7503 (let ((gnus-mime-security-button-pressed
7504 (not (get-text-property (point) 'gnus-mime-details)))
7505 (gnus-mime-security-button-line-format
7506 (get-text-property (point) 'gnus-line-format))
7507 (inhibit-read-only t))
7508 (forward-char -1)
7509 (while (eq (get-text-property (point) 'gnus-line-format)
7510 gnus-mime-security-button-line-format)
7511 (forward-char -1))
7512 (forward-char)
7513 (save-restriction
7514 (narrow-to-region (point) (point))
7515 (gnus-insert-mime-security-button handle))
7516 (delete-region (point)
7517 (or (text-property-not-all
7518 (point) (point-max)
7519 'gnus-line-format
7520 gnus-mime-security-button-line-format)
7521 (point-max))))
7522 ;; Not inlined.
7523 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7524 (with-current-buffer gnus-mime-security-details-buffer
7525 (erase-buffer)
7526 t)
7527 (setq gnus-mime-security-details-buffer
7528 (gnus-get-buffer-create "*MIME Security Details*")))
7529 (with-current-buffer gnus-mime-security-details-buffer
7530 (insert details)
7531 (goto-char (point-min)))
7532 (pop-to-buffer gnus-mime-security-details-buffer)))))
7533
7534 (defun gnus-mime-security-press-button (handle)
7535 (save-excursion
7536 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7537 (gnus-mime-security-show-details handle)
7538 (gnus-mime-security-verify-or-decrypt handle))))
7539
7540 (defun gnus-insert-mime-security-button (handle &optional displayed)
7541 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7542 (gnus-tmp-type
7543 (concat
7544 (or (nth 2 (assoc protocol mm-verify-function-alist))
7545 (nth 2 (assoc protocol mm-decrypt-function-alist))
7546 "Unknown")
7547 (if (equal (car handle) "multipart/signed")
7548 " Signed" " Encrypted")
7549 " Part"))
7550 (gnus-tmp-info
7551 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7552 "Undecided"))
7553 (gnus-tmp-details
7554 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7555 gnus-tmp-pressed-details
7556 b e)
7557 (setq gnus-tmp-details
7558 (if gnus-tmp-details
7559 (concat "\n" gnus-tmp-details)
7560 ""))
7561 (setq gnus-tmp-pressed-details
7562 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7563 (unless (bolp)
7564 (insert "\n"))
7565 (setq b (point))
7566 (gnus-eval-format
7567 gnus-mime-security-button-line-format
7568 gnus-mime-security-button-line-format-alist
7569 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7570 gnus-callback gnus-mime-security-press-button
7571 gnus-line-format ,gnus-mime-security-button-line-format
7572 gnus-mime-details ,gnus-mime-security-button-pressed
7573 article-type annotation
7574 gnus-data ,handle))
7575 (setq e (if (bolp)
7576 ;; Exclude a newline.
7577 (1- (point))
7578 (point)))
7579 (widget-convert-button
7580 'link b e
7581 :mime-handle handle
7582 :action 'gnus-widget-press-button
7583 :button-keymap gnus-mime-security-button-map
7584 :help-echo
7585 (lambda (widget/window &optional overlay pos)
7586 ;; Needed to properly clear the message due to a bug in
7587 ;; wid-edit (XEmacs only).
7588 (when (boundp 'help-echo-owns-message)
7589 (setq help-echo-owns-message t))
7590 (format
7591 "%S: show detail"
7592 (aref gnus-mouse-2 0))))))
7593
7594 (defun gnus-mime-display-security (handle)
7595 (save-restriction
7596 (narrow-to-region (point) (point))
7597 (unless (gnus-unbuttonized-mime-type-p (car handle))
7598 (gnus-insert-mime-security-button handle))
7599 (gnus-mime-display-mixed (cdr handle))
7600 (unless (bolp)
7601 (insert "\n"))
7602 (unless (gnus-unbuttonized-mime-type-p (car handle))
7603 (let ((gnus-mime-security-button-line-format
7604 gnus-mime-security-button-end-line-format))
7605 (gnus-insert-mime-security-button handle)))
7606 (mm-set-handle-multipart-parameter
7607 handle 'gnus-region
7608 (cons (set-marker (make-marker) (point-min))
7609 (set-marker (make-marker) (point-max))))))
7610
7611 (gnus-ems-redefine)
7612
7613 (provide 'gnus-art)
7614
7615 (run-hooks 'gnus-art-load-hook)
7616
7617 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7618 ;;; gnus-art.el ends here