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