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