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