Merge from gnus--rel--5.10
[emacs.git] / lisp / gnus / gnus-art.el
blob1ab31bb519ff6d227ea3b73667845d28c2fdd564
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
9 ;; This file is part of GNU Emacs.
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 3, or (at your option)
14 ;; any later version.
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.
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.
26 ;;; Commentary:
28 ;;; Code:
30 (eval-when-compile
31 (require 'cl)
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map))
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)
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")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
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)
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)
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)
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:
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)
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)
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)
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)
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)
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)
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)
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)
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.
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.")
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:
318 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
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)
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))
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)))
342 (if (nth 1 value) 2 3)
343 (nth 2 value))
344 value)))
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))))
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:
387 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
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)
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)
442 (defface gnus-emphasis-bold '((t (:bold t)))
443 "Face used for displaying strong emphasized text (*word*)."
444 :group 'gnus-article-emphasis)
446 (defface gnus-emphasis-italic '((t (:italic t)))
447 "Face used for displaying italic emphasized text (/word/)."
448 :group 'gnus-article-emphasis)
450 (defface gnus-emphasis-underline '((t (:underline t)))
451 "Face used for displaying underlined emphasized text (_word_)."
452 :group 'gnus-article-emphasis)
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)
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)
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)
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)
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)
478 (defface gnus-emphasis-highlight-words
479 '((t (:background "black" :foreground "yellow")))
480 "Face used for displaying highlighted words."
481 :group 'gnus-article-emphasis)
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.
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)
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)
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)))
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)
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'.
531 Gnus provides the following functions:
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)
542 The symbol of each function may have the following properties:
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'.
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'.
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)))
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.
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:
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
588 and the functions to which you may set `gnus-default-article-saver':
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
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")))
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)
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)
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)
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)
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:
645 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
646 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
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.
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 evalled in the same buffer.
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))))
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)
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.
675 The following additional specs are available:
677 %w The article washing status.
678 %m The number of MIME parts in the article."
679 :type 'string
680 :group 'gnus-article-various)
682 (defcustom gnus-article-mode-hook nil
683 "*A hook for Gnus article mode."
684 :type 'hook
685 :group 'gnus-article-various)
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))
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)
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)
704 (make-obsolete-variable 'gnus-article-hide-pgp-hook
705 "This variable is obsolete in Gnus 5.10.")
707 (defcustom gnus-article-button-face 'bold
708 "Face used for highlighting buttons in the article buffer.
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)
715 (defcustom gnus-article-mouse-face 'highlight
716 "Face used for mouse highlighting in the article buffer.
718 Article buttons will be displayed in this face when the cursor is
719 above them."
720 :type 'face
721 :group 'gnus-article-buttons)
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)
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)
739 (defface gnus-header-from
740 '((((class color)
741 (background dark))
742 (:foreground "spring green"))
743 (((class color)
744 (background light))
745 (:foreground "red3"))
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)
754 (defface gnus-header-subject
755 '((((class color)
756 (background dark))
757 (:foreground "SeaGreen3"))
758 (((class color)
759 (background light))
760 (:foreground "red4"))
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)
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))
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)
786 (defface gnus-header-name
787 '((((class color)
788 (background dark))
789 (:foreground "SeaGreen"))
790 (((class color)
791 (background light))
792 (:foreground "maroon"))
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)
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))
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)
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.
822 An alist of the form (HEADER NAME CONTENT).
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.
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)))))
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)
848 (defcustom gnus-display-mime-function 'gnus-display-mime
849 "Function to display MIME articles."
850 :group 'gnus-article-mime
851 :type 'function)
853 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
854 "Function used to decode headers.")
856 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
857 "Function used to decode addresses.")
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.")
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))
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))
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))
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)
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))
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)
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))
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))
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)
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)
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)))
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))))
1003 ;;; The treatment variables
1006 (defvar gnus-part-display-hook nil
1007 "Hook called on parts that are to receive treatment.")
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")))
1018 (defvar gnus-article-treat-head-custom
1019 '(choice (const :tag "Off" nil)
1020 (const :tag "Header" head)))
1022 (defvar gnus-article-treat-types '("text/plain")
1023 "Parts to treat.")
1025 (defvar gnus-inhibit-treatment nil
1026 "Whether to inhibit treatment.")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
1152 (make-obsolete-variable 'gnus-treat-strip-pgp
1153 "This option is obsolete in Gnus 5.10.")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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.
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)
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.
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)
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)
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)
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)
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)
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)
1323 (make-obsolete-variable 'gnus-treat-display-xface
1324 'gnus-treat-display-x-face)
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 and `head'.
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))))
1359 value)))))
1360 (put 'gnus-treat-display-x-face 'highlight t)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
1505 (defvar gnus-article-encrypt-protocol-alist
1506 '(("PGP" . mml2015-self-encrypt)))
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)
1517 (defvar gnus-article-wash-function nil
1518 "Function used for converting HTML into text.")
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)
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)
1535 ;;; Internal variables
1537 (defvar gnus-english-month-names
1538 '("January" "February" "March" "April" "May" "June" "July" "August"
1539 "September" "October" "November" "December"))
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)
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)))
1598 (defvar gnus-article-mime-handle-alist nil)
1599 (defvar article-lapsed-timer nil)
1600 (defvar gnus-article-current-summary nil)
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.")
1615 (defvar gnus-save-article-buffer nil)
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))
1622 (defvar gnus-number-of-articles-to-be-saved nil)
1624 (defvar gnus-inhibit-hiding nil)
1626 (defvar gnus-article-edit-mode nil)
1628 ;;; Macros for dealing with the article buffer.
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))))
1640 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1641 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
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)))
1649 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1650 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1652 (defun gnus-article-goto-header (header)
1653 "Go to HEADER, which is a regular expression."
1654 (re-search-forward (concat "^\\(" header "\\):") nil t))
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)))))
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)))
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))))
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)))
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)))))
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)
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))))))))
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)))))))
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))
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)))
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 t)
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))))))))
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)
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)))))))))))))
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))))
1968 (defvar gnus-article-normalized-header-length 40
1969 "Length of normalized headers.")
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))
1995 ;; Do nothing.
1997 (forward-line 1))))))
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.
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))
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)))))
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)))))))))
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)))))))))
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)))))))
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))))))
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)))))))
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)))))
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))))))
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)))))
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)))))))
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)))))
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)))))
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))))))
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))))))))))
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))
2308 (error "%s is not a function"
2309 gnus-article-x-face-command))))))))))
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)))))
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)))))))
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)))))
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))))))
2437 (autoload 'idna-to-unicode "idna")
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)))))))))
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))))))
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)))))))
2520 (eval-when-compile
2521 (require 'rfc1843))
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)))))
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))))
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))
2586 (apply (car func) (cdr func))))))))))
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))))
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))))
2614 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
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")))
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))))))))
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
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)))))))
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)))))))))))))
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)))))))))
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))))))
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))
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)))))
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))))))
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)))
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
2800 ((search-forward "\n\n" nil t)
2803 (goto-char (point-max))
2804 nil)))
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)))))))
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)))))
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)))))
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))
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)))))
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)))))
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))
2901 (goto-char cur)
2902 nil)))
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)))
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)
2925 (if (eq hide 'hidden)
2926 (progn
2927 (gnus-article-show-hidden-text type)
2929 nil)))))))
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)))
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)))
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.")
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)))))
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]")
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))
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))))))
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")
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.
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)
3154 (number-to-string (nth 5 dtime))
3155 " at "
3156 (format "%02d" (nth 2 dtime))
3158 (format "%02d" (nth 1 dtime)))))))
3159 (error
3160 (format "Date: %s (from Gnus)" date))))
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))
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))
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))
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))
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))))))
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)))
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)))
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))
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))
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)))
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)))))
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)))))))
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)))))))))
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)))))
3324 (eval-when-compile
3325 (defvar gnus-summary-article-menu)
3326 (defvar gnus-summary-post-menu))
3328 ;;; Saving functions.
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)))))
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)
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.
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))
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)))))
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)))
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)
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)
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)
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))
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)
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))
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))
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)))
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))
3606 ;;; Article file names when saving.
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))))
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))))
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))))
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)))
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)))
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)))))))))
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)))
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)
3817 ;;; Gnus article mode
3820 (put 'gnus-article-mode 'mode-class 'special)
3822 (set-keymap-parent gnus-article-mode-map widget-keymap)
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
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)
3850 (substitute-key-definition
3851 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
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]))
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]))
3884 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3886 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3888 (gnus-run-hooks 'gnus-article-menu-hook)))
3890 (defun gnus-article-mode ()
3891 "Major mode for displaying an article.
3893 All normal editing commands are switched off.
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 Emacs 22 from displaying non-break space with `nobreak-space'
3929 ;; face.
3930 (set (make-local-variable 'nobreak-char-display) nil)
3931 (setq cursor-in-non-selected-windows nil)
3932 (gnus-set-default-directory)
3933 (buffer-disable-undo)
3934 (setq buffer-read-only t)
3935 (set-syntax-table gnus-article-mode-syntax-table)
3936 (mm-enable-multibyte)
3937 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3939 ;; Internal variables. Are `gnus-button-regexp' and `gnus-button-last' used
3940 ;; at all?
3941 (defvar gnus-button-regexp nil)
3942 (defvar gnus-button-marker-list nil
3943 "Regexp matching any of the regexps from `gnus-button-alist'.")
3944 (defvar gnus-button-last nil
3945 "The value of `gnus-button-alist' when `gnus-button-regexp' was build.")
3947 (defun gnus-article-setup-buffer ()
3948 "Initialize the article buffer."
3949 (let* ((name (if gnus-single-article-buffer "*Article*"
3950 (concat "*Article " gnus-newsgroup-name "*")))
3951 (original
3952 (progn (string-match "\\*Article" name)
3953 (concat " *Original Article"
3954 (substring name (match-end 0))))))
3955 (setq gnus-article-buffer name)
3956 (setq gnus-original-article-buffer original)
3957 (setq gnus-article-mime-handle-alist nil)
3958 ;; This might be a variable local to the summary buffer.
3959 (unless gnus-single-article-buffer
3960 (save-excursion
3961 (set-buffer gnus-summary-buffer)
3962 (setq gnus-article-buffer name)
3963 (setq gnus-original-article-buffer original)
3964 (gnus-set-global-variables)))
3965 (gnus-article-setup-highlight-words)
3966 ;; Init original article buffer.
3967 (save-excursion
3968 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3969 (mm-enable-multibyte)
3970 (setq major-mode 'gnus-original-article-mode)
3971 (make-local-variable 'gnus-original-article))
3972 (if (and (get-buffer name)
3973 (with-current-buffer name
3974 (if gnus-article-edit-mode
3975 (if (y-or-n-p "Article mode edit in progress; discard? ")
3976 (progn
3977 (set-buffer-modified-p nil)
3978 (gnus-kill-buffer name)
3979 (message "")
3980 nil)
3981 (error "Action aborted"))
3982 t)))
3983 (save-excursion
3984 (set-buffer name)
3985 (set (make-local-variable 'gnus-article-edit-mode) nil)
3986 (when gnus-article-mime-handles
3987 (mm-destroy-parts gnus-article-mime-handles)
3988 (setq gnus-article-mime-handles nil))
3989 ;; Set it to nil in article-buffer!
3990 (setq gnus-article-mime-handle-alist nil)
3991 (buffer-disable-undo)
3992 (setq buffer-read-only t)
3993 ;; This list just keeps growing if we don't reset it.
3994 (setq gnus-button-marker-list nil)
3995 (unless (eq major-mode 'gnus-article-mode)
3996 (gnus-article-mode))
3997 (current-buffer))
3998 (save-excursion
3999 (set-buffer (gnus-get-buffer-create name))
4000 (gnus-article-mode)
4001 (make-local-variable 'gnus-summary-buffer)
4002 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4003 (current-buffer)))))
4005 ;; Set article window start at LINE, where LINE is the number of lines
4006 ;; from the head of the article.
4007 (defun gnus-article-set-window-start (&optional line)
4008 (set-window-start
4009 (gnus-get-buffer-window gnus-article-buffer t)
4010 (save-excursion
4011 (set-buffer gnus-article-buffer)
4012 (goto-char (point-min))
4013 (if (not line)
4014 (point-min)
4015 (gnus-message 6 "Moved to bookmark")
4016 (search-forward "\n\n" nil t)
4017 (forward-line line)
4018 (point)))))
4020 (defun gnus-article-prepare (article &optional all-headers header)
4021 "Prepare ARTICLE in article mode buffer.
4022 ARTICLE should either be an article number or a Message-ID.
4023 If ARTICLE is an id, HEADER should be the article headers.
4024 If ALL-HEADERS is non-nil, no headers are hidden."
4025 (save-excursion
4026 ;; Make sure we start in a summary buffer.
4027 (unless (eq major-mode 'gnus-summary-mode)
4028 (set-buffer gnus-summary-buffer))
4029 (setq gnus-summary-buffer (current-buffer))
4030 (let* ((gnus-article (if header (mail-header-number header) article))
4031 (summary-buffer (current-buffer))
4032 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4033 (group gnus-newsgroup-name)
4034 result)
4035 (save-excursion
4036 (gnus-article-setup-buffer)
4037 (set-buffer gnus-article-buffer)
4038 ;; Deactivate active regions.
4039 (when (and (boundp 'transient-mark-mode)
4040 transient-mark-mode)
4041 (setq mark-active nil))
4042 (if (not (setq result (let ((inhibit-read-only t))
4043 (gnus-request-article-this-buffer
4044 article group))))
4045 ;; There is no such article.
4046 (save-excursion
4047 (when (and (numberp article)
4048 (not (memq article gnus-newsgroup-sparse)))
4049 (setq gnus-article-current
4050 (cons gnus-newsgroup-name article))
4051 (set-buffer gnus-summary-buffer)
4052 (setq gnus-current-article article)
4053 (if (and (memq article gnus-newsgroup-undownloaded)
4054 (not (gnus-online (gnus-find-method-for-group
4055 gnus-newsgroup-name))))
4056 (progn
4057 (gnus-summary-set-agent-mark article)
4058 (message "Message marked for downloading"))
4059 (gnus-summary-mark-article article gnus-canceled-mark)
4060 (unless (memq article gnus-newsgroup-sparse)
4061 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4062 (if (or (eq result 'pseudo)
4063 (eq result 'nneething))
4064 (progn
4065 (save-excursion
4066 (set-buffer summary-buffer)
4067 (push article gnus-newsgroup-history)
4068 (setq gnus-last-article gnus-current-article
4069 gnus-current-article 0
4070 gnus-current-headers nil
4071 gnus-article-current nil)
4072 (if (eq result 'nneething)
4073 (gnus-configure-windows 'summary)
4074 (gnus-configure-windows 'article))
4075 (gnus-set-global-variables))
4076 (let ((gnus-article-mime-handle-alist-1
4077 gnus-article-mime-handle-alist))
4078 (gnus-set-mode-line 'article)))
4079 ;; The result from the `request' was an actual article -
4080 ;; or at least some text that is now displayed in the
4081 ;; article buffer.
4082 (when (and (numberp article)
4083 (not (eq article gnus-current-article)))
4084 ;; Seems like a new article has been selected.
4085 ;; `gnus-current-article' must be an article number.
4086 (save-excursion
4087 (set-buffer summary-buffer)
4088 (push article gnus-newsgroup-history)
4089 (setq gnus-last-article gnus-current-article
4090 gnus-current-article article
4091 gnus-current-headers
4092 (gnus-summary-article-header gnus-current-article)
4093 gnus-article-current
4094 (cons gnus-newsgroup-name gnus-current-article))
4095 (unless (vectorp gnus-current-headers)
4096 (setq gnus-current-headers nil))
4097 (gnus-summary-goto-subject gnus-current-article)
4098 (when (gnus-summary-show-thread)
4099 ;; If the summary buffer really was folded, the
4100 ;; previous goto may not actually have gone to
4101 ;; the right article, but the thread root instead.
4102 ;; So we go again.
4103 (gnus-summary-goto-subject gnus-current-article))
4104 (gnus-run-hooks 'gnus-mark-article-hook)
4105 (gnus-set-mode-line 'summary)
4106 (when (gnus-visual-p 'article-highlight 'highlight)
4107 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4108 ;; Set the global newsgroup variables here.
4109 (gnus-set-global-variables)
4110 (setq gnus-have-all-headers
4111 (or all-headers gnus-show-all-headers))))
4112 (save-excursion
4113 (gnus-configure-windows 'article))
4114 (when (or (numberp article)
4115 (stringp article))
4116 (gnus-article-prepare-display)
4117 ;; Do page break.
4118 (goto-char (point-min))
4119 (when gnus-break-pages
4120 (gnus-narrow-to-page)))
4121 (let ((gnus-article-mime-handle-alist-1
4122 gnus-article-mime-handle-alist))
4123 (gnus-set-mode-line 'article))
4124 (article-goto-body)
4125 (unless (bobp)
4126 (forward-line -1))
4127 (set-window-point (get-buffer-window (current-buffer)) (point))
4128 (gnus-configure-windows 'article)
4129 t))))))
4131 ;;;###autoload
4132 (defun gnus-article-prepare-display ()
4133 "Make the current buffer look like a nice article."
4134 ;; Hooks for getting information from the article.
4135 ;; This hook must be called before being narrowed.
4136 (let ((gnus-article-buffer (current-buffer))
4137 buffer-read-only
4138 (inhibit-read-only t))
4139 (unless (eq major-mode 'gnus-article-mode)
4140 (gnus-article-mode))
4141 (setq buffer-read-only nil
4142 gnus-article-wash-types nil
4143 gnus-article-image-alist nil)
4144 (gnus-run-hooks 'gnus-tmp-internal-hook)
4145 (when gnus-display-mime-function
4146 (funcall gnus-display-mime-function))
4147 (gnus-run-hooks 'gnus-article-prepare-hook)))
4150 ;;; Gnus MIME viewing functions
4153 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4154 "Format of the MIME buttons.
4156 Valid specifiers include:
4157 %t The MIME type
4158 %T MIME type, along with additional info
4159 %n The `name' parameter
4160 %d The description, if any
4161 %l The length of the encoded part
4162 %p The part identifier number
4163 %e Dots if the part isn't displayed
4165 General format specifiers can also be used. See Info node
4166 `(gnus)Formatting Variables'.")
4168 (defvar gnus-mime-button-line-format-alist
4169 '((?t gnus-tmp-type ?s)
4170 (?T gnus-tmp-type-long ?s)
4171 (?n gnus-tmp-name ?s)
4172 (?d gnus-tmp-description ?s)
4173 (?p gnus-tmp-id ?s)
4174 (?l gnus-tmp-length ?d)
4175 (?e gnus-tmp-dots ?s)))
4177 (defvar gnus-mime-button-commands
4178 '((gnus-article-press-button "\r" "Toggle Display")
4179 (gnus-mime-view-part "v" "View Interactively...")
4180 (gnus-mime-view-part-as-type "t" "View As Type...")
4181 (gnus-mime-view-part-as-charset "C" "View As charset...")
4182 (gnus-mime-save-part "o" "Save...")
4183 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4184 (gnus-mime-delete-part "d" "Delete part")
4185 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4186 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4187 (gnus-mime-view-part-internally "E" "View Internally")
4188 (gnus-mime-view-part-externally "e" "View Externally")
4189 (gnus-mime-print-part "p" "Print")
4190 (gnus-mime-pipe-part "|" "Pipe To Command...")
4191 (gnus-mime-action-on-part "." "Take action on the part...")))
4193 (defun gnus-article-mime-part-status ()
4194 (if gnus-article-mime-handle-alist-1
4195 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4196 " (1 part)"
4197 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4198 ""))
4200 (defvar gnus-mime-button-map
4201 (let ((map (make-sparse-keymap)))
4202 (unless (>= (string-to-number emacs-version) 21)
4203 ;; XEmacs doesn't care.
4204 (set-keymap-parent map gnus-article-mode-map))
4205 (define-key map gnus-mouse-2 'gnus-article-push-button)
4206 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4207 (dolist (c gnus-mime-button-commands)
4208 (define-key map (cadr c) (car c)))
4209 map))
4211 (easy-menu-define
4212 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4213 `("MIME Part"
4214 ,@(mapcar (lambda (c)
4215 (vector (caddr c) (car c) :enable t))
4216 gnus-mime-button-commands)))
4218 (eval-when-compile
4219 (define-compiler-macro popup-menu (&whole form
4220 menu &optional position prefix)
4221 (if (and (fboundp 'popup-menu)
4222 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4223 form
4224 ;; Gnus is probably running under Emacs 20.
4225 `(let* ((menu (cdr ,menu))
4226 (response (x-popup-menu
4227 t (list (car menu)
4228 (cons "" (mapcar (lambda (c)
4229 (cons (caddr c) (car c)))
4230 (cdr menu)))))))
4231 (if response
4232 (call-interactively (nth 3 (assq response menu))))))))
4234 (defun gnus-mime-button-menu (event prefix)
4235 "Construct a context-sensitive menu of MIME commands."
4236 (interactive "e\nP")
4237 (save-window-excursion
4238 (let ((pos (event-start event)))
4239 (select-window (posn-window pos))
4240 (goto-char (posn-point pos))
4241 (gnus-article-check-buffer)
4242 (popup-menu gnus-mime-button-menu nil prefix))))
4244 (defun gnus-mime-view-all-parts (&optional handles)
4245 "View all the MIME parts."
4246 (interactive)
4247 (save-current-buffer
4248 (set-buffer gnus-article-buffer)
4249 (let ((handles (or handles gnus-article-mime-handles))
4250 (mail-parse-charset gnus-newsgroup-charset)
4251 (mail-parse-ignored-charsets
4252 (with-current-buffer gnus-summary-buffer
4253 gnus-newsgroup-ignored-charsets)))
4254 (when handles
4255 (mm-remove-parts handles)
4256 (goto-char (point-min))
4257 (or (search-forward "\n\n") (goto-char (point-max)))
4258 (let ((inhibit-read-only t))
4259 (delete-region (point) (point-max))
4260 (mm-display-parts handles))))))
4262 (defun gnus-mime-save-part-and-strip ()
4263 "Save the MIME part under point then replace it with an external body."
4264 (interactive)
4265 (gnus-article-check-buffer)
4266 (when (gnus-group-read-only-p)
4267 (error "The current group does not support deleting of parts"))
4268 (when (mm-complicated-handles gnus-article-mime-handles)
4269 (error "\
4270 The current article has a complicated MIME structure, giving up..."))
4271 (when (gnus-yes-or-no-p "\
4272 Deleting parts may malfunction or destroy the article; continue? ")
4273 (let* ((data (get-text-property (point) 'gnus-data))
4274 file param
4275 (handles gnus-article-mime-handles))
4276 (setq file (and data (mm-save-part data)))
4277 (when file
4278 (with-current-buffer (mm-handle-buffer data)
4279 (erase-buffer)
4280 (insert "Content-Type: " (mm-handle-media-type data))
4281 (mml-insert-parameter-string (cdr (mm-handle-type data))
4282 '(charset))
4283 ;; Add a filename for the sake of saving the part again.
4284 (mml-insert-parameter
4285 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4286 (insert "\n")
4287 (insert "Content-ID: " (message-make-message-id) "\n")
4288 (insert "Content-Transfer-Encoding: binary\n")
4289 (insert "\n"))
4290 (setcdr data
4291 (cdr (mm-make-handle nil
4292 `("message/external-body"
4293 (access-type . "LOCAL-FILE")
4294 (name . ,file)))))
4295 (set-buffer gnus-summary-buffer)
4296 (gnus-article-edit-article
4297 `(lambda ()
4298 (erase-buffer)
4299 (let ((mail-parse-charset (or gnus-article-charset
4300 ',gnus-newsgroup-charset))
4301 (mail-parse-ignored-charsets
4302 (or gnus-article-ignored-charsets
4303 ',gnus-newsgroup-ignored-charsets))
4304 (mbl mml-buffer-list))
4305 (setq mml-buffer-list nil)
4306 (insert-buffer-substring gnus-original-article-buffer)
4307 (mime-to-mml ',handles)
4308 (setq gnus-article-mime-handles nil)
4309 (let ((mbl1 mml-buffer-list))
4310 (setq mml-buffer-list mbl)
4311 (set (make-local-variable 'mml-buffer-list) mbl1))
4312 (gnus-make-local-hook 'kill-buffer-hook)
4313 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4314 `(lambda (no-highlight)
4315 (let ((mail-parse-charset (or gnus-article-charset
4316 ',gnus-newsgroup-charset))
4317 (message-options message-options)
4318 (message-options-set-recipient)
4319 (mail-parse-ignored-charsets
4320 (or gnus-article-ignored-charsets
4321 ',gnus-newsgroup-ignored-charsets)))
4322 (mml-to-mime)
4323 (mml-destroy-buffers)
4324 (remove-hook 'kill-buffer-hook
4325 'mml-destroy-buffers t)
4326 (kill-local-variable 'mml-buffer-list))
4327 (gnus-summary-edit-article-done
4328 ,(or (mail-header-references gnus-current-headers) "")
4329 ,(gnus-group-read-only-p)
4330 ,gnus-summary-buffer no-highlight)))))))
4332 (defun gnus-mime-delete-part ()
4333 "Delete the MIME part under point.
4334 Replace it with some information about the removed part."
4335 (interactive)
4336 (gnus-article-check-buffer)
4337 (when (gnus-group-read-only-p)
4338 (error "The current group does not support deleting of parts"))
4339 (when (mm-complicated-handles gnus-article-mime-handles)
4340 (error "\
4341 The current article has a complicated MIME structure, giving up..."))
4342 (when (gnus-yes-or-no-p "\
4343 Deleting parts may malfunction or destroy the article; continue? ")
4344 (let* ((data (get-text-property (point) 'gnus-data))
4345 (handles gnus-article-mime-handles)
4346 (none "(none)")
4347 (description
4348 (mail-decode-encoded-word-string (or (mm-handle-description data)
4349 none)))
4350 (filename
4351 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4352 none))
4353 (type (mm-handle-media-type data)))
4354 (unless data
4355 (error "No MIME part under point"))
4356 (with-current-buffer (mm-handle-buffer data)
4357 (let ((bsize (format "%s" (buffer-size))))
4358 (erase-buffer)
4359 (insert
4360 (concat
4361 ",----\n"
4362 "| The following attachment has been deleted:\n"
4363 "|\n"
4364 "| Type: " type "\n"
4365 "| Filename: " filename "\n"
4366 "| Size (encoded): " bsize " Byte\n"
4367 "| Description: " description "\n"
4368 "`----\n"))
4369 (setcdr data
4370 (cdr (mm-make-handle
4371 nil `("text/plain") nil nil
4372 (list "attachment")
4373 (format "Deleted attachment (%s bytes)" bsize))))))
4374 (set-buffer gnus-summary-buffer)
4375 ;; FIXME: maybe some of the following code (borrowed from
4376 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4377 (gnus-article-edit-article
4378 `(lambda ()
4379 (erase-buffer)
4380 (let ((mail-parse-charset (or gnus-article-charset
4381 ',gnus-newsgroup-charset))
4382 (mail-parse-ignored-charsets
4383 (or gnus-article-ignored-charsets
4384 ',gnus-newsgroup-ignored-charsets))
4385 (mbl mml-buffer-list))
4386 (setq mml-buffer-list nil)
4387 (insert-buffer-substring gnus-original-article-buffer)
4388 (mime-to-mml ',handles)
4389 (setq gnus-article-mime-handles nil)
4390 (let ((mbl1 mml-buffer-list))
4391 (setq mml-buffer-list mbl)
4392 (set (make-local-variable 'mml-buffer-list) mbl1))
4393 (gnus-make-local-hook 'kill-buffer-hook)
4394 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4395 `(lambda (no-highlight)
4396 (let ((mail-parse-charset (or gnus-article-charset
4397 ',gnus-newsgroup-charset))
4398 (message-options message-options)
4399 (message-options-set-recipient)
4400 (mail-parse-ignored-charsets
4401 (or gnus-article-ignored-charsets
4402 ',gnus-newsgroup-ignored-charsets)))
4403 (mml-to-mime)
4404 (mml-destroy-buffers)
4405 (remove-hook 'kill-buffer-hook
4406 'mml-destroy-buffers t)
4407 (kill-local-variable 'mml-buffer-list))
4408 (gnus-summary-edit-article-done
4409 ,(or (mail-header-references gnus-current-headers) "")
4410 ,(gnus-group-read-only-p)
4411 ,gnus-summary-buffer no-highlight))))
4412 ;; Not in `gnus-mime-save-part-and-strip':
4413 (gnus-article-edit-done)
4414 (gnus-summary-expand-window)
4415 (gnus-summary-show-article)))
4417 (defun gnus-mime-save-part ()
4418 "Save the MIME part under point."
4419 (interactive)
4420 (gnus-article-check-buffer)
4421 (let ((data (get-text-property (point) 'gnus-data)))
4422 (when data
4423 (mm-save-part data))))
4425 (defun gnus-mime-pipe-part ()
4426 "Pipe the MIME part under point to a process."
4427 (interactive)
4428 (gnus-article-check-buffer)
4429 (let ((data (get-text-property (point) 'gnus-data)))
4430 (when data
4431 (mm-pipe-part data))))
4433 (defun gnus-mime-view-part ()
4434 "Interactively choose a viewing method for the MIME part under point."
4435 (interactive)
4436 (gnus-article-check-buffer)
4437 (let ((data (get-text-property (point) 'gnus-data)))
4438 (when data
4439 (setq gnus-article-mime-handles
4440 (mm-merge-handles
4441 gnus-article-mime-handles (setq data (copy-sequence data))))
4442 (mm-interactively-view-part data))))
4444 (defun gnus-mime-view-part-as-type-internal ()
4445 (gnus-article-check-buffer)
4446 (let* ((handle (get-text-property (point) 'gnus-data))
4447 (name (or
4448 ;; Content-Type: foo/bar; name=...
4449 (mail-content-type-get (mm-handle-type handle) 'name)
4450 ;; Content-Disposition: attachment; filename=...
4451 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4452 (def-type (and name (mm-default-file-encoding name))))
4453 (and def-type (cons def-type 0))))
4455 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4456 "Choose a MIME media type, and view the part as such.
4457 If non-nil, PRED is a predicate to use during completion to limit the
4458 available media-types."
4459 (interactive)
4460 (unless mime-type
4461 (setq mime-type
4462 (let ((default (gnus-mime-view-part-as-type-internal)))
4463 (completing-read
4464 (format "View as MIME type (default %s): "
4465 (car default))
4466 (mapcar #'list (mailcap-mime-types))
4467 pred nil nil nil
4468 (car default)))))
4469 (gnus-article-check-buffer)
4470 (let ((handle (get-text-property (point) 'gnus-data)))
4471 (when handle
4472 (when (equal (mm-handle-media-type handle) "message/external-body")
4473 (unless (mm-handle-cache handle)
4474 (mm-extern-cache-contents handle))
4475 (setq handle (mm-handle-cache handle)))
4476 (setq handle
4477 (mm-make-handle (mm-handle-buffer handle)
4478 (cons mime-type (cdr (mm-handle-type handle)))
4479 (mm-handle-encoding handle)
4480 (mm-handle-undisplayer handle)
4481 (mm-handle-disposition handle)
4482 (mm-handle-description handle)
4484 (mm-handle-id handle)))
4485 (setq gnus-article-mime-handles
4486 (mm-merge-handles gnus-article-mime-handles handle))
4487 (gnus-mm-display-part handle))))
4489 (eval-when-compile
4490 (require 'jka-compr))
4492 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4493 ;; emacs can do that itself.
4495 (defun gnus-mime-jka-compr-maybe-uncompress ()
4496 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4497 The uncompress method used is derived from `buffer-file-name'."
4498 (when (and (fboundp 'jka-compr-installed-p)
4499 (jka-compr-installed-p))
4500 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4501 (when info
4502 (let ((basename (file-name-nondirectory buffer-file-name))
4503 (args (jka-compr-info-uncompress-args info))
4504 (prog (jka-compr-info-uncompress-program info))
4505 (message (jka-compr-info-uncompress-message info))
4506 (err-file (jka-compr-make-temp-name)))
4507 (if message
4508 (message "%s %s..." message basename))
4509 (unwind-protect
4510 (unless (memq (apply 'call-process-region
4511 (point-min) (point-max)
4512 prog
4513 t (list t err-file) nil
4514 args)
4515 jka-compr-acceptable-retval-list)
4516 (jka-compr-error prog args basename message err-file))
4517 (jka-compr-delete-temp-file err-file)))))))
4519 (defun gnus-mime-copy-part (&optional handle)
4520 "Put the MIME part under point into a new buffer.
4521 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4522 are decompressed."
4523 (interactive)
4524 (gnus-article-check-buffer)
4525 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4526 (contents (and handle (mm-get-part handle)))
4527 (base (and handle
4528 (file-name-nondirectory
4530 (mail-content-type-get (mm-handle-type handle) 'name)
4531 (mail-content-type-get (mm-handle-disposition handle)
4532 'filename)
4533 "*decoded*"))))
4534 (buffer (and base (generate-new-buffer base))))
4535 (when contents
4536 (switch-to-buffer buffer)
4537 (insert contents)
4538 ;; We do it this way to make `normal-mode' set the appropriate mode.
4539 (unwind-protect
4540 (progn
4541 (setq buffer-file-name (expand-file-name base))
4542 (gnus-mime-jka-compr-maybe-uncompress)
4543 (normal-mode))
4544 (setq buffer-file-name nil))
4545 (goto-char (point-min)))))
4547 (defun gnus-mime-print-part (&optional handle filename)
4548 "Print the MIME part under point."
4549 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4550 (gnus-article-check-buffer)
4551 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4552 (contents (and handle (mm-get-part handle)))
4553 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4554 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4555 (when contents
4556 (if printer
4557 (unwind-protect
4558 (progn
4559 (mm-save-part-to-file handle file)
4560 (call-process shell-file-name nil
4561 (generate-new-buffer " *mm*")
4563 shell-command-switch
4564 (mm-mailcap-command
4565 printer file (mm-handle-type handle))))
4566 (delete-file file))
4567 (with-temp-buffer
4568 (insert contents)
4569 (gnus-print-buffer))
4570 (ps-despool filename)))))
4572 (defun gnus-mime-inline-part (&optional handle arg)
4573 "Insert the MIME part under point into the current buffer."
4574 (interactive (list nil current-prefix-arg))
4575 (gnus-article-check-buffer)
4576 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4577 contents charset
4578 (b (point))
4579 (inhibit-read-only t))
4580 (when handle
4581 (if (and (not arg) (mm-handle-undisplayer handle))
4582 (mm-remove-part handle)
4583 (setq contents (mm-get-part handle))
4584 (cond
4585 ((not arg)
4586 (setq charset (or (mail-content-type-get
4587 (mm-handle-type handle) 'charset)
4588 gnus-newsgroup-charset)))
4589 ((numberp arg)
4590 (if (mm-handle-undisplayer handle)
4591 (mm-remove-part handle))
4592 (setq charset
4593 (or (cdr (assq arg
4594 gnus-summary-show-article-charset-alist))
4595 (mm-read-coding-system "Charset: "))))
4597 (if (mm-handle-undisplayer handle)
4598 (mm-remove-part handle))))
4599 (forward-line 2)
4600 (mm-insert-inline
4601 handle
4602 (if (and charset
4603 (setq charset (mm-charset-to-coding-system
4604 charset))
4605 (not (eq charset 'ascii)))
4606 (mm-decode-coding-string contents charset)
4607 (mm-string-to-multibyte contents)))
4608 (goto-char b)))))
4610 (defun gnus-mime-strip-charset-parameters (handle)
4611 "Strip charset parameters from HANDLE."
4612 (if (stringp (car handle))
4613 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
4614 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
4615 "message/external-body")
4616 (progn
4617 (unless (mm-handle-cache handle)
4618 (mm-extern-cache-contents handle))
4619 (mm-handle-cache handle))
4620 handle)))
4621 (charset (assq 'charset (cdr type))))
4622 (when charset
4623 (delq charset type)))))
4625 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4626 "Insert the MIME part under point into the current buffer using the
4627 specified charset."
4628 (interactive (list nil current-prefix-arg))
4629 (gnus-article-check-buffer)
4630 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4631 (fun (get-text-property (point) 'gnus-callback))
4632 (gnus-newsgroup-ignored-charsets 'gnus-all)
4633 gnus-newsgroup-charset form preferred parts)
4634 (when handle
4635 (if (mm-handle-undisplayer handle)
4636 (mm-remove-part handle))
4637 (when fun
4638 (setq gnus-newsgroup-charset
4639 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4640 (mm-read-coding-system "Charset: ")))
4641 (gnus-mime-strip-charset-parameters handle)
4642 (when (and (consp (setq form (cdr-safe fun)))
4643 (setq form (ignore-errors
4644 (assq 'gnus-mime-display-alternative form)))
4645 (setq preferred (caddr form))
4646 (progn
4647 (when (eq (car preferred) 'quote)
4648 (setq preferred (cadr preferred)))
4649 (not (equal preferred
4650 (get-text-property (point) 'gnus-data))))
4651 (setq parts (get-text-property (point) 'gnus-part))
4652 (setq parts (cdr (assq parts
4653 gnus-article-mime-handle-alist)))
4654 (equal (mm-handle-media-type parts) "multipart/alternative")
4655 (setq parts (reverse (cdr parts))))
4656 (setcar (cddr form)
4657 (list 'quote (or (cadr (member preferred parts))
4658 (car parts)))))
4659 (funcall fun handle)))))
4661 (defun gnus-mime-view-part-externally (&optional handle)
4662 "View the MIME part under point with an external viewer."
4663 (interactive)
4664 (gnus-article-check-buffer)
4665 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4666 (mm-user-display-methods nil)
4667 (mm-inlined-types nil)
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 (type (mm-handle-media-type handle))
4673 (method (mailcap-mime-info type))
4674 (mm-enable-external t))
4675 (if (not (stringp method))
4676 (gnus-mime-view-part-as-type
4677 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
4678 (when handle
4679 (if (mm-handle-undisplayer handle)
4680 (mm-remove-part handle)
4681 (mm-display-part handle))))))
4683 (defun gnus-mime-view-part-internally (&optional handle)
4684 "View the MIME part under point with an internal viewer.
4685 If no internal viewer is available, use an external viewer."
4686 (interactive)
4687 (gnus-article-check-buffer)
4688 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4689 (mm-inlined-types '(".*"))
4690 (mm-inline-large-images t)
4691 (mail-parse-charset gnus-newsgroup-charset)
4692 (mail-parse-ignored-charsets
4693 (with-current-buffer gnus-summary-buffer
4694 gnus-newsgroup-ignored-charsets))
4695 (inhibit-read-only t))
4696 (if (not (mm-inlinable-p handle))
4697 (gnus-mime-view-part-as-type
4698 nil (lambda (types) (mm-inlinable-p handle (car types))))
4699 (when handle
4700 (if (mm-handle-undisplayer handle)
4701 (mm-remove-part handle)
4702 (mm-display-part handle))))))
4704 (defun gnus-mime-action-on-part (&optional action)
4705 "Do something with the MIME attachment at \(point\)."
4706 (interactive
4707 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4708 (gnus-article-check-buffer)
4709 (let ((action-pair (assoc action gnus-mime-action-alist)))
4710 (if action-pair
4711 (funcall (cdr action-pair)))))
4713 (defun gnus-article-part-wrapper (n function)
4714 (let ((window (get-buffer-window gnus-article-buffer 'visible))
4715 frame)
4716 (when window
4717 ;; It is necessary to select the article window so that
4718 ;; `gnus-article-goto-part' may really move the point.
4719 (setq frame (selected-frame))
4720 (gnus-select-frame-set-input-focus (window-frame window))
4721 (unwind-protect
4722 (save-window-excursion
4723 (select-window window)
4724 (when (> n (length gnus-article-mime-handle-alist))
4725 (error "No such part"))
4726 (gnus-article-goto-part n)
4727 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4728 (funcall function handle)))
4729 (gnus-select-frame-set-input-focus frame)))))
4731 (defun gnus-article-pipe-part (n)
4732 "Pipe MIME part N, which is the numerical prefix."
4733 (interactive "p")
4734 (gnus-article-part-wrapper n 'mm-pipe-part))
4736 (defun gnus-article-save-part (n)
4737 "Save MIME part N, which is the numerical prefix."
4738 (interactive "p")
4739 (gnus-article-part-wrapper n 'mm-save-part))
4741 (defun gnus-article-interactively-view-part (n)
4742 "View MIME part N interactively, which is the numerical prefix."
4743 (interactive "p")
4744 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4746 (defun gnus-article-copy-part (n)
4747 "Copy MIME part N, which is the numerical prefix."
4748 (interactive "p")
4749 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4751 (defun gnus-article-view-part-as-charset (n)
4752 "View MIME part N using a specified charset.
4753 N is the numerical prefix."
4754 (interactive "p")
4755 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4757 (defun gnus-article-view-part-externally (n)
4758 "View MIME part N externally, which is the numerical prefix."
4759 (interactive "p")
4760 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4762 (defun gnus-article-inline-part (n)
4763 "Inline MIME part N, which is the numerical prefix."
4764 (interactive "p")
4765 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4767 (defun gnus-article-mime-match-handle-first (condition)
4768 (if condition
4769 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4770 (while (setq ihandle (pop alist))
4771 (if (and (cond
4772 ((functionp condition)
4773 (funcall condition (cdr ihandle)))
4774 ((eq condition 'undisplayed)
4775 (not (or (mm-handle-undisplayer (cdr ihandle))
4776 (equal (mm-handle-media-type (cdr ihandle))
4777 "multipart/alternative"))))
4778 ((eq condition 'undisplayed-alternative)
4779 (not (mm-handle-undisplayer (cdr ihandle))))
4780 (t t))
4781 (gnus-article-goto-part (car ihandle))
4782 (or (not n) (< (car ihandle) n)))
4783 (setq n (car ihandle))))
4784 (or n 1))
4787 (defun gnus-article-view-part (&optional n)
4788 "View MIME part N, which is the numerical prefix."
4789 (interactive "P")
4790 (save-current-buffer
4791 (set-buffer gnus-article-buffer)
4792 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4793 gnus-article-mime-match-handle-function)))
4794 (when (> n (length gnus-article-mime-handle-alist))
4795 (error "No such part"))
4796 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4797 (when (gnus-article-goto-part n)
4798 (if (equal (car handle) "multipart/alternative")
4799 (gnus-article-press-button)
4800 (when (eq (gnus-mm-display-part handle) 'internal)
4801 (gnus-set-window-start)))))))
4803 (defsubst gnus-article-mime-total-parts ()
4804 (if (bufferp (car gnus-article-mime-handles))
4805 1 ;; single part
4806 (1- (length gnus-article-mime-handles))))
4808 (defun gnus-mm-display-part (handle)
4809 "Display HANDLE and fix MIME button."
4810 (let ((id (get-text-property (point) 'gnus-part))
4811 (point (point))
4812 (inhibit-read-only t))
4813 (forward-line 1)
4814 (prog1
4815 (let ((window (selected-window))
4816 (mail-parse-charset gnus-newsgroup-charset)
4817 (mail-parse-ignored-charsets
4818 (if (gnus-buffer-live-p gnus-summary-buffer)
4819 (save-excursion
4820 (set-buffer gnus-summary-buffer)
4821 gnus-newsgroup-ignored-charsets)
4822 nil)))
4823 (save-excursion
4824 (unwind-protect
4825 (let ((win (gnus-get-buffer-window (current-buffer) t))
4826 (beg (point)))
4827 (when win
4828 (select-window win))
4829 (goto-char point)
4830 (forward-line)
4831 (if (mm-handle-displayed-p handle)
4832 ;; This will remove the part.
4833 (mm-display-part handle)
4834 (save-restriction
4835 (narrow-to-region (point)
4836 (if (eobp) (point) (1+ (point))))
4837 (mm-display-part handle)
4838 ;; We narrow to the part itself and
4839 ;; then call the treatment functions.
4840 (goto-char (point-min))
4841 (forward-line 1)
4842 (narrow-to-region (point) (point-max))
4843 (gnus-treat-article
4844 nil id
4845 (gnus-article-mime-total-parts)
4846 (mm-handle-media-type handle)))))
4847 (if (window-live-p window)
4848 (select-window window)))))
4849 (goto-char point)
4850 (gnus-delete-line)
4851 (gnus-insert-mime-button
4852 handle id (list (mm-handle-displayed-p handle)))
4853 (goto-char point))))
4855 (defun gnus-article-goto-part (n)
4856 "Go to MIME part N."
4857 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4859 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4860 (let ((gnus-tmp-name
4861 (or (mail-content-type-get (mm-handle-type handle) 'name)
4862 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4863 (mail-content-type-get (mm-handle-type handle) 'url)
4864 ""))
4865 (gnus-tmp-type (mm-handle-media-type handle))
4866 (gnus-tmp-description
4867 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4868 "")))
4869 (gnus-tmp-dots
4870 (if (if displayed (car displayed)
4871 (mm-handle-displayed-p handle))
4872 "" "..."))
4873 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4874 (buffer-size)))
4875 gnus-tmp-type-long b e)
4876 (when (string-match ".*/" gnus-tmp-name)
4877 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4878 (setq gnus-tmp-type-long (concat gnus-tmp-type
4879 (and (not (equal gnus-tmp-name ""))
4880 (concat "; " gnus-tmp-name))))
4881 (unless (equal gnus-tmp-description "")
4882 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4883 (unless (bolp)
4884 (insert "\n"))
4885 (setq b (point))
4886 (gnus-eval-format
4887 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4888 `(,@(gnus-local-map-property gnus-mime-button-map)
4889 gnus-callback gnus-mm-display-part
4890 gnus-part ,gnus-tmp-id
4891 article-type annotation
4892 gnus-data ,handle))
4893 (setq e (if (bolp)
4894 ;; Exclude a newline.
4895 (1- (point))
4896 (point)))
4897 (widget-convert-button
4898 'link b e
4899 :mime-handle handle
4900 :action 'gnus-widget-press-button
4901 :button-keymap gnus-mime-button-map
4902 :help-echo
4903 (lambda (widget/window &optional overlay pos)
4904 ;; Needed to properly clear the message due to a bug in
4905 ;; wid-edit (XEmacs only).
4906 (if (boundp 'help-echo-owns-message)
4907 (setq help-echo-owns-message t))
4908 (format
4909 "%S: %s the MIME part; %S: more options"
4910 (aref gnus-mouse-2 0)
4911 ;; XEmacs will get a single widget arg; Emacs 21 will get
4912 ;; window, overlay, position.
4913 (if (mm-handle-displayed-p
4914 (if overlay
4915 (with-current-buffer (gnus-overlay-buffer overlay)
4916 (widget-get (widget-at (gnus-overlay-start overlay))
4917 :mime-handle))
4918 (widget-get widget/window :mime-handle)))
4919 "hide" "show")
4920 (aref gnus-down-mouse-3 0))))))
4922 (defun gnus-widget-press-button (elems el)
4923 (goto-char (widget-get elems :from))
4924 (gnus-article-press-button))
4926 (defvar gnus-displaying-mime nil)
4928 (defun gnus-display-mime (&optional ihandles)
4929 "Display the MIME parts."
4930 (save-excursion
4931 (save-selected-window
4932 (let ((window (get-buffer-window gnus-article-buffer))
4933 (point (point)))
4934 (when window
4935 (select-window window)
4936 ;; We have to do this since selecting the window
4937 ;; may change the point. So we set the window point.
4938 (set-window-point window point)))
4939 (let ((handles ihandles)
4940 (inhibit-read-only t)
4941 handle)
4942 (cond (handles)
4943 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4944 (when gnus-article-emulate-mime
4945 (mm-uu-dissect-text-parts handles)))
4946 (gnus-article-emulate-mime
4947 (setq handles (mm-uu-dissect))))
4948 (when (and (not ihandles)
4949 (not gnus-displaying-mime))
4950 ;; Top-level call; we clean up.
4951 (when gnus-article-mime-handles
4952 (mm-destroy-parts gnus-article-mime-handles)
4953 (setq gnus-article-mime-handle-alist nil));; A trick.
4954 (setq gnus-article-mime-handles handles)
4955 ;; We allow users to glean info from the handles.
4956 (when gnus-article-mime-part-function
4957 (gnus-mime-part-function handles)))
4958 (if (and handles
4959 (or (not (stringp (car handles)))
4960 (cdr handles)))
4961 (progn
4962 (when (and (not ihandles)
4963 (not gnus-displaying-mime))
4964 ;; Clean up for mime parts.
4965 (article-goto-body)
4966 (delete-region (point) (point-max)))
4967 (let ((gnus-displaying-mime t))
4968 (gnus-mime-display-part handles)))
4969 (save-restriction
4970 (article-goto-body)
4971 (narrow-to-region (point) (point-max))
4972 (gnus-treat-article nil 1 1)
4973 (widen)))
4974 (unless ihandles
4975 ;; Highlight the headers.
4976 (save-excursion
4977 (save-restriction
4978 (article-goto-body)
4979 (narrow-to-region (point-min) (point))
4980 (gnus-article-save-original-date
4981 (gnus-treat-article 'head)))))))
4982 ;; Cope with broken MIME messages.
4983 (goto-char (point-max))
4984 (unless (bolp)
4985 (insert "\n"))))
4987 (defcustom gnus-mime-display-multipart-as-mixed nil
4988 "Display \"multipart\" parts as \"multipart/mixed\".
4990 If t, it overrides nil values of
4991 `gnus-mime-display-multipart-alternative-as-mixed' and
4992 `gnus-mime-display-multipart-related-as-mixed'."
4993 :group 'gnus-article-mime
4994 :type 'boolean)
4996 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4997 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4998 :version "22.1"
4999 :group 'gnus-article-mime
5000 :type 'boolean)
5002 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5003 "Display \"multipart/related\" parts as \"multipart/mixed\".
5005 If displaying \"text/html\" is discouraged \(see
5006 `mm-discouraged-alternatives'\) images or other material inside a
5007 \"multipart/related\" part might be overlooked when this variable is nil."
5008 :version "22.1"
5009 :group 'gnus-article-mime
5010 :type 'boolean)
5012 (defun gnus-mime-display-part (handle)
5013 (cond
5014 ;; Maybe a broken MIME message.
5015 ((null handle))
5016 ;; Single part.
5017 ((not (stringp (car handle)))
5018 (gnus-mime-display-single handle))
5019 ;; User-defined multipart
5020 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5021 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5022 handle))
5023 ;; multipart/alternative
5024 ((and (equal (car handle) "multipart/alternative")
5025 (not (or gnus-mime-display-multipart-as-mixed
5026 gnus-mime-display-multipart-alternative-as-mixed)))
5027 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5028 (push (cons id handle) gnus-article-mime-handle-alist)
5029 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5030 ;; multipart/related
5031 ((and (equal (car handle) "multipart/related")
5032 (not (or gnus-mime-display-multipart-as-mixed
5033 gnus-mime-display-multipart-related-as-mixed)))
5034 ;;;!!!We should find the start part, but we just default
5035 ;;;!!!to the first part.
5036 ;;(gnus-mime-display-part (cadr handle))
5037 ;;;!!! Most multipart/related is an HTML message plus images.
5038 ;;;!!! Unfortunately we are unable to let W3 display those
5039 ;;;!!! included images, so we just display it as a mixed multipart.
5040 ;;(gnus-mime-display-mixed (cdr handle))
5041 ;;;!!! No, w3 can display everything just fine.
5042 (gnus-mime-display-part (cadr handle)))
5043 ((equal (car handle) "multipart/signed")
5044 (gnus-add-wash-type 'signed)
5045 (gnus-mime-display-security handle))
5046 ((equal (car handle) "multipart/encrypted")
5047 (gnus-add-wash-type 'encrypted)
5048 (gnus-mime-display-security handle))
5049 ;; Other multiparts are handled like multipart/mixed.
5051 (gnus-mime-display-mixed (cdr handle)))))
5053 (defun gnus-mime-part-function (handles)
5054 (if (stringp (car handles))
5055 (mapcar 'gnus-mime-part-function (cdr handles))
5056 (funcall gnus-article-mime-part-function handles)))
5058 (defun gnus-mime-display-mixed (handles)
5059 (mapcar 'gnus-mime-display-part handles))
5061 (defun gnus-mime-display-single (handle)
5062 (let ((type (mm-handle-media-type handle))
5063 (ignored gnus-ignored-mime-types)
5064 (not-attachment t)
5065 (move nil)
5066 display text)
5067 (catch 'ignored
5068 (progn
5069 (while ignored
5070 (when (string-match (pop ignored) type)
5071 (throw 'ignored nil)))
5072 (if (and (setq not-attachment
5073 (and (not (mm-inline-override-p handle))
5074 (or (not (mm-handle-disposition handle))
5075 (equal (car (mm-handle-disposition handle))
5076 "inline")
5077 (mm-attachment-override-p handle))))
5078 (mm-automatic-display-p handle)
5079 (or (and
5080 (mm-inlinable-p handle)
5081 (mm-inlined-p handle))
5082 (mm-automatic-external-display-p type)))
5083 (setq display t)
5084 (when (equal (mm-handle-media-supertype handle) "text")
5085 (setq text t)))
5086 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5087 beg)
5088 (push (cons id handle) gnus-article-mime-handle-alist)
5089 (when (and display
5090 (equal (mm-handle-media-supertype handle) "message"))
5091 (insert-char
5093 (cond ((not (bolp)) 2)
5094 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5095 (t 1))))
5096 (when (or (not display)
5097 (not (gnus-unbuttonized-mime-type-p type)))
5098 (gnus-insert-mime-button
5099 handle id (list (or display (and not-attachment text))))
5100 (gnus-article-insert-newline)
5101 ;; Remember modify the number of forward lines.
5102 (setq move t))
5103 (setq beg (point))
5104 (cond
5105 (display
5106 (when move
5107 (forward-line -1)
5108 (setq beg (point)))
5109 (let ((mail-parse-charset gnus-newsgroup-charset)
5110 (mail-parse-ignored-charsets
5111 (save-excursion (condition-case ()
5112 (set-buffer gnus-summary-buffer)
5113 (error))
5114 gnus-newsgroup-ignored-charsets)))
5115 (mm-display-part handle t))
5116 (goto-char (point-max)))
5117 ((and text not-attachment)
5118 (when move
5119 (forward-line -1)
5120 (setq beg (point)))
5121 (gnus-article-insert-newline)
5122 (mm-insert-inline
5123 handle
5124 (let ((charset (mail-content-type-get (mm-handle-type handle)
5125 'charset)))
5126 (cond ((not charset)
5127 (mm-string-as-multibyte (mm-get-part handle)))
5128 ((eq charset 'gnus-decoded)
5129 (with-current-buffer (mm-handle-buffer handle)
5130 (buffer-string)))
5132 (mm-decode-string (mm-get-part handle) charset)))))
5133 (goto-char (point-max))))
5134 ;; Do highlighting.
5135 (save-excursion
5136 (save-restriction
5137 (narrow-to-region beg (point))
5138 (gnus-treat-article
5139 nil id
5140 (gnus-article-mime-total-parts)
5141 (mm-handle-media-type handle)))))))))
5143 (defun gnus-unbuttonized-mime-type-p (type)
5144 "Say whether TYPE is to be unbuttonized."
5145 (unless gnus-inhibit-mime-unbuttonizing
5146 (when (catch 'found
5147 (let ((types gnus-unbuttonized-mime-types))
5148 (while types
5149 (when (string-match (pop types) type)
5150 (throw 'found t)))))
5151 (not (catch 'found
5152 (let ((types gnus-buttonized-mime-types))
5153 (while types
5154 (when (string-match (pop types) type)
5155 (throw 'found t)))))))))
5157 (defun gnus-article-insert-newline ()
5158 "Insert a newline, but mark it as undeletable."
5159 (gnus-put-text-property
5160 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5162 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5163 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5164 (ihandles handles)
5165 (point (point))
5166 handle (inhibit-read-only t) from props begend not-pref)
5167 (save-window-excursion
5168 (save-restriction
5169 (when ibegend
5170 (narrow-to-region (car ibegend)
5171 (or (cdr ibegend)
5172 (progn
5173 (goto-char (car ibegend))
5174 (forward-line 2)
5175 (point))))
5176 (delete-region (point-min) (point-max))
5177 (mm-remove-parts handles))
5178 (setq begend (list (point-marker)))
5179 ;; Do the toggle.
5180 (unless (setq not-pref (cadr (member preferred ihandles)))
5181 (setq not-pref (car ihandles)))
5182 (when (or ibegend
5183 (not preferred)
5184 (not (gnus-unbuttonized-mime-type-p
5185 "multipart/alternative")))
5186 (gnus-add-text-properties
5187 (setq from (point))
5188 (progn
5189 (insert (format "%d. " id))
5190 (point))
5191 `(gnus-callback
5192 (lambda (handles)
5193 (unless ,(not ibegend)
5194 (setq gnus-article-mime-handle-alist
5195 ',gnus-article-mime-handle-alist))
5196 (gnus-mime-display-alternative
5197 ',ihandles ',not-pref ',begend ,id))
5198 ,@(gnus-local-map-property gnus-mime-button-map)
5199 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5200 face ,gnus-article-button-face
5201 gnus-part ,id
5202 article-type multipart))
5203 (widget-convert-button 'link from (point)
5204 :action 'gnus-widget-press-button
5205 :button-keymap gnus-widget-button-keymap)
5206 ;; Do the handles
5207 (while (setq handle (pop handles))
5208 (gnus-add-text-properties
5209 (setq from (point))
5210 (progn
5211 (insert (format "(%c) %-18s"
5212 (if (equal handle preferred) ?* ? )
5213 (mm-handle-media-type handle)))
5214 (point))
5215 `(gnus-callback
5216 (lambda (handles)
5217 (unless ,(not ibegend)
5218 (setq gnus-article-mime-handle-alist
5219 ',gnus-article-mime-handle-alist))
5220 (gnus-mime-display-alternative
5221 ',ihandles ',handle ',begend ,id))
5222 ,@(gnus-local-map-property gnus-mime-button-map)
5223 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5224 face ,gnus-article-button-face
5225 gnus-part ,id
5226 gnus-data ,handle))
5227 (widget-convert-button 'link from (point)
5228 :action 'gnus-widget-press-button
5229 :button-keymap gnus-widget-button-keymap)
5230 (insert " "))
5231 (insert "\n\n"))
5232 (when preferred
5233 (if (stringp (car preferred))
5234 (gnus-display-mime preferred)
5235 (let ((mail-parse-charset gnus-newsgroup-charset)
5236 (mail-parse-ignored-charsets
5237 (save-excursion (set-buffer gnus-summary-buffer)
5238 gnus-newsgroup-ignored-charsets)))
5239 (mm-display-part preferred)
5240 ;; Do highlighting.
5241 (save-excursion
5242 (save-restriction
5243 (narrow-to-region (car begend) (point-max))
5244 (gnus-treat-article
5245 nil (length gnus-article-mime-handle-alist)
5246 (gnus-article-mime-total-parts)
5247 (mm-handle-media-type handle))))))
5248 (goto-char (point-max))
5249 (setcdr begend (point-marker)))))
5250 (when ibegend
5251 (goto-char point))))
5253 (defconst gnus-article-wash-status-strings
5254 (let ((alist '((cite "c" "Possible hidden citation text"
5255 " " "All citation text visible")
5256 (headers "h" "Hidden headers"
5257 " " "All headers visible.")
5258 (pgp "p" "Encrypted or signed message status hidden"
5259 " " "No hidden encryption nor digital signature status")
5260 (signature "s" "Signature has been hidden"
5261 " " "Signature is visible")
5262 (overstrike "o" "Overstrike (^H) characters applied"
5263 " " "No overstrike characters applied")
5264 (emphasis "e" "/*_Emphasis_*/ characters applied"
5265 " " "No /*_emphasis_*/ characters applied")))
5266 result)
5267 (dolist (entry alist result)
5268 (let ((key (nth 0 entry))
5269 (on (copy-sequence (nth 1 entry)))
5270 (on-help (nth 2 entry))
5271 (off (copy-sequence (nth 3 entry)))
5272 (off-help (nth 4 entry)))
5273 (put-text-property 0 1 'help-echo on-help on)
5274 (put-text-property 0 1 'help-echo off-help off)
5275 (push (list key on off) result))))
5276 "Alist of strings describing wash status in the mode line.
5277 Each entry has the form (KEY ON OF), where the KEY is a symbol
5278 representing the particular washing function, ON is the string to use
5279 in the article mode line when the washing function is active, and OFF
5280 is the string to use when it is inactive.")
5282 (defun gnus-article-wash-status-entry (key value)
5283 (let ((entry (assoc key gnus-article-wash-status-strings)))
5284 (if value (nth 1 entry) (nth 2 entry))))
5286 (defun gnus-article-wash-status ()
5287 "Return a string which display status of article washing."
5288 (save-excursion
5289 (set-buffer gnus-article-buffer)
5290 (let ((cite (memq 'cite gnus-article-wash-types))
5291 (headers (memq 'headers gnus-article-wash-types))
5292 (boring (memq 'boring-headers gnus-article-wash-types))
5293 (pgp (memq 'pgp gnus-article-wash-types))
5294 (pem (memq 'pem gnus-article-wash-types))
5295 (signed (memq 'signed gnus-article-wash-types))
5296 (encrypted (memq 'encrypted gnus-article-wash-types))
5297 (signature (memq 'signature gnus-article-wash-types))
5298 (overstrike (memq 'overstrike gnus-article-wash-types))
5299 (emphasis (memq 'emphasis gnus-article-wash-types)))
5300 (concat
5301 (gnus-article-wash-status-entry 'cite cite)
5302 (gnus-article-wash-status-entry 'headers (or headers boring))
5303 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5304 (gnus-article-wash-status-entry 'signature signature)
5305 (gnus-article-wash-status-entry 'overstrike overstrike)
5306 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5308 (defun gnus-add-wash-type (type)
5309 "Add a washing of TYPE to the current status."
5310 (add-to-list 'gnus-article-wash-types type))
5312 (defun gnus-delete-wash-type (type)
5313 "Add a washing of TYPE to the current status."
5314 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5316 (defun gnus-add-image (category image)
5317 "Add IMAGE of CATEGORY to the list of displayed images."
5318 (let ((entry (assq category gnus-article-image-alist)))
5319 (unless entry
5320 (setq entry (list category))
5321 (push entry gnus-article-image-alist))
5322 (nconc entry (list image))))
5324 (defun gnus-delete-images (category)
5325 "Delete all images in CATEGORY."
5326 (let ((entry (assq category gnus-article-image-alist)))
5327 (dolist (image (cdr entry))
5328 (gnus-remove-image image category))
5329 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5330 (gnus-delete-wash-type category)))
5332 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5334 (defun gnus-article-maybe-hide-headers ()
5335 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5336 Provided for backwards compatibility."
5337 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5338 (not (save-excursion (set-buffer gnus-summary-buffer)
5339 gnus-have-all-headers)))
5340 (not gnus-inhibit-hiding))
5341 (gnus-article-hide-headers)))
5343 ;;; Article savers.
5345 (defun gnus-output-to-file (file-name)
5346 "Append the current article to a file named FILE-NAME.
5347 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5348 text and used as the value of the coding cookie which is added to the
5349 top of a file. Otherwise, this function saves a raw article without
5350 the coding cookie."
5351 (let* ((artbuf (current-buffer))
5352 (file-name-coding-system nnmail-pathname-coding-system)
5353 (coding gnus-article-save-coding-system)
5354 (coding-system-for-read (if coding
5355 nil ;; Rely on the coding cookie.
5356 mm-text-coding-system))
5357 (coding-system-for-write (or coding
5358 mm-text-coding-system-for-write
5359 mm-text-coding-system))
5360 (exists (file-exists-p file-name)))
5361 (with-temp-buffer
5362 (when exists
5363 (insert-file-contents file-name)
5364 (goto-char (point-min))
5365 ;; Remove the existing coding cookie.
5366 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5367 (delete-region (match-beginning 0) (match-end 0))))
5368 (goto-char (point-max))
5369 (insert-buffer-substring artbuf)
5370 ;; Append newline at end of the buffer as separator, and then
5371 ;; save it to file.
5372 (goto-char (point-max))
5373 (insert "\n")
5374 (when coding
5375 ;; If the coding system is not suitable to encode the text,
5376 ;; ask a user for a proper one.
5377 (when (fboundp 'select-safe-coding-system)
5378 (setq coding (coding-system-base
5379 (save-window-excursion
5380 (select-safe-coding-system (point-min) (point-max)
5381 coding))))
5382 (setq coding-system-for-write
5383 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5384 coding)))
5385 (goto-char (point-min))
5386 ;; Add the coding cookie.
5387 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5388 coding-system-for-write)))
5389 (if exists
5390 (progn
5391 (write-region (point-min) (point-max) file-name nil 'no-message)
5392 (message "Appended to %s" file-name))
5393 (write-region (point-min) (point-max) file-name))))
5396 (defun gnus-narrow-to-page (&optional arg)
5397 "Narrow the article buffer to a page.
5398 If given a numerical ARG, move forward ARG pages."
5399 (interactive "P")
5400 (setq arg (if arg (prefix-numeric-value arg) 0))
5401 (save-excursion
5402 (set-buffer gnus-article-buffer)
5403 (goto-char (point-min))
5404 (widen)
5405 ;; Remove any old next/prev buttons.
5406 (when (gnus-visual-p 'page-marker)
5407 (let ((inhibit-read-only t))
5408 (gnus-remove-text-with-property 'gnus-prev)
5409 (gnus-remove-text-with-property 'gnus-next)))
5411 (cond ((< arg 0)
5412 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5413 ((> arg 0)
5414 (re-search-forward page-delimiter nil 'move arg)))
5415 (goto-char (match-end 0))
5416 (save-excursion
5417 (goto-char (point-min))
5418 (setq gnus-page-broken
5419 (and (re-search-forward page-delimiter nil t) t))))
5420 (when gnus-page-broken
5421 (narrow-to-region
5422 (point)
5423 (if (re-search-forward page-delimiter nil 'move)
5424 (match-beginning 0)
5425 (point)))
5426 (when (and (gnus-visual-p 'page-marker)
5427 (> (point-min) (save-restriction (widen) (point-min))))
5428 (save-excursion
5429 (goto-char (point-min))
5430 (gnus-insert-prev-page-button)))
5431 (when (and (gnus-visual-p 'page-marker)
5432 (< (point-max) (save-restriction (widen) (point-max))))
5433 (save-excursion
5434 (goto-char (point-max))
5435 (gnus-insert-next-page-button))))))
5437 ;; Article mode commands
5439 (defun gnus-article-goto-next-page ()
5440 "Show the next page of the article."
5441 (interactive)
5442 (when (gnus-article-next-page)
5443 (goto-char (point-min))
5444 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5447 (defun gnus-article-goto-prev-page ()
5448 "Show the previous page of the article."
5449 (interactive)
5450 (if (bobp)
5451 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5452 (gnus-article-prev-page nil)))
5454 ;; This is cleaner but currently breaks `gnus-pick-mode':
5456 ;; (defun gnus-article-goto-next-page ()
5457 ;; "Show the next page of the article."
5458 ;; (interactive)
5459 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5460 ;; (gnus-summary-next-page)))
5462 ;; (defun gnus-article-goto-prev-page ()
5463 ;; "Show the next page of the article."
5464 ;; (interactive)
5465 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5466 ;; (gnus-summary-prev-page)))
5468 (defun gnus-article-next-page (&optional lines)
5469 "Show the next page of the current article.
5470 If end of article, return non-nil. Otherwise return nil.
5471 Argument LINES specifies lines to be scrolled up."
5472 (interactive "p")
5473 (move-to-window-line -1)
5474 (if (save-excursion
5475 (end-of-line)
5476 (and (pos-visible-in-window-p) ;Not continuation line.
5477 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5478 ;; Nothing in this page.
5479 (if (or (not gnus-page-broken)
5480 (save-excursion
5481 (save-restriction
5482 (widen)
5483 (forward-line)
5484 (eobp)))) ;Real end-of-buffer?
5485 (progn
5486 (when gnus-article-over-scroll
5487 (gnus-article-next-page-1 lines))
5488 t) ;Nothing more.
5489 (gnus-narrow-to-page 1) ;Go to next page.
5490 nil)
5491 ;; More in this page.
5492 (gnus-article-next-page-1 lines)
5493 nil))
5495 (defmacro gnus-article-beginning-of-window ()
5496 "Move point to the beginning of the window.
5497 In Emacs, the point is placed at the line number which `scroll-margin'
5498 specifies."
5499 (if (featurep 'xemacs)
5500 '(move-to-window-line 0)
5501 '(move-to-window-line
5502 (min (max 0 scroll-margin)
5503 (max 1 (- (window-height)
5504 (if mode-line-format 1 0)
5505 (if (and (boundp 'header-line-format)
5506 (symbol-value 'header-line-format))
5507 1 0)))))))
5509 (defun gnus-article-next-page-1 (lines)
5510 (when (and (not (featurep 'xemacs))
5511 (numberp lines)
5512 (> lines 0)
5513 (numberp (symbol-value 'scroll-margin))
5514 (> (symbol-value 'scroll-margin) 0))
5515 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5516 ;; too many number of lines if `scroll-margin' is set as two or greater.
5517 (setq lines (min lines
5518 (max 0 (- (count-lines (window-start) (point-max))
5519 (symbol-value 'scroll-margin))))))
5520 (condition-case ()
5521 (let ((scroll-in-place nil))
5522 (scroll-up lines))
5523 (end-of-buffer
5524 ;; Long lines may cause an end-of-buffer error.
5525 (goto-char (point-max))))
5526 (gnus-article-beginning-of-window))
5528 (defun gnus-article-prev-page (&optional lines)
5529 "Show previous page of current article.
5530 Argument LINES specifies lines to be scrolled down."
5531 (interactive "p")
5532 (move-to-window-line 0)
5533 (if (and gnus-page-broken
5534 (bobp)
5535 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5536 (progn
5537 (gnus-narrow-to-page -1) ;Go to previous page.
5538 (goto-char (point-max))
5539 (recenter -1))
5540 (prog1
5541 (condition-case ()
5542 (let ((scroll-in-place nil))
5543 (scroll-down lines))
5544 (beginning-of-buffer
5545 (goto-char (point-min))))
5546 (gnus-article-beginning-of-window))))
5548 (defun gnus-article-only-boring-p ()
5549 "Decide whether there is only boring text remaining in the article.
5550 Something \"interesting\" is a word of at least two letters that does
5551 not have a face in `gnus-article-boring-faces'."
5552 (when (and gnus-article-skip-boring
5553 (boundp 'gnus-article-boring-faces)
5554 (symbol-value 'gnus-article-boring-faces))
5555 (save-excursion
5556 (let ((inhibit-point-motion-hooks t))
5557 (catch 'only-boring
5558 (while (re-search-forward "\\b\\w\\w" nil t)
5559 (forward-char -1)
5560 (when (not (gnus-intersection
5561 (gnus-faces-at (point))
5562 (symbol-value 'gnus-article-boring-faces)))
5563 (throw 'only-boring nil)))
5564 (throw 'only-boring t))))))
5566 (defun gnus-article-refer-article ()
5567 "Read article specified by message-id around point."
5568 (interactive)
5569 (save-excursion
5570 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5571 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5572 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5573 (let ((msg-id (concat "<" (match-string 0) ">")))
5574 (set-buffer gnus-summary-buffer)
5575 (gnus-summary-refer-article msg-id))
5576 (error "No references around point"))))
5578 (defun gnus-article-show-summary ()
5579 "Reconfigure windows to show summary buffer."
5580 (interactive)
5581 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5582 (error "There is no summary buffer for this article buffer")
5583 (gnus-article-set-globals)
5584 (gnus-configure-windows 'article)
5585 (gnus-summary-goto-subject gnus-current-article)
5586 (gnus-summary-position-point)))
5588 (defun gnus-article-describe-briefly ()
5589 "Describe article mode commands briefly."
5590 (interactive)
5591 (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")))
5593 (defun gnus-article-summary-command ()
5594 "Execute the last keystroke in the summary buffer."
5595 (interactive)
5596 (let ((obuf (current-buffer))
5597 (owin (current-window-configuration))
5598 func)
5599 (switch-to-buffer gnus-article-current-summary 'norecord)
5600 (setq func (lookup-key (current-local-map) (this-command-keys)))
5601 (call-interactively func)
5602 (set-buffer obuf)
5603 (set-window-configuration owin)
5604 (set-window-point (get-buffer-window (current-buffer)) (point))))
5606 (defun gnus-article-summary-command-nosave ()
5607 "Execute the last keystroke in the summary buffer."
5608 (interactive)
5609 (let (func)
5610 (pop-to-buffer gnus-article-current-summary)
5611 (setq func (lookup-key (current-local-map) (this-command-keys)))
5612 (call-interactively func)))
5614 (defun gnus-article-check-buffer ()
5615 "Beep if not in an article buffer."
5616 (unless (equal major-mode 'gnus-article-mode)
5617 (error "Command invoked outside of a Gnus article buffer")))
5619 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5620 "Read a summary buffer key sequence and execute it from the article buffer."
5621 (interactive "P")
5622 (gnus-article-check-buffer)
5623 (let ((nosaves
5624 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5625 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5626 "=" "^" "\M-^" "|"))
5627 (nosave-but-article
5628 '("A\r"))
5629 (nosave-in-article
5630 '("\C-d"))
5631 (up-to-top
5632 '("n" "Gn" "p" "Gp"))
5633 keys new-sum-point)
5634 (save-excursion
5635 (set-buffer gnus-article-current-summary)
5636 (let (gnus-pick-mode)
5637 (push (or key last-command-event) unread-command-events)
5638 (setq keys (if (featurep 'xemacs)
5639 (events-to-keys (read-key-sequence nil))
5640 (read-key-sequence nil)))))
5642 (message "")
5644 (if (or (member keys nosaves)
5645 (member keys nosave-but-article)
5646 (member keys nosave-in-article))
5647 (let (func)
5648 (save-window-excursion
5649 (pop-to-buffer gnus-article-current-summary)
5650 ;; We disable the pick minor mode commands.
5651 (let (gnus-pick-mode)
5652 (setq func (lookup-key (current-local-map) keys))))
5653 (if (or (not func)
5654 (numberp func))
5655 (ding)
5656 (unless (member keys nosave-in-article)
5657 (set-buffer gnus-article-current-summary))
5658 (call-interactively func)
5659 (setq new-sum-point (point)))
5660 (when (member keys nosave-but-article)
5661 (pop-to-buffer gnus-article-buffer)))
5662 ;; These commands should restore window configuration.
5663 (let ((obuf (current-buffer))
5664 (owin (current-window-configuration))
5665 (opoint (point))
5666 win func in-buffer selected new-sum-start new-sum-hscroll)
5667 (cond (not-restore-window
5668 (pop-to-buffer gnus-article-current-summary))
5669 ((setq win (get-buffer-window gnus-article-current-summary))
5670 (select-window win))
5672 (switch-to-buffer gnus-article-current-summary 'norecord)))
5673 (setq in-buffer (current-buffer))
5674 ;; We disable the pick minor mode commands.
5675 (if (and (setq func (let (gnus-pick-mode)
5676 (lookup-key (current-local-map) keys)))
5677 (functionp func))
5678 (progn
5679 (call-interactively func)
5680 (when (eq win (selected-window))
5681 (setq new-sum-point (point)
5682 new-sum-start (window-start win)
5683 new-sum-hscroll (window-hscroll win)))
5684 (when (eq in-buffer (current-buffer))
5685 (setq selected (gnus-summary-select-article))
5686 (set-buffer obuf)
5687 (unless not-restore-window
5688 (set-window-configuration owin))
5689 (when (eq selected 'old)
5690 (article-goto-body)
5691 (set-window-start (get-buffer-window (current-buffer))
5693 (set-window-point (get-buffer-window (current-buffer))
5694 (point)))
5695 (when (and (not not-restore-window)
5696 new-sum-point)
5697 (set-window-point win new-sum-point)
5698 (set-window-start win new-sum-start)
5699 (set-window-hscroll win new-sum-hscroll))))
5700 (set-window-configuration owin)
5701 (ding))))))
5703 (defun gnus-article-describe-key (key)
5704 "Display documentation of the function invoked by KEY. KEY is a string."
5705 (interactive "kDescribe key: ")
5706 (gnus-article-check-buffer)
5707 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5708 (save-excursion
5709 (set-buffer gnus-article-current-summary)
5710 (let (gnus-pick-mode)
5711 (if (featurep 'xemacs)
5712 (progn
5713 (push (elt key 0) unread-command-events)
5714 (setq key (events-to-keys
5715 (read-key-sequence "Describe key: "))))
5716 (setq unread-command-events
5717 (mapcar
5718 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5719 (string-to-list key)))
5720 (setq key (read-key-sequence "Describe key: "))))
5721 (describe-key key))
5722 (describe-key key)))
5724 (defun gnus-article-describe-key-briefly (key &optional insert)
5725 "Display documentation of the function invoked by KEY. KEY is a string."
5726 (interactive "kDescribe key: \nP")
5727 (gnus-article-check-buffer)
5728 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5729 (save-excursion
5730 (set-buffer gnus-article-current-summary)
5731 (let (gnus-pick-mode)
5732 (if (featurep 'xemacs)
5733 (progn
5734 (push (elt key 0) unread-command-events)
5735 (setq key (events-to-keys
5736 (read-key-sequence "Describe key: "))))
5737 (setq unread-command-events
5738 (mapcar
5739 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5740 (string-to-list key)))
5741 (setq key (read-key-sequence "Describe key: "))))
5742 (describe-key-briefly key insert))
5743 (describe-key-briefly key insert)))
5745 (defun gnus-article-reply-with-original (&optional wide)
5746 "Start composing a reply mail to the current message.
5747 The text in the region will be yanked. If the region isn't active,
5748 the entire article will be yanked."
5749 (interactive "P")
5750 (let ((article (cdr gnus-article-current))
5751 contents)
5752 (if (not (gnus-mark-active-p))
5753 (with-current-buffer gnus-summary-buffer
5754 (gnus-summary-reply (list (list article)) wide))
5755 (setq contents (buffer-substring (point) (mark t)))
5756 ;; Deactivate active regions.
5757 (when (and (boundp 'transient-mark-mode)
5758 transient-mark-mode)
5759 (setq mark-active nil))
5760 (with-current-buffer gnus-summary-buffer
5761 (gnus-summary-reply
5762 (list (list article contents)) wide)))))
5764 (defun gnus-article-followup-with-original ()
5765 "Compose a followup to the current article.
5766 The text in the region will be yanked. If the region isn't active,
5767 the entire article will be yanked."
5768 (interactive)
5769 (let ((article (cdr gnus-article-current))
5770 contents)
5771 (if (not (gnus-mark-active-p))
5772 (with-current-buffer gnus-summary-buffer
5773 (gnus-summary-followup (list (list article))))
5774 (setq contents (buffer-substring (point) (mark t)))
5775 ;; Deactivate active regions.
5776 (when (and (boundp 'transient-mark-mode)
5777 transient-mark-mode)
5778 (setq mark-active nil))
5779 (with-current-buffer gnus-summary-buffer
5780 (gnus-summary-followup
5781 (list (list article contents)))))))
5783 (defun gnus-article-hide (&optional arg force)
5784 "Hide all the gruft in the current article.
5785 This means that signatures, cited text and (some) headers will be
5786 hidden.
5787 If given a prefix, show the hidden text instead."
5788 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5789 (gnus-article-hide-headers arg)
5790 (gnus-article-hide-list-identifiers arg)
5791 (gnus-article-hide-citation-maybe arg force)
5792 (gnus-article-hide-signature arg))
5794 (defun gnus-article-maybe-highlight ()
5795 "Do some article highlighting if article highlighting is requested."
5796 (when (gnus-visual-p 'article-highlight 'highlight)
5797 (gnus-article-highlight-some)))
5799 (defun gnus-check-group-server ()
5800 ;; Make sure the connection to the server is alive.
5801 (unless (gnus-server-opened
5802 (gnus-find-method-for-group gnus-newsgroup-name))
5803 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5804 (gnus-request-group gnus-newsgroup-name t)))
5806 (eval-when-compile
5807 (autoload 'nneething-get-file-name "nneething"))
5809 (defun gnus-request-article-this-buffer (article group)
5810 "Get an article and insert it into this buffer."
5811 (let (do-update-line sparse-header)
5812 (prog1
5813 (save-excursion
5814 (erase-buffer)
5815 (gnus-kill-all-overlays)
5816 (setq group (or group gnus-newsgroup-name))
5818 ;; Using `gnus-request-article' directly will insert the article into
5819 ;; `nntp-server-buffer' - so we'll save some time by not having to
5820 ;; copy it from the server buffer into the article buffer.
5822 ;; We only request an article by message-id when we do not have the
5823 ;; headers for it, so we'll have to get those.
5824 (when (stringp article)
5825 (gnus-read-header article))
5827 ;; If the article number is negative, that means that this article
5828 ;; doesn't belong in this newsgroup (possibly), so we find its
5829 ;; message-id and request it by id instead of number.
5830 (when (and (numberp article)
5831 gnus-summary-buffer
5832 (get-buffer gnus-summary-buffer)
5833 (gnus-buffer-exists-p gnus-summary-buffer))
5834 (save-excursion
5835 (set-buffer gnus-summary-buffer)
5836 (let ((header (gnus-summary-article-header article)))
5837 (when (< article 0)
5838 (cond
5839 ((memq article gnus-newsgroup-sparse)
5840 ;; This is a sparse gap article.
5841 (setq do-update-line article)
5842 (setq article (mail-header-id header))
5843 (setq sparse-header (gnus-read-header article))
5844 (setq gnus-newsgroup-sparse
5845 (delq article gnus-newsgroup-sparse)))
5846 ((vectorp header)
5847 ;; It's a real article.
5848 (setq article (mail-header-id header)))
5850 ;; It is an extracted pseudo-article.
5851 (setq article 'pseudo)
5852 (gnus-request-pseudo-article header))))
5854 (let ((method (gnus-find-method-for-group
5855 gnus-newsgroup-name)))
5856 (when (and (eq (car method) 'nneething)
5857 (vectorp header))
5858 (let ((dir (nneething-get-file-name
5859 (mail-header-id header))))
5860 (when (and (stringp dir)
5861 (file-directory-p dir))
5862 (setq article 'nneething)
5863 (gnus-group-enter-directory dir))))))))
5865 (cond
5866 ;; Refuse to select canceled articles.
5867 ((and (numberp article)
5868 gnus-summary-buffer
5869 (get-buffer gnus-summary-buffer)
5870 (gnus-buffer-exists-p gnus-summary-buffer)
5871 (eq (cdr (save-excursion
5872 (set-buffer gnus-summary-buffer)
5873 (assq article gnus-newsgroup-reads)))
5874 gnus-canceled-mark))
5875 nil)
5876 ;; We first check `gnus-original-article-buffer'.
5877 ((and (get-buffer gnus-original-article-buffer)
5878 (numberp article)
5879 (save-excursion
5880 (set-buffer gnus-original-article-buffer)
5881 (and (equal (car gnus-original-article) group)
5882 (eq (cdr gnus-original-article) article))))
5883 (insert-buffer-substring gnus-original-article-buffer)
5884 'article)
5885 ;; Check the backlog.
5886 ((and gnus-keep-backlog
5887 (gnus-backlog-request-article group article (current-buffer)))
5888 'article)
5889 ;; Check asynchronous pre-fetch.
5890 ((gnus-async-request-fetched-article group article (current-buffer))
5891 (gnus-async-prefetch-next group article gnus-summary-buffer)
5892 (when (and (numberp article) gnus-keep-backlog)
5893 (gnus-backlog-enter-article group article (current-buffer)))
5894 'article)
5895 ;; Check the cache.
5896 ((and gnus-use-cache
5897 (numberp article)
5898 (gnus-cache-request-article article group))
5899 'article)
5900 ;; Check the agent cache.
5901 ((gnus-agent-request-article article group)
5902 'article)
5903 ;; Get the article and put into the article buffer.
5904 ((or (stringp article)
5905 (numberp article))
5906 (let ((gnus-override-method gnus-override-method)
5907 (methods (and (stringp article)
5908 gnus-refer-article-method))
5909 (backend (car (gnus-find-method-for-group
5910 gnus-newsgroup-name)))
5911 result
5912 (inhibit-read-only t))
5913 (if (or (not (listp methods))
5914 (and (symbolp (car methods))
5915 (assq (car methods) nnoo-definition-alist)))
5916 (setq methods (list methods)))
5917 (when (and (null gnus-override-method)
5918 methods)
5919 (setq gnus-override-method (pop methods)))
5920 (while (not result)
5921 (when (eq gnus-override-method 'current)
5922 (setq gnus-override-method
5923 (with-current-buffer gnus-summary-buffer
5924 gnus-current-select-method)))
5925 (erase-buffer)
5926 (gnus-kill-all-overlays)
5927 (let ((gnus-newsgroup-name group))
5928 (gnus-check-group-server))
5929 (cond
5930 ((gnus-request-article article group (current-buffer))
5931 (when (numberp article)
5932 (gnus-async-prefetch-next group article
5933 gnus-summary-buffer)
5934 (when gnus-keep-backlog
5935 (gnus-backlog-enter-article
5936 group article (current-buffer))))
5937 (setq result 'article))
5938 (methods
5939 (setq gnus-override-method (pop methods)))
5940 ((not (string-match "^400 "
5941 (nnheader-get-report backend)))
5942 ;; If we get 400 server disconnect, reconnect and
5943 ;; retry; otherwise, assume the article has expired.
5944 (setq result 'done))))
5945 (and (eq result 'article) 'article)))
5946 ;; It was a pseudo.
5947 (t article)))
5949 ;; Associate this article with the current summary buffer.
5950 (setq gnus-article-current-summary gnus-summary-buffer)
5952 ;; Take the article from the original article buffer
5953 ;; and place it in the buffer it's supposed to be in.
5954 (when (and (get-buffer gnus-article-buffer)
5955 (equal (buffer-name (current-buffer))
5956 (buffer-name (get-buffer gnus-article-buffer))))
5957 (save-excursion
5958 (if (get-buffer gnus-original-article-buffer)
5959 (set-buffer gnus-original-article-buffer)
5960 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5961 (buffer-disable-undo)
5962 (setq major-mode 'gnus-original-article-mode)
5963 (setq buffer-read-only t))
5964 (let ((inhibit-read-only t))
5965 (erase-buffer)
5966 (insert-buffer-substring gnus-article-buffer))
5967 (setq gnus-original-article (cons group article)))
5969 ;; Decode charsets.
5970 (run-hooks 'gnus-article-decode-hook)
5971 ;; Mark article as decoded or not.
5972 (setq gnus-article-decoded-p gnus-article-decode-hook))
5974 ;; Update sparse articles.
5975 (when (and do-update-line
5976 (or (numberp article)
5977 (stringp article)))
5978 (let ((buf (current-buffer)))
5979 (set-buffer gnus-summary-buffer)
5980 (gnus-summary-update-article do-update-line sparse-header)
5981 (gnus-summary-goto-subject do-update-line nil t)
5982 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5983 (point))
5984 (set-buffer buf))))))
5987 ;;; Article editing
5990 (defcustom gnus-article-edit-mode-hook nil
5991 "Hook run in article edit mode buffers."
5992 :group 'gnus-article-various
5993 :type 'hook)
5995 (defvar gnus-article-edit-done-function nil)
5997 (defvar gnus-article-edit-mode-map nil)
5998 (defvar gnus-article-edit-mode nil)
6000 ;; Should we be using derived.el for this?
6001 (unless gnus-article-edit-mode-map
6002 (setq gnus-article-edit-mode-map (make-keymap))
6003 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6005 (gnus-define-keys gnus-article-edit-mode-map
6006 "\C-c?" describe-mode
6007 "\C-c\C-c" gnus-article-edit-done
6008 "\C-c\C-k" gnus-article-edit-exit
6009 "\C-c\C-f\C-t" message-goto-to
6010 "\C-c\C-f\C-o" message-goto-from
6011 "\C-c\C-f\C-b" message-goto-bcc
6012 ;;"\C-c\C-f\C-w" message-goto-fcc
6013 "\C-c\C-f\C-c" message-goto-cc
6014 "\C-c\C-f\C-s" message-goto-subject
6015 "\C-c\C-f\C-r" message-goto-reply-to
6016 "\C-c\C-f\C-n" message-goto-newsgroups
6017 "\C-c\C-f\C-d" message-goto-distribution
6018 "\C-c\C-f\C-f" message-goto-followup-to
6019 "\C-c\C-f\C-m" message-goto-mail-followup-to
6020 "\C-c\C-f\C-k" message-goto-keywords
6021 "\C-c\C-f\C-u" message-goto-summary
6022 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6023 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6024 "\C-c\C-b" message-goto-body
6025 "\C-c\C-i" message-goto-signature
6027 "\C-c\C-t" message-insert-to
6028 "\C-c\C-n" message-insert-newsgroups
6029 "\C-c\C-o" message-sort-headers
6030 "\C-c\C-e" message-elide-region
6031 "\C-c\C-v" message-delete-not-region
6032 "\C-c\C-z" message-kill-to-signature
6033 "\M-\r" message-newline-and-reformat
6034 "\C-c\C-a" mml-attach-file
6035 "\C-a" message-beginning-of-line
6036 "\t" message-tab
6037 "\M-;" comment-region)
6039 (gnus-define-keys (gnus-article-edit-wash-map
6040 "\C-c\C-w" gnus-article-edit-mode-map)
6041 "f" gnus-article-edit-full-stops))
6043 (easy-menu-define
6044 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6045 '("Field"
6046 ["Fetch To" message-insert-to t]
6047 ["Fetch Newsgroups" message-insert-newsgroups t]
6048 "----"
6049 ["To" message-goto-to t]
6050 ["From" message-goto-from t]
6051 ["Subject" message-goto-subject t]
6052 ["Cc" message-goto-cc t]
6053 ["Reply-To" message-goto-reply-to t]
6054 ["Summary" message-goto-summary t]
6055 ["Keywords" message-goto-keywords t]
6056 ["Newsgroups" message-goto-newsgroups t]
6057 ["Followup-To" message-goto-followup-to t]
6058 ["Mail-Followup-To" message-goto-mail-followup-to t]
6059 ["Distribution" message-goto-distribution t]
6060 ["Body" message-goto-body t]
6061 ["Signature" message-goto-signature t]))
6063 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6064 "Major mode for editing articles.
6065 This is an extended text-mode.
6067 \\{gnus-article-edit-mode-map}"
6068 (make-local-variable 'gnus-article-edit-done-function)
6069 (make-local-variable 'gnus-prev-winconf)
6070 (set (make-local-variable 'font-lock-defaults)
6071 '(message-font-lock-keywords t))
6072 (set (make-local-variable 'mail-header-separator) "")
6073 (set (make-local-variable 'gnus-article-edit-mode) t)
6074 (easy-menu-add message-mode-field-menu message-mode-map)
6075 (mml-mode)
6076 (setq buffer-read-only nil)
6077 (buffer-enable-undo)
6078 (widen))
6080 (defun gnus-article-edit (&optional force)
6081 "Edit the current article.
6082 This will have permanent effect only in mail groups.
6083 If FORCE is non-nil, allow editing of articles even in read-only
6084 groups."
6085 (interactive "P")
6086 (when (and (not force)
6087 (gnus-group-read-only-p))
6088 (error "The current newsgroup does not support article editing"))
6089 (gnus-article-date-original)
6090 (gnus-article-edit-article
6091 'ignore
6092 `(lambda (no-highlight)
6093 'ignore
6094 (gnus-summary-edit-article-done
6095 ,(or (mail-header-references gnus-current-headers) "")
6096 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6098 (defun gnus-article-edit-article (start-func exit-func)
6099 "Start editing the contents of the current article buffer."
6100 (let ((winconf (current-window-configuration)))
6101 (set-buffer gnus-article-buffer)
6102 (let ((message-auto-save-directory
6103 ;; Don't associate the article buffer with a draft file.
6104 nil))
6105 (gnus-article-edit-mode))
6106 (funcall start-func)
6107 (set-buffer-modified-p nil)
6108 (gnus-configure-windows 'edit-article)
6109 (setq gnus-article-edit-done-function exit-func)
6110 (setq gnus-prev-winconf winconf)
6111 (gnus-message 6 "C-c C-c to end edits")))
6113 (defun gnus-article-edit-done (&optional arg)
6114 "Update the article edits and exit."
6115 (interactive "P")
6116 (let ((func gnus-article-edit-done-function)
6117 (buf (current-buffer))
6118 (start (window-start))
6119 (p (point))
6120 (winconf gnus-prev-winconf))
6121 (widen) ;; Widen it in case that users narrowed the buffer.
6122 (funcall func arg)
6123 (set-buffer buf)
6124 ;; The cache and backlog have to be flushed somewhat.
6125 (when gnus-keep-backlog
6126 (gnus-backlog-remove-article
6127 (car gnus-article-current) (cdr gnus-article-current)))
6128 ;; Flush original article as well.
6129 (save-excursion
6130 (when (get-buffer gnus-original-article-buffer)
6131 (set-buffer gnus-original-article-buffer)
6132 (setq gnus-original-article nil)))
6133 (when gnus-use-cache
6134 (gnus-cache-update-article
6135 (car gnus-article-current) (cdr gnus-article-current)))
6136 ;; We remove all text props from the article buffer.
6137 (kill-all-local-variables)
6138 (gnus-set-text-properties (point-min) (point-max) nil)
6139 (gnus-article-mode)
6140 (set-window-configuration winconf)
6141 (set-buffer buf)
6142 (set-window-start (get-buffer-window buf) start)
6143 (set-window-point (get-buffer-window buf) (point)))
6144 (gnus-summary-show-article))
6146 (defun gnus-article-edit-exit ()
6147 "Exit the article editing without updating."
6148 (interactive)
6149 (when (or (not (buffer-modified-p))
6150 (yes-or-no-p "Article modified; kill anyway? "))
6151 (let ((curbuf (current-buffer))
6152 (p (point))
6153 (window-start (window-start)))
6154 (erase-buffer)
6155 (if (gnus-buffer-live-p gnus-original-article-buffer)
6156 (insert-buffer-substring gnus-original-article-buffer))
6157 (let ((winconf gnus-prev-winconf))
6158 (kill-all-local-variables)
6159 (gnus-article-mode)
6160 (set-window-configuration winconf)
6161 ;; Tippy-toe some to make sure that point remains where it was.
6162 (save-current-buffer
6163 (set-buffer curbuf)
6164 (set-window-start (get-buffer-window (current-buffer)) window-start)
6165 (goto-char p))))
6166 (gnus-summary-show-article)))
6168 (defun gnus-article-edit-full-stops ()
6169 "Interactively repair spacing at end of sentences."
6170 (interactive)
6171 (save-excursion
6172 (goto-char (point-min))
6173 (search-forward-regexp "^$" nil t)
6174 (let ((case-fold-search nil))
6175 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6178 ;;; Article highlights
6181 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6183 ;;; Internal Variables:
6185 (defcustom gnus-button-url-regexp
6186 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6187 "\\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:]]\\)"
6188 "\\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\\)\\)")
6189 "Regular expression that matches URLs."
6190 :group 'gnus-article-buttons
6191 :type 'regexp)
6193 (defcustom gnus-button-valid-fqdn-regexp
6194 message-valid-fqdn-regexp
6195 "Regular expression that matches a valid FQDN."
6196 :version "22.1"
6197 :group 'gnus-article-buttons
6198 :type 'regexp)
6200 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6201 (defcustom gnus-button-valid-localpart-regexp
6202 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6203 "Regular expression that matches a localpart of mail addresses or MIDs."
6204 :version "22.1"
6205 :group 'gnus-article-buttons
6206 :type 'regexp)
6208 (defcustom gnus-button-man-handler 'manual-entry
6209 "Function to use for displaying man pages.
6210 The function must take at least one argument with a string naming the
6211 man page."
6212 :version "22.1"
6213 :type '(choice (function-item :tag "Man" manual-entry)
6214 (function-item :tag "Woman" woman)
6215 (function :tag "Other"))
6216 :group 'gnus-article-buttons)
6218 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6219 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6220 If the default site is too slow, try to find a CTAN mirror, see
6221 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6222 the variable `gnus-button-handle-ctan'."
6223 :version "22.1"
6224 :group 'gnus-article-buttons
6225 :link '(custom-manual "(gnus)Group Parameters")
6226 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6227 (const "http://tug.ctan.org/tex-archive/")
6228 (const "http://www.dante.de/CTAN/")
6229 (string :tag "Other")))
6231 (defcustom gnus-button-ctan-handler 'browse-url
6232 "Function to use for displaying CTAN links.
6233 The function must take one argument, the string naming the URL."
6234 :version "22.1"
6235 :type '(choice (function-item :tag "Browse Url" browse-url)
6236 (function :tag "Other"))
6237 :group 'gnus-article-buttons)
6239 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6240 "Bogus strings removed from CTAN URLs."
6241 :version "22.1"
6242 :group 'gnus-article-buttons
6243 :type '(choice (const "^/?tex-archive/\\|/")
6244 (regexp :tag "Other")))
6246 (defcustom gnus-button-ctan-directory-regexp
6247 (regexp-opt
6248 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6249 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6250 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6251 "tds" "tools" "usergrps" "web") t)
6252 "Regular expression for ctan directories.
6253 It should match all directories in the top level of `gnus-ctan-url'."
6254 :version "22.1"
6255 :group 'gnus-article-buttons
6256 :type 'regexp)
6258 (defcustom gnus-button-mid-or-mail-regexp
6259 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6260 gnus-button-valid-fqdn-regexp
6261 ">?\\)\\b")
6262 "Regular expression that matches a message ID or a mail address."
6263 :version "22.1"
6264 :group 'gnus-article-buttons
6265 :type 'regexp)
6267 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6268 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6269 Strings like this can be either a message ID or a mail address. If it is one
6270 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6271 message ID or a mail address, respectively. If this variable is set to the
6272 symbol `ask', always query the user what do do. If it is a function, this
6273 function will be called with the string as its only argument. The function
6274 must return `mid', `mail', `invalid' or `ask'."
6275 :version "22.1"
6276 :group 'gnus-article-buttons
6277 :type '(choice (function-item :tag "Heuristic function"
6278 gnus-button-mid-or-mail-heuristic)
6279 (const ask)
6280 (const mid)
6281 (const mail)))
6283 (defcustom gnus-button-mid-or-mail-heuristic-alist
6284 '((-10.0 . ".+\\$.+@")
6285 (-10.0 . "#")
6286 (-10.0 . "\\*")
6287 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6288 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6289 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6290 (-1.0 . "^[^a-z]+@")
6292 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6293 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6294 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6295 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6297 (-2.0 . "^[0-9]")
6298 (-1.0 . "^[0-9][0-9]")
6300 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6301 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6302 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6303 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6305 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6306 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6307 ;; "[0-9]{8,}.*\@"
6308 (-3.0
6309 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6310 ;; "[0-9]{12,}.*\@"
6311 ;; compensation for TDMA dated mail addresses:
6312 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6314 (-20.0 . "\\.fsf@") ;; Gnus
6315 (-20.0 . "^slrn")
6316 (-20.0 . "^Pine")
6317 (-20.0 . "_-_") ;; Subject change in thread
6319 (-20.0 . "\\.ln@") ;; leafnode
6320 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6321 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6323 ;; (5.0 . "") ;; $local_part_len <= 7
6324 (10.0 . "^[^0-9]+@")
6325 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6326 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6327 (3.0 . "\@stud")
6329 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6331 (0.5 . "^[A-Z][a-z]")
6332 (0.5 . "^[A-Z][a-z][a-z]")
6333 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6334 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6335 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6337 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6338 address. The REGEXP is processed with `case-fold-search' set to nil."
6339 :version "22.1"
6340 :group 'gnus-article-buttons
6341 :type '(repeat (cons (number :tag "Rate")
6342 (regexp :tag "Regexp"))))
6344 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6345 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6346 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6347 address, `ask' if unsure and `invalid' if the string is invalid."
6348 (let ((case-fold-search nil)
6349 (list gnus-button-mid-or-mail-heuristic-alist)
6350 (result 0) rate regexp lpartlen elem)
6351 (setq lpartlen
6352 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6353 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6354 ;; Certain special cases...
6355 (when (string-match
6356 (concat
6357 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6358 "^[0-9]+\\.[0-9]+@compuserve\\|"
6359 "@public\\.gmane\\.org")
6360 mid-or-mail)
6361 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6362 (setq result 'mail))
6363 (when (string-match "@.*@\\| " mid-or-mail)
6364 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6365 (setq result 'invalid))
6366 ;; Nothing more to do, if result is not a number here...
6367 (when (numberp result)
6368 (while list
6369 (setq elem (car list)
6370 rate (car elem)
6371 regexp (cdr elem)
6372 list (cdr list))
6373 (when (string-match regexp mid-or-mail)
6374 (setq result (+ result rate))
6375 (gnus-message
6376 9 "`%s' matched `%s', rate `%s', result `%s'."
6377 mid-or-mail regexp rate result)))
6378 (when (<= lpartlen 7)
6379 (setq result (+ result 5.0))
6380 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6381 mid-or-mail result))
6382 (when (>= lpartlen 12)
6383 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6384 (cond
6385 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6386 ;; Long local part should contain realname if e-mail address,
6387 ;; too many digits: message-id.
6388 ;; $score -= 5.0 + 0.1 * $local_part_len;
6389 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6390 (setq result (+ result rate))
6391 (gnus-message
6392 9 "Many digits in `%s', rate `%s', result `%s'."
6393 mid-or-mail rate result))
6394 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6395 mid-or-mail)
6396 ;; Too few vowels [^aeiouy]{4,}.*\@
6397 (setq result (+ result -5.0))
6398 (gnus-message
6399 9 "Few vowels in `%s', rate `%s', result `%s'."
6400 mid-or-mail -5.0 result))
6402 (setq result (+ result 5.0))
6403 (gnus-message
6404 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6405 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6406 ;; Maybe we should make this a customizable alist: (condition . 'result)
6407 (cond
6408 ((symbolp result) result)
6409 ;; Now convert number into proper results:
6410 ((< result -10.0) 'mid)
6411 ((> result 10.0) 'mail)
6412 (t 'ask))))
6414 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6415 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6416 (url-mid (concat "news" ":" mid-or-mail))
6417 (url-mailto (concat "mailto" ":" mid-or-mail)))
6418 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6419 (when (fboundp pref)
6420 (setq guessed
6421 ;; get rid of surrounding angles...
6422 (funcall pref
6423 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6424 (if (or (eq 'mid guessed) (eq 'mail guessed))
6425 (setq pref guessed)
6426 (setq pref 'ask)))
6427 (if (eq pref 'ask)
6428 (save-window-excursion
6429 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6430 (setq pref 'mail)
6431 (setq pref 'mid))))
6432 (cond ((eq pref 'mid)
6433 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6434 (gnus-button-handle-news url-mid))
6435 ((eq pref 'mail)
6436 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6437 (gnus-url-mailto url-mailto))
6438 (t (gnus-message 3 "Invalid string.")))))
6440 (defun gnus-button-handle-custom (url)
6441 "Follow a Custom URL."
6442 (customize-apropos (gnus-url-unhex-string url)))
6444 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6446 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6447 ;; stuff?
6449 (defun gnus-button-handle-describe-function (url)
6450 "Call `describe-function' when pushing the corresponding URL button."
6451 (describe-function
6452 (intern
6453 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6455 (defun gnus-button-handle-describe-variable (url)
6456 "Call `describe-variable' when pushing the corresponding URL button."
6457 (describe-variable
6458 (intern
6459 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6461 (defun gnus-button-handle-symbol (url)
6462 "Display help on variable or function.
6463 Calls `describe-variable' or `describe-function'."
6464 (let ((sym (intern url)))
6465 (cond
6466 ((fboundp sym) (describe-function sym))
6467 ((boundp sym) (describe-variable sym))
6468 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6470 (defun gnus-button-handle-describe-key (url)
6471 "Call `describe-key' when pushing the corresponding URL button."
6472 (let* ((key-string
6473 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6474 (keys (ignore-errors (eval `(kbd ,key-string)))))
6475 (if keys
6476 (describe-key keys)
6477 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6479 (defun gnus-button-handle-apropos (url)
6480 "Call `apropos' when pushing the corresponding URL button."
6481 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6483 (defun gnus-button-handle-apropos-command (url)
6484 "Call `apropos' when pushing the corresponding URL button."
6485 (apropos-command
6486 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6488 (defun gnus-button-handle-apropos-variable (url)
6489 "Call `apropos' when pushing the corresponding URL button."
6490 (funcall
6491 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6492 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6494 (defun gnus-button-handle-apropos-documentation (url)
6495 "Call `apropos' when pushing the corresponding URL button."
6496 (funcall
6497 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6498 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6500 (defun gnus-button-handle-library (url)
6501 "Call `locate-library' when pushing the corresponding URL button."
6502 (gnus-message 9 "url=`%s'" url)
6503 (let* ((lib (locate-library url))
6504 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6505 (if (not lib)
6506 (gnus-message 1 "Cannot locale library `%s'." url)
6507 (find-file-read-only file))))
6509 (defun gnus-button-handle-ctan (url)
6510 "Call `browse-url' when pushing a CTAN URL button."
6511 (funcall
6512 gnus-button-ctan-handler
6513 (concat
6514 gnus-ctan-url
6515 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6517 (defcustom gnus-button-tex-level 5
6518 "*Integer that says how many TeX-related buttons Gnus will show.
6519 The higher the number, the more buttons will appear and the more false
6520 positives are possible. Note that you can set this variable local to
6521 specific groups. Setting it higher in TeX groups is probably a good idea.
6522 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6523 how to set variables in specific groups."
6524 :version "22.1"
6525 :group 'gnus-article-buttons
6526 :link '(custom-manual "(gnus)Group Parameters")
6527 :type 'integer)
6529 (defcustom gnus-button-man-level 5
6530 "*Integer that says how many man-related buttons Gnus will show.
6531 The higher the number, the more buttons will appear and the more false
6532 positives are possible. Note that you can set this variable local to
6533 specific groups. Setting it higher in Unix groups is probably a good idea.
6534 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6535 how to set variables in specific groups."
6536 :version "22.1"
6537 :group 'gnus-article-buttons
6538 :link '(custom-manual "(gnus)Group Parameters")
6539 :type 'integer)
6541 (defcustom gnus-button-emacs-level 5
6542 "*Integer that says how many emacs-related buttons Gnus will show.
6543 The higher the number, the more buttons will appear and the more false
6544 positives are possible. Note that you can set this variable local to
6545 specific groups. Setting it higher in Emacs or Gnus related groups is
6546 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6547 `gnus-parameters' on how to set variables in specific groups."
6548 :version "22.1"
6549 :group 'gnus-article-buttons
6550 :link '(custom-manual "(gnus)Group Parameters")
6551 :type 'integer)
6553 (defcustom gnus-button-message-level 5
6554 "*Integer that says how many buttons for news or mail messages will appear.
6555 The higher the number, the more buttons will appear and the more false
6556 positives are possible."
6557 ;; mail addresses, MIDs, URLs for news, ...
6558 :version "22.1"
6559 :group 'gnus-article-buttons
6560 :type 'integer)
6562 (defcustom gnus-button-browse-level 5
6563 "*Integer that says how many buttons for browsing will appear.
6564 The higher the number, the more buttons will appear and the more false
6565 positives are possible."
6566 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6567 :version "22.1"
6568 :group 'gnus-article-buttons
6569 :type 'integer)
6571 (defcustom gnus-button-alist
6572 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6573 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6574 ((concat "\\b\\(nntp\\|news\\):\\("
6575 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6576 0 t gnus-button-handle-news 2)
6577 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6578 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6579 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6580 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6581 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6582 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6583 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6584 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6585 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6586 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6587 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6588 ;; RFC 2368 (The mailto URL scheme)
6589 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6590 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6591 ("\\bmailto:\\([^ \n\t]+\\)"
6592 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6593 ;; CTAN
6594 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6595 gnus-button-ctan-directory-regexp
6596 "[^][>)!;:,'\n\t ]+\\)")
6597 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6598 ((concat "\\btex-archive/\\("
6599 gnus-button-ctan-directory-regexp
6600 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6601 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6602 ((concat
6603 "\\b\\("
6604 gnus-button-ctan-directory-regexp
6605 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6606 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6607 ;; This is info (home-grown style) <info://foo/bar+baz>
6608 ("\\binfo://\\([^'\">\n\t ]+\\)"
6609 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6610 ;; Info GNOME style <info:foo#bar_baz>
6611 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6612 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6613 ;; Info KDE style <info:(foo)bar baz>
6614 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6615 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6616 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6617 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6618 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6619 ;; Info links like `C-h i d m CC Mode RET'
6620 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6621 ;; This is custom
6622 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6623 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6624 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6625 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6626 ;; Emacs help commands
6627 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6628 ;; regexp doesn't match arguments containing ` '.
6629 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6630 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6631 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6632 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6633 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6634 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6635 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6636 ;; The following entries may lead to many false positives so don't enable
6637 ;; them by default (use a high button level).
6638 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6639 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6640 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6641 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6642 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6643 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6644 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6645 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6646 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6647 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6648 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6649 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6650 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6651 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6652 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6653 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6654 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6655 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6656 ;; Unlike the other regexps we really have to require quoting
6657 ;; here to determine where it ends.
6658 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6659 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6660 ("<URL: *\\([^<>]*\\)>"
6661 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6662 ;; RFC 2396 (2.4.3., delims) ...
6663 ("\"URL: *\\([^\"]*\\)\""
6664 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6665 ;; RFC 2396 (2.4.3., delims) ...
6666 ("\"URL: *\\([^\"]*\\)\""
6667 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6668 ;; Raw URLs.
6669 (gnus-button-url-regexp
6670 0 (>= gnus-button-browse-level 0) browse-url 0)
6671 ;; man pages
6672 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6673 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6674 gnus-button-handle-man 1)
6675 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6676 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6677 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6678 gnus-button-handle-man 1)
6679 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6680 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6681 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6682 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6683 ;; MID or mail: To avoid too many false positives we don't try to catch
6684 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6685 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6686 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6687 ;; so that non-ambiguous entries (see above) match first.
6688 (gnus-button-mid-or-mail-regexp
6689 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6690 "*Alist of regexps matching buttons in article bodies.
6692 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6693 REGEXP: is the string (case insensitive) matching text around the button (can
6694 also be Lisp expression evaluating to a string),
6695 BUTTON: is the number of the regexp grouping actually matching the button,
6696 FORM: is a Lisp expression which must eval to true for the button to
6697 be added,
6698 CALLBACK: is the function to call when the user push this button, and each
6699 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6701 CALLBACK can also be a variable, in that case the value of that
6702 variable it the real callback function."
6703 :group 'gnus-article-buttons
6704 :type '(repeat (list (choice regexp variable sexp)
6705 (integer :tag "Button")
6706 (sexp :tag "Form")
6707 (function :tag "Callback")
6708 (repeat :tag "Par"
6709 :inline t
6710 (integer :tag "Regexp group")))))
6711 (put 'gnus-button-alist 'risky-local-variable t)
6713 (defcustom gnus-header-button-alist
6714 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6715 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6716 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6717 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6718 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6719 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6720 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6721 0 (>= gnus-button-browse-level 0) browse-url 0)
6722 ("^Subject:" gnus-button-url-regexp
6723 0 (>= gnus-button-browse-level 0) browse-url 0)
6724 ("^[^:]+:" gnus-button-url-regexp
6725 0 (>= gnus-button-browse-level 0) browse-url 0)
6726 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6727 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6728 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6729 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6730 "*Alist of headers and regexps to match buttons in article heads.
6732 This alist is very similar to `gnus-button-alist', except that each
6733 alist has an additional HEADER element first in each entry:
6735 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6737 HEADER is a regexp to match a header. For a fuller explanation, see
6738 `gnus-button-alist'."
6739 :group 'gnus-article-buttons
6740 :group 'gnus-article-headers
6741 :type '(repeat (list (regexp :tag "Header")
6742 (choice regexp variable)
6743 (integer :tag "Button")
6744 (sexp :tag "Form")
6745 (function :tag "Callback")
6746 (repeat :tag "Par"
6747 :inline t
6748 (integer :tag "Regexp group")))))
6749 (put 'gnus-header-button-alist 'risky-local-variable t)
6751 ;;; Commands:
6753 (defun gnus-article-push-button (event)
6754 "Check text under the mouse pointer for a callback function.
6755 If the text under the mouse pointer has a `gnus-callback' property,
6756 call it with the value of the `gnus-data' text property."
6757 (interactive "e")
6758 (set-buffer (window-buffer (posn-window (event-start event))))
6759 (let* ((pos (posn-point (event-start event)))
6760 (data (get-text-property pos 'gnus-data))
6761 (fun (get-text-property pos 'gnus-callback)))
6762 (goto-char pos)
6763 (when fun
6764 (funcall fun data))))
6766 (defun gnus-article-press-button ()
6767 "Check text at point for a callback function.
6768 If the text at point has a `gnus-callback' property,
6769 call it with the value of the `gnus-data' text property."
6770 (interactive)
6771 (let ((data (get-text-property (point) 'gnus-data))
6772 (fun (get-text-property (point) 'gnus-callback)))
6773 (when fun
6774 (funcall fun data))))
6776 (defun gnus-article-highlight (&optional force)
6777 "Highlight current article.
6778 This function calls `gnus-article-highlight-headers',
6779 `gnus-article-highlight-citation',
6780 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6781 do the highlighting. See the documentation for those functions."
6782 (interactive (list 'force))
6783 (gnus-article-highlight-headers)
6784 (gnus-article-highlight-citation force)
6785 (gnus-article-highlight-signature)
6786 (gnus-article-add-buttons force)
6787 (gnus-article-add-buttons-to-head))
6789 (defun gnus-article-highlight-some (&optional force)
6790 "Highlight current article.
6791 This function calls `gnus-article-highlight-headers',
6792 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6793 do the highlighting. See the documentation for those functions."
6794 (interactive (list 'force))
6795 (gnus-article-highlight-headers)
6796 (gnus-article-highlight-signature)
6797 (gnus-article-add-buttons))
6799 (defun gnus-article-highlight-headers ()
6800 "Highlight article headers as specified by `gnus-header-face-alist'."
6801 (interactive)
6802 (save-excursion
6803 (set-buffer gnus-article-buffer)
6804 (save-restriction
6805 (let ((alist gnus-header-face-alist)
6806 (inhibit-read-only t)
6807 (case-fold-search t)
6808 (inhibit-point-motion-hooks t)
6809 entry regexp header-face field-face from hpoints fpoints)
6810 (article-narrow-to-head)
6811 (while (setq entry (pop alist))
6812 (goto-char (point-min))
6813 (setq regexp (concat "^\\("
6814 (if (string-equal "" (nth 0 entry))
6815 "[^\t ]"
6816 (nth 0 entry))
6817 "\\)")
6818 header-face (nth 1 entry)
6819 field-face (nth 2 entry))
6820 (while (and (re-search-forward regexp nil t)
6821 (not (eobp)))
6822 (beginning-of-line)
6823 (setq from (point))
6824 (unless (search-forward ":" nil t)
6825 (forward-char 1))
6826 (when (and header-face
6827 (not (memq (point) hpoints)))
6828 (push (point) hpoints)
6829 (gnus-put-text-property from (point) 'face header-face))
6830 (when (and field-face
6831 (not (memq (setq from (point)) fpoints)))
6832 (push from fpoints)
6833 (if (re-search-forward "^[^ \t]" nil t)
6834 (forward-char -2)
6835 (goto-char (point-max)))
6836 (gnus-put-text-property from (point) 'face field-face))))))))
6838 (defun gnus-article-highlight-signature ()
6839 "Highlight the signature in an article.
6840 It does this by highlighting everything after
6841 `gnus-signature-separator' using the face `gnus-signature'."
6842 (interactive)
6843 (save-excursion
6844 (set-buffer gnus-article-buffer)
6845 (let ((inhibit-read-only t)
6846 (inhibit-point-motion-hooks t))
6847 (save-restriction
6848 (when (and gnus-signature-face
6849 (gnus-article-narrow-to-signature))
6850 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6851 'face gnus-signature-face)
6852 (widen)
6853 (gnus-article-search-signature)
6854 (let ((start (match-beginning 0))
6855 (end (set-marker (make-marker) (1+ (match-end 0)))))
6856 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6857 end)))))))
6859 (defun gnus-button-in-region-p (b e prop)
6860 "Say whether PROP exists in the region."
6861 (text-property-not-all b e prop nil))
6863 (defun gnus-article-add-buttons (&optional force)
6864 "Find external references in the article and make buttons of them.
6865 \"External references\" are things like Message-IDs and URLs, as
6866 specified by `gnus-button-alist'."
6867 (interactive (list 'force))
6868 (save-excursion
6869 (set-buffer gnus-article-buffer)
6870 (let ((inhibit-read-only t)
6871 (inhibit-point-motion-hooks t)
6872 (case-fold-search t)
6873 (alist gnus-button-alist)
6874 beg entry regexp)
6875 ;; Remove all old markers.
6876 (let (marker entry new-list)
6877 (while (setq marker (pop gnus-button-marker-list))
6878 (if (or (< marker (point-min)) (>= marker (point-max)))
6879 (push marker new-list)
6880 (goto-char marker)
6881 (when (setq entry (gnus-button-entry))
6882 (put-text-property (match-beginning (nth 1 entry))
6883 (match-end (nth 1 entry))
6884 'gnus-callback nil))
6885 (set-marker marker nil)))
6886 (setq gnus-button-marker-list new-list))
6887 ;; We skip the headers.
6888 (article-goto-body)
6889 (setq beg (point))
6890 (while (setq entry (pop alist))
6891 (setq regexp (eval (car entry)))
6892 (goto-char beg)
6893 (while (re-search-forward regexp nil t)
6894 (let* ((start (and entry (match-beginning (nth 1 entry))))
6895 (end (and entry (match-end (nth 1 entry))))
6896 (from (match-beginning 0)))
6897 (when (and (or (eq t (nth 2 entry))
6898 (eval (nth 2 entry)))
6899 (not (gnus-button-in-region-p
6900 start end 'gnus-callback)))
6901 ;; That optional form returned non-nil, so we add the
6902 ;; button.
6903 (gnus-article-add-button
6904 start end 'gnus-button-push
6905 (car (push (set-marker (make-marker) from)
6906 gnus-button-marker-list))))))))))
6908 ;; Add buttons to the head of an article.
6909 (defun gnus-article-add-buttons-to-head ()
6910 "Add buttons to the head of the article."
6911 (interactive)
6912 (save-excursion
6913 (set-buffer gnus-article-buffer)
6914 (save-restriction
6915 (let ((inhibit-read-only t)
6916 (inhibit-point-motion-hooks t)
6917 (case-fold-search t)
6918 (alist gnus-header-button-alist)
6919 entry beg end)
6920 (article-narrow-to-head)
6921 (while alist
6922 ;; Each alist entry.
6923 (setq entry (car alist)
6924 alist (cdr alist))
6925 (goto-char (point-min))
6926 (while (re-search-forward (car entry) nil t)
6927 ;; Each header matching the entry.
6928 (setq beg (match-beginning 0))
6929 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6930 (match-beginning 0))
6931 (point-max)))
6932 (goto-char beg)
6933 (while (re-search-forward (eval (nth 1 entry)) end t)
6934 ;; Each match within a header.
6935 (let* ((entry (cdr entry))
6936 (start (match-beginning (nth 1 entry)))
6937 (end (match-end (nth 1 entry)))
6938 (form (nth 2 entry)))
6939 (goto-char (match-end 0))
6940 (when (eval form)
6941 (gnus-article-add-button
6942 start end (nth 3 entry)
6943 (buffer-substring (match-beginning (nth 4 entry))
6944 (match-end (nth 4 entry)))))))
6945 (goto-char end)))))))
6947 ;;; External functions:
6949 (defun gnus-article-add-button (from to fun &optional data)
6950 "Create a button between FROM and TO with callback FUN and data DATA."
6951 (when gnus-article-button-face
6952 (gnus-overlay-put (gnus-make-overlay from to)
6953 'face gnus-article-button-face))
6954 (gnus-add-text-properties
6955 from to
6956 (nconc (and gnus-article-mouse-face
6957 (list gnus-mouse-face-prop gnus-article-mouse-face))
6958 (list 'gnus-callback fun)
6959 (and data (list 'gnus-data data))))
6960 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6961 :button-keymap gnus-widget-button-keymap))
6963 ;;; Internal functions:
6965 (defun gnus-article-set-globals ()
6966 (save-excursion
6967 (set-buffer gnus-summary-buffer)
6968 (gnus-set-global-variables)))
6970 (defun gnus-signature-toggle (end)
6971 (save-excursion
6972 (set-buffer gnus-article-buffer)
6973 (let ((inhibit-read-only t)
6974 (inhibit-point-motion-hooks t))
6975 (if (text-property-any end (point-max) 'article-type 'signature)
6976 (progn
6977 (gnus-delete-wash-type 'signature)
6978 (gnus-remove-text-properties-when
6979 'article-type 'signature end (point-max)
6980 (cons 'article-type (cons 'signature
6981 gnus-hidden-properties))))
6982 (gnus-add-wash-type 'signature)
6983 (gnus-add-text-properties-when
6984 'article-type nil end (point-max)
6985 (cons 'article-type (cons 'signature
6986 gnus-hidden-properties)))))
6987 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6988 (gnus-set-mode-line 'article))))
6990 (defun gnus-button-entry ()
6991 ;; Return the first entry in `gnus-button-alist' matching this place.
6992 (let ((alist gnus-button-alist)
6993 (entry nil))
6994 (while alist
6995 (setq entry (pop alist))
6996 (if (looking-at (eval (car entry)))
6997 (setq alist nil)
6998 (setq entry nil)))
6999 entry))
7001 (defun gnus-button-push (marker)
7002 ;; Push button starting at MARKER.
7003 (save-excursion
7004 (goto-char marker)
7005 (let* ((entry (gnus-button-entry))
7006 (inhibit-point-motion-hooks t)
7007 (fun (nth 3 entry))
7008 (args (mapcar (lambda (group)
7009 (let ((string (match-string group)))
7010 (gnus-set-text-properties
7011 0 (length string) nil string)
7012 string))
7013 (nthcdr 4 entry))))
7014 (cond
7015 ((fboundp fun)
7016 (apply fun args))
7017 ((and (boundp fun)
7018 (fboundp (symbol-value fun)))
7019 (apply (symbol-value fun) args))
7021 (gnus-message 1 "You must define `%S' to use this button"
7022 (cons fun args)))))))
7024 (defun gnus-parse-news-url (url)
7025 (let (scheme server port group message-id articles)
7026 (with-temp-buffer
7027 (insert url)
7028 (goto-char (point-min))
7029 (when (looking-at "\\([A-Za-z]+\\):")
7030 (setq scheme (match-string 1))
7031 (goto-char (match-end 0)))
7032 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7033 (setq server (match-string 1))
7034 (setq port (if (stringp (match-string 3))
7035 (string-to-number (match-string 3))
7036 (match-string 3)))
7037 (goto-char (match-end 0)))
7039 (cond
7040 ((looking-at "\\(.*@.*\\)")
7041 (setq message-id (match-string 1)))
7042 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7043 (setq group (match-string 1)
7044 articles (split-string (match-string 2) "-")))
7045 ((looking-at "\\([^/]+\\)/?")
7046 (setq group (match-string 1)))
7048 (error "Unknown news URL syntax"))))
7049 (list scheme server port group message-id articles)))
7051 (defun gnus-button-handle-news (url)
7052 "Fetch a news URL."
7053 (destructuring-bind (scheme server port group message-id articles)
7054 (gnus-parse-news-url url)
7055 (cond
7056 (message-id
7057 (save-excursion
7058 (set-buffer gnus-summary-buffer)
7059 (if server
7060 (let ((gnus-refer-article-method
7061 (nconc (list (list 'nntp server))
7062 gnus-refer-article-method))
7063 (nntp-port-number (or port "nntp")))
7064 (gnus-message 7 "Fetching %s with %s"
7065 message-id gnus-refer-article-method)
7066 (gnus-summary-refer-article message-id))
7067 (gnus-summary-refer-article message-id))))
7068 (group
7069 (gnus-button-fetch-group url)))))
7071 (defun gnus-button-handle-man (url)
7072 "Fetch a man page."
7073 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7074 (when (eq gnus-button-man-handler 'woman)
7075 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7076 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7077 (funcall gnus-button-man-handler url))
7079 (defun gnus-button-handle-info-url (url)
7080 "Fetch an info URL."
7081 (setq url (mm-subst-char-in-string ?+ ?\ url))
7082 (cond
7083 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7084 (gnus-info-find-node
7085 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7086 "Gnus")
7087 ")" (gnus-url-unhex-string (match-string 2 url)))))
7088 ((string-match "([^)\"]+)[^\"]+" url)
7089 (setq url
7090 (gnus-replace-in-string
7091 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7092 (gnus-info-find-node url))
7093 (t (error "Can't parse %s" url))))
7095 (defun gnus-button-handle-info-url-gnome (url)
7096 "Fetch GNOME style info URL."
7097 (setq url (mm-subst-char-in-string ?_ ?\ url))
7098 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7099 (gnus-info-find-node
7100 (concat "("
7101 (gnus-url-unhex-string
7102 (match-string 1 url))
7104 (or (gnus-url-unhex-string
7105 (match-string 2 url))
7106 "Top")))
7107 (error "Can't parse %s" url)))
7109 (defun gnus-button-handle-info-url-kde (url)
7110 "Fetch KDE style info URL."
7111 (gnus-info-find-node (gnus-url-unhex-string url)))
7113 (defun gnus-button-handle-info-keystrokes (url)
7114 "Call `info' when pushing the corresponding URL button."
7115 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7116 (info)
7117 (Info-directory)
7118 (Info-menu url))
7120 (defun gnus-button-message-id (message-id)
7121 "Fetch MESSAGE-ID."
7122 (save-excursion
7123 (set-buffer gnus-summary-buffer)
7124 (gnus-summary-refer-article message-id)))
7126 (defun gnus-button-fetch-group (address)
7127 "Fetch GROUP specified by ADDRESS."
7128 (if (not (string-match "[:/]" address))
7129 ;; This is just a simple group url.
7130 (gnus-group-read-ephemeral-group address gnus-select-method)
7131 (if (not
7132 (string-match
7133 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7134 address))
7135 (error "Can't parse %s" address)
7136 (gnus-group-read-ephemeral-group
7137 (match-string 4 address)
7138 `(nntp ,(match-string 1 address)
7139 (nntp-address ,(match-string 1 address))
7140 (nntp-port-number ,(if (match-end 3)
7141 (match-string 3 address)
7142 "nntp")))
7143 nil nil nil
7144 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7146 (defun gnus-url-parse-query-string (query &optional downcase)
7147 (let (retval pairs cur key val)
7148 (setq pairs (split-string query "&"))
7149 (while pairs
7150 (setq cur (car pairs)
7151 pairs (cdr pairs))
7152 (if (not (string-match "=" cur))
7153 nil ; Grace
7154 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7155 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7156 (if downcase
7157 (setq key (downcase key)))
7158 (setq cur (assoc key retval))
7159 (if cur
7160 (setcdr cur (cons val (cdr cur)))
7161 (setq retval (cons (list key val) retval)))))
7162 retval))
7164 (defun gnus-url-mailto (url)
7165 ;; Send mail to someone
7166 (when (string-match "mailto:/*\\(.*\\)" url)
7167 (setq url (substring url (match-beginning 1) nil)))
7168 (let (to args subject func)
7169 (setq args (gnus-url-parse-query-string
7170 (if (string-match "^\\?" url)
7171 (substring url 1)
7172 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7173 (concat "to=" (match-string 1 url) "&"
7174 (match-string 2 url))
7175 (concat "to=" url)))
7177 subject (cdr-safe (assoc "subject" args)))
7178 (gnus-msg-mail)
7179 (while args
7180 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7181 (if (fboundp func)
7182 (funcall func)
7183 (message-position-on-field (caar args)))
7184 (insert (gnus-replace-in-string
7185 (mapconcat 'identity (reverse (cdar args)) ", ")
7186 "\r\n" "\n" t))
7187 (setq args (cdr args)))
7188 (if subject
7189 (message-goto-body)
7190 (message-goto-subject))))
7192 (defun gnus-button-embedded-url (address)
7193 "Activate ADDRESS with `browse-url'."
7194 (browse-url (gnus-strip-whitespace address)))
7196 ;;; Next/prev buttons in the article buffer.
7198 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7199 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7201 (defvar gnus-prev-page-map
7202 (let ((map (make-sparse-keymap)))
7203 (unless (>= emacs-major-version 21)
7204 ;; XEmacs doesn't care.
7205 (set-keymap-parent map gnus-article-mode-map))
7206 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7207 (define-key map "\r" 'gnus-button-prev-page)
7208 map))
7210 (defvar gnus-next-page-map
7211 (let ((map (make-sparse-keymap)))
7212 (unless (>= emacs-major-version 21)
7213 ;; XEmacs doesn't care.
7214 (set-keymap-parent map gnus-article-mode-map))
7215 (define-key map gnus-mouse-2 'gnus-button-next-page)
7216 (define-key map "\r" 'gnus-button-next-page)
7217 map))
7219 (defun gnus-insert-prev-page-button ()
7220 (let ((b (point))
7221 (inhibit-read-only t))
7222 (gnus-eval-format
7223 gnus-prev-page-line-format nil
7224 `(,@(gnus-local-map-property gnus-prev-page-map)
7225 gnus-prev t
7226 gnus-callback gnus-article-button-prev-page
7227 article-type annotation))
7228 (widget-convert-button
7229 'link b (if (bolp)
7230 ;; Exclude a newline.
7231 (1- (point))
7232 (point))
7233 :action 'gnus-button-prev-page
7234 :button-keymap gnus-prev-page-map)))
7236 (defun gnus-button-next-page (&optional args more-args)
7237 "Go to the next page."
7238 (interactive)
7239 (let ((win (selected-window)))
7240 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7241 (gnus-article-next-page)
7242 (select-window win)))
7244 (defun gnus-button-prev-page (&optional args more-args)
7245 "Go to the prev page."
7246 (interactive)
7247 (let ((win (selected-window)))
7248 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7249 (gnus-article-prev-page)
7250 (select-window win)))
7252 (defun gnus-insert-next-page-button ()
7253 (let ((b (point))
7254 (inhibit-read-only t))
7255 (gnus-eval-format gnus-next-page-line-format nil
7256 `(,@(gnus-local-map-property gnus-next-page-map)
7257 gnus-next t
7258 gnus-callback gnus-article-button-next-page
7259 article-type annotation))
7260 (widget-convert-button
7261 'link b (if (bolp)
7262 ;; Exclude a newline.
7263 (1- (point))
7264 (point))
7265 :action 'gnus-button-next-page
7266 :button-keymap gnus-next-page-map)))
7268 (defun gnus-article-button-next-page (arg)
7269 "Go to the next page."
7270 (interactive "P")
7271 (let ((win (selected-window)))
7272 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7273 (gnus-article-next-page)
7274 (select-window win)))
7276 (defun gnus-article-button-prev-page (arg)
7277 "Go to the prev page."
7278 (interactive "P")
7279 (let ((win (selected-window)))
7280 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7281 (gnus-article-prev-page)
7282 (select-window win)))
7284 (defvar gnus-decode-header-methods
7285 '(mail-decode-encoded-word-region)
7286 "List of methods used to decode headers.
7288 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7289 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7290 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7291 whose names match REGEXP.
7293 For example:
7294 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7295 mail-decode-encoded-word-region
7296 (\"chinese\" . rfc1843-decode-region))
7299 (defvar gnus-decode-header-methods-cache nil)
7301 (defun gnus-multi-decode-header (start end)
7302 "Apply the functions from `gnus-encoded-word-methods' that match."
7303 (unless (and gnus-decode-header-methods-cache
7304 (eq gnus-newsgroup-name
7305 (car gnus-decode-header-methods-cache)))
7306 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7307 (mapcar (lambda (x)
7308 (if (symbolp x)
7309 (nconc gnus-decode-header-methods-cache (list x))
7310 (if (and gnus-newsgroup-name
7311 (string-match (car x) gnus-newsgroup-name))
7312 (nconc gnus-decode-header-methods-cache
7313 (list (cdr x))))))
7314 gnus-decode-header-methods))
7315 (let ((xlist gnus-decode-header-methods-cache))
7316 (pop xlist)
7317 (save-restriction
7318 (narrow-to-region start end)
7319 (while xlist
7320 (funcall (pop xlist) (point-min) (point-max))))))
7323 ;;; Treatment top-level handling.
7326 (defun gnus-treat-article (condition &optional part-number total-parts type)
7327 (let ((length (- (point-max) (point-min)))
7328 (alist gnus-treatment-function-alist)
7329 (article-goto-body-goes-to-point-min-p t)
7330 (treated-type
7331 (or (not type)
7332 (catch 'found
7333 (let ((list gnus-article-treat-types))
7334 (while list
7335 (when (string-match (pop list) type)
7336 (throw 'found t)))))))
7337 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7338 val elem)
7339 (gnus-run-hooks 'gnus-part-display-hook)
7340 (dolist (elem alist)
7341 (setq val
7342 (save-excursion
7343 (when (gnus-buffer-live-p gnus-summary-buffer)
7344 (set-buffer gnus-summary-buffer))
7345 (symbol-value (car elem))))
7346 (when (and (or (consp val)
7347 treated-type)
7348 (gnus-treat-predicate val)
7349 (or (not (get (car elem) 'highlight))
7350 highlightp))
7351 (save-restriction
7352 (funcall (cadr elem)))))))
7354 ;; Dynamic variables.
7355 (eval-when-compile
7356 (defvar part-number)
7357 (defvar total-parts)
7358 (defvar type)
7359 (defvar condition)
7360 (defvar length))
7362 (defun gnus-treat-predicate (val)
7363 (cond
7364 ((null val)
7365 nil)
7366 (condition
7367 (eq condition val))
7368 ((and (listp val)
7369 (stringp (car val)))
7370 (apply 'gnus-or (mapcar `(lambda (s)
7371 (string-match s ,(or gnus-newsgroup-name "")))
7372 val)))
7373 ((listp val)
7374 (let ((pred (pop val)))
7375 (cond
7376 ((eq pred 'or)
7377 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7378 ((eq pred 'and)
7379 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7380 ((eq pred 'not)
7381 (not (gnus-treat-predicate (car val))))
7382 ((eq pred 'typep)
7383 (equal (car val) type))
7385 (error "%S is not a valid predicate" pred)))))
7386 ((eq val t)
7388 ((eq val 'head)
7389 nil)
7390 ((eq val 'last)
7391 (eq part-number total-parts))
7392 ((numberp val)
7393 (< length val))
7395 (error "%S is not a valid value" val))))
7397 (defun gnus-article-encrypt-body (protocol &optional n)
7398 "Encrypt the article body."
7399 (interactive
7400 (list
7401 (or gnus-article-encrypt-protocol
7402 (completing-read "Encrypt protocol: "
7403 gnus-article-encrypt-protocol-alist
7404 nil t))
7405 current-prefix-arg))
7406 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7407 (unless func
7408 (error "Can't find the encrypt protocol %s" protocol))
7409 (if (member gnus-newsgroup-name '("nndraft:delayed"
7410 "nndraft:drafts"
7411 "nndraft:queue"))
7412 (error "Can't encrypt the article in group %s"
7413 gnus-newsgroup-name))
7414 (gnus-summary-iterate n
7415 (save-excursion
7416 (set-buffer gnus-summary-buffer)
7417 (let ((mail-parse-charset gnus-newsgroup-charset)
7418 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7419 (summary-buffer gnus-summary-buffer)
7420 references point)
7421 (gnus-set-global-variables)
7422 (when (gnus-group-read-only-p)
7423 (error "The current newsgroup does not support article encrypt"))
7424 (gnus-summary-show-article t)
7425 (setq references
7426 (or (mail-header-references gnus-current-headers) ""))
7427 (set-buffer gnus-article-buffer)
7428 (let* ((inhibit-read-only t)
7429 (headers
7430 (mapcar (lambda (field)
7431 (and (save-restriction
7432 (message-narrow-to-head)
7433 (goto-char (point-min))
7434 (search-forward field nil t))
7435 (prog2
7436 (message-narrow-to-field)
7437 (buffer-string)
7438 (delete-region (point-min) (point-max))
7439 (widen))))
7440 '("Content-Type:" "Content-Transfer-Encoding:"
7441 "Content-Disposition:"))))
7442 (message-narrow-to-head)
7443 (message-remove-header "MIME-Version")
7444 (goto-char (point-max))
7445 (setq point (point))
7446 (insert (apply 'concat headers))
7447 (widen)
7448 (narrow-to-region point (point-max))
7449 (let ((message-options message-options))
7450 (message-options-set 'message-sender user-mail-address)
7451 (message-options-set 'message-recipients user-mail-address)
7452 (message-options-set 'message-sign-encrypt 'not)
7453 (funcall func))
7454 (goto-char (point-min))
7455 (insert "MIME-Version: 1.0\n")
7456 (widen)
7457 (gnus-summary-edit-article-done
7458 references nil summary-buffer t))
7459 (when gnus-keep-backlog
7460 (gnus-backlog-remove-article
7461 (car gnus-article-current) (cdr gnus-article-current)))
7462 (save-excursion
7463 (when (get-buffer gnus-original-article-buffer)
7464 (set-buffer gnus-original-article-buffer)
7465 (setq gnus-original-article nil)))
7466 (when gnus-use-cache
7467 (gnus-cache-update-article
7468 (car gnus-article-current) (cdr gnus-article-current))))))))
7470 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7471 "The following specs can be used:
7472 %t The security MIME type
7473 %i Additional info
7474 %d Details
7475 %D Details if button is pressed")
7477 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7478 "The following specs can be used:
7479 %t The security MIME type
7480 %i Additional info
7481 %d Details
7482 %D Details if button is pressed")
7484 (defvar gnus-mime-security-button-line-format-alist
7485 '((?t gnus-tmp-type ?s)
7486 (?i gnus-tmp-info ?s)
7487 (?d gnus-tmp-details ?s)
7488 (?D gnus-tmp-pressed-details ?s)))
7490 (defvar gnus-mime-security-button-map
7491 (let ((map (make-sparse-keymap)))
7492 (unless (>= (string-to-number emacs-version) 21)
7493 (set-keymap-parent map gnus-article-mode-map))
7494 (define-key map gnus-mouse-2 'gnus-article-push-button)
7495 (define-key map "\r" 'gnus-article-press-button)
7496 map))
7498 (defvar gnus-mime-security-details-buffer nil)
7500 (defvar gnus-mime-security-button-pressed nil)
7502 (defvar gnus-mime-security-show-details-inline t
7503 "If non-nil, show details in the article buffer.")
7505 (defun gnus-mime-security-verify-or-decrypt (handle)
7506 (mm-remove-parts (cdr handle))
7507 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7508 point (inhibit-read-only t))
7509 (if region
7510 (goto-char (car region)))
7511 (save-restriction
7512 (narrow-to-region (point) (point))
7513 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7514 (let* ((mm-verify-option 'known)
7515 (mm-decrypt-option 'known)
7516 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7517 (unless (eq nparts (cdr handle))
7518 (mm-destroy-parts (cdr handle))
7519 (setcdr handle nparts))))
7520 (setq point (point))
7521 (gnus-mime-display-security handle)
7522 (goto-char (point-max)))
7523 (when region
7524 (delete-region (point) (cdr region))
7525 (set-marker (car region) nil)
7526 (set-marker (cdr region) nil))
7527 (goto-char point)))
7529 (defun gnus-mime-security-show-details (handle)
7530 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7531 (if (not details)
7532 (gnus-message 5 "No details.")
7533 (if gnus-mime-security-show-details-inline
7534 (let ((gnus-mime-security-button-pressed
7535 (not (get-text-property (point) 'gnus-mime-details)))
7536 (gnus-mime-security-button-line-format
7537 (get-text-property (point) 'gnus-line-format))
7538 (inhibit-read-only t))
7539 (forward-char -1)
7540 (while (eq (get-text-property (point) 'gnus-line-format)
7541 gnus-mime-security-button-line-format)
7542 (forward-char -1))
7543 (forward-char)
7544 (save-restriction
7545 (narrow-to-region (point) (point))
7546 (gnus-insert-mime-security-button handle))
7547 (delete-region (point)
7548 (or (text-property-not-all
7549 (point) (point-max)
7550 'gnus-line-format
7551 gnus-mime-security-button-line-format)
7552 (point-max))))
7553 ;; Not inlined.
7554 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7555 (with-current-buffer gnus-mime-security-details-buffer
7556 (erase-buffer)
7558 (setq gnus-mime-security-details-buffer
7559 (gnus-get-buffer-create "*MIME Security Details*")))
7560 (with-current-buffer gnus-mime-security-details-buffer
7561 (insert details)
7562 (goto-char (point-min)))
7563 (pop-to-buffer gnus-mime-security-details-buffer)))))
7565 (defun gnus-mime-security-press-button (handle)
7566 (save-excursion
7567 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7568 (gnus-mime-security-show-details handle)
7569 (gnus-mime-security-verify-or-decrypt handle))))
7571 (defun gnus-insert-mime-security-button (handle &optional displayed)
7572 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7573 (gnus-tmp-type
7574 (concat
7575 (or (nth 2 (assoc protocol mm-verify-function-alist))
7576 (nth 2 (assoc protocol mm-decrypt-function-alist))
7577 "Unknown")
7578 (if (equal (car handle) "multipart/signed")
7579 " Signed" " Encrypted")
7580 " Part"))
7581 (gnus-tmp-info
7582 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7583 "Undecided"))
7584 (gnus-tmp-details
7585 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7586 gnus-tmp-pressed-details
7587 b e)
7588 (setq gnus-tmp-details
7589 (if gnus-tmp-details
7590 (concat "\n" gnus-tmp-details)
7591 ""))
7592 (setq gnus-tmp-pressed-details
7593 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7594 (unless (bolp)
7595 (insert "\n"))
7596 (setq b (point))
7597 (gnus-eval-format
7598 gnus-mime-security-button-line-format
7599 gnus-mime-security-button-line-format-alist
7600 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7601 gnus-callback gnus-mime-security-press-button
7602 gnus-line-format ,gnus-mime-security-button-line-format
7603 gnus-mime-details ,gnus-mime-security-button-pressed
7604 article-type annotation
7605 gnus-data ,handle))
7606 (setq e (if (bolp)
7607 ;; Exclude a newline.
7608 (1- (point))
7609 (point)))
7610 (widget-convert-button
7611 'link b e
7612 :mime-handle handle
7613 :action 'gnus-widget-press-button
7614 :button-keymap gnus-mime-security-button-map
7615 :help-echo
7616 (lambda (widget/window &optional overlay pos)
7617 ;; Needed to properly clear the message due to a bug in
7618 ;; wid-edit (XEmacs only).
7619 (when (boundp 'help-echo-owns-message)
7620 (setq help-echo-owns-message t))
7621 (format
7622 "%S: show detail"
7623 (aref gnus-mouse-2 0))))))
7625 (defun gnus-mime-display-security (handle)
7626 (save-restriction
7627 (narrow-to-region (point) (point))
7628 (unless (gnus-unbuttonized-mime-type-p (car handle))
7629 (gnus-insert-mime-security-button handle))
7630 (gnus-mime-display-mixed (cdr handle))
7631 (unless (bolp)
7632 (insert "\n"))
7633 (unless (gnus-unbuttonized-mime-type-p (car handle))
7634 (let ((gnus-mime-security-button-line-format
7635 gnus-mime-security-button-end-line-format))
7636 (gnus-insert-mime-security-button handle)))
7637 (mm-set-handle-multipart-parameter
7638 handle 'gnus-region
7639 (cons (set-marker (make-marker) (point-min))
7640 (set-marker (make-marker) (point-max))))))
7642 (gnus-ems-redefine)
7644 (provide 'gnus-art)
7646 (run-hooks 'gnus-art-load-hook)
7648 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7649 ;;; gnus-art.el ends here