* smime.el (from):
[emacs.git] / lisp / gnus / gnus-art.el
blob3897f355b2977d434e469f83fa6e63886341114d
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-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 ()
2338 "Display any Face headers in the header."
2339 (interactive)
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 (face faces from)
2350 (save-current-buffer
2351 (when (and wash-face-p
2352 (gnus-buffer-live-p gnus-original-article-buffer)
2353 (not (re-search-forward "^Face:[\t ]*" nil t)))
2354 (set-buffer gnus-original-article-buffer))
2355 (save-restriction
2356 (mail-narrow-to-head)
2357 (while (gnus-article-goto-header "Face")
2358 (push (mail-header-field-value) faces))))
2359 (when faces
2360 (goto-char (point-min))
2361 (let ((from (gnus-article-goto-header "from"))
2362 png image)
2363 (unless from
2364 (insert "From:")
2365 (setq from (point))
2366 (insert "[no `from' set]\n"))
2367 (while faces
2368 (when (setq png (gnus-convert-face-to-png (pop faces)))
2369 (setq image
2370 (apply 'gnus-create-image png 'png t
2371 (cdr (assq 'png gnus-face-properties-alist))))
2372 (goto-char from)
2373 (gnus-add-wash-type 'face)
2374 (gnus-add-image 'face image)
2375 (gnus-put-image image nil 'face))))))))))
2377 (defun article-display-x-face (&optional force)
2378 "Look for an X-Face header and display it if present."
2379 (interactive (list 'force))
2380 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2381 (gnus-with-article-headers
2382 ;; Delete the old process, if any.
2383 (when (process-status "article-x-face")
2384 (delete-process "article-x-face"))
2385 ;; See the comment in `article-display-face'.
2386 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2387 ;; We have already displayed X-Faces, so we remove them
2388 ;; instead.
2389 (gnus-delete-images 'xface)
2390 ;; Display X-Faces.
2391 (let (x-faces from face)
2392 (save-current-buffer
2393 (when (and wash-face-p
2394 (gnus-buffer-live-p gnus-original-article-buffer)
2395 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2396 ;; If type `W f', use gnus-original-article-buffer,
2397 ;; otherwise use the current buffer because displaying
2398 ;; RFC822 parts calls this function too.
2399 (set-buffer gnus-original-article-buffer))
2400 (save-restriction
2401 (mail-narrow-to-head)
2402 (while (gnus-article-goto-header "X-Face")
2403 (push (mail-header-field-value) x-faces))
2404 (setq from (message-fetch-field "from"))))
2405 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2406 ;; single external face.
2407 (when (stringp gnus-article-x-face-command)
2408 (setq x-faces (list (car x-faces))))
2409 (when (and x-faces
2410 gnus-article-x-face-command
2411 (or force
2412 ;; Check whether this face is censored.
2413 (not gnus-article-x-face-too-ugly)
2414 (and from
2415 (not (string-match gnus-article-x-face-too-ugly
2416 from)))))
2417 (while (setq face (pop x-faces))
2418 ;; We display the face.
2419 (cond ((stringp gnus-article-x-face-command)
2420 ;; The command is a string, so we interpret the command
2421 ;; as a, well, command, and fork it off.
2422 (let ((process-connection-type nil))
2423 (gnus-set-process-query-on-exit-flag
2424 (start-process
2425 "article-x-face" nil shell-file-name
2426 shell-command-switch gnus-article-x-face-command)
2427 nil)
2428 (with-temp-buffer
2429 (insert face)
2430 (process-send-region "article-x-face"
2431 (point-min) (point-max)))
2432 (process-send-eof "article-x-face")))
2433 ((functionp gnus-article-x-face-command)
2434 ;; The command is a lisp function, so we call it.
2435 (funcall gnus-article-x-face-command face))
2437 (error "%s is not a function"
2438 gnus-article-x-face-command))))))))))
2440 (defun article-decode-mime-words ()
2441 "Decode all MIME-encoded words in the article."
2442 (interactive)
2443 (gnus-with-article-buffer
2444 (let ((inhibit-point-motion-hooks t)
2445 (mail-parse-charset gnus-newsgroup-charset)
2446 (mail-parse-ignored-charsets
2447 (with-current-buffer gnus-summary-buffer
2448 gnus-newsgroup-ignored-charsets)))
2449 (mail-decode-encoded-word-region (point-min) (point-max)))))
2451 (defun article-decode-charset (&optional prompt)
2452 "Decode charset-encoded text in the article.
2453 If PROMPT (the prefix), prompt for a coding system to use."
2454 (interactive "P")
2455 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2456 (inhibit-read-only t)
2457 (mail-parse-charset gnus-newsgroup-charset)
2458 (mail-parse-ignored-charsets
2459 (save-excursion (condition-case nil
2460 (set-buffer gnus-summary-buffer)
2461 (error))
2462 gnus-newsgroup-ignored-charsets))
2463 ct cte ctl charset format)
2464 (save-excursion
2465 (save-restriction
2466 (article-narrow-to-head)
2467 (setq ct (message-fetch-field "Content-Type" t)
2468 cte (message-fetch-field "Content-Transfer-Encoding" t)
2469 ctl (and ct (mail-header-parse-content-type ct))
2470 charset (cond
2471 (prompt
2472 (mm-read-coding-system "Charset to decode: "))
2473 (ctl
2474 (mail-content-type-get ctl 'charset)))
2475 format (and ctl (mail-content-type-get ctl 'format)))
2476 (when cte
2477 (setq cte (mail-header-strip cte)))
2478 (if (and ctl (not (string-match "/" (car ctl))))
2479 (setq ctl nil))
2480 (goto-char (point-max)))
2481 (forward-line 1)
2482 (save-restriction
2483 (narrow-to-region (point) (point-max))
2484 (when (and (eq mail-parse-charset 'gnus-decoded)
2485 (eq (mm-body-7-or-8) '8bit))
2486 ;; The text code could have been decoded.
2487 (setq charset mail-parse-charset))
2488 (when (and (or (not ctl)
2489 (equal (car ctl) "text/plain"))
2490 (not format)) ;; article with format will decode later.
2491 (mm-decode-body
2492 charset (and cte (intern (downcase
2493 (gnus-strip-whitespace cte))))
2494 (car ctl)))))))
2496 (defun article-decode-encoded-words ()
2497 "Remove encoded-word encoding from headers."
2498 (let ((inhibit-point-motion-hooks t)
2499 (mail-parse-charset gnus-newsgroup-charset)
2500 (mail-parse-ignored-charsets
2501 (save-excursion (condition-case nil
2502 (set-buffer gnus-summary-buffer)
2503 (error))
2504 gnus-newsgroup-ignored-charsets))
2505 (inhibit-read-only t)
2506 end start)
2507 (goto-char (point-min))
2508 (when (search-forward "\n\n" nil 'move)
2509 (forward-line -1))
2510 (setq end (point))
2511 (while (not (bobp))
2512 (while (progn
2513 (forward-line -1)
2514 (and (not (bobp))
2515 (memq (char-after) '(?\t ? )))))
2516 (setq start (point))
2517 (if (looking-at "\
2518 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2519 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2520 (funcall gnus-decode-address-function start end)
2521 (funcall gnus-decode-header-function start end))
2522 (goto-char (setq end start)))))
2524 (defun article-decode-group-name ()
2525 "Decode group names in Newsgroups, Followup-To and Xref headers."
2526 (let ((inhibit-point-motion-hooks t)
2527 (inhibit-read-only t)
2528 (method (gnus-find-method-for-group gnus-newsgroup-name))
2529 regexp)
2530 (when (and (or gnus-group-name-charset-method-alist
2531 gnus-group-name-charset-group-alist)
2532 (gnus-buffer-live-p gnus-original-article-buffer))
2533 (save-restriction
2534 (article-narrow-to-head)
2535 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2536 (with-current-buffer gnus-original-article-buffer
2537 (goto-char (point-min)))
2538 (setq regexp (concat "^" header
2539 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2540 (while (re-search-forward regexp nil t)
2541 (replace-match (save-match-data
2542 (gnus-decode-newsgroups
2543 ;; XXX how to use data in article buffer?
2544 (with-current-buffer gnus-original-article-buffer
2545 (re-search-forward regexp nil t)
2546 (match-string 1))
2547 gnus-newsgroup-name method))
2548 t t nil 1))
2549 (goto-char (point-min)))))))
2551 (autoload 'idna-to-unicode "idna")
2553 (defun article-decode-idna-rhs ()
2554 "Decode IDNA strings in RHS in various headers in current buffer.
2555 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2556 Mail-Reply-To: and Mail-Followup-To:."
2557 (when gnus-use-idna
2558 (save-restriction
2559 (let ((inhibit-point-motion-hooks t)
2560 (inhibit-read-only t))
2561 (article-narrow-to-head)
2562 (goto-char (point-min))
2563 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2564 (let (ace unicode)
2565 (when (save-match-data
2566 (and (setq ace (match-string 1))
2567 (save-excursion
2568 (and (re-search-backward "^[^ \t]" nil t)
2569 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2570 (setq unicode (idna-to-unicode ace))))
2571 (unless (string= ace unicode)
2572 (replace-match unicode nil nil nil 1)))))))))
2574 (defun article-de-quoted-unreadable (&optional force read-charset)
2575 "Translate a quoted-printable-encoded article.
2576 If FORCE, decode the article whether it is marked as quoted-printable
2577 or not.
2578 If READ-CHARSET, ask for a coding system."
2579 (interactive (list 'force current-prefix-arg))
2580 (save-excursion
2581 (let ((inhibit-read-only t) type charset)
2582 (if (gnus-buffer-live-p gnus-original-article-buffer)
2583 (with-current-buffer gnus-original-article-buffer
2584 (setq type
2585 (gnus-fetch-field "content-transfer-encoding"))
2586 (let* ((ct (gnus-fetch-field "content-type"))
2587 (ctl (and ct (mail-header-parse-content-type ct))))
2588 (setq charset (and ctl
2589 (mail-content-type-get ctl 'charset)))
2590 (if (stringp charset)
2591 (setq charset (intern (downcase charset)))))))
2592 (if read-charset
2593 (setq charset (mm-read-coding-system "Charset: " charset)))
2594 (unless charset
2595 (setq charset gnus-newsgroup-charset))
2596 (when (or force
2597 (and type (let ((case-fold-search t))
2598 (string-match "quoted-printable" type))))
2599 (article-goto-body)
2600 (quoted-printable-decode-region
2601 (point) (point-max) (mm-charset-to-coding-system charset))))))
2603 (defun article-de-base64-unreadable (&optional force read-charset)
2604 "Translate a base64 article.
2605 If FORCE, decode the article whether it is marked as base64 not.
2606 If READ-CHARSET, ask for a coding system."
2607 (interactive (list 'force current-prefix-arg))
2608 (save-excursion
2609 (let ((inhibit-read-only t) type charset)
2610 (if (gnus-buffer-live-p gnus-original-article-buffer)
2611 (with-current-buffer gnus-original-article-buffer
2612 (setq type
2613 (gnus-fetch-field "content-transfer-encoding"))
2614 (let* ((ct (gnus-fetch-field "content-type"))
2615 (ctl (and ct (mail-header-parse-content-type ct))))
2616 (setq charset (and ctl
2617 (mail-content-type-get ctl 'charset)))
2618 (if (stringp charset)
2619 (setq charset (intern (downcase charset)))))))
2620 (if read-charset
2621 (setq charset (mm-read-coding-system "Charset: " charset)))
2622 (unless charset
2623 (setq charset gnus-newsgroup-charset))
2624 (when (or force
2625 (and type (let ((case-fold-search t))
2626 (string-match "base64" type))))
2627 (article-goto-body)
2628 (save-restriction
2629 (narrow-to-region (point) (point-max))
2630 (base64-decode-region (point-min) (point-max))
2631 (mm-decode-coding-region
2632 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2634 (eval-when-compile
2635 (require 'rfc1843))
2637 (defun article-decode-HZ ()
2638 "Translate a HZ-encoded article."
2639 (interactive)
2640 (require 'rfc1843)
2641 (save-excursion
2642 (let ((inhibit-read-only t))
2643 (rfc1843-decode-region (point-min) (point-max)))))
2645 (defun article-unsplit-urls ()
2646 "Remove the newlines that some other mailers insert into URLs."
2647 (interactive)
2648 (save-excursion
2649 (let ((inhibit-read-only t))
2650 (goto-char (point-min))
2651 (while (re-search-forward
2652 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2653 (replace-match "\\1\\3" t)))
2654 (when (interactive-p)
2655 (gnus-treat-article nil))))
2658 (defun article-wash-html (&optional read-charset)
2659 "Format an HTML article.
2660 If READ-CHARSET, ask for a coding system. If it is a number, the
2661 charset defined in `gnus-summary-show-article-charset-alist' is used."
2662 (interactive "P")
2663 (save-excursion
2664 (let ((inhibit-read-only t)
2665 charset)
2666 (if read-charset
2667 (if (or (and (numberp read-charset)
2668 (setq charset
2669 (cdr
2670 (assq read-charset
2671 gnus-summary-show-article-charset-alist))))
2672 (setq charset (mm-read-coding-system "Charset: ")))
2673 (let ((gnus-summary-show-article-charset-alist
2674 (list (cons 1 charset))))
2675 (with-current-buffer gnus-summary-buffer
2676 (gnus-summary-show-article 1)))
2677 (error "No charset is given"))
2678 (when (gnus-buffer-live-p gnus-original-article-buffer)
2679 (with-current-buffer gnus-original-article-buffer
2680 (let* ((ct (gnus-fetch-field "content-type"))
2681 (ctl (and ct (mail-header-parse-content-type ct))))
2682 (setq charset (and ctl
2683 (mail-content-type-get ctl 'charset)))
2684 (when (stringp charset)
2685 (setq charset (intern (downcase charset)))))))
2686 (unless charset
2687 (setq charset gnus-newsgroup-charset)))
2688 (article-goto-body)
2689 (save-window-excursion
2690 (save-restriction
2691 (narrow-to-region (point) (point-max))
2692 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2693 (entry (assq func mm-text-html-washer-alist)))
2694 (when entry
2695 (setq func (cdr entry)))
2696 (cond
2697 ((functionp func)
2698 (funcall func))
2700 (apply (car func) (cdr func))))))))))
2702 (defun gnus-article-wash-html-with-w3 ()
2703 "Wash the current buffer with w3."
2704 (mm-setup-w3)
2705 (let ((w3-strict-width (window-width))
2706 (url-standalone-mode t)
2707 (url-gateway-unplugged t)
2708 (w3-honor-stylesheets nil))
2709 (condition-case ()
2710 (w3-region (point-min) (point-max))
2711 (error))))
2713 (defun gnus-article-wash-html-with-w3m ()
2714 "Wash the current buffer with emacs-w3m."
2715 (mm-setup-w3m)
2716 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2717 w3m-force-redisplay)
2718 (w3m-region (point-min) (point-max)))
2719 (when (and mm-inline-text-html-with-w3m-keymap
2720 (boundp 'w3m-minor-mode-map)
2721 w3m-minor-mode-map)
2722 (add-text-properties
2723 (point-min) (point-max)
2724 (list 'keymap w3m-minor-mode-map
2725 ;; Put the mark meaning this part was rendered by emacs-w3m.
2726 'mm-inline-text-html-with-w3m t))))
2728 (defvar charset) ;; Bound by `article-wash-html'.
2730 (defun gnus-article-wash-html-with-w3m-standalone ()
2731 "Wash the current buffer with w3m."
2732 (if (mm-w3m-standalone-supports-m17n-p)
2733 (progn
2734 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2735 ;; The default.
2736 (setq charset 'iso-8859-1))
2737 (let ((coding-system-for-write charset)
2738 (coding-system-for-read charset))
2739 (call-process-region
2740 (point-min) (point-max)
2741 "w3m" t t nil "-dump" "-T" "text/html"
2742 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2743 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2745 (defvar gnus-article-browse-html-temp-list nil
2746 "List of temporary files created by `gnus-article-browse-html-parts'.
2747 Internal variable.")
2749 (defcustom gnus-article-browse-delete-temp 'ask
2750 "What to do with temporary files from `gnus-article-browse-html-parts'.
2751 If nil, don't delete temporary files. If it is t, delete them on
2752 exit from the summary buffer. If it is the symbol `file', query
2753 on each file, if it is `ask' ask once when exiting from the
2754 summary buffer."
2755 :group 'gnus-article
2756 :version "23.0" ;; No Gnus
2757 :type '(choice (const :tag "Don't delete" nil)
2758 (const :tag "Don't ask" t)
2759 (const :tag "Ask" ask)
2760 (const :tag "Ask for each file" file)))
2762 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2764 (defun gnus-article-browse-delete-temp-files (&optional how)
2765 "Delete temp-files created by `gnus-article-browse-html-parts'."
2766 (when (and gnus-article-browse-html-temp-list
2767 (or how
2768 (setq how gnus-article-browse-delete-temp)))
2769 (when (and (eq how 'ask)
2770 (y-or-n-p (format
2771 "Delete all %s temporary HTML file(s)? "
2772 (length gnus-article-browse-html-temp-list)))
2773 (setq how t)))
2774 (dolist (file gnus-article-browse-html-temp-list)
2775 (when (and (file-exists-p file)
2776 (or (eq how t)
2777 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2778 (gnus-y-or-n-p
2779 (format "Delete temporary HTML file `%s'? " file))))
2780 (delete-file file)))
2781 ;; Also remove file from the list when not deleted or if file doesn't
2782 ;; exist anymore.
2783 (setq gnus-article-browse-html-temp-list nil))
2784 gnus-article-browse-html-temp-list)
2786 (defun gnus-article-browse-html-parts (list)
2787 "View all \"text/html\" parts from LIST.
2788 Recurse into multiparts."
2789 ;; Internal function used by `gnus-article-browse-html-article'.
2790 (let ((showed))
2791 ;; Find and show the html-parts.
2792 (dolist (handle list)
2793 ;; If HTML, show it:
2794 (when (listp handle)
2795 (cond ((and (bufferp (car handle))
2796 (string-match "text/html" (car (mm-handle-type handle))))
2797 (let ((tmp-file (mm-make-temp-file
2798 ;; Do we need to care for 8.3 filenames?
2799 "mm-" nil ".html")))
2800 (mm-save-part-to-file handle tmp-file)
2801 (add-to-list 'gnus-article-browse-html-temp-list tmp-file)
2802 (add-hook 'gnus-summary-prepare-exit-hook
2803 'gnus-article-browse-delete-temp-files)
2804 (add-hook 'gnus-exit-gnus-hook
2805 (lambda ()
2806 (gnus-article-browse-delete-temp-files t)))
2807 ;; FIXME: Warn if there's an <img> tag?
2808 (browse-url-of-file tmp-file)
2809 (setq showed t)))
2810 ;; If multipart, recurse
2811 ((and (stringp (car handle))
2812 (string-match "^multipart/" (car handle))
2813 (setq showed
2814 (or showed
2815 (gnus-article-browse-html-parts handle))))))))
2816 showed))
2818 ;; FIXME: Documentation in texi/gnus.texi missing.
2819 (defun gnus-article-browse-html-article ()
2820 "View \"text/html\" parts of the current article with a WWW browser.
2822 Warning: Spammers use links to images in HTML articles to verify
2823 whether you have read the message. As
2824 `gnus-article-browse-html-article' passes the unmodified HTML
2825 content to the browser without eliminating these \"web bugs\" you
2826 should only use it for mails from trusted senders."
2827 ;; Cf. `mm-w3m-safe-url-regexp'
2828 (interactive)
2829 (save-window-excursion
2830 ;; Open raw article and select the buffer
2831 (gnus-summary-show-article t)
2832 (gnus-summary-select-article-buffer)
2833 (let ((parts (mm-dissect-buffer t t)))
2834 ;; If singlepart, enforce a list.
2835 (when (and (bufferp (car parts))
2836 (stringp (car (mm-handle-type parts))))
2837 (setq parts (list parts)))
2838 ;; Process the list
2839 (unless (gnus-article-browse-html-parts parts)
2840 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2841 (gnus-summary-show-article))))
2843 (defun article-hide-list-identifiers ()
2844 "Remove list identifies from the Subject header.
2845 The `gnus-list-identifiers' variable specifies what to do."
2846 (interactive)
2847 (let ((inhibit-point-motion-hooks t)
2848 (regexp (if (consp gnus-list-identifiers)
2849 (mapconcat 'identity gnus-list-identifiers " *\\|")
2850 gnus-list-identifiers))
2851 (inhibit-read-only t))
2852 (when regexp
2853 (save-excursion
2854 (save-restriction
2855 (article-narrow-to-head)
2856 (goto-char (point-min))
2857 (while (re-search-forward
2858 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2859 nil t)
2860 (delete-region (match-beginning 2) (match-end 0))
2861 (beginning-of-line))
2862 (when (re-search-forward
2863 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2864 (delete-region (match-beginning 1) (match-end 1))))))))
2866 (defun article-hide-pem (&optional arg)
2867 "Toggle hiding of any PEM headers and signatures in the current article.
2868 If given a negative prefix, always show; if given a positive prefix,
2869 always hide."
2870 (interactive (gnus-article-hidden-arg))
2871 (unless (gnus-article-check-hidden-text 'pem arg)
2872 (save-excursion
2873 (let ((inhibit-read-only t) end)
2874 (goto-char (point-min))
2875 ;; Hide the horrendously ugly "header".
2876 (when (and (search-forward
2877 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2878 nil t)
2879 (setq end (1+ (match-beginning 0))))
2880 (gnus-add-wash-type 'pem)
2881 (gnus-article-hide-text-type
2883 (if (search-forward "\n\n" nil t)
2884 (match-end 0)
2885 (point-max))
2886 'pem)
2887 ;; Hide the trailer as well
2888 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2889 nil t)
2890 (gnus-article-hide-text-type
2891 (match-beginning 0) (match-end 0) 'pem)))))))
2893 (defun article-strip-banner ()
2894 "Strip the banners specified by the `banner' group parameter and by
2895 `gnus-article-address-banner-alist'."
2896 (interactive)
2897 (save-excursion
2898 (save-restriction
2899 (let ((inhibit-point-motion-hooks t))
2900 (when (gnus-parameter-banner gnus-newsgroup-name)
2901 (article-really-strip-banner
2902 (gnus-parameter-banner gnus-newsgroup-name)))
2903 (when gnus-article-address-banner-alist
2904 ;; Note that the From header is decoded here, so it is
2905 ;; required that the *-extract-address-components function
2906 ;; supports non-ASCII text.
2907 (let ((from (save-restriction
2908 (widen)
2909 (article-narrow-to-head)
2910 (mail-fetch-field "from"))))
2911 (when (and from
2912 (setq from
2913 (cadr (funcall gnus-extract-address-components
2914 from))))
2915 (catch 'found
2916 (dolist (pair gnus-article-address-banner-alist)
2917 (when (string-match (car pair) from)
2918 (throw 'found
2919 (article-really-strip-banner (cdr pair)))))))))))))
2921 (defun article-really-strip-banner (banner)
2922 "Strip the banner specified by the argument."
2923 (save-excursion
2924 (save-restriction
2925 (let ((inhibit-point-motion-hooks t)
2926 (gnus-signature-limit nil)
2927 (inhibit-read-only t))
2928 (article-goto-body)
2929 (cond
2930 ((eq banner 'signature)
2931 (when (gnus-article-narrow-to-signature)
2932 (widen)
2933 (forward-line -1)
2934 (delete-region (point) (point-max))))
2935 ((symbolp banner)
2936 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2937 (while (re-search-forward banner nil t)
2938 (delete-region (match-beginning 0) (match-end 0)))))
2939 ((stringp banner)
2940 (while (re-search-forward banner nil t)
2941 (delete-region (match-beginning 0) (match-end 0)))))))))
2943 (defun article-babel ()
2944 "Translate article using an online translation service."
2945 (interactive)
2946 (require 'babel)
2947 (gnus-with-article-buffer
2948 (when (article-goto-body)
2949 (let* ((start (point))
2950 (end (point-max))
2951 (orig (buffer-substring start end))
2952 (trans (babel-as-string orig)))
2953 (save-restriction
2954 (narrow-to-region start end)
2955 (delete-region start end)
2956 (insert trans))))))
2958 (defun article-hide-signature (&optional arg)
2959 "Hide the signature in the current article.
2960 If given a negative prefix, always show; if given a positive prefix,
2961 always hide."
2962 (interactive (gnus-article-hidden-arg))
2963 (unless (gnus-article-check-hidden-text 'signature arg)
2964 (save-excursion
2965 (save-restriction
2966 (let ((inhibit-read-only t))
2967 (when (gnus-article-narrow-to-signature)
2968 (gnus-article-hide-text-type
2969 (point-min) (point-max) 'signature))))))
2970 (gnus-set-mode-line 'article))
2972 (defun article-strip-headers-in-body ()
2973 "Strip offensive headers from bodies."
2974 (interactive)
2975 (save-excursion
2976 (article-goto-body)
2977 (let ((case-fold-search t))
2978 (when (looking-at "x-no-archive:")
2979 (gnus-delete-line)))))
2981 (defun article-strip-leading-blank-lines ()
2982 "Remove all blank lines from the beginning of the article."
2983 (interactive)
2984 (save-excursion
2985 (let ((inhibit-point-motion-hooks t)
2986 (inhibit-read-only t))
2987 (when (article-goto-body)
2988 (while (and (not (eobp))
2989 (looking-at "[ \t]*$"))
2990 (gnus-delete-line))))))
2992 (defun article-narrow-to-head ()
2993 "Narrow the buffer to the head of the message.
2994 Point is left at the beginning of the narrowed-to region."
2995 (narrow-to-region
2996 (goto-char (point-min))
2997 (if (search-forward "\n\n" nil 1)
2998 (1- (point))
2999 (point-max)))
3000 (goto-char (point-min)))
3002 (defun article-goto-body ()
3003 "Place point at the start of the body."
3004 (goto-char (point-min))
3005 (cond
3006 ;; This variable is only bound when dealing with separate
3007 ;; MIME body parts.
3008 (article-goto-body-goes-to-point-min-p
3010 ((search-forward "\n\n" nil t)
3013 (goto-char (point-max))
3014 nil)))
3016 (defun article-strip-multiple-blank-lines ()
3017 "Replace consecutive blank lines with one empty line."
3018 (interactive)
3019 (save-excursion
3020 (let ((inhibit-point-motion-hooks t)
3021 (inhibit-read-only t))
3022 ;; First make all blank lines empty.
3023 (article-goto-body)
3024 (while (re-search-forward "^[ \t]+$" nil t)
3025 (unless (gnus-annotation-in-region-p
3026 (match-beginning 0) (match-end 0))
3027 (replace-match "" nil t)))
3028 ;; Then replace multiple empty lines with a single empty line.
3029 (article-goto-body)
3030 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3031 (unless (gnus-annotation-in-region-p
3032 (match-beginning 0) (match-end 0))
3033 (delete-region (match-beginning 1) (match-end 1)))))))
3035 (defun article-strip-leading-space ()
3036 "Remove all white space from the beginning of the lines in the article."
3037 (interactive)
3038 (save-excursion
3039 (let ((inhibit-point-motion-hooks t)
3040 (inhibit-read-only t))
3041 (article-goto-body)
3042 (while (re-search-forward "^[ \t]+" nil t)
3043 (replace-match "" t t)))))
3045 (defun article-strip-trailing-space ()
3046 "Remove all white space from the end of the lines in the article."
3047 (interactive)
3048 (save-excursion
3049 (let ((inhibit-point-motion-hooks t)
3050 (inhibit-read-only t))
3051 (article-goto-body)
3052 (while (re-search-forward "[ \t]+$" nil t)
3053 (replace-match "" t t)))))
3055 (defun article-strip-blank-lines ()
3056 "Strip leading, trailing and multiple blank lines."
3057 (interactive)
3058 (article-strip-leading-blank-lines)
3059 (article-remove-trailing-blank-lines)
3060 (article-strip-multiple-blank-lines))
3062 (defun article-strip-all-blank-lines ()
3063 "Strip all blank lines."
3064 (interactive)
3065 (save-excursion
3066 (let ((inhibit-point-motion-hooks t)
3067 (inhibit-read-only t))
3068 (article-goto-body)
3069 (while (re-search-forward "^[ \t]*\n" nil t)
3070 (replace-match "" t t)))))
3072 (defun gnus-article-narrow-to-signature ()
3073 "Narrow to the signature; return t if a signature is found, else nil."
3074 (let ((inhibit-point-motion-hooks t))
3075 (when (gnus-article-search-signature)
3076 (forward-line 1)
3077 ;; Check whether we have some limits to what we consider
3078 ;; to be a signature.
3079 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3080 (list gnus-signature-limit)))
3081 limit limited)
3082 (while (setq limit (pop limits))
3083 (if (or (and (integerp limit)
3084 (< (- (point-max) (point)) limit))
3085 (and (floatp limit)
3086 (< (count-lines (point) (point-max)) limit))
3087 (and (functionp limit)
3088 (funcall limit))
3089 (and (stringp limit)
3090 (not (re-search-forward limit nil t))))
3091 () ; This limit did not succeed.
3092 (setq limited t
3093 limits nil)))
3094 (unless limited
3095 (narrow-to-region (point) (point-max))
3096 t)))))
3098 (defun gnus-article-search-signature ()
3099 "Search the current buffer for the signature separator.
3100 Put point at the beginning of the signature separator."
3101 (let ((cur (point)))
3102 (goto-char (point-max))
3103 (if (if (stringp gnus-signature-separator)
3104 (re-search-backward gnus-signature-separator nil t)
3105 (let ((seps gnus-signature-separator))
3106 (while (and seps
3107 (not (re-search-backward (car seps) nil t)))
3108 (pop seps))
3109 seps))
3111 (goto-char cur)
3112 nil)))
3114 (defun gnus-article-hidden-arg ()
3115 "Return the current prefix arg as a number, or 0 if no prefix."
3116 (list (if current-prefix-arg
3117 (prefix-numeric-value current-prefix-arg)
3118 0)))
3120 (defun gnus-article-check-hidden-text (type arg)
3121 "Return nil if hiding is necessary.
3122 Arg can be nil or a number. nil and positive means hide, negative
3123 means show, 0 means toggle."
3124 (save-excursion
3125 (save-restriction
3126 (let ((hide (gnus-article-hidden-text-p type)))
3127 (cond
3128 ((or (null arg)
3129 (> arg 0))
3130 nil)
3131 ((< arg 0)
3132 (gnus-article-show-hidden-text type)
3135 (if (eq hide 'hidden)
3136 (progn
3137 (gnus-article-show-hidden-text type)
3139 nil)))))))
3141 (defun gnus-article-hidden-text-p (type)
3142 "Say whether the current buffer contains hidden text of type TYPE."
3143 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3144 (while (and pos
3145 (not (get-text-property pos 'invisible))
3146 (not (get-text-property pos 'dummy-invisible)))
3147 (setq pos
3148 (text-property-any (1+ pos) (point-max) 'article-type type)))
3149 (if pos
3150 'hidden
3151 nil)))
3153 (defun gnus-article-show-hidden-text (type &optional dummy)
3154 "Show all hidden text of type TYPE.
3155 Originally it is hide instead of DUMMY."
3156 (let ((inhibit-read-only t)
3157 (inhibit-point-motion-hooks t))
3158 (gnus-remove-text-properties-when
3159 'article-type type
3160 (point-min) (point-max)
3161 (cons 'article-type (cons type
3162 gnus-hidden-properties)))
3163 (gnus-delete-wash-type type)))
3165 (defconst article-time-units
3166 `((year . ,(* 365.25 24 60 60))
3167 (week . ,(* 7 24 60 60))
3168 (day . ,(* 24 60 60))
3169 (hour . ,(* 60 60))
3170 (minute . 60)
3171 (second . 1))
3172 "Mapping from time units to seconds.")
3174 (defun gnus-article-forward-header ()
3175 "Move point to the start of the next header.
3176 If the current header is a continuation header, this can be several
3177 lines forward."
3178 (let ((ended nil))
3179 (while (not ended)
3180 (forward-line 1)
3181 (if (looking-at "[ \t]+[^ \t]")
3182 (forward-line 1)
3183 (setq ended t)))))
3185 (defun article-date-ut (&optional type highlight)
3186 "Convert DATE date to universal time in the current article.
3187 If TYPE is `local', convert to local time; if it is `lapsed', output
3188 how much time has lapsed since DATE. For `lapsed', the value of
3189 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3190 should replace the \"Date:\" one, or should be added below it."
3191 (interactive (list 'ut t))
3192 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3193 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3194 tdate-regexp)
3195 ((eq type 'lapsed)
3196 "^X-Sent:[ \t]")
3197 (article-lapsed-timer
3198 "^Date:[ \t]")
3200 tdate-regexp)))
3201 (case-fold-search t)
3202 (inhibit-read-only t)
3203 (inhibit-point-motion-hooks t)
3204 pos date bface eface)
3205 (save-excursion
3206 (save-restriction
3207 (widen)
3208 (goto-char (point-min))
3209 (while (or (setq date (get-text-property (setq pos (point))
3210 'original-date))
3211 (when (setq pos (next-single-property-change
3212 (point) 'original-date))
3213 (setq date (get-text-property pos 'original-date))
3215 (narrow-to-region pos (or (text-property-any pos (point-max)
3216 'original-date nil)
3217 (point-max)))
3218 (goto-char (point-min))
3219 (when (re-search-forward tdate-regexp nil t)
3220 (setq bface (get-text-property (point-at-bol) 'face)
3221 eface (get-text-property (1- (point-at-eol)) 'face)))
3222 (goto-char (point-min))
3223 (setq pos nil)
3224 ;; Delete any old Date headers.
3225 (while (re-search-forward date-regexp nil t)
3226 (if pos
3227 (delete-region (point-at-bol) (progn
3228 (gnus-article-forward-header)
3229 (point)))
3230 (delete-region (point-at-bol) (progn
3231 (gnus-article-forward-header)
3232 (forward-char -1)
3233 (point)))
3234 (setq pos (point))))
3235 (when (and (not pos)
3236 (re-search-forward tdate-regexp nil t))
3237 (forward-line 1))
3238 (gnus-goto-char pos)
3239 (insert (article-make-date-line date (or type 'ut)))
3240 (unless pos
3241 (insert "\n")
3242 (forward-line -1))
3243 ;; Do highlighting.
3244 (beginning-of-line)
3245 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3246 (put-text-property (match-beginning 1) (1+ (match-end 1))
3247 'face bface)
3248 (put-text-property (match-beginning 2) (match-end 2)
3249 'face eface))
3250 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3251 (goto-char (point-max))
3252 (widen))))))
3254 (defun article-make-date-line (date type)
3255 "Return a DATE line of TYPE."
3256 (unless (memq type '(local ut original user iso8601 lapsed english))
3257 (error "Unknown conversion type: %s" type))
3258 (condition-case ()
3259 (let ((time (date-to-time date)))
3260 (cond
3261 ;; Convert to the local timezone.
3262 ((eq type 'local)
3263 (concat "Date: " (message-make-date time)))
3264 ;; Convert to Universal Time.
3265 ((eq type 'ut)
3266 (concat "Date: "
3267 (substring
3268 (message-make-date
3269 (let* ((e (parse-time-string date))
3270 (tm (apply 'encode-time e))
3271 (ms (car tm))
3272 (ls (- (cadr tm) (car (current-time-zone time)))))
3273 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3274 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3275 (t (list ms ls)))))
3276 0 -5)
3277 "UT"))
3278 ;; Get the original date from the article.
3279 ((eq type 'original)
3280 (concat "Date: " (if (string-match "\n+$" date)
3281 (substring date 0 (match-beginning 0))
3282 date)))
3283 ;; Let the user define the format.
3284 ((eq type 'user)
3285 (let ((format (or (condition-case nil
3286 (with-current-buffer gnus-summary-buffer
3287 gnus-article-time-format)
3288 (error nil))
3289 gnus-article-time-format)))
3290 (if (functionp format)
3291 (funcall format time)
3292 (concat "Date: " (format-time-string format time)))))
3293 ;; ISO 8601.
3294 ((eq type 'iso8601)
3295 (let ((tz (car (current-time-zone time))))
3296 (concat
3297 "Date: "
3298 (format-time-string "%Y%m%dT%H%M%S" time)
3299 (format "%s%02d%02d"
3300 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3301 (/ (% (abs tz) 3600) 60)))))
3302 ;; Do an X-Sent lapsed format.
3303 ((eq type 'lapsed)
3304 ;; If the date is seriously mangled, the timezone functions are
3305 ;; liable to bug out, so we ignore all errors.
3306 (let* ((now (current-time))
3307 (real-time (subtract-time now time))
3308 (real-sec (and real-time
3309 (+ (* (float (car real-time)) 65536)
3310 (cadr real-time))))
3311 (sec (and real-time (abs real-sec)))
3312 num prev)
3313 (cond
3314 ((null real-time)
3315 "X-Sent: Unknown")
3316 ((zerop sec)
3317 "X-Sent: Now")
3319 (concat
3320 "X-Sent: "
3321 ;; This is a bit convoluted, but basically we go
3322 ;; through the time units for years, weeks, etc,
3323 ;; and divide things to see whether that results
3324 ;; in positive answers.
3325 (mapconcat
3326 (lambda (unit)
3327 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3328 ;; The (remaining) seconds are too few to
3329 ;; be divided into this time unit.
3331 ;; It's big enough, so we output it.
3332 (setq sec (- sec (* num (cdr unit))))
3333 (prog1
3334 (concat (if prev ", " "") (int-to-string
3335 (floor num))
3336 " " (symbol-name (car unit))
3337 (if (> num 1) "s" ""))
3338 (setq prev t))))
3339 article-time-units "")
3340 ;; If dates are odd, then it might appear like the
3341 ;; article was sent in the future.
3342 (if (> real-sec 0)
3343 " ago"
3344 " in the future"))))))
3345 ;; Display the date in proper English
3346 ((eq type 'english)
3347 (let ((dtime (decode-time time)))
3348 (concat
3349 "Date: the "
3350 (number-to-string (nth 3 dtime))
3351 (let ((digit (% (nth 3 dtime) 10)))
3352 (cond
3353 ((memq (nth 3 dtime) '(11 12 13)) "th")
3354 ((= digit 1) "st")
3355 ((= digit 2) "nd")
3356 ((= digit 3) "rd")
3357 (t "th")))
3358 " of "
3359 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3361 (number-to-string (nth 5 dtime))
3362 " at "
3363 (format "%02d" (nth 2 dtime))
3365 (format "%02d" (nth 1 dtime)))))))
3366 (error
3367 (format "Date: %s (from Gnus)" date))))
3369 (defun article-date-local (&optional highlight)
3370 "Convert the current article date to the local timezone."
3371 (interactive (list t))
3372 (article-date-ut 'local highlight))
3374 (defun article-date-english (&optional highlight)
3375 "Convert the current article date to something that is proper English."
3376 (interactive (list t))
3377 (article-date-ut 'english highlight))
3379 (defun article-date-original (&optional highlight)
3380 "Convert the current article date to what it was originally.
3381 This is only useful if you have used some other date conversion
3382 function and want to see what the date was before converting."
3383 (interactive (list t))
3384 (article-date-ut 'original highlight))
3386 (defun article-date-lapsed (&optional highlight)
3387 "Convert the current article date to time lapsed since it was sent."
3388 (interactive (list t))
3389 (article-date-ut 'lapsed highlight))
3391 (defun article-update-date-lapsed ()
3392 "Function to be run from a timer to update the lapsed time line."
3393 (save-match-data
3394 (let (deactivate-mark)
3395 (save-excursion
3396 (ignore-errors
3397 (walk-windows
3398 (lambda (w)
3399 (set-buffer (window-buffer w))
3400 (when (eq major-mode 'gnus-article-mode)
3401 (let ((mark (point-marker)))
3402 (goto-char (point-min))
3403 (when (re-search-forward "^X-Sent:" nil t)
3404 (article-date-lapsed t))
3405 (goto-char (marker-position mark))
3406 (move-marker mark nil))))
3407 nil 'visible))))))
3409 (defun gnus-start-date-timer (&optional n)
3410 "Start a timer to update the X-Sent header in the article buffers.
3411 The numerical prefix says how frequently (in seconds) the function
3412 is to run."
3413 (interactive "p")
3414 (unless n
3415 (setq n 1))
3416 (gnus-stop-date-timer)
3417 (setq article-lapsed-timer
3418 (run-at-time 1 n 'article-update-date-lapsed)))
3420 (defun gnus-stop-date-timer ()
3421 "Stop the X-Sent timer."
3422 (interactive)
3423 (when article-lapsed-timer
3424 (nnheader-cancel-timer article-lapsed-timer)
3425 (setq article-lapsed-timer nil)))
3427 (defun article-date-user (&optional highlight)
3428 "Convert the current article date to the user-defined format.
3429 This format is defined by the `gnus-article-time-format' variable."
3430 (interactive (list t))
3431 (article-date-ut 'user highlight))
3433 (defun article-date-iso8601 (&optional highlight)
3434 "Convert the current article date to ISO8601."
3435 (interactive (list t))
3436 (article-date-ut 'iso8601 highlight))
3438 (defmacro gnus-article-save-original-date (&rest forms)
3439 "Save the original date as a text property and evaluate FORMS."
3440 `(let* ((case-fold-search t)
3441 (start (progn
3442 (goto-char (point-min))
3443 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3444 (not (bolp)))
3445 (match-end 0))))
3446 (date (when (and start
3447 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3448 nil t))
3449 (buffer-substring-no-properties start
3450 (match-beginning 0)))))
3451 (goto-char (point-max))
3452 (skip-chars-backward "\n")
3453 (put-text-property (point-min) (point) 'original-date date)
3454 ,@forms
3455 (goto-char (point-max))
3456 (skip-chars-backward "\n")
3457 (put-text-property (point-min) (point) 'original-date date)))
3459 ;; (defun article-show-all ()
3460 ;; "Show all hidden text in the article buffer."
3461 ;; (interactive)
3462 ;; (save-excursion
3463 ;; (let ((inhibit-read-only t))
3464 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3466 (defun article-remove-leading-whitespace ()
3467 "Remove excessive whitespace from all headers."
3468 (interactive)
3469 (save-excursion
3470 (save-restriction
3471 (let ((inhibit-read-only t))
3472 (article-narrow-to-head)
3473 (goto-char (point-min))
3474 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3475 (delete-region (match-beginning 1) (match-end 1)))))))
3477 (defun article-emphasize (&optional arg)
3478 "Emphasize text according to `gnus-emphasis-alist'."
3479 (interactive (gnus-article-hidden-arg))
3480 (unless (gnus-article-check-hidden-text 'emphasis arg)
3481 (save-excursion
3482 (let ((alist (or
3483 (condition-case nil
3484 (with-current-buffer gnus-summary-buffer
3485 gnus-article-emphasis-alist)
3486 (error))
3487 gnus-emphasis-alist))
3488 (inhibit-read-only t)
3489 (props (append '(article-type emphasis)
3490 gnus-hidden-properties))
3491 regexp elem beg invisible visible face)
3492 (article-goto-body)
3493 (setq beg (point))
3494 (while (setq elem (pop alist))
3495 (goto-char beg)
3496 (setq regexp (car elem)
3497 invisible (nth 1 elem)
3498 visible (nth 2 elem)
3499 face (nth 3 elem))
3500 (while (re-search-forward regexp nil t)
3501 (when (and (match-beginning visible) (match-beginning invisible))
3502 (gnus-article-hide-text
3503 (match-beginning invisible) (match-end invisible) props)
3504 (gnus-article-unhide-text-type
3505 (match-beginning visible) (match-end visible) 'emphasis)
3506 (gnus-put-overlay-excluding-newlines
3507 (match-beginning visible) (match-end visible) 'face face)
3508 (gnus-add-wash-type 'emphasis)
3509 (goto-char (match-end invisible)))))))))
3511 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3512 "Setup newsgroup emphasis alist."
3513 (unless gnus-article-emphasis-alist
3514 (let ((name (and gnus-newsgroup-name
3515 (gnus-group-real-name gnus-newsgroup-name))))
3516 (make-local-variable 'gnus-article-emphasis-alist)
3517 (setq gnus-article-emphasis-alist
3518 (nconc
3519 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3520 (while (setq elem (pop alist))
3521 (when (and name (string-match (car elem) name))
3522 (setq alist nil
3523 highlight (copy-sequence (cdr elem)))))
3524 highlight)
3525 (copy-sequence highlight-words)
3526 (if gnus-newsgroup-name
3527 (copy-sequence (gnus-group-find-parameter
3528 gnus-newsgroup-name 'highlight-words t)))
3529 gnus-emphasis-alist)))))
3531 (defvar gnus-summary-article-menu)
3532 (defvar gnus-summary-post-menu)
3534 ;;; Saving functions.
3536 (defun gnus-article-save (save-buffer file &optional num)
3537 "Save the currently selected article."
3538 (when (or (get gnus-default-article-saver :headers)
3539 (not gnus-save-all-headers))
3540 ;; Remove headers according to `gnus-saved-headers' or the value
3541 ;; of the `:headers' property that the saver function might have.
3542 (let ((gnus-visible-headers
3543 (or (symbol-value (get gnus-default-article-saver :headers))
3544 gnus-saved-headers gnus-visible-headers))
3545 (gnus-article-buffer save-buffer))
3546 (save-excursion
3547 (set-buffer save-buffer)
3548 (article-hide-headers 1 t))))
3549 (save-window-excursion
3550 (if (not gnus-default-article-saver)
3551 (error "No default saver is defined")
3552 ;; !!! Magic! The saving functions all save
3553 ;; `gnus-save-article-buffer' (or so they think), but we
3554 ;; bind that variable to our save-buffer.
3555 (set-buffer gnus-article-buffer)
3556 (let* ((gnus-save-article-buffer save-buffer)
3557 (filename
3558 (cond
3559 ((not gnus-prompt-before-saving) 'default)
3560 ((eq gnus-prompt-before-saving 'always) nil)
3561 (t file)))
3562 (gnus-number-of-articles-to-be-saved
3563 (when (eq gnus-prompt-before-saving t)
3564 num))) ; Magic
3565 (set-buffer gnus-article-current-summary)
3566 (funcall gnus-default-article-saver filename)))))
3568 (defun gnus-read-save-file-name (prompt &optional filename
3569 function group headers variable
3570 dir-var)
3571 (let ((default-name
3572 (funcall function group headers (symbol-value variable)))
3573 result)
3574 (setq result
3575 (expand-file-name
3576 (cond
3577 ((eq filename 'default)
3578 default-name)
3579 ((eq filename t)
3580 default-name)
3581 (filename filename)
3583 (when (symbol-value dir-var)
3584 (setq default-name (expand-file-name
3585 (file-name-nondirectory default-name)
3586 (symbol-value dir-var))))
3587 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3588 (prompt
3589 (format prompt
3590 (if (and gnus-number-of-articles-to-be-saved
3591 (> gnus-number-of-articles-to-be-saved 1))
3592 (format "these %d articles"
3593 gnus-number-of-articles-to-be-saved)
3594 "this article")))
3595 (file
3596 ;; Let the split methods have their say.
3597 (cond
3598 ;; No split name was found.
3599 ((null split-name)
3600 (read-file-name
3601 (concat prompt " (default "
3602 (file-name-nondirectory default-name) "): ")
3603 (file-name-directory default-name)
3604 default-name))
3605 ;; A single group name is returned.
3606 ((stringp split-name)
3607 (setq default-name
3608 (funcall function split-name headers
3609 (symbol-value variable)))
3610 (read-file-name
3611 (concat prompt " (default "
3612 (file-name-nondirectory default-name) "): ")
3613 (file-name-directory default-name)
3614 default-name))
3615 ;; A single split name was found
3616 ((= 1 (length split-name))
3617 (let* ((name (expand-file-name
3618 (car split-name)
3619 gnus-article-save-directory))
3620 (dir (cond ((file-directory-p name)
3621 (file-name-as-directory name))
3622 ((file-exists-p name) name)
3623 (t gnus-article-save-directory))))
3624 (read-file-name
3625 (concat prompt " (default " name "): ")
3626 dir name)))
3627 ;; A list of splits was found.
3629 (setq split-name (nreverse split-name))
3630 (let (result)
3631 (let ((file-name-history
3632 (nconc split-name file-name-history)))
3633 (setq result
3634 (expand-file-name
3635 (read-file-name
3636 (concat prompt " (`M-p' for defaults): ")
3637 gnus-article-save-directory
3638 (car split-name))
3639 gnus-article-save-directory)))
3640 (car (push result file-name-history)))))))
3641 ;; Create the directory.
3642 (gnus-make-directory (file-name-directory file))
3643 ;; If we have read a directory, we append the default file name.
3644 (when (file-directory-p file)
3645 (setq file (expand-file-name (file-name-nondirectory
3646 default-name)
3647 (file-name-as-directory file))))
3648 ;; Possibly translate some characters.
3649 (nnheader-translate-file-chars file))))))
3650 (gnus-make-directory (file-name-directory result))
3651 (when variable
3652 (set variable result))
3653 (when dir-var
3654 (set dir-var (file-name-directory result)))
3655 result))
3657 (defun gnus-article-archive-name (group)
3658 "Return the first instance of an \"Archive-name\" in the current buffer."
3659 (let ((case-fold-search t))
3660 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3661 (nnheader-concat gnus-article-save-directory
3662 (match-string 1)))))
3664 (defun gnus-article-nndoc-name (group)
3665 "If GROUP is an nndoc group, return the name of the parent group."
3666 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3667 (gnus-group-get-parameter group 'save-article-group)))
3669 (defun gnus-summary-save-in-rmail (&optional filename)
3670 "Append this article to Rmail file.
3671 Optional argument FILENAME specifies file name.
3672 Directory to save to is default to `gnus-article-save-directory'."
3673 (setq filename (gnus-read-save-file-name
3674 "Save %s in rmail file" filename
3675 gnus-rmail-save-name gnus-newsgroup-name
3676 gnus-current-headers 'gnus-newsgroup-last-rmail))
3677 (gnus-eval-in-buffer-window gnus-save-article-buffer
3678 (save-excursion
3679 (save-restriction
3680 (widen)
3681 (gnus-output-to-rmail filename))))
3682 filename)
3684 (defun gnus-summary-save-in-mail (&optional filename)
3685 "Append this article to Unix mail file.
3686 Optional argument FILENAME specifies file name.
3687 Directory to save to is default to `gnus-article-save-directory'."
3688 (setq filename (gnus-read-save-file-name
3689 "Save %s in Unix mail file" filename
3690 gnus-mail-save-name gnus-newsgroup-name
3691 gnus-current-headers 'gnus-newsgroup-last-mail))
3692 (gnus-eval-in-buffer-window gnus-save-article-buffer
3693 (save-excursion
3694 (save-restriction
3695 (widen)
3696 (if (and (file-readable-p filename)
3697 (file-regular-p filename)
3698 (mail-file-babyl-p filename))
3699 (rmail-output-to-rmail-file filename t)
3700 (gnus-output-to-mail filename)))))
3701 filename)
3703 (put 'gnus-summary-save-in-file :decode t)
3704 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3705 (defun gnus-summary-save-in-file (&optional filename overwrite)
3706 "Append this article to file.
3707 Optional argument FILENAME specifies file name.
3708 Directory to save to is default to `gnus-article-save-directory'."
3709 (setq filename (gnus-read-save-file-name
3710 "Save %s in file" filename
3711 gnus-file-save-name gnus-newsgroup-name
3712 gnus-current-headers 'gnus-newsgroup-last-file))
3713 (gnus-eval-in-buffer-window gnus-save-article-buffer
3714 (save-excursion
3715 (save-restriction
3716 (widen)
3717 (when (and overwrite
3718 (file-exists-p filename))
3719 (delete-file filename))
3720 (gnus-output-to-file filename))))
3721 filename)
3723 (put 'gnus-summary-write-to-file :decode t)
3724 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3725 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3726 (defun gnus-summary-write-to-file (&optional filename)
3727 "Write this article to a file, overwriting it if the file exists.
3728 Optional argument FILENAME specifies file name.
3729 The directory to save in defaults to `gnus-article-save-directory'."
3730 (setq filename (gnus-read-save-file-name
3731 "Save %s in file" filename
3732 gnus-file-save-name gnus-newsgroup-name
3733 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3734 (gnus-summary-save-in-file filename t))
3736 (put 'gnus-summary-save-body-in-file :decode t)
3737 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3738 "Append this article body to a file.
3739 Optional argument FILENAME specifies file name.
3740 The directory to save in defaults to `gnus-article-save-directory'."
3741 (setq filename (gnus-read-save-file-name
3742 "Save %s body in file" filename
3743 gnus-file-save-name gnus-newsgroup-name
3744 gnus-current-headers 'gnus-newsgroup-last-file))
3745 (gnus-eval-in-buffer-window gnus-save-article-buffer
3746 (save-excursion
3747 (save-restriction
3748 (widen)
3749 (when (article-goto-body)
3750 (narrow-to-region (point) (point-max)))
3751 (when (and overwrite
3752 (file-exists-p filename))
3753 (delete-file filename))
3754 (gnus-output-to-file filename))))
3755 filename)
3757 (put 'gnus-summary-write-body-to-file :decode t)
3758 (put 'gnus-summary-write-body-to-file
3759 :function 'gnus-summary-save-body-in-file)
3760 (defun gnus-summary-write-body-to-file (&optional filename)
3761 "Write this article body to a file, overwriting it if the file exists.
3762 Optional argument FILENAME specifies file name.
3763 The directory to save in defaults to `gnus-article-save-directory'."
3764 (setq filename (gnus-read-save-file-name
3765 "Save %s body in file" filename
3766 gnus-file-save-name gnus-newsgroup-name
3767 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3768 (gnus-summary-save-body-in-file filename t))
3770 (defun gnus-summary-save-in-pipe (&optional command)
3771 "Pipe this article to subprocess."
3772 (setq command
3773 (cond ((and (eq command 'default)
3774 gnus-last-shell-command)
3775 gnus-last-shell-command)
3776 ((stringp command)
3777 command)
3778 (t (read-string
3779 (format
3780 "Shell command on %s: "
3781 (if (and gnus-number-of-articles-to-be-saved
3782 (> gnus-number-of-articles-to-be-saved 1))
3783 (format "these %d articles"
3784 gnus-number-of-articles-to-be-saved)
3785 "this article"))
3786 gnus-last-shell-command))))
3787 (when (string-equal command "")
3788 (if gnus-last-shell-command
3789 (setq command gnus-last-shell-command)
3790 (error "A command is required")))
3791 (gnus-eval-in-buffer-window gnus-article-buffer
3792 (save-restriction
3793 (widen)
3794 (shell-command-on-region (point-min) (point-max) command nil)))
3795 (setq gnus-last-shell-command command))
3797 (defun gnus-summary-pipe-to-muttprint (&optional command)
3798 "Pipe this article to muttprint."
3799 (setq command (read-string
3800 "Print using command: " gnus-summary-muttprint-program
3801 nil gnus-summary-muttprint-program))
3802 (gnus-summary-save-in-pipe command))
3804 ;;; Article file names when saving.
3806 (defun gnus-capitalize-newsgroup (newsgroup)
3807 "Capitalize NEWSGROUP name."
3808 (when (not (zerop (length newsgroup)))
3809 (concat (char-to-string (upcase (aref newsgroup 0)))
3810 (substring newsgroup 1))))
3812 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3813 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3814 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3815 Otherwise, it is like ~/News/news/group/num."
3816 (let ((default
3817 (expand-file-name
3818 (concat (if (gnus-use-long-file-name 'not-save)
3819 (gnus-capitalize-newsgroup newsgroup)
3820 (gnus-newsgroup-directory-form newsgroup))
3821 "/" (int-to-string (mail-header-number headers)))
3822 gnus-article-save-directory)))
3823 (if (and last-file
3824 (string-equal (file-name-directory default)
3825 (file-name-directory last-file))
3826 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3827 default
3828 (or last-file default))))
3830 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3831 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3832 If variable `gnus-use-long-file-name' is non-nil, it is
3833 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3834 (let ((default
3835 (expand-file-name
3836 (concat (if (gnus-use-long-file-name 'not-save)
3837 newsgroup
3838 (gnus-newsgroup-directory-form newsgroup))
3839 "/" (int-to-string (mail-header-number headers)))
3840 gnus-article-save-directory)))
3841 (if (and last-file
3842 (string-equal (file-name-directory default)
3843 (file-name-directory last-file))
3844 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3845 default
3846 (or last-file default))))
3848 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3849 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3850 If variable `gnus-use-long-file-name' is non-nil, it is
3851 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3852 (or last-file
3853 (expand-file-name
3854 (if (gnus-use-long-file-name 'not-save)
3855 newsgroup
3856 (file-relative-name
3857 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3858 default-directory))
3859 gnus-article-save-directory)))
3861 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3862 "Generate file name from sender."
3863 (let ((from (mail-header-from headers)))
3864 (expand-file-name
3865 (if (and from (string-match "\\([^ <]+\\)@" from))
3866 (match-string 1 from)
3867 "nobody")
3868 gnus-article-save-directory)))
3870 (defun article-verify-x-pgp-sig ()
3871 "Verify X-PGP-Sig."
3872 (interactive)
3873 (if (gnus-buffer-live-p gnus-original-article-buffer)
3874 (let ((sig (with-current-buffer gnus-original-article-buffer
3875 (gnus-fetch-field "X-PGP-Sig")))
3876 items info headers)
3877 (when (and sig
3878 mml2015-use
3879 (mml2015-clear-verify-function))
3880 (with-temp-buffer
3881 (insert-buffer-substring gnus-original-article-buffer)
3882 (setq items (split-string sig))
3883 (message-narrow-to-head)
3884 (let ((inhibit-point-motion-hooks t)
3885 (case-fold-search t))
3886 ;; Don't verify multiple headers.
3887 (setq headers (mapconcat (lambda (header)
3888 (concat header ": "
3889 (mail-fetch-field header)
3890 "\n"))
3891 (split-string (nth 1 items) ",") "")))
3892 (delete-region (point-min) (point-max))
3893 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3894 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3895 (insert headers)
3896 (widen)
3897 (forward-line)
3898 (while (not (eobp))
3899 (if (looking-at "^-")
3900 (insert "- "))
3901 (forward-line))
3902 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3903 (insert "Version: " (car items) "\n\n")
3904 (insert (mapconcat 'identity (cddr items) "\n"))
3905 (insert "\n-----END PGP SIGNATURE-----\n")
3906 (let ((mm-security-handle (list (format "multipart/signed"))))
3907 (mml2015-clean-buffer)
3908 (let ((coding-system-for-write (or gnus-newsgroup-charset
3909 'iso-8859-1)))
3910 (funcall (mml2015-clear-verify-function)))
3911 (setq info
3912 (or (mm-handle-multipart-ctl-parameter
3913 mm-security-handle 'gnus-details)
3914 (mm-handle-multipart-ctl-parameter
3915 mm-security-handle 'gnus-info)))))
3916 (when info
3917 (let ((inhibit-read-only t) bface eface)
3918 (save-restriction
3919 (message-narrow-to-head)
3920 (goto-char (point-max))
3921 (forward-line -1)
3922 (setq bface (get-text-property (point-at-bol) 'face)
3923 eface (get-text-property (1- (point-at-eol)) 'face))
3924 (message-remove-header "X-Gnus-PGP-Verify")
3925 (if (re-search-forward "^X-PGP-Sig:" nil t)
3926 (forward-line)
3927 (goto-char (point-max)))
3928 (narrow-to-region (point) (point))
3929 (insert "X-Gnus-PGP-Verify: " info "\n")
3930 (goto-char (point-min))
3931 (forward-line)
3932 (while (not (eobp))
3933 (if (not (looking-at "^[ \t]"))
3934 (insert " "))
3935 (forward-line))
3936 ;; Do highlighting.
3937 (goto-char (point-min))
3938 (when (looking-at "\\([^:]+\\): *")
3939 (put-text-property (match-beginning 1) (1+ (match-end 1))
3940 'face bface)
3941 (put-text-property (match-end 0) (point-max)
3942 'face eface)))))))))
3944 (defun article-verify-cancel-lock ()
3945 "Verify Cancel-Lock header."
3946 (interactive)
3947 (if (gnus-buffer-live-p gnus-original-article-buffer)
3948 (canlock-verify gnus-original-article-buffer)))
3950 (eval-and-compile
3951 (mapc
3952 (lambda (func)
3953 (let (afunc gfunc)
3954 (if (consp func)
3955 (setq afunc (car func)
3956 gfunc (cdr func))
3957 (setq afunc func
3958 gfunc (intern (format "gnus-%s" func))))
3959 (defalias gfunc
3960 (when (fboundp afunc)
3961 `(lambda (&optional interactive &rest args)
3962 ,(documentation afunc t)
3963 (interactive (list t))
3964 (save-excursion
3965 (set-buffer gnus-article-buffer)
3966 (if interactive
3967 (call-interactively ',afunc)
3968 (apply ',afunc args))))))))
3969 '(article-hide-headers
3970 article-verify-x-pgp-sig
3971 article-verify-cancel-lock
3972 article-hide-boring-headers
3973 article-treat-overstrike
3974 article-treat-ansi-sequences
3975 article-fill-long-lines
3976 article-capitalize-sentences
3977 article-remove-cr
3978 article-remove-leading-whitespace
3979 article-display-x-face
3980 article-display-face
3981 article-de-quoted-unreadable
3982 article-de-base64-unreadable
3983 article-decode-HZ
3984 article-wash-html
3985 article-unsplit-urls
3986 article-hide-list-identifiers
3987 article-strip-banner
3988 article-babel
3989 article-hide-pem
3990 article-hide-signature
3991 article-strip-headers-in-body
3992 article-remove-trailing-blank-lines
3993 article-strip-leading-blank-lines
3994 article-strip-multiple-blank-lines
3995 article-strip-leading-space
3996 article-strip-trailing-space
3997 article-strip-blank-lines
3998 article-strip-all-blank-lines
3999 article-date-local
4000 article-date-english
4001 article-date-iso8601
4002 article-date-original
4003 article-date-ut
4004 article-decode-mime-words
4005 article-decode-charset
4006 article-decode-encoded-words
4007 article-date-user
4008 article-date-lapsed
4009 article-emphasize
4010 article-treat-dumbquotes
4011 article-normalize-headers
4012 ;;(article-show-all . gnus-article-show-all-headers)
4016 ;;; Gnus article mode
4019 (put 'gnus-article-mode 'mode-class 'special)
4021 (set-keymap-parent gnus-article-mode-map widget-keymap)
4023 (gnus-define-keys gnus-article-mode-map
4024 " " gnus-article-goto-next-page
4025 "\177" gnus-article-goto-prev-page
4026 [delete] gnus-article-goto-prev-page
4027 [backspace] gnus-article-goto-prev-page
4028 "\C-c^" gnus-article-refer-article
4029 "h" gnus-article-show-summary
4030 "s" gnus-article-show-summary
4031 "\C-c\C-m" gnus-article-mail
4032 "?" gnus-article-describe-briefly
4033 "e" gnus-summary-edit-article
4034 "<" beginning-of-buffer
4035 ">" end-of-buffer
4036 "\C-c\C-i" gnus-info-find-node
4037 "\C-c\C-b" gnus-bug
4038 "R" gnus-article-reply-with-original
4039 "F" gnus-article-followup-with-original
4040 "\C-hk" gnus-article-describe-key
4041 "\C-hc" gnus-article-describe-key-briefly
4043 "\C-d" gnus-article-read-summary-keys
4044 "\M-*" gnus-article-read-summary-keys
4045 "\M-#" gnus-article-read-summary-keys
4046 "\M-^" gnus-article-read-summary-keys
4047 "\M-g" gnus-article-read-summary-keys)
4049 (substitute-key-definition
4050 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4052 (defun gnus-article-make-menu-bar ()
4053 (unless (boundp 'gnus-article-commands-menu)
4054 (gnus-summary-make-menu-bar))
4055 (gnus-turn-off-edit-menu 'article)
4056 (unless (boundp 'gnus-article-article-menu)
4057 (easy-menu-define
4058 gnus-article-article-menu gnus-article-mode-map ""
4059 '("Article"
4060 ["Scroll forwards" gnus-article-goto-next-page t]
4061 ["Scroll backwards" gnus-article-goto-prev-page t]
4062 ["Show summary" gnus-article-show-summary t]
4063 ["Fetch Message-ID at point" gnus-article-refer-article t]
4064 ["Mail to address at point" gnus-article-mail t]
4065 ["Send a bug report" gnus-bug t]))
4067 (easy-menu-define
4068 gnus-article-treatment-menu gnus-article-mode-map ""
4069 ;; Fixme: this should use :active (and maybe :visible).
4070 '("Treatment"
4071 ["Hide headers" gnus-article-hide-headers t]
4072 ["Hide signature" gnus-article-hide-signature t]
4073 ["Hide citation" gnus-article-hide-citation t]
4074 ["Treat overstrike" gnus-article-treat-overstrike t]
4075 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4076 ["Remove carriage return" gnus-article-remove-cr t]
4077 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4078 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4079 ["Remove base64" gnus-article-de-base64-unreadable t]
4080 ["Treat html" gnus-article-wash-html t]
4081 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4082 ["Decode HZ" gnus-article-decode-HZ t]))
4084 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4086 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4088 (gnus-run-hooks 'gnus-article-menu-hook)))
4090 (defun gnus-article-mode ()
4091 "Major mode for displaying an article.
4093 All normal editing commands are switched off.
4095 The following commands are available in addition to all summary mode
4096 commands:
4097 \\<gnus-article-mode-map>
4098 \\[gnus-article-next-page]\t Scroll the article one page forwards
4099 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4100 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4101 \\[gnus-article-show-summary]\t Display the summary buffer
4102 \\[gnus-article-mail]\t Send a reply to the address near point
4103 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4104 \\[gnus-info-find-node]\t Go to the Gnus info node"
4105 (interactive)
4106 (kill-all-local-variables)
4107 (gnus-simplify-mode-line)
4108 (setq mode-name "Article")
4109 (setq major-mode 'gnus-article-mode)
4110 (make-local-variable 'minor-mode-alist)
4111 (use-local-map gnus-article-mode-map)
4112 (when (gnus-visual-p 'article-menu 'menu)
4113 (gnus-article-make-menu-bar)
4114 (when gnus-summary-tool-bar-map
4115 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4116 (gnus-update-format-specifications nil 'article-mode)
4117 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4118 (set (make-local-variable 'gnus-page-broken) nil)
4119 (make-local-variable 'gnus-button-marker-list)
4120 (make-local-variable 'gnus-article-current-summary)
4121 (make-local-variable 'gnus-article-mime-handles)
4122 (make-local-variable 'gnus-article-decoded-p)
4123 (make-local-variable 'gnus-article-mime-handle-alist)
4124 (make-local-variable 'gnus-article-wash-types)
4125 (make-local-variable 'gnus-article-image-alist)
4126 (make-local-variable 'gnus-article-charset)
4127 (make-local-variable 'gnus-article-ignored-charsets)
4128 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4129 ;; face.
4130 (set (make-local-variable 'nobreak-char-display) nil)
4131 (setq cursor-in-non-selected-windows nil)
4132 (setq truncate-lines gnus-article-truncate-lines)
4133 (gnus-set-default-directory)
4134 (buffer-disable-undo)
4135 (setq buffer-read-only t
4136 show-trailing-whitespace nil)
4137 (set-syntax-table gnus-article-mode-syntax-table)
4138 (mm-enable-multibyte)
4139 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4141 (defvar gnus-button-marker-list nil
4142 "Regexp matching any of the regexps from `gnus-button-alist'.
4143 Internal variable.")
4145 (defun gnus-article-setup-buffer ()
4146 "Initialize the article buffer."
4147 (let* ((name (if gnus-single-article-buffer "*Article*"
4148 (concat "*Article " gnus-newsgroup-name "*")))
4149 (original
4150 (progn (string-match "\\*Article" name)
4151 (concat " *Original Article"
4152 (substring name (match-end 0))))))
4153 (setq gnus-article-buffer name)
4154 (setq gnus-original-article-buffer original)
4155 (setq gnus-article-mime-handle-alist nil)
4156 (with-current-buffer gnus-summary-buffer
4157 ;; This might be a variable local to the summary buffer.
4158 (unless gnus-single-article-buffer
4159 (setq gnus-article-buffer name)
4160 (setq gnus-original-article-buffer original)
4161 (gnus-set-global-variables)))
4162 (gnus-article-setup-highlight-words)
4163 ;; Init original article buffer.
4164 (save-excursion
4165 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4166 (mm-enable-multibyte)
4167 (setq major-mode 'gnus-original-article-mode)
4168 (make-local-variable 'gnus-original-article))
4169 (if (and (get-buffer name)
4170 (with-current-buffer name
4171 (if gnus-article-edit-mode
4172 (if (y-or-n-p "Article mode edit in progress; discard? ")
4173 (progn
4174 (set-buffer-modified-p nil)
4175 (gnus-kill-buffer name)
4176 (message "")
4177 nil)
4178 (error "Action aborted"))
4179 t)))
4180 (save-excursion
4181 (set-buffer name)
4182 (set (make-local-variable 'gnus-article-edit-mode) nil)
4183 (when gnus-article-mime-handles
4184 (mm-destroy-parts gnus-article-mime-handles)
4185 (setq gnus-article-mime-handles nil))
4186 ;; Set it to nil in article-buffer!
4187 (setq gnus-article-mime-handle-alist nil)
4188 (buffer-disable-undo)
4189 (setq buffer-read-only t)
4190 ;; This list just keeps growing if we don't reset it.
4191 (setq gnus-button-marker-list nil)
4192 (unless (eq major-mode 'gnus-article-mode)
4193 (gnus-article-mode))
4194 (current-buffer))
4195 (save-excursion
4196 (set-buffer (gnus-get-buffer-create name))
4197 (gnus-article-mode)
4198 (make-local-variable 'gnus-summary-buffer)
4199 (setq gnus-summary-buffer
4200 (gnus-summary-buffer-name gnus-newsgroup-name))
4201 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4202 (current-buffer)))))
4204 ;; Set article window start at LINE, where LINE is the number of lines
4205 ;; from the head of the article.
4206 (defun gnus-article-set-window-start (&optional line)
4207 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4208 (when article-window
4209 (set-window-start
4210 article-window
4211 (save-excursion
4212 (set-buffer gnus-article-buffer)
4213 (goto-char (point-min))
4214 (if (not line)
4215 (point-min)
4216 (gnus-message 6 "Moved to bookmark")
4217 (search-forward "\n\n" nil t)
4218 (forward-line line)
4219 (point)))))))
4221 (defun gnus-article-prepare (article &optional all-headers header)
4222 "Prepare ARTICLE in article mode buffer.
4223 ARTICLE should either be an article number or a Message-ID.
4224 If ARTICLE is an id, HEADER should be the article headers.
4225 If ALL-HEADERS is non-nil, no headers are hidden."
4226 (save-excursion
4227 ;; Make sure we start in a summary buffer.
4228 (unless (eq major-mode 'gnus-summary-mode)
4229 (set-buffer gnus-summary-buffer))
4230 (setq gnus-summary-buffer (current-buffer))
4231 (let* ((gnus-article (if header (mail-header-number header) article))
4232 (summary-buffer (current-buffer))
4233 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4234 (group gnus-newsgroup-name)
4235 result)
4236 (save-excursion
4237 (gnus-article-setup-buffer)
4238 (set-buffer gnus-article-buffer)
4239 ;; Deactivate active regions.
4240 (when (and (boundp 'transient-mark-mode)
4241 transient-mark-mode)
4242 (setq mark-active nil))
4243 (if (not (setq result (let ((inhibit-read-only t))
4244 (gnus-request-article-this-buffer
4245 article group))))
4246 ;; There is no such article.
4247 (save-excursion
4248 (when (and (numberp article)
4249 (not (memq article gnus-newsgroup-sparse)))
4250 (setq gnus-article-current
4251 (cons gnus-newsgroup-name article))
4252 (set-buffer gnus-summary-buffer)
4253 (setq gnus-current-article article)
4254 (if (and (memq article gnus-newsgroup-undownloaded)
4255 (not (gnus-online (gnus-find-method-for-group
4256 gnus-newsgroup-name))))
4257 (progn
4258 (gnus-summary-set-agent-mark article)
4259 (message "Message marked for downloading"))
4260 (gnus-summary-mark-article article gnus-canceled-mark)
4261 (unless (memq article gnus-newsgroup-sparse)
4262 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4263 (if (or (eq result 'pseudo)
4264 (eq result 'nneething))
4265 (progn
4266 (save-excursion
4267 (set-buffer summary-buffer)
4268 (push article gnus-newsgroup-history)
4269 (setq gnus-last-article gnus-current-article
4270 gnus-current-article 0
4271 gnus-current-headers nil
4272 gnus-article-current nil)
4273 (if (eq result 'nneething)
4274 (gnus-configure-windows 'summary)
4275 (gnus-configure-windows 'article))
4276 (gnus-set-global-variables))
4277 (let ((gnus-article-mime-handle-alist-1
4278 gnus-article-mime-handle-alist))
4279 (gnus-set-mode-line 'article)))
4280 ;; The result from the `request' was an actual article -
4281 ;; or at least some text that is now displayed in the
4282 ;; article buffer.
4283 (when (and (numberp article)
4284 (not (eq article gnus-current-article)))
4285 ;; Seems like a new article has been selected.
4286 ;; `gnus-current-article' must be an article number.
4287 (save-excursion
4288 (set-buffer summary-buffer)
4289 (push article gnus-newsgroup-history)
4290 (setq gnus-last-article gnus-current-article
4291 gnus-current-article article
4292 gnus-current-headers
4293 (gnus-summary-article-header gnus-current-article)
4294 gnus-article-current
4295 (cons gnus-newsgroup-name gnus-current-article))
4296 (unless (vectorp gnus-current-headers)
4297 (setq gnus-current-headers nil))
4298 (gnus-summary-goto-subject gnus-current-article)
4299 (when (gnus-summary-show-thread)
4300 ;; If the summary buffer really was folded, the
4301 ;; previous goto may not actually have gone to
4302 ;; the right article, but the thread root instead.
4303 ;; So we go again.
4304 (gnus-summary-goto-subject gnus-current-article))
4305 (gnus-run-hooks 'gnus-mark-article-hook)
4306 (gnus-set-mode-line 'summary)
4307 (when (gnus-visual-p 'article-highlight 'highlight)
4308 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4309 ;; Set the global newsgroup variables here.
4310 (gnus-set-global-variables)
4311 (setq gnus-have-all-headers
4312 (or all-headers gnus-show-all-headers))))
4313 (save-excursion
4314 (gnus-configure-windows 'article))
4315 (when (or (numberp article)
4316 (stringp article))
4317 (gnus-article-prepare-display)
4318 ;; Do page break.
4319 (goto-char (point-min))
4320 (when gnus-break-pages
4321 (gnus-narrow-to-page)))
4322 (let ((gnus-article-mime-handle-alist-1
4323 gnus-article-mime-handle-alist))
4324 (gnus-set-mode-line 'article))
4325 (article-goto-body)
4326 (unless (bobp)
4327 (forward-line -1))
4328 (set-window-point (get-buffer-window (current-buffer)) (point))
4329 (gnus-configure-windows 'article)
4330 t))))))
4332 ;;;###autoload
4333 (defun gnus-article-prepare-display ()
4334 "Make the current buffer look like a nice article."
4335 ;; Hooks for getting information from the article.
4336 ;; This hook must be called before being narrowed.
4337 (let ((gnus-article-buffer (current-buffer))
4338 buffer-read-only
4339 (inhibit-read-only t))
4340 (unless (eq major-mode 'gnus-article-mode)
4341 (gnus-article-mode))
4342 (setq buffer-read-only nil
4343 gnus-article-wash-types nil
4344 gnus-article-image-alist nil)
4345 (gnus-run-hooks 'gnus-tmp-internal-hook)
4346 (when gnus-display-mime-function
4347 (funcall gnus-display-mime-function))
4348 (gnus-run-hooks 'gnus-article-prepare-hook)))
4351 ;;; Gnus Sticky Article Mode
4354 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4355 "Mode for sticky articles."
4356 ;; Release bindings that won't work.
4357 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4358 gnus-sticky-article-mode-map)
4359 (substitute-key-definition 'gnus-article-refer-article 'undefined
4360 gnus-sticky-article-mode-map)
4361 (dolist (k '("e" "h" "s" "F" "R"))
4362 (define-key gnus-sticky-article-mode-map k nil))
4363 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4364 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4365 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4366 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4368 (defun gnus-sticky-article (arg)
4369 "Make the current article sticky.
4370 If a prefix ARG is given, ask for a name for this sticky article buffer."
4371 (interactive "P")
4372 (gnus-summary-show-thread)
4373 (gnus-summary-select-article nil nil 'pseudo)
4374 (let (new-art-buf-name)
4375 (gnus-eval-in-buffer-window gnus-article-buffer
4376 (setq new-art-buf-name
4377 (concat
4378 "*Sticky Article: "
4379 (if arg
4380 (read-from-minibuffer "Sticky article buffer name: ")
4381 (gnus-with-article-headers
4382 (gnus-article-goto-header "subject")
4383 (setq new-art-buf-name
4384 (buffer-substring-no-properties
4385 (line-beginning-position) (line-end-position)))
4386 (goto-char (point-min))
4387 (gnus-article-goto-header "from")
4388 (setq new-art-buf-name
4389 (concat
4390 new-art-buf-name ", "
4391 (buffer-substring-no-properties
4392 (line-beginning-position) (line-end-position))))
4393 (goto-char (point-min))
4394 (gnus-article-goto-header "date")
4395 (setq new-art-buf-name
4396 (concat
4397 new-art-buf-name ", "
4398 (buffer-substring-no-properties
4399 (line-beginning-position) (line-end-position))))))
4400 "*"))
4401 (if (and (gnus-buffer-live-p new-art-buf-name)
4402 (with-current-buffer new-art-buf-name
4403 (eq major-mode 'gnus-sticky-article-mode)))
4404 (switch-to-buffer new-art-buf-name)
4405 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4406 (gnus-sticky-article-mode))
4407 (setq gnus-article-buffer new-art-buf-name))
4408 (gnus-summary-recenter)
4409 (gnus-summary-position-point))
4411 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4412 "Kill the given sticky article BUFFER.
4413 If none is given, assume the current buffer and kill it if it has
4414 `gnus-sticky-article-mode'."
4415 (interactive)
4416 (unless buffer
4417 (setq buffer (current-buffer)))
4418 (with-current-buffer buffer
4419 (when (eq major-mode 'gnus-sticky-article-mode)
4420 (gnus-kill-buffer buffer))))
4422 (defun gnus-kill-sticky-article-buffers (arg)
4423 "Kill all sticky article buffers.
4424 If a prefix ARG is given, ask for confirmation."
4425 (interactive "P")
4426 (dolist (buf (gnus-buffers))
4427 (with-current-buffer buf
4428 (when (eq major-mode 'gnus-sticky-article-mode)
4429 (if (not arg)
4430 (gnus-kill-buffer buf)
4431 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4432 (gnus-kill-buffer buf)))))))
4435 ;;; Gnus MIME viewing functions
4438 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4439 "Format of the MIME buttons.
4441 Valid specifiers include:
4442 %t The MIME type
4443 %T MIME type, along with additional info
4444 %n The `name' parameter
4445 %d The description, if any
4446 %l The length of the encoded part
4447 %p The part identifier number
4448 %e Dots if the part isn't displayed
4450 General format specifiers can also be used. See Info node
4451 `(gnus)Formatting Variables'.")
4453 (defvar gnus-mime-button-line-format-alist
4454 '((?t gnus-tmp-type ?s)
4455 (?T gnus-tmp-type-long ?s)
4456 (?n gnus-tmp-name ?s)
4457 (?d gnus-tmp-description ?s)
4458 (?p gnus-tmp-id ?s)
4459 (?l gnus-tmp-length ?d)
4460 (?e gnus-tmp-dots ?s)))
4462 (defvar gnus-mime-button-commands
4463 '((gnus-article-press-button "\r" "Toggle Display")
4464 (gnus-mime-view-part "v" "View Interactively...")
4465 (gnus-mime-view-part-as-type "t" "View As Type...")
4466 (gnus-mime-view-part-as-charset "C" "View As charset...")
4467 (gnus-mime-save-part "o" "Save...")
4468 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4469 (gnus-mime-replace-part "r" "Replace part")
4470 (gnus-mime-delete-part "d" "Delete part")
4471 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4472 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4473 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4474 (gnus-mime-view-part-externally "e" "View Externally")
4475 (gnus-mime-print-part "p" "Print")
4476 (gnus-mime-pipe-part "|" "Pipe To Command...")
4477 (gnus-mime-action-on-part "." "Take action on the part...")))
4479 (defun gnus-article-mime-part-status ()
4480 (if gnus-article-mime-handle-alist-1
4481 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4482 " (1 part)"
4483 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4484 ""))
4486 (defvar gnus-mime-button-map
4487 (let ((map (make-sparse-keymap)))
4488 (define-key map gnus-mouse-2 'gnus-article-push-button)
4489 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4490 (dolist (c gnus-mime-button-commands)
4491 (define-key map (cadr c) (car c)))
4492 map))
4494 (easy-menu-define
4495 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4496 `("MIME Part"
4497 ,@(mapcar (lambda (c)
4498 (vector (caddr c) (car c) :active t))
4499 gnus-mime-button-commands)))
4501 (defun gnus-mime-button-menu (event prefix)
4502 "Construct a context-sensitive menu of MIME commands."
4503 (interactive "e\nP")
4504 (save-window-excursion
4505 (let ((pos (event-start event)))
4506 (select-window (posn-window pos))
4507 (goto-char (posn-point pos))
4508 (gnus-article-check-buffer)
4509 (popup-menu gnus-mime-button-menu nil prefix))))
4511 (defun gnus-mime-view-all-parts (&optional handles)
4512 "View all the MIME parts."
4513 (interactive)
4514 (with-current-buffer gnus-article-buffer
4515 (let ((handles (or handles gnus-article-mime-handles))
4516 (mail-parse-charset gnus-newsgroup-charset)
4517 (mail-parse-ignored-charsets
4518 (with-current-buffer gnus-summary-buffer
4519 gnus-newsgroup-ignored-charsets)))
4520 (when handles
4521 (mm-remove-parts handles)
4522 (goto-char (point-min))
4523 (or (search-forward "\n\n") (goto-char (point-max)))
4524 (let ((inhibit-read-only t))
4525 (delete-region (point) (point-max))
4526 (mm-display-parts handles))))))
4528 (defun gnus-article-jump-to-part (n)
4529 "Jump to MIME part N."
4530 (interactive "P")
4531 (pop-to-buffer gnus-article-buffer)
4532 ;; FIXME: why is it necessary?
4533 (sit-for 0)
4534 (let ((parts (length gnus-article-mime-handle-alist)))
4535 (or n (setq n
4536 (string-to-number
4537 (read-string ;; Emacs 21 doesn't have `read-number'.
4538 (format "Jump to part (2..%s): " parts)))))
4539 (unless (and (integerp n) (<= n parts) (>= n 1))
4540 (setq n
4541 (progn
4542 (gnus-message 7 "Invalid part `%s', using %s instead."
4543 n parts)
4544 parts)))
4545 (gnus-message 9 "Jumping to part %s." n)
4546 (cond ((>= gnus-auto-select-part 1)
4547 (while (and (<= n parts)
4548 (not (gnus-article-goto-part n)))
4549 (setq n (1+ n))))
4550 ((< gnus-auto-select-part 0)
4551 (while (and (>= n 1)
4552 (not (gnus-article-goto-part n)))
4553 (setq n (1- n))))
4555 (gnus-article-goto-part n)))))
4557 (eval-when-compile
4558 (defsubst gnus-article-edit-part (handles &optional current-id)
4559 "Edit an article in order to delete a mime part.
4560 This function is exclusively used by `gnus-mime-save-part-and-strip'
4561 and `gnus-mime-delete-part', and not provided at run-time normally."
4562 (gnus-article-edit-article
4563 `(lambda ()
4564 (buffer-disable-undo)
4565 (erase-buffer)
4566 (let ((mail-parse-charset (or gnus-article-charset
4567 ',gnus-newsgroup-charset))
4568 (mail-parse-ignored-charsets
4569 (or gnus-article-ignored-charsets
4570 ',gnus-newsgroup-ignored-charsets))
4571 (mbl mml-buffer-list))
4572 (setq mml-buffer-list nil)
4573 (insert-buffer-substring gnus-original-article-buffer)
4574 (mime-to-mml ',handles)
4575 (setq gnus-article-mime-handles nil)
4576 (let ((mbl1 mml-buffer-list))
4577 (setq mml-buffer-list mbl)
4578 (set (make-local-variable 'mml-buffer-list) mbl1))
4579 (gnus-make-local-hook 'kill-buffer-hook)
4580 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4581 `(lambda (no-highlight)
4582 (let ((mail-parse-charset (or gnus-article-charset
4583 ',gnus-newsgroup-charset))
4584 (message-options message-options)
4585 (message-options-set-recipient)
4586 (mail-parse-ignored-charsets
4587 (or gnus-article-ignored-charsets
4588 ',gnus-newsgroup-ignored-charsets)))
4589 (mml-to-mime)
4590 (mml-destroy-buffers)
4591 (remove-hook 'kill-buffer-hook
4592 'mml-destroy-buffers t)
4593 (kill-local-variable 'mml-buffer-list))
4594 (gnus-summary-edit-article-done
4595 ,(or (mail-header-references gnus-current-headers) "")
4596 ,(gnus-group-read-only-p)
4597 ,gnus-summary-buffer no-highlight))
4599 (gnus-article-edit-done)
4600 (gnus-summary-expand-window)
4601 (gnus-summary-show-article)
4602 (when (and current-id (integerp gnus-auto-select-part))
4603 (gnus-article-jump-to-part
4604 (if (text-property-any (point-min) (point-max)
4605 'gnus-part (+ current-id gnus-auto-select-part))
4606 (+ current-id gnus-auto-select-part)
4607 (with-current-buffer gnus-article-buffer
4608 (length gnus-article-mime-handle-alist)))))))
4610 (defun gnus-mime-replace-part (file)
4611 "Replace MIME part under point with an external body."
4612 ;; Useful if file has already been saved to disk
4613 (interactive
4614 (list
4615 (mm-with-multibyte
4616 (read-file-name "Replace MIME part with file: "
4617 (or mm-default-directory default-directory)
4618 nil nil))))
4619 (gnus-mime-save-part-and-strip file))
4621 (defun gnus-mime-save-part-and-strip (&optional file)
4622 "Save the MIME part under point then replace it with an external body.
4623 If FILE is given, use it for the external part."
4624 (interactive)
4625 (gnus-article-check-buffer)
4626 (when (gnus-group-read-only-p)
4627 (error "The current group does not support deleting of parts"))
4628 (when (mm-complicated-handles gnus-article-mime-handles)
4629 (error "\
4630 The current article has a complicated MIME structure, giving up..."))
4631 (let* ((data (get-text-property (point) 'gnus-data))
4632 (id (get-text-property (point) 'gnus-part))
4633 param
4634 (handles gnus-article-mime-handles))
4635 (unless file
4636 (setq file
4637 (and data (mm-save-part data "Delete MIME part and save to: "))))
4638 (when file
4639 (with-current-buffer (mm-handle-buffer data)
4640 (erase-buffer)
4641 (insert "Content-Type: " (mm-handle-media-type data))
4642 (mml-insert-parameter-string (cdr (mm-handle-type data))
4643 '(charset))
4644 ;; Add a filename for the sake of saving the part again.
4645 (mml-insert-parameter
4646 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4647 (insert "\n")
4648 (insert "Content-ID: " (message-make-message-id) "\n")
4649 (insert "Content-Transfer-Encoding: binary\n")
4650 (insert "\n"))
4651 (setcdr data
4652 (cdr (mm-make-handle nil
4653 `("message/external-body"
4654 (access-type . "LOCAL-FILE")
4655 (name . ,file)))))
4656 ;; (set-buffer gnus-summary-buffer)
4657 (gnus-article-edit-part handles id))))
4659 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4660 ;; parts...>') but with stripping would be nice.
4662 (defun gnus-mime-delete-part ()
4663 "Delete the MIME part under point.
4664 Replace it with some information about the removed part."
4665 (interactive)
4666 (gnus-article-check-buffer)
4667 (when (gnus-group-read-only-p)
4668 (error "The current group does not support deleting of parts"))
4669 (when (mm-complicated-handles gnus-article-mime-handles)
4670 (error "\
4671 The current article has a complicated MIME structure, giving up..."))
4672 (when (or gnus-expert-user
4673 (gnus-yes-or-no-p "\
4674 Deleting parts may malfunction or destroy the article; continue? "))
4675 (let* ((data (get-text-property (point) 'gnus-data))
4676 (id (get-text-property (point) 'gnus-part))
4677 (handles gnus-article-mime-handles)
4678 (none "(none)")
4679 (description
4680 (mail-decode-encoded-word-string (or (mm-handle-description data)
4681 none)))
4682 (filename
4683 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4684 none))
4685 (type (mm-handle-media-type data)))
4686 (unless data
4687 (error "No MIME part under point"))
4688 (with-current-buffer (mm-handle-buffer data)
4689 (let ((bsize (format "%s" (buffer-size))))
4690 (erase-buffer)
4691 (insert
4692 (concat
4693 ",----\n"
4694 "| The following attachment has been deleted:\n"
4695 "|\n"
4696 "| Type: " type "\n"
4697 "| Filename: " filename "\n"
4698 "| Size (encoded): " bsize " Byte\n"
4699 "| Description: " description "\n"
4700 "`----\n"))
4701 (setcdr data
4702 (cdr (mm-make-handle
4703 nil `("text/plain") nil nil
4704 (list "attachment")
4705 (format "Deleted attachment (%s bytes)" bsize))))))
4706 ;; (set-buffer gnus-summary-buffer)
4707 (gnus-article-edit-part handles id))))
4709 (defun gnus-mime-save-part ()
4710 "Save the MIME part under point."
4711 (interactive)
4712 (gnus-article-check-buffer)
4713 (let ((data (get-text-property (point) 'gnus-data)))
4714 (when data
4715 (mm-save-part data))))
4717 (defun gnus-mime-pipe-part ()
4718 "Pipe the MIME part under point to a process."
4719 (interactive)
4720 (gnus-article-check-buffer)
4721 (let ((data (get-text-property (point) 'gnus-data)))
4722 (when data
4723 (mm-pipe-part data))))
4725 (defun gnus-mime-view-part ()
4726 "Interactively choose a viewing method for the MIME part under point."
4727 (interactive)
4728 (gnus-article-check-buffer)
4729 (let ((data (get-text-property (point) 'gnus-data)))
4730 (when data
4731 (setq gnus-article-mime-handles
4732 (mm-merge-handles
4733 gnus-article-mime-handles (setq data (copy-sequence data))))
4734 (mm-interactively-view-part data))))
4736 (defun gnus-mime-view-part-as-type-internal ()
4737 (gnus-article-check-buffer)
4738 (let* ((handle (get-text-property (point) 'gnus-data))
4739 (name (or
4740 ;; Content-Type: foo/bar; name=...
4741 (mail-content-type-get (mm-handle-type handle) 'name)
4742 ;; Content-Disposition: attachment; filename=...
4743 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4744 (def-type (and name (mm-default-file-encoding name))))
4745 (or (and def-type (cons def-type 0))
4746 (and handle
4747 (equal (mm-handle-media-supertype handle) "text")
4748 '("text/plain" . 0))
4749 '("application/octet-stream" . 0))))
4751 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4752 "Choose a MIME media type, and view the part as such.
4753 If non-nil, PRED is a predicate to use during completion to limit the
4754 available media-types."
4755 (interactive)
4756 (unless mime-type
4757 (setq mime-type
4758 (let ((default (gnus-mime-view-part-as-type-internal)))
4759 (completing-read
4760 (format "View as MIME type (default %s): "
4761 (car default))
4762 (mapcar #'list (mailcap-mime-types))
4763 pred nil nil nil
4764 (car default)))))
4765 (gnus-article-check-buffer)
4766 (let ((handle (get-text-property (point) 'gnus-data)))
4767 (when handle
4768 (when (equal (mm-handle-media-type handle) "message/external-body")
4769 (unless (mm-handle-cache handle)
4770 (mm-extern-cache-contents handle))
4771 (setq handle (mm-handle-cache handle)))
4772 (setq handle
4773 (mm-make-handle (mm-handle-buffer handle)
4774 (cons mime-type (cdr (mm-handle-type handle)))
4775 (mm-handle-encoding handle)
4776 (mm-handle-undisplayer handle)
4777 (mm-handle-disposition handle)
4778 (mm-handle-description handle)
4780 (mm-handle-id handle)))
4781 (setq gnus-article-mime-handles
4782 (mm-merge-handles gnus-article-mime-handles handle))
4783 (when (mm-handle-displayed-p handle)
4784 (mm-remove-part handle))
4785 (gnus-mm-display-part handle))))
4787 (defun gnus-mime-copy-part (&optional handle arg)
4788 "Put the MIME part under point into a new buffer.
4789 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4790 are decompressed."
4791 (interactive (list nil current-prefix-arg))
4792 (gnus-article-check-buffer)
4793 (unless handle
4794 (setq handle (get-text-property (point) 'gnus-data)))
4795 (when handle
4796 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4797 'name)
4798 (mail-content-type-get (mm-handle-disposition handle)
4799 'filename)))
4800 contents dont-decode charset coding-system)
4801 (mm-with-unibyte-buffer
4802 (mm-insert-part handle)
4803 (setq contents (or (condition-case nil
4804 (mm-decompress-buffer filename nil 'sig)
4805 (error
4806 (setq dont-decode t)
4807 nil))
4808 (buffer-string))))
4809 (setq filename (cond (filename (file-name-nondirectory filename))
4810 (dont-decode "*raw data*")
4811 (t "*decoded*")))
4812 (cond
4813 (dont-decode)
4814 ((not arg)
4815 (unless (setq charset (mail-content-type-get
4816 (mm-handle-type handle) 'charset))
4817 (unless (setq coding-system (mm-with-unibyte-buffer
4818 (insert contents)
4819 (mm-find-buffer-file-coding-system)))
4820 (setq charset gnus-newsgroup-charset))))
4821 ((numberp arg)
4822 (setq charset (or (cdr (assq arg
4823 gnus-summary-show-article-charset-alist))
4824 (mm-read-coding-system "Charset: ")))))
4825 (switch-to-buffer (generate-new-buffer filename))
4826 (if (or coding-system
4827 (and charset
4828 (setq coding-system (mm-charset-to-coding-system charset))
4829 (not (eq charset 'ascii))))
4830 (progn
4831 (mm-enable-multibyte)
4832 (insert (mm-decode-coding-string contents coding-system))
4833 (setq buffer-file-coding-system
4834 (if (boundp 'last-coding-system-used)
4835 (symbol-value 'last-coding-system-used)
4836 coding-system)))
4837 (mm-disable-multibyte)
4838 (insert contents)
4839 (setq buffer-file-coding-system mm-binary-coding-system))
4840 ;; We do it this way to make `normal-mode' set the appropriate mode.
4841 (unwind-protect
4842 (progn
4843 (setq buffer-file-name (expand-file-name filename))
4844 (normal-mode))
4845 (setq buffer-file-name nil))
4846 (goto-char (point-min)))))
4848 (defun gnus-mime-print-part (&optional handle filename)
4849 "Print the MIME part under point."
4850 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4851 (gnus-article-check-buffer)
4852 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4853 (contents (and handle (mm-get-part handle)))
4854 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4855 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4856 (when contents
4857 (if printer
4858 (unwind-protect
4859 (progn
4860 (mm-save-part-to-file handle file)
4861 (call-process shell-file-name nil
4862 (generate-new-buffer " *mm*")
4864 shell-command-switch
4865 (mm-mailcap-command
4866 printer file (mm-handle-type handle))))
4867 (delete-file file))
4868 (with-temp-buffer
4869 (insert contents)
4870 (gnus-print-buffer))
4871 (ps-despool filename)))))
4873 (defun gnus-mime-inline-part (&optional handle arg)
4874 "Insert the MIME part under point into the current buffer.
4875 Compressed files like .gz and .bz2 are decompressed."
4876 (interactive (list nil current-prefix-arg))
4877 (gnus-article-check-buffer)
4878 (unless handle
4879 (setq handle (get-text-property (point) 'gnus-data)))
4880 (when handle
4881 (let ((b (point))
4882 (inhibit-read-only t)
4883 contents charset coding-system)
4884 (if (and (not arg) (mm-handle-undisplayer handle))
4885 (mm-remove-part handle)
4886 (mm-with-unibyte-buffer
4887 (mm-insert-part handle)
4888 (setq contents
4889 (or (mm-decompress-buffer
4890 (or (mail-content-type-get (mm-handle-type handle)
4891 'name)
4892 (mail-content-type-get (mm-handle-disposition handle)
4893 'filename))
4894 nil t)
4895 (buffer-string))))
4896 (cond
4897 ((not arg)
4898 (unless (setq charset (mail-content-type-get
4899 (mm-handle-type handle) 'charset))
4900 (unless (setq coding-system
4901 (mm-with-unibyte-buffer
4902 (insert contents)
4903 (mm-find-buffer-file-coding-system)))
4904 (setq charset gnus-newsgroup-charset))))
4905 ((numberp arg)
4906 (if (mm-handle-undisplayer handle)
4907 (mm-remove-part handle))
4908 (setq charset
4909 (or (cdr (assq arg
4910 gnus-summary-show-article-charset-alist))
4911 (mm-read-coding-system "Charset: "))))
4913 (if (mm-handle-undisplayer handle)
4914 (mm-remove-part handle))))
4915 (forward-line 2)
4916 (mm-insert-inline
4917 handle
4918 (if (or coding-system
4919 (and charset
4920 (setq coding-system
4921 (mm-charset-to-coding-system charset))
4922 (not (eq coding-system 'ascii))))
4923 (mm-decode-coding-string contents coding-system)
4924 (mm-string-to-multibyte contents)))
4925 (goto-char b)))))
4927 (defun gnus-mime-strip-charset-parameters (handle)
4928 "Strip charset parameters from HANDLE."
4929 (if (stringp (car handle))
4930 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
4931 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
4932 "message/external-body")
4933 (progn
4934 (unless (mm-handle-cache handle)
4935 (mm-extern-cache-contents handle))
4936 (mm-handle-cache handle))
4937 handle)))
4938 (charset (assq 'charset (cdr type))))
4939 (when charset
4940 (delq charset type)))))
4942 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4943 "Insert the MIME part under point into the current buffer using the
4944 specified charset."
4945 (interactive (list nil current-prefix-arg))
4946 (gnus-article-check-buffer)
4947 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4948 (fun (get-text-property (point) 'gnus-callback))
4949 (gnus-newsgroup-ignored-charsets 'gnus-all)
4950 gnus-newsgroup-charset form preferred parts)
4951 (when handle
4952 (when (prog1
4953 (and fun
4954 (setq gnus-newsgroup-charset
4955 (or (cdr (assq
4957 gnus-summary-show-article-charset-alist))
4958 (mm-read-coding-system "Charset: "))))
4959 (if (mm-handle-undisplayer handle)
4960 (mm-remove-part handle)))
4961 (gnus-mime-strip-charset-parameters handle)
4962 (when (and (consp (setq form (cdr-safe fun)))
4963 (setq form (ignore-errors
4964 (assq 'gnus-mime-display-alternative form)))
4965 (setq preferred (caddr form))
4966 (progn
4967 (when (eq (car preferred) 'quote)
4968 (setq preferred (cadr preferred)))
4969 (not (equal preferred
4970 (get-text-property (point) 'gnus-data))))
4971 (setq parts (get-text-property (point) 'gnus-part))
4972 (setq parts (cdr (assq parts
4973 gnus-article-mime-handle-alist)))
4974 (equal (mm-handle-media-type parts) "multipart/alternative")
4975 (setq parts (reverse (cdr parts))))
4976 (setcar (cddr form)
4977 (list 'quote (or (cadr (member preferred parts))
4978 (car parts)))))
4979 (funcall fun handle)))))
4981 (defun gnus-mime-view-part-externally (&optional handle)
4982 "View the MIME part under point with an external viewer."
4983 (interactive)
4984 (gnus-article-check-buffer)
4985 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4986 (mm-user-display-methods nil)
4987 (mm-inlined-types nil)
4988 (mail-parse-charset gnus-newsgroup-charset)
4989 (mail-parse-ignored-charsets
4990 (with-current-buffer gnus-summary-buffer
4991 gnus-newsgroup-ignored-charsets))
4992 (type (mm-handle-media-type handle))
4993 (method (mailcap-mime-info type))
4994 (mm-enable-external t))
4995 (if (not (stringp method))
4996 (gnus-mime-view-part-as-type
4997 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
4998 (when handle
4999 (if (mm-handle-undisplayer handle)
5000 (mm-remove-part handle)
5001 (mm-display-part handle))))))
5003 (defun gnus-mime-view-part-internally (&optional handle)
5004 "View the MIME part under point with an internal viewer.
5005 If no internal viewer is available, use an external viewer."
5006 (interactive)
5007 (gnus-article-check-buffer)
5008 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5009 (mm-inlined-types '(".*"))
5010 (mm-inline-large-images t)
5011 (mail-parse-charset gnus-newsgroup-charset)
5012 (mail-parse-ignored-charsets
5013 (with-current-buffer gnus-summary-buffer
5014 gnus-newsgroup-ignored-charsets))
5015 (inhibit-read-only t))
5016 (if (not (mm-inlinable-p handle))
5017 (gnus-mime-view-part-as-type
5018 nil (lambda (types) (mm-inlinable-p handle (car types))))
5019 (when handle
5020 (if (mm-handle-undisplayer handle)
5021 (mm-remove-part handle)
5022 (mm-display-part handle))))))
5024 (defun gnus-mime-action-on-part (&optional action)
5025 "Do something with the MIME attachment at \(point\)."
5026 (interactive
5027 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5028 (gnus-article-check-buffer)
5029 (let ((action-pair (assoc action gnus-mime-action-alist)))
5030 (if action-pair
5031 (funcall (cdr action-pair)))))
5033 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5034 "Call FUNCTION on MIME part N.
5035 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5036 If INTERACTIVE, call FUNCTION interactivly."
5037 (let (window frame)
5038 ;; Check whether the article is displayed.
5039 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5040 (setq window (get-buffer-window gnus-article-buffer t))
5041 (frame-visible-p (setq frame (window-frame window))))
5042 (error "No article is displayed"))
5043 (with-current-buffer gnus-article-buffer
5044 ;; Check whether the article displays the right contents.
5045 (unless (with-current-buffer gnus-summary-buffer
5046 (eq gnus-current-article (gnus-summary-article-number)))
5047 (error "You should select the right article first"))
5048 (if n
5049 (setq n (prefix-numeric-value n))
5050 (let ((pt (point)))
5051 (setq n (or (get-text-property pt 'gnus-part)
5052 (and (not (bobp))
5053 (get-text-property (1- pt) 'gnus-part))
5054 (get-text-property (prog2
5055 (forward-line 1)
5056 (point)
5057 (goto-char pt))
5058 'gnus-part)
5059 (get-text-property
5060 (or (and (setq pt (previous-single-property-change
5061 pt 'gnus-part))
5062 (1- pt))
5063 (next-single-property-change (point) 'gnus-part)
5064 (point))
5065 'gnus-part)
5066 1))))
5067 ;; Check whether the specified part exists.
5068 (when (> n (length gnus-article-mime-handle-alist))
5069 (error "No such part")))
5070 (unless
5071 (progn
5072 ;; To select the window is needed so that the cursor
5073 ;; might be visible on the MIME button.
5074 (select-window (prog1
5075 window
5076 (setq window (selected-window))
5077 ;; Article may be displayed in the other frame.
5078 (gnus-select-frame-set-input-focus
5079 (prog1
5080 frame
5081 (setq frame (selected-frame))))))
5082 (when (gnus-article-goto-part n)
5083 ;; We point the cursor and the arrow at the MIME button
5084 ;; when the `function' prompt the user for something.
5085 (let ((cursor-in-non-selected-windows t)
5086 (overlay-arrow-string "=>")
5087 (overlay-arrow-position (point-marker)))
5088 (unwind-protect
5089 (cond
5090 ((and no-handle interactive)
5091 (call-interactively function))
5092 (no-handle
5093 (funcall function))
5094 (interactive
5095 (call-interactively
5096 function
5097 (cdr (assq n gnus-article-mime-handle-alist))))
5099 (funcall function
5100 (cdr (assq n gnus-article-mime-handle-alist)))))
5101 (set-marker overlay-arrow-position nil)
5102 (unless gnus-auto-select-part
5103 (gnus-select-frame-set-input-focus frame)
5104 (select-window window))))
5106 (if gnus-inhibit-mime-unbuttonizing
5107 ;; This is the default though the program shouldn't reach here.
5108 (error "No such part")
5109 ;; The part which doesn't have the MIME button is selected.
5110 ;; So, we display all the buttons and redo it.
5111 (let ((gnus-inhibit-mime-unbuttonizing t))
5112 (gnus-summary-show-article)
5113 (gnus-article-part-wrapper n function no-handle))))))
5115 (defun gnus-article-pipe-part (n)
5116 "Pipe MIME part N, which is the numerical prefix."
5117 (interactive "P")
5118 (gnus-article-part-wrapper n 'mm-pipe-part))
5120 (defun gnus-article-save-part (n)
5121 "Save MIME part N, which is the numerical prefix."
5122 (interactive "P")
5123 (gnus-article-part-wrapper n 'mm-save-part))
5125 (defun gnus-article-interactively-view-part (n)
5126 "View MIME part N interactively, which is the numerical prefix."
5127 (interactive "P")
5128 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5130 (defun gnus-article-copy-part (n)
5131 "Copy MIME part N, which is the numerical prefix."
5132 (interactive "P")
5133 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5135 (defun gnus-article-view-part-as-charset (n)
5136 "View MIME part N using a specified charset.
5137 N is the numerical prefix."
5138 (interactive "P")
5139 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5141 (defun gnus-article-view-part-externally (n)
5142 "View MIME part N externally, which is the numerical prefix."
5143 (interactive "P")
5144 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5146 (defun gnus-article-inline-part (n)
5147 "Inline MIME part N, which is the numerical prefix."
5148 (interactive "P")
5149 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5151 (defun gnus-article-save-part-and-strip (n)
5152 "Save MIME part N and replace it with an external body.
5153 N is the numerical prefix."
5154 (interactive "P")
5155 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5157 (defun gnus-article-replace-part (n)
5158 "Replace MIME part N with an external body.
5159 N is the numerical prefix."
5160 (interactive "P")
5161 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5163 (defun gnus-article-delete-part (n)
5164 "Delete MIME part N and add some information about the removed part.
5165 N is the numerical prefix."
5166 (interactive "P")
5167 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5169 (defun gnus-article-view-part-as-type (n)
5170 "Choose a MIME media type, and view part N as such.
5171 N is the numerical prefix."
5172 (interactive "P")
5173 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5175 (defun gnus-article-mime-match-handle-first (condition)
5176 (if condition
5177 (let (n)
5178 (dolist (ihandle gnus-article-mime-handle-alist)
5179 (if (and (cond
5180 ((functionp condition)
5181 (funcall condition (cdr ihandle)))
5182 ((eq condition 'undisplayed)
5183 (not (or (mm-handle-undisplayer (cdr ihandle))
5184 (equal (mm-handle-media-type (cdr ihandle))
5185 "multipart/alternative"))))
5186 ((eq condition 'undisplayed-alternative)
5187 (not (mm-handle-undisplayer (cdr ihandle))))
5188 (t t))
5189 (gnus-article-goto-part (car ihandle))
5190 (or (not n) (< (car ihandle) n)))
5191 (setq n (car ihandle))))
5192 (or n 1))
5195 (defun gnus-article-view-part (&optional n)
5196 "View MIME part N, which is the numerical prefix."
5197 (interactive "P")
5198 (with-current-buffer gnus-article-buffer
5199 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5200 gnus-article-mime-match-handle-function)))
5201 (when (> n (length gnus-article-mime-handle-alist))
5202 (error "No such part"))
5203 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5204 (when (gnus-article-goto-part n)
5205 (if (equal (car handle) "multipart/alternative")
5206 (gnus-article-press-button)
5207 (when (eq (gnus-mm-display-part handle) 'internal)
5208 (gnus-set-window-start)))))))
5210 (defsubst gnus-article-mime-total-parts ()
5211 (if (bufferp (car gnus-article-mime-handles))
5212 1 ;; single part
5213 (1- (length gnus-article-mime-handles))))
5215 (defun gnus-mm-display-part (handle)
5216 "Display HANDLE and fix MIME button."
5217 (let ((id (get-text-property (point) 'gnus-part))
5218 (point (point))
5219 (inhibit-read-only t))
5220 (forward-line 1)
5221 (prog1
5222 (let ((window (selected-window))
5223 (mail-parse-charset gnus-newsgroup-charset)
5224 (mail-parse-ignored-charsets
5225 (if (gnus-buffer-live-p gnus-summary-buffer)
5226 (with-current-buffer gnus-summary-buffer
5227 gnus-newsgroup-ignored-charsets)
5228 nil)))
5229 (save-excursion
5230 (unwind-protect
5231 (let ((win (gnus-get-buffer-window (current-buffer) t))
5232 (beg (point)))
5233 (when win
5234 (select-window win))
5235 (goto-char point)
5236 (forward-line)
5237 (if (mm-handle-displayed-p handle)
5238 ;; This will remove the part.
5239 (mm-display-part handle)
5240 (save-restriction
5241 (narrow-to-region (point)
5242 (if (eobp) (point) (1+ (point))))
5243 (mm-display-part handle)
5244 ;; We narrow to the part itself and
5245 ;; then call the treatment functions.
5246 (goto-char (point-min))
5247 (forward-line 1)
5248 (narrow-to-region (point) (point-max))
5249 (gnus-treat-article
5250 nil id
5251 (gnus-article-mime-total-parts)
5252 (mm-handle-media-type handle)))))
5253 (if (window-live-p window)
5254 (select-window window)))))
5255 (goto-char point)
5256 (gnus-delete-line)
5257 (gnus-insert-mime-button
5258 handle id (list (mm-handle-displayed-p handle)))
5259 (goto-char point))))
5261 (defun gnus-article-goto-part (n)
5262 "Go to MIME part N."
5263 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5265 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5266 (let ((gnus-tmp-name
5267 (or (mail-content-type-get (mm-handle-type handle) 'name)
5268 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5269 (mail-content-type-get (mm-handle-type handle) 'url)
5270 ""))
5271 (gnus-tmp-type (mm-handle-media-type handle))
5272 (gnus-tmp-description
5273 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5274 "")))
5275 (gnus-tmp-dots
5276 (if (if displayed (car displayed)
5277 (mm-handle-displayed-p handle))
5278 "" "..."))
5279 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5280 (buffer-size)))
5281 gnus-tmp-type-long b e)
5282 (when (string-match ".*/" gnus-tmp-name)
5283 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5284 (setq gnus-tmp-type-long (concat gnus-tmp-type
5285 (and (not (equal gnus-tmp-name ""))
5286 (concat "; " gnus-tmp-name))))
5287 (unless (equal gnus-tmp-description "")
5288 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5289 (unless (bolp)
5290 (insert "\n"))
5291 (setq b (point))
5292 (gnus-eval-format
5293 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5294 `(keymap ,gnus-mime-button-map
5295 gnus-callback gnus-mm-display-part
5296 gnus-part ,gnus-tmp-id
5297 article-type annotation
5298 gnus-data ,handle))
5299 (setq e (if (bolp)
5300 ;; Exclude a newline.
5301 (1- (point))
5302 (point)))
5303 (when gnus-article-button-face
5304 (gnus-overlay-put (gnus-make-overlay b e nil t)
5305 'face gnus-article-button-face))
5306 (widget-convert-button
5307 'link b e
5308 :mime-handle handle
5309 :action 'gnus-widget-press-button
5310 :button-keymap gnus-mime-button-map
5311 :help-echo
5312 (lambda (widget/window &optional overlay pos)
5313 ;; Needed to properly clear the message due to a bug in
5314 ;; wid-edit (XEmacs only).
5315 (if (boundp 'help-echo-owns-message)
5316 (setq help-echo-owns-message t))
5317 (format
5318 "%S: %s the MIME part; %S: more options"
5319 (aref gnus-mouse-2 0)
5320 ;; XEmacs will get a single widget arg; Emacs 21 will get
5321 ;; window, overlay, position.
5322 (if (mm-handle-displayed-p
5323 (if overlay
5324 (with-current-buffer (gnus-overlay-buffer overlay)
5325 (widget-get (widget-at (gnus-overlay-start overlay))
5326 :mime-handle))
5327 (widget-get widget/window :mime-handle)))
5328 "hide" "show")
5329 (aref gnus-down-mouse-3 0))))))
5331 (defun gnus-widget-press-button (elems el)
5332 (goto-char (widget-get elems :from))
5333 (gnus-article-press-button))
5335 (defvar gnus-displaying-mime nil)
5337 (defun gnus-display-mime (&optional ihandles)
5338 "Display the MIME parts."
5339 (save-excursion
5340 (save-selected-window
5341 (let ((window (get-buffer-window gnus-article-buffer))
5342 (point (point)))
5343 (when window
5344 (select-window window)
5345 ;; We have to do this since selecting the window
5346 ;; may change the point. So we set the window point.
5347 (set-window-point window point)))
5348 (let ((handles ihandles)
5349 (inhibit-read-only t)
5350 handle)
5351 (cond (handles)
5352 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5353 (when gnus-article-emulate-mime
5354 (mm-uu-dissect-text-parts handles)))
5355 (gnus-article-emulate-mime
5356 (setq handles (mm-uu-dissect))))
5357 (when (and (not ihandles)
5358 (not gnus-displaying-mime))
5359 ;; Top-level call; we clean up.
5360 (when gnus-article-mime-handles
5361 (mm-destroy-parts gnus-article-mime-handles)
5362 (setq gnus-article-mime-handle-alist nil));; A trick.
5363 (setq gnus-article-mime-handles handles)
5364 ;; We allow users to glean info from the handles.
5365 (when gnus-article-mime-part-function
5366 (gnus-mime-part-function handles)))
5367 (if (and handles
5368 (or (not (stringp (car handles)))
5369 (cdr handles)))
5370 (progn
5371 (when (and (not ihandles)
5372 (not gnus-displaying-mime))
5373 ;; Clean up for mime parts.
5374 (article-goto-body)
5375 (delete-region (point) (point-max)))
5376 (let ((gnus-displaying-mime t))
5377 (gnus-mime-display-part handles)))
5378 (save-restriction
5379 (article-goto-body)
5380 (narrow-to-region (point) (point-max))
5381 (gnus-treat-article nil 1 1)
5382 (widen)))
5383 (unless ihandles
5384 ;; Highlight the headers.
5385 (save-excursion
5386 (save-restriction
5387 (article-goto-body)
5388 (narrow-to-region (point-min) (point))
5389 (gnus-article-save-original-date
5390 (gnus-treat-article 'head)))))))
5391 ;; Cope with broken MIME messages.
5392 (goto-char (point-max))
5393 (unless (bolp)
5394 (insert "\n"))))
5396 (defcustom gnus-mime-display-multipart-as-mixed nil
5397 "Display \"multipart\" parts as \"multipart/mixed\".
5399 If t, it overrides nil values of
5400 `gnus-mime-display-multipart-alternative-as-mixed' and
5401 `gnus-mime-display-multipart-related-as-mixed'."
5402 :group 'gnus-article-mime
5403 :type 'boolean)
5405 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5406 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5407 :version "22.1"
5408 :group 'gnus-article-mime
5409 :type 'boolean)
5411 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5412 "Display \"multipart/related\" parts as \"multipart/mixed\".
5414 If displaying \"text/html\" is discouraged \(see
5415 `mm-discouraged-alternatives'\) images or other material inside a
5416 \"multipart/related\" part might be overlooked when this variable is nil."
5417 :version "22.1"
5418 :group 'gnus-article-mime
5419 :type 'boolean)
5421 (defun gnus-mime-display-part (handle)
5422 (cond
5423 ;; Maybe a broken MIME message.
5424 ((null handle))
5425 ;; Single part.
5426 ((not (stringp (car handle)))
5427 (gnus-mime-display-single handle))
5428 ;; User-defined multipart
5429 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5430 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5431 handle))
5432 ;; multipart/alternative
5433 ((and (equal (car handle) "multipart/alternative")
5434 (not (or gnus-mime-display-multipart-as-mixed
5435 gnus-mime-display-multipart-alternative-as-mixed)))
5436 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5437 (push (cons id handle) gnus-article-mime-handle-alist)
5438 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5439 ;; multipart/related
5440 ((and (equal (car handle) "multipart/related")
5441 (not (or gnus-mime-display-multipart-as-mixed
5442 gnus-mime-display-multipart-related-as-mixed)))
5443 ;;;!!!We should find the start part, but we just default
5444 ;;;!!!to the first part.
5445 ;;(gnus-mime-display-part (cadr handle))
5446 ;;;!!! Most multipart/related is an HTML message plus images.
5447 ;;;!!! Unfortunately we are unable to let W3 display those
5448 ;;;!!! included images, so we just display it as a mixed multipart.
5449 ;;(gnus-mime-display-mixed (cdr handle))
5450 ;;;!!! No, w3 can display everything just fine.
5451 (gnus-mime-display-part (cadr handle)))
5452 ((equal (car handle) "multipart/signed")
5453 (gnus-add-wash-type 'signed)
5454 (gnus-mime-display-security handle))
5455 ((equal (car handle) "multipart/encrypted")
5456 (gnus-add-wash-type 'encrypted)
5457 (gnus-mime-display-security handle))
5458 ;; Other multiparts are handled like multipart/mixed.
5460 (gnus-mime-display-mixed (cdr handle)))))
5462 (defun gnus-mime-part-function (handles)
5463 (if (stringp (car handles))
5464 (mapcar 'gnus-mime-part-function (cdr handles))
5465 (funcall gnus-article-mime-part-function handles)))
5467 (defun gnus-mime-display-mixed (handles)
5468 (mapcar 'gnus-mime-display-part handles))
5470 (defun gnus-mime-display-single (handle)
5471 (let ((type (mm-handle-media-type handle))
5472 (ignored gnus-ignored-mime-types)
5473 (not-attachment t)
5474 (move nil)
5475 display text)
5476 (catch 'ignored
5477 (progn
5478 (while ignored
5479 (when (string-match (pop ignored) type)
5480 (throw 'ignored nil)))
5481 (if (and (setq not-attachment
5482 (and (not (mm-inline-override-p handle))
5483 (or (not (mm-handle-disposition handle))
5484 (equal (car (mm-handle-disposition handle))
5485 "inline")
5486 (mm-attachment-override-p handle))))
5487 (mm-automatic-display-p handle)
5488 (or (and
5489 (mm-inlinable-p handle)
5490 (mm-inlined-p handle))
5491 (mm-automatic-external-display-p type)))
5492 (setq display t)
5493 (when (equal (mm-handle-media-supertype handle) "text")
5494 (setq text t)))
5495 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5496 beg)
5497 (push (cons id handle) gnus-article-mime-handle-alist)
5498 (when (and display
5499 (equal (mm-handle-media-supertype handle) "message"))
5500 (insert-char
5502 (cond ((not (bolp)) 2)
5503 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5504 (t 1))))
5505 (when (or (not display)
5506 (not (gnus-unbuttonized-mime-type-p type)))
5507 (gnus-insert-mime-button
5508 handle id (list (or display (and not-attachment text))))
5509 (gnus-article-insert-newline)
5510 ;; Remember modify the number of forward lines.
5511 (setq move t))
5512 (setq beg (point))
5513 (cond
5514 (display
5515 (when move
5516 (forward-line -1)
5517 (setq beg (point)))
5518 (let ((mail-parse-charset gnus-newsgroup-charset)
5519 (mail-parse-ignored-charsets
5520 (save-excursion (condition-case ()
5521 (set-buffer gnus-summary-buffer)
5522 (error))
5523 gnus-newsgroup-ignored-charsets)))
5524 (mm-display-part handle t))
5525 (goto-char (point-max)))
5526 ((and text not-attachment)
5527 (when move
5528 (forward-line -1)
5529 (setq beg (point)))
5530 (gnus-article-insert-newline)
5531 (mm-insert-inline
5532 handle
5533 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5534 'charset)
5535 (and (equal type "text/calendar") 'utf-8))))
5536 (cond ((not charset)
5537 (mm-string-as-multibyte (mm-get-part handle)))
5538 ((eq charset 'gnus-decoded)
5539 (with-current-buffer (mm-handle-buffer handle)
5540 (buffer-string)))
5542 (mm-decode-string (mm-get-part handle) charset)))))
5543 (goto-char (point-max))))
5544 ;; Do highlighting.
5545 (save-excursion
5546 (save-restriction
5547 (narrow-to-region beg (point))
5548 (if (eq handle gnus-article-mime-handles)
5549 ;; The format=flowed case.
5550 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5551 ;; Don't count signature parts that are never displayed.
5552 ;; The part number should be re-calculated supposing this
5553 ;; might be a message/rfc822 part.
5554 (let (handles)
5555 (dolist (part gnus-article-mime-handles)
5556 (unless (or (stringp part)
5557 (equal (car (mm-handle-type part))
5558 "application/pgp-signature"))
5559 (push part handles)))
5560 (gnus-treat-article
5561 nil (length (memq handle handles)) (length handles)
5562 (mm-handle-media-type handle)))))))))))
5564 (defun gnus-unbuttonized-mime-type-p (type)
5565 "Say whether TYPE is to be unbuttonized."
5566 (unless gnus-inhibit-mime-unbuttonizing
5567 (when (catch 'found
5568 (let ((types gnus-unbuttonized-mime-types))
5569 (while types
5570 (when (string-match (pop types) type)
5571 (throw 'found t)))))
5572 (not (catch 'found
5573 (let ((types gnus-buttonized-mime-types))
5574 (while types
5575 (when (string-match (pop types) type)
5576 (throw 'found t)))))))))
5578 (defun gnus-article-insert-newline ()
5579 "Insert a newline, but mark it as undeletable."
5580 (gnus-put-text-property
5581 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5583 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5584 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5585 (ihandles handles)
5586 (point (point))
5587 handle (inhibit-read-only t) from props begend not-pref)
5588 (save-window-excursion
5589 (save-restriction
5590 (when ibegend
5591 (narrow-to-region (car ibegend)
5592 (or (cdr ibegend)
5593 (progn
5594 (goto-char (car ibegend))
5595 (forward-line 2)
5596 (point))))
5597 (delete-region (point-min) (point-max))
5598 (mm-remove-parts handles))
5599 (setq begend (list (point-marker)))
5600 ;; Do the toggle.
5601 (unless (setq not-pref (cadr (member preferred ihandles)))
5602 (setq not-pref (car ihandles)))
5603 (when (or ibegend
5604 (not preferred)
5605 (not (gnus-unbuttonized-mime-type-p
5606 "multipart/alternative")))
5607 (gnus-add-text-properties
5608 (setq from (point))
5609 (progn
5610 (insert (format "%d. " id))
5611 (point))
5612 `(gnus-callback
5613 (lambda (handles)
5614 (unless ,(not ibegend)
5615 (setq gnus-article-mime-handle-alist
5616 ',gnus-article-mime-handle-alist))
5617 (gnus-mime-display-alternative
5618 ',ihandles ',not-pref ',begend ,id))
5619 keymap ,gnus-mime-button-map
5620 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5621 face ,gnus-article-button-face
5622 gnus-part ,id
5623 article-type multipart))
5624 (widget-convert-button 'link from (point)
5625 :action 'gnus-widget-press-button
5626 :button-keymap gnus-widget-button-keymap)
5627 ;; Do the handles
5628 (while (setq handle (pop handles))
5629 (gnus-add-text-properties
5630 (setq from (point))
5631 (progn
5632 (insert (format "(%c) %-18s"
5633 (if (equal handle preferred) ?* ? )
5634 (mm-handle-media-type handle)))
5635 (point))
5636 `(gnus-callback
5637 (lambda (handles)
5638 (unless ,(not ibegend)
5639 (setq gnus-article-mime-handle-alist
5640 ',gnus-article-mime-handle-alist))
5641 (gnus-mime-display-alternative
5642 ',ihandles ',handle ',begend ,id))
5643 keymap ,gnus-mime-button-map
5644 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5645 face ,gnus-article-button-face
5646 gnus-part ,id
5647 gnus-data ,handle))
5648 (widget-convert-button 'link from (point)
5649 :action 'gnus-widget-press-button
5650 :button-keymap gnus-widget-button-keymap)
5651 (insert " "))
5652 (insert "\n\n"))
5653 (when preferred
5654 (if (stringp (car preferred))
5655 (gnus-display-mime preferred)
5656 (let ((mail-parse-charset gnus-newsgroup-charset)
5657 (mail-parse-ignored-charsets
5658 (with-current-buffer gnus-summary-buffer
5659 gnus-newsgroup-ignored-charsets)))
5660 (mm-display-part preferred)
5661 ;; Do highlighting.
5662 (save-excursion
5663 (save-restriction
5664 (narrow-to-region (car begend) (point-max))
5665 (gnus-treat-article
5666 nil (length gnus-article-mime-handle-alist)
5667 (gnus-article-mime-total-parts)
5668 (mm-handle-media-type handle))))))
5669 (goto-char (point-max))
5670 (setcdr begend (point-marker)))))
5671 (when ibegend
5672 (goto-char point))))
5674 (defconst gnus-article-wash-status-strings
5675 (let ((alist '((cite "c" "Possible hidden citation text"
5676 " " "All citation text visible")
5677 (headers "h" "Hidden headers"
5678 " " "All headers visible.")
5679 (pgp "p" "Encrypted or signed message status hidden"
5680 " " "No hidden encryption nor digital signature status")
5681 (signature "s" "Signature has been hidden"
5682 " " "Signature is visible")
5683 (overstrike "o" "Overstrike (^H) characters applied"
5684 " " "No overstrike characters applied")
5685 (emphasis "e" "/*_Emphasis_*/ characters applied"
5686 " " "No /*_emphasis_*/ characters applied")))
5687 result)
5688 (dolist (entry alist result)
5689 (let ((key (nth 0 entry))
5690 (on (copy-sequence (nth 1 entry)))
5691 (on-help (nth 2 entry))
5692 (off (copy-sequence (nth 3 entry)))
5693 (off-help (nth 4 entry)))
5694 (put-text-property 0 1 'help-echo on-help on)
5695 (put-text-property 0 1 'help-echo off-help off)
5696 (push (list key on off) result))))
5697 "Alist of strings describing wash status in the mode line.
5698 Each entry has the form (KEY ON OF), where the KEY is a symbol
5699 representing the particular washing function, ON is the string to use
5700 in the article mode line when the washing function is active, and OFF
5701 is the string to use when it is inactive.")
5703 (defun gnus-article-wash-status-entry (key value)
5704 (let ((entry (assoc key gnus-article-wash-status-strings)))
5705 (if value (nth 1 entry) (nth 2 entry))))
5707 (defun gnus-article-wash-status ()
5708 "Return a string which display status of article washing."
5709 (with-current-buffer gnus-article-buffer
5710 (let ((cite (memq 'cite gnus-article-wash-types))
5711 (headers (memq 'headers gnus-article-wash-types))
5712 (boring (memq 'boring-headers gnus-article-wash-types))
5713 (pgp (memq 'pgp gnus-article-wash-types))
5714 (pem (memq 'pem gnus-article-wash-types))
5715 (signed (memq 'signed gnus-article-wash-types))
5716 (encrypted (memq 'encrypted gnus-article-wash-types))
5717 (signature (memq 'signature gnus-article-wash-types))
5718 (overstrike (memq 'overstrike gnus-article-wash-types))
5719 (emphasis (memq 'emphasis gnus-article-wash-types)))
5720 (concat
5721 (gnus-article-wash-status-entry 'cite cite)
5722 (gnus-article-wash-status-entry 'headers (or headers boring))
5723 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5724 (gnus-article-wash-status-entry 'signature signature)
5725 (gnus-article-wash-status-entry 'overstrike overstrike)
5726 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5728 (defun gnus-add-wash-type (type)
5729 "Add a washing of TYPE to the current status."
5730 (add-to-list 'gnus-article-wash-types type))
5732 (defun gnus-delete-wash-type (type)
5733 "Add a washing of TYPE to the current status."
5734 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5736 (defun gnus-add-image (category image)
5737 "Add IMAGE of CATEGORY to the list of displayed images."
5738 (let ((entry (assq category gnus-article-image-alist)))
5739 (unless entry
5740 (setq entry (list category))
5741 (push entry gnus-article-image-alist))
5742 (nconc entry (list image))))
5744 (defun gnus-delete-images (category)
5745 "Delete all images in CATEGORY."
5746 (let ((entry (assq category gnus-article-image-alist)))
5747 (dolist (image (cdr entry))
5748 (gnus-remove-image image category))
5749 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5750 (gnus-delete-wash-type category)))
5752 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5754 (defun gnus-article-maybe-hide-headers ()
5755 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5756 Provided for backwards compatibility."
5757 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5758 (not (with-current-buffer gnus-summary-buffer
5759 gnus-have-all-headers)))
5760 (not gnus-inhibit-hiding))
5761 (gnus-article-hide-headers)))
5763 ;;; Article savers.
5765 (defun gnus-output-to-file (file-name)
5766 "Append the current article to a file named FILE-NAME.
5767 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5768 text and used as the value of the coding cookie which is added to the
5769 top of a file. Otherwise, this function saves a raw article without
5770 the coding cookie."
5771 (let* ((artbuf (current-buffer))
5772 (file-name-coding-system nnmail-pathname-coding-system)
5773 (coding gnus-article-save-coding-system)
5774 (coding-system-for-read (if coding
5775 nil ;; Rely on the coding cookie.
5776 mm-text-coding-system))
5777 (coding-system-for-write (or coding
5778 mm-text-coding-system-for-write
5779 mm-text-coding-system))
5780 (exists (file-exists-p file-name)))
5781 (with-temp-buffer
5782 (when exists
5783 (insert-file-contents file-name)
5784 (goto-char (point-min))
5785 ;; Remove the existing coding cookie.
5786 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5787 (delete-region (match-beginning 0) (match-end 0))))
5788 (goto-char (point-max))
5789 (insert-buffer-substring artbuf)
5790 ;; Append newline at end of the buffer as separator, and then
5791 ;; save it to file.
5792 (goto-char (point-max))
5793 (insert "\n")
5794 (when coding
5795 ;; If the coding system is not suitable to encode the text,
5796 ;; ask a user for a proper one.
5797 (when (fboundp 'select-safe-coding-system)
5798 (setq coding (coding-system-base
5799 (save-window-excursion
5800 (select-safe-coding-system (point-min) (point-max)
5801 coding))))
5802 (setq coding-system-for-write
5803 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5804 coding)))
5805 (goto-char (point-min))
5806 ;; Add the coding cookie.
5807 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5808 coding-system-for-write)))
5809 (if exists
5810 (progn
5811 (write-region (point-min) (point-max) file-name nil 'no-message)
5812 (message "Appended to %s" file-name))
5813 (write-region (point-min) (point-max) file-name))))
5816 (defun gnus-narrow-to-page (&optional arg)
5817 "Narrow the article buffer to a page.
5818 If given a numerical ARG, move forward ARG pages."
5819 (interactive "P")
5820 (setq arg (if arg (prefix-numeric-value arg) 0))
5821 (save-excursion
5822 (set-buffer gnus-article-buffer)
5823 (goto-char (point-min))
5824 (widen)
5825 ;; Remove any old next/prev buttons.
5826 (when (gnus-visual-p 'page-marker)
5827 (let ((inhibit-read-only t))
5828 (gnus-remove-text-with-property 'gnus-prev)
5829 (gnus-remove-text-with-property 'gnus-next)))
5831 (cond ((< arg 0)
5832 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5833 ((> arg 0)
5834 (re-search-forward page-delimiter nil 'move arg)))
5835 (goto-char (match-end 0))
5836 (save-excursion
5837 (goto-char (point-min))
5838 (setq gnus-page-broken
5839 (and (re-search-forward page-delimiter nil t) t))))
5840 (when gnus-page-broken
5841 (narrow-to-region
5842 (point)
5843 (if (re-search-forward page-delimiter nil 'move)
5844 (match-beginning 0)
5845 (point)))
5846 (when (and (gnus-visual-p 'page-marker)
5847 (> (point-min) (save-restriction (widen) (point-min))))
5848 (save-excursion
5849 (goto-char (point-min))
5850 (gnus-insert-prev-page-button)))
5851 (when (and (gnus-visual-p 'page-marker)
5852 (< (point-max) (save-restriction (widen) (point-max))))
5853 (save-excursion
5854 (goto-char (point-max))
5855 (gnus-insert-next-page-button))))))
5857 ;; Article mode commands
5859 (defun gnus-article-goto-next-page ()
5860 "Show the next page of the article."
5861 (interactive)
5862 (when (gnus-article-next-page)
5863 (goto-char (point-min))
5864 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5867 (defun gnus-article-goto-prev-page ()
5868 "Show the previous page of the article."
5869 (interactive)
5870 (if (bobp)
5871 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5872 (gnus-article-prev-page nil)))
5874 ;; This is cleaner but currently breaks `gnus-pick-mode':
5876 ;; (defun gnus-article-goto-next-page ()
5877 ;; "Show the next page of the article."
5878 ;; (interactive)
5879 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5880 ;; (gnus-summary-next-page)))
5882 ;; (defun gnus-article-goto-prev-page ()
5883 ;; "Show the next page of the article."
5884 ;; (interactive)
5885 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5886 ;; (gnus-summary-prev-page)))
5888 (defun gnus-article-next-page (&optional lines)
5889 "Show the next page of the current article.
5890 If end of article, return non-nil. Otherwise return nil.
5891 Argument LINES specifies lines to be scrolled up."
5892 (interactive "p")
5893 (move-to-window-line -1)
5894 (if (and (not (and gnus-article-over-scroll
5895 (> (count-lines (window-start) (point-max))
5896 (+ (or lines (1- (window-height)))
5897 (or (and (boundp 'scroll-margin)
5898 (symbol-value 'scroll-margin))
5899 0)))))
5900 (save-excursion
5901 (end-of-line)
5902 (and (pos-visible-in-window-p) ;Not continuation line.
5903 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
5904 ;; Nothing in this page.
5905 (if (or (not gnus-page-broken)
5906 (save-excursion
5907 (save-restriction
5908 (widen)
5909 (forward-line)
5910 (eobp)))) ;Real end-of-buffer?
5911 (progn
5912 (when gnus-article-over-scroll
5913 (gnus-article-next-page-1 lines))
5914 t) ;Nothing more.
5915 (gnus-narrow-to-page 1) ;Go to next page.
5916 nil)
5917 ;; More in this page.
5918 (gnus-article-next-page-1 lines)
5919 nil))
5921 (defmacro gnus-article-beginning-of-window ()
5922 "Move point to the beginning of the window.
5923 In Emacs, the point is placed at the line number which `scroll-margin'
5924 specifies."
5925 (if (featurep 'xemacs)
5926 '(move-to-window-line 0)
5927 '(move-to-window-line
5928 (min (max 0 scroll-margin)
5929 (max 1 (- (window-height)
5930 (if mode-line-format 1 0)
5931 (if header-line-format 1 0)))))))
5933 (defun gnus-article-next-page-1 (lines)
5934 (when (and (not (featurep 'xemacs))
5935 (numberp lines)
5936 (> lines 0)
5937 (numberp (symbol-value 'scroll-margin))
5938 (> (symbol-value 'scroll-margin) 0))
5939 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5940 ;; too many number of lines if `scroll-margin' is set as two or greater.
5941 (setq lines (min lines
5942 (max 0 (- (count-lines (window-start) (point-max))
5943 (symbol-value 'scroll-margin))))))
5944 (condition-case ()
5945 (let ((scroll-in-place nil))
5946 (scroll-up lines))
5947 (end-of-buffer
5948 ;; Long lines may cause an end-of-buffer error.
5949 (goto-char (point-max))))
5950 (gnus-article-beginning-of-window))
5952 (defun gnus-article-prev-page (&optional lines)
5953 "Show previous page of current article.
5954 Argument LINES specifies lines to be scrolled down."
5955 (interactive "p")
5956 (move-to-window-line 0)
5957 (if (and gnus-page-broken
5958 (bobp)
5959 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5960 (progn
5961 (gnus-narrow-to-page -1) ;Go to previous page.
5962 (goto-char (point-max))
5963 (recenter (if gnus-article-over-scroll
5964 (if lines
5965 (max (+ lines (or (and (boundp 'scroll-margin)
5966 (symbol-value 'scroll-margin))
5969 (- (window-height) 2))
5970 -1)))
5971 (prog1
5972 (condition-case ()
5973 (let ((scroll-in-place nil))
5974 (scroll-down lines))
5975 (beginning-of-buffer
5976 (goto-char (point-min))))
5977 (gnus-article-beginning-of-window))))
5979 (defun gnus-article-only-boring-p ()
5980 "Decide whether there is only boring text remaining in the article.
5981 Something \"interesting\" is a word of at least two letters that does
5982 not have a face in `gnus-article-boring-faces'."
5983 (when (and gnus-article-skip-boring
5984 (boundp 'gnus-article-boring-faces)
5985 (symbol-value 'gnus-article-boring-faces))
5986 (save-excursion
5987 (let ((inhibit-point-motion-hooks t))
5988 (catch 'only-boring
5989 (while (re-search-forward "\\b\\w\\w" nil t)
5990 (forward-char -1)
5991 (when (not (gnus-intersection
5992 (gnus-faces-at (point))
5993 (symbol-value 'gnus-article-boring-faces)))
5994 (throw 'only-boring nil)))
5995 (throw 'only-boring t))))))
5997 (defun gnus-article-refer-article ()
5998 "Read article specified by message-id around point."
5999 (interactive)
6000 (save-excursion
6001 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6002 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6003 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6004 (let ((msg-id (concat "<" (match-string 0) ">")))
6005 (set-buffer gnus-summary-buffer)
6006 (gnus-summary-refer-article msg-id))
6007 (error "No references around point"))))
6009 (defun gnus-article-show-summary ()
6010 "Reconfigure windows to show summary buffer."
6011 (interactive)
6012 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6013 (error "There is no summary buffer for this article buffer")
6014 (gnus-article-set-globals)
6015 (gnus-configure-windows 'article)
6016 (gnus-summary-goto-subject gnus-current-article)
6017 (gnus-summary-position-point)))
6019 (defun gnus-article-describe-briefly ()
6020 "Describe article mode commands briefly."
6021 (interactive)
6022 (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")))
6024 (defun gnus-article-summary-command ()
6025 "Execute the last keystroke in the summary buffer."
6026 (interactive)
6027 (let ((obuf (current-buffer))
6028 (owin (current-window-configuration))
6029 func)
6030 (switch-to-buffer gnus-article-current-summary 'norecord)
6031 (setq func (lookup-key (current-local-map) (this-command-keys)))
6032 (call-interactively func)
6033 (set-buffer obuf)
6034 (set-window-configuration owin)
6035 (set-window-point (get-buffer-window (current-buffer)) (point))))
6037 (defun gnus-article-summary-command-nosave ()
6038 "Execute the last keystroke in the summary buffer."
6039 (interactive)
6040 (let (func)
6041 (pop-to-buffer gnus-article-current-summary)
6042 (setq func (lookup-key (current-local-map) (this-command-keys)))
6043 (call-interactively func)))
6045 (defun gnus-article-check-buffer ()
6046 "Beep if not in an article buffer."
6047 (unless (equal major-mode 'gnus-article-mode)
6048 (error "Command invoked outside of a Gnus article buffer")))
6050 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6051 "Read a summary buffer key sequence and execute it from the article buffer."
6052 (interactive "P")
6053 (gnus-article-check-buffer)
6054 (let ((nosaves
6055 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6056 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6057 "=" "^" "\M-^" "|"))
6058 (nosave-but-article
6059 '("A\r"))
6060 (nosave-in-article
6061 '("\C-d"))
6062 (up-to-top
6063 '("n" "Gn" "p" "Gp"))
6064 keys new-sum-point)
6065 (save-excursion
6066 (set-buffer gnus-article-current-summary)
6067 (let (gnus-pick-mode)
6068 (push (or key last-command-event) unread-command-events)
6069 (setq keys (if (featurep 'xemacs)
6070 (events-to-keys (read-key-sequence nil))
6071 (read-key-sequence nil)))))
6073 (message "")
6075 (cond
6076 ((eq (aref keys (1- (length keys))) ?\C-h)
6077 (with-current-buffer gnus-article-current-summary
6078 (describe-bindings (substring keys 0 -1))))
6079 ((or (member keys nosaves)
6080 (member keys nosave-but-article)
6081 (member keys nosave-in-article))
6082 (let (func)
6083 (save-window-excursion
6084 (pop-to-buffer gnus-article-current-summary)
6085 ;; We disable the pick minor mode commands.
6086 (let (gnus-pick-mode)
6087 (setq func (lookup-key (current-local-map) keys))))
6088 (if (or (not func)
6089 (numberp func))
6090 (ding)
6091 (unless (member keys nosave-in-article)
6092 (set-buffer gnus-article-current-summary))
6093 (call-interactively func)
6094 (setq new-sum-point (point)))
6095 (when (member keys nosave-but-article)
6096 (pop-to-buffer gnus-article-buffer))))
6098 ;; These commands should restore window configuration.
6099 (let ((obuf (current-buffer))
6100 (owin (current-window-configuration))
6101 win func in-buffer selected new-sum-start new-sum-hscroll err)
6102 (cond (not-restore-window
6103 (pop-to-buffer gnus-article-current-summary)
6104 (setq win (selected-window)))
6105 ((setq win (get-buffer-window gnus-article-current-summary))
6106 (select-window win))
6108 (let ((summary-buffer gnus-article-current-summary))
6109 (gnus-configure-windows 'article)
6110 (unless (setq win (get-buffer-window summary-buffer 'visible))
6111 (let ((gnus-buffer-configuration
6112 '(article ((vertical 1.0
6113 (summary 0.25 point)
6114 (article 1.0))))))
6115 (gnus-configure-windows 'article))
6116 (setq win (get-buffer-window summary-buffer 'visible)))
6117 (gnus-select-frame-set-input-focus (window-frame win))
6118 (select-window win))))
6119 (setq in-buffer (current-buffer))
6120 ;; We disable the pick minor mode commands.
6121 (if (and (setq func (let (gnus-pick-mode)
6122 (lookup-key (current-local-map) keys)))
6123 (functionp func)
6124 (condition-case code
6125 (progn
6126 (call-interactively func)
6128 (error
6129 (setq err code)
6130 nil)))
6131 (progn
6132 (when (eq win (selected-window))
6133 (setq new-sum-point (point)
6134 new-sum-start (window-start win)
6135 new-sum-hscroll (window-hscroll win)))
6136 (when (or (eq in-buffer (current-buffer))
6137 (when (eq obuf (current-buffer))
6138 (set-buffer in-buffer)
6140 (setq selected (gnus-summary-select-article))
6141 (set-buffer obuf)
6142 (unless not-restore-window
6143 (set-window-configuration owin))
6144 (when (and (eq selected 'old)
6145 new-sum-point)
6146 (set-window-start (get-buffer-window (current-buffer))
6148 (set-window-point (get-buffer-window (current-buffer))
6149 (if (article-goto-body)
6150 (1- (point))
6151 (point))))
6152 (when (and (not not-restore-window)
6153 new-sum-point
6154 (with-current-buffer (window-buffer win)
6155 (eq major-mode 'gnus-summary-mode)))
6156 (set-window-point win new-sum-point)
6157 (set-window-start win new-sum-start)
6158 (set-window-hscroll win new-sum-hscroll))))
6159 (set-window-configuration owin)
6160 (if err
6161 (signal (car err) (cdr err))
6162 (ding))))))))
6164 (defun gnus-article-describe-key (key)
6165 "Display documentation of the function invoked by KEY. KEY is a string."
6166 (interactive "kDescribe key: ")
6167 (gnus-article-check-buffer)
6168 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6169 (save-excursion
6170 (set-buffer gnus-article-current-summary)
6171 (let (gnus-pick-mode)
6172 (if (featurep 'xemacs)
6173 (progn
6174 (push (elt key 0) unread-command-events)
6175 (setq key (events-to-keys
6176 (read-key-sequence "Describe key: "))))
6177 (setq unread-command-events
6178 (mapcar
6179 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6180 (string-to-list key)))
6181 (setq key (read-key-sequence "Describe key: "))))
6182 (describe-key key))
6183 (describe-key key)))
6185 (defun gnus-article-describe-key-briefly (key &optional insert)
6186 "Display documentation of the function invoked by KEY. KEY is a string."
6187 (interactive "kDescribe key: \nP")
6188 (gnus-article-check-buffer)
6189 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6190 (save-excursion
6191 (set-buffer gnus-article-current-summary)
6192 (let (gnus-pick-mode)
6193 (if (featurep 'xemacs)
6194 (progn
6195 (push (elt key 0) unread-command-events)
6196 (setq key (events-to-keys
6197 (read-key-sequence "Describe key: "))))
6198 (setq unread-command-events
6199 (mapcar
6200 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6201 (string-to-list key)))
6202 (setq key (read-key-sequence "Describe key: "))))
6203 (describe-key-briefly key insert))
6204 (describe-key-briefly key insert)))
6206 (defun gnus-article-reply-with-original (&optional wide)
6207 "Start composing a reply mail to the current message.
6208 The text in the region will be yanked. If the region isn't active,
6209 the entire article will be yanked."
6210 (interactive "P")
6211 (let ((article (cdr gnus-article-current))
6212 contents)
6213 (if (not (gnus-region-active-p))
6214 (with-current-buffer gnus-summary-buffer
6215 (gnus-summary-reply (list (list article)) wide))
6216 (setq contents (buffer-substring (point) (mark t)))
6217 ;; Deactivate active regions.
6218 (when (and (boundp 'transient-mark-mode)
6219 transient-mark-mode)
6220 (setq mark-active nil))
6221 (with-current-buffer gnus-summary-buffer
6222 (gnus-summary-reply
6223 (list (list article contents)) wide)))))
6225 (defun gnus-article-followup-with-original ()
6226 "Compose a followup to the current article.
6227 The text in the region will be yanked. If the region isn't active,
6228 the entire article will be yanked."
6229 (interactive)
6230 (let ((article (cdr gnus-article-current))
6231 contents)
6232 (if (not (gnus-region-active-p))
6233 (with-current-buffer gnus-summary-buffer
6234 (gnus-summary-followup (list (list article))))
6235 (setq contents (buffer-substring (point) (mark t)))
6236 ;; Deactivate active regions.
6237 (when (and (boundp 'transient-mark-mode)
6238 transient-mark-mode)
6239 (setq mark-active nil))
6240 (with-current-buffer gnus-summary-buffer
6241 (gnus-summary-followup
6242 (list (list article contents)))))))
6244 (defun gnus-article-hide (&optional arg force)
6245 "Hide all the gruft in the current article.
6246 This means that signatures, cited text and (some) headers will be
6247 hidden.
6248 If given a prefix, show the hidden text instead."
6249 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6250 (gnus-article-hide-headers arg)
6251 (gnus-article-hide-list-identifiers arg)
6252 (gnus-article-hide-citation-maybe arg force)
6253 (gnus-article-hide-signature arg))
6255 (defun gnus-article-maybe-highlight ()
6256 "Do some article highlighting if article highlighting is requested."
6257 (when (gnus-visual-p 'article-highlight 'highlight)
6258 (gnus-article-highlight-some)))
6260 (defun gnus-check-group-server ()
6261 ;; Make sure the connection to the server is alive.
6262 (unless (gnus-server-opened
6263 (gnus-find-method-for-group gnus-newsgroup-name))
6264 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6265 (gnus-request-group gnus-newsgroup-name t)))
6267 (eval-when-compile
6268 (autoload 'nneething-get-file-name "nneething"))
6270 (defun gnus-request-article-this-buffer (article group)
6271 "Get an article and insert it into this buffer."
6272 (let (do-update-line sparse-header)
6273 (prog1
6274 (save-excursion
6275 (erase-buffer)
6276 (gnus-kill-all-overlays)
6277 (setq group (or group gnus-newsgroup-name))
6279 ;; Using `gnus-request-article' directly will insert the article into
6280 ;; `nntp-server-buffer' - so we'll save some time by not having to
6281 ;; copy it from the server buffer into the article buffer.
6283 ;; We only request an article by message-id when we do not have the
6284 ;; headers for it, so we'll have to get those.
6285 (when (stringp article)
6286 (gnus-read-header article))
6288 ;; If the article number is negative, that means that this article
6289 ;; doesn't belong in this newsgroup (possibly), so we find its
6290 ;; message-id and request it by id instead of number.
6291 (when (and (numberp article)
6292 gnus-summary-buffer
6293 (get-buffer gnus-summary-buffer)
6294 (gnus-buffer-exists-p gnus-summary-buffer))
6295 (save-excursion
6296 (set-buffer gnus-summary-buffer)
6297 (let ((header (gnus-summary-article-header article)))
6298 (when (< article 0)
6299 (cond
6300 ((memq article gnus-newsgroup-sparse)
6301 ;; This is a sparse gap article.
6302 (setq do-update-line article)
6303 (setq article (mail-header-id header))
6304 (setq sparse-header (gnus-read-header article))
6305 (setq gnus-newsgroup-sparse
6306 (delq article gnus-newsgroup-sparse)))
6307 ((vectorp header)
6308 ;; It's a real article.
6309 (setq article (mail-header-id header)))
6311 ;; It is an extracted pseudo-article.
6312 (setq article 'pseudo)
6313 (gnus-request-pseudo-article header))))
6315 (let ((method (gnus-find-method-for-group
6316 gnus-newsgroup-name)))
6317 (when (and (eq (car method) 'nneething)
6318 (vectorp header))
6319 (let ((dir (nneething-get-file-name
6320 (mail-header-id header))))
6321 (when (and (stringp dir)
6322 (file-directory-p dir))
6323 (setq article 'nneething)
6324 (gnus-group-enter-directory dir))))))))
6326 (cond
6327 ;; Refuse to select canceled articles.
6328 ((and (numberp article)
6329 gnus-summary-buffer
6330 (get-buffer gnus-summary-buffer)
6331 (gnus-buffer-exists-p gnus-summary-buffer)
6332 (eq (cdr (with-current-buffer gnus-summary-buffer
6333 (assq article gnus-newsgroup-reads)))
6334 gnus-canceled-mark))
6335 nil)
6336 ;; We first check `gnus-original-article-buffer'.
6337 ((and (get-buffer gnus-original-article-buffer)
6338 (numberp article)
6339 (with-current-buffer gnus-original-article-buffer
6340 (and (equal (car gnus-original-article) group)
6341 (eq (cdr gnus-original-article) article))))
6342 (insert-buffer-substring gnus-original-article-buffer)
6343 'article)
6344 ;; Check the backlog.
6345 ((and gnus-keep-backlog
6346 (gnus-backlog-request-article group article (current-buffer)))
6347 'article)
6348 ;; Check asynchronous pre-fetch.
6349 ((gnus-async-request-fetched-article group article (current-buffer))
6350 (gnus-async-prefetch-next group article gnus-summary-buffer)
6351 (when (and (numberp article) gnus-keep-backlog)
6352 (gnus-backlog-enter-article group article (current-buffer)))
6353 'article)
6354 ;; Check the cache.
6355 ((and gnus-use-cache
6356 (numberp article)
6357 (gnus-cache-request-article article group))
6358 'article)
6359 ;; Check the agent cache.
6360 ((gnus-agent-request-article article group)
6361 'article)
6362 ;; Get the article and put into the article buffer.
6363 ((or (stringp article)
6364 (numberp article))
6365 (let ((gnus-override-method gnus-override-method)
6366 (methods (and (stringp article)
6367 gnus-refer-article-method))
6368 (backend (car (gnus-find-method-for-group
6369 gnus-newsgroup-name)))
6370 result
6371 (inhibit-read-only t))
6372 (if (or (not (listp methods))
6373 (and (symbolp (car methods))
6374 (assq (car methods) nnoo-definition-alist)))
6375 (setq methods (list methods)))
6376 (when (and (null gnus-override-method)
6377 methods)
6378 (setq gnus-override-method (pop methods)))
6379 (while (not result)
6380 (when (eq gnus-override-method 'current)
6381 (setq gnus-override-method
6382 (with-current-buffer gnus-summary-buffer
6383 gnus-current-select-method)))
6384 (erase-buffer)
6385 (gnus-kill-all-overlays)
6386 (let ((gnus-newsgroup-name group))
6387 (gnus-check-group-server))
6388 (cond
6389 ((gnus-request-article article group (current-buffer))
6390 (when (numberp article)
6391 (gnus-async-prefetch-next group article
6392 gnus-summary-buffer)
6393 (when gnus-keep-backlog
6394 (gnus-backlog-enter-article
6395 group article (current-buffer))))
6396 (setq result 'article))
6397 (methods
6398 (setq gnus-override-method (pop methods)))
6399 ((not (string-match "^400 "
6400 (nnheader-get-report backend)))
6401 ;; If we get 400 server disconnect, reconnect and
6402 ;; retry; otherwise, assume the article has expired.
6403 (setq result 'done))))
6404 (and (eq result 'article) 'article)))
6405 ;; It was a pseudo.
6406 (t article)))
6408 ;; Associate this article with the current summary buffer.
6409 (setq gnus-article-current-summary gnus-summary-buffer)
6411 ;; Take the article from the original article buffer
6412 ;; and place it in the buffer it's supposed to be in.
6413 (when (and (get-buffer gnus-article-buffer)
6414 (equal (buffer-name (current-buffer))
6415 (buffer-name (get-buffer gnus-article-buffer))))
6416 (save-excursion
6417 (if (get-buffer gnus-original-article-buffer)
6418 (set-buffer gnus-original-article-buffer)
6419 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6420 (buffer-disable-undo)
6421 (setq major-mode 'gnus-original-article-mode)
6422 (setq buffer-read-only t))
6423 (let ((inhibit-read-only t))
6424 (erase-buffer)
6425 (insert-buffer-substring gnus-article-buffer))
6426 (setq gnus-original-article (cons group article)))
6428 ;; Decode charsets.
6429 (run-hooks 'gnus-article-decode-hook)
6430 ;; Mark article as decoded or not.
6431 (setq gnus-article-decoded-p gnus-article-decode-hook))
6433 ;; Update sparse articles.
6434 (when (and do-update-line
6435 (or (numberp article)
6436 (stringp article)))
6437 (let ((buf (current-buffer)))
6438 (set-buffer gnus-summary-buffer)
6439 (gnus-summary-update-article do-update-line sparse-header)
6440 (gnus-summary-goto-subject do-update-line nil t)
6441 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6442 (point))
6443 (set-buffer buf))))))
6446 ;;; Article editing
6449 (defcustom gnus-article-edit-mode-hook nil
6450 "Hook run in article edit mode buffers."
6451 :group 'gnus-article-various
6452 :type 'hook)
6454 (defvar gnus-article-edit-done-function nil)
6456 (defvar gnus-article-edit-mode-map nil)
6458 ;; Should we be using derived.el for this?
6459 (unless gnus-article-edit-mode-map
6460 (setq gnus-article-edit-mode-map (make-keymap))
6461 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6463 (gnus-define-keys gnus-article-edit-mode-map
6464 "\C-c?" describe-mode
6465 "\C-c\C-c" gnus-article-edit-done
6466 "\C-c\C-k" gnus-article-edit-exit
6467 "\C-c\C-f\C-t" message-goto-to
6468 "\C-c\C-f\C-o" message-goto-from
6469 "\C-c\C-f\C-b" message-goto-bcc
6470 ;;"\C-c\C-f\C-w" message-goto-fcc
6471 "\C-c\C-f\C-c" message-goto-cc
6472 "\C-c\C-f\C-s" message-goto-subject
6473 "\C-c\C-f\C-r" message-goto-reply-to
6474 "\C-c\C-f\C-n" message-goto-newsgroups
6475 "\C-c\C-f\C-d" message-goto-distribution
6476 "\C-c\C-f\C-f" message-goto-followup-to
6477 "\C-c\C-f\C-m" message-goto-mail-followup-to
6478 "\C-c\C-f\C-k" message-goto-keywords
6479 "\C-c\C-f\C-u" message-goto-summary
6480 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6481 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6482 "\C-c\C-b" message-goto-body
6483 "\C-c\C-i" message-goto-signature
6485 "\C-c\C-t" message-insert-to
6486 "\C-c\C-n" message-insert-newsgroups
6487 "\C-c\C-o" message-sort-headers
6488 "\C-c\C-e" message-elide-region
6489 "\C-c\C-v" message-delete-not-region
6490 "\C-c\C-z" message-kill-to-signature
6491 "\M-\r" message-newline-and-reformat
6492 "\C-c\C-a" mml-attach-file
6493 "\C-a" message-beginning-of-line
6494 "\t" message-tab
6495 "\M-;" comment-region)
6497 (gnus-define-keys (gnus-article-edit-wash-map
6498 "\C-c\C-w" gnus-article-edit-mode-map)
6499 "f" gnus-article-edit-full-stops))
6501 (easy-menu-define
6502 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6503 '("Field"
6504 ["Fetch To" message-insert-to t]
6505 ["Fetch Newsgroups" message-insert-newsgroups t]
6506 "----"
6507 ["To" message-goto-to t]
6508 ["From" message-goto-from t]
6509 ["Subject" message-goto-subject t]
6510 ["Cc" message-goto-cc t]
6511 ["Reply-To" message-goto-reply-to t]
6512 ["Summary" message-goto-summary t]
6513 ["Keywords" message-goto-keywords t]
6514 ["Newsgroups" message-goto-newsgroups t]
6515 ["Followup-To" message-goto-followup-to t]
6516 ["Mail-Followup-To" message-goto-mail-followup-to t]
6517 ["Distribution" message-goto-distribution t]
6518 ["Body" message-goto-body t]
6519 ["Signature" message-goto-signature t]))
6521 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6522 "Major mode for editing articles.
6523 This is an extended text-mode.
6525 \\{gnus-article-edit-mode-map}"
6526 (make-local-variable 'gnus-article-edit-done-function)
6527 (make-local-variable 'gnus-prev-winconf)
6528 (set (make-local-variable 'font-lock-defaults)
6529 '(message-font-lock-keywords t))
6530 (set (make-local-variable 'mail-header-separator) "")
6531 (set (make-local-variable 'gnus-article-edit-mode) t)
6532 (easy-menu-add message-mode-field-menu message-mode-map)
6533 (mml-mode)
6534 (setq buffer-read-only nil)
6535 (buffer-enable-undo)
6536 (widen))
6538 (defun gnus-article-edit (&optional force)
6539 "Edit the current article.
6540 This will have permanent effect only in mail groups.
6541 If FORCE is non-nil, allow editing of articles even in read-only
6542 groups."
6543 (interactive "P")
6544 (when (and (not force)
6545 (gnus-group-read-only-p))
6546 (error "The current newsgroup does not support article editing"))
6547 (gnus-article-date-original)
6548 (gnus-article-edit-article
6549 'ignore
6550 `(lambda (no-highlight)
6551 'ignore
6552 (gnus-summary-edit-article-done
6553 ,(or (mail-header-references gnus-current-headers) "")
6554 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6556 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6557 "Start editing the contents of the current article buffer."
6558 (let ((winconf (current-window-configuration)))
6559 (set-buffer gnus-article-buffer)
6560 (let ((message-auto-save-directory
6561 ;; Don't associate the article buffer with a draft file.
6562 nil))
6563 (gnus-article-edit-mode))
6564 (funcall start-func)
6565 (set-buffer-modified-p nil)
6566 (gnus-configure-windows 'edit-article)
6567 (setq gnus-article-edit-done-function exit-func)
6568 (setq gnus-prev-winconf winconf)
6569 (unless quiet
6570 (gnus-message 6 "C-c C-c to end edits"))))
6572 (defun gnus-article-edit-done (&optional arg)
6573 "Update the article edits and exit."
6574 (interactive "P")
6575 (let ((func gnus-article-edit-done-function)
6576 (buf (current-buffer))
6577 (start (window-start))
6578 (p (point))
6579 (winconf gnus-prev-winconf))
6580 (widen) ;; Widen it in case that users narrowed the buffer.
6581 (funcall func arg)
6582 (set-buffer buf)
6583 ;; The cache and backlog have to be flushed somewhat.
6584 (when gnus-keep-backlog
6585 (gnus-backlog-remove-article
6586 (car gnus-article-current) (cdr gnus-article-current)))
6587 ;; Flush original article as well.
6588 (save-excursion
6589 (when (get-buffer gnus-original-article-buffer)
6590 (set-buffer gnus-original-article-buffer)
6591 (setq gnus-original-article nil)))
6592 (when gnus-use-cache
6593 (gnus-cache-update-article
6594 (car gnus-article-current) (cdr gnus-article-current)))
6595 ;; We remove all text props from the article buffer.
6596 (kill-all-local-variables)
6597 (set-text-properties (point-min) (point-max) nil)
6598 (gnus-article-mode)
6599 (set-window-configuration winconf)
6600 (set-buffer buf)
6601 (set-window-start (get-buffer-window buf) start)
6602 (set-window-point (get-buffer-window buf) (point)))
6603 (gnus-summary-show-article))
6605 (defun gnus-article-edit-exit ()
6606 "Exit the article editing without updating."
6607 (interactive)
6608 (when (or (not (buffer-modified-p))
6609 (yes-or-no-p "Article modified; kill anyway? "))
6610 (let ((curbuf (current-buffer))
6611 (p (point))
6612 (window-start (window-start)))
6613 (erase-buffer)
6614 (if (gnus-buffer-live-p gnus-original-article-buffer)
6615 (insert-buffer-substring gnus-original-article-buffer))
6616 (let ((winconf gnus-prev-winconf))
6617 (kill-all-local-variables)
6618 (gnus-article-mode)
6619 (set-window-configuration winconf)
6620 ;; Tippy-toe some to make sure that point remains where it was.
6621 (save-current-buffer
6622 (set-buffer curbuf)
6623 (set-window-start (get-buffer-window (current-buffer)) window-start)
6624 (goto-char p))))
6625 (gnus-summary-show-article)))
6627 (defun gnus-article-edit-full-stops ()
6628 "Interactively repair spacing at end of sentences."
6629 (interactive)
6630 (save-excursion
6631 (goto-char (point-min))
6632 (search-forward-regexp "^$" nil t)
6633 (let ((case-fold-search nil))
6634 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6637 ;;; Article highlights
6640 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6642 ;;; Internal Variables:
6644 (defcustom gnus-button-url-regexp
6645 (concat
6646 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6647 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6648 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6649 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6650 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6651 (punct "!?:;.,"))
6652 (concat
6653 "\\(?:"
6654 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6655 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6656 "\\|"
6657 "[" chars punct "]+" "[" chars "]"
6658 "\\)"))
6659 (concat ;; XEmacs 21.4 doesn't support POSIX.
6660 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6661 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6662 "\\)")
6663 "Regular expression that matches URLs."
6664 :group 'gnus-article-buttons
6665 :type 'regexp)
6667 (defcustom gnus-button-valid-fqdn-regexp
6668 message-valid-fqdn-regexp
6669 "Regular expression that matches a valid FQDN."
6670 :version "22.1"
6671 :group 'gnus-article-buttons
6672 :type 'regexp)
6674 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6675 (defcustom gnus-button-valid-localpart-regexp
6676 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6677 "Regular expression that matches a localpart of mail addresses or MIDs."
6678 :version "22.1"
6679 :group 'gnus-article-buttons
6680 :type 'regexp)
6682 (defcustom gnus-button-man-handler 'manual-entry
6683 "Function to use for displaying man pages.
6684 The function must take at least one argument with a string naming the
6685 man page."
6686 :version "22.1"
6687 :type '(choice (function-item :tag "Man" manual-entry)
6688 (function-item :tag "Woman" woman)
6689 (function :tag "Other"))
6690 :group 'gnus-article-buttons)
6692 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6693 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6694 If the default site is too slow, try to find a CTAN mirror, see
6695 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6696 the variable `gnus-button-handle-ctan'."
6697 :version "22.1"
6698 :group 'gnus-article-buttons
6699 :link '(custom-manual "(gnus)Group Parameters")
6700 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6701 (const "http://tug.ctan.org/tex-archive/")
6702 (const "http://www.dante.de/CTAN/")
6703 (string :tag "Other")))
6705 (defcustom gnus-button-ctan-handler 'browse-url
6706 "Function to use for displaying CTAN links.
6707 The function must take one argument, the string naming the URL."
6708 :version "22.1"
6709 :type '(choice (function-item :tag "Browse Url" browse-url)
6710 (function :tag "Other"))
6711 :group 'gnus-article-buttons)
6713 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6714 "Bogus strings removed from CTAN URLs."
6715 :version "22.1"
6716 :group 'gnus-article-buttons
6717 :type '(choice (const "^/?tex-archive/\\|/")
6718 (regexp :tag "Other")))
6720 (defcustom gnus-button-ctan-directory-regexp
6721 (regexp-opt
6722 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6723 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6724 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6725 "tds" "tools" "usergrps" "web") t)
6726 "Regular expression for ctan directories.
6727 It should match all directories in the top level of `gnus-ctan-url'."
6728 :version "22.1"
6729 :group 'gnus-article-buttons
6730 :type 'regexp)
6732 (defcustom gnus-button-mid-or-mail-regexp
6733 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6734 gnus-button-valid-fqdn-regexp
6735 ">?\\)\\b")
6736 "Regular expression that matches a message ID or a mail address."
6737 :version "22.1"
6738 :group 'gnus-article-buttons
6739 :type 'regexp)
6741 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6742 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6743 Strings like this can be either a message ID or a mail address. If it is one
6744 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6745 message ID or a mail address, respectively. If this variable is set to the
6746 symbol `ask', always query the user what do do. If it is a function, this
6747 function will be called with the string as its only argument. The function
6748 must return `mid', `mail', `invalid' or `ask'."
6749 :version "22.1"
6750 :group 'gnus-article-buttons
6751 :type '(choice (function-item :tag "Heuristic function"
6752 gnus-button-mid-or-mail-heuristic)
6753 (const ask)
6754 (const mid)
6755 (const mail)))
6757 (defcustom gnus-button-mid-or-mail-heuristic-alist
6758 '((-10.0 . ".+\\$.+@")
6759 (-10.0 . "#")
6760 (-10.0 . "\\*")
6761 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6762 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6763 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6764 (-1.0 . "^[^a-z]+@")
6766 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6767 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6768 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6769 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6771 (-2.0 . "^[0-9]")
6772 (-1.0 . "^[0-9][0-9]")
6774 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6775 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6776 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6777 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6779 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6780 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6781 ;; "[0-9]{8,}.*\@"
6782 (-3.0
6783 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6784 ;; "[0-9]{12,}.*\@"
6785 ;; compensation for TDMA dated mail addresses:
6786 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6788 (-20.0 . "\\.fsf@") ;; Gnus
6789 (-20.0 . "^slrn")
6790 (-20.0 . "^Pine")
6791 (-20.0 . "^alpine\\.")
6792 (-20.0 . "_-_") ;; Subject change in thread
6794 (-20.0 . "\\.ln@") ;; leafnode
6795 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6796 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6798 ;; (5.0 . "") ;; $local_part_len <= 7
6799 (10.0 . "^[^0-9]+@")
6800 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6801 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6802 (3.0 . "\@stud")
6804 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6806 (0.5 . "^[A-Z][a-z]")
6807 (0.5 . "^[A-Z][a-z][a-z]")
6808 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6809 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6810 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6812 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6813 address. The REGEXP is processed with `case-fold-search' set to nil."
6814 :version "22.1"
6815 :group 'gnus-article-buttons
6816 :type '(repeat (cons (number :tag "Rate")
6817 (regexp :tag "Regexp"))))
6819 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6820 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6821 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6822 address, `ask' if unsure and `invalid' if the string is invalid."
6823 (let ((case-fold-search nil)
6824 (list gnus-button-mid-or-mail-heuristic-alist)
6825 (result 0) rate regexp lpartlen elem)
6826 (setq lpartlen
6827 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6828 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6829 ;; Certain special cases...
6830 (when (string-match
6831 (concat
6832 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6833 "^[0-9]+\\.[0-9]+@compuserve\\|"
6834 "@public\\.gmane\\.org")
6835 mid-or-mail)
6836 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6837 (setq result 'mail))
6838 (when (string-match "@.*@\\| " mid-or-mail)
6839 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6840 (setq result 'invalid))
6841 ;; Nothing more to do, if result is not a number here...
6842 (when (numberp result)
6843 (while list
6844 (setq elem (car list)
6845 rate (car elem)
6846 regexp (cdr elem)
6847 list (cdr list))
6848 (when (string-match regexp mid-or-mail)
6849 (setq result (+ result rate))
6850 (gnus-message
6851 9 "`%s' matched `%s', rate `%s', result `%s'."
6852 mid-or-mail regexp rate result)))
6853 (when (<= lpartlen 7)
6854 (setq result (+ result 5.0))
6855 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6856 mid-or-mail result))
6857 (when (>= lpartlen 12)
6858 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6859 (cond
6860 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6861 ;; Long local part should contain realname if e-mail address,
6862 ;; too many digits: message-id.
6863 ;; $score -= 5.0 + 0.1 * $local_part_len;
6864 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6865 (setq result (+ result rate))
6866 (gnus-message
6867 9 "Many digits in `%s', rate `%s', result `%s'."
6868 mid-or-mail rate result))
6869 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6870 mid-or-mail)
6871 ;; Too few vowels [^aeiouy]{4,}.*\@
6872 (setq result (+ result -5.0))
6873 (gnus-message
6874 9 "Few vowels in `%s', rate `%s', result `%s'."
6875 mid-or-mail -5.0 result))
6877 (setq result (+ result 5.0))
6878 (gnus-message
6879 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6880 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6881 ;; Maybe we should make this a customizable alist: (condition . 'result)
6882 (cond
6883 ((symbolp result) result)
6884 ;; Now convert number into proper results:
6885 ((< result -10.0) 'mid)
6886 ((> result 10.0) 'mail)
6887 (t 'ask))))
6889 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6890 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6891 (url-mid (concat "news" ":" mid-or-mail))
6892 (url-mailto (concat "mailto" ":" mid-or-mail)))
6893 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6894 (when (fboundp pref)
6895 (setq guessed
6896 ;; get rid of surrounding angles...
6897 (funcall pref
6898 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6899 (if (or (eq 'mid guessed) (eq 'mail guessed))
6900 (setq pref guessed)
6901 (setq pref 'ask)))
6902 (if (eq pref 'ask)
6903 (save-window-excursion
6904 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6905 (setq pref 'mail)
6906 (setq pref 'mid))))
6907 (cond ((eq pref 'mid)
6908 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6909 (gnus-button-handle-news url-mid))
6910 ((eq pref 'mail)
6911 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6912 (gnus-url-mailto url-mailto))
6913 (t (gnus-message 3 "Invalid string.")))))
6915 (defun gnus-button-handle-custom (fun arg)
6916 "Call function FUN on argument ARG.
6917 Both FUN and ARG are supposed to be strings. ARG will be passed
6918 as a symbol to FUN."
6919 (funcall (intern fun)
6920 (if (string-match "^customize-apropos" fun)
6922 (intern arg))))
6924 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6926 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6927 ;; stuff?
6929 (defun gnus-button-handle-describe-function (url)
6930 "Call `describe-function' when pushing the corresponding URL button."
6931 (describe-function
6932 (intern
6933 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6935 (defun gnus-button-handle-describe-variable (url)
6936 "Call `describe-variable' when pushing the corresponding URL button."
6937 (describe-variable
6938 (intern
6939 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6941 (defun gnus-button-handle-symbol (url)
6942 "Display help on variable or function.
6943 Calls `describe-variable' or `describe-function'."
6944 (let ((sym (intern url)))
6945 (cond
6946 ((fboundp sym) (describe-function sym))
6947 ((boundp sym) (describe-variable sym))
6948 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6950 (defun gnus-button-handle-describe-key (url)
6951 "Call `describe-key' when pushing the corresponding URL button."
6952 (let* ((key-string
6953 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6954 (keys (ignore-errors (eval `(kbd ,key-string)))))
6955 (if keys
6956 (describe-key keys)
6957 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6959 (defun gnus-button-handle-apropos (url)
6960 "Call `apropos' when pushing the corresponding URL button."
6961 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6963 (defun gnus-button-handle-apropos-command (url)
6964 "Call `apropos' when pushing the corresponding URL button."
6965 (apropos-command
6966 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6968 (defun gnus-button-handle-apropos-variable (url)
6969 "Call `apropos' when pushing the corresponding URL button."
6970 (funcall
6971 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6972 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6974 (defun gnus-button-handle-apropos-documentation (url)
6975 "Call `apropos' when pushing the corresponding URL button."
6976 (funcall
6977 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6978 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6980 (defun gnus-button-handle-library (url)
6981 "Call `locate-library' when pushing the corresponding URL button."
6982 (gnus-message 9 "url=`%s'" url)
6983 (let* ((lib (locate-library url))
6984 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6985 (if (not lib)
6986 (gnus-message 1 "Cannot locale library `%s'." url)
6987 (find-file-read-only file))))
6989 (defun gnus-button-handle-ctan (url)
6990 "Call `browse-url' when pushing a CTAN URL button."
6991 (funcall
6992 gnus-button-ctan-handler
6993 (concat
6994 gnus-ctan-url
6995 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6997 (defcustom gnus-button-tex-level 5
6998 "*Integer that says how many TeX-related buttons Gnus will show.
6999 The higher the number, the more buttons will appear and the more false
7000 positives are possible. Note that you can set this variable local to
7001 specific groups. Setting it higher in TeX groups is probably a good idea.
7002 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7003 how to set variables in specific groups."
7004 :version "22.1"
7005 :group 'gnus-article-buttons
7006 :link '(custom-manual "(gnus)Group Parameters")
7007 :type 'integer)
7009 (defcustom gnus-button-man-level 5
7010 "*Integer that says how many man-related buttons Gnus will show.
7011 The higher the number, the more buttons will appear and the more false
7012 positives are possible. Note that you can set this variable local to
7013 specific groups. Setting it higher in Unix groups is probably a good idea.
7014 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7015 how to set variables in specific groups."
7016 :version "22.1"
7017 :group 'gnus-article-buttons
7018 :link '(custom-manual "(gnus)Group Parameters")
7019 :type 'integer)
7021 (defcustom gnus-button-emacs-level 5
7022 "*Integer that says how many emacs-related buttons Gnus will show.
7023 The higher the number, the more buttons will appear and the more false
7024 positives are possible. Note that you can set this variable local to
7025 specific groups. Setting it higher in Emacs or Gnus related groups is
7026 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7027 `gnus-parameters' on how to set variables in specific groups."
7028 :version "22.1"
7029 :group 'gnus-article-buttons
7030 :link '(custom-manual "(gnus)Group Parameters")
7031 :type 'integer)
7033 (defcustom gnus-button-message-level 5
7034 "*Integer that says how many buttons for news or mail messages will appear.
7035 The higher the number, the more buttons will appear and the more false
7036 positives are possible."
7037 ;; mail addresses, MIDs, URLs for news, ...
7038 :version "22.1"
7039 :group 'gnus-article-buttons
7040 :type 'integer)
7042 (defcustom gnus-button-browse-level 5
7043 "*Integer that says how many buttons for browsing will appear.
7044 The higher the number, the more buttons will appear and the more false
7045 positives are possible."
7046 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7047 :version "22.1"
7048 :group 'gnus-article-buttons
7049 :type 'integer)
7051 (defcustom gnus-button-alist
7052 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7053 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7054 ((concat "\\b\\(nntp\\|news\\):\\("
7055 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7056 0 t gnus-button-handle-news 2)
7057 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7058 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7059 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7060 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7061 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7062 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7063 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7064 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7065 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7066 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7067 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7068 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7069 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7070 ;; RFC 2368 (The mailto URL scheme)
7071 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7072 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7073 ("\\bmailto:\\([^ \n\t]+\\)"
7074 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7075 ;; CTAN
7076 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7077 gnus-button-ctan-directory-regexp
7078 "[^][>)!;:,'\n\t ]+\\)")
7079 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7080 ((concat "\\btex-archive/\\("
7081 gnus-button-ctan-directory-regexp
7082 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7083 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7084 ((concat
7085 "\\b\\("
7086 gnus-button-ctan-directory-regexp
7087 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7088 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7089 ;; This is info (home-grown style) <info://foo/bar+baz>
7090 ("\\binfo://\\([^'\">\n\t ]+\\)"
7091 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7092 ;; Info GNOME style <info:foo#bar_baz>
7093 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7094 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7095 ;; Info KDE style <info:(foo)bar baz>
7096 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7097 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7098 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7099 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7100 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7101 ;; Info links like `C-h i d m CC Mode RET'
7102 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7103 ;; This is custom
7104 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7105 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7106 ;; Emacs help commands
7107 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7108 ;; regexp doesn't match arguments containing ` '.
7109 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7110 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7111 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7112 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7113 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7114 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7115 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7116 ;; The following entries may lead to many false positives so don't enable
7117 ;; them by default (use a high button level).
7118 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7119 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7120 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7121 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7122 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7123 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7124 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7125 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7126 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7127 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7128 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7129 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7130 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7131 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7132 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7133 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7134 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7135 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7136 ;; Unlike the other regexps we really have to require quoting
7137 ;; here to determine where it ends.
7138 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7139 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7140 ("<URL: *\\([^\n<>]*\\)>"
7141 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7142 ;; RFC 2396 (2.4.3., delims) ...
7143 ("\"URL: *\\([^\n\"]*\\)\""
7144 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7145 ;; Raw URLs.
7146 (gnus-button-url-regexp
7147 0 (>= gnus-button-browse-level 0) browse-url 0)
7148 ;; man pages
7149 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7150 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7151 gnus-button-handle-man 1)
7152 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7153 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7154 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7155 gnus-button-handle-man 1)
7156 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7157 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7158 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7159 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7160 ;; Recognizing patches to .el files. This is somewhat obscure,
7161 ;; but considering the percentage of Gnus users who hack Emacs
7162 ;; Lisp files...
7163 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7164 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7165 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7166 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7167 ;; MID or mail: To avoid too many false positives we don't try to catch
7168 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7169 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7170 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7171 ;; so that non-ambiguous entries (see above) match first.
7172 (gnus-button-mid-or-mail-regexp
7173 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7174 "*Alist of regexps matching buttons in article bodies.
7176 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7177 REGEXP: is the string (case insensitive) matching text around the button (can
7178 also be Lisp expression evaluating to a string),
7179 BUTTON: is the number of the regexp grouping actually matching the button,
7180 FORM: is a Lisp expression which must eval to true for the button to
7181 be added,
7182 CALLBACK: is the function to call when the user push this button, and each
7183 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7185 CALLBACK can also be a variable, in that case the value of that
7186 variable it the real callback function."
7187 :group 'gnus-article-buttons
7188 :type '(repeat (list (choice regexp variable sexp)
7189 (integer :tag "Button")
7190 (sexp :tag "Form")
7191 (function :tag "Callback")
7192 (repeat :tag "Par"
7193 :inline t
7194 (integer :tag "Regexp group")))))
7195 (put 'gnus-button-alist 'risky-local-variable t)
7197 (defcustom gnus-header-button-alist
7198 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7199 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7200 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7201 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7202 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7203 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7204 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7205 0 (>= gnus-button-browse-level 0) browse-url 0)
7206 ("^Subject:" gnus-button-url-regexp
7207 0 (>= gnus-button-browse-level 0) browse-url 0)
7208 ("^[^:]+:" gnus-button-url-regexp
7209 0 (>= gnus-button-browse-level 0) browse-url 0)
7210 ("^OpenPGP:.*url=" gnus-button-url-regexp
7211 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7212 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7213 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7214 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7215 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7216 "*Alist of headers and regexps to match buttons in article heads.
7218 This alist is very similar to `gnus-button-alist', except that each
7219 alist has an additional HEADER element first in each entry:
7221 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7223 HEADER is a regexp to match a header. For a fuller explanation, see
7224 `gnus-button-alist'."
7225 :group 'gnus-article-buttons
7226 :group 'gnus-article-headers
7227 :type '(repeat (list (regexp :tag "Header")
7228 (choice regexp variable)
7229 (integer :tag "Button")
7230 (sexp :tag "Form")
7231 (function :tag "Callback")
7232 (repeat :tag "Par"
7233 :inline t
7234 (integer :tag "Regexp group")))))
7235 (put 'gnus-header-button-alist 'risky-local-variable t)
7237 ;;; Commands:
7239 (defun gnus-article-push-button (event)
7240 "Check text under the mouse pointer for a callback function.
7241 If the text under the mouse pointer has a `gnus-callback' property,
7242 call it with the value of the `gnus-data' text property."
7243 (interactive "e")
7244 (set-buffer (window-buffer (posn-window (event-start event))))
7245 (let* ((pos (posn-point (event-start event)))
7246 (data (get-text-property pos 'gnus-data))
7247 (fun (get-text-property pos 'gnus-callback)))
7248 (goto-char pos)
7249 (when fun
7250 (funcall fun data))))
7252 (defun gnus-article-press-button ()
7253 "Check text at point for a callback function.
7254 If the text at point has a `gnus-callback' property,
7255 call it with the value of the `gnus-data' text property."
7256 (interactive)
7257 (let ((data (get-text-property (point) 'gnus-data))
7258 (fun (get-text-property (point) 'gnus-callback)))
7259 (when fun
7260 (funcall fun data))))
7262 (defun gnus-article-highlight (&optional force)
7263 "Highlight current article.
7264 This function calls `gnus-article-highlight-headers',
7265 `gnus-article-highlight-citation',
7266 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7267 do the highlighting. See the documentation for those functions."
7268 (interactive (list 'force))
7269 (gnus-article-highlight-headers)
7270 (gnus-article-highlight-citation force)
7271 (gnus-article-highlight-signature)
7272 (gnus-article-add-buttons force)
7273 (gnus-article-add-buttons-to-head))
7275 (defun gnus-article-highlight-some (&optional force)
7276 "Highlight current article.
7277 This function calls `gnus-article-highlight-headers',
7278 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7279 do the highlighting. See the documentation for those functions."
7280 (interactive (list 'force))
7281 (gnus-article-highlight-headers)
7282 (gnus-article-highlight-signature)
7283 (gnus-article-add-buttons))
7285 (defun gnus-article-highlight-headers ()
7286 "Highlight article headers as specified by `gnus-header-face-alist'."
7287 (interactive)
7288 (gnus-with-article-headers
7289 (let (regexp header-face field-face from hpoints fpoints)
7290 (dolist (entry gnus-header-face-alist)
7291 (goto-char (point-min))
7292 (setq regexp (concat "^\\("
7293 (if (string-equal "" (nth 0 entry))
7294 "[^\t ]"
7295 (nth 0 entry))
7296 "\\)")
7297 header-face (nth 1 entry)
7298 field-face (nth 2 entry))
7299 (while (and (re-search-forward regexp nil t)
7300 (not (eobp)))
7301 (beginning-of-line)
7302 (setq from (point))
7303 (unless (search-forward ":" nil t)
7304 (forward-char 1))
7305 (when (and header-face
7306 (not (memq (point) hpoints)))
7307 (push (point) hpoints)
7308 (gnus-put-text-property from (point) 'face header-face))
7309 (when (and field-face
7310 (not (memq (setq from (point)) fpoints)))
7311 (push from fpoints)
7312 (if (re-search-forward "^[^ \t]" nil t)
7313 (forward-char -2)
7314 (goto-char (point-max)))
7315 (gnus-put-text-property from (point) 'face field-face)))))))
7317 (defun gnus-article-highlight-signature ()
7318 "Highlight the signature in an article.
7319 It does this by highlighting everything after
7320 `gnus-signature-separator' using the face `gnus-signature'."
7321 (interactive)
7322 (gnus-with-article-buffer
7323 (let ((inhibit-point-motion-hooks t))
7324 (save-restriction
7325 (when (and gnus-signature-face
7326 (gnus-article-narrow-to-signature))
7327 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7328 'face gnus-signature-face)
7329 (widen)
7330 (gnus-article-search-signature)
7331 (let ((start (match-beginning 0))
7332 (end (set-marker (make-marker) (1+ (match-end 0)))))
7333 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7334 end)))))))
7336 (defun gnus-button-in-region-p (b e prop)
7337 "Say whether PROP exists in the region."
7338 (text-property-not-all b e prop nil))
7340 (defun gnus-article-add-buttons (&optional force)
7341 "Find external references in the article and make buttons of them.
7342 \"External references\" are things like Message-IDs and URLs, as
7343 specified by `gnus-button-alist'."
7344 (interactive (list 'force))
7345 (gnus-with-article-buffer
7346 (let ((inhibit-point-motion-hooks t)
7347 (case-fold-search t)
7348 (alist gnus-button-alist)
7349 beg entry regexp)
7350 ;; Remove all old markers.
7351 (let (marker entry new-list)
7352 (while (setq marker (pop gnus-button-marker-list))
7353 (if (or (< marker (point-min)) (>= marker (point-max)))
7354 (push marker new-list)
7355 (goto-char marker)
7356 (when (setq entry (gnus-button-entry))
7357 (put-text-property (match-beginning (nth 1 entry))
7358 (match-end (nth 1 entry))
7359 'gnus-callback nil))
7360 (set-marker marker nil)))
7361 (setq gnus-button-marker-list new-list))
7362 ;; We skip the headers.
7363 (article-goto-body)
7364 (setq beg (point))
7365 (while (setq entry (pop alist))
7366 (setq regexp (eval (car entry)))
7367 (goto-char beg)
7368 (while (re-search-forward regexp nil t)
7369 (let ((start (match-beginning (nth 1 entry)))
7370 (end (match-end (nth 1 entry)))
7371 (from (match-beginning 0)))
7372 (when (and (or (eq t (nth 2 entry))
7373 (eval (nth 2 entry)))
7374 (not (gnus-button-in-region-p
7375 start end 'gnus-callback)))
7376 ;; That optional form returned non-nil, so we add the
7377 ;; button.
7378 (setq from (set-marker (make-marker) from))
7379 (push from gnus-button-marker-list)
7380 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7381 (gnus-article-extend-url-button from start end))
7382 (gnus-article-add-button start end
7383 'gnus-button-push from)))))))))
7385 (defun gnus-article-extend-url-button (beg start end)
7386 "Extend url button if url is folded into two or more lines.
7387 Return non-nil if button is extended. BEG is a marker that points to
7388 the beginning position of a text containing url. START and END are
7389 the endpoints of a url button before it is extended. The concatenated
7390 url is put as the `gnus-button-url' overlay property on the button."
7391 (let ((opoint (point))
7392 (points (list start end))
7393 url delim regexp)
7394 (prog1
7395 (when (and (progn
7396 (goto-char end)
7397 (not (looking-at "[\t ]*[\">]")))
7398 (progn
7399 (goto-char start)
7400 (string-match
7401 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7402 (buffer-substring (point-at-bol) start)))
7403 (progn
7404 (setq url (list (buffer-substring start end))
7405 delim (if (match-beginning 1) ">" "\""))
7406 (beginning-of-line)
7407 (setq regexp (concat
7408 (when (and (looking-at
7409 message-cite-prefix-regexp)
7410 (< (match-end 0) start))
7411 (regexp-quote (match-string 0)))
7413 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7414 delim "\\)"))
7415 (while (progn
7416 (forward-line 1)
7417 (and (looking-at regexp)
7418 (prog1
7419 (match-beginning 1)
7420 (push (or (match-string 2)
7421 (match-string 1))
7422 url)
7423 (push (setq end (or (match-end 2)
7424 (match-end 1)))
7425 points)
7426 (push (or (match-beginning 2)
7427 (match-beginning 1))
7428 points)))))
7429 (match-beginning 2)))
7430 (let (gnus-article-mouse-face widget-mouse-face)
7431 (while points
7432 (gnus-article-add-button (pop points) (pop points)
7433 'gnus-button-push beg)))
7434 (let ((overlay (gnus-make-overlay start end)))
7435 (gnus-overlay-put overlay 'evaporate t)
7436 (gnus-overlay-put overlay 'gnus-button-url
7437 (list (mapconcat 'identity (nreverse url) "")))
7438 (when gnus-article-mouse-face
7439 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7441 (goto-char opoint))))
7443 ;; Add buttons to the head of an article.
7444 (defun gnus-article-add-buttons-to-head ()
7445 "Add buttons to the head of the article."
7446 (interactive)
7447 (gnus-with-article-headers
7448 (let (beg end)
7449 (dolist (entry gnus-header-button-alist)
7450 ;; Each alist entry.
7451 (goto-char (point-min))
7452 (while (re-search-forward (car entry) nil t)
7453 ;; Each header matching the entry.
7454 (setq beg (match-beginning 0))
7455 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7456 (match-beginning 0))
7457 (point-max)))
7458 (goto-char beg)
7459 (while (re-search-forward (eval (nth 1 entry)) end t)
7460 ;; Each match within a header.
7461 (let* ((entry (cdr entry))
7462 (start (match-beginning (nth 1 entry)))
7463 (end (match-end (nth 1 entry)))
7464 (form (nth 2 entry)))
7465 (goto-char (match-end 0))
7466 (when (eval form)
7467 (gnus-article-add-button
7468 start end (nth 3 entry)
7469 (buffer-substring (match-beginning (nth 4 entry))
7470 (match-end (nth 4 entry)))))))
7471 (goto-char end))))))
7473 ;;; External functions:
7475 (defun gnus-article-add-button (from to fun &optional data)
7476 "Create a button between FROM and TO with callback FUN and data DATA."
7477 (when gnus-article-button-face
7478 (gnus-overlay-put (gnus-make-overlay from to nil t)
7479 'face gnus-article-button-face))
7480 (gnus-add-text-properties
7481 from to
7482 (nconc (and gnus-article-mouse-face
7483 (list gnus-mouse-face-prop gnus-article-mouse-face))
7484 (list 'gnus-callback fun)
7485 (and data (list 'gnus-data data))))
7486 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7487 :button-keymap gnus-widget-button-keymap))
7489 ;;; Internal functions:
7491 (defun gnus-article-set-globals ()
7492 (with-current-buffer gnus-summary-buffer
7493 (gnus-set-global-variables)))
7495 (defun gnus-signature-toggle (end)
7496 (gnus-with-article-buffer
7497 (let ((inhibit-point-motion-hooks t))
7498 (if (text-property-any end (point-max) 'article-type 'signature)
7499 (progn
7500 (gnus-delete-wash-type 'signature)
7501 (gnus-remove-text-properties-when
7502 'article-type 'signature end (point-max)
7503 (cons 'article-type (cons 'signature
7504 gnus-hidden-properties))))
7505 (gnus-add-wash-type 'signature)
7506 (gnus-add-text-properties-when
7507 'article-type nil end (point-max)
7508 (cons 'article-type (cons 'signature
7509 gnus-hidden-properties)))))
7510 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7511 (gnus-set-mode-line 'article))))
7513 (defun gnus-button-entry ()
7514 ;; Return the first entry in `gnus-button-alist' matching this place.
7515 (let ((alist gnus-button-alist)
7516 (entry nil))
7517 (while alist
7518 (setq entry (pop alist))
7519 (if (looking-at (eval (car entry)))
7520 (setq alist nil)
7521 (setq entry nil)))
7522 entry))
7524 (defun gnus-button-push (marker)
7525 ;; Push button starting at MARKER.
7526 (save-excursion
7527 (goto-char marker)
7528 (let* ((entry (gnus-button-entry))
7529 (inhibit-point-motion-hooks t)
7530 (fun (nth 3 entry))
7531 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7532 (get-char-property marker 'gnus-button-url))
7533 (mapcar (lambda (group)
7534 (let ((string (match-string group)))
7535 (set-text-properties
7536 0 (length string) nil string)
7537 string))
7538 (nthcdr 4 entry)))))
7539 (cond
7540 ((fboundp fun)
7541 (apply fun args))
7542 ((and (boundp fun)
7543 (fboundp (symbol-value fun)))
7544 (apply (symbol-value fun) args))
7546 (gnus-message 1 "You must define `%S' to use this button"
7547 (cons fun args)))))))
7549 (defun gnus-parse-news-url (url)
7550 (let (scheme server port group message-id articles)
7551 (with-temp-buffer
7552 (insert url)
7553 (goto-char (point-min))
7554 (when (looking-at "\\([A-Za-z]+\\):")
7555 (setq scheme (match-string 1))
7556 (goto-char (match-end 0)))
7557 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7558 (setq server (match-string 1))
7559 (setq port (if (stringp (match-string 3))
7560 (string-to-number (match-string 3))
7561 (match-string 3)))
7562 (goto-char (match-end 0)))
7564 (cond
7565 ((looking-at "\\(.*@.*\\)")
7566 (setq message-id (match-string 1)))
7567 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7568 (setq group (match-string 1)
7569 articles (split-string (match-string 2) "-")))
7570 ((looking-at "\\([^/]+\\)/?")
7571 (setq group (match-string 1)))
7573 (error "Unknown news URL syntax"))))
7574 (list scheme server port group message-id articles)))
7576 (defun gnus-button-handle-news (url)
7577 "Fetch a news URL."
7578 (destructuring-bind (scheme server port group message-id articles)
7579 (gnus-parse-news-url url)
7580 (cond
7581 (message-id
7582 (save-excursion
7583 (set-buffer gnus-summary-buffer)
7584 (if server
7585 (let ((gnus-refer-article-method
7586 (nconc (list (list 'nntp server))
7587 gnus-refer-article-method))
7588 (nntp-port-number (or port "nntp")))
7589 (gnus-message 7 "Fetching %s with %s"
7590 message-id gnus-refer-article-method)
7591 (gnus-summary-refer-article message-id))
7592 (gnus-summary-refer-article message-id))))
7593 (group
7594 (gnus-button-fetch-group url)))))
7596 (defun gnus-button-patch (library line)
7597 "Visit an Emacs Lisp library LIBRARY on line LINE."
7598 (interactive)
7599 (let ((file (locate-library (file-name-nondirectory library))))
7600 (unless file
7601 (error "Couldn't find library %s" library))
7602 (find-file file)
7603 (goto-line (string-to-number line))))
7605 (defun gnus-button-handle-man (url)
7606 "Fetch a man page."
7607 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7608 (when (eq gnus-button-man-handler 'woman)
7609 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7610 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7611 (funcall gnus-button-man-handler url))
7613 (defun gnus-button-handle-info-url (url)
7614 "Fetch an info URL."
7615 (setq url (mm-subst-char-in-string ?+ ?\ url))
7616 (cond
7617 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7618 (gnus-info-find-node
7619 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7620 "Gnus")
7621 ")" (gnus-url-unhex-string (match-string 2 url)))))
7622 ((string-match "([^)\"]+)[^\"]+" url)
7623 (setq url
7624 (gnus-replace-in-string
7625 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7626 (gnus-info-find-node url))
7627 (t (error "Can't parse %s" url))))
7629 (defun gnus-button-handle-info-url-gnome (url)
7630 "Fetch GNOME style info URL."
7631 (setq url (mm-subst-char-in-string ?_ ?\ url))
7632 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7633 (gnus-info-find-node
7634 (concat "("
7635 (gnus-url-unhex-string
7636 (match-string 1 url))
7638 (or (gnus-url-unhex-string
7639 (match-string 2 url))
7640 "Top")))
7641 (error "Can't parse %s" url)))
7643 (defun gnus-button-handle-info-url-kde (url)
7644 "Fetch KDE style info URL."
7645 (gnus-info-find-node (gnus-url-unhex-string url)))
7647 (defun gnus-button-handle-info-keystrokes (url)
7648 "Call `info' when pushing the corresponding URL button."
7649 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7650 (info)
7651 (Info-directory)
7652 (Info-menu url))
7654 (defun gnus-button-openpgp (url)
7655 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7656 (with-temp-buffer
7657 (mm-url-insert-file-contents-external url)
7658 (pgg-snarf-keys-region (point-min) (point-max))
7659 (pgg-display-output-buffer nil nil nil)))
7661 (defun gnus-button-message-id (message-id)
7662 "Fetch MESSAGE-ID."
7663 (with-current-buffer gnus-summary-buffer
7664 (gnus-summary-refer-article message-id)))
7666 (defun gnus-button-fetch-group (address &rest ignore)
7667 "Fetch GROUP specified by ADDRESS."
7668 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7669 address)
7670 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7671 ;; for nntp:// and news://
7672 (setq address (match-string 3 address)))
7673 (if (not (string-match "[:/]" address))
7674 ;; This is just a simple group url.
7675 (gnus-group-read-ephemeral-group address gnus-select-method)
7676 (if (not
7677 (string-match
7678 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7679 address))
7680 (error "Can't parse %s" address)
7681 (gnus-group-read-ephemeral-group
7682 (match-string 4 address)
7683 `(nntp ,(match-string 1 address)
7684 (nntp-address ,(match-string 1 address))
7685 (nntp-port-number ,(if (match-end 3)
7686 (match-string 3 address)
7687 "nntp")))
7688 nil nil nil
7689 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7691 (defun gnus-url-parse-query-string (query &optional downcase)
7692 (let (retval pairs cur key val)
7693 (setq pairs (split-string query "&"))
7694 (while pairs
7695 (setq cur (car pairs)
7696 pairs (cdr pairs))
7697 (if (not (string-match "=" cur))
7698 nil ; Grace
7699 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7700 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7701 (if downcase
7702 (setq key (downcase key)))
7703 (setq cur (assoc key retval))
7704 (if cur
7705 (setcdr cur (cons val (cdr cur)))
7706 (setq retval (cons (list key val) retval)))))
7707 retval))
7709 (defun gnus-url-mailto (url)
7710 ;; Send mail to someone
7711 (when (string-match "mailto:/*\\(.*\\)" url)
7712 (setq url (substring url (match-beginning 1) nil)))
7713 (let (to args subject func)
7714 (setq args (gnus-url-parse-query-string
7715 (if (string-match "^\\?" url)
7716 (substring url 1)
7717 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7718 (concat "to=" (match-string 1 url) "&"
7719 (match-string 2 url))
7720 (concat "to=" url)))
7722 subject (cdr-safe (assoc "subject" args)))
7723 (gnus-msg-mail)
7724 (while args
7725 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7726 (if (fboundp func)
7727 (funcall func)
7728 (message-position-on-field (caar args)))
7729 (insert (gnus-replace-in-string
7730 (mapconcat 'identity (reverse (cdar args)) ", ")
7731 "\r\n" "\n" t))
7732 (setq args (cdr args)))
7733 (if subject
7734 (message-goto-body)
7735 (message-goto-subject))))
7737 (defun gnus-button-embedded-url (address)
7738 "Activate ADDRESS with `browse-url'."
7739 (browse-url (gnus-strip-whitespace address)))
7741 ;;; Next/prev buttons in the article buffer.
7743 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7744 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7746 (defvar gnus-prev-page-map
7747 (let ((map (make-sparse-keymap)))
7748 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7749 (define-key map "\r" 'gnus-button-prev-page)
7750 map))
7752 (defvar gnus-next-page-map
7753 (let ((map (make-sparse-keymap)))
7754 (unless (>= emacs-major-version 21)
7755 ;; XEmacs doesn't care.
7756 (set-keymap-parent map gnus-article-mode-map))
7757 (define-key map gnus-mouse-2 'gnus-button-next-page)
7758 (define-key map "\r" 'gnus-button-next-page)
7759 map))
7761 (defun gnus-insert-prev-page-button ()
7762 (let ((b (point)) e
7763 (inhibit-read-only t))
7764 (gnus-eval-format
7765 gnus-prev-page-line-format nil
7766 `(keymap ,gnus-prev-page-map
7767 gnus-prev t
7768 gnus-callback gnus-article-button-prev-page
7769 article-type annotation))
7770 (setq e (if (bolp)
7771 ;; Exclude a newline.
7772 (1- (point))
7773 (point)))
7774 (when gnus-article-button-face
7775 (gnus-overlay-put (gnus-make-overlay b e nil t)
7776 'face gnus-article-button-face))
7777 (widget-convert-button
7778 'link b e
7779 :action 'gnus-button-prev-page
7780 :button-keymap gnus-prev-page-map)))
7782 (defun gnus-button-next-page (&optional args more-args)
7783 "Go to the next page."
7784 (interactive)
7785 (let ((win (selected-window)))
7786 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7787 (gnus-article-next-page)
7788 (select-window win)))
7790 (defun gnus-button-prev-page (&optional args more-args)
7791 "Go to the prev page."
7792 (interactive)
7793 (let ((win (selected-window)))
7794 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7795 (gnus-article-prev-page)
7796 (select-window win)))
7798 (defun gnus-insert-next-page-button ()
7799 (let ((b (point)) e
7800 (inhibit-read-only t))
7801 (gnus-eval-format gnus-next-page-line-format nil
7802 `(keymap ,gnus-next-page-map
7803 gnus-next t
7804 gnus-callback gnus-article-button-next-page
7805 article-type annotation))
7806 (setq e (if (bolp)
7807 ;; Exclude a newline.
7808 (1- (point))
7809 (point)))
7810 (when gnus-article-button-face
7811 (gnus-overlay-put (gnus-make-overlay b e nil t)
7812 'face gnus-article-button-face))
7813 (widget-convert-button
7814 'link b e
7815 :action 'gnus-button-next-page
7816 :button-keymap gnus-next-page-map)))
7818 (defun gnus-article-button-next-page (arg)
7819 "Go to the next page."
7820 (interactive "P")
7821 (let ((win (selected-window)))
7822 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7823 (gnus-article-next-page)
7824 (select-window win)))
7826 (defun gnus-article-button-prev-page (arg)
7827 "Go to the prev page."
7828 (interactive "P")
7829 (let ((win (selected-window)))
7830 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7831 (gnus-article-prev-page)
7832 (select-window win)))
7834 (defvar gnus-decode-header-methods
7835 '(mail-decode-encoded-word-region)
7836 "List of methods used to decode headers.
7838 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7839 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7840 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7841 whose names match REGEXP.
7843 For example:
7844 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7845 mail-decode-encoded-word-region
7846 (\"chinese\" . rfc1843-decode-region))
7849 (defvar gnus-decode-header-methods-cache nil)
7851 (defun gnus-multi-decode-header (start end)
7852 "Apply the functions from `gnus-encoded-word-methods' that match."
7853 (unless (and gnus-decode-header-methods-cache
7854 (eq gnus-newsgroup-name
7855 (car gnus-decode-header-methods-cache)))
7856 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7857 (dolist (x gnus-decode-header-methods)
7858 (if (symbolp x)
7859 (nconc gnus-decode-header-methods-cache (list x))
7860 (if (and gnus-newsgroup-name
7861 (string-match (car x) gnus-newsgroup-name))
7862 (nconc gnus-decode-header-methods-cache
7863 (list (cdr x)))))))
7864 (let ((xlist gnus-decode-header-methods-cache))
7865 (pop xlist)
7866 (save-restriction
7867 (narrow-to-region start end)
7868 (while xlist
7869 (funcall (pop xlist) (point-min) (point-max))))))
7872 ;;; Treatment top-level handling.
7875 (defun gnus-treat-article (condition &optional part-number total-parts type)
7876 (let ((length (- (point-max) (point-min)))
7877 (alist gnus-treatment-function-alist)
7878 (article-goto-body-goes-to-point-min-p t)
7879 (treated-type
7880 (or (not type)
7881 (catch 'found
7882 (let ((list gnus-article-treat-types))
7883 (while list
7884 (when (string-match (pop list) type)
7885 (throw 'found t)))))))
7886 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7887 val elem)
7888 (gnus-run-hooks 'gnus-part-display-hook)
7889 (dolist (elem alist)
7890 (setq val
7891 (save-excursion
7892 (when (gnus-buffer-live-p gnus-summary-buffer)
7893 (set-buffer gnus-summary-buffer))
7894 (symbol-value (car elem))))
7895 (when (and (or (consp val)
7896 treated-type)
7897 (gnus-treat-predicate val)
7898 (or (not (get (car elem) 'highlight))
7899 highlightp))
7900 (save-restriction
7901 (funcall (cadr elem)))))))
7903 ;; Dynamic variables.
7904 (defvar part-number)
7905 (defvar total-parts)
7906 (defvar type)
7907 (defvar condition)
7908 (defvar length)
7910 (defun gnus-treat-predicate (val)
7911 (cond
7912 ((null val)
7913 nil)
7914 (condition
7915 (eq condition val))
7916 ((and (listp val)
7917 (stringp (car val)))
7918 (apply 'gnus-or (mapcar `(lambda (s)
7919 (string-match s ,(or gnus-newsgroup-name "")))
7920 val)))
7921 ((listp val)
7922 (let ((pred (pop val)))
7923 (cond
7924 ((eq pred 'or)
7925 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7926 ((eq pred 'and)
7927 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7928 ((eq pred 'not)
7929 (not (gnus-treat-predicate (car val))))
7930 ((eq pred 'typep)
7931 (equal (car val) type))
7933 (error "%S is not a valid predicate" pred)))))
7934 ((eq val t)
7936 ((eq val 'head)
7937 nil)
7938 ((eq val 'first)
7939 (eq part-number 1))
7940 ((eq val 'last)
7941 (eq part-number total-parts))
7942 ((numberp val)
7943 (< length val))
7945 (error "%S is not a valid value" val))))
7947 (defun gnus-article-encrypt-body (protocol &optional n)
7948 "Encrypt the article body."
7949 (interactive
7950 (list
7951 (or gnus-article-encrypt-protocol
7952 (completing-read "Encrypt protocol: "
7953 gnus-article-encrypt-protocol-alist
7954 nil t))
7955 current-prefix-arg))
7956 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7957 (unless func
7958 (error "Can't find the encrypt protocol %s" protocol))
7959 (if (member gnus-newsgroup-name '("nndraft:delayed"
7960 "nndraft:drafts"
7961 "nndraft:queue"))
7962 (error "Can't encrypt the article in group %s"
7963 gnus-newsgroup-name))
7964 (gnus-summary-iterate n
7965 (save-excursion
7966 (set-buffer gnus-summary-buffer)
7967 (let ((mail-parse-charset gnus-newsgroup-charset)
7968 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7969 (summary-buffer gnus-summary-buffer)
7970 references point)
7971 (gnus-set-global-variables)
7972 (when (gnus-group-read-only-p)
7973 (error "The current newsgroup does not support article encrypt"))
7974 (gnus-summary-show-article t)
7975 (setq references
7976 (or (mail-header-references gnus-current-headers) ""))
7977 (set-buffer gnus-article-buffer)
7978 (let* ((inhibit-read-only t)
7979 (headers
7980 (mapcar (lambda (field)
7981 (and (save-restriction
7982 (message-narrow-to-head)
7983 (goto-char (point-min))
7984 (search-forward field nil t))
7985 (prog2
7986 (message-narrow-to-field)
7987 (buffer-string)
7988 (delete-region (point-min) (point-max))
7989 (widen))))
7990 '("Content-Type:" "Content-Transfer-Encoding:"
7991 "Content-Disposition:"))))
7992 (message-narrow-to-head)
7993 (message-remove-header "MIME-Version")
7994 (goto-char (point-max))
7995 (setq point (point))
7996 (insert (apply 'concat headers))
7997 (widen)
7998 (narrow-to-region point (point-max))
7999 (let ((message-options message-options))
8000 (message-options-set 'message-sender user-mail-address)
8001 (message-options-set 'message-recipients user-mail-address)
8002 (message-options-set 'message-sign-encrypt 'not)
8003 (funcall func))
8004 (goto-char (point-min))
8005 (insert "MIME-Version: 1.0\n")
8006 (widen)
8007 (gnus-summary-edit-article-done
8008 references nil summary-buffer t))
8009 (when gnus-keep-backlog
8010 (gnus-backlog-remove-article
8011 (car gnus-article-current) (cdr gnus-article-current)))
8012 (save-excursion
8013 (when (get-buffer gnus-original-article-buffer)
8014 (set-buffer gnus-original-article-buffer)
8015 (setq gnus-original-article nil)))
8016 (when gnus-use-cache
8017 (gnus-cache-update-article
8018 (car gnus-article-current) (cdr gnus-article-current))))))))
8020 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8021 "The following specs can be used:
8022 %t The security MIME type
8023 %i Additional info
8024 %d Details
8025 %D Details if button is pressed")
8027 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8028 "The following specs can be used:
8029 %t The security MIME type
8030 %i Additional info
8031 %d Details
8032 %D Details if button is pressed")
8034 (defvar gnus-mime-security-button-line-format-alist
8035 '((?t gnus-tmp-type ?s)
8036 (?i gnus-tmp-info ?s)
8037 (?d gnus-tmp-details ?s)
8038 (?D gnus-tmp-pressed-details ?s)))
8040 (defvar gnus-mime-security-button-commands
8041 '((gnus-article-press-button "\r" "Show Detail")
8042 (undefined "v")
8043 (undefined "t")
8044 (undefined "C")
8045 (gnus-mime-security-save-part "o" "Save...")
8046 (undefined "\C-o")
8047 (undefined "r")
8048 (undefined "d")
8049 (undefined "c")
8050 (undefined "i")
8051 (undefined "E")
8052 (undefined "e")
8053 (undefined "p")
8054 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8055 (undefined ".")))
8057 (defvar gnus-mime-security-button-map
8058 (let ((map (make-sparse-keymap)))
8059 (define-key map gnus-mouse-2 'gnus-article-push-button)
8060 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8061 (dolist (c gnus-mime-security-button-commands)
8062 (define-key map (cadr c) (car c)))
8063 map))
8065 (easy-menu-define
8066 gnus-mime-security-button-menu gnus-mime-security-button-map
8067 "Security button menu."
8068 `("Security Part"
8069 ,@(delq nil
8070 (mapcar (lambda (c)
8071 (unless (eq (car c) 'undefined)
8072 (vector (caddr c) (car c) :active t)))
8073 gnus-mime-security-button-commands))))
8075 (defun gnus-mime-security-button-menu (event prefix)
8076 "Construct a context-sensitive menu of security commands."
8077 (interactive "e\nP")
8078 (save-window-excursion
8079 (let ((pos (event-start event)))
8080 (select-window (posn-window pos))
8081 (goto-char (posn-point pos))
8082 (gnus-article-check-buffer)
8083 (popup-menu gnus-mime-security-button-menu nil prefix))))
8085 (defvar gnus-mime-security-details-buffer nil)
8087 (defvar gnus-mime-security-button-pressed nil)
8089 (defvar gnus-mime-security-show-details-inline t
8090 "If non-nil, show details in the article buffer.")
8092 (defun gnus-mime-security-verify-or-decrypt (handle)
8093 (mm-remove-parts (cdr handle))
8094 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8095 point (inhibit-read-only t))
8096 (if region
8097 (goto-char (car region)))
8098 (setq point (point))
8099 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8100 (let* ((mm-verify-option 'known)
8101 (mm-decrypt-option 'known)
8102 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8103 (unless (eq nparts (cdr handle))
8104 (mm-destroy-parts (cdr handle))
8105 (setcdr handle nparts))))
8106 (gnus-mime-display-security handle)
8107 (when region
8108 (delete-region (point) (cdr region))
8109 (set-marker (car region) nil)
8110 (set-marker (cdr region) nil))
8111 (goto-char point)))
8113 (defun gnus-mime-security-show-details (handle)
8114 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8115 (if (not details)
8116 (gnus-message 5 "No details.")
8117 (if gnus-mime-security-show-details-inline
8118 (let ((gnus-mime-security-button-pressed
8119 (not (get-text-property (point) 'gnus-mime-details)))
8120 (gnus-mime-security-button-line-format
8121 (get-text-property (point) 'gnus-line-format))
8122 (inhibit-read-only t))
8123 (forward-char -1)
8124 (while (eq (get-text-property (point) 'gnus-line-format)
8125 gnus-mime-security-button-line-format)
8126 (forward-char -1))
8127 (forward-char)
8128 (save-restriction
8129 (narrow-to-region (point) (point))
8130 (gnus-insert-mime-security-button handle))
8131 (delete-region (point)
8132 (or (text-property-not-all
8133 (point) (point-max)
8134 'gnus-line-format
8135 gnus-mime-security-button-line-format)
8136 (point-max))))
8137 ;; Not inlined.
8138 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8139 (with-current-buffer gnus-mime-security-details-buffer
8140 (erase-buffer)
8142 (setq gnus-mime-security-details-buffer
8143 (gnus-get-buffer-create "*MIME Security Details*")))
8144 (with-current-buffer gnus-mime-security-details-buffer
8145 (insert details)
8146 (goto-char (point-min)))
8147 (pop-to-buffer gnus-mime-security-details-buffer)))))
8149 (defun gnus-mime-security-press-button (handle)
8150 (save-excursion
8151 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8152 (gnus-mime-security-show-details handle)
8153 (gnus-mime-security-verify-or-decrypt handle))))
8155 (defun gnus-insert-mime-security-button (handle &optional displayed)
8156 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8157 (gnus-tmp-type
8158 (concat
8159 (or (nth 2 (assoc protocol mm-verify-function-alist))
8160 (nth 2 (assoc protocol mm-decrypt-function-alist))
8161 "Unknown")
8162 (if (equal (car handle) "multipart/signed")
8163 " Signed" " Encrypted")
8164 " Part"))
8165 (gnus-tmp-info
8166 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8167 "Undecided"))
8168 (gnus-tmp-details
8169 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8170 gnus-tmp-pressed-details
8171 b e)
8172 (setq gnus-tmp-details
8173 (if gnus-tmp-details
8174 (concat "\n" gnus-tmp-details)
8175 ""))
8176 (setq gnus-tmp-pressed-details
8177 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8178 (unless (bolp)
8179 (insert "\n"))
8180 (setq b (point))
8181 (gnus-eval-format
8182 gnus-mime-security-button-line-format
8183 gnus-mime-security-button-line-format-alist
8184 `(keymap ,gnus-mime-security-button-map
8185 gnus-callback gnus-mime-security-press-button
8186 gnus-line-format ,gnus-mime-security-button-line-format
8187 gnus-mime-details ,gnus-mime-security-button-pressed
8188 article-type annotation
8189 gnus-data ,handle))
8190 (setq e (if (bolp)
8191 ;; Exclude a newline.
8192 (1- (point))
8193 (point)))
8194 (when gnus-article-button-face
8195 (gnus-overlay-put (gnus-make-overlay b e nil t)
8196 'face gnus-article-button-face))
8197 (widget-convert-button
8198 'link b e
8199 :mime-handle handle
8200 :action 'gnus-widget-press-button
8201 :button-keymap gnus-mime-security-button-map
8202 :help-echo
8203 (lambda (widget/window &optional overlay pos)
8204 ;; Needed to properly clear the message due to a bug in
8205 ;; wid-edit (XEmacs only).
8206 (when (boundp 'help-echo-owns-message)
8207 (setq help-echo-owns-message t))
8208 (format
8209 "%S: show detail; %S: more options"
8210 (aref gnus-mouse-2 0)
8211 (aref gnus-down-mouse-3 0))))))
8213 (defun gnus-mime-display-security (handle)
8214 (save-restriction
8215 (narrow-to-region (point) (point))
8216 (unless (gnus-unbuttonized-mime-type-p (car handle))
8217 (gnus-insert-mime-security-button handle))
8218 (gnus-mime-display-part (cadr handle))
8219 (unless (bolp)
8220 (insert "\n"))
8221 (unless (gnus-unbuttonized-mime-type-p (car handle))
8222 (let ((gnus-mime-security-button-line-format
8223 gnus-mime-security-button-end-line-format))
8224 (gnus-insert-mime-security-button handle)))
8225 (mm-set-handle-multipart-parameter
8226 handle 'gnus-region
8227 (cons (set-marker (make-marker) (point-min))
8228 (set-marker (make-marker) (point-max))))
8229 (goto-char (point-max))))
8231 (defun gnus-mime-security-run-function (function)
8232 "Run FUNCTION with the security part under point."
8233 (gnus-article-check-buffer)
8234 (let ((data (get-text-property (point) 'gnus-data))
8235 buffer handle)
8236 (when (and (stringp (car-safe data))
8237 (setq buffer (mm-handle-multipart-original-buffer data))
8238 (setq handle (cadr data)))
8239 (if (bufferp (mm-handle-buffer handle))
8240 (progn
8241 (setq handle (cons buffer (copy-sequence (cdr handle))))
8242 (mm-handle-set-undisplayer handle nil))
8243 (setq handle (mm-make-handle
8244 buffer
8245 (mm-handle-multipart-ctl-parameter handle 'protocol)
8246 nil nil nil nil nil nil)))
8247 (funcall function handle))))
8249 (defun gnus-mime-security-save-part ()
8250 "Save the security part under point."
8251 (interactive)
8252 (gnus-mime-security-run-function 'mm-save-part))
8254 (defun gnus-mime-security-pipe-part ()
8255 "Pipe the security part under point to a process."
8256 (interactive)
8257 (gnus-mime-security-run-function 'mm-pipe-part))
8259 (gnus-ems-redefine)
8261 (provide 'gnus-art)
8263 (run-hooks 'gnus-art-load-hook)
8265 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8266 ;;; gnus-art.el ends here