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