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