]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
(gnus-article-x-face-command, gnus-numeric-save-name):
[gnu-emacs] / 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 (with-current-buffer gnus-original-article-buffer
1921 ;; If date in `gnus-article-buffer' is localized
1922 ;; (`gnus-treat-date-user-defined'),
1923 ;; `days-between' might fail.
1924 (message-fetch-field "date"))))
1925 (when (and date
1926 (< (days-between (current-time-string) date)
1927 4))
1928 (gnus-article-hide-header "date"))))
1929 ((eq elem 'long-to)
1930 (let ((to (message-fetch-field "to"))
1931 (cc (message-fetch-field "cc")))
1932 (when (> (length to) 1024)
1933 (gnus-article-hide-header "to"))
1934 (when (> (length cc) 1024)
1935 (gnus-article-hide-header "cc"))))
1936 ((eq elem 'many-to)
1937 (let ((to-count 0)
1938 (cc-count 0))
1939 (goto-char (point-min))
1940 (while (re-search-forward "^to:" nil t)
1941 (setq to-count (1+ to-count)))
1942 (when (> to-count 1)
1943 (while (> to-count 0)
1944 (goto-char (point-min))
1945 (save-restriction
1946 (re-search-forward "^to:" nil nil to-count)
1947 (forward-line -1)
1948 (narrow-to-region (point) (point-max))
1949 (gnus-article-hide-header "to"))
1950 (setq to-count (1- to-count))))
1951 (goto-char (point-min))
1952 (while (re-search-forward "^cc:" nil t)
1953 (setq cc-count (1+ cc-count)))
1954 (when (> cc-count 1)
1955 (while (> cc-count 0)
1956 (goto-char (point-min))
1957 (save-restriction
1958 (re-search-forward "^cc:" nil nil cc-count)
1959 (forward-line -1)
1960 (narrow-to-region (point) (point-max))
1961 (gnus-article-hide-header "cc"))
1962 (setq cc-count (1- cc-count)))))))))))))
1963
1964 (defun gnus-article-hide-header (header)
1965 (save-excursion
1966 (goto-char (point-min))
1967 (when (re-search-forward (concat "^" header ":") nil t)
1968 (gnus-article-hide-text-type
1969 (gnus-point-at-bol)
1970 (progn
1971 (end-of-line)
1972 (if (re-search-forward "^[^ \t]" nil t)
1973 (match-beginning 0)
1974 (point-max)))
1975 'boring-headers))))
1976
1977 (defvar gnus-article-normalized-header-length 40
1978 "Length of normalized headers.")
1979
1980 (defun article-normalize-headers ()
1981 "Make all header lines 40 characters long."
1982 (interactive)
1983 (let ((inhibit-read-only t)
1984 column)
1985 (save-excursion
1986 (save-restriction
1987 (article-narrow-to-head)
1988 (while (not (eobp))
1989 (cond
1990 ((< (setq column (- (gnus-point-at-eol) (point)))
1991 gnus-article-normalized-header-length)
1992 (end-of-line)
1993 (insert (make-string
1994 (- gnus-article-normalized-header-length column)
1995 ? )))
1996 ((> column gnus-article-normalized-header-length)
1997 (gnus-put-text-property
1998 (progn
1999 (forward-char gnus-article-normalized-header-length)
2000 (point))
2001 (gnus-point-at-eol)
2002 'invisible t))
2003 (t
2004 ;; Do nothing.
2005 ))
2006 (forward-line 1))))))
2007
2008 (defun article-treat-dumbquotes ()
2009 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2010 Note that this function guesses whether a character is a sm*rtq**t* or
2011 not, so it should only be used interactively.
2012
2013 Sm*rtq**t*s are M****s***'s unilateral extension to the
2014 iso-8859-1 character map in an attempt to provide more quoting
2015 characters. If you see something like \\222 or \\264 where
2016 you're expecting some kind of apostrophe or quotation mark, then
2017 try this wash."
2018 (interactive)
2019 (article-translate-strings gnus-article-dumbquotes-map))
2020
2021 (defun article-translate-characters (from to)
2022 "Translate all characters in the body of the article according to FROM and TO.
2023 FROM is a string of characters to translate from; to is a string of
2024 characters to translate to."
2025 (save-excursion
2026 (when (article-goto-body)
2027 (let ((inhibit-read-only t)
2028 (x (make-string 225 ?x))
2029 (i -1))
2030 (while (< (incf i) (length x))
2031 (aset x i i))
2032 (setq i 0)
2033 (while (< i (length from))
2034 (aset x (aref from i) (aref to i))
2035 (incf i))
2036 (translate-region (point) (point-max) x)))))
2037
2038 (defun article-translate-strings (map)
2039 "Translate all string in the body of the article according to MAP.
2040 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2041 (save-excursion
2042 (when (article-goto-body)
2043 (let ((inhibit-read-only t)
2044 elem)
2045 (while (setq elem (pop map))
2046 (save-excursion
2047 (while (search-forward (car elem) nil t)
2048 (replace-match (cadr elem)))))))))
2049
2050 (defun article-treat-overstrike ()
2051 "Translate overstrikes into bold text."
2052 (interactive)
2053 (save-excursion
2054 (when (article-goto-body)
2055 (let ((inhibit-read-only t))
2056 (while (search-forward "\b" nil t)
2057 (let ((next (char-after))
2058 (previous (char-after (- (point) 2))))
2059 ;; We do the boldification/underlining by hiding the
2060 ;; overstrikes and putting the proper text property
2061 ;; on the letters.
2062 (cond
2063 ((eq next previous)
2064 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2065 (put-text-property (point) (1+ (point)) 'face 'bold))
2066 ((eq next ?_)
2067 (gnus-article-hide-text-type
2068 (1- (point)) (1+ (point)) 'overstrike)
2069 (put-text-property
2070 (- (point) 2) (1- (point)) 'face 'underline))
2071 ((eq previous ?_)
2072 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2073 (put-text-property
2074 (point) (1+ (point)) 'face 'underline)))))))))
2075
2076 (defun gnus-article-treat-unfold-headers ()
2077 "Unfold folded message headers.
2078 Only the headers that fit into the current window width will be
2079 unfolded."
2080 (interactive)
2081 (gnus-with-article-headers
2082 (let (length)
2083 (while (not (eobp))
2084 (save-restriction
2085 (mail-header-narrow-to-field)
2086 (let ((header (buffer-string)))
2087 (with-temp-buffer
2088 (insert header)
2089 (goto-char (point-min))
2090 (while (re-search-forward "\n[\t ]" nil t)
2091 (replace-match " " t t)))
2092 (setq length (- (point-max) (point-min) 1)))
2093 (when (< length (window-width))
2094 (while (re-search-forward "\n[\t ]" nil t)
2095 (replace-match " " t t)))
2096 (goto-char (point-max)))))))
2097
2098 (defun gnus-article-treat-fold-headers ()
2099 "Fold message headers."
2100 (interactive)
2101 (gnus-with-article-headers
2102 (while (not (eobp))
2103 (save-restriction
2104 (mail-header-narrow-to-field)
2105 (mail-header-fold-field)
2106 (goto-char (point-max))))))
2107
2108 (defun gnus-treat-smiley ()
2109 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2110 (interactive)
2111 (gnus-with-article-buffer
2112 (if (memq 'smiley gnus-article-wash-types)
2113 (gnus-delete-images 'smiley)
2114 (article-goto-body)
2115 (let ((images (smiley-region (point) (point-max))))
2116 (when images
2117 (gnus-add-wash-type 'smiley)
2118 (dolist (image images)
2119 (gnus-add-image 'smiley image)))))))
2120
2121 (defun gnus-article-remove-images ()
2122 "Remove all images from the article buffer."
2123 (interactive)
2124 (gnus-with-article-buffer
2125 (dolist (elem gnus-article-image-alist)
2126 (gnus-delete-images (car elem)))))
2127
2128 (defun gnus-article-treat-fold-newsgroups ()
2129 "Unfold folded message headers.
2130 Only the headers that fit into the current window width will be
2131 unfolded."
2132 (interactive)
2133 (gnus-with-article-headers
2134 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2135 (save-restriction
2136 (mail-header-narrow-to-field)
2137 (while (re-search-forward ", *" nil t)
2138 (replace-match ", " t t))
2139 (mail-header-fold-field)
2140 (goto-char (point-max))))))
2141
2142 (defun gnus-article-treat-body-boundary ()
2143 "Place a boundary line at the end of the headers."
2144 (interactive)
2145 (when (and gnus-body-boundary-delimiter
2146 (> (length gnus-body-boundary-delimiter) 0))
2147 (gnus-with-article-headers
2148 (goto-char (point-max))
2149 (let ((start (point)))
2150 (insert "X-Boundary: ")
2151 (gnus-add-text-properties start (point) '(invisible t intangible t))
2152 (insert (let (str)
2153 (while (>= (1- (window-width)) (length str))
2154 (setq str (concat str gnus-body-boundary-delimiter)))
2155 (substring str 0 (1- (window-width))))
2156 "\n")
2157 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2158
2159 (defun article-fill-long-lines ()
2160 "Fill lines that are wider than the window width."
2161 (interactive)
2162 (save-excursion
2163 (let ((inhibit-read-only t)
2164 (width (window-width (get-buffer-window (current-buffer)))))
2165 (save-restriction
2166 (article-goto-body)
2167 (let ((adaptive-fill-mode nil)) ;Why? -sm
2168 (while (not (eobp))
2169 (end-of-line)
2170 (when (>= (current-column) (min fill-column width))
2171 (narrow-to-region (min (1+ (point)) (point-max))
2172 (gnus-point-at-bol))
2173 (let ((goback (point-marker)))
2174 (fill-paragraph nil)
2175 (goto-char (marker-position goback)))
2176 (widen))
2177 (forward-line 1)))))))
2178
2179 (defun article-capitalize-sentences ()
2180 "Capitalize the first word in each sentence."
2181 (interactive)
2182 (save-excursion
2183 (let ((inhibit-read-only t)
2184 (paragraph-start "^[\n\^L]"))
2185 (article-goto-body)
2186 (while (not (eobp))
2187 (capitalize-word 1)
2188 (forward-sentence)))))
2189
2190 (defun article-remove-cr ()
2191 "Remove trailing CRs and then translate remaining CRs into LFs."
2192 (interactive)
2193 (save-excursion
2194 (let ((inhibit-read-only t))
2195 (goto-char (point-min))
2196 (while (re-search-forward "\r+$" nil t)
2197 (replace-match "" t t))
2198 (goto-char (point-min))
2199 (while (search-forward "\r" nil t)
2200 (replace-match "\n" t t)))))
2201
2202 (defun article-remove-trailing-blank-lines ()
2203 "Remove all trailing blank lines from the article."
2204 (interactive)
2205 (save-excursion
2206 (let ((inhibit-read-only t))
2207 (goto-char (point-max))
2208 (delete-region
2209 (point)
2210 (progn
2211 (while (and (not (bobp))
2212 (looking-at "^[ \t]*$")
2213 (not (gnus-annotation-in-region-p
2214 (point) (gnus-point-at-eol))))
2215 (forward-line -1))
2216 (forward-line 1)
2217 (point))))))
2218
2219 (defun article-display-face ()
2220 "Display any Face headers in the header."
2221 (interactive)
2222 (let ((wash-face-p buffer-read-only))
2223 (gnus-with-article-headers
2224 ;; When displaying parts, this function can be called several times on
2225 ;; the same article, without any intended toggle semantic (as typing `W
2226 ;; D d' would have). So face deletion must occur only when we come from
2227 ;; an interactive command, that is when the *Article* buffer is
2228 ;; read-only.
2229 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2230 (gnus-delete-images 'face)
2231 (let (face faces from)
2232 (save-current-buffer
2233 (when (and wash-face-p
2234 (gnus-buffer-live-p gnus-original-article-buffer)
2235 (not (re-search-forward "^Face:[\t ]*" nil t)))
2236 (set-buffer gnus-original-article-buffer))
2237 (save-restriction
2238 (mail-narrow-to-head)
2239 (while (gnus-article-goto-header "Face")
2240 (push (mail-header-field-value) faces))))
2241 (when faces
2242 (goto-char (point-min))
2243 (let ((from (gnus-article-goto-header "from"))
2244 png image)
2245 (unless from
2246 (insert "From:")
2247 (setq from (point))
2248 (insert "[no `from' set]\n"))
2249 (while faces
2250 (when (setq png (gnus-convert-face-to-png (pop faces)))
2251 (setq image (gnus-create-image png 'png t))
2252 (goto-char from)
2253 (gnus-add-wash-type 'face)
2254 (gnus-add-image 'face image)
2255 (gnus-put-image image nil 'face))))))))))
2256
2257 (defun article-display-x-face (&optional force)
2258 "Look for an X-Face header and display it if present."
2259 (interactive (list 'force))
2260 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2261 (gnus-with-article-headers
2262 ;; Delete the old process, if any.
2263 (when (process-status "article-x-face")
2264 (delete-process "article-x-face"))
2265 ;; See the comment in `article-display-face'.
2266 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2267 ;; We have already displayed X-Faces, so we remove them
2268 ;; instead.
2269 (gnus-delete-images 'xface)
2270 ;; Display X-Faces.
2271 (let (x-faces from face)
2272 (save-current-buffer
2273 (when (and wash-face-p
2274 (gnus-buffer-live-p gnus-original-article-buffer)
2275 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2276 ;; If type `W f', use gnus-original-article-buffer,
2277 ;; otherwise use the current buffer because displaying
2278 ;; RFC822 parts calls this function too.
2279 (set-buffer gnus-original-article-buffer))
2280 (save-restriction
2281 (mail-narrow-to-head)
2282 (while (gnus-article-goto-header "X-Face")
2283 (push (mail-header-field-value) x-faces))
2284 (setq from (message-fetch-field "from"))))
2285 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2286 ;; single external face.
2287 (when (stringp gnus-article-x-face-command)
2288 (setq x-faces (list (car x-faces))))
2289 (when (and x-faces
2290 gnus-article-x-face-command
2291 (or force
2292 ;; Check whether this face is censored.
2293 (not gnus-article-x-face-too-ugly)
2294 (and from
2295 (not (string-match gnus-article-x-face-too-ugly
2296 from)))))
2297 (while (setq face (pop x-faces))
2298 ;; We display the face.
2299 (cond ((stringp gnus-article-x-face-command)
2300 ;; The command is a string, so we interpret the command
2301 ;; as a, well, command, and fork it off.
2302 (let ((process-connection-type nil))
2303 (gnus-set-process-query-on-exit-flag
2304 (start-process
2305 "article-x-face" nil shell-file-name
2306 shell-command-switch gnus-article-x-face-command)
2307 nil)
2308 (with-temp-buffer
2309 (insert face)
2310 (process-send-region "article-x-face"
2311 (point-min) (point-max)))
2312 (process-send-eof "article-x-face")))
2313 ((functionp gnus-article-x-face-command)
2314 ;; The command is a lisp function, so we call it.
2315 (funcall gnus-article-x-face-command face))
2316 (t
2317 (error "%s is not a function"
2318 gnus-article-x-face-command))))))))))
2319
2320 (defun article-decode-mime-words ()
2321 "Decode all MIME-encoded words in the article."
2322 (interactive)
2323 (save-excursion
2324 (set-buffer gnus-article-buffer)
2325 (let ((inhibit-point-motion-hooks t)
2326 (inhibit-read-only t)
2327 (mail-parse-charset gnus-newsgroup-charset)
2328 (mail-parse-ignored-charsets
2329 (save-excursion (set-buffer gnus-summary-buffer)
2330 gnus-newsgroup-ignored-charsets)))
2331 (mail-decode-encoded-word-region (point-min) (point-max)))))
2332
2333 (defun article-decode-charset (&optional prompt)
2334 "Decode charset-encoded text in the article.
2335 If PROMPT (the prefix), prompt for a coding system to use."
2336 (interactive "P")
2337 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2338 (inhibit-read-only t)
2339 (mail-parse-charset gnus-newsgroup-charset)
2340 (mail-parse-ignored-charsets
2341 (save-excursion (condition-case nil
2342 (set-buffer gnus-summary-buffer)
2343 (error))
2344 gnus-newsgroup-ignored-charsets))
2345 ct cte ctl charset format)
2346 (save-excursion
2347 (save-restriction
2348 (article-narrow-to-head)
2349 (setq ct (message-fetch-field "Content-Type" t)
2350 cte (message-fetch-field "Content-Transfer-Encoding" t)
2351 ctl (and ct (mail-header-parse-content-type ct))
2352 charset (cond
2353 (prompt
2354 (mm-read-coding-system "Charset to decode: "))
2355 (ctl
2356 (mail-content-type-get ctl 'charset)))
2357 format (and ctl (mail-content-type-get ctl 'format)))
2358 (when cte
2359 (setq cte (mail-header-strip cte)))
2360 (if (and ctl (not (string-match "/" (car ctl))))
2361 (setq ctl nil))
2362 (goto-char (point-max)))
2363 (forward-line 1)
2364 (save-restriction
2365 (narrow-to-region (point) (point-max))
2366 (when (and (eq mail-parse-charset 'gnus-decoded)
2367 (eq (mm-body-7-or-8) '8bit))
2368 ;; The text code could have been decoded.
2369 (setq charset mail-parse-charset))
2370 (when (and (or (not ctl)
2371 (equal (car ctl) "text/plain"))
2372 (not format)) ;; article with format will decode later.
2373 (mm-decode-body
2374 charset (and cte (intern (downcase
2375 (gnus-strip-whitespace cte))))
2376 (car ctl)))))))
2377
2378 (defun article-decode-encoded-words ()
2379 "Remove encoded-word encoding from headers."
2380 (let ((inhibit-point-motion-hooks t)
2381 (mail-parse-charset gnus-newsgroup-charset)
2382 (mail-parse-ignored-charsets
2383 (save-excursion (condition-case nil
2384 (set-buffer gnus-summary-buffer)
2385 (error))
2386 gnus-newsgroup-ignored-charsets))
2387 (inhibit-read-only t)
2388 end start)
2389 (goto-char (point-min))
2390 (when (search-forward "\n\n" nil 'move)
2391 (forward-line -1))
2392 (setq end (point))
2393 (while (not (bobp))
2394 (while (progn
2395 (forward-line -1)
2396 (and (not (bobp))
2397 (memq (char-after) '(?\t ? )))))
2398 (setq start (point))
2399 (if (looking-at "\
2400 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2401 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2402 (funcall gnus-decode-address-function start end)
2403 (funcall gnus-decode-header-function start end))
2404 (goto-char (setq end start)))))
2405
2406 (defun article-decode-group-name ()
2407 "Decode group names in `Newsgroups:'."
2408 (let ((inhibit-point-motion-hooks t)
2409 (inhibit-read-only t)
2410 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2411 (when (and (or gnus-group-name-charset-method-alist
2412 gnus-group-name-charset-group-alist)
2413 (gnus-buffer-live-p gnus-original-article-buffer))
2414 (save-restriction
2415 (article-narrow-to-head)
2416 (with-current-buffer gnus-original-article-buffer
2417 (goto-char (point-min)))
2418 (while (re-search-forward
2419 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2420 (replace-match (save-match-data
2421 (gnus-decode-newsgroups
2422 ;; XXX how to use data in article buffer?
2423 (with-current-buffer gnus-original-article-buffer
2424 (re-search-forward
2425 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2426 nil t)
2427 (match-string 1))
2428 gnus-newsgroup-name method))
2429 t t nil 1))
2430 (goto-char (point-min))
2431 (with-current-buffer gnus-original-article-buffer
2432 (goto-char (point-min)))
2433 (while (re-search-forward
2434 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2435 (replace-match (save-match-data
2436 (gnus-decode-newsgroups
2437 ;; XXX how to use data in article buffer?
2438 (with-current-buffer gnus-original-article-buffer
2439 (re-search-forward
2440 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2441 nil t)
2442 (match-string 1))
2443 gnus-newsgroup-name method))
2444 t t nil 1))))))
2445
2446 (autoload 'idna-to-unicode "idna")
2447
2448 (defun article-decode-idna-rhs ()
2449 "Decode IDNA strings in RHS in various headers in current buffer.
2450 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2451 Mail-Reply-To: and Mail-Followup-To:."
2452 (when gnus-use-idna
2453 (save-restriction
2454 (let ((inhibit-point-motion-hooks t)
2455 (inhibit-read-only t))
2456 (article-narrow-to-head)
2457 (goto-char (point-min))
2458 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2459 (let (ace unicode)
2460 (when (save-match-data
2461 (and (setq ace (match-string 1))
2462 (save-excursion
2463 (and (re-search-backward "^[^ \t]" nil t)
2464 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2465 (setq unicode (idna-to-unicode ace))))
2466 (unless (string= ace unicode)
2467 (replace-match unicode nil nil nil 1)))))))))
2468
2469 (defun article-de-quoted-unreadable (&optional force read-charset)
2470 "Translate a quoted-printable-encoded article.
2471 If FORCE, decode the article whether it is marked as quoted-printable
2472 or not.
2473 If READ-CHARSET, ask for a coding system."
2474 (interactive (list 'force current-prefix-arg))
2475 (save-excursion
2476 (let ((inhibit-read-only t) type charset)
2477 (if (gnus-buffer-live-p gnus-original-article-buffer)
2478 (with-current-buffer gnus-original-article-buffer
2479 (setq type
2480 (gnus-fetch-field "content-transfer-encoding"))
2481 (let* ((ct (gnus-fetch-field "content-type"))
2482 (ctl (and ct (mail-header-parse-content-type ct))))
2483 (setq charset (and ctl
2484 (mail-content-type-get ctl 'charset)))
2485 (if (stringp charset)
2486 (setq charset (intern (downcase charset)))))))
2487 (if read-charset
2488 (setq charset (mm-read-coding-system "Charset: " charset)))
2489 (unless charset
2490 (setq charset gnus-newsgroup-charset))
2491 (when (or force
2492 (and type (let ((case-fold-search t))
2493 (string-match "quoted-printable" type))))
2494 (article-goto-body)
2495 (quoted-printable-decode-region
2496 (point) (point-max) (mm-charset-to-coding-system charset))))))
2497
2498 (defun article-de-base64-unreadable (&optional force read-charset)
2499 "Translate a base64 article.
2500 If FORCE, decode the article whether it is marked as base64 not.
2501 If READ-CHARSET, ask for a coding system."
2502 (interactive (list 'force current-prefix-arg))
2503 (save-excursion
2504 (let ((inhibit-read-only t) type charset)
2505 (if (gnus-buffer-live-p gnus-original-article-buffer)
2506 (with-current-buffer gnus-original-article-buffer
2507 (setq type
2508 (gnus-fetch-field "content-transfer-encoding"))
2509 (let* ((ct (gnus-fetch-field "content-type"))
2510 (ctl (and ct (mail-header-parse-content-type ct))))
2511 (setq charset (and ctl
2512 (mail-content-type-get ctl 'charset)))
2513 (if (stringp charset)
2514 (setq charset (intern (downcase charset)))))))
2515 (if read-charset
2516 (setq charset (mm-read-coding-system "Charset: " charset)))
2517 (unless charset
2518 (setq charset gnus-newsgroup-charset))
2519 (when (or force
2520 (and type (let ((case-fold-search t))
2521 (string-match "base64" type))))
2522 (article-goto-body)
2523 (save-restriction
2524 (narrow-to-region (point) (point-max))
2525 (base64-decode-region (point-min) (point-max))
2526 (mm-decode-coding-region
2527 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2528
2529 (eval-when-compile
2530 (require 'rfc1843))
2531
2532 (defun article-decode-HZ ()
2533 "Translate a HZ-encoded article."
2534 (interactive)
2535 (require 'rfc1843)
2536 (save-excursion
2537 (let ((inhibit-read-only t))
2538 (rfc1843-decode-region (point-min) (point-max)))))
2539
2540 (defun article-unsplit-urls ()
2541 "Remove the newlines that some other mailers insert into URLs."
2542 (interactive)
2543 (save-excursion
2544 (let ((inhibit-read-only t))
2545 (goto-char (point-min))
2546 (while (re-search-forward
2547 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2548 (replace-match "\\1\\3" t)))
2549 (when (interactive-p)
2550 (gnus-treat-article nil))))
2551
2552
2553 (defun article-wash-html (&optional read-charset)
2554 "Format an HTML article.
2555 If READ-CHARSET, ask for a coding system. If it is a number, the
2556 charset defined in `gnus-summary-show-article-charset-alist' is used."
2557 (interactive "P")
2558 (save-excursion
2559 (let ((inhibit-read-only t)
2560 charset)
2561 (if read-charset
2562 (if (or (and (numberp read-charset)
2563 (setq charset
2564 (cdr
2565 (assq read-charset
2566 gnus-summary-show-article-charset-alist))))
2567 (setq charset (mm-read-coding-system "Charset: ")))
2568 (let ((gnus-summary-show-article-charset-alist
2569 (list (cons 1 charset))))
2570 (with-current-buffer gnus-summary-buffer
2571 (gnus-summary-show-article 1)))
2572 (error "No charset is given"))
2573 (when (gnus-buffer-live-p gnus-original-article-buffer)
2574 (with-current-buffer gnus-original-article-buffer
2575 (let* ((ct (gnus-fetch-field "content-type"))
2576 (ctl (and ct (mail-header-parse-content-type ct))))
2577 (setq charset (and ctl
2578 (mail-content-type-get ctl 'charset)))
2579 (when (stringp charset)
2580 (setq charset (intern (downcase charset)))))))
2581 (unless charset
2582 (setq charset gnus-newsgroup-charset)))
2583 (article-goto-body)
2584 (save-window-excursion
2585 (save-restriction
2586 (narrow-to-region (point) (point-max))
2587 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2588 (entry (assq func mm-text-html-washer-alist)))
2589 (when entry
2590 (setq func (cdr entry)))
2591 (cond
2592 ((functionp func)
2593 (funcall func))
2594 (t
2595 (apply (car func) (cdr func))))))))))
2596
2597 (defun gnus-article-wash-html-with-w3 ()
2598 "Wash the current buffer with w3."
2599 (mm-setup-w3)
2600 (let ((w3-strict-width (window-width))
2601 (url-standalone-mode t)
2602 (url-gateway-unplugged t)
2603 (w3-honor-stylesheets nil))
2604 (condition-case ()
2605 (w3-region (point-min) (point-max))
2606 (error))))
2607
2608 (defun gnus-article-wash-html-with-w3m ()
2609 "Wash the current buffer with emacs-w3m."
2610 (mm-setup-w3m)
2611 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2612 w3m-force-redisplay)
2613 (w3m-region (point-min) (point-max)))
2614 (when (and mm-inline-text-html-with-w3m-keymap
2615 (boundp 'w3m-minor-mode-map)
2616 w3m-minor-mode-map)
2617 (add-text-properties
2618 (point-min) (point-max)
2619 (list 'keymap w3m-minor-mode-map
2620 ;; Put the mark meaning this part was rendered by emacs-w3m.
2621 'mm-inline-text-html-with-w3m t))))
2622
2623 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2624
2625 (defun gnus-article-wash-html-with-w3m-standalone ()
2626 "Wash the current buffer with w3m."
2627 (if (mm-w3m-standalone-supports-m17n-p)
2628 (progn
2629 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2630 ;; The default.
2631 (setq charset 'iso-8859-1))
2632 (let ((coding-system-for-write charset)
2633 (coding-system-for-read charset))
2634 (call-process-region
2635 (point-min) (point-max)
2636 "w3m" t t nil "-dump" "-T" "text/html"
2637 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2638 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2639
2640 (defun article-hide-list-identifiers ()
2641 "Remove list identifies from the Subject header.
2642 The `gnus-list-identifiers' variable specifies what to do."
2643 (interactive)
2644 (let ((inhibit-point-motion-hooks t)
2645 (regexp (if (consp gnus-list-identifiers)
2646 (mapconcat 'identity gnus-list-identifiers " *\\|")
2647 gnus-list-identifiers))
2648 (inhibit-read-only t))
2649 (when regexp
2650 (save-excursion
2651 (save-restriction
2652 (article-narrow-to-head)
2653 (goto-char (point-min))
2654 (while (re-search-forward
2655 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2656 nil t)
2657 (delete-region (match-beginning 2) (match-end 0))
2658 (beginning-of-line))
2659 (when (re-search-forward
2660 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2661 (delete-region (match-beginning 1) (match-end 1))))))))
2662
2663 (defun article-hide-pem (&optional arg)
2664 "Toggle hiding of any PEM headers and signatures in the current article.
2665 If given a negative prefix, always show; if given a positive prefix,
2666 always hide."
2667 (interactive (gnus-article-hidden-arg))
2668 (unless (gnus-article-check-hidden-text 'pem arg)
2669 (save-excursion
2670 (let ((inhibit-read-only t) end)
2671 (goto-char (point-min))
2672 ;; Hide the horrendously ugly "header".
2673 (when (and (search-forward
2674 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2675 nil t)
2676 (setq end (1+ (match-beginning 0))))
2677 (gnus-add-wash-type 'pem)
2678 (gnus-article-hide-text-type
2679 end
2680 (if (search-forward "\n\n" nil t)
2681 (match-end 0)
2682 (point-max))
2683 'pem)
2684 ;; Hide the trailer as well
2685 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2686 nil t)
2687 (gnus-article-hide-text-type
2688 (match-beginning 0) (match-end 0) 'pem)))))))
2689
2690 (defun article-strip-banner ()
2691 "Strip the banners specified by the `banner' group parameter and by
2692 `gnus-article-address-banner-alist'."
2693 (interactive)
2694 (save-excursion
2695 (save-restriction
2696 (let ((inhibit-point-motion-hooks t))
2697 (when (gnus-parameter-banner gnus-newsgroup-name)
2698 (article-really-strip-banner
2699 (gnus-parameter-banner gnus-newsgroup-name)))
2700 (when gnus-article-address-banner-alist
2701 ;; Note that the From header is decoded here, so it is
2702 ;; required that the *-extract-address-components function
2703 ;; supports non-ASCII text.
2704 (let ((from (save-restriction
2705 (widen)
2706 (article-narrow-to-head)
2707 (mail-fetch-field "from"))))
2708 (when (and from
2709 (setq from
2710 (cadr (funcall gnus-extract-address-components
2711 from))))
2712 (catch 'found
2713 (dolist (pair gnus-article-address-banner-alist)
2714 (when (string-match (car pair) from)
2715 (throw 'found
2716 (article-really-strip-banner (cdr pair)))))))))))))
2717
2718 (defun article-really-strip-banner (banner)
2719 "Strip the banner specified by the argument."
2720 (save-excursion
2721 (save-restriction
2722 (let ((inhibit-point-motion-hooks t)
2723 (gnus-signature-limit nil)
2724 (inhibit-read-only t))
2725 (article-goto-body)
2726 (cond
2727 ((eq banner 'signature)
2728 (when (gnus-article-narrow-to-signature)
2729 (widen)
2730 (forward-line -1)
2731 (delete-region (point) (point-max))))
2732 ((symbolp banner)
2733 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2734 (while (re-search-forward banner nil t)
2735 (delete-region (match-beginning 0) (match-end 0)))))
2736 ((stringp banner)
2737 (while (re-search-forward banner nil t)
2738 (delete-region (match-beginning 0) (match-end 0)))))))))
2739
2740 (defun article-babel ()
2741 "Translate article using an online translation service."
2742 (interactive)
2743 (require 'babel)
2744 (save-excursion
2745 (set-buffer gnus-article-buffer)
2746 (when (article-goto-body)
2747 (let* ((inhibit-read-only t)
2748 (start (point))
2749 (end (point-max))
2750 (orig (buffer-substring start end))
2751 (trans (babel-as-string orig)))
2752 (save-restriction
2753 (narrow-to-region start end)
2754 (delete-region start end)
2755 (insert trans))))))
2756
2757 (defun article-hide-signature (&optional arg)
2758 "Hide the signature in the current article.
2759 If given a negative prefix, always show; if given a positive prefix,
2760 always hide."
2761 (interactive (gnus-article-hidden-arg))
2762 (unless (gnus-article-check-hidden-text 'signature arg)
2763 (save-excursion
2764 (save-restriction
2765 (let ((inhibit-read-only t))
2766 (when (gnus-article-narrow-to-signature)
2767 (gnus-article-hide-text-type
2768 (point-min) (point-max) 'signature))))))
2769 (gnus-set-mode-line 'article))
2770
2771 (defun article-strip-headers-in-body ()
2772 "Strip offensive headers from bodies."
2773 (interactive)
2774 (save-excursion
2775 (article-goto-body)
2776 (let ((case-fold-search t))
2777 (when (looking-at "x-no-archive:")
2778 (gnus-delete-line)))))
2779
2780 (defun article-strip-leading-blank-lines ()
2781 "Remove all blank lines from the beginning of the article."
2782 (interactive)
2783 (save-excursion
2784 (let ((inhibit-point-motion-hooks t)
2785 (inhibit-read-only t))
2786 (when (article-goto-body)
2787 (while (and (not (eobp))
2788 (looking-at "[ \t]*$"))
2789 (gnus-delete-line))))))
2790
2791 (defun article-narrow-to-head ()
2792 "Narrow the buffer to the head of the message.
2793 Point is left at the beginning of the narrowed-to region."
2794 (narrow-to-region
2795 (goto-char (point-min))
2796 (if (search-forward "\n\n" nil 1)
2797 (1- (point))
2798 (point-max)))
2799 (goto-char (point-min)))
2800
2801 (defun article-goto-body ()
2802 "Place point at the start of the body."
2803 (goto-char (point-min))
2804 (cond
2805 ;; This variable is only bound when dealing with separate
2806 ;; MIME body parts.
2807 (article-goto-body-goes-to-point-min-p
2808 t)
2809 ((search-forward "\n\n" nil t)
2810 t)
2811 (t
2812 (goto-char (point-max))
2813 nil)))
2814
2815 (defun article-strip-multiple-blank-lines ()
2816 "Replace consecutive blank lines with one empty line."
2817 (interactive)
2818 (save-excursion
2819 (let ((inhibit-point-motion-hooks t)
2820 (inhibit-read-only t))
2821 ;; First make all blank lines empty.
2822 (article-goto-body)
2823 (while (re-search-forward "^[ \t]+$" nil t)
2824 (unless (gnus-annotation-in-region-p
2825 (match-beginning 0) (match-end 0))
2826 (replace-match "" nil t)))
2827 ;; Then replace multiple empty lines with a single empty line.
2828 (article-goto-body)
2829 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2830 (unless (gnus-annotation-in-region-p
2831 (match-beginning 0) (match-end 0))
2832 (delete-region (match-beginning 1) (match-end 1)))))))
2833
2834 (defun article-strip-leading-space ()
2835 "Remove all white space from the beginning of the lines in the article."
2836 (interactive)
2837 (save-excursion
2838 (let ((inhibit-point-motion-hooks t)
2839 (inhibit-read-only t))
2840 (article-goto-body)
2841 (while (re-search-forward "^[ \t]+" nil t)
2842 (replace-match "" t t)))))
2843
2844 (defun article-strip-trailing-space ()
2845 "Remove all white space from the end of the lines in the article."
2846 (interactive)
2847 (save-excursion
2848 (let ((inhibit-point-motion-hooks t)
2849 (inhibit-read-only t))
2850 (article-goto-body)
2851 (while (re-search-forward "[ \t]+$" nil t)
2852 (replace-match "" t t)))))
2853
2854 (defun article-strip-blank-lines ()
2855 "Strip leading, trailing and multiple blank lines."
2856 (interactive)
2857 (article-strip-leading-blank-lines)
2858 (article-remove-trailing-blank-lines)
2859 (article-strip-multiple-blank-lines))
2860
2861 (defun article-strip-all-blank-lines ()
2862 "Strip all blank lines."
2863 (interactive)
2864 (save-excursion
2865 (let ((inhibit-point-motion-hooks t)
2866 (inhibit-read-only t))
2867 (article-goto-body)
2868 (while (re-search-forward "^[ \t]*\n" nil t)
2869 (replace-match "" t t)))))
2870
2871 (defun gnus-article-narrow-to-signature ()
2872 "Narrow to the signature; return t if a signature is found, else nil."
2873 (let ((inhibit-point-motion-hooks t))
2874 (when (gnus-article-search-signature)
2875 (forward-line 1)
2876 ;; Check whether we have some limits to what we consider
2877 ;; to be a signature.
2878 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2879 (list gnus-signature-limit)))
2880 limit limited)
2881 (while (setq limit (pop limits))
2882 (if (or (and (integerp limit)
2883 (< (- (point-max) (point)) limit))
2884 (and (floatp limit)
2885 (< (count-lines (point) (point-max)) limit))
2886 (and (functionp limit)
2887 (funcall limit))
2888 (and (stringp limit)
2889 (not (re-search-forward limit nil t))))
2890 () ; This limit did not succeed.
2891 (setq limited t
2892 limits nil)))
2893 (unless limited
2894 (narrow-to-region (point) (point-max))
2895 t)))))
2896
2897 (defun gnus-article-search-signature ()
2898 "Search the current buffer for the signature separator.
2899 Put point at the beginning of the signature separator."
2900 (let ((cur (point)))
2901 (goto-char (point-max))
2902 (if (if (stringp gnus-signature-separator)
2903 (re-search-backward gnus-signature-separator nil t)
2904 (let ((seps gnus-signature-separator))
2905 (while (and seps
2906 (not (re-search-backward (car seps) nil t)))
2907 (pop seps))
2908 seps))
2909 t
2910 (goto-char cur)
2911 nil)))
2912
2913 (defun gnus-article-hidden-arg ()
2914 "Return the current prefix arg as a number, or 0 if no prefix."
2915 (list (if current-prefix-arg
2916 (prefix-numeric-value current-prefix-arg)
2917 0)))
2918
2919 (defun gnus-article-check-hidden-text (type arg)
2920 "Return nil if hiding is necessary.
2921 Arg can be nil or a number. nil and positive means hide, negative
2922 means show, 0 means toggle."
2923 (save-excursion
2924 (save-restriction
2925 (let ((hide (gnus-article-hidden-text-p type)))
2926 (cond
2927 ((or (null arg)
2928 (> arg 0))
2929 nil)
2930 ((< arg 0)
2931 (gnus-article-show-hidden-text type)
2932 t)
2933 (t
2934 (if (eq hide 'hidden)
2935 (progn
2936 (gnus-article-show-hidden-text type)
2937 t)
2938 nil)))))))
2939
2940 (defun gnus-article-hidden-text-p (type)
2941 "Say whether the current buffer contains hidden text of type TYPE."
2942 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2943 (while (and pos
2944 (not (get-text-property pos 'invisible))
2945 (not (get-text-property pos 'dummy-invisible)))
2946 (setq pos
2947 (text-property-any (1+ pos) (point-max) 'article-type type)))
2948 (if pos
2949 'hidden
2950 nil)))
2951
2952 (defun gnus-article-show-hidden-text (type &optional dummy)
2953 "Show all hidden text of type TYPE.
2954 Originally it is hide instead of DUMMY."
2955 (let ((inhibit-read-only t)
2956 (inhibit-point-motion-hooks t))
2957 (gnus-remove-text-properties-when
2958 'article-type type
2959 (point-min) (point-max)
2960 (cons 'article-type (cons type
2961 gnus-hidden-properties)))
2962 (gnus-delete-wash-type type)))
2963
2964 (defconst article-time-units
2965 `((year . ,(* 365.25 24 60 60))
2966 (week . ,(* 7 24 60 60))
2967 (day . ,(* 24 60 60))
2968 (hour . ,(* 60 60))
2969 (minute . 60)
2970 (second . 1))
2971 "Mapping from time units to seconds.")
2972
2973 (defun gnus-article-forward-header ()
2974 "Move point to the start of the next header.
2975 If the current header is a continuation header, this can be several
2976 lines forward."
2977 (let ((ended nil))
2978 (while (not ended)
2979 (forward-line 1)
2980 (if (looking-at "[ \t]+[^ \t]")
2981 (forward-line 1)
2982 (setq ended t)))))
2983
2984 (defun article-date-ut (&optional type highlight)
2985 "Convert DATE date to universal time in the current article.
2986 If TYPE is `local', convert to local time; if it is `lapsed', output
2987 how much time has lapsed since DATE. For `lapsed', the value of
2988 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2989 should replace the \"Date:\" one, or should be added below it."
2990 (interactive (list 'ut t))
2991 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2992 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2993 tdate-regexp)
2994 ((eq type 'lapsed)
2995 "^X-Sent:[ \t]")
2996 (article-lapsed-timer
2997 "^Date:[ \t]")
2998 (t
2999 tdate-regexp)))
3000 (case-fold-search t)
3001 (inhibit-read-only t)
3002 (inhibit-point-motion-hooks t)
3003 pos date bface eface)
3004 (save-excursion
3005 (save-restriction
3006 (widen)
3007 (goto-char (point-min))
3008 (while (or (setq date (get-text-property (setq pos (point))
3009 'original-date))
3010 (when (setq pos (next-single-property-change
3011 (point) 'original-date))
3012 (setq date (get-text-property pos 'original-date))
3013 t))
3014 (narrow-to-region pos (or (text-property-any pos (point-max)
3015 'original-date nil)
3016 (point-max)))
3017 (goto-char (point-min))
3018 (when (re-search-forward tdate-regexp nil t)
3019 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3020 eface (get-text-property (1- (gnus-point-at-eol)) 'face)))
3021 (goto-char (point-min))
3022 (setq pos nil)
3023 ;; Delete any old Date headers.
3024 (while (re-search-forward date-regexp nil t)
3025 (if pos
3026 (delete-region (gnus-point-at-bol)
3027 (progn
3028 (gnus-article-forward-header)
3029 (point)))
3030 (delete-region (gnus-point-at-bol)
3031 (progn
3032 (gnus-article-forward-header)
3033 (forward-char -1)
3034 (point)))
3035 (setq pos (point))))
3036 (when (and (not pos)
3037 (re-search-forward tdate-regexp nil t))
3038 (forward-line 1))
3039 (gnus-goto-char pos)
3040 (insert (article-make-date-line date (or type 'ut)))
3041 (unless pos
3042 (insert "\n")
3043 (forward-line -1))
3044 ;; Do highlighting.
3045 (beginning-of-line)
3046 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3047 (put-text-property (match-beginning 1) (1+ (match-end 1))
3048 'face bface)
3049 (put-text-property (match-beginning 2) (match-end 2)
3050 'face eface))
3051 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3052 (goto-char (point-max))
3053 (widen))))))
3054
3055 (defun article-make-date-line (date type)
3056 "Return a DATE line of TYPE."
3057 (unless (memq type '(local ut original user iso8601 lapsed english))
3058 (error "Unknown conversion type: %s" type))
3059 (condition-case ()
3060 (let ((time (date-to-time date)))
3061 (cond
3062 ;; Convert to the local timezone.
3063 ((eq type 'local)
3064 (let ((tz (car (current-time-zone time))))
3065 (format "Date: %s %s%02d%02d" (current-time-string time)
3066 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3067 (/ (% (abs tz) 3600) 60))))
3068 ;; Convert to Universal Time.
3069 ((eq type 'ut)
3070 (concat "Date: "
3071 (current-time-string
3072 (let* ((e (parse-time-string date))
3073 (tm (apply 'encode-time e))
3074 (ms (car tm))
3075 (ls (- (cadr tm) (car (current-time-zone time)))))
3076 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3077 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3078 (t (list ms ls)))))
3079 " UT"))
3080 ;; Get the original date from the article.
3081 ((eq type 'original)
3082 (concat "Date: " (if (string-match "\n+$" date)
3083 (substring date 0 (match-beginning 0))
3084 date)))
3085 ;; Let the user define the format.
3086 ((eq type 'user)
3087 (let ((format (or (condition-case nil
3088 (with-current-buffer gnus-summary-buffer
3089 gnus-article-time-format)
3090 (error nil))
3091 gnus-article-time-format)))
3092 (if (functionp format)
3093 (funcall format time)
3094 (concat "Date: " (format-time-string format time)))))
3095 ;; ISO 8601.
3096 ((eq type 'iso8601)
3097 (let ((tz (car (current-time-zone time))))
3098 (concat
3099 "Date: "
3100 (format-time-string "%Y%m%dT%H%M%S" time)
3101 (format "%s%02d%02d"
3102 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3103 (/ (% (abs tz) 3600) 60)))))
3104 ;; Do an X-Sent lapsed format.
3105 ((eq type 'lapsed)
3106 ;; If the date is seriously mangled, the timezone functions are
3107 ;; liable to bug out, so we ignore all errors.
3108 (let* ((now (current-time))
3109 (real-time (subtract-time now time))
3110 (real-sec (and real-time
3111 (+ (* (float (car real-time)) 65536)
3112 (cadr real-time))))
3113 (sec (and real-time (abs real-sec)))
3114 num prev)
3115 (cond
3116 ((null real-time)
3117 "X-Sent: Unknown")
3118 ((zerop sec)
3119 "X-Sent: Now")
3120 (t
3121 (concat
3122 "X-Sent: "
3123 ;; This is a bit convoluted, but basically we go
3124 ;; through the time units for years, weeks, etc,
3125 ;; and divide things to see whether that results
3126 ;; in positive answers.
3127 (mapconcat
3128 (lambda (unit)
3129 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3130 ;; The (remaining) seconds are too few to
3131 ;; be divided into this time unit.
3132 ""
3133 ;; It's big enough, so we output it.
3134 (setq sec (- sec (* num (cdr unit))))
3135 (prog1
3136 (concat (if prev ", " "") (int-to-string
3137 (floor num))
3138 " " (symbol-name (car unit))
3139 (if (> num 1) "s" ""))
3140 (setq prev t))))
3141 article-time-units "")
3142 ;; If dates are odd, then it might appear like the
3143 ;; article was sent in the future.
3144 (if (> real-sec 0)
3145 " ago"
3146 " in the future"))))))
3147 ;; Display the date in proper English
3148 ((eq type 'english)
3149 (let ((dtime (decode-time time)))
3150 (concat
3151 "Date: the "
3152 (number-to-string (nth 3 dtime))
3153 (let ((digit (% (nth 3 dtime) 10)))
3154 (cond
3155 ((memq (nth 3 dtime) '(11 12 13)) "th")
3156 ((= digit 1) "st")
3157 ((= digit 2) "nd")
3158 ((= digit 3) "rd")
3159 (t "th")))
3160 " of "
3161 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3162 " "
3163 (number-to-string (nth 5 dtime))
3164 " at "
3165 (format "%02d" (nth 2 dtime))
3166 ":"
3167 (format "%02d" (nth 1 dtime)))))))
3168 (error
3169 (format "Date: %s (from Gnus)" date))))
3170
3171 (defun article-date-local (&optional highlight)
3172 "Convert the current article date to the local timezone."
3173 (interactive (list t))
3174 (article-date-ut 'local highlight))
3175
3176 (defun article-date-english (&optional highlight)
3177 "Convert the current article date to something that is proper English."
3178 (interactive (list t))
3179 (article-date-ut 'english highlight))
3180
3181 (defun article-date-original (&optional highlight)
3182 "Convert the current article date to what it was originally.
3183 This is only useful if you have used some other date conversion
3184 function and want to see what the date was before converting."
3185 (interactive (list t))
3186 (article-date-ut 'original highlight))
3187
3188 (defun article-date-lapsed (&optional highlight)
3189 "Convert the current article date to time lapsed since it was sent."
3190 (interactive (list t))
3191 (article-date-ut 'lapsed highlight))
3192
3193 (defun article-update-date-lapsed ()
3194 "Function to be run from a timer to update the lapsed time line."
3195 (save-match-data
3196 (let (deactivate-mark)
3197 (save-excursion
3198 (ignore-errors
3199 (walk-windows
3200 (lambda (w)
3201 (set-buffer (window-buffer w))
3202 (when (eq major-mode 'gnus-article-mode)
3203 (let ((mark (point-marker)))
3204 (goto-char (point-min))
3205 (when (re-search-forward "^X-Sent:" nil t)
3206 (article-date-lapsed t))
3207 (goto-char (marker-position mark))
3208 (move-marker mark nil))))
3209 nil 'visible))))))
3210
3211 (defun gnus-start-date-timer (&optional n)
3212 "Start a timer to update the X-Sent header in the article buffers.
3213 The numerical prefix says how frequently (in seconds) the function
3214 is to run."
3215 (interactive "p")
3216 (unless n
3217 (setq n 1))
3218 (gnus-stop-date-timer)
3219 (setq article-lapsed-timer
3220 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
3221
3222 (defun gnus-stop-date-timer ()
3223 "Stop the X-Sent timer."
3224 (interactive)
3225 (when article-lapsed-timer
3226 (nnheader-cancel-timer article-lapsed-timer)
3227 (setq article-lapsed-timer nil)))
3228
3229 (defun article-date-user (&optional highlight)
3230 "Convert the current article date to the user-defined format.
3231 This format is defined by the `gnus-article-time-format' variable."
3232 (interactive (list t))
3233 (article-date-ut 'user highlight))
3234
3235 (defun article-date-iso8601 (&optional highlight)
3236 "Convert the current article date to ISO8601."
3237 (interactive (list t))
3238 (article-date-ut 'iso8601 highlight))
3239
3240 (defmacro gnus-article-save-original-date (&rest forms)
3241 "Save the original date as a text property and evaluate FORMS."
3242 `(let* ((case-fold-search t)
3243 (start (progn
3244 (goto-char (point-min))
3245 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3246 (not (bolp)))
3247 (match-end 0))))
3248 (date (when (and start
3249 (re-search-forward "[\t ]*\n\\([^\t ]\\|\\'\\)"
3250 nil t))
3251 (buffer-substring-no-properties start
3252 (match-beginning 0)))))
3253 (goto-char (point-max))
3254 (skip-chars-backward "\n")
3255 (put-text-property (point-min) (point) 'original-date date)
3256 ,@forms
3257 (goto-char (point-max))
3258 (skip-chars-backward "\n")
3259 (put-text-property (point-min) (point) 'original-date date)))
3260
3261 ;; (defun article-show-all ()
3262 ;; "Show all hidden text in the article buffer."
3263 ;; (interactive)
3264 ;; (save-excursion
3265 ;; (let ((inhibit-read-only t))
3266 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3267
3268 (defun article-remove-leading-whitespace ()
3269 "Remove excessive whitespace from all headers."
3270 (interactive)
3271 (save-excursion
3272 (save-restriction
3273 (let ((inhibit-read-only t))
3274 (article-narrow-to-head)
3275 (goto-char (point-min))
3276 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3277 (delete-region (match-beginning 1) (match-end 1)))))))
3278
3279 (defun article-emphasize (&optional arg)
3280 "Emphasize text according to `gnus-emphasis-alist'."
3281 (interactive (gnus-article-hidden-arg))
3282 (unless (gnus-article-check-hidden-text 'emphasis arg)
3283 (save-excursion
3284 (let ((alist (or
3285 (condition-case nil
3286 (with-current-buffer gnus-summary-buffer
3287 gnus-article-emphasis-alist)
3288 (error))
3289 gnus-emphasis-alist))
3290 (inhibit-read-only t)
3291 (props (append '(article-type emphasis)
3292 gnus-hidden-properties))
3293 regexp elem beg invisible visible face)
3294 (article-goto-body)
3295 (setq beg (point))
3296 (while (setq elem (pop alist))
3297 (goto-char beg)
3298 (setq regexp (car elem)
3299 invisible (nth 1 elem)
3300 visible (nth 2 elem)
3301 face (nth 3 elem))
3302 (while (re-search-forward regexp nil t)
3303 (when (and (match-beginning visible) (match-beginning invisible))
3304 (gnus-article-hide-text
3305 (match-beginning invisible) (match-end invisible) props)
3306 (gnus-article-unhide-text-type
3307 (match-beginning visible) (match-end visible) 'emphasis)
3308 (gnus-put-overlay-excluding-newlines
3309 (match-beginning visible) (match-end visible) 'face face)
3310 (gnus-add-wash-type 'emphasis)
3311 (goto-char (match-end invisible)))))))))
3312
3313 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3314 "Setup newsgroup emphasis alist."
3315 (unless gnus-article-emphasis-alist
3316 (let ((name (and gnus-newsgroup-name
3317 (gnus-group-real-name gnus-newsgroup-name))))
3318 (make-local-variable 'gnus-article-emphasis-alist)
3319 (setq gnus-article-emphasis-alist
3320 (nconc
3321 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3322 (while (setq elem (pop alist))
3323 (when (and name (string-match (car elem) name))
3324 (setq alist nil
3325 highlight (copy-sequence (cdr elem)))))
3326 highlight)
3327 (copy-sequence highlight-words)
3328 (if gnus-newsgroup-name
3329 (copy-sequence (gnus-group-find-parameter
3330 gnus-newsgroup-name 'highlight-words t)))
3331 gnus-emphasis-alist)))))
3332
3333 (eval-when-compile
3334 (defvar gnus-summary-article-menu)
3335 (defvar gnus-summary-post-menu))
3336
3337 ;;; Saving functions.
3338
3339 (defun gnus-article-save (save-buffer file &optional num)
3340 "Save the currently selected article."
3341 (when (or (get gnus-default-article-saver :headers)
3342 (not gnus-save-all-headers))
3343 ;; Remove headers according to `gnus-saved-headers' or the value
3344 ;; of the `:headers' property that the saver function might have.
3345 (let ((gnus-visible-headers
3346 (or (symbol-value (get gnus-default-article-saver :headers))
3347 gnus-saved-headers gnus-visible-headers))
3348 (gnus-article-buffer save-buffer))
3349 (save-excursion
3350 (set-buffer save-buffer)
3351 (article-hide-headers 1 t))))
3352 (save-window-excursion
3353 (if (not gnus-default-article-saver)
3354 (error "No default saver is defined")
3355 ;; !!! Magic! The saving functions all save
3356 ;; `gnus-save-article-buffer' (or so they think), but we
3357 ;; bind that variable to our save-buffer.
3358 (set-buffer gnus-article-buffer)
3359 (let* ((gnus-save-article-buffer save-buffer)
3360 (filename
3361 (cond
3362 ((not gnus-prompt-before-saving) 'default)
3363 ((eq gnus-prompt-before-saving 'always) nil)
3364 (t file)))
3365 (gnus-number-of-articles-to-be-saved
3366 (when (eq gnus-prompt-before-saving t)
3367 num))) ; Magic
3368 (set-buffer gnus-article-current-summary)
3369 (funcall gnus-default-article-saver filename)))))
3370
3371 (defun gnus-read-save-file-name (prompt &optional filename
3372 function group headers variable
3373 dir-var)
3374 (let ((default-name
3375 (funcall function group headers (symbol-value variable)))
3376 result)
3377 (setq result
3378 (expand-file-name
3379 (cond
3380 ((eq filename 'default)
3381 default-name)
3382 ((eq filename t)
3383 default-name)
3384 (filename filename)
3385 (t
3386 (when (symbol-value dir-var)
3387 (setq default-name (expand-file-name
3388 (file-name-nondirectory default-name)
3389 (symbol-value dir-var))))
3390 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3391 (prompt
3392 (format prompt
3393 (if (and gnus-number-of-articles-to-be-saved
3394 (> gnus-number-of-articles-to-be-saved 1))
3395 (format "these %d articles"
3396 gnus-number-of-articles-to-be-saved)
3397 "this article")))
3398 (file
3399 ;; Let the split methods have their say.
3400 (cond
3401 ;; No split name was found.
3402 ((null split-name)
3403 (read-file-name
3404 (concat prompt " (default "
3405 (file-name-nondirectory default-name) "): ")
3406 (file-name-directory default-name)
3407 default-name))
3408 ;; A single group name is returned.
3409 ((stringp split-name)
3410 (setq default-name
3411 (funcall function split-name headers
3412 (symbol-value variable)))
3413 (read-file-name
3414 (concat prompt " (default "
3415 (file-name-nondirectory default-name) "): ")
3416 (file-name-directory default-name)
3417 default-name))
3418 ;; A single split name was found
3419 ((= 1 (length split-name))
3420 (let* ((name (expand-file-name
3421 (car split-name)
3422 gnus-article-save-directory))
3423 (dir (cond ((file-directory-p name)
3424 (file-name-as-directory name))
3425 ((file-exists-p name) name)
3426 (t gnus-article-save-directory))))
3427 (read-file-name
3428 (concat prompt " (default " name "): ")
3429 dir name)))
3430 ;; A list of splits was found.
3431 (t
3432 (setq split-name (nreverse split-name))
3433 (let (result)
3434 (let ((file-name-history
3435 (nconc split-name file-name-history)))
3436 (setq result
3437 (expand-file-name
3438 (read-file-name
3439 (concat prompt " (`M-p' for defaults): ")
3440 gnus-article-save-directory
3441 (car split-name))
3442 gnus-article-save-directory)))
3443 (car (push result file-name-history)))))))
3444 ;; Create the directory.
3445 (gnus-make-directory (file-name-directory file))
3446 ;; If we have read a directory, we append the default file name.
3447 (when (file-directory-p file)
3448 (setq file (expand-file-name (file-name-nondirectory
3449 default-name)
3450 (file-name-as-directory file))))
3451 ;; Possibly translate some characters.
3452 (nnheader-translate-file-chars file))))))
3453 (gnus-make-directory (file-name-directory result))
3454 (when variable
3455 (set variable result))
3456 (when dir-var
3457 (set dir-var (file-name-directory result)))
3458 result))
3459
3460 (defun gnus-article-archive-name (group)
3461 "Return the first instance of an \"Archive-name\" in the current buffer."
3462 (let ((case-fold-search t))
3463 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3464 (nnheader-concat gnus-article-save-directory
3465 (match-string 1)))))
3466
3467 (defun gnus-article-nndoc-name (group)
3468 "If GROUP is an nndoc group, return the name of the parent group."
3469 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3470 (gnus-group-get-parameter group 'save-article-group)))
3471
3472 (defun gnus-summary-save-in-rmail (&optional filename)
3473 "Append this article to Rmail file.
3474 Optional argument FILENAME specifies file name.
3475 Directory to save to is default to `gnus-article-save-directory'."
3476 (setq filename (gnus-read-save-file-name
3477 "Save %s in rmail file" filename
3478 gnus-rmail-save-name gnus-newsgroup-name
3479 gnus-current-headers 'gnus-newsgroup-last-rmail))
3480 (gnus-eval-in-buffer-window gnus-save-article-buffer
3481 (save-excursion
3482 (save-restriction
3483 (widen)
3484 (gnus-output-to-rmail filename))))
3485 filename)
3486
3487 (defun gnus-summary-save-in-mail (&optional filename)
3488 "Append this article to Unix mail file.
3489 Optional argument FILENAME specifies file name.
3490 Directory to save to is default to `gnus-article-save-directory'."
3491 (setq filename (gnus-read-save-file-name
3492 "Save %s in Unix mail file" filename
3493 gnus-mail-save-name gnus-newsgroup-name
3494 gnus-current-headers 'gnus-newsgroup-last-mail))
3495 (gnus-eval-in-buffer-window gnus-save-article-buffer
3496 (save-excursion
3497 (save-restriction
3498 (widen)
3499 (if (and (file-readable-p filename)
3500 (file-regular-p filename)
3501 (mail-file-babyl-p filename))
3502 (rmail-output-to-rmail-file filename t)
3503 (gnus-output-to-mail filename)))))
3504 filename)
3505
3506 (put 'gnus-summary-save-in-file :decode t)
3507 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3508 (defun gnus-summary-save-in-file (&optional filename overwrite)
3509 "Append this article to file.
3510 Optional argument FILENAME specifies file name.
3511 Directory to save to is default to `gnus-article-save-directory'."
3512 (setq filename (gnus-read-save-file-name
3513 "Save %s in file" filename
3514 gnus-file-save-name gnus-newsgroup-name
3515 gnus-current-headers 'gnus-newsgroup-last-file))
3516 (gnus-eval-in-buffer-window gnus-save-article-buffer
3517 (save-excursion
3518 (save-restriction
3519 (widen)
3520 (when (and overwrite
3521 (file-exists-p filename))
3522 (delete-file filename))
3523 (gnus-output-to-file filename))))
3524 filename)
3525
3526 (put 'gnus-summary-write-to-file :decode t)
3527 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3528 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3529 (defun gnus-summary-write-to-file (&optional filename)
3530 "Write this article to a file, overwriting it if the file exists.
3531 Optional argument FILENAME specifies file name.
3532 The directory to save in defaults to `gnus-article-save-directory'."
3533 (setq filename (gnus-read-save-file-name
3534 "Save %s in file" filename
3535 gnus-file-save-name gnus-newsgroup-name
3536 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3537 (gnus-summary-save-in-file filename t))
3538
3539 (put 'gnus-summary-save-body-in-file :decode t)
3540 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3541 "Append this article body to a file.
3542 Optional argument FILENAME specifies file name.
3543 The directory to save in defaults to `gnus-article-save-directory'."
3544 (setq filename (gnus-read-save-file-name
3545 "Save %s body in file" filename
3546 gnus-file-save-name gnus-newsgroup-name
3547 gnus-current-headers 'gnus-newsgroup-last-file))
3548 (gnus-eval-in-buffer-window gnus-save-article-buffer
3549 (save-excursion
3550 (save-restriction
3551 (widen)
3552 (when (article-goto-body)
3553 (narrow-to-region (point) (point-max)))
3554 (when (and overwrite
3555 (file-exists-p filename))
3556 (delete-file filename))
3557 (gnus-output-to-file filename))))
3558 filename)
3559
3560 (put 'gnus-summary-write-body-to-file :decode t)
3561 (put 'gnus-summary-write-body-to-file
3562 :function 'gnus-summary-save-body-in-file)
3563 (defun gnus-summary-write-body-to-file (&optional filename)
3564 "Write this article body to a file, overwriting it if the file exists.
3565 Optional argument FILENAME specifies file name.
3566 The directory to save in defaults to `gnus-article-save-directory'."
3567 (setq filename (gnus-read-save-file-name
3568 "Save %s body in file" filename
3569 gnus-file-save-name gnus-newsgroup-name
3570 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3571 (gnus-summary-save-body-in-file filename t))
3572
3573 (defun gnus-summary-save-in-pipe (&optional command)
3574 "Pipe this article to subprocess."
3575 (setq command
3576 (cond ((and (eq command 'default)
3577 gnus-last-shell-command)
3578 gnus-last-shell-command)
3579 ((stringp command)
3580 command)
3581 (t (read-string
3582 (format
3583 "Shell command on %s: "
3584 (if (and gnus-number-of-articles-to-be-saved
3585 (> gnus-number-of-articles-to-be-saved 1))
3586 (format "these %d articles"
3587 gnus-number-of-articles-to-be-saved)
3588 "this article"))
3589 gnus-last-shell-command))))
3590 (when (string-equal command "")
3591 (if gnus-last-shell-command
3592 (setq command gnus-last-shell-command)
3593 (error "A command is required")))
3594 (gnus-eval-in-buffer-window gnus-article-buffer
3595 (save-restriction
3596 (widen)
3597 (shell-command-on-region (point-min) (point-max) command nil)))
3598 (setq gnus-last-shell-command command))
3599
3600 (defmacro gnus-read-string (prompt &optional initial-contents history
3601 default-value)
3602 "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3603 (if (and (featurep 'xemacs)
3604 (< emacs-minor-version 2))
3605 `(read-string ,prompt ,initial-contents ,history)
3606 `(read-string ,prompt ,initial-contents ,history ,default-value)))
3607
3608 (defun gnus-summary-pipe-to-muttprint (&optional command)
3609 "Pipe this article to muttprint."
3610 (setq command (gnus-read-string
3611 "Print using command: " gnus-summary-muttprint-program
3612 nil gnus-summary-muttprint-program))
3613 (gnus-summary-save-in-pipe command))
3614
3615 ;;; Article file names when saving.
3616
3617 (defun gnus-capitalize-newsgroup (newsgroup)
3618 "Capitalize NEWSGROUP name."
3619 (when (not (zerop (length newsgroup)))
3620 (concat (char-to-string (upcase (aref newsgroup 0)))
3621 (substring newsgroup 1))))
3622
3623 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3624 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3625 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3626 Otherwise, it is like ~/News/news/group/num."
3627 (let ((default
3628 (expand-file-name
3629 (concat (if (gnus-use-long-file-name 'not-save)
3630 (gnus-capitalize-newsgroup newsgroup)
3631 (gnus-newsgroup-directory-form newsgroup))
3632 "/" (int-to-string (mail-header-number headers)))
3633 gnus-article-save-directory)))
3634 (if (and last-file
3635 (string-equal (file-name-directory default)
3636 (file-name-directory last-file))
3637 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3638 default
3639 (or last-file default))))
3640
3641 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3642 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3643 If variable `gnus-use-long-file-name' is non-nil, it is
3644 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3645 (let ((default
3646 (expand-file-name
3647 (concat (if (gnus-use-long-file-name 'not-save)
3648 newsgroup
3649 (gnus-newsgroup-directory-form newsgroup))
3650 "/" (int-to-string (mail-header-number headers)))
3651 gnus-article-save-directory)))
3652 (if (and last-file
3653 (string-equal (file-name-directory default)
3654 (file-name-directory last-file))
3655 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3656 default
3657 (or last-file default))))
3658
3659 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3660 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3661 If variable `gnus-use-long-file-name' is non-nil, it is
3662 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3663 (or last-file
3664 (expand-file-name
3665 (if (gnus-use-long-file-name 'not-save)
3666 newsgroup
3667 (file-relative-name
3668 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3669 default-directory))
3670 gnus-article-save-directory)))
3671
3672 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3673 "Generate file name from sender."
3674 (let ((from (mail-header-from headers)))
3675 (expand-file-name
3676 (if (and from (string-match "\\([^ <]+\\)@" from))
3677 (match-string 1 from)
3678 "nobody")
3679 gnus-article-save-directory)))
3680
3681 (defun article-verify-x-pgp-sig ()
3682 "Verify X-PGP-Sig."
3683 (interactive)
3684 (if (gnus-buffer-live-p gnus-original-article-buffer)
3685 (let ((sig (with-current-buffer gnus-original-article-buffer
3686 (gnus-fetch-field "X-PGP-Sig")))
3687 items info headers)
3688 (when (and sig
3689 mml2015-use
3690 (mml2015-clear-verify-function))
3691 (with-temp-buffer
3692 (insert-buffer-substring gnus-original-article-buffer)
3693 (setq items (split-string sig))
3694 (message-narrow-to-head)
3695 (let ((inhibit-point-motion-hooks t)
3696 (case-fold-search t))
3697 ;; Don't verify multiple headers.
3698 (setq headers (mapconcat (lambda (header)
3699 (concat header ": "
3700 (mail-fetch-field header)
3701 "\n"))
3702 (split-string (nth 1 items) ",") "")))
3703 (delete-region (point-min) (point-max))
3704 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3705 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3706 (insert headers)
3707 (widen)
3708 (forward-line)
3709 (while (not (eobp))
3710 (if (looking-at "^-")
3711 (insert "- "))
3712 (forward-line))
3713 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3714 (insert "Version: " (car items) "\n\n")
3715 (insert (mapconcat 'identity (cddr items) "\n"))
3716 (insert "\n-----END PGP SIGNATURE-----\n")
3717 (let ((mm-security-handle (list (format "multipart/signed"))))
3718 (mml2015-clean-buffer)
3719 (let ((coding-system-for-write (or gnus-newsgroup-charset
3720 'iso-8859-1)))
3721 (funcall (mml2015-clear-verify-function)))
3722 (setq info
3723 (or (mm-handle-multipart-ctl-parameter
3724 mm-security-handle 'gnus-details)
3725 (mm-handle-multipart-ctl-parameter
3726 mm-security-handle 'gnus-info)))))
3727 (when info
3728 (let ((inhibit-read-only t) bface eface)
3729 (save-restriction
3730 (message-narrow-to-head)
3731 (goto-char (point-max))
3732 (forward-line -1)
3733 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3734 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3735 (message-remove-header "X-Gnus-PGP-Verify")
3736 (if (re-search-forward "^X-PGP-Sig:" nil t)
3737 (forward-line)
3738 (goto-char (point-max)))
3739 (narrow-to-region (point) (point))
3740 (insert "X-Gnus-PGP-Verify: " info "\n")
3741 (goto-char (point-min))
3742 (forward-line)
3743 (while (not (eobp))
3744 (if (not (looking-at "^[ \t]"))
3745 (insert " "))
3746 (forward-line))
3747 ;; Do highlighting.
3748 (goto-char (point-min))
3749 (when (looking-at "\\([^:]+\\): *")
3750 (put-text-property (match-beginning 1) (1+ (match-end 1))
3751 'face bface)
3752 (put-text-property (match-end 0) (point-max)
3753 'face eface)))))))))
3754
3755 (defun article-verify-cancel-lock ()
3756 "Verify Cancel-Lock header."
3757 (interactive)
3758 (if (gnus-buffer-live-p gnus-original-article-buffer)
3759 (canlock-verify gnus-original-article-buffer)))
3760
3761 (eval-and-compile
3762 (mapcar
3763 (lambda (func)
3764 (let (afunc gfunc)
3765 (if (consp func)
3766 (setq afunc (car func)
3767 gfunc (cdr func))
3768 (setq afunc func
3769 gfunc (intern (format "gnus-%s" func))))
3770 (defalias gfunc
3771 (when (fboundp afunc)
3772 `(lambda (&optional interactive &rest args)
3773 ,(documentation afunc t)
3774 (interactive (list t))
3775 (save-excursion
3776 (set-buffer gnus-article-buffer)
3777 (if interactive
3778 (call-interactively ',afunc)
3779 (apply ',afunc args))))))))
3780 '(article-hide-headers
3781 article-verify-x-pgp-sig
3782 article-verify-cancel-lock
3783 article-hide-boring-headers
3784 article-treat-overstrike
3785 article-fill-long-lines
3786 article-capitalize-sentences
3787 article-remove-cr
3788 article-remove-leading-whitespace
3789 article-display-x-face
3790 article-display-face
3791 article-de-quoted-unreadable
3792 article-de-base64-unreadable
3793 article-decode-HZ
3794 article-wash-html
3795 article-unsplit-urls
3796 article-hide-list-identifiers
3797 article-strip-banner
3798 article-babel
3799 article-hide-pem
3800 article-hide-signature
3801 article-strip-headers-in-body
3802 article-remove-trailing-blank-lines
3803 article-strip-leading-blank-lines
3804 article-strip-multiple-blank-lines
3805 article-strip-leading-space
3806 article-strip-trailing-space
3807 article-strip-blank-lines
3808 article-strip-all-blank-lines
3809 article-date-local
3810 article-date-english
3811 article-date-iso8601
3812 article-date-original
3813 article-date-ut
3814 article-decode-mime-words
3815 article-decode-charset
3816 article-decode-encoded-words
3817 article-date-user
3818 article-date-lapsed
3819 article-emphasize
3820 article-treat-dumbquotes
3821 article-normalize-headers
3822 ;; (article-show-all . gnus-article-show-all-headers)
3823 )))
3824 \f
3825 ;;;
3826 ;;; Gnus article mode
3827 ;;;
3828
3829 (put 'gnus-article-mode 'mode-class 'special)
3830
3831 (set-keymap-parent gnus-article-mode-map widget-keymap)
3832
3833 (gnus-define-keys gnus-article-mode-map
3834 " " gnus-article-goto-next-page
3835 "\177" gnus-article-goto-prev-page
3836 [delete] gnus-article-goto-prev-page
3837 [backspace] gnus-article-goto-prev-page
3838 "\C-c^" gnus-article-refer-article
3839 "h" gnus-article-show-summary
3840 "s" gnus-article-show-summary
3841 "\C-c\C-m" gnus-article-mail
3842 "?" gnus-article-describe-briefly
3843 "e" gnus-summary-edit-article
3844 "<" beginning-of-buffer
3845 ">" end-of-buffer
3846 "\C-c\C-i" gnus-info-find-node
3847 "\C-c\C-b" gnus-bug
3848 "R" gnus-article-reply-with-original
3849 "F" gnus-article-followup-with-original
3850 "\C-hk" gnus-article-describe-key
3851 "\C-hc" gnus-article-describe-key-briefly
3852
3853 "\C-d" gnus-article-read-summary-keys
3854 "\M-*" gnus-article-read-summary-keys
3855 "\M-#" gnus-article-read-summary-keys
3856 "\M-^" gnus-article-read-summary-keys
3857 "\M-g" gnus-article-read-summary-keys)
3858
3859 (substitute-key-definition
3860 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3861
3862 (defun gnus-article-make-menu-bar ()
3863 (unless (boundp 'gnus-article-commands-menu)
3864 (gnus-summary-make-menu-bar))
3865 (gnus-turn-off-edit-menu 'article)
3866 (unless (boundp 'gnus-article-article-menu)
3867 (easy-menu-define
3868 gnus-article-article-menu gnus-article-mode-map ""
3869 '("Article"
3870 ["Scroll forwards" gnus-article-goto-next-page t]
3871 ["Scroll backwards" gnus-article-goto-prev-page t]
3872 ["Show summary" gnus-article-show-summary t]
3873 ["Fetch Message-ID at point" gnus-article-refer-article t]
3874 ["Mail to address at point" gnus-article-mail t]
3875 ["Send a bug report" gnus-bug t]))
3876
3877 (easy-menu-define
3878 gnus-article-treatment-menu gnus-article-mode-map ""
3879 ;; Fixme: this should use :active (and maybe :visible).
3880 '("Treatment"
3881 ["Hide headers" gnus-article-hide-headers t]
3882 ["Hide signature" gnus-article-hide-signature t]
3883 ["Hide citation" gnus-article-hide-citation t]
3884 ["Treat overstrike" gnus-article-treat-overstrike t]
3885 ["Remove carriage return" gnus-article-remove-cr t]
3886 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3887 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3888 ["Remove base64" gnus-article-de-base64-unreadable t]
3889 ["Treat html" gnus-article-wash-html t]
3890 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3891 ["Decode HZ" gnus-article-decode-HZ t]))
3892
3893 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3894
3895 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3896
3897 (gnus-run-hooks 'gnus-article-menu-hook)))
3898
3899 (defun gnus-article-mode ()
3900 "Major mode for displaying an article.
3901
3902 All normal editing commands are switched off.
3903
3904 The following commands are available in addition to all summary mode
3905 commands:
3906 \\<gnus-article-mode-map>
3907 \\[gnus-article-next-page]\t Scroll the article one page forwards
3908 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3909 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3910 \\[gnus-article-show-summary]\t Display the summary buffer
3911 \\[gnus-article-mail]\t Send a reply to the address near point
3912 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3913 \\[gnus-info-find-node]\t Go to the Gnus info node"
3914 (interactive)
3915 (kill-all-local-variables)
3916 (gnus-simplify-mode-line)
3917 (setq mode-name "Article")
3918 (setq major-mode 'gnus-article-mode)
3919 (make-local-variable 'minor-mode-alist)
3920 (use-local-map gnus-article-mode-map)
3921 (when (gnus-visual-p 'article-menu 'menu)
3922 (gnus-article-make-menu-bar)
3923 (when gnus-summary-tool-bar-map
3924 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3925 (gnus-update-format-specifications nil 'article-mode)
3926 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3927 (set (make-local-variable 'gnus-page-broken) nil)
3928 (make-local-variable 'gnus-button-marker-list)
3929 (make-local-variable 'gnus-article-current-summary)
3930 (make-local-variable 'gnus-article-mime-handles)
3931 (make-local-variable 'gnus-article-decoded-p)
3932 (make-local-variable 'gnus-article-mime-handle-alist)
3933 (make-local-variable 'gnus-article-wash-types)
3934 (make-local-variable 'gnus-article-image-alist)
3935 (make-local-variable 'gnus-article-charset)
3936 (make-local-variable 'gnus-article-ignored-charsets)
3937 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3938 (set (make-local-variable 'nobreak-char-display) nil)
3939 (setq cursor-in-non-selected-windows nil)
3940 (gnus-set-default-directory)
3941 (buffer-disable-undo)
3942 (setq buffer-read-only t)
3943 (set-syntax-table gnus-article-mode-syntax-table)
3944 (mm-enable-multibyte)
3945 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3946
3947 ;; Internal variables. Are `gnus-button-regexp' and `gnus-button-last' used
3948 ;; at all?
3949 (defvar gnus-button-regexp nil)
3950 (defvar gnus-button-marker-list nil
3951 "Regexp matching any of the regexps from `gnus-button-alist'.")
3952 (defvar gnus-button-last nil
3953 "The value of `gnus-button-alist' when `gnus-button-regexp' was build.")
3954
3955 (defun gnus-article-setup-buffer ()
3956 "Initialize the article buffer."
3957 (let* ((name (if gnus-single-article-buffer "*Article*"
3958 (concat "*Article " gnus-newsgroup-name "*")))
3959 (original
3960 (progn (string-match "\\*Article" name)
3961 (concat " *Original Article"
3962 (substring name (match-end 0))))))
3963 (setq gnus-article-buffer name)
3964 (setq gnus-original-article-buffer original)
3965 (setq gnus-article-mime-handle-alist nil)
3966 ;; This might be a variable local to the summary buffer.
3967 (unless gnus-single-article-buffer
3968 (save-excursion
3969 (set-buffer gnus-summary-buffer)
3970 (setq gnus-article-buffer name)
3971 (setq gnus-original-article-buffer original)
3972 (gnus-set-global-variables)))
3973 (gnus-article-setup-highlight-words)
3974 ;; Init original article buffer.
3975 (save-excursion
3976 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3977 (mm-enable-multibyte)
3978 (setq major-mode 'gnus-original-article-mode)
3979 (make-local-variable 'gnus-original-article))
3980 (if (and (get-buffer name)
3981 (with-current-buffer name
3982 (if gnus-article-edit-mode
3983 (if (y-or-n-p "Article mode edit in progress; discard? ")
3984 (progn
3985 (set-buffer-modified-p nil)
3986 (gnus-kill-buffer name)
3987 (message "")
3988 nil)
3989 (error "Action aborted"))
3990 t)))
3991 (save-excursion
3992 (set-buffer name)
3993 (set (make-local-variable 'gnus-article-edit-mode) nil)
3994 (when gnus-article-mime-handles
3995 (mm-destroy-parts gnus-article-mime-handles)
3996 (setq gnus-article-mime-handles nil))
3997 ;; Set it to nil in article-buffer!
3998 (setq gnus-article-mime-handle-alist nil)
3999 (buffer-disable-undo)
4000 (setq buffer-read-only t)
4001 ;; This list just keeps growing if we don't reset it.
4002 (setq gnus-button-marker-list nil)
4003 (unless (eq major-mode 'gnus-article-mode)
4004 (gnus-article-mode))
4005 (current-buffer))
4006 (save-excursion
4007 (set-buffer (gnus-get-buffer-create name))
4008 (gnus-article-mode)
4009 (make-local-variable 'gnus-summary-buffer)
4010 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4011 (current-buffer)))))
4012
4013 ;; Set article window start at LINE, where LINE is the number of lines
4014 ;; from the head of the article.
4015 (defun gnus-article-set-window-start (&optional line)
4016 (set-window-start
4017 (gnus-get-buffer-window gnus-article-buffer t)
4018 (save-excursion
4019 (set-buffer gnus-article-buffer)
4020 (goto-char (point-min))
4021 (if (not line)
4022 (point-min)
4023 (gnus-message 6 "Moved to bookmark")
4024 (search-forward "\n\n" nil t)
4025 (forward-line line)
4026 (point)))))
4027
4028 (defun gnus-article-prepare (article &optional all-headers header)
4029 "Prepare ARTICLE in article mode buffer.
4030 ARTICLE should either be an article number or a Message-ID.
4031 If ARTICLE is an id, HEADER should be the article headers.
4032 If ALL-HEADERS is non-nil, no headers are hidden."
4033 (save-excursion
4034 ;; Make sure we start in a summary buffer.
4035 (unless (eq major-mode 'gnus-summary-mode)
4036 (set-buffer gnus-summary-buffer))
4037 (setq gnus-summary-buffer (current-buffer))
4038 (let* ((gnus-article (if header (mail-header-number header) article))
4039 (summary-buffer (current-buffer))
4040 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4041 (group gnus-newsgroup-name)
4042 result)
4043 (save-excursion
4044 (gnus-article-setup-buffer)
4045 (set-buffer gnus-article-buffer)
4046 ;; Deactivate active regions.
4047 (when (and (boundp 'transient-mark-mode)
4048 transient-mark-mode)
4049 (setq mark-active nil))
4050 (if (not (setq result (let ((inhibit-read-only t))
4051 (gnus-request-article-this-buffer
4052 article group))))
4053 ;; There is no such article.
4054 (save-excursion
4055 (when (and (numberp article)
4056 (not (memq article gnus-newsgroup-sparse)))
4057 (setq gnus-article-current
4058 (cons gnus-newsgroup-name article))
4059 (set-buffer gnus-summary-buffer)
4060 (setq gnus-current-article article)
4061 (if (and (memq article gnus-newsgroup-undownloaded)
4062 (not (gnus-online (gnus-find-method-for-group
4063 gnus-newsgroup-name))))
4064 (progn
4065 (gnus-summary-set-agent-mark article)
4066 (message "Message marked for downloading"))
4067 (gnus-summary-mark-article article gnus-canceled-mark)
4068 (unless (memq article gnus-newsgroup-sparse)
4069 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4070 (if (or (eq result 'pseudo)
4071 (eq result 'nneething))
4072 (progn
4073 (save-excursion
4074 (set-buffer summary-buffer)
4075 (push article gnus-newsgroup-history)
4076 (setq gnus-last-article gnus-current-article
4077 gnus-current-article 0
4078 gnus-current-headers nil
4079 gnus-article-current nil)
4080 (if (eq result 'nneething)
4081 (gnus-configure-windows 'summary)
4082 (gnus-configure-windows 'article))
4083 (gnus-set-global-variables))
4084 (let ((gnus-article-mime-handle-alist-1
4085 gnus-article-mime-handle-alist))
4086 (gnus-set-mode-line 'article)))
4087 ;; The result from the `request' was an actual article -
4088 ;; or at least some text that is now displayed in the
4089 ;; article buffer.
4090 (when (and (numberp article)
4091 (not (eq article gnus-current-article)))
4092 ;; Seems like a new article has been selected.
4093 ;; `gnus-current-article' must be an article number.
4094 (save-excursion
4095 (set-buffer summary-buffer)
4096 (push article gnus-newsgroup-history)
4097 (setq gnus-last-article gnus-current-article
4098 gnus-current-article article
4099 gnus-current-headers
4100 (gnus-summary-article-header gnus-current-article)
4101 gnus-article-current
4102 (cons gnus-newsgroup-name gnus-current-article))
4103 (unless (vectorp gnus-current-headers)
4104 (setq gnus-current-headers nil))
4105 (gnus-summary-goto-subject gnus-current-article)
4106 (when (gnus-summary-show-thread)
4107 ;; If the summary buffer really was folded, the
4108 ;; previous goto may not actually have gone to
4109 ;; the right article, but the thread root instead.
4110 ;; So we go again.
4111 (gnus-summary-goto-subject gnus-current-article))
4112 (gnus-run-hooks 'gnus-mark-article-hook)
4113 (gnus-set-mode-line 'summary)
4114 (when (gnus-visual-p 'article-highlight 'highlight)
4115 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4116 ;; Set the global newsgroup variables here.
4117 (gnus-set-global-variables)
4118 (setq gnus-have-all-headers
4119 (or all-headers gnus-show-all-headers))))
4120 (save-excursion
4121 (gnus-configure-windows 'article))
4122 (when (or (numberp article)
4123 (stringp article))
4124 (gnus-article-prepare-display)
4125 ;; Do page break.
4126 (goto-char (point-min))
4127 (when gnus-break-pages
4128 (gnus-narrow-to-page)))
4129 (let ((gnus-article-mime-handle-alist-1
4130 gnus-article-mime-handle-alist))
4131 (gnus-set-mode-line 'article))
4132 (article-goto-body)
4133 (unless (bobp)
4134 (forward-line -1))
4135 (set-window-point (get-buffer-window (current-buffer)) (point))
4136 (gnus-configure-windows 'article)
4137 t))))))
4138
4139 ;;;###autoload
4140 (defun gnus-article-prepare-display ()
4141 "Make the current buffer look like a nice article."
4142 ;; Hooks for getting information from the article.
4143 ;; This hook must be called before being narrowed.
4144 (let ((gnus-article-buffer (current-buffer))
4145 buffer-read-only
4146 (inhibit-read-only t))
4147 (unless (eq major-mode 'gnus-article-mode)
4148 (gnus-article-mode))
4149 (setq buffer-read-only nil
4150 gnus-article-wash-types nil
4151 gnus-article-image-alist nil)
4152 (gnus-run-hooks 'gnus-tmp-internal-hook)
4153 (when gnus-display-mime-function
4154 (funcall gnus-display-mime-function))
4155 (gnus-run-hooks 'gnus-article-prepare-hook)))
4156
4157 ;;;
4158 ;;; Gnus MIME viewing functions
4159 ;;;
4160
4161 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4162 "Format of the MIME buttons.
4163
4164 Valid specifiers include:
4165 %t The MIME type
4166 %T MIME type, along with additional info
4167 %n The `name' parameter
4168 %d The description, if any
4169 %l The length of the encoded part
4170 %p The part identifier number
4171 %e Dots if the part isn't displayed
4172
4173 General format specifiers can also be used. See Info node
4174 `(gnus)Formatting Variables'.")
4175
4176 (defvar gnus-mime-button-line-format-alist
4177 '((?t gnus-tmp-type ?s)
4178 (?T gnus-tmp-type-long ?s)
4179 (?n gnus-tmp-name ?s)
4180 (?d gnus-tmp-description ?s)
4181 (?p gnus-tmp-id ?s)
4182 (?l gnus-tmp-length ?d)
4183 (?e gnus-tmp-dots ?s)))
4184
4185 (defvar gnus-mime-button-commands
4186 '((gnus-article-press-button "\r" "Toggle Display")
4187 (gnus-mime-view-part "v" "View Interactively...")
4188 (gnus-mime-view-part-as-type "t" "View As Type...")
4189 (gnus-mime-view-part-as-charset "C" "View As charset...")
4190 (gnus-mime-save-part "o" "Save...")
4191 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4192 (gnus-mime-delete-part "d" "Delete part")
4193 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4194 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4195 (gnus-mime-view-part-internally "E" "View Internally")
4196 (gnus-mime-view-part-externally "e" "View Externally")
4197 (gnus-mime-print-part "p" "Print")
4198 (gnus-mime-pipe-part "|" "Pipe To Command...")
4199 (gnus-mime-action-on-part "." "Take action on the part...")))
4200
4201 (defun gnus-article-mime-part-status ()
4202 (if gnus-article-mime-handle-alist-1
4203 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4204 " (1 part)"
4205 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4206 ""))
4207
4208 (defvar gnus-mime-button-map
4209 (let ((map (make-sparse-keymap)))
4210 (unless (>= (string-to-number emacs-version) 21)
4211 ;; XEmacs doesn't care.
4212 (set-keymap-parent map gnus-article-mode-map))
4213 (define-key map gnus-mouse-2 'gnus-article-push-button)
4214 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4215 (dolist (c gnus-mime-button-commands)
4216 (define-key map (cadr c) (car c)))
4217 map))
4218
4219 (easy-menu-define
4220 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4221 `("MIME Part"
4222 ,@(mapcar (lambda (c)
4223 (vector (caddr c) (car c) :enable t))
4224 gnus-mime-button-commands)))
4225
4226 (eval-when-compile
4227 (define-compiler-macro popup-menu (&whole form
4228 menu &optional position prefix)
4229 (if (and (fboundp 'popup-menu)
4230 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4231 form
4232 ;; Gnus is probably running under Emacs 20.
4233 `(let* ((menu (cdr ,menu))
4234 (response (x-popup-menu
4235 t (list (car menu)
4236 (cons "" (mapcar (lambda (c)
4237 (cons (caddr c) (car c)))
4238 (cdr menu)))))))
4239 (if response
4240 (call-interactively (nth 3 (assq response menu))))))))
4241
4242 (defun gnus-mime-button-menu (event prefix)
4243 "Construct a context-sensitive menu of MIME commands."
4244 (interactive "e\nP")
4245 (save-window-excursion
4246 (let ((pos (event-start event)))
4247 (select-window (posn-window pos))
4248 (goto-char (posn-point pos))
4249 (gnus-article-check-buffer)
4250 (popup-menu gnus-mime-button-menu nil prefix))))
4251
4252 (defun gnus-mime-view-all-parts (&optional handles)
4253 "View all the MIME parts."
4254 (interactive)
4255 (save-current-buffer
4256 (set-buffer gnus-article-buffer)
4257 (let ((handles (or handles gnus-article-mime-handles))
4258 (mail-parse-charset gnus-newsgroup-charset)
4259 (mail-parse-ignored-charsets
4260 (with-current-buffer gnus-summary-buffer
4261 gnus-newsgroup-ignored-charsets)))
4262 (when handles
4263 (mm-remove-parts handles)
4264 (goto-char (point-min))
4265 (or (search-forward "\n\n") (goto-char (point-max)))
4266 (let ((inhibit-read-only t))
4267 (delete-region (point) (point-max))
4268 (mm-display-parts handles))))))
4269
4270 (defun gnus-mime-save-part-and-strip ()
4271 "Save the MIME part under point then replace it with an external body."
4272 (interactive)
4273 (gnus-article-check-buffer)
4274 (when (gnus-group-read-only-p)
4275 (error "The current group does not support deleting of parts"))
4276 (when (mm-complicated-handles gnus-article-mime-handles)
4277 (error "\
4278 The current article has a complicated MIME structure, giving up..."))
4279 (when (gnus-yes-or-no-p "\
4280 Deleting parts may malfunction or destroy the article; continue? ")
4281 (let* ((data (get-text-property (point) 'gnus-data))
4282 file param
4283 (handles gnus-article-mime-handles))
4284 (setq file (and data (mm-save-part data)))
4285 (when file
4286 (with-current-buffer (mm-handle-buffer data)
4287 (erase-buffer)
4288 (insert "Content-Type: " (mm-handle-media-type data))
4289 (mml-insert-parameter-string (cdr (mm-handle-type data))
4290 '(charset))
4291 ;; Add a filename for the sake of saving the part again.
4292 (mml-insert-parameter
4293 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4294 (insert "\n")
4295 (insert "Content-ID: " (message-make-message-id) "\n")
4296 (insert "Content-Transfer-Encoding: binary\n")
4297 (insert "\n"))
4298 (setcdr data
4299 (cdr (mm-make-handle nil
4300 `("message/external-body"
4301 (access-type . "LOCAL-FILE")
4302 (name . ,file)))))
4303 (set-buffer gnus-summary-buffer)
4304 (gnus-article-edit-article
4305 `(lambda ()
4306 (erase-buffer)
4307 (let ((mail-parse-charset (or gnus-article-charset
4308 ',gnus-newsgroup-charset))
4309 (mail-parse-ignored-charsets
4310 (or gnus-article-ignored-charsets
4311 ',gnus-newsgroup-ignored-charsets))
4312 (mbl mml-buffer-list))
4313 (setq mml-buffer-list nil)
4314 (insert-buffer-substring gnus-original-article-buffer)
4315 (mime-to-mml ',handles)
4316 (setq gnus-article-mime-handles nil)
4317 (let ((mbl1 mml-buffer-list))
4318 (setq mml-buffer-list mbl)
4319 (set (make-local-variable 'mml-buffer-list) mbl1))
4320 (gnus-make-local-hook 'kill-buffer-hook)
4321 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4322 `(lambda (no-highlight)
4323 (let ((mail-parse-charset (or gnus-article-charset
4324 ',gnus-newsgroup-charset))
4325 (message-options message-options)
4326 (message-options-set-recipient)
4327 (mail-parse-ignored-charsets
4328 (or gnus-article-ignored-charsets
4329 ',gnus-newsgroup-ignored-charsets)))
4330 (mml-to-mime)
4331 (mml-destroy-buffers)
4332 (remove-hook 'kill-buffer-hook
4333 'mml-destroy-buffers t)
4334 (kill-local-variable 'mml-buffer-list))
4335 (gnus-summary-edit-article-done
4336 ,(or (mail-header-references gnus-current-headers) "")
4337 ,(gnus-group-read-only-p)
4338 ,gnus-summary-buffer no-highlight)))))))
4339
4340 (defun gnus-mime-delete-part ()
4341 "Delete the MIME part under point.
4342 Replace it with some information about the removed part."
4343 (interactive)
4344 (gnus-article-check-buffer)
4345 (when (gnus-group-read-only-p)
4346 (error "The current group does not support deleting of parts"))
4347 (when (mm-complicated-handles gnus-article-mime-handles)
4348 (error "\
4349 The current article has a complicated MIME structure, giving up..."))
4350 (when (gnus-yes-or-no-p "\
4351 Deleting parts may malfunction or destroy the article; continue? ")
4352 (let* ((data (get-text-property (point) 'gnus-data))
4353 (handles gnus-article-mime-handles)
4354 (none "(none)")
4355 (description
4356 (mail-decode-encoded-word-string (or (mm-handle-description data)
4357 none)))
4358 (filename
4359 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4360 none))
4361 (type (mm-handle-media-type data)))
4362 (unless data
4363 (error "No MIME part under point"))
4364 (with-current-buffer (mm-handle-buffer data)
4365 (let ((bsize (format "%s" (buffer-size))))
4366 (erase-buffer)
4367 (insert
4368 (concat
4369 ",----\n"
4370 "| The following attachment has been deleted:\n"
4371 "|\n"
4372 "| Type: " type "\n"
4373 "| Filename: " filename "\n"
4374 "| Size (encoded): " bsize " Byte\n"
4375 "| Description: " description "\n"
4376 "`----\n"))
4377 (setcdr data
4378 (cdr (mm-make-handle
4379 nil `("text/plain") nil nil
4380 (list "attachment")
4381 (format "Deleted attachment (%s bytes)" bsize))))))
4382 (set-buffer gnus-summary-buffer)
4383 ;; FIXME: maybe some of the following code (borrowed from
4384 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4385 (gnus-article-edit-article
4386 `(lambda ()
4387 (erase-buffer)
4388 (let ((mail-parse-charset (or gnus-article-charset
4389 ',gnus-newsgroup-charset))
4390 (mail-parse-ignored-charsets
4391 (or gnus-article-ignored-charsets
4392 ',gnus-newsgroup-ignored-charsets))
4393 (mbl mml-buffer-list))
4394 (setq mml-buffer-list nil)
4395 (insert-buffer-substring gnus-original-article-buffer)
4396 (mime-to-mml ',handles)
4397 (setq gnus-article-mime-handles nil)
4398 (let ((mbl1 mml-buffer-list))
4399 (setq mml-buffer-list mbl)
4400 (set (make-local-variable 'mml-buffer-list) mbl1))
4401 (gnus-make-local-hook 'kill-buffer-hook)
4402 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4403 `(lambda (no-highlight)
4404 (let ((mail-parse-charset (or gnus-article-charset
4405 ',gnus-newsgroup-charset))
4406 (message-options message-options)
4407 (message-options-set-recipient)
4408 (mail-parse-ignored-charsets
4409 (or gnus-article-ignored-charsets
4410 ',gnus-newsgroup-ignored-charsets)))
4411 (mml-to-mime)
4412 (mml-destroy-buffers)
4413 (remove-hook 'kill-buffer-hook
4414 'mml-destroy-buffers t)
4415 (kill-local-variable 'mml-buffer-list))
4416 (gnus-summary-edit-article-done
4417 ,(or (mail-header-references gnus-current-headers) "")
4418 ,(gnus-group-read-only-p)
4419 ,gnus-summary-buffer no-highlight)))))
4420 ;; Not in `gnus-mime-save-part-and-strip':
4421 (gnus-article-edit-done)
4422 (gnus-summary-expand-window)
4423 (gnus-summary-show-article))
4424
4425 (defun gnus-mime-save-part ()
4426 "Save the MIME part under point."
4427 (interactive)
4428 (gnus-article-check-buffer)
4429 (let ((data (get-text-property (point) 'gnus-data)))
4430 (when data
4431 (mm-save-part data))))
4432
4433 (defun gnus-mime-pipe-part ()
4434 "Pipe the MIME part under point to a process."
4435 (interactive)
4436 (gnus-article-check-buffer)
4437 (let ((data (get-text-property (point) 'gnus-data)))
4438 (when data
4439 (mm-pipe-part data))))
4440
4441 (defun gnus-mime-view-part ()
4442 "Interactively choose a viewing method for the MIME part under point."
4443 (interactive)
4444 (gnus-article-check-buffer)
4445 (let ((data (get-text-property (point) 'gnus-data)))
4446 (when data
4447 (setq gnus-article-mime-handles
4448 (mm-merge-handles
4449 gnus-article-mime-handles (setq data (copy-sequence data))))
4450 (mm-interactively-view-part data))))
4451
4452 (defun gnus-mime-view-part-as-type-internal ()
4453 (gnus-article-check-buffer)
4454 (let* ((handle (get-text-property (point) 'gnus-data))
4455 (name (or
4456 ;; Content-Type: foo/bar; name=...
4457 (mail-content-type-get (mm-handle-type handle) 'name)
4458 ;; Content-Disposition: attachment; filename=...
4459 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4460 (def-type (and name (mm-default-file-encoding name))))
4461 (and def-type (cons def-type 0))))
4462
4463 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4464 "Choose a MIME media type, and view the part as such.
4465 If non-nil, PRED is a predicate to use during completion to limit the
4466 available media-types."
4467 (interactive)
4468 (unless mime-type
4469 (setq mime-type
4470 (let ((default (gnus-mime-view-part-as-type-internal)))
4471 (completing-read
4472 (format "View as MIME type (default %s): "
4473 (car default))
4474 (mapcar #'list (mailcap-mime-types))
4475 pred nil nil nil
4476 (car default)))))
4477 (gnus-article-check-buffer)
4478 (let ((handle (get-text-property (point) 'gnus-data)))
4479 (when handle
4480 (when (equal (mm-handle-media-type handle) "message/external-body")
4481 (unless (mm-handle-cache handle)
4482 (mm-extern-cache-contents handle))
4483 (setq handle (mm-handle-cache handle)))
4484 (setq handle
4485 (mm-make-handle (mm-handle-buffer handle)
4486 (cons mime-type (cdr (mm-handle-type handle)))
4487 (mm-handle-encoding handle)
4488 (mm-handle-undisplayer handle)
4489 (mm-handle-disposition handle)
4490 (mm-handle-description handle)
4491 nil
4492 (mm-handle-id handle)))
4493 (setq gnus-article-mime-handles
4494 (mm-merge-handles gnus-article-mime-handles handle))
4495 (gnus-mm-display-part handle))))
4496
4497 (eval-when-compile
4498 (require 'jka-compr))
4499
4500 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4501 ;; emacs can do that itself.
4502 ;;
4503 (defun gnus-mime-jka-compr-maybe-uncompress ()
4504 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4505 The uncompress method used is derived from `buffer-file-name'."
4506 (when (and (fboundp 'jka-compr-installed-p)
4507 (jka-compr-installed-p))
4508 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4509 (when info
4510 (let ((basename (file-name-nondirectory buffer-file-name))
4511 (args (jka-compr-info-uncompress-args info))
4512 (prog (jka-compr-info-uncompress-program info))
4513 (message (jka-compr-info-uncompress-message info))
4514 (err-file (jka-compr-make-temp-name)))
4515 (if message
4516 (message "%s %s..." message basename))
4517 (unwind-protect
4518 (unless (memq (apply 'call-process-region
4519 (point-min) (point-max)
4520 prog
4521 t (list t err-file) nil
4522 args)
4523 jka-compr-acceptable-retval-list)
4524 (jka-compr-error prog args basename message err-file))
4525 (jka-compr-delete-temp-file err-file)))))))
4526
4527 (defun gnus-mime-copy-part (&optional handle)
4528 "Put the MIME part under point into a new buffer.
4529 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4530 are decompressed."
4531 (interactive)
4532 (gnus-article-check-buffer)
4533 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4534 (contents (and handle (mm-get-part handle)))
4535 (base (and handle
4536 (file-name-nondirectory
4537 (or
4538 (mail-content-type-get (mm-handle-type handle) 'name)
4539 (mail-content-type-get (mm-handle-disposition handle)
4540 'filename)
4541 "*decoded*"))))
4542 (buffer (and base (generate-new-buffer base))))
4543 (when contents
4544 (switch-to-buffer buffer)
4545 (insert contents)
4546 ;; We do it this way to make `normal-mode' set the appropriate mode.
4547 (unwind-protect
4548 (progn
4549 (setq buffer-file-name (expand-file-name base))
4550 (gnus-mime-jka-compr-maybe-uncompress)
4551 (normal-mode))
4552 (setq buffer-file-name nil))
4553 (goto-char (point-min)))))
4554
4555 (defun gnus-mime-print-part (&optional handle filename)
4556 "Print the MIME part under point."
4557 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4558 (gnus-article-check-buffer)
4559 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4560 (contents (and handle (mm-get-part handle)))
4561 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4562 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4563 (when contents
4564 (if printer
4565 (unwind-protect
4566 (progn
4567 (mm-save-part-to-file handle file)
4568 (call-process shell-file-name nil
4569 (generate-new-buffer " *mm*")
4570 nil
4571 shell-command-switch
4572 (mm-mailcap-command
4573 printer file (mm-handle-type handle))))
4574 (delete-file file))
4575 (with-temp-buffer
4576 (insert contents)
4577 (gnus-print-buffer))
4578 (ps-despool filename)))))
4579
4580 (defun gnus-mime-inline-part (&optional handle arg)
4581 "Insert the MIME part under point into the current buffer."
4582 (interactive (list nil current-prefix-arg))
4583 (gnus-article-check-buffer)
4584 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4585 contents charset
4586 (b (point))
4587 (inhibit-read-only t))
4588 (when handle
4589 (if (and (not arg) (mm-handle-undisplayer handle))
4590 (mm-remove-part handle)
4591 (setq contents (mm-get-part handle))
4592 (cond
4593 ((not arg)
4594 (setq charset (or (mail-content-type-get
4595 (mm-handle-type handle) 'charset)
4596 gnus-newsgroup-charset)))
4597 ((numberp arg)
4598 (if (mm-handle-undisplayer handle)
4599 (mm-remove-part handle))
4600 (setq charset
4601 (or (cdr (assq arg
4602 gnus-summary-show-article-charset-alist))
4603 (mm-read-coding-system "Charset: "))))
4604 (t
4605 (if (mm-handle-undisplayer handle)
4606 (mm-remove-part handle))))
4607 (forward-line 2)
4608 (mm-insert-inline
4609 handle
4610 (if (and charset
4611 (setq charset (mm-charset-to-coding-system
4612 charset))
4613 (not (eq charset 'ascii)))
4614 (mm-decode-coding-string contents charset)
4615 (mm-string-to-multibyte contents)))
4616 (goto-char b)))))
4617
4618 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4619 "Insert the MIME part under point into the current buffer using the
4620 specified charset."
4621 (interactive (list nil current-prefix-arg))
4622 (gnus-article-check-buffer)
4623 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4624 (fun (get-text-property (point) 'gnus-callback))
4625 (gnus-newsgroup-ignored-charsets 'gnus-all)
4626 gnus-newsgroup-charset type charset)
4627 (when handle
4628 (if (mm-handle-undisplayer handle)
4629 (mm-remove-part handle))
4630 (when fun
4631 (setq gnus-newsgroup-charset
4632 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4633 (mm-read-coding-system "Charset: ")))
4634 ;; Strip the charset parameter from `handle'.
4635 (setq type (mm-handle-type
4636 (if (equal (mm-handle-media-type handle)
4637 "message/external-body")
4638 (progn
4639 (unless (mm-handle-cache handle)
4640 (mm-extern-cache-contents handle))
4641 (mm-handle-cache handle))
4642 handle))
4643 charset (assq 'charset (cdr type)))
4644 (delq charset type)
4645 (funcall fun handle)))))
4646
4647 (defun gnus-mime-view-part-externally (&optional handle)
4648 "View the MIME part under point with an external viewer."
4649 (interactive)
4650 (gnus-article-check-buffer)
4651 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4652 (mm-user-display-methods nil)
4653 (mm-inlined-types nil)
4654 (mail-parse-charset gnus-newsgroup-charset)
4655 (mail-parse-ignored-charsets
4656 (with-current-buffer gnus-summary-buffer
4657 gnus-newsgroup-ignored-charsets))
4658 (type (mm-handle-media-type handle))
4659 (method (mailcap-mime-info type))
4660 (mm-enable-external t))
4661 (if (not (stringp method))
4662 (gnus-mime-view-part-as-type
4663 nil (lambda (type) (stringp (mailcap-mime-info type))))
4664 (when handle
4665 (if (mm-handle-undisplayer handle)
4666 (mm-remove-part handle)
4667 (mm-display-part handle))))))
4668
4669 (defun gnus-mime-view-part-internally (&optional handle)
4670 "View the MIME part under point with an internal viewer.
4671 If no internal viewer is available, use an external viewer."
4672 (interactive)
4673 (gnus-article-check-buffer)
4674 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4675 (mm-inlined-types '(".*"))
4676 (mm-inline-large-images t)
4677 (mail-parse-charset gnus-newsgroup-charset)
4678 (mail-parse-ignored-charsets
4679 (with-current-buffer gnus-summary-buffer
4680 gnus-newsgroup-ignored-charsets))
4681 (inhibit-read-only t))
4682 (if (not (mm-inlinable-p handle))
4683 (gnus-mime-view-part-as-type
4684 nil (lambda (type) (mm-inlinable-p handle type)))
4685 (when handle
4686 (if (mm-handle-undisplayer handle)
4687 (mm-remove-part handle)
4688 (mm-display-part handle))))))
4689
4690 (defun gnus-mime-action-on-part (&optional action)
4691 "Do something with the MIME attachment at \(point\)."
4692 (interactive
4693 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4694 (gnus-article-check-buffer)
4695 (let ((action-pair (assoc action gnus-mime-action-alist)))
4696 (if action-pair
4697 (funcall (cdr action-pair)))))
4698
4699 (defun gnus-article-part-wrapper (n function)
4700 (save-current-buffer
4701 (set-buffer gnus-article-buffer)
4702 (when (> n (length gnus-article-mime-handle-alist))
4703 (error "No such part"))
4704 (gnus-article-goto-part n)
4705 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4706 (funcall function handle))))
4707
4708 (defun gnus-article-pipe-part (n)
4709 "Pipe MIME part N, which is the numerical prefix."
4710 (interactive "p")
4711 (gnus-article-part-wrapper n 'mm-pipe-part))
4712
4713 (defun gnus-article-save-part (n)
4714 "Save MIME part N, which is the numerical prefix."
4715 (interactive "p")
4716 (gnus-article-part-wrapper n 'mm-save-part))
4717
4718 (defun gnus-article-interactively-view-part (n)
4719 "View MIME part N interactively, which is the numerical prefix."
4720 (interactive "p")
4721 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4722
4723 (defun gnus-article-copy-part (n)
4724 "Copy MIME part N, which is the numerical prefix."
4725 (interactive "p")
4726 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4727
4728 (defun gnus-article-view-part-as-charset (n)
4729 "View MIME part N using a specified charset.
4730 N is the numerical prefix."
4731 (interactive "p")
4732 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4733
4734 (defun gnus-article-view-part-externally (n)
4735 "View MIME part N externally, which is the numerical prefix."
4736 (interactive "p")
4737 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4738
4739 (defun gnus-article-inline-part (n)
4740 "Inline MIME part N, which is the numerical prefix."
4741 (interactive "p")
4742 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4743
4744 (defun gnus-article-mime-match-handle-first (condition)
4745 (if condition
4746 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4747 (while (setq ihandle (pop alist))
4748 (if (and (cond
4749 ((functionp condition)
4750 (funcall condition (cdr ihandle)))
4751 ((eq condition 'undisplayed)
4752 (not (or (mm-handle-undisplayer (cdr ihandle))
4753 (equal (mm-handle-media-type (cdr ihandle))
4754 "multipart/alternative"))))
4755 ((eq condition 'undisplayed-alternative)
4756 (not (mm-handle-undisplayer (cdr ihandle))))
4757 (t t))
4758 (gnus-article-goto-part (car ihandle))
4759 (or (not n) (< (car ihandle) n)))
4760 (setq n (car ihandle))))
4761 (or n 1))
4762 1))
4763
4764 (defun gnus-article-view-part (&optional n)
4765 "View MIME part N, which is the numerical prefix."
4766 (interactive "P")
4767 (save-current-buffer
4768 (set-buffer gnus-article-buffer)
4769 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4770 gnus-article-mime-match-handle-function)))
4771 (when (> n (length gnus-article-mime-handle-alist))
4772 (error "No such part"))
4773 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4774 (when (gnus-article-goto-part n)
4775 (if (equal (car handle) "multipart/alternative")
4776 (gnus-article-press-button)
4777 (when (eq (gnus-mm-display-part handle) 'internal)
4778 (gnus-set-window-start)))))))
4779
4780 (defsubst gnus-article-mime-total-parts ()
4781 (if (bufferp (car gnus-article-mime-handles))
4782 1 ;; single part
4783 (1- (length gnus-article-mime-handles))))
4784
4785 (defun gnus-mm-display-part (handle)
4786 "Display HANDLE and fix MIME button."
4787 (let ((id (get-text-property (point) 'gnus-part))
4788 (point (point))
4789 (inhibit-read-only t))
4790 (forward-line 1)
4791 (prog1
4792 (let ((window (selected-window))
4793 (mail-parse-charset gnus-newsgroup-charset)
4794 (mail-parse-ignored-charsets
4795 (if (gnus-buffer-live-p gnus-summary-buffer)
4796 (save-excursion
4797 (set-buffer gnus-summary-buffer)
4798 gnus-newsgroup-ignored-charsets)
4799 nil)))
4800 (save-excursion
4801 (unwind-protect
4802 (let ((win (gnus-get-buffer-window (current-buffer) t))
4803 (beg (point)))
4804 (when win
4805 (select-window win))
4806 (goto-char point)
4807 (forward-line)
4808 (if (mm-handle-displayed-p handle)
4809 ;; This will remove the part.
4810 (mm-display-part handle)
4811 (save-restriction
4812 (narrow-to-region (point)
4813 (if (eobp) (point) (1+ (point))))
4814 (mm-display-part handle)
4815 ;; We narrow to the part itself and
4816 ;; then call the treatment functions.
4817 (goto-char (point-min))
4818 (forward-line 1)
4819 (narrow-to-region (point) (point-max))
4820 (gnus-treat-article
4821 nil id
4822 (gnus-article-mime-total-parts)
4823 (mm-handle-media-type handle)))))
4824 (if (window-live-p window)
4825 (select-window window)))))
4826 (goto-char point)
4827 (gnus-delete-line)
4828 (gnus-insert-mime-button
4829 handle id (list (mm-handle-displayed-p handle)))
4830 (goto-char point))))
4831
4832 (defun gnus-article-goto-part (n)
4833 "Go to MIME part N."
4834 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4835
4836 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4837 (let ((gnus-tmp-name
4838 (or (mail-content-type-get (mm-handle-type handle) 'name)
4839 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4840 (mail-content-type-get (mm-handle-type handle) 'url)
4841 ""))
4842 (gnus-tmp-type (mm-handle-media-type handle))
4843 (gnus-tmp-description
4844 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4845 "")))
4846 (gnus-tmp-dots
4847 (if (if displayed (car displayed)
4848 (mm-handle-displayed-p handle))
4849 "" "..."))
4850 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4851 (buffer-size)))
4852 gnus-tmp-type-long b e)
4853 (when (string-match ".*/" gnus-tmp-name)
4854 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4855 (setq gnus-tmp-type-long (concat gnus-tmp-type
4856 (and (not (equal gnus-tmp-name ""))
4857 (concat "; " gnus-tmp-name))))
4858 (unless (equal gnus-tmp-description "")
4859 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4860 (unless (bolp)
4861 (insert "\n"))
4862 (setq b (point))
4863 (gnus-eval-format
4864 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4865 `(,@(gnus-local-map-property gnus-mime-button-map)
4866 gnus-callback gnus-mm-display-part
4867 gnus-part ,gnus-tmp-id
4868 article-type annotation
4869 gnus-data ,handle))
4870 (setq e (if (bolp)
4871 ;; Exclude a newline.
4872 (1- (point))
4873 (point)))
4874 (widget-convert-button
4875 'link b e
4876 :mime-handle handle
4877 :action 'gnus-widget-press-button
4878 :button-keymap gnus-mime-button-map
4879 :help-echo
4880 (lambda (widget/window &optional overlay pos)
4881 ;; Needed to properly clear the message due to a bug in
4882 ;; wid-edit (XEmacs only).
4883 (if (boundp 'help-echo-owns-message)
4884 (setq help-echo-owns-message t))
4885 (format
4886 "%S: %s the MIME part; %S: more options"
4887 (aref gnus-mouse-2 0)
4888 ;; XEmacs will get a single widget arg; Emacs 21 will get
4889 ;; window, overlay, position.
4890 (if (mm-handle-displayed-p
4891 (if overlay
4892 (with-current-buffer (gnus-overlay-buffer overlay)
4893 (widget-get (widget-at (gnus-overlay-start overlay))
4894 :mime-handle))
4895 (widget-get widget/window :mime-handle)))
4896 "hide" "show")
4897 (aref gnus-down-mouse-3 0))))))
4898
4899 (defun gnus-widget-press-button (elems el)
4900 (goto-char (widget-get elems :from))
4901 (gnus-article-press-button))
4902
4903 (defvar gnus-displaying-mime nil)
4904
4905 (defun gnus-display-mime (&optional ihandles)
4906 "Display the MIME parts."
4907 (save-excursion
4908 (save-selected-window
4909 (let ((window (get-buffer-window gnus-article-buffer))
4910 (point (point)))
4911 (when window
4912 (select-window window)
4913 ;; We have to do this since selecting the window
4914 ;; may change the point. So we set the window point.
4915 (set-window-point window point)))
4916 (let ((handles ihandles)
4917 (inhibit-read-only t)
4918 handle)
4919 (cond (handles)
4920 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4921 (when gnus-article-emulate-mime
4922 (mm-uu-dissect-text-parts handles)))
4923 (gnus-article-emulate-mime
4924 (setq handles (mm-uu-dissect))))
4925 (when (and (not ihandles)
4926 (not gnus-displaying-mime))
4927 ;; Top-level call; we clean up.
4928 (when gnus-article-mime-handles
4929 (mm-destroy-parts gnus-article-mime-handles)
4930 (setq gnus-article-mime-handle-alist nil));; A trick.
4931 (setq gnus-article-mime-handles handles)
4932 ;; We allow users to glean info from the handles.
4933 (when gnus-article-mime-part-function
4934 (gnus-mime-part-function handles)))
4935 (if (and handles
4936 (or (not (stringp (car handles)))
4937 (cdr handles)))
4938 (progn
4939 (when (and (not ihandles)
4940 (not gnus-displaying-mime))
4941 ;; Clean up for mime parts.
4942 (article-goto-body)
4943 (delete-region (point) (point-max)))
4944 (let ((gnus-displaying-mime t))
4945 (gnus-mime-display-part handles)))
4946 (save-restriction
4947 (article-goto-body)
4948 (narrow-to-region (point) (point-max))
4949 (gnus-treat-article nil 1 1)
4950 (widen)))
4951 (unless ihandles
4952 ;; Highlight the headers.
4953 (save-excursion
4954 (save-restriction
4955 (article-goto-body)
4956 (narrow-to-region (point-min) (point))
4957 (gnus-article-save-original-date
4958 (gnus-treat-article 'head)))))))
4959 ;; Cope with broken MIME messages.
4960 (goto-char (point-max))
4961 (unless (bolp)
4962 (insert "\n"))))
4963
4964 (defcustom gnus-mime-display-multipart-as-mixed nil
4965 "Display \"multipart\" parts as \"multipart/mixed\".
4966
4967 If t, it overrides nil values of
4968 `gnus-mime-display-multipart-alternative-as-mixed' and
4969 `gnus-mime-display-multipart-related-as-mixed'."
4970 :group 'gnus-article-mime
4971 :type 'boolean)
4972
4973 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4974 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4975 :version "22.1"
4976 :group 'gnus-article-mime
4977 :type 'boolean)
4978
4979 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4980 "Display \"multipart/related\" parts as \"multipart/mixed\".
4981
4982 If displaying \"text/html\" is discouraged \(see
4983 `mm-discouraged-alternatives'\) images or other material inside a
4984 \"multipart/related\" part might be overlooked when this variable is nil."
4985 :version "22.1"
4986 :group 'gnus-article-mime
4987 :type 'boolean)
4988
4989 (defun gnus-mime-display-part (handle)
4990 (cond
4991 ;; Maybe a broken MIME message.
4992 ((null handle))
4993 ;; Single part.
4994 ((not (stringp (car handle)))
4995 (gnus-mime-display-single handle))
4996 ;; User-defined multipart
4997 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4998 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4999 handle))
5000 ;; multipart/alternative
5001 ((and (equal (car handle) "multipart/alternative")
5002 (not (or gnus-mime-display-multipart-as-mixed
5003 gnus-mime-display-multipart-alternative-as-mixed)))
5004 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5005 (push (cons id handle) gnus-article-mime-handle-alist)
5006 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5007 ;; multipart/related
5008 ((and (equal (car handle) "multipart/related")
5009 (not (or gnus-mime-display-multipart-as-mixed
5010 gnus-mime-display-multipart-related-as-mixed)))
5011 ;;;!!!We should find the start part, but we just default
5012 ;;;!!!to the first part.
5013 ;;(gnus-mime-display-part (cadr handle))
5014 ;;;!!! Most multipart/related is an HTML message plus images.
5015 ;;;!!! Unfortunately we are unable to let W3 display those
5016 ;;;!!! included images, so we just display it as a mixed multipart.
5017 ;;(gnus-mime-display-mixed (cdr handle))
5018 ;;;!!! No, w3 can display everything just fine.
5019 (gnus-mime-display-part (cadr handle)))
5020 ((equal (car handle) "multipart/signed")
5021 (gnus-add-wash-type 'signed)
5022 (gnus-mime-display-security handle))
5023 ((equal (car handle) "multipart/encrypted")
5024 (gnus-add-wash-type 'encrypted)
5025 (gnus-mime-display-security handle))
5026 ;; Other multiparts are handled like multipart/mixed.
5027 (t
5028 (gnus-mime-display-mixed (cdr handle)))))
5029
5030 (defun gnus-mime-part-function (handles)
5031 (if (stringp (car handles))
5032 (mapcar 'gnus-mime-part-function (cdr handles))
5033 (funcall gnus-article-mime-part-function handles)))
5034
5035 (defun gnus-mime-display-mixed (handles)
5036 (mapcar 'gnus-mime-display-part handles))
5037
5038 (defun gnus-mime-display-single (handle)
5039 (let ((type (mm-handle-media-type handle))
5040 (ignored gnus-ignored-mime-types)
5041 (not-attachment t)
5042 (move nil)
5043 display text)
5044 (catch 'ignored
5045 (progn
5046 (while ignored
5047 (when (string-match (pop ignored) type)
5048 (throw 'ignored nil)))
5049 (if (and (setq not-attachment
5050 (and (not (mm-inline-override-p handle))
5051 (or (not (mm-handle-disposition handle))
5052 (equal (car (mm-handle-disposition handle))
5053 "inline")
5054 (mm-attachment-override-p handle))))
5055 (mm-automatic-display-p handle)
5056 (or (and
5057 (mm-inlinable-p handle)
5058 (mm-inlined-p handle))
5059 (mm-automatic-external-display-p type)))
5060 (setq display t)
5061 (when (equal (mm-handle-media-supertype handle) "text")
5062 (setq text t)))
5063 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5064 beg)
5065 (push (cons id handle) gnus-article-mime-handle-alist)
5066 (when (and display
5067 (equal (mm-handle-media-supertype handle) "message"))
5068 (insert-char
5069 ?\n
5070 (cond ((not (bolp)) 2)
5071 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5072 (t 1))))
5073 (when (or (not display)
5074 (not (gnus-unbuttonized-mime-type-p type)))
5075 (gnus-insert-mime-button
5076 handle id (list (or display (and not-attachment text))))
5077 (gnus-article-insert-newline)
5078 ;; Remember modify the number of forward lines.
5079 (setq move t))
5080 (setq beg (point))
5081 (cond
5082 (display
5083 (when move
5084 (forward-line -1)
5085 (setq beg (point)))
5086 (let ((mail-parse-charset gnus-newsgroup-charset)
5087 (mail-parse-ignored-charsets
5088 (save-excursion (condition-case ()
5089 (set-buffer gnus-summary-buffer)
5090 (error))
5091 gnus-newsgroup-ignored-charsets)))
5092 (mm-display-part handle t))
5093 (goto-char (point-max)))
5094 ((and text not-attachment)
5095 (when move
5096 (forward-line -1)
5097 (setq beg (point)))
5098 (gnus-article-insert-newline)
5099 (mm-insert-inline
5100 handle
5101 (let ((charset (mail-content-type-get (mm-handle-type handle)
5102 'charset)))
5103 (cond ((not charset)
5104 (mm-string-as-multibyte (mm-get-part handle)))
5105 ((eq charset 'gnus-decoded)
5106 (with-current-buffer (mm-handle-buffer handle)
5107 (buffer-string)))
5108 (t
5109 (mm-decode-string (mm-get-part handle) charset)))))
5110 (goto-char (point-max))))
5111 ;; Do highlighting.
5112 (save-excursion
5113 (save-restriction
5114 (narrow-to-region beg (point))
5115 (gnus-treat-article
5116 nil id
5117 (gnus-article-mime-total-parts)
5118 (mm-handle-media-type handle)))))))))
5119
5120 (defun gnus-unbuttonized-mime-type-p (type)
5121 "Say whether TYPE is to be unbuttonized."
5122 (unless gnus-inhibit-mime-unbuttonizing
5123 (when (catch 'found
5124 (let ((types gnus-unbuttonized-mime-types))
5125 (while types
5126 (when (string-match (pop types) type)
5127 (throw 'found t)))))
5128 (not (catch 'found
5129 (let ((types gnus-buttonized-mime-types))
5130 (while types
5131 (when (string-match (pop types) type)
5132 (throw 'found t)))))))))
5133
5134 (defun gnus-article-insert-newline ()
5135 "Insert a newline, but mark it as undeletable."
5136 (gnus-put-text-property
5137 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5138
5139 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5140 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5141 (ihandles handles)
5142 (point (point))
5143 handle (inhibit-read-only t) from props begend not-pref)
5144 (save-window-excursion
5145 (save-restriction
5146 (when ibegend
5147 (narrow-to-region (car ibegend)
5148 (or (cdr ibegend)
5149 (progn
5150 (goto-char (car ibegend))
5151 (forward-line 2)
5152 (point))))
5153 (delete-region (point-min) (point-max))
5154 (mm-remove-parts handles))
5155 (setq begend (list (point-marker)))
5156 ;; Do the toggle.
5157 (unless (setq not-pref (cadr (member preferred ihandles)))
5158 (setq not-pref (car ihandles)))
5159 (when (or ibegend
5160 (not preferred)
5161 (not (gnus-unbuttonized-mime-type-p
5162 "multipart/alternative")))
5163 (gnus-add-text-properties
5164 (setq from (point))
5165 (progn
5166 (insert (format "%d. " id))
5167 (point))
5168 `(gnus-callback
5169 (lambda (handles)
5170 (unless ,(not ibegend)
5171 (setq gnus-article-mime-handle-alist
5172 ',gnus-article-mime-handle-alist))
5173 (gnus-mime-display-alternative
5174 ',ihandles ',not-pref ',begend ,id))
5175 ,@(gnus-local-map-property gnus-mime-button-map)
5176 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5177 face ,gnus-article-button-face
5178 gnus-part ,id
5179 article-type multipart))
5180 (widget-convert-button 'link from (point)
5181 :action 'gnus-widget-press-button
5182 :button-keymap gnus-widget-button-keymap)
5183 ;; Do the handles
5184 (while (setq handle (pop handles))
5185 (gnus-add-text-properties
5186 (setq from (point))
5187 (progn
5188 (insert (format "(%c) %-18s"
5189 (if (equal handle preferred) ?* ? )
5190 (mm-handle-media-type handle)))
5191 (point))
5192 `(gnus-callback
5193 (lambda (handles)
5194 (unless ,(not ibegend)
5195 (setq gnus-article-mime-handle-alist
5196 ',gnus-article-mime-handle-alist))
5197 (gnus-mime-display-alternative
5198 ',ihandles ',handle ',begend ,id))
5199 ,@(gnus-local-map-property gnus-mime-button-map)
5200 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5201 face ,gnus-article-button-face
5202 gnus-part ,id
5203 gnus-data ,handle))
5204 (widget-convert-button 'link from (point)
5205 :action 'gnus-widget-press-button
5206 :button-keymap gnus-widget-button-keymap)
5207 (insert " "))
5208 (insert "\n\n"))
5209 (when preferred
5210 (if (stringp (car preferred))
5211 (gnus-display-mime preferred)
5212 (let ((mail-parse-charset gnus-newsgroup-charset)
5213 (mail-parse-ignored-charsets
5214 (save-excursion (set-buffer gnus-summary-buffer)
5215 gnus-newsgroup-ignored-charsets)))
5216 (mm-display-part preferred)
5217 ;; Do highlighting.
5218 (save-excursion
5219 (save-restriction
5220 (narrow-to-region (car begend) (point-max))
5221 (gnus-treat-article
5222 nil (length gnus-article-mime-handle-alist)
5223 (gnus-article-mime-total-parts)
5224 (mm-handle-media-type handle))))))
5225 (goto-char (point-max))
5226 (setcdr begend (point-marker)))))
5227 (when ibegend
5228 (goto-char point))))
5229
5230 (defconst gnus-article-wash-status-strings
5231 (let ((alist '((cite "c" "Possible hidden citation text"
5232 " " "All citation text visible")
5233 (headers "h" "Hidden headers"
5234 " " "All headers visible.")
5235 (pgp "p" "Encrypted or signed message status hidden"
5236 " " "No hidden encryption nor digital signature status")
5237 (signature "s" "Signature has been hidden"
5238 " " "Signature is visible")
5239 (overstrike "o" "Overstrike (^H) characters applied"
5240 " " "No overstrike characters applied")
5241 (emphasis "e" "/*_Emphasis_*/ characters applied"
5242 " " "No /*_emphasis_*/ characters applied")))
5243 result)
5244 (dolist (entry alist result)
5245 (let ((key (nth 0 entry))
5246 (on (copy-sequence (nth 1 entry)))
5247 (on-help (nth 2 entry))
5248 (off (copy-sequence (nth 3 entry)))
5249 (off-help (nth 4 entry)))
5250 (put-text-property 0 1 'help-echo on-help on)
5251 (put-text-property 0 1 'help-echo off-help off)
5252 (push (list key on off) result))))
5253 "Alist of strings describing wash status in the mode line.
5254 Each entry has the form (KEY ON OF), where the KEY is a symbol
5255 representing the particular washing function, ON is the string to use
5256 in the article mode line when the washing function is active, and OFF
5257 is the string to use when it is inactive.")
5258
5259 (defun gnus-article-wash-status-entry (key value)
5260 (let ((entry (assoc key gnus-article-wash-status-strings)))
5261 (if value (nth 1 entry) (nth 2 entry))))
5262
5263 (defun gnus-article-wash-status ()
5264 "Return a string which display status of article washing."
5265 (save-excursion
5266 (set-buffer gnus-article-buffer)
5267 (let ((cite (memq 'cite gnus-article-wash-types))
5268 (headers (memq 'headers gnus-article-wash-types))
5269 (boring (memq 'boring-headers gnus-article-wash-types))
5270 (pgp (memq 'pgp gnus-article-wash-types))
5271 (pem (memq 'pem gnus-article-wash-types))
5272 (signed (memq 'signed gnus-article-wash-types))
5273 (encrypted (memq 'encrypted gnus-article-wash-types))
5274 (signature (memq 'signature gnus-article-wash-types))
5275 (overstrike (memq 'overstrike gnus-article-wash-types))
5276 (emphasis (memq 'emphasis gnus-article-wash-types)))
5277 (concat
5278 (gnus-article-wash-status-entry 'cite cite)
5279 (gnus-article-wash-status-entry 'headers (or headers boring))
5280 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5281 (gnus-article-wash-status-entry 'signature signature)
5282 (gnus-article-wash-status-entry 'overstrike overstrike)
5283 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5284
5285 (defun gnus-add-wash-type (type)
5286 "Add a washing of TYPE to the current status."
5287 (add-to-list 'gnus-article-wash-types type))
5288
5289 (defun gnus-delete-wash-type (type)
5290 "Add a washing of TYPE to the current status."
5291 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5292
5293 (defun gnus-add-image (category image)
5294 "Add IMAGE of CATEGORY to the list of displayed images."
5295 (let ((entry (assq category gnus-article-image-alist)))
5296 (unless entry
5297 (setq entry (list category))
5298 (push entry gnus-article-image-alist))
5299 (nconc entry (list image))))
5300
5301 (defun gnus-delete-images (category)
5302 "Delete all images in CATEGORY."
5303 (let ((entry (assq category gnus-article-image-alist)))
5304 (dolist (image (cdr entry))
5305 (gnus-remove-image image category))
5306 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5307 (gnus-delete-wash-type category)))
5308
5309 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5310
5311 (defun gnus-article-maybe-hide-headers ()
5312 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5313 Provided for backwards compatibility."
5314 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5315 (not (save-excursion (set-buffer gnus-summary-buffer)
5316 gnus-have-all-headers)))
5317 (not gnus-inhibit-hiding))
5318 (gnus-article-hide-headers)))
5319
5320 ;;; Article savers.
5321
5322 (defun gnus-output-to-file (file-name)
5323 "Append the current article to a file named FILE-NAME.
5324 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5325 text and used as the value of the coding cookie which is added to the
5326 top of a file. Otherwise, this function saves a raw article without
5327 the coding cookie."
5328 (let* ((artbuf (current-buffer))
5329 (file-name-coding-system nnmail-pathname-coding-system)
5330 (coding gnus-article-save-coding-system)
5331 (coding-system-for-read (if coding
5332 nil ;; Rely on the coding cookie.
5333 mm-text-coding-system))
5334 (coding-system-for-write (or coding
5335 mm-text-coding-system-for-write
5336 mm-text-coding-system))
5337 (exists (file-exists-p file-name)))
5338 (with-temp-buffer
5339 (when exists
5340 (insert-file-contents file-name)
5341 (goto-char (point-min))
5342 ;; Remove the existing coding cookie.
5343 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5344 (delete-region (match-beginning 0) (match-end 0))))
5345 (goto-char (point-max))
5346 (insert-buffer-substring artbuf)
5347 ;; Append newline at end of the buffer as separator, and then
5348 ;; save it to file.
5349 (goto-char (point-max))
5350 (insert "\n")
5351 (when coding
5352 ;; If the coding system is not suitable to encode the text,
5353 ;; ask a user for a proper one.
5354 (when (fboundp 'select-safe-coding-system)
5355 (setq coding (coding-system-base
5356 (save-window-excursion
5357 (select-safe-coding-system (point-min) (point-max)
5358 coding))))
5359 (setq coding-system-for-write
5360 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5361 coding)))
5362 (goto-char (point-min))
5363 ;; Add the coding cookie.
5364 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5365 coding-system-for-write)))
5366 (if exists
5367 (progn
5368 (write-region (point-min) (point-max) file-name nil 'no-message)
5369 (message "Appended to %s" file-name))
5370 (write-region (point-min) (point-max) file-name))))
5371 t)
5372
5373 (defun gnus-narrow-to-page (&optional arg)
5374 "Narrow the article buffer to a page.
5375 If given a numerical ARG, move forward ARG pages."
5376 (interactive "P")
5377 (setq arg (if arg (prefix-numeric-value arg) 0))
5378 (save-excursion
5379 (set-buffer gnus-article-buffer)
5380 (goto-char (point-min))
5381 (widen)
5382 ;; Remove any old next/prev buttons.
5383 (when (gnus-visual-p 'page-marker)
5384 (let ((inhibit-read-only t))
5385 (gnus-remove-text-with-property 'gnus-prev)
5386 (gnus-remove-text-with-property 'gnus-next)))
5387 (if
5388 (cond ((< arg 0)
5389 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5390 ((> arg 0)
5391 (re-search-forward page-delimiter nil 'move arg)))
5392 (goto-char (match-end 0))
5393 (save-excursion
5394 (goto-char (point-min))
5395 (setq gnus-page-broken
5396 (and (re-search-forward page-delimiter nil t) t))))
5397 (when gnus-page-broken
5398 (narrow-to-region
5399 (point)
5400 (if (re-search-forward page-delimiter nil 'move)
5401 (match-beginning 0)
5402 (point)))
5403 (when (and (gnus-visual-p 'page-marker)
5404 (> (point-min) (save-restriction (widen) (point-min))))
5405 (save-excursion
5406 (goto-char (point-min))
5407 (gnus-insert-prev-page-button)))
5408 (when (and (gnus-visual-p 'page-marker)
5409 (< (point-max) (save-restriction (widen) (point-max))))
5410 (save-excursion
5411 (goto-char (point-max))
5412 (gnus-insert-next-page-button))))))
5413
5414 ;; Article mode commands
5415
5416 (defun gnus-article-goto-next-page ()
5417 "Show the next page of the article."
5418 (interactive)
5419 (when (gnus-article-next-page)
5420 (goto-char (point-min))
5421 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5422
5423
5424 (defun gnus-article-goto-prev-page ()
5425 "Show the previous page of the article."
5426 (interactive)
5427 (if (bobp)
5428 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5429 (gnus-article-prev-page nil)))
5430
5431 ;; This is cleaner but currently breaks `gnus-pick-mode':
5432 ;;
5433 ;; (defun gnus-article-goto-next-page ()
5434 ;; "Show the next page of the article."
5435 ;; (interactive)
5436 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5437 ;; (gnus-summary-next-page)))
5438 ;;
5439 ;; (defun gnus-article-goto-prev-page ()
5440 ;; "Show the next page of the article."
5441 ;; (interactive)
5442 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5443 ;; (gnus-summary-prev-page)))
5444
5445 (defun gnus-article-next-page (&optional lines)
5446 "Show the next page of the current article.
5447 If end of article, return non-nil. Otherwise return nil.
5448 Argument LINES specifies lines to be scrolled up."
5449 (interactive "p")
5450 (move-to-window-line -1)
5451 (if (save-excursion
5452 (end-of-line)
5453 (and (pos-visible-in-window-p) ;Not continuation line.
5454 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5455 ;; Nothing in this page.
5456 (if (or (not gnus-page-broken)
5457 (save-excursion
5458 (save-restriction
5459 (widen)
5460 (forward-line)
5461 (eobp)))) ;Real end-of-buffer?
5462 (progn
5463 (when gnus-article-over-scroll
5464 (gnus-article-next-page-1 lines))
5465 t) ;Nothing more.
5466 (gnus-narrow-to-page 1) ;Go to next page.
5467 nil)
5468 ;; More in this page.
5469 (gnus-article-next-page-1 lines)
5470 nil))
5471
5472 (defmacro gnus-article-beginning-of-window ()
5473 "Move point to the beginning of the window.
5474 In Emacs, the point is placed at the line number which `scroll-margin'
5475 specifies."
5476 (if (featurep 'xemacs)
5477 '(move-to-window-line 0)
5478 '(move-to-window-line
5479 (min (max 0 scroll-margin)
5480 (max 1 (- (window-height)
5481 (if mode-line-format 1 0)
5482 (if (and (boundp 'header-line-format)
5483 (symbol-value 'header-line-format))
5484 1 0)))))))
5485
5486 (defun gnus-article-next-page-1 (lines)
5487 (when (and (not (featurep 'xemacs))
5488 (numberp lines)
5489 (> lines 0)
5490 (numberp (symbol-value 'scroll-margin))
5491 (> (symbol-value 'scroll-margin) 0))
5492 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5493 ;; too many number of lines if `scroll-margin' is set as two or greater.
5494 (setq lines (min lines
5495 (max 0 (- (count-lines (window-start) (point-max))
5496 (symbol-value 'scroll-margin))))))
5497 (condition-case ()
5498 (let ((scroll-in-place nil))
5499 (scroll-up lines))
5500 (end-of-buffer
5501 ;; Long lines may cause an end-of-buffer error.
5502 (goto-char (point-max))))
5503 (gnus-article-beginning-of-window))
5504
5505 (defun gnus-article-prev-page (&optional lines)
5506 "Show previous page of current article.
5507 Argument LINES specifies lines to be scrolled down."
5508 (interactive "p")
5509 (move-to-window-line 0)
5510 (if (and gnus-page-broken
5511 (bobp)
5512 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5513 (progn
5514 (gnus-narrow-to-page -1) ;Go to previous page.
5515 (goto-char (point-max))
5516 (recenter -1))
5517 (prog1
5518 (condition-case ()
5519 (let ((scroll-in-place nil))
5520 (scroll-down lines))
5521 (beginning-of-buffer
5522 (goto-char (point-min))))
5523 (gnus-article-beginning-of-window))))
5524
5525 (defun gnus-article-only-boring-p ()
5526 "Decide whether there is only boring text remaining in the article.
5527 Something \"interesting\" is a word of at least two letters that does
5528 not have a face in `gnus-article-boring-faces'."
5529 (when (and gnus-article-skip-boring
5530 (boundp 'gnus-article-boring-faces)
5531 (symbol-value 'gnus-article-boring-faces))
5532 (save-excursion
5533 (let ((inhibit-point-motion-hooks t))
5534 (catch 'only-boring
5535 (while (re-search-forward "\\b\\w\\w" nil t)
5536 (forward-char -1)
5537 (when (not (gnus-intersection
5538 (gnus-faces-at (point))
5539 (symbol-value 'gnus-article-boring-faces)))
5540 (throw 'only-boring nil)))
5541 (throw 'only-boring t))))))
5542
5543 (defun gnus-article-refer-article ()
5544 "Read article specified by message-id around point."
5545 (interactive)
5546 (save-excursion
5547 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5548 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5549 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5550 (let ((msg-id (concat "<" (match-string 0) ">")))
5551 (set-buffer gnus-summary-buffer)
5552 (gnus-summary-refer-article msg-id))
5553 (error "No references around point"))))
5554
5555 (defun gnus-article-show-summary ()
5556 "Reconfigure windows to show summary buffer."
5557 (interactive)
5558 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5559 (error "There is no summary buffer for this article buffer")
5560 (gnus-article-set-globals)
5561 (gnus-configure-windows 'article)
5562 (gnus-summary-goto-subject gnus-current-article)
5563 (gnus-summary-position-point)))
5564
5565 (defun gnus-article-describe-briefly ()
5566 "Describe article mode commands briefly."
5567 (interactive)
5568 (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")))
5569
5570 (defun gnus-article-summary-command ()
5571 "Execute the last keystroke in the summary buffer."
5572 (interactive)
5573 (let ((obuf (current-buffer))
5574 (owin (current-window-configuration))
5575 func)
5576 (switch-to-buffer gnus-article-current-summary 'norecord)
5577 (setq func (lookup-key (current-local-map) (this-command-keys)))
5578 (call-interactively func)
5579 (set-buffer obuf)
5580 (set-window-configuration owin)
5581 (set-window-point (get-buffer-window (current-buffer)) (point))))
5582
5583 (defun gnus-article-summary-command-nosave ()
5584 "Execute the last keystroke in the summary buffer."
5585 (interactive)
5586 (let (func)
5587 (pop-to-buffer gnus-article-current-summary 'norecord)
5588 (setq func (lookup-key (current-local-map) (this-command-keys)))
5589 (call-interactively func)))
5590
5591 (defun gnus-article-check-buffer ()
5592 "Beep if not in an article buffer."
5593 (unless (equal major-mode 'gnus-article-mode)
5594 (error "Command invoked outside of a Gnus article buffer")))
5595
5596 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5597 "Read a summary buffer key sequence and execute it from the article buffer."
5598 (interactive "P")
5599 (gnus-article-check-buffer)
5600 (let ((nosaves
5601 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5602 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5603 "=" "^" "\M-^" "|"))
5604 (nosave-but-article
5605 '("A\r"))
5606 (nosave-in-article
5607 '("\C-d"))
5608 (up-to-top
5609 '("n" "Gn" "p" "Gp"))
5610 keys new-sum-point)
5611 (save-excursion
5612 (set-buffer gnus-article-current-summary)
5613 (let (gnus-pick-mode)
5614 (push (or key last-command-event) unread-command-events)
5615 (setq keys (if (featurep 'xemacs)
5616 (events-to-keys (read-key-sequence nil))
5617 (read-key-sequence nil)))))
5618
5619 (message "")
5620
5621 (if (or (member keys nosaves)
5622 (member keys nosave-but-article)
5623 (member keys nosave-in-article))
5624 (let (func)
5625 (save-window-excursion
5626 (pop-to-buffer gnus-article-current-summary 'norecord)
5627 ;; We disable the pick minor mode commands.
5628 (let (gnus-pick-mode)
5629 (setq func (lookup-key (current-local-map) keys))))
5630 (if (or (not func)
5631 (numberp func))
5632 (ding)
5633 (unless (member keys nosave-in-article)
5634 (set-buffer gnus-article-current-summary))
5635 (call-interactively func)
5636 (setq new-sum-point (point)))
5637 (when (member keys nosave-but-article)
5638 (pop-to-buffer gnus-article-buffer 'norecord)))
5639 ;; These commands should restore window configuration.
5640 (let ((obuf (current-buffer))
5641 (owin (current-window-configuration))
5642 (opoint (point))
5643 win func in-buffer selected new-sum-start new-sum-hscroll)
5644 (cond (not-restore-window
5645 (pop-to-buffer gnus-article-current-summary 'norecord))
5646 ((setq win (get-buffer-window gnus-article-current-summary))
5647 (select-window win))
5648 (t
5649 (switch-to-buffer gnus-article-current-summary 'norecord)))
5650 (setq in-buffer (current-buffer))
5651 ;; We disable the pick minor mode commands.
5652 (if (and (setq func (let (gnus-pick-mode)
5653 (lookup-key (current-local-map) keys)))
5654 (functionp func))
5655 (progn
5656 (call-interactively func)
5657 (when (eq win (selected-window))
5658 (setq new-sum-point (point)
5659 new-sum-start (window-start win)
5660 new-sum-hscroll (window-hscroll win)))
5661 (when (eq in-buffer (current-buffer))
5662 (setq selected (gnus-summary-select-article))
5663 (set-buffer obuf)
5664 (unless not-restore-window
5665 (set-window-configuration owin))
5666 (when (eq selected 'old)
5667 (article-goto-body)
5668 (set-window-start (get-buffer-window (current-buffer))
5669 1)
5670 (set-window-point (get-buffer-window (current-buffer))
5671 (point)))
5672 (when (and (not not-restore-window)
5673 new-sum-point)
5674 (set-window-point win new-sum-point)
5675 (set-window-start win new-sum-start)
5676 (set-window-hscroll win new-sum-hscroll))))
5677 (set-window-configuration owin)
5678 (ding))))))
5679
5680 (defun gnus-article-describe-key (key)
5681 "Display documentation of the function invoked by KEY. KEY is a string."
5682 (interactive "kDescribe key: ")
5683 (gnus-article-check-buffer)
5684 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5685 (save-excursion
5686 (set-buffer gnus-article-current-summary)
5687 (let (gnus-pick-mode)
5688 (if (featurep 'xemacs)
5689 (progn
5690 (push (elt key 0) unread-command-events)
5691 (setq key (events-to-keys
5692 (read-key-sequence "Describe key: "))))
5693 (setq unread-command-events
5694 (mapcar
5695 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5696 (string-to-list key)))
5697 (setq key (read-key-sequence "Describe key: "))))
5698 (describe-key key))
5699 (describe-key key)))
5700
5701 (defun gnus-article-describe-key-briefly (key &optional insert)
5702 "Display documentation of the function invoked by KEY. KEY is a string."
5703 (interactive "kDescribe key: \nP")
5704 (gnus-article-check-buffer)
5705 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5706 (save-excursion
5707 (set-buffer gnus-article-current-summary)
5708 (let (gnus-pick-mode)
5709 (if (featurep 'xemacs)
5710 (progn
5711 (push (elt key 0) unread-command-events)
5712 (setq key (events-to-keys
5713 (read-key-sequence "Describe key: "))))
5714 (setq unread-command-events
5715 (mapcar
5716 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5717 (string-to-list key)))
5718 (setq key (read-key-sequence "Describe key: "))))
5719 (describe-key-briefly key insert))
5720 (describe-key-briefly key insert)))
5721
5722 (defun gnus-article-reply-with-original (&optional wide)
5723 "Start composing a reply mail to the current message.
5724 The text in the region will be yanked. If the region isn't active,
5725 the entire article will be yanked."
5726 (interactive "P")
5727 (let ((article (cdr gnus-article-current))
5728 contents)
5729 (if (not (gnus-mark-active-p))
5730 (with-current-buffer gnus-summary-buffer
5731 (gnus-summary-reply (list (list article)) wide))
5732 (setq contents (buffer-substring (point) (mark t)))
5733 ;; Deactivate active regions.
5734 (when (and (boundp 'transient-mark-mode)
5735 transient-mark-mode)
5736 (setq mark-active nil))
5737 (with-current-buffer gnus-summary-buffer
5738 (gnus-summary-reply
5739 (list (list article contents)) wide)))))
5740
5741 (defun gnus-article-followup-with-original ()
5742 "Compose a followup to the current article.
5743 The text in the region will be yanked. If the region isn't active,
5744 the entire article will be yanked."
5745 (interactive)
5746 (let ((article (cdr gnus-article-current))
5747 contents)
5748 (if (not (gnus-mark-active-p))
5749 (with-current-buffer gnus-summary-buffer
5750 (gnus-summary-followup (list (list article))))
5751 (setq contents (buffer-substring (point) (mark t)))
5752 ;; Deactivate active regions.
5753 (when (and (boundp 'transient-mark-mode)
5754 transient-mark-mode)
5755 (setq mark-active nil))
5756 (with-current-buffer gnus-summary-buffer
5757 (gnus-summary-followup
5758 (list (list article contents)))))))
5759
5760 (defun gnus-article-hide (&optional arg force)
5761 "Hide all the gruft in the current article.
5762 This means that signatures, cited text and (some) headers will be
5763 hidden.
5764 If given a prefix, show the hidden text instead."
5765 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5766 (gnus-article-hide-headers arg)
5767 (gnus-article-hide-list-identifiers arg)
5768 (gnus-article-hide-citation-maybe arg force)
5769 (gnus-article-hide-signature arg))
5770
5771 (defun gnus-article-maybe-highlight ()
5772 "Do some article highlighting if article highlighting is requested."
5773 (when (gnus-visual-p 'article-highlight 'highlight)
5774 (gnus-article-highlight-some)))
5775
5776 (defun gnus-check-group-server ()
5777 ;; Make sure the connection to the server is alive.
5778 (unless (gnus-server-opened
5779 (gnus-find-method-for-group gnus-newsgroup-name))
5780 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5781 (gnus-request-group gnus-newsgroup-name t)))
5782
5783 (eval-when-compile
5784 (autoload 'nneething-get-file-name "nneething"))
5785
5786 (defun gnus-request-article-this-buffer (article group)
5787 "Get an article and insert it into this buffer."
5788 (let (do-update-line sparse-header)
5789 (prog1
5790 (save-excursion
5791 (erase-buffer)
5792 (gnus-kill-all-overlays)
5793 (setq group (or group gnus-newsgroup-name))
5794
5795 ;; Using `gnus-request-article' directly will insert the article into
5796 ;; `nntp-server-buffer' - so we'll save some time by not having to
5797 ;; copy it from the server buffer into the article buffer.
5798
5799 ;; We only request an article by message-id when we do not have the
5800 ;; headers for it, so we'll have to get those.
5801 (when (stringp article)
5802 (gnus-read-header article))
5803
5804 ;; If the article number is negative, that means that this article
5805 ;; doesn't belong in this newsgroup (possibly), so we find its
5806 ;; message-id and request it by id instead of number.
5807 (when (and (numberp article)
5808 gnus-summary-buffer
5809 (get-buffer gnus-summary-buffer)
5810 (gnus-buffer-exists-p gnus-summary-buffer))
5811 (save-excursion
5812 (set-buffer gnus-summary-buffer)
5813 (let ((header (gnus-summary-article-header article)))
5814 (when (< article 0)
5815 (cond
5816 ((memq article gnus-newsgroup-sparse)
5817 ;; This is a sparse gap article.
5818 (setq do-update-line article)
5819 (setq article (mail-header-id header))
5820 (setq sparse-header (gnus-read-header article))
5821 (setq gnus-newsgroup-sparse
5822 (delq article gnus-newsgroup-sparse)))
5823 ((vectorp header)
5824 ;; It's a real article.
5825 (setq article (mail-header-id header)))
5826 (t
5827 ;; It is an extracted pseudo-article.
5828 (setq article 'pseudo)
5829 (gnus-request-pseudo-article header))))
5830
5831 (let ((method (gnus-find-method-for-group
5832 gnus-newsgroup-name)))
5833 (when (and (eq (car method) 'nneething)
5834 (vectorp header))
5835 (let ((dir (nneething-get-file-name
5836 (mail-header-id header))))
5837 (when (and (stringp dir)
5838 (file-directory-p dir))
5839 (setq article 'nneething)
5840 (gnus-group-enter-directory dir))))))))
5841
5842 (cond
5843 ;; Refuse to select canceled articles.
5844 ((and (numberp article)
5845 gnus-summary-buffer
5846 (get-buffer gnus-summary-buffer)
5847 (gnus-buffer-exists-p gnus-summary-buffer)
5848 (eq (cdr (save-excursion
5849 (set-buffer gnus-summary-buffer)
5850 (assq article gnus-newsgroup-reads)))
5851 gnus-canceled-mark))
5852 nil)
5853 ;; We first check `gnus-original-article-buffer'.
5854 ((and (get-buffer gnus-original-article-buffer)
5855 (numberp article)
5856 (save-excursion
5857 (set-buffer gnus-original-article-buffer)
5858 (and (equal (car gnus-original-article) group)
5859 (eq (cdr gnus-original-article) article))))
5860 (insert-buffer-substring gnus-original-article-buffer)
5861 'article)
5862 ;; Check the backlog.
5863 ((and gnus-keep-backlog
5864 (gnus-backlog-request-article group article (current-buffer)))
5865 'article)
5866 ;; Check asynchronous pre-fetch.
5867 ((gnus-async-request-fetched-article group article (current-buffer))
5868 (gnus-async-prefetch-next group article gnus-summary-buffer)
5869 (when (and (numberp article) gnus-keep-backlog)
5870 (gnus-backlog-enter-article group article (current-buffer)))
5871 'article)
5872 ;; Check the cache.
5873 ((and gnus-use-cache
5874 (numberp article)
5875 (gnus-cache-request-article article group))
5876 'article)
5877 ;; Check the agent cache.
5878 ((gnus-agent-request-article article group)
5879 'article)
5880 ;; Get the article and put into the article buffer.
5881 ((or (stringp article)
5882 (numberp article))
5883 (let ((gnus-override-method gnus-override-method)
5884 (methods (and (stringp article)
5885 gnus-refer-article-method))
5886 (backend (car (gnus-find-method-for-group
5887 gnus-newsgroup-name)))
5888 result
5889 (inhibit-read-only t))
5890 (if (or (not (listp methods))
5891 (and (symbolp (car methods))
5892 (assq (car methods) nnoo-definition-alist)))
5893 (setq methods (list methods)))
5894 (when (and (null gnus-override-method)
5895 methods)
5896 (setq gnus-override-method (pop methods)))
5897 (while (not result)
5898 (when (eq gnus-override-method 'current)
5899 (setq gnus-override-method
5900 (with-current-buffer gnus-summary-buffer
5901 gnus-current-select-method)))
5902 (erase-buffer)
5903 (gnus-kill-all-overlays)
5904 (let ((gnus-newsgroup-name group))
5905 (gnus-check-group-server))
5906 (cond
5907 ((gnus-request-article article group (current-buffer))
5908 (when (numberp article)
5909 (gnus-async-prefetch-next group article
5910 gnus-summary-buffer)
5911 (when gnus-keep-backlog
5912 (gnus-backlog-enter-article
5913 group article (current-buffer))))
5914 (setq result 'article))
5915 (methods
5916 (setq gnus-override-method (pop methods)))
5917 ((not (string-match "^400 "
5918 (nnheader-get-report backend)))
5919 ;; If we get 400 server disconnect, reconnect and
5920 ;; retry; otherwise, assume the article has expired.
5921 (setq result 'done))))
5922 (and (eq result 'article) 'article)))
5923 ;; It was a pseudo.
5924 (t article)))
5925
5926 ;; Associate this article with the current summary buffer.
5927 (setq gnus-article-current-summary gnus-summary-buffer)
5928
5929 ;; Take the article from the original article buffer
5930 ;; and place it in the buffer it's supposed to be in.
5931 (when (and (get-buffer gnus-article-buffer)
5932 (equal (buffer-name (current-buffer))
5933 (buffer-name (get-buffer gnus-article-buffer))))
5934 (save-excursion
5935 (if (get-buffer gnus-original-article-buffer)
5936 (set-buffer gnus-original-article-buffer)
5937 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5938 (buffer-disable-undo)
5939 (setq major-mode 'gnus-original-article-mode)
5940 (setq buffer-read-only t))
5941 (let ((inhibit-read-only t))
5942 (erase-buffer)
5943 (insert-buffer-substring gnus-article-buffer))
5944 (setq gnus-original-article (cons group article)))
5945
5946 ;; Decode charsets.
5947 (run-hooks 'gnus-article-decode-hook)
5948 ;; Mark article as decoded or not.
5949 (setq gnus-article-decoded-p gnus-article-decode-hook))
5950
5951 ;; Update sparse articles.
5952 (when (and do-update-line
5953 (or (numberp article)
5954 (stringp article)))
5955 (let ((buf (current-buffer)))
5956 (set-buffer gnus-summary-buffer)
5957 (gnus-summary-update-article do-update-line sparse-header)
5958 (gnus-summary-goto-subject do-update-line nil t)
5959 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5960 (point))
5961 (set-buffer buf))))))
5962
5963 ;;;
5964 ;;; Article editing
5965 ;;;
5966
5967 (defcustom gnus-article-edit-mode-hook nil
5968 "Hook run in article edit mode buffers."
5969 :group 'gnus-article-various
5970 :type 'hook)
5971
5972 (defvar gnus-article-edit-done-function nil)
5973
5974 (defvar gnus-article-edit-mode-map nil)
5975 (defvar gnus-article-edit-mode nil)
5976
5977 ;; Should we be using derived.el for this?
5978 (unless gnus-article-edit-mode-map
5979 (setq gnus-article-edit-mode-map (make-keymap))
5980 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5981
5982 (gnus-define-keys gnus-article-edit-mode-map
5983 "\C-c?" describe-mode
5984 "\C-c\C-c" gnus-article-edit-done
5985 "\C-c\C-k" gnus-article-edit-exit
5986 "\C-c\C-f\C-t" message-goto-to
5987 "\C-c\C-f\C-o" message-goto-from
5988 "\C-c\C-f\C-b" message-goto-bcc
5989 ;;"\C-c\C-f\C-w" message-goto-fcc
5990 "\C-c\C-f\C-c" message-goto-cc
5991 "\C-c\C-f\C-s" message-goto-subject
5992 "\C-c\C-f\C-r" message-goto-reply-to
5993 "\C-c\C-f\C-n" message-goto-newsgroups
5994 "\C-c\C-f\C-d" message-goto-distribution
5995 "\C-c\C-f\C-f" message-goto-followup-to
5996 "\C-c\C-f\C-m" message-goto-mail-followup-to
5997 "\C-c\C-f\C-k" message-goto-keywords
5998 "\C-c\C-f\C-u" message-goto-summary
5999 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6000 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6001 "\C-c\C-b" message-goto-body
6002 "\C-c\C-i" message-goto-signature
6003
6004 "\C-c\C-t" message-insert-to
6005 "\C-c\C-n" message-insert-newsgroups
6006 "\C-c\C-o" message-sort-headers
6007 "\C-c\C-e" message-elide-region
6008 "\C-c\C-v" message-delete-not-region
6009 "\C-c\C-z" message-kill-to-signature
6010 "\M-\r" message-newline-and-reformat
6011 "\C-c\C-a" mml-attach-file
6012 "\C-a" message-beginning-of-line
6013 "\t" message-tab
6014 "\M-;" comment-region)
6015
6016 (gnus-define-keys (gnus-article-edit-wash-map
6017 "\C-c\C-w" gnus-article-edit-mode-map)
6018 "f" gnus-article-edit-full-stops))
6019
6020 (easy-menu-define
6021 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6022 '("Field"
6023 ["Fetch To" message-insert-to t]
6024 ["Fetch Newsgroups" message-insert-newsgroups t]
6025 "----"
6026 ["To" message-goto-to t]
6027 ["From" message-goto-from t]
6028 ["Subject" message-goto-subject t]
6029 ["Cc" message-goto-cc t]
6030 ["Reply-To" message-goto-reply-to t]
6031 ["Summary" message-goto-summary t]
6032 ["Keywords" message-goto-keywords t]
6033 ["Newsgroups" message-goto-newsgroups t]
6034 ["Followup-To" message-goto-followup-to t]
6035 ["Mail-Followup-To" message-goto-mail-followup-to t]
6036 ["Distribution" message-goto-distribution t]
6037 ["Body" message-goto-body t]
6038 ["Signature" message-goto-signature t]))
6039
6040 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6041 "Major mode for editing articles.
6042 This is an extended text-mode.
6043
6044 \\{gnus-article-edit-mode-map}"
6045 (make-local-variable 'gnus-article-edit-done-function)
6046 (make-local-variable 'gnus-prev-winconf)
6047 (set (make-local-variable 'font-lock-defaults)
6048 '(message-font-lock-keywords t))
6049 (set (make-local-variable 'mail-header-separator) "")
6050 (set (make-local-variable 'gnus-article-edit-mode) t)
6051 (easy-menu-add message-mode-field-menu message-mode-map)
6052 (mml-mode)
6053 (setq buffer-read-only nil)
6054 (buffer-enable-undo)
6055 (widen))
6056
6057 (defun gnus-article-edit (&optional force)
6058 "Edit the current article.
6059 This will have permanent effect only in mail groups.
6060 If FORCE is non-nil, allow editing of articles even in read-only
6061 groups."
6062 (interactive "P")
6063 (when (and (not force)
6064 (gnus-group-read-only-p))
6065 (error "The current newsgroup does not support article editing"))
6066 (gnus-article-date-original)
6067 (gnus-article-edit-article
6068 'ignore
6069 `(lambda (no-highlight)
6070 'ignore
6071 (gnus-summary-edit-article-done
6072 ,(or (mail-header-references gnus-current-headers) "")
6073 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6074
6075 (defun gnus-article-edit-article (start-func exit-func)
6076 "Start editing the contents of the current article buffer."
6077 (let ((winconf (current-window-configuration)))
6078 (set-buffer gnus-article-buffer)
6079 (let ((message-auto-save-directory
6080 ;; Don't associate the article buffer with a draft file.
6081 nil))
6082 (gnus-article-edit-mode))
6083 (funcall start-func)
6084 (set-buffer-modified-p nil)
6085 (gnus-configure-windows 'edit-article)
6086 (setq gnus-article-edit-done-function exit-func)
6087 (setq gnus-prev-winconf winconf)
6088 (gnus-message 6 "C-c C-c to end edits")))
6089
6090 (defun gnus-article-edit-done (&optional arg)
6091 "Update the article edits and exit."
6092 (interactive "P")
6093 (let ((func gnus-article-edit-done-function)
6094 (buf (current-buffer))
6095 (start (window-start))
6096 (p (point))
6097 (winconf gnus-prev-winconf))
6098 (widen) ;; Widen it in case that users narrowed the buffer.
6099 (funcall func arg)
6100 (set-buffer buf)
6101 ;; The cache and backlog have to be flushed somewhat.
6102 (when gnus-keep-backlog
6103 (gnus-backlog-remove-article
6104 (car gnus-article-current) (cdr gnus-article-current)))
6105 ;; Flush original article as well.
6106 (save-excursion
6107 (when (get-buffer gnus-original-article-buffer)
6108 (set-buffer gnus-original-article-buffer)
6109 (setq gnus-original-article nil)))
6110 (when gnus-use-cache
6111 (gnus-cache-update-article
6112 (car gnus-article-current) (cdr gnus-article-current)))
6113 ;; We remove all text props from the article buffer.
6114 (kill-all-local-variables)
6115 (gnus-set-text-properties (point-min) (point-max) nil)
6116 (gnus-article-mode)
6117 (set-window-configuration winconf)
6118 (set-buffer buf)
6119 (set-window-start (get-buffer-window buf) start)
6120 (set-window-point (get-buffer-window buf) (point)))
6121 (gnus-summary-show-article))
6122
6123 (defun gnus-article-edit-exit ()
6124 "Exit the article editing without updating."
6125 (interactive)
6126 (when (or (not (buffer-modified-p))
6127 (yes-or-no-p "Article modified; kill anyway? "))
6128 (let ((curbuf (current-buffer))
6129 (p (point))
6130 (window-start (window-start)))
6131 (erase-buffer)
6132 (if (gnus-buffer-live-p gnus-original-article-buffer)
6133 (insert-buffer-substring gnus-original-article-buffer))
6134 (let ((winconf gnus-prev-winconf))
6135 (kill-all-local-variables)
6136 (gnus-article-mode)
6137 (set-window-configuration winconf)
6138 ;; Tippy-toe some to make sure that point remains where it was.
6139 (save-current-buffer
6140 (set-buffer curbuf)
6141 (set-window-start (get-buffer-window (current-buffer)) window-start)
6142 (goto-char p))))
6143 (gnus-summary-show-article)))
6144
6145 (defun gnus-article-edit-full-stops ()
6146 "Interactively repair spacing at end of sentences."
6147 (interactive)
6148 (save-excursion
6149 (goto-char (point-min))
6150 (search-forward-regexp "^$" nil t)
6151 (let ((case-fold-search nil))
6152 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6153
6154 ;;;
6155 ;;; Article highlights
6156 ;;;
6157
6158 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6159
6160 ;;; Internal Variables:
6161
6162 (defcustom gnus-button-url-regexp
6163 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6164 "\\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:]]\\)"
6165 "\\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\\)\\)")
6166 "Regular expression that matches URLs."
6167 :group 'gnus-article-buttons
6168 :type 'regexp)
6169
6170 (defcustom gnus-button-valid-fqdn-regexp
6171 message-valid-fqdn-regexp
6172 "Regular expression that matches a valid FQDN."
6173 :version "22.1"
6174 :group 'gnus-article-buttons
6175 :type 'regexp)
6176
6177 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6178 (defcustom gnus-button-valid-localpart-regexp
6179 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6180 "Regular expression that matches a localpart of mail addresses or MIDs."
6181 :version "22.1"
6182 :group 'gnus-article-buttons
6183 :type 'regexp)
6184
6185 (defcustom gnus-button-man-handler 'manual-entry
6186 "Function to use for displaying man pages.
6187 The function must take at least one argument with a string naming the
6188 man page."
6189 :version "22.1"
6190 :type '(choice (function-item :tag "Man" manual-entry)
6191 (function-item :tag "Woman" woman)
6192 (function :tag "Other"))
6193 :group 'gnus-article-buttons)
6194
6195 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6196 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6197 If the default site is too slow, try to find a CTAN mirror, see
6198 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6199 the variable `gnus-button-handle-ctan'."
6200 :version "22.1"
6201 :group 'gnus-article-buttons
6202 :link '(custom-manual "(gnus)Group Parameters")
6203 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6204 (const "http://tug.ctan.org/tex-archive/")
6205 (const "http://www.dante.de/CTAN/")
6206 (string :tag "Other")))
6207
6208 (defcustom gnus-button-ctan-handler 'browse-url
6209 "Function to use for displaying CTAN links.
6210 The function must take one argument, the string naming the URL."
6211 :version "22.1"
6212 :type '(choice (function-item :tag "Browse Url" browse-url)
6213 (function :tag "Other"))
6214 :group 'gnus-article-buttons)
6215
6216 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6217 "Bogus strings removed from CTAN URLs."
6218 :version "22.1"
6219 :group 'gnus-article-buttons
6220 :type '(choice (const "^/?tex-archive/\\|/")
6221 (regexp :tag "Other")))
6222
6223 (defcustom gnus-button-ctan-directory-regexp
6224 (regexp-opt
6225 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6226 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6227 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6228 "tds" "tools" "usergrps" "web") t)
6229 "Regular expression for ctan directories.
6230 It should match all directories in the top level of `gnus-ctan-url'."
6231 :version "22.1"
6232 :group 'gnus-article-buttons
6233 :type 'regexp)
6234
6235 (defcustom gnus-button-mid-or-mail-regexp
6236 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6237 gnus-button-valid-fqdn-regexp
6238 ">?\\)\\b")
6239 "Regular expression that matches a message ID or a mail address."
6240 :version "22.1"
6241 :group 'gnus-article-buttons
6242 :type 'regexp)
6243
6244 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6245 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6246 Strings like this can be either a message ID or a mail address. If it is one
6247 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6248 message ID or a mail address, respectively. If this variable is set to the
6249 symbol `ask', always query the user what do do. If it is a function, this
6250 function will be called with the string as it's only argument. The function
6251 must return `mid', `mail', `invalid' or `ask'."
6252 :version "22.1"
6253 :group 'gnus-article-buttons
6254 :type '(choice (function-item :tag "Heuristic function"
6255 gnus-button-mid-or-mail-heuristic)
6256 (const ask)
6257 (const mid)
6258 (const mail)))
6259
6260 (defcustom gnus-button-mid-or-mail-heuristic-alist
6261 '((-10.0 . ".+\\$.+@")
6262 (-10.0 . "#")
6263 (-10.0 . "\\*")
6264 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6265 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6266 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6267 (-1.0 . "^[^a-z]+@")
6268 ;;
6269 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6270 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6271 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6272 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6273 ;;
6274 (-2.0 . "^[0-9]")
6275 (-1.0 . "^[0-9][0-9]")
6276 ;;
6277 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6278 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6279 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6280 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6281 ;;
6282 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6283 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6284 ;; "[0-9]{8,}.*\@"
6285 (-3.0
6286 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6287 ;; "[0-9]{12,}.*\@"
6288 ;; compensation for TDMA dated mail addresses:
6289 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6290 ;;
6291 (-20.0 . "\\.fsf@") ;; Gnus
6292 (-20.0 . "^slrn")
6293 (-20.0 . "^Pine")
6294 (-20.0 . "_-_") ;; Subject change in thread
6295 ;;
6296 (-20.0 . "\\.ln@") ;; leafnode
6297 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6298 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6299 ;;
6300 ;; (5.0 . "") ;; $local_part_len <= 7
6301 (10.0 . "^[^0-9]+@")
6302 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6303 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6304 (3.0 . "\@stud")
6305 ;;
6306 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6307 ;;
6308 (0.5 . "^[A-Z][a-z]")
6309 (0.5 . "^[A-Z][a-z][a-z]")
6310 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6311 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6312 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6313
6314 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6315 address. The REGEXP is processed with `case-fold-search' set to nil."
6316 :version "22.1"
6317 :group 'gnus-article-buttons
6318 :type '(repeat (cons (number :tag "Rate")
6319 (regexp :tag "Regexp"))))
6320
6321 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6322 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6323 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6324 address, `ask' if unsure and `invalid' if the string is invalid."
6325 (let ((case-fold-search nil)
6326 (list gnus-button-mid-or-mail-heuristic-alist)
6327 (result 0) rate regexp lpartlen elem)
6328 (setq lpartlen
6329 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6330 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6331 ;; Certain special cases...
6332 (when (string-match
6333 (concat
6334 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6335 "^[0-9]+\\.[0-9]+@compuserve\\|"
6336 "@public\\.gmane\\.org")
6337 mid-or-mail)
6338 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6339 (setq result 'mail))
6340 (when (string-match "@.*@\\| " mid-or-mail)
6341 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6342 (setq result 'invalid))
6343 ;; Nothing more to do, if result is not a number here...
6344 (when (numberp result)
6345 (while list
6346 (setq elem (car list)
6347 rate (car elem)
6348 regexp (cdr elem)
6349 list (cdr list))
6350 (when (string-match regexp mid-or-mail)
6351 (setq result (+ result rate))
6352 (gnus-message
6353 9 "`%s' matched `%s', rate `%s', result `%s'."
6354 mid-or-mail regexp rate result)))
6355 (when (<= lpartlen 7)
6356 (setq result (+ result 5.0))
6357 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6358 mid-or-mail result))
6359 (when (>= lpartlen 12)
6360 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6361 (cond
6362 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6363 ;; Long local part should contain realname if e-mail address,
6364 ;; too many digits: message-id.
6365 ;; $score -= 5.0 + 0.1 * $local_part_len;
6366 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6367 (setq result (+ result rate))
6368 (gnus-message
6369 9 "Many digits in `%s', rate `%s', result `%s'."
6370 mid-or-mail rate result))
6371 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6372 mid-or-mail)
6373 ;; Too few vowels [^aeiouy]{4,}.*\@
6374 (setq result (+ result -5.0))
6375 (gnus-message
6376 9 "Few vowels in `%s', rate `%s', result `%s'."
6377 mid-or-mail -5.0 result))
6378 (t
6379 (setq result (+ result 5.0))
6380 (gnus-message
6381 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6382 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6383 ;; Maybe we should make this a customizable alist: (condition . 'result)
6384 (cond
6385 ((symbolp result) result)
6386 ;; Now convert number into proper results:
6387 ((< result -10.0) 'mid)
6388 ((> result 10.0) 'mail)
6389 (t 'ask))))
6390
6391 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6392 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6393 (url-mid (concat "news" ":" mid-or-mail))
6394 (url-mailto (concat "mailto" ":" mid-or-mail)))
6395 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6396 (when (fboundp pref)
6397 (setq guessed
6398 ;; get rid of surrounding angles...
6399 (funcall pref
6400 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6401 (if (or (eq 'mid guessed) (eq 'mail guessed))
6402 (setq pref guessed)
6403 (setq pref 'ask)))
6404 (if (eq pref 'ask)
6405 (save-window-excursion
6406 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6407 (setq pref 'mail)
6408 (setq pref 'mid))))
6409 (cond ((eq pref 'mid)
6410 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6411 (gnus-button-handle-news url-mid))
6412 ((eq pref 'mail)
6413 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6414 (gnus-url-mailto url-mailto))
6415 (t (gnus-message 3 "Invalid string.")))))
6416
6417 (defun gnus-button-handle-custom (url)
6418 "Follow a Custom URL."
6419 (customize-apropos (gnus-url-unhex-string url)))
6420
6421 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6422
6423 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6424 ;; stuff?
6425
6426 (defun gnus-button-handle-describe-function (url)
6427 "Call `describe-function' when pushing the corresponding URL button."
6428 (describe-function
6429 (intern
6430 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6431
6432 (defun gnus-button-handle-describe-variable (url)
6433 "Call `describe-variable' when pushing the corresponding URL button."
6434 (describe-variable
6435 (intern
6436 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6437
6438 (defun gnus-button-handle-symbol (url)
6439 "Display help on variable or function.
6440 Calls `describe-variable' or `describe-function'."
6441 (let ((sym (intern url)))
6442 (cond
6443 ((fboundp sym) (describe-function sym))
6444 ((boundp sym) (describe-variable sym))
6445 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6446
6447 (defun gnus-button-handle-describe-key (url)
6448 "Call `describe-key' when pushing the corresponding URL button."
6449 (let* ((key-string
6450 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6451 (keys (ignore-errors (eval `(kbd ,key-string)))))
6452 (if keys
6453 (describe-key keys)
6454 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6455
6456 (defun gnus-button-handle-apropos (url)
6457 "Call `apropos' when pushing the corresponding URL button."
6458 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6459
6460 (defun gnus-button-handle-apropos-command (url)
6461 "Call `apropos' when pushing the corresponding URL button."
6462 (apropos-command
6463 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6464
6465 (defun gnus-button-handle-apropos-variable (url)
6466 "Call `apropos' when pushing the corresponding URL button."
6467 (funcall
6468 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6469 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6470
6471 (defun gnus-button-handle-apropos-documentation (url)
6472 "Call `apropos' when pushing the corresponding URL button."
6473 (funcall
6474 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6475 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6476
6477 (defun gnus-button-handle-library (url)
6478 "Call `locate-library' when pushing the corresponding URL button."
6479 (gnus-message 9 "url=`%s'" url)
6480 (let* ((lib (locate-library url))
6481 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6482 (if (not lib)
6483 (gnus-message 1 "Cannot locale library `%s'." url)
6484 (find-file-read-only file))))
6485
6486 (defun gnus-button-handle-ctan (url)
6487 "Call `browse-url' when pushing a CTAN URL button."
6488 (funcall
6489 gnus-button-ctan-handler
6490 (concat
6491 gnus-ctan-url
6492 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6493
6494 (defcustom gnus-button-tex-level 5
6495 "*Integer that says how many TeX-related buttons Gnus will show.
6496 The higher the number, the more buttons will appear and the more false
6497 positives are possible. Note that you can set this variable local to
6498 specific groups. Setting it higher in TeX groups is probably a good idea.
6499 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6500 how to set variables in specific groups."
6501 :version "22.1"
6502 :group 'gnus-article-buttons
6503 :link '(custom-manual "(gnus)Group Parameters")
6504 :type 'integer)
6505
6506 (defcustom gnus-button-man-level 5
6507 "*Integer that says how many man-related buttons Gnus will show.
6508 The higher the number, the more buttons will appear and the more false
6509 positives are possible. Note that you can set this variable local to
6510 specific groups. Setting it higher in Unix groups is probably a good idea.
6511 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6512 how to set variables in specific groups."
6513 :version "22.1"
6514 :group 'gnus-article-buttons
6515 :link '(custom-manual "(gnus)Group Parameters")
6516 :type 'integer)
6517
6518 (defcustom gnus-button-emacs-level 5
6519 "*Integer that says how many emacs-related buttons Gnus will show.
6520 The higher the number, the more buttons will appear and the more false
6521 positives are possible. Note that you can set this variable local to
6522 specific groups. Setting it higher in Emacs or Gnus related groups is
6523 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6524 `gnus-parameters' on how to set variables in specific groups."
6525 :version "22.1"
6526 :group 'gnus-article-buttons
6527 :link '(custom-manual "(gnus)Group Parameters")
6528 :type 'integer)
6529
6530 (defcustom gnus-button-message-level 5
6531 "*Integer that says how many buttons for news or mail messages will appear.
6532 The higher the number, the more buttons will appear and the more false
6533 positives are possible."
6534 ;; mail addresses, MIDs, URLs for news, ...
6535 :version "22.1"
6536 :group 'gnus-article-buttons
6537 :type 'integer)
6538
6539 (defcustom gnus-button-browse-level 5
6540 "*Integer that says how many buttons for browsing will appear.
6541 The higher the number, the more buttons will appear and the more false
6542 positives are possible."
6543 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6544 :version "22.1"
6545 :group 'gnus-article-buttons
6546 :type 'integer)
6547
6548 (defcustom gnus-button-alist
6549 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6550 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6551 ((concat "\\b\\(nntp\\|news\\):\\("
6552 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6553 0 t gnus-button-handle-news 2)
6554 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6555 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6556 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6557 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6558 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6559 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6560 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6561 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6562 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6563 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6564 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6565 ;; RFC 2368 (The mailto URL scheme)
6566 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6567 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6568 ("\\bmailto:\\([^ \n\t]+\\)"
6569 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6570 ;; CTAN
6571 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6572 gnus-button-ctan-directory-regexp
6573 "[^][>)!;:,'\n\t ]+\\)")
6574 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6575 ((concat "\\btex-archive/\\("
6576 gnus-button-ctan-directory-regexp
6577 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6578 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6579 ((concat
6580 "\\b\\("
6581 gnus-button-ctan-directory-regexp
6582 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6583 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6584 ;; This is info (home-grown style) <info://foo/bar+baz>
6585 ("\\binfo://\\([^'\">\n\t ]+\\)"
6586 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6587 ;; Info GNOME style <info:foo#bar_baz>
6588 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6589 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6590 ;; Info KDE style <info:(foo)bar baz>
6591 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6592 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6593 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6594 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6595 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6596 ;; Info links like `C-h i d m CC Mode RET'
6597 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6598 ;; This is custom
6599 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6600 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6601 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6602 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6603 ;; Emacs help commands
6604 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6605 ;; regexp doesn't match arguments containing ` '.
6606 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6607 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6608 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6609 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6610 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6611 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6612 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6613 ;; The following entries may lead to many false positives so don't enable
6614 ;; them by default (use a high button level).
6615 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6616 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6617 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6618 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6619 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6620 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6621 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6622 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6623 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6624 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6625 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6626 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6627 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6628 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6629 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6630 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6631 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6632 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6633 ;; Unlike the other regexps we really have to require quoting
6634 ;; here to determine where it ends.
6635 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6636 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6637 ("<URL: *\\([^<>]*\\)>"
6638 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6639 ;; RFC 2396 (2.4.3., delims) ...
6640 ("\"URL: *\\([^\"]*\\)\""
6641 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6642 ;; RFC 2396 (2.4.3., delims) ...
6643 ("\"URL: *\\([^\"]*\\)\""
6644 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6645 ;; Raw URLs.
6646 (gnus-button-url-regexp
6647 0 (>= gnus-button-browse-level 0) browse-url 0)
6648 ;; man pages
6649 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6650 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6651 gnus-button-handle-man 1)
6652 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6653 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6654 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6655 gnus-button-handle-man 1)
6656 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6657 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6658 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6659 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6660 ;; MID or mail: To avoid too many false positives we don't try to catch
6661 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6662 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6663 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6664 ;; so that non-ambiguous entries (see above) match first.
6665 (gnus-button-mid-or-mail-regexp
6666 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6667 "*Alist of regexps matching buttons in article bodies.
6668
6669 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6670 REGEXP: is the string (case insensitive) matching text around the button (can
6671 also be Lisp expression evaluating to a string),
6672 BUTTON: is the number of the regexp grouping actually matching the button,
6673 FORM: is a Lisp expression which must eval to true for the button to
6674 be added,
6675 CALLBACK: is the function to call when the user push this button, and each
6676 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6677
6678 CALLBACK can also be a variable, in that case the value of that
6679 variable it the real callback function."
6680 :group 'gnus-article-buttons
6681 :type '(repeat (list (choice regexp variable sexp)
6682 (integer :tag "Button")
6683 (sexp :tag "Form")
6684 (function :tag "Callback")
6685 (repeat :tag "Par"
6686 :inline t
6687 (integer :tag "Regexp group")))))
6688
6689 (defcustom gnus-header-button-alist
6690 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6691 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6692 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6693 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6694 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6695 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6696 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6697 0 (>= gnus-button-browse-level 0) browse-url 0)
6698 ("^Subject:" gnus-button-url-regexp
6699 0 (>= gnus-button-browse-level 0) browse-url 0)
6700 ("^[^:]+:" gnus-button-url-regexp
6701 0 (>= gnus-button-browse-level 0) browse-url 0)
6702 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6703 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6704 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6705 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6706 "*Alist of headers and regexps to match buttons in article heads.
6707
6708 This alist is very similar to `gnus-button-alist', except that each
6709 alist has an additional HEADER element first in each entry:
6710
6711 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6712
6713 HEADER is a regexp to match a header. For a fuller explanation, see
6714 `gnus-button-alist'."
6715 :group 'gnus-article-buttons
6716 :group 'gnus-article-headers
6717 :type '(repeat (list (regexp :tag "Header")
6718 (choice regexp variable)
6719 (integer :tag "Button")
6720 (sexp :tag "Form")
6721 (function :tag "Callback")
6722 (repeat :tag "Par"
6723 :inline t
6724 (integer :tag "Regexp group")))))
6725
6726 ;;; Commands:
6727
6728 (defun gnus-article-push-button (event)
6729 "Check text under the mouse pointer for a callback function.
6730 If the text under the mouse pointer has a `gnus-callback' property,
6731 call it with the value of the `gnus-data' text property."
6732 (interactive "e")
6733 (set-buffer (window-buffer (posn-window (event-start event))))
6734 (let* ((pos (posn-point (event-start event)))
6735 (data (get-text-property pos 'gnus-data))
6736 (fun (get-text-property pos 'gnus-callback)))
6737 (goto-char pos)
6738 (when fun
6739 (funcall fun data))))
6740
6741 (defun gnus-article-press-button ()
6742 "Check text at point for a callback function.
6743 If the text at point has a `gnus-callback' property,
6744 call it with the value of the `gnus-data' text property."
6745 (interactive)
6746 (let ((data (get-text-property (point) 'gnus-data))
6747 (fun (get-text-property (point) 'gnus-callback)))
6748 (when fun
6749 (funcall fun data))))
6750
6751 (defun gnus-article-highlight (&optional force)
6752 "Highlight current article.
6753 This function calls `gnus-article-highlight-headers',
6754 `gnus-article-highlight-citation',
6755 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6756 do the highlighting. See the documentation for those functions."
6757 (interactive (list 'force))
6758 (gnus-article-highlight-headers)
6759 (gnus-article-highlight-citation force)
6760 (gnus-article-highlight-signature)
6761 (gnus-article-add-buttons force)
6762 (gnus-article-add-buttons-to-head))
6763
6764 (defun gnus-article-highlight-some (&optional force)
6765 "Highlight current article.
6766 This function calls `gnus-article-highlight-headers',
6767 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6768 do the highlighting. See the documentation for those functions."
6769 (interactive (list 'force))
6770 (gnus-article-highlight-headers)
6771 (gnus-article-highlight-signature)
6772 (gnus-article-add-buttons))
6773
6774 (defun gnus-article-highlight-headers ()
6775 "Highlight article headers as specified by `gnus-header-face-alist'."
6776 (interactive)
6777 (save-excursion
6778 (set-buffer gnus-article-buffer)
6779 (save-restriction
6780 (let ((alist gnus-header-face-alist)
6781 (inhibit-read-only t)
6782 (case-fold-search t)
6783 (inhibit-point-motion-hooks t)
6784 entry regexp header-face field-face from hpoints fpoints)
6785 (article-narrow-to-head)
6786 (while (setq entry (pop alist))
6787 (goto-char (point-min))
6788 (setq regexp (concat "^\\("
6789 (if (string-equal "" (nth 0 entry))
6790 "[^\t ]"
6791 (nth 0 entry))
6792 "\\)")
6793 header-face (nth 1 entry)
6794 field-face (nth 2 entry))
6795 (while (and (re-search-forward regexp nil t)
6796 (not (eobp)))
6797 (beginning-of-line)
6798 (setq from (point))
6799 (unless (search-forward ":" nil t)
6800 (forward-char 1))
6801 (when (and header-face
6802 (not (memq (point) hpoints)))
6803 (push (point) hpoints)
6804 (gnus-put-text-property from (point) 'face header-face))
6805 (when (and field-face
6806 (not (memq (setq from (point)) fpoints)))
6807 (push from fpoints)
6808 (if (re-search-forward "^[^ \t]" nil t)
6809 (forward-char -2)
6810 (goto-char (point-max)))
6811 (gnus-put-text-property from (point) 'face field-face))))))))
6812
6813 (defun gnus-article-highlight-signature ()
6814 "Highlight the signature in an article.
6815 It does this by highlighting everything after
6816 `gnus-signature-separator' using the face `gnus-signature'."
6817 (interactive)
6818 (save-excursion
6819 (set-buffer gnus-article-buffer)
6820 (let ((inhibit-read-only t)
6821 (inhibit-point-motion-hooks t))
6822 (save-restriction
6823 (when (and gnus-signature-face
6824 (gnus-article-narrow-to-signature))
6825 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6826 'face gnus-signature-face)
6827 (widen)
6828 (gnus-article-search-signature)
6829 (let ((start (match-beginning 0))
6830 (end (set-marker (make-marker) (1+ (match-end 0)))))
6831 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6832 end)))))))
6833
6834 (defun gnus-button-in-region-p (b e prop)
6835 "Say whether PROP exists in the region."
6836 (text-property-not-all b e prop nil))
6837
6838 (defun gnus-article-add-buttons (&optional force)
6839 "Find external references in the article and make buttons of them.
6840 \"External references\" are things like Message-IDs and URLs, as
6841 specified by `gnus-button-alist'."
6842 (interactive (list 'force))
6843 (save-excursion
6844 (set-buffer gnus-article-buffer)
6845 (let ((inhibit-read-only t)
6846 (inhibit-point-motion-hooks t)
6847 (case-fold-search t)
6848 (alist gnus-button-alist)
6849 beg entry regexp)
6850 ;; Remove all old markers.
6851 (let (marker entry new-list)
6852 (while (setq marker (pop gnus-button-marker-list))
6853 (if (or (< marker (point-min)) (>= marker (point-max)))
6854 (push marker new-list)
6855 (goto-char marker)
6856 (when (setq entry (gnus-button-entry))
6857 (put-text-property (match-beginning (nth 1 entry))
6858 (match-end (nth 1 entry))
6859 'gnus-callback nil))
6860 (set-marker marker nil)))
6861 (setq gnus-button-marker-list new-list))
6862 ;; We skip the headers.
6863 (article-goto-body)
6864 (setq beg (point))
6865 (while (setq entry (pop alist))
6866 (setq regexp (eval (car entry)))
6867 (goto-char beg)
6868 (while (re-search-forward regexp nil t)
6869 (let* ((start (and entry (match-beginning (nth 1 entry))))
6870 (end (and entry (match-end (nth 1 entry))))
6871 (from (match-beginning 0)))
6872 (when (and (or (eq t (nth 2 entry))
6873 (eval (nth 2 entry)))
6874 (not (gnus-button-in-region-p
6875 start end 'gnus-callback)))
6876 ;; That optional form returned non-nil, so we add the
6877 ;; button.
6878 (gnus-article-add-button
6879 start end 'gnus-button-push
6880 (car (push (set-marker (make-marker) from)
6881 gnus-button-marker-list))))))))))
6882
6883 ;; Add buttons to the head of an article.
6884 (defun gnus-article-add-buttons-to-head ()
6885 "Add buttons to the head of the article."
6886 (interactive)
6887 (save-excursion
6888 (set-buffer gnus-article-buffer)
6889 (save-restriction
6890 (let ((inhibit-read-only t)
6891 (inhibit-point-motion-hooks t)
6892 (case-fold-search t)
6893 (alist gnus-header-button-alist)
6894 entry beg end)
6895 (article-narrow-to-head)
6896 (while alist
6897 ;; Each alist entry.
6898 (setq entry (car alist)
6899 alist (cdr alist))
6900 (goto-char (point-min))
6901 (while (re-search-forward (car entry) nil t)
6902 ;; Each header matching the entry.
6903 (setq beg (match-beginning 0))
6904 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6905 (match-beginning 0))
6906 (point-max)))
6907 (goto-char beg)
6908 (while (re-search-forward (eval (nth 1 entry)) end t)
6909 ;; Each match within a header.
6910 (let* ((entry (cdr entry))
6911 (start (match-beginning (nth 1 entry)))
6912 (end (match-end (nth 1 entry)))
6913 (form (nth 2 entry)))
6914 (goto-char (match-end 0))
6915 (when (eval form)
6916 (gnus-article-add-button
6917 start end (nth 3 entry)
6918 (buffer-substring (match-beginning (nth 4 entry))
6919 (match-end (nth 4 entry)))))))
6920 (goto-char end)))))))
6921
6922 ;;; External functions:
6923
6924 (defun gnus-article-add-button (from to fun &optional data)
6925 "Create a button between FROM and TO with callback FUN and data DATA."
6926 (when gnus-article-button-face
6927 (gnus-overlay-put (gnus-make-overlay from to)
6928 'face gnus-article-button-face))
6929 (gnus-add-text-properties
6930 from to
6931 (nconc (and gnus-article-mouse-face
6932 (list gnus-mouse-face-prop gnus-article-mouse-face))
6933 (list 'gnus-callback fun)
6934 (and data (list 'gnus-data data))))
6935 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6936 :button-keymap gnus-widget-button-keymap))
6937
6938 ;;; Internal functions:
6939
6940 (defun gnus-article-set-globals ()
6941 (save-excursion
6942 (set-buffer gnus-summary-buffer)
6943 (gnus-set-global-variables)))
6944
6945 (defun gnus-signature-toggle (end)
6946 (save-excursion
6947 (set-buffer gnus-article-buffer)
6948 (let ((inhibit-read-only t)
6949 (inhibit-point-motion-hooks t))
6950 (if (text-property-any end (point-max) 'article-type 'signature)
6951 (progn
6952 (gnus-delete-wash-type 'signature)
6953 (gnus-remove-text-properties-when
6954 'article-type 'signature end (point-max)
6955 (cons 'article-type (cons 'signature
6956 gnus-hidden-properties))))
6957 (gnus-add-wash-type 'signature)
6958 (gnus-add-text-properties-when
6959 'article-type nil end (point-max)
6960 (cons 'article-type (cons 'signature
6961 gnus-hidden-properties)))))
6962 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6963 (gnus-set-mode-line 'article))))
6964
6965 (defun gnus-button-entry ()
6966 ;; Return the first entry in `gnus-button-alist' matching this place.
6967 (let ((alist gnus-button-alist)
6968 (entry nil))
6969 (while alist
6970 (setq entry (pop alist))
6971 (if (looking-at (eval (car entry)))
6972 (setq alist nil)
6973 (setq entry nil)))
6974 entry))
6975
6976 (defun gnus-button-push (marker)
6977 ;; Push button starting at MARKER.
6978 (save-excursion
6979 (goto-char marker)
6980 (let* ((entry (gnus-button-entry))
6981 (inhibit-point-motion-hooks t)
6982 (fun (nth 3 entry))
6983 (args (mapcar (lambda (group)
6984 (let ((string (match-string group)))
6985 (gnus-set-text-properties
6986 0 (length string) nil string)
6987 string))
6988 (nthcdr 4 entry))))
6989 (cond
6990 ((fboundp fun)
6991 (apply fun args))
6992 ((and (boundp fun)
6993 (fboundp (symbol-value fun)))
6994 (apply (symbol-value fun) args))
6995 (t
6996 (gnus-message 1 "You must define `%S' to use this button"
6997 (cons fun args)))))))
6998
6999 (defun gnus-parse-news-url (url)
7000 (let (scheme server port group message-id articles)
7001 (with-temp-buffer
7002 (insert url)
7003 (goto-char (point-min))
7004 (when (looking-at "\\([A-Za-z]+\\):")
7005 (setq scheme (match-string 1))
7006 (goto-char (match-end 0)))
7007 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7008 (setq server (match-string 1))
7009 (setq port (if (stringp (match-string 3))
7010 (string-to-number (match-string 3))
7011 (match-string 3)))
7012 (goto-char (match-end 0)))
7013
7014 (cond
7015 ((looking-at "\\(.*@.*\\)")
7016 (setq message-id (match-string 1)))
7017 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7018 (setq group (match-string 1)
7019 articles (split-string (match-string 2) "-")))
7020 ((looking-at "\\([^/]+\\)/?")
7021 (setq group (match-string 1)))
7022 (t
7023 (error "Unknown news URL syntax"))))
7024 (list scheme server port group message-id articles)))
7025
7026 (defun gnus-button-handle-news (url)
7027 "Fetch a news URL."
7028 (destructuring-bind (scheme server port group message-id articles)
7029 (gnus-parse-news-url url)
7030 (cond
7031 (message-id
7032 (save-excursion
7033 (set-buffer gnus-summary-buffer)
7034 (if server
7035 (let ((gnus-refer-article-method
7036 (nconc (list (list 'nntp server))
7037 gnus-refer-article-method))
7038 (nntp-port-number (or port "nntp")))
7039 (gnus-message 7 "Fetching %s with %s"
7040 message-id gnus-refer-article-method)
7041 (gnus-summary-refer-article message-id))
7042 (gnus-summary-refer-article message-id))))
7043 (group
7044 (gnus-button-fetch-group url)))))
7045
7046 (defun gnus-button-handle-man (url)
7047 "Fetch a man page."
7048 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7049 (when (eq gnus-button-man-handler 'woman)
7050 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7051 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7052 (funcall gnus-button-man-handler url))
7053
7054 (defun gnus-button-handle-info-url (url)
7055 "Fetch an info URL."
7056 (setq url (mm-subst-char-in-string ?+ ?\ url))
7057 (cond
7058 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7059 (gnus-info-find-node
7060 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7061 "Gnus")
7062 ")" (gnus-url-unhex-string (match-string 2 url)))))
7063 ((string-match "([^)\"]+)[^\"]+" url)
7064 (setq url
7065 (gnus-replace-in-string
7066 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7067 (gnus-info-find-node url))
7068 (t (error "Can't parse %s" url))))
7069
7070 (defun gnus-button-handle-info-url-gnome (url)
7071 "Fetch GNOME style info URL."
7072 (setq url (mm-subst-char-in-string ?_ ?\ url))
7073 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7074 (gnus-info-find-node
7075 (concat "("
7076 (gnus-url-unhex-string
7077 (match-string 1 url))
7078 ")"
7079 (or (gnus-url-unhex-string
7080 (match-string 2 url))
7081 "Top")))
7082 (error "Can't parse %s" url)))
7083
7084 (defun gnus-button-handle-info-url-kde (url)
7085 "Fetch KDE style info URL."
7086 (gnus-info-find-node (gnus-url-unhex-string url)))
7087
7088 (defun gnus-button-handle-info-keystrokes (url)
7089 "Call `info' when pushing the corresponding URL button."
7090 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7091 (info)
7092 (Info-directory)
7093 (Info-menu url))
7094
7095 (defun gnus-button-message-id (message-id)
7096 "Fetch MESSAGE-ID."
7097 (save-excursion
7098 (set-buffer gnus-summary-buffer)
7099 (gnus-summary-refer-article message-id)))
7100
7101 (defun gnus-button-fetch-group (address)
7102 "Fetch GROUP specified by ADDRESS."
7103 (if (not (string-match "[:/]" address))
7104 ;; This is just a simple group url.
7105 (gnus-group-read-ephemeral-group address gnus-select-method)
7106 (if (not
7107 (string-match
7108 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7109 address))
7110 (error "Can't parse %s" address)
7111 (gnus-group-read-ephemeral-group
7112 (match-string 4 address)
7113 `(nntp ,(match-string 1 address)
7114 (nntp-address ,(match-string 1 address))
7115 (nntp-port-number ,(if (match-end 3)
7116 (match-string 3 address)
7117 "nntp")))
7118 nil nil nil
7119 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7120
7121 (defun gnus-url-parse-query-string (query &optional downcase)
7122 (let (retval pairs cur key val)
7123 (setq pairs (split-string query "&"))
7124 (while pairs
7125 (setq cur (car pairs)
7126 pairs (cdr pairs))
7127 (if (not (string-match "=" cur))
7128 nil ; Grace
7129 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7130 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7131 (if downcase
7132 (setq key (downcase key)))
7133 (setq cur (assoc key retval))
7134 (if cur
7135 (setcdr cur (cons val (cdr cur)))
7136 (setq retval (cons (list key val) retval)))))
7137 retval))
7138
7139 (defun gnus-url-mailto (url)
7140 ;; Send mail to someone
7141 (when (string-match "mailto:/*\\(.*\\)" url)
7142 (setq url (substring url (match-beginning 1) nil)))
7143 (let (to args subject func)
7144 (setq args (gnus-url-parse-query-string
7145 (if (string-match "^\\?" url)
7146 (substring url 1)
7147 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7148 (concat "to=" (match-string 1 url) "&"
7149 (match-string 2 url))
7150 (concat "to=" url)))
7151 t)
7152 subject (cdr-safe (assoc "subject" args)))
7153 (gnus-msg-mail)
7154 (while args
7155 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7156 (if (fboundp func)
7157 (funcall func)
7158 (message-position-on-field (caar args)))
7159 (insert (gnus-replace-in-string
7160 (mapconcat 'identity (reverse (cdar args)) ", ")
7161 "\r\n" "\n" t))
7162 (setq args (cdr args)))
7163 (if subject
7164 (message-goto-body)
7165 (message-goto-subject))))
7166
7167 (defun gnus-button-embedded-url (address)
7168 "Activate ADDRESS with `browse-url'."
7169 (browse-url (gnus-strip-whitespace address)))
7170
7171 ;;; Next/prev buttons in the article buffer.
7172
7173 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7174 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7175
7176 (defvar gnus-prev-page-map
7177 (let ((map (make-sparse-keymap)))
7178 (unless (>= emacs-major-version 21)
7179 ;; XEmacs doesn't care.
7180 (set-keymap-parent map gnus-article-mode-map))
7181 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7182 (define-key map "\r" 'gnus-button-prev-page)
7183 map))
7184
7185 (defvar gnus-next-page-map
7186 (let ((map (make-sparse-keymap)))
7187 (unless (>= emacs-major-version 21)
7188 ;; XEmacs doesn't care.
7189 (set-keymap-parent map gnus-article-mode-map))
7190 (define-key map gnus-mouse-2 'gnus-button-next-page)
7191 (define-key map "\r" 'gnus-button-next-page)
7192 map))
7193
7194 (defun gnus-insert-prev-page-button ()
7195 (let ((b (point))
7196 (inhibit-read-only t))
7197 (gnus-eval-format
7198 gnus-prev-page-line-format nil
7199 `(,@(gnus-local-map-property gnus-prev-page-map)
7200 gnus-prev t
7201 gnus-callback gnus-article-button-prev-page
7202 article-type annotation))
7203 (widget-convert-button
7204 'link b (if (bolp)
7205 ;; Exclude a newline.
7206 (1- (point))
7207 (point))
7208 :action 'gnus-button-prev-page
7209 :button-keymap gnus-prev-page-map)))
7210
7211 (defun gnus-button-next-page (&optional args more-args)
7212 "Go to the next page."
7213 (interactive)
7214 (let ((win (selected-window)))
7215 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7216 (gnus-article-next-page)
7217 (select-window win)))
7218
7219 (defun gnus-button-prev-page (&optional args more-args)
7220 "Go to the prev page."
7221 (interactive)
7222 (let ((win (selected-window)))
7223 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7224 (gnus-article-prev-page)
7225 (select-window win)))
7226
7227 (defun gnus-insert-next-page-button ()
7228 (let ((b (point))
7229 (inhibit-read-only t))
7230 (gnus-eval-format gnus-next-page-line-format nil
7231 `(,@(gnus-local-map-property gnus-next-page-map)
7232 gnus-next t
7233 gnus-callback gnus-article-button-next-page
7234 article-type annotation))
7235 (widget-convert-button
7236 'link b (if (bolp)
7237 ;; Exclude a newline.
7238 (1- (point))
7239 (point))
7240 :action 'gnus-button-next-page
7241 :button-keymap gnus-next-page-map)))
7242
7243 (defun gnus-article-button-next-page (arg)
7244 "Go to the next page."
7245 (interactive "P")
7246 (let ((win (selected-window)))
7247 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7248 (gnus-article-next-page)
7249 (select-window win)))
7250
7251 (defun gnus-article-button-prev-page (arg)
7252 "Go to the prev page."
7253 (interactive "P")
7254 (let ((win (selected-window)))
7255 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7256 (gnus-article-prev-page)
7257 (select-window win)))
7258
7259 (defvar gnus-decode-header-methods
7260 '(mail-decode-encoded-word-region)
7261 "List of methods used to decode headers.
7262
7263 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7264 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7265 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7266 whose names match REGEXP.
7267
7268 For example:
7269 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7270 mail-decode-encoded-word-region
7271 (\"chinese\" . rfc1843-decode-region))
7272 ")
7273
7274 (defvar gnus-decode-header-methods-cache nil)
7275
7276 (defun gnus-multi-decode-header (start end)
7277 "Apply the functions from `gnus-encoded-word-methods' that match."
7278 (unless (and gnus-decode-header-methods-cache
7279 (eq gnus-newsgroup-name
7280 (car gnus-decode-header-methods-cache)))
7281 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7282 (mapcar (lambda (x)
7283 (if (symbolp x)
7284 (nconc gnus-decode-header-methods-cache (list x))
7285 (if (and gnus-newsgroup-name
7286 (string-match (car x) gnus-newsgroup-name))
7287 (nconc gnus-decode-header-methods-cache
7288 (list (cdr x))))))
7289 gnus-decode-header-methods))
7290 (let ((xlist gnus-decode-header-methods-cache))
7291 (pop xlist)
7292 (save-restriction
7293 (narrow-to-region start end)
7294 (while xlist
7295 (funcall (pop xlist) (point-min) (point-max))))))
7296
7297 ;;;
7298 ;;; Treatment top-level handling.
7299 ;;;
7300
7301 (defun gnus-treat-article (condition &optional part-number total-parts type)
7302 (let ((length (- (point-max) (point-min)))
7303 (alist gnus-treatment-function-alist)
7304 (article-goto-body-goes-to-point-min-p t)
7305 (treated-type
7306 (or (not type)
7307 (catch 'found
7308 (let ((list gnus-article-treat-types))
7309 (while list
7310 (when (string-match (pop list) type)
7311 (throw 'found t)))))))
7312 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7313 val elem)
7314 (gnus-run-hooks 'gnus-part-display-hook)
7315 (dolist (elem alist)
7316 (setq val
7317 (save-excursion
7318 (when (gnus-buffer-live-p gnus-summary-buffer)
7319 (set-buffer gnus-summary-buffer))
7320 (symbol-value (car elem))))
7321 (when (and (or (consp val)
7322 treated-type)
7323 (gnus-treat-predicate val)
7324 (or (not (get (car elem) 'highlight))
7325 highlightp))
7326 (save-restriction
7327 (funcall (cadr elem)))))))
7328
7329 ;; Dynamic variables.
7330 (eval-when-compile
7331 (defvar part-number)
7332 (defvar total-parts)
7333 (defvar type)
7334 (defvar condition)
7335 (defvar length))
7336
7337 (defun gnus-treat-predicate (val)
7338 (cond
7339 ((null val)
7340 nil)
7341 (condition
7342 (eq condition val))
7343 ((and (listp val)
7344 (stringp (car val)))
7345 (apply 'gnus-or (mapcar `(lambda (s)
7346 (string-match s ,(or gnus-newsgroup-name "")))
7347 val)))
7348 ((listp val)
7349 (let ((pred (pop val)))
7350 (cond
7351 ((eq pred 'or)
7352 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7353 ((eq pred 'and)
7354 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7355 ((eq pred 'not)
7356 (not (gnus-treat-predicate (car val))))
7357 ((eq pred 'typep)
7358 (equal (car val) type))
7359 (t
7360 (error "%S is not a valid predicate" pred)))))
7361 ((eq val t)
7362 t)
7363 ((eq val 'head)
7364 nil)
7365 ((eq val 'last)
7366 (eq part-number total-parts))
7367 ((numberp val)
7368 (< length val))
7369 (t
7370 (error "%S is not a valid value" val))))
7371
7372 (defun gnus-article-encrypt-body (protocol &optional n)
7373 "Encrypt the article body."
7374 (interactive
7375 (list
7376 (or gnus-article-encrypt-protocol
7377 (completing-read "Encrypt protocol: "
7378 gnus-article-encrypt-protocol-alist
7379 nil t))
7380 current-prefix-arg))
7381 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7382 (unless func
7383 (error "Can't find the encrypt protocol %s" protocol))
7384 (if (member gnus-newsgroup-name '("nndraft:delayed"
7385 "nndraft:drafts"
7386 "nndraft:queue"))
7387 (error "Can't encrypt the article in group %s"
7388 gnus-newsgroup-name))
7389 (gnus-summary-iterate n
7390 (save-excursion
7391 (set-buffer gnus-summary-buffer)
7392 (let ((mail-parse-charset gnus-newsgroup-charset)
7393 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7394 (summary-buffer gnus-summary-buffer)
7395 references point)
7396 (gnus-set-global-variables)
7397 (when (gnus-group-read-only-p)
7398 (error "The current newsgroup does not support article encrypt"))
7399 (gnus-summary-show-article t)
7400 (setq references
7401 (or (mail-header-references gnus-current-headers) ""))
7402 (set-buffer gnus-article-buffer)
7403 (let* ((inhibit-read-only t)
7404 (headers
7405 (mapcar (lambda (field)
7406 (and (save-restriction
7407 (message-narrow-to-head)
7408 (goto-char (point-min))
7409 (search-forward field nil t))
7410 (prog2
7411 (message-narrow-to-field)
7412 (buffer-string)
7413 (delete-region (point-min) (point-max))
7414 (widen))))
7415 '("Content-Type:" "Content-Transfer-Encoding:"
7416 "Content-Disposition:"))))
7417 (message-narrow-to-head)
7418 (message-remove-header "MIME-Version")
7419 (goto-char (point-max))
7420 (setq point (point))
7421 (insert (apply 'concat headers))
7422 (widen)
7423 (narrow-to-region point (point-max))
7424 (let ((message-options message-options))
7425 (message-options-set 'message-sender user-mail-address)
7426 (message-options-set 'message-recipients user-mail-address)
7427 (message-options-set 'message-sign-encrypt 'not)
7428 (funcall func))
7429 (goto-char (point-min))
7430 (insert "MIME-Version: 1.0\n")
7431 (widen)
7432 (gnus-summary-edit-article-done
7433 references nil summary-buffer t))
7434 (when gnus-keep-backlog
7435 (gnus-backlog-remove-article
7436 (car gnus-article-current) (cdr gnus-article-current)))
7437 (save-excursion
7438 (when (get-buffer gnus-original-article-buffer)
7439 (set-buffer gnus-original-article-buffer)
7440 (setq gnus-original-article nil)))
7441 (when gnus-use-cache
7442 (gnus-cache-update-article
7443 (car gnus-article-current) (cdr gnus-article-current))))))))
7444
7445 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7446 "The following specs can be used:
7447 %t The security MIME type
7448 %i Additional info
7449 %d Details
7450 %D Details if button is pressed")
7451
7452 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7453 "The following specs can be used:
7454 %t The security MIME type
7455 %i Additional info
7456 %d Details
7457 %D Details if button is pressed")
7458
7459 (defvar gnus-mime-security-button-line-format-alist
7460 '((?t gnus-tmp-type ?s)
7461 (?i gnus-tmp-info ?s)
7462 (?d gnus-tmp-details ?s)
7463 (?D gnus-tmp-pressed-details ?s)))
7464
7465 (defvar gnus-mime-security-button-map
7466 (let ((map (make-sparse-keymap)))
7467 (unless (>= (string-to-number emacs-version) 21)
7468 (set-keymap-parent map gnus-article-mode-map))
7469 (define-key map gnus-mouse-2 'gnus-article-push-button)
7470 (define-key map "\r" 'gnus-article-press-button)
7471 map))
7472
7473 (defvar gnus-mime-security-details-buffer nil)
7474
7475 (defvar gnus-mime-security-button-pressed nil)
7476
7477 (defvar gnus-mime-security-show-details-inline t
7478 "If non-nil, show details in the article buffer.")
7479
7480 (defun gnus-mime-security-verify-or-decrypt (handle)
7481 (mm-remove-parts (cdr handle))
7482 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7483 point (inhibit-read-only t))
7484 (if region
7485 (goto-char (car region)))
7486 (save-restriction
7487 (narrow-to-region (point) (point))
7488 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7489 (let* ((mm-verify-option 'known)
7490 (mm-decrypt-option 'known)
7491 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7492 (unless (eq nparts (cdr handle))
7493 (mm-destroy-parts (cdr handle))
7494 (setcdr handle nparts))))
7495 (setq point (point))
7496 (gnus-mime-display-security handle)
7497 (goto-char (point-max)))
7498 (when region
7499 (delete-region (point) (cdr region))
7500 (set-marker (car region) nil)
7501 (set-marker (cdr region) nil))
7502 (goto-char point)))
7503
7504 (defun gnus-mime-security-show-details (handle)
7505 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7506 (if (not details)
7507 (gnus-message 5 "No details.")
7508 (if gnus-mime-security-show-details-inline
7509 (let ((gnus-mime-security-button-pressed
7510 (not (get-text-property (point) 'gnus-mime-details)))
7511 (gnus-mime-security-button-line-format
7512 (get-text-property (point) 'gnus-line-format))
7513 (inhibit-read-only t))
7514 (forward-char -1)
7515 (while (eq (get-text-property (point) 'gnus-line-format)
7516 gnus-mime-security-button-line-format)
7517 (forward-char -1))
7518 (forward-char)
7519 (save-restriction
7520 (narrow-to-region (point) (point))
7521 (gnus-insert-mime-security-button handle))
7522 (delete-region (point)
7523 (or (text-property-not-all
7524 (point) (point-max)
7525 'gnus-line-format
7526 gnus-mime-security-button-line-format)
7527 (point-max))))
7528 ;; Not inlined.
7529 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7530 (with-current-buffer gnus-mime-security-details-buffer
7531 (erase-buffer)
7532 t)
7533 (setq gnus-mime-security-details-buffer
7534 (gnus-get-buffer-create "*MIME Security Details*")))
7535 (with-current-buffer gnus-mime-security-details-buffer
7536 (insert details)
7537 (goto-char (point-min)))
7538 (pop-to-buffer gnus-mime-security-details-buffer)))))
7539
7540 (defun gnus-mime-security-press-button (handle)
7541 (save-excursion
7542 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7543 (gnus-mime-security-show-details handle)
7544 (gnus-mime-security-verify-or-decrypt handle))))
7545
7546 (defun gnus-insert-mime-security-button (handle &optional displayed)
7547 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7548 (gnus-tmp-type
7549 (concat
7550 (or (nth 2 (assoc protocol mm-verify-function-alist))
7551 (nth 2 (assoc protocol mm-decrypt-function-alist))
7552 "Unknown")
7553 (if (equal (car handle) "multipart/signed")
7554 " Signed" " Encrypted")
7555 " Part"))
7556 (gnus-tmp-info
7557 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7558 "Undecided"))
7559 (gnus-tmp-details
7560 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7561 gnus-tmp-pressed-details
7562 b e)
7563 (setq gnus-tmp-details
7564 (if gnus-tmp-details
7565 (concat "\n" gnus-tmp-details)
7566 ""))
7567 (setq gnus-tmp-pressed-details
7568 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7569 (unless (bolp)
7570 (insert "\n"))
7571 (setq b (point))
7572 (gnus-eval-format
7573 gnus-mime-security-button-line-format
7574 gnus-mime-security-button-line-format-alist
7575 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7576 gnus-callback gnus-mime-security-press-button
7577 gnus-line-format ,gnus-mime-security-button-line-format
7578 gnus-mime-details ,gnus-mime-security-button-pressed
7579 article-type annotation
7580 gnus-data ,handle))
7581 (setq e (if (bolp)
7582 ;; Exclude a newline.
7583 (1- (point))
7584 (point)))
7585 (widget-convert-button
7586 'link b e
7587 :mime-handle handle
7588 :action 'gnus-widget-press-button
7589 :button-keymap gnus-mime-security-button-map
7590 :help-echo
7591 (lambda (widget/window &optional overlay pos)
7592 ;; Needed to properly clear the message due to a bug in
7593 ;; wid-edit (XEmacs only).
7594 (when (boundp 'help-echo-owns-message)
7595 (setq help-echo-owns-message t))
7596 (format
7597 "%S: show detail"
7598 (aref gnus-mouse-2 0))))))
7599
7600 (defun gnus-mime-display-security (handle)
7601 (save-restriction
7602 (narrow-to-region (point) (point))
7603 (unless (gnus-unbuttonized-mime-type-p (car handle))
7604 (gnus-insert-mime-security-button handle))
7605 (gnus-mime-display-mixed (cdr handle))
7606 (unless (bolp)
7607 (insert "\n"))
7608 (unless (gnus-unbuttonized-mime-type-p (car handle))
7609 (let ((gnus-mime-security-button-line-format
7610 gnus-mime-security-button-end-line-format))
7611 (gnus-insert-mime-security-button handle)))
7612 (mm-set-handle-multipart-parameter
7613 handle 'gnus-region
7614 (cons (set-marker (make-marker) (point-min))
7615 (set-marker (make-marker) (point-max))))))
7616
7617 (gnus-ems-redefine)
7618
7619 (provide 'gnus-art)
7620
7621 (run-hooks 'gnus-art-load-hook)
7622
7623 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7624 ;;; gnus-art.el ends here