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