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