lisp/gnus/gnus-art.el: Refactored out gnus-article-mime-handles
[emacs.git] / lisp / gnus / gnus-art.el
blob53da05e939ba2d802b063907684a66ce9237a36c
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
167 (defcustom gnus-visible-headers
168 "^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:"
169 "*All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "*This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
197 'empty Headers with no content.
198 'newsgroups Newsgroup identical to Gnus group.
199 'to-address To identical to To-address.
200 'to-list To identical to To-list.
201 'cc-list CC identical to To-list.
202 'followup-to Followup-to identical to Newsgroups.
203 'reply-to Reply-to identical to From.
204 'date Date less than four days old.
205 'long-to To and/or Cc longer than 1024 characters.
206 'many-to Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "CC identical to To-list." cc-list)
212 (const :tag "Followup-to identical to Newsgroups." followup-to)
213 (const :tag "Reply-to identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
256 (defcustom gnus-hidden-properties
257 (if (featurep 'xemacs)
258 ;; `intangible' is evil, but I keep it here in case it's useful.
259 '(invisible t intangible t)
260 ;; Emacs's command loop moves point out of invisible text anyway, so
261 ;; `intangible' is clearly not needed there.
262 '(invisible t))
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo \
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | ee -")
277 (if (gnus-image-type-available-p 'pbm)
278 'gnus-display-x-face-in-from
279 "{ echo \
280 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
281 ; uncompface; } | icontopbm | display -"))
282 "*String or function to be executed to display an X-Face header.
283 If it is a string, the command will be executed in a sub-shell
284 asynchronously. The compressed face will be piped to this command."
285 :type `(choice string
286 (function-item gnus-display-x-face-in-from)
287 function)
288 :version "21.1"
289 :group 'gnus-picon
290 :group 'gnus-article-washing)
292 (defcustom gnus-article-x-face-too-ugly nil
293 "Regexp matching posters whose face shouldn't be shown automatically."
294 :type '(choice regexp (const nil))
295 :group 'gnus-article-washing)
297 (defcustom gnus-article-banner-alist nil
298 "Banner alist for stripping.
299 For example,
300 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301 :version "21.1"
302 :type '(repeat (cons symbol regexp))
303 :group 'gnus-article-washing)
305 (gnus-define-group-parameter
306 banner
307 :variable-document
308 "Alist of regexps (to match group names) and banner."
309 :variable-group gnus-article-washing
310 :parameter-type
311 '(choice :tag "Banner"
312 :value nil
313 (const :tag "Remove signature" signature)
314 (symbol :tag "Item in `gnus-article-banner-alist'" none)
315 regexp
316 (const :tag "None" nil))
317 :parameter-document
318 "If non-nil, specify how to remove `banners' from articles.
320 Symbol `signature' means to remove signatures delimited by
321 `gnus-signature-separator'. Any other symbol is used to look up a
322 regular expression to match the banner in `gnus-article-banner-alist'.
323 A string is used as a regular expression to match the banner
324 directly.")
326 (defcustom gnus-article-address-banner-alist nil
327 "Alist of mail addresses and banners.
328 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
329 to match a mail address in the From: header, BANNER is one of a symbol
330 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
331 If ADDRESS matches author's mail address, it will remove things like
332 advertisements. For example:
334 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
336 :type '(repeat
337 (cons
338 (regexp :tag "Address")
339 (choice :tag "Banner" :value nil
340 (const :tag "Remove signature" signature)
341 (symbol :tag "Item in `gnus-article-banner-alist'" none)
342 regexp
343 (const :tag "None" nil))))
344 :version "22.1"
345 :group 'gnus-article-washing)
347 (defmacro gnus-emphasis-custom-with-format (&rest body)
348 `(let ((format "\
349 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
350 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351 ,@body))
353 (defun gnus-emphasis-custom-value-to-external (value)
354 (gnus-emphasis-custom-with-format
355 (if (consp (car value))
356 (list (format format (car (car value)) (cdr (car value)))
358 (if (nth 1 value) 2 3)
359 (nth 2 value))
360 value)))
362 (defun gnus-emphasis-custom-value-to-internal (value)
363 (gnus-emphasis-custom-with-format
364 (let ((regexp (concat "\\`"
365 (format (regexp-quote format)
366 "\\([^()]+\\)" "\\([^()]+\\)")
367 "\\'"))
368 pattern)
369 (if (string-match regexp (setq pattern (car value)))
370 (list (cons (match-string 1 pattern) (match-string 2 pattern))
371 (= (nth 2 value) 2)
372 (nth 3 value))
373 value))))
375 (defcustom gnus-emphasis-alist
376 (let ((types
377 '(("\\*" "\\*" bold nil 2)
378 ("_" "_" underline)
379 ("/" "/" italic)
380 ("_/" "/_" underline-italic)
381 ("_\\*" "\\*_" underline-bold)
382 ("\\*/" "/\\*" bold-italic)
383 ("_\\*/" "/\\*_" underline-bold-italic))))
384 (nconc
385 (gnus-emphasis-custom-with-format
386 (mapcar (lambda (spec)
387 (list (format format (car spec) (cadr spec))
388 (or (nth 3 spec) 2)
389 (or (nth 4 spec) 3)
390 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391 types))
392 '(;; I've never seen anyone use this strikethru convention whereas I've
393 ;; several times seen it triggered by normal text. --Stef
394 ;; Miles suggests that this form is sometimes used but for italics,
395 ;; so maybe we should map it to `italic'.
396 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
397 ;; 2 3 gnus-emphasis-strikethru)
398 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
399 2 3 gnus-emphasis-underline))))
400 "*Alist that says how to fontify certain phrases.
401 Each item looks like this:
403 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
405 The first element is a regular expression to be matched. The second
406 is a number that says what regular expression grouping used to find
407 the entire emphasized word. The third is a number that says what
408 regexp grouping should be displayed and highlighted. The fourth
409 is the face used for highlighting."
410 :type
411 '(repeat
412 (menu-choice
413 :format "%[Customizing Style%]\n%v"
414 :indent 2
415 (group :tag "Default"
416 :value ("" 0 0 default)
417 :value-create
418 (lambda (widget)
419 (let ((value (widget-get
420 (cadr (widget-get (widget-get widget :parent)
421 :args))
422 :value)))
423 (if (not (eq (nth 2 value) 'default))
424 (widget-put
425 widget
426 :value
427 (gnus-emphasis-custom-value-to-external value))))
428 (widget-group-value-create widget))
429 regexp
430 (integer :format "Match group: %v")
431 (integer :format "Emphasize group: %v")
432 face)
433 (group :tag "Simple"
434 :value (("_" . "_") nil default)
435 (cons :format "%v"
436 (regexp :format "Start regexp: %v")
437 (regexp :format "End regexp: %v"))
438 (boolean :format "Show start and end patterns: %[%v%]\n"
439 :on " On " :off " Off ")
440 face)))
441 :get (lambda (symbol)
442 (mapcar 'gnus-emphasis-custom-value-to-internal
443 (default-value symbol)))
444 :set (lambda (symbol value)
445 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446 value)))
447 :group 'gnus-article-emphasis)
449 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
450 "A regexp to describe whitespace which should not be emphasized.
451 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
452 The former avoids underlining of leading and trailing whitespace,
453 and the latter avoids underlining any whitespace at all."
454 :version "21.1"
455 :group 'gnus-article-emphasis
456 :type 'regexp)
458 (defface gnus-emphasis-bold '((t (:bold t)))
459 "Face used for displaying strong emphasized text (*word*)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-italic '((t (:italic t)))
463 "Face used for displaying italic emphasized text (/word/)."
464 :group 'gnus-article-emphasis)
466 (defface gnus-emphasis-underline '((t (:underline t)))
467 "Face used for displaying underlined emphasized text (_word_)."
468 :group 'gnus-article-emphasis)
470 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
471 "Face used for displaying underlined bold emphasized text (_*word*_)."
472 :group 'gnus-article-emphasis)
474 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
475 "Face used for displaying underlined italic emphasized text (_/word/_)."
476 :group 'gnus-article-emphasis)
478 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
479 "Face used for displaying bold italic emphasized text (/*word*/)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-underline-bold-italic
483 '((t (:bold t :italic t :underline t)))
484 "Face used for displaying underlined bold italic emphasized text.
485 Example: (_/*word*/_)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
489 '((t (:strikethru t)))
490 '((t (:strike-through t))))
491 "Face used for displaying strike-through text (-word-)."
492 :group 'gnus-article-emphasis)
494 (defface gnus-emphasis-highlight-words
495 '((t (:background "black" :foreground "yellow")))
496 "Face used for displaying highlighted words."
497 :group 'gnus-article-emphasis)
499 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
500 "Format for display of Date headers in article bodies.
501 See `format-time-string' for the possible values.
503 The variable can also be function, which should return a complete Date
504 header. The function is called with one argument, the time, which can
505 be fed to `format-time-string'."
506 :type '(choice string function)
507 :link '(custom-manual "(gnus)Article Date")
508 :group 'gnus-article-washing)
510 (defcustom gnus-save-all-headers t
511 "*If non-nil, don't remove any headers before saving.
512 This will be overridden by the `:headers' property that the symbol of
513 the saver function, which is specified by `gnus-default-article-saver',
514 might have."
515 :group 'gnus-article-saving
516 :type 'boolean)
518 (defcustom gnus-prompt-before-saving 'always
519 "*This variable says how much prompting is to be done when saving articles.
520 If it is nil, no prompting will be done, and the articles will be
521 saved to the default files. If this variable is `always', each and
522 every article that is saved will be preceded by a prompt, even when
523 saving large batches of articles. If this variable is neither nil not
524 `always', there the user will be prompted once for a file name for
525 each invocation of the saving commands."
526 :group 'gnus-article-saving
527 :type '(choice (item always)
528 (item :tag "never" nil)
529 (sexp :tag "once" :format "%t\n" :value t)))
531 (defcustom gnus-saved-headers gnus-visible-headers
532 "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving. This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539 :group 'gnus-article-saving
540 :type 'regexp)
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544 "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
548 Gnus provides the following functions:
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
560 The symbol of each function may have the following properties:
562 * :decode
563 The value non-nil means save decoded articles. This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file. This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file. This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved. If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580 :group 'gnus-article-saving
581 :type '(radio (function-item gnus-summary-save-in-rmail)
582 (function-item gnus-summary-save-in-mail)
583 (function-item gnus-summary-save-in-folder)
584 (function-item gnus-summary-save-in-file)
585 (function-item gnus-summary-save-body-in-file)
586 (function-item gnus-summary-save-in-vm)
587 (function-item gnus-summary-write-to-file)
588 (function-item gnus-summary-write-body-to-file)
589 (function-item gnus-summary-save-in-pipe)
590 (function)))
592 (defcustom gnus-article-save-coding-system
593 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597 "Coding system used to save decoded articles to a file.
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text. This is used by the
601 commands including:
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
608 and the functions to which you may set `gnus-default-article-saver':
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil. Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619 :group 'gnus-article-saving
620 :type `(choice
621 :format "%{%t%}:\n %[Value Menu%] %v"
622 (const :tag "Save raw articles" nil)
623 ,@(delq nil
624 (mapcar
625 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626 '((const :tag "UTF-8" utf-8)
627 (const :tag "iso-2022-7bit" iso-2022-7bit)
628 (const :tag "Emacs internal" emacs-mule)
629 (const :tag "escape-quoted" escape-quoted))))
630 (symbol :tag "Coding system")))
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639 "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645 "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647 :group 'gnus-article-saving
648 :type 'function)
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651 "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654 :group 'gnus-article-saving
655 :type 'function)
657 (defcustom gnus-split-methods
658 '((gnus-article-archive-name)
659 (gnus-article-nndoc-name))
660 "*Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
665 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
672 If the match is a string, it is used as a regexp match on the
673 article. If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter. If it is a list, it will be evalled in the same buffer.
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680 :group 'gnus-article-saving
681 :type '(repeat (choice (list :value (fun) function)
682 (cons :value ("" "") regexp (repeat string))
683 (sexp :value nil))))
685 (defcustom gnus-page-delimiter "^\^L"
686 "*Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689 :type 'regexp
690 :group 'gnus-article-various)
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693 "*The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
696 The following additional specs are available:
698 %w The article washing status.
699 %m The number of MIME parts in the article."
700 :version "24.1"
701 :type 'string
702 :group 'gnus-article-various)
704 (defcustom gnus-article-mode-hook nil
705 "*A hook for Gnus article mode."
706 :type 'hook
707 :group 'gnus-article-various)
709 (when (featurep 'xemacs)
710 ;; Extracted from gnus-xmas-define in order to preserve user settings
711 (when (fboundp 'turn-off-scroll-in-place)
712 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
713 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
714 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
716 (defcustom gnus-article-menu-hook nil
717 "*Hook run after the creation of the article mode menu."
718 :type 'hook
719 :group 'gnus-article-various)
721 (defcustom gnus-article-prepare-hook nil
722 "*A hook called after an article has been prepared in the article buffer."
723 :type 'hook
724 :group 'gnus-article-various)
726 (defcustom gnus-copy-article-ignored-headers nil
727 "List of headers to be removed when copying an article.
728 Each element is a regular expression."
729 :version "23.1" ;; No Gnus
730 :type '(repeat regexp)
731 :group 'gnus-article-various)
733 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
734 "Gnus 5.10 (Emacs 22.1)")
736 (defface gnus-button
737 '((t (:weight bold)))
738 "Face used for highlighting a button in the article buffer."
739 :group 'gnus-article-buttons)
741 (defcustom gnus-article-button-face 'gnus-button
742 "Face used for highlighting buttons in the article buffer.
744 An article button is a piece of text that you can activate by pressing
745 `RET' or `mouse-2' above it."
746 :type 'face
747 :group 'gnus-article-buttons)
749 (defcustom gnus-article-mouse-face 'highlight
750 "Face used for mouse highlighting in the article buffer.
752 Article buttons will be displayed in this face when the cursor is
753 above them."
754 :type 'face
755 :group 'gnus-article-buttons)
757 (defcustom gnus-signature-face 'gnus-signature
758 "Face used for highlighting a signature in the article buffer.
759 Obsolete; use the face `gnus-signature' for customizations instead."
760 :type 'face
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
764 (defface gnus-signature
765 '((t
766 (:italic t)))
767 "Face used for highlighting a signature in the article buffer."
768 :group 'gnus-article-highlight
769 :group 'gnus-article-signature)
770 ;; backward-compatibility alias
771 (put 'gnus-signature-face 'face-alias 'gnus-signature)
772 (put 'gnus-signature-face 'obsolete-face "22.1")
774 (defface gnus-header-from
775 '((((class color)
776 (background dark))
777 (:foreground "PaleGreen1"))
778 (((class color)
779 (background light))
780 (:foreground "red3"))
782 (:italic t)))
783 "Face used for displaying from headers."
784 :group 'gnus-article-headers
785 :group 'gnus-article-highlight)
786 ;; backward-compatibility alias
787 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
788 (put 'gnus-header-from-face 'obsolete-face "22.1")
790 (defface gnus-header-subject
791 '((((class color)
792 (background dark))
793 (:foreground "SeaGreen1"))
794 (((class color)
795 (background light))
796 (:foreground "red4"))
798 (:bold t :italic t)))
799 "Face used for displaying subject headers."
800 :group 'gnus-article-headers
801 :group 'gnus-article-highlight)
802 ;; backward-compatibility alias
803 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
804 (put 'gnus-header-subject-face 'obsolete-face "22.1")
806 (defface gnus-header-newsgroups
807 '((((class color)
808 (background dark))
809 (:foreground "yellow" :italic t))
810 (((class color)
811 (background light))
812 (:foreground "MidnightBlue" :italic t))
814 (:italic t)))
815 "Face used for displaying newsgroups headers.
816 In the default setup this face is only used for crossposted
817 articles."
818 :group 'gnus-article-headers
819 :group 'gnus-article-highlight)
820 ;; backward-compatibility alias
821 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
822 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
824 (defface gnus-header-name
825 '((((class color)
826 (background dark))
827 (:foreground "SpringGreen2"))
828 (((class color)
829 (background light))
830 (:foreground "maroon"))
832 (:bold t)))
833 "Face used for displaying header names."
834 :group 'gnus-article-headers
835 :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
838 (put 'gnus-header-name-face 'obsolete-face "22.1")
840 (defface gnus-header-content
841 '((((class color)
842 (background dark))
843 (:foreground "SpringGreen1" :italic t))
844 (((class color)
845 (background light))
846 (:foreground "indianred4" :italic t))
848 (:italic t))) "Face used for displaying header content."
849 :group 'gnus-article-headers
850 :group 'gnus-article-highlight)
851 ;; backward-compatibility alias
852 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
853 (put 'gnus-header-content-face 'obsolete-face "22.1")
855 (defcustom gnus-header-face-alist
856 '(("From" nil gnus-header-from)
857 ("Subject" nil gnus-header-subject)
858 ("Newsgroups:.*," nil gnus-header-newsgroups)
859 ("" gnus-header-name gnus-header-content))
860 "*Controls highlighting of article headers.
862 An alist of the form (HEADER NAME CONTENT).
864 HEADER is a regular expression which should match the name of a
865 header and NAME and CONTENT are either face names or nil.
867 The name of each header field will be displayed using the face
868 specified by the first element in the list where HEADER matches
869 the header name and NAME is non-nil. Similarly, the content will
870 be displayed by the first non-nil matching CONTENT face."
871 :group 'gnus-article-headers
872 :group 'gnus-article-highlight
873 :type '(repeat (list (regexp :tag "Header")
874 (choice :tag "Name"
875 (item :tag "skip" nil)
876 (face :value default))
877 (choice :tag "Content"
878 (item :tag "skip" nil)
879 (face :value default)))))
881 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
882 '((xface . (:face gnus-x-face)))
883 '((pbm . (:face gnus-x-face))
884 (png . nil)))
885 "Alist of image types and properties applied to Face and X-Face images.
886 Here are examples:
888 ;; Specify the altitude of Face images in the From header.
889 \(setq gnus-face-properties-alist
890 '((pbm . (:face gnus-x-face :ascent 80))
891 (png . (:ascent 80))))
893 ;; Show Face images as pressed buttons.
894 \(setq gnus-face-properties-alist
895 '((pbm . (:face gnus-x-face :relief -2))
896 (png . (:relief -2))))
898 See the manual for the valid properties for various image types.
899 Currently, `pbm' is used for X-Face images and `png' is used for Face
900 images in Emacs. Only the `:face' property is effective on the `xface'
901 image type in XEmacs if it is built with the libcompface library."
902 :version "23.1" ;; No Gnus
903 :group 'gnus-article-headers
904 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
906 (defcustom gnus-article-decode-hook
907 '(article-decode-charset article-decode-encoded-words
908 article-decode-group-name article-decode-idna-rhs)
909 "*Hook run to decode charsets in articles."
910 :group 'gnus-article-headers
911 :type 'hook)
913 (defcustom gnus-display-mime-function 'gnus-display-mime
914 "Function to display MIME articles."
915 :group 'gnus-article-mime
916 :type 'function)
918 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
919 "Function used to decode headers.")
921 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
922 "Function used to decode addresses.")
924 (defvar gnus-article-dumbquotes-map
925 '((?\200 "EUR")
926 (?\202 ",")
927 (?\203 "f")
928 (?\204 ",,")
929 (?\205 "...")
930 (?\213 "<")
931 (?\214 "OE")
932 (?\221 "`")
933 (?\222 "'")
934 (?\223 "``")
935 (?\224 "\"")
936 (?\225 "*")
937 (?\226 "-")
938 (?\227 "--")
939 (?\230 "~")
940 (?\231 "(TM)")
941 (?\233 ">")
942 (?\234 "oe")
943 (?\264 "'"))
944 "Table for MS-to-Latin1 translation.")
946 (defcustom gnus-ignored-mime-types nil
947 "List of MIME types that should be ignored by Gnus."
948 :version "21.1"
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
952 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
953 "List of MIME types that should not be given buttons when rendered inline.
954 See also `gnus-buttonized-mime-types' which may override this variable.
955 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956 :version "21.1"
957 :group 'gnus-article-mime
958 :type '(repeat regexp))
960 (defcustom gnus-buttonized-mime-types nil
961 "List of MIME types that should be given buttons when rendered inline.
962 If set, this variable overrides `gnus-unbuttonized-mime-types'.
963 To see e.g. security buttons you could set this to
964 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
965 this list to display radio buttons that allow you to choose one of two
966 media types those mails include. See also `mm-discouraged-alternatives'.
967 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type '(repeat regexp))
972 (defcustom gnus-inhibit-mime-unbuttonizing nil
973 "If non-nil, all MIME parts get buttons.
974 When nil (the default value), then some MIME parts do not get buttons,
975 as described by the variables `gnus-buttonized-mime-types' and
976 `gnus-unbuttonized-mime-types'."
977 :version "22.1"
978 :group 'gnus-article-mime
979 :type 'boolean)
981 (defcustom gnus-body-boundary-delimiter "_"
982 "String used to delimit header and body.
983 This variable is used by `gnus-article-treat-body-boundary' which can
984 be controlled by `gnus-treat-body-boundary'."
985 :version "22.1"
986 :group 'gnus-article-various
987 :type '(choice (item :tag "None" :value nil)
988 string))
990 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991 "/usr/share/picons")
992 "Defines the location of the faces database.
993 For information on obtaining this database of pretty pictures, please
994 see http://www.cs.indiana.edu/picons/ftp/index.html"
995 :version "22.1"
996 :type '(repeat directory)
997 :link '(url-link :tag "download"
998 "http://www.cs.indiana.edu/picons/ftp/index.html")
999 :link '(custom-manual "(gnus)Picons")
1000 :group 'gnus-picon)
1002 (defun gnus-picons-installed-p ()
1003 "Say whether picons are installed on your machine."
1004 (let ((installed nil))
1005 (dolist (database gnus-picon-databases)
1006 (when (file-exists-p database)
1007 (setq installed t)))
1008 installed))
1010 (defcustom gnus-article-mime-part-function nil
1011 "Function called with a MIME handle as the argument.
1012 This is meant for people who want to do something automatic based
1013 on parts -- for instance, adding Vcard info to a database."
1014 :group 'gnus-article-mime
1015 :type '(choice (const nil)
1016 function))
1018 (defcustom gnus-mime-multipart-functions nil
1019 "An alist of MIME types to functions to display them."
1020 :version "21.1"
1021 :group 'gnus-article-mime
1022 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1024 (defcustom gnus-article-date-headers '(combined-lapsed)
1025 "A list of Date header formats to display.
1026 Valid formats are `ut' (universal time), `local' (local time
1027 zone), `english' (readable English), `lapsed' (elapsed time),
1028 `combined-lapsed' (both the original date and the elapsed time),
1029 `original' (the original date header), `iso8601' (ISO8601
1030 format), and `user-defined' (a user-defined format defined by the
1031 `gnus-article-time-format' variable).
1033 You have as many date headers as you want in the article buffer.
1034 Some of these headers are updated automatically. See
1035 `gnus-article-update-date-headers' for details."
1036 :version "24.1"
1037 :group 'gnus-article-headers
1038 :type '(set
1039 (const :tag "Universal time (UT)" ut)
1040 (const :tag "Local time zone" local)
1041 (const :tag "Readable English" english)
1042 (const :tag "Elapsed time" lapsed)
1043 (const :tag "Original and elapsed time" combined-lapsed)
1044 (const :tag "Original date header" original)
1045 (const :tag "ISO8601 format" iso8601)
1046 (const :tag "User-defined" user-defined)))
1048 (defcustom gnus-article-update-date-headers nil
1049 "A number that says how often to update the date header (in seconds).
1050 If nil, don't update it at all."
1051 :version "24.1"
1052 :group 'gnus-article-headers
1053 :type '(choice
1054 (item :tag "Don't update" :value nil)
1055 integer))
1057 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1058 "Function called with a MIME handle as the argument.
1059 This is meant for people who want to view first matched part.
1060 For `undisplayed-alternative' (default), the first undisplayed
1061 part or alternative part is used. For `undisplayed', the first
1062 undisplayed part is used. For a function, the first part which
1063 the function return t is used. For nil, the first part is
1064 used."
1065 :version "21.1"
1066 :group 'gnus-article-mime
1067 :type '(choice
1068 (item :tag "first" :value nil)
1069 (item :tag "undisplayed" :value undisplayed)
1070 (item :tag "undisplayed or alternative"
1071 :value undisplayed-alternative)
1072 (function)))
1074 (defcustom gnus-mime-action-alist
1075 '(("save to file" . gnus-mime-save-part)
1076 ("save and strip" . gnus-mime-save-part-and-strip)
1077 ("replace with file" . gnus-mime-replace-part)
1078 ("delete part" . gnus-mime-delete-part)
1079 ("display as text" . gnus-mime-inline-part)
1080 ("view the part" . gnus-mime-view-part)
1081 ("pipe to command" . gnus-mime-pipe-part)
1082 ("toggle display" . gnus-article-press-button)
1083 ("toggle display" . gnus-article-view-part-as-charset)
1084 ("view as type" . gnus-mime-view-part-as-type)
1085 ("view internally" . gnus-mime-view-part-internally)
1086 ("view externally" . gnus-mime-view-part-externally))
1087 "An alist of actions that run on the MIME attachment."
1088 :group 'gnus-article-mime
1089 :type '(repeat (cons (string :tag "name")
1090 (function))))
1092 (defcustom gnus-auto-select-part 1
1093 "Advance to next MIME part when deleting or stripping parts.
1095 When 0, point will be placed on the same part as before. When
1096 positive (negative), move point forward (backwards) this many
1097 parts. When nil, redisplay article."
1098 :version "23.1" ;; No Gnus
1099 :group 'gnus-article-mime
1100 :type '(choice (const nil :tag "Redisplay article.")
1101 (const 1 :tag "Next part.")
1102 (const 0 :tag "Current part.")
1103 integer))
1106 ;;; The treatment variables
1109 (defvar gnus-part-display-hook nil
1110 "Hook called on parts that are to receive treatment.")
1112 (defvar gnus-article-treat-custom
1113 '(choice (const :tag "Off" nil)
1114 (const :tag "On" t)
1115 (const :tag "Header" head)
1116 (const :tag "First" first)
1117 (const :tag "Last" last)
1118 (integer :tag "Less")
1119 (repeat :tag "Groups" regexp)
1120 (sexp :tag "Predicate")))
1122 (defvar gnus-article-treat-head-custom
1123 '(choice (const :tag "Off" nil)
1124 (const :tag "Header" head)))
1126 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 "text/x-patch" "text/html")
1128 "Part types eligible for treatment.")
1130 (defvar gnus-inhibit-treatment nil
1131 "Whether to inhibit treatment.")
1133 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1134 "Highlight the signature.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-signature 'highlight t)
1142 (defcustom gnus-treat-buttonize 100000
1143 "Add buttons.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-custom)
1149 (put 'gnus-treat-buttonize 'highlight t)
1151 (defcustom gnus-treat-buttonize-head 'head
1152 "Add buttons to the head.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-head-custom)
1158 (put 'gnus-treat-buttonize-head 'highlight t)
1160 (defcustom gnus-treat-date 'head
1161 "Display dates according to the `gnus-article-date-headers' variable.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :version "24.1"
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
1167 :type gnus-article-treat-head-custom)
1169 (defcustom gnus-treat-emphasize 50000
1170 "Emphasize text.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :group 'gnus-article-treat
1174 :link '(custom-manual "(gnus)Customizing Articles")
1175 :type gnus-article-treat-custom)
1176 (put 'gnus-treat-emphasize 'highlight t)
1178 (defcustom gnus-treat-strip-cr nil
1179 "Remove carriage returns.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate. See Info node `(gnus)Customizing Articles'."
1182 :version "22.1"
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1187 (defcustom gnus-treat-unsplit-urls nil
1188 "Remove newlines from within URLs.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :version "22.1"
1192 :group 'gnus-article-treat
1193 :link '(custom-manual "(gnus)Customizing Articles")
1194 :type gnus-article-treat-custom)
1196 (defcustom gnus-treat-leading-whitespace nil
1197 "Remove leading whitespace in headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :version "22.1"
1201 :group 'gnus-article-treat
1202 :link '(custom-manual "(gnus)Customizing Articles")
1203 :type gnus-article-treat-custom)
1205 (defcustom gnus-treat-hide-headers 'head
1206 "Hide headers.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate. See Info node `(gnus)Customizing Articles'."
1209 :group 'gnus-article-treat
1210 :link '(custom-manual "(gnus)Customizing Articles")
1211 :type gnus-article-treat-head-custom)
1213 (defcustom gnus-treat-hide-boring-headers nil
1214 "Hide boring headers.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate. See Info node `(gnus)Customizing Articles'."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-head-custom)
1221 (defcustom gnus-treat-hide-signature nil
1222 "Hide the signature.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate. See Info node `(gnus)Customizing Articles'."
1225 :group 'gnus-article-treat
1226 :link '(custom-manual "(gnus)Customizing Articles")
1227 :type gnus-article-treat-custom)
1229 (defcustom gnus-treat-fill-article nil
1230 "Fill the article.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate. See Info node `(gnus)Customizing Articles'."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1237 (defcustom gnus-treat-hide-citation nil
1238 "Hide cited text.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate. See Info node `(gnus)Customizing Articles'.
1242 See `gnus-article-highlight-citation' for variables used to
1243 control what it hides."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1248 (defcustom gnus-treat-hide-citation-maybe nil
1249 "Hide cited text according to certain conditions.
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate. See Info node `(gnus)Customizing Articles'.
1253 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1254 how to control what it hides."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (defcustom gnus-treat-strip-list-identifiers 'head
1260 "Strip list identifiers from `gnus-list-identifiers`.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate. See Info node `(gnus)Customizing Articles'."
1263 :version "21.1"
1264 :group 'gnus-article-treat
1265 :link '(custom-manual "(gnus)Customizing Articles")
1266 :type gnus-article-treat-custom)
1268 (gnus-define-group-parameter
1269 list-identifier
1270 :variable-document
1271 "Alist of regexps and correspondent identifiers."
1272 :variable-group gnus-article-washing
1273 :parameter-type
1274 '(choice :tag "Identifier"
1275 :value nil
1276 (symbol :tag "Item in `gnus-list-identifiers'" none)
1277 regexp
1278 (const :tag "None" nil))
1279 :parameter-document
1280 "If non-nil, specify how to remove `identifiers' from articles' subject.
1282 Any symbol is used to look up a regular expression to match the
1283 banner in `gnus-list-identifiers'. A string is used as a regular
1284 expression to match the identifier directly.")
1286 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1287 "Gnus 5.10 (Emacs 22.1)")
1289 (defcustom gnus-treat-strip-pem nil
1290 "Strip PEM signatures.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate. See Info node `(gnus)Customizing Articles'."
1293 :group 'gnus-article-treat
1294 :link '(custom-manual "(gnus)Customizing Articles")
1295 :type gnus-article-treat-custom)
1297 (defcustom gnus-treat-strip-banner t
1298 "Strip banners from articles.
1299 The banner to be stripped is specified in the `banner' group parameter.
1300 Valid values are nil, t, `head', `first', `last', an integer or a
1301 predicate. See Info node `(gnus)Customizing Articles'."
1302 :group 'gnus-article-treat
1303 :link '(custom-manual "(gnus)Customizing Articles")
1304 :type gnus-article-treat-custom)
1306 (defcustom gnus-treat-highlight-headers 'head
1307 "Highlight the headers.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate. See Info node `(gnus)Customizing Articles'."
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-head-custom)
1313 (put 'gnus-treat-highlight-headers 'highlight t)
1315 (defcustom gnus-treat-highlight-citation t
1316 "Highlight cited text.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-custom)
1322 (put 'gnus-treat-highlight-citation 'highlight t)
1324 (defcustom gnus-treat-strip-headers-in-body t
1325 "Strip the X-No-Archive header line from the beginning of the body.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'."
1328 :version "21.1"
1329 :group 'gnus-article-treat
1330 :link '(custom-manual "(gnus)Customizing Articles")
1331 :type gnus-article-treat-custom)
1333 (defcustom gnus-treat-strip-trailing-blank-lines nil
1334 "Strip trailing blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate. See Info node `(gnus)Customizing Articles'.
1338 When set to t, it also strips trailing blanks in all MIME parts.
1339 Consider to use `last' instead."
1340 :group 'gnus-article-treat
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :type gnus-article-treat-custom)
1344 (defcustom gnus-treat-strip-leading-blank-lines nil
1345 "Strip leading blank lines.
1346 Valid values are nil, t, `head', `first', `last', an integer or a
1347 predicate. See Info node `(gnus)Customizing Articles'.
1349 When set to t, it also strips trailing blanks in all MIME parts."
1350 :group 'gnus-article-treat
1351 :link '(custom-manual "(gnus)Customizing Articles")
1352 :type gnus-article-treat-custom)
1354 (defcustom gnus-treat-strip-multiple-blank-lines nil
1355 "Strip multiple blank lines.
1356 Valid values are nil, t, `head', `first', `last', an integer or a
1357 predicate. See Info node `(gnus)Customizing Articles'."
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1362 (defcustom gnus-treat-unfold-headers 'head
1363 "Unfold folded header lines.
1364 Valid values are nil, t, `head', `first', `last', an integer or a
1365 predicate. See Info node `(gnus)Customizing Articles'."
1366 :version "22.1"
1367 :group 'gnus-article-treat
1368 :link '(custom-manual "(gnus)Customizing Articles")
1369 :type gnus-article-treat-custom)
1371 (defcustom gnus-article-unfold-long-headers nil
1372 "If non-nil, allow unfolding headers even if the header is long.
1373 If it is a regexp, only long headers matching this regexp are unfolded.
1374 If it is t, all long headers are unfolded.
1376 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1377 :version "23.1" ;; No Gnus
1378 :group 'gnus-article-treat
1379 :type '(choice (const nil)
1380 (const :tag "all" t)
1381 (regexp)))
1383 (defcustom gnus-treat-fold-headers nil
1384 "Fold headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles'."
1387 :version "22.1"
1388 :group 'gnus-article-treat
1389 :link '(custom-manual "(gnus)Customizing Articles")
1390 :type gnus-article-treat-custom)
1392 (defcustom gnus-treat-fold-newsgroups 'head
1393 "Fold the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :version "22.1"
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1401 (defcustom gnus-treat-overstrike t
1402 "Treat overstrike highlighting.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate. See Info node `(gnus)Customizing Articles'."
1405 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :type gnus-article-treat-custom)
1408 (put 'gnus-treat-overstrike 'highlight t)
1410 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1411 "Treat ANSI SGR control sequences.
1412 Valid values are nil, t, `head', `first', `last', an integer or a
1413 predicate. See Info node `(gnus)Customizing Articles'."
1414 :group 'gnus-article-treat
1415 :link '(custom-manual "(gnus)Customizing Articles")
1416 :type gnus-article-treat-custom)
1418 (make-obsolete-variable 'gnus-treat-display-xface
1419 'gnus-treat-display-x-face "Emacs 22.1")
1421 (defcustom gnus-treat-display-x-face
1422 (and (not noninteractive)
1423 (gnus-image-type-available-p 'xbm)
1424 (if (featurep 'xemacs)
1425 (featurep 'xface)
1426 (condition-case nil
1427 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1428 (executable-find "icontopbm"))
1429 ;; shell-command-to-string may signal an error, e.g. if
1430 ;; shell-file-name is not found.
1431 (error nil)))
1432 'head)
1433 "Display X-Face headers.
1434 Valid values are nil and `head'.
1435 See Info node `(gnus)Customizing Articles' and Info node
1436 `(gnus)X-Face' for details."
1437 :group 'gnus-article-treat
1438 :version "21.1"
1439 :link '(custom-manual "(gnus)Customizing Articles")
1440 :link '(custom-manual "(gnus)X-Face")
1441 :type gnus-article-treat-head-custom
1442 :set (lambda (symbol value)
1443 (set-default
1444 symbol
1445 (cond ((or (boundp symbol) (get symbol 'saved-value))
1446 value)
1447 ((boundp 'gnus-treat-display-xface)
1448 (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450 use gnus-treat-display-x-face instead")
1451 (default-value 'gnus-treat-display-xface))
1452 ((get 'gnus-treat-display-xface 'saved-value)
1453 (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455 use gnus-treat-display-x-face instead")
1456 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1458 value)))))
1459 (put 'gnus-treat-display-x-face 'highlight t)
1461 (defcustom gnus-treat-display-face
1462 (and (not noninteractive)
1463 (gnus-image-type-available-p 'png)
1464 'head)
1465 "Display Face headers.
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate. See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Face' for details."
1469 :group 'gnus-article-treat
1470 :version "22.1"
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :link '(custom-manual "(gnus)X-Face")
1473 :type gnus-article-treat-head-custom)
1474 (put 'gnus-treat-display-face 'highlight t)
1476 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477 "Display smileys.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Smileys' for details."
1481 :group 'gnus-article-treat
1482 :version "21.1"
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Smileys")
1485 :type gnus-article-treat-custom)
1486 (put 'gnus-treat-display-smileys 'highlight t)
1488 (defcustom gnus-treat-from-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in the From header.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-from-picon 'highlight t)
1504 (defcustom gnus-treat-mail-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in To and Cc headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-mail-picon 'highlight t)
1520 (defcustom gnus-treat-newsgroups-picon
1521 (if (and (gnus-image-type-available-p 'xpm)
1522 (gnus-picons-installed-p))
1523 'head nil)
1524 "Display picons in the Newsgroups and Followup-To headers.
1525 Valid values are nil, t, `head', `first', `last', an integer or a
1526 predicate. See Info node `(gnus)Customizing Articles' and Info
1527 node `(gnus)Picons' for details."
1528 :version "22.1"
1529 :group 'gnus-article-treat
1530 :group 'gnus-picon
1531 :link '(custom-manual "(gnus)Customizing Articles")
1532 :link '(custom-manual "(gnus)Picons")
1533 :type gnus-article-treat-head-custom)
1534 (put 'gnus-treat-newsgroups-picon 'highlight t)
1536 (defcustom gnus-treat-from-gravatar nil
1537 "Display gravatars in the From header.
1538 Valid values are nil, t, `head', `first', `last', an integer or a
1539 predicate. See Info node `(gnus)Customizing Articles' and Info
1540 node `(gnus)Gravatars' for details."
1541 :version "24.1"
1542 :group 'gnus-article-treat
1543 :group 'gnus-gravatar
1544 :link '(custom-manual "(gnus)Customizing Articles")
1545 :link '(custom-manual "(gnus)Gravatars")
1546 :type gnus-article-treat-head-custom)
1547 (put 'gnus-treat-from-gravatar 'highlight t)
1549 (defcustom gnus-treat-mail-gravatar nil
1550 "Display gravatars in To and Cc headers.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate. See Info node `(gnus)Customizing Articles' and Info
1553 node `(gnus)Gravatars' for details."
1554 :version "24.1"
1555 :group 'gnus-article-treat
1556 :group 'gnus-gravatar
1557 :link '(custom-manual "(gnus)Customizing Articles")
1558 :link '(custom-manual "(gnus)Gravatars")
1559 :type gnus-article-treat-head-custom)
1560 (put 'gnus-treat-mail-gravatar 'highlight t)
1562 (defcustom gnus-treat-body-boundary
1563 (if (or gnus-treat-newsgroups-picon
1564 gnus-treat-mail-picon
1565 gnus-treat-from-picon
1566 gnus-treat-from-gravatar
1567 gnus-treat-mail-gravatar)
1568 ;; If there's much decoration, the user might prefer a boundary.
1569 'head
1570 nil)
1571 "Draw a boundary at the end of the headers.
1572 Valid values are nil and `head'.
1573 See Info node `(gnus)Customizing Articles' for details."
1574 :version "22.1"
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-head-custom)
1579 (defcustom gnus-treat-capitalize-sentences nil
1580 "Capitalize sentence-starting words.
1581 Valid values are nil, t, `head', `first', `last', an integer or a
1582 predicate. See Info node `(gnus)Customizing Articles'."
1583 :version "21.1"
1584 :group 'gnus-article-treat
1585 :link '(custom-manual "(gnus)Customizing Articles")
1586 :type gnus-article-treat-custom)
1588 (defcustom gnus-treat-wash-html nil
1589 "Format as HTML.
1590 Valid values are nil, t, `head', `first', `last', an integer or a
1591 predicate. See Info node `(gnus)Customizing Articles'."
1592 :version "22.1"
1593 :group 'gnus-article-treat
1594 :link '(custom-manual "(gnus)Customizing Articles")
1595 :type gnus-article-treat-custom)
1597 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598 "Fill long lines.
1599 Valid values are nil, t, `head', `first', `last', an integer or a
1600 predicate. See Info node `(gnus)Customizing Articles'."
1601 :version "24.1"
1602 :group 'gnus-article-treat
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1606 (defcustom gnus-treat-x-pgp-sig nil
1607 "Verify X-PGP-Sig.
1608 To automatically treat X-PGP-Sig, set it to head.
1609 Valid values are nil, t, `head', `first', `last', an integer or a
1610 predicate. See Info node `(gnus)Customizing Articles'."
1611 :version "22.1"
1612 :group 'gnus-article-treat
1613 :group 'mime-security
1614 :link '(custom-manual "(gnus)Customizing Articles")
1615 :type gnus-article-treat-custom)
1617 (defvar gnus-article-encrypt-protocol-alist
1618 '(("PGP" . mml2015-self-encrypt)))
1620 ;; Set to nil if more than one protocol added to
1621 ;; gnus-article-encrypt-protocol-alist.
1622 (defcustom gnus-article-encrypt-protocol "PGP"
1623 "The protocol used for encrypt articles.
1624 It is a string, such as \"PGP\". If nil, ask user."
1625 :version "22.1"
1626 :type 'string
1627 :group 'mime-security)
1629 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1630 (mm-coding-system-p 'utf-8)
1631 idna-program
1632 (executable-find idna-program))
1633 "Whether IDNA decoding of headers is used when viewing messages.
1634 This requires GNU Libidn, and by default only enabled if it is found."
1635 :version "22.1"
1636 :group 'gnus-article-headers
1637 :type 'boolean)
1639 (defcustom gnus-article-over-scroll nil
1640 "If non-nil, allow scrolling the article buffer even when there no more text."
1641 :version "22.1"
1642 :group 'gnus-article
1643 :type 'boolean)
1645 (defcustom gnus-inhibit-images nil
1646 "Non-nil means inhibit displaying of images inline in the article body."
1647 :version "24.1"
1648 :group 'gnus-article
1649 :type 'boolean)
1651 (defcustom gnus-blocked-images 'gnus-block-private-groups
1652 "Images that have URLs matching this regexp will be blocked.
1653 This can also be a function to be evaluated. If so, it will be
1654 called with the group name as the parameter, and should return a
1655 regexp."
1656 :version "24.1"
1657 :group 'gnus-art
1658 :type '(choice regexp function))
1660 ;;; Internal variables
1662 (defvar gnus-english-month-names
1663 '("January" "February" "March" "April" "May" "June" "July" "August"
1664 "September" "October" "November" "December"))
1666 (defvar article-goto-body-goes-to-point-min-p nil)
1667 (defvar gnus-article-wash-types nil)
1668 (defvar gnus-article-emphasis-alist nil)
1669 (defvar gnus-article-image-alist nil)
1671 (defvar gnus-article-mime-handle-alist-1 nil)
1672 (defvar gnus-treatment-function-alist
1673 '((gnus-treat-strip-cr gnus-article-remove-cr)
1674 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1675 (gnus-treat-strip-banner gnus-article-strip-banner)
1676 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1677 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1678 (gnus-treat-buttonize gnus-article-add-buttons)
1679 (gnus-treat-fill-article gnus-article-fill-cited-article)
1680 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1681 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1682 (gnus-treat-display-x-face gnus-article-display-x-face)
1683 (gnus-treat-display-face gnus-article-display-face)
1684 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1685 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1686 (gnus-treat-hide-signature gnus-article-hide-signature)
1687 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1688 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1689 (gnus-treat-from-picon gnus-treat-from-picon)
1690 (gnus-treat-mail-picon gnus-treat-mail-picon)
1691 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1692 (gnus-treat-strip-pem gnus-article-hide-pem)
1693 (gnus-treat-date gnus-article-treat-date)
1694 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1695 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1696 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1697 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1698 (gnus-treat-strip-trailing-blank-lines
1699 gnus-article-remove-trailing-blank-lines)
1700 (gnus-treat-strip-leading-blank-lines
1701 gnus-article-strip-leading-blank-lines)
1702 (gnus-treat-strip-multiple-blank-lines
1703 gnus-article-strip-multiple-blank-lines)
1704 (gnus-treat-overstrike gnus-article-treat-overstrike)
1705 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1706 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1707 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1708 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1709 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1710 (gnus-treat-display-smileys gnus-treat-smiley)
1711 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1712 (gnus-treat-wash-html gnus-article-wash-html)
1713 (gnus-treat-emphasize gnus-article-emphasize)
1714 (gnus-treat-hide-citation gnus-article-hide-citation)
1715 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1716 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1717 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1719 (defvar gnus-article-mime-handle-alist nil)
1720 (defvar article-lapsed-timer nil)
1721 (defvar gnus-article-current-summary nil)
1723 (defvar gnus-article-mode-syntax-table
1724 (let ((table (copy-syntax-table text-mode-syntax-table)))
1725 ;; This causes the citation match run O(2^n).
1726 ;; (modify-syntax-entry ?- "w" table)
1727 (modify-syntax-entry ?> ")<" table)
1728 (modify-syntax-entry ?< "(>" table)
1729 ;; make M-. in article buffers work for `foo' strings
1730 (modify-syntax-entry ?' " " table)
1731 (modify-syntax-entry ?` " " table)
1732 table)
1733 "Syntax table used in article mode buffers.
1734 Initialized from `text-mode-syntax-table.")
1736 (defvar gnus-save-article-buffer nil)
1738 (defvar gnus-number-of-articles-to-be-saved nil)
1740 (defvar gnus-inhibit-hiding nil)
1742 (defvar gnus-article-edit-mode nil)
1744 ;;; Macros for dealing with the article buffer.
1746 (defmacro gnus-with-article-headers (&rest forms)
1747 `(with-current-buffer gnus-article-buffer
1748 (save-restriction
1749 (let ((inhibit-read-only t)
1750 (inhibit-point-motion-hooks t)
1751 (case-fold-search t))
1752 (article-narrow-to-head)
1753 ,@forms))))
1755 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1756 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1758 (defmacro gnus-with-article-buffer (&rest forms)
1759 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1760 (with-current-buffer gnus-article-buffer
1761 (let ((inhibit-read-only t))
1762 ,@forms))))
1764 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1765 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1767 (defun gnus-article-goto-header (header)
1768 "Go to HEADER, which is a regular expression."
1769 (re-search-forward (concat "^\\(" header "\\):") nil t))
1771 (defsubst gnus-article-hide-text (b e props)
1772 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1773 (gnus-add-text-properties-when 'article-type nil b e props)
1774 (when (memq 'intangible props)
1775 (put-text-property
1776 (max (1- b) (point-min))
1777 b 'intangible (cddr (memq 'intangible props)))))
1779 (defsubst gnus-article-unhide-text (b e)
1780 "Remove hidden text properties from region between B and E."
1781 (remove-text-properties b e gnus-hidden-properties)
1782 (when (memq 'intangible gnus-hidden-properties)
1783 (put-text-property (max (1- b) (point-min))
1784 b 'intangible nil)))
1786 (defun gnus-article-hide-text-type (b e type)
1787 "Hide text of TYPE between B and E."
1788 (gnus-add-wash-type type)
1789 (gnus-article-hide-text
1790 b e (cons 'article-type (cons type gnus-hidden-properties))))
1792 (defun gnus-article-unhide-text-type (b e type)
1793 "Unhide text of TYPE between B and E."
1794 (gnus-delete-wash-type type)
1795 (remove-text-properties
1796 b e (cons 'article-type (cons type gnus-hidden-properties)))
1797 (when (memq 'intangible gnus-hidden-properties)
1798 (put-text-property (max (1- b) (point-min))
1799 b 'intangible nil)))
1801 (defun gnus-article-delete-text-of-type (type)
1802 "Delete text of TYPE in the current buffer."
1803 (save-excursion
1804 (let ((b (point-min)))
1805 (if (eq type 'multipart)
1806 ;; Remove MIME buttons associated with multipart/alternative parts.
1807 (progn
1808 (goto-char b)
1809 (while (if (get-text-property (point) 'gnus-part)
1810 (setq b (point))
1811 (when (setq b (next-single-property-change (point)
1812 'gnus-part))
1813 (goto-char b)
1815 (end-of-line)
1816 (skip-chars-forward "\n")
1817 (when (eq (get-text-property b 'article-type) 'multipart)
1818 (delete-region b (point)))))
1819 (while (setq b (text-property-any b (point-max) 'article-type type))
1820 (delete-region
1821 b (or (text-property-not-all b (point-max) 'article-type type)
1822 (point-max))))))))
1824 (defun gnus-article-delete-invisible-text ()
1825 "Delete all invisible text in the current buffer."
1826 (save-excursion
1827 (let ((b (point-min)))
1828 (while (setq b (text-property-any b (point-max) 'invisible t))
1829 (delete-region
1830 b (or (text-property-not-all b (point-max) 'invisible t)
1831 (point-max)))))))
1833 (defsubst gnus-article-header-rank ()
1834 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1835 (let ((list gnus-sorted-header-list)
1836 (i 1))
1837 (while list
1838 (if (looking-at (car list))
1839 (setq list nil)
1840 (setq list (cdr list))
1841 (incf i)))
1844 (defun article-hide-headers (&optional arg delete)
1845 "Hide unwanted headers and possibly sort them as well."
1846 (interactive)
1847 ;; This function might be inhibited.
1848 (unless gnus-inhibit-hiding
1849 (let ((inhibit-read-only t)
1850 (case-fold-search t)
1851 (max (1+ (length gnus-sorted-header-list)))
1852 (inhibit-point-motion-hooks t)
1853 (cur (current-buffer))
1854 ignored visible beg)
1855 (save-excursion
1856 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1857 ;; group parameters, so we should go to the summary buffer.
1858 (when (prog1
1859 (condition-case nil
1860 (progn (set-buffer gnus-summary-buffer) t)
1861 (error nil))
1862 (setq ignored (when (not gnus-visible-headers)
1863 (cond ((stringp gnus-ignored-headers)
1864 gnus-ignored-headers)
1865 ((listp gnus-ignored-headers)
1866 (mapconcat 'identity
1867 gnus-ignored-headers
1868 "\\|"))))
1869 visible (cond ((stringp gnus-visible-headers)
1870 gnus-visible-headers)
1871 ((and gnus-visible-headers
1872 (listp gnus-visible-headers))
1873 (mapconcat 'identity
1874 gnus-visible-headers
1875 "\\|")))))
1876 (set-buffer cur))
1877 (save-restriction
1878 ;; First we narrow to just the headers.
1879 (article-narrow-to-head)
1880 ;; Hide any "From " lines at the beginning of (mail) articles.
1881 (while (looking-at "From ")
1882 (forward-line 1))
1883 (unless (bobp)
1884 (delete-region (point-min) (point)))
1885 ;; Then treat the rest of the header lines.
1886 ;; Then we use the two regular expressions
1887 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1888 ;; select which header lines is to remain visible in the
1889 ;; article buffer.
1890 (while (re-search-forward "^[^ \t:]*:" nil t)
1891 (beginning-of-line)
1892 ;; Mark the rank of the header.
1893 (put-text-property
1894 (point) (1+ (point)) 'message-rank
1895 (if (or (and visible (looking-at visible))
1896 (and ignored
1897 (not (looking-at ignored))))
1898 (gnus-article-header-rank)
1899 (+ 2 max)))
1900 (forward-line 1))
1901 (message-sort-headers-1)
1902 (when (setq beg (text-property-any
1903 (point-min) (point-max) 'message-rank (+ 2 max)))
1904 ;; We delete the unwanted headers.
1905 (gnus-add-wash-type 'headers)
1906 (add-text-properties (point-min) (+ 5 (point-min))
1907 '(article-type headers dummy-invisible t))
1908 (delete-region beg (point-max))))))))
1910 (defun article-hide-boring-headers (&optional arg)
1911 "Toggle hiding of headers that aren't very interesting.
1912 If given a negative prefix, always show; if given a positive prefix,
1913 always hide."
1914 (interactive (gnus-article-hidden-arg))
1915 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1916 (not gnus-show-all-headers))
1917 (save-excursion
1918 (save-restriction
1919 (let ((inhibit-read-only t)
1920 (inhibit-point-motion-hooks t))
1921 (article-narrow-to-head)
1922 (dolist (elem gnus-boring-article-headers)
1923 (goto-char (point-min))
1924 (cond
1925 ;; Hide empty headers.
1926 ((eq elem 'empty)
1927 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1928 (forward-line -1)
1929 (gnus-article-hide-text-type
1930 (point-at-bol)
1931 (progn
1932 (end-of-line)
1933 (if (re-search-forward "^[^ \t]" nil t)
1934 (match-beginning 0)
1935 (point-max)))
1936 'boring-headers)))
1937 ;; Hide boring Newsgroups header.
1938 ((eq elem 'newsgroups)
1939 (when (gnus-string-equal
1940 (gnus-fetch-field "newsgroups")
1941 (gnus-group-real-name
1942 (if (boundp 'gnus-newsgroup-name)
1943 gnus-newsgroup-name
1944 "")))
1945 (gnus-article-hide-header "newsgroups")))
1946 ((eq elem 'to-address)
1947 (let ((to (message-fetch-field "to"))
1948 (to-address
1949 (gnus-parameter-to-address
1950 (if (boundp 'gnus-newsgroup-name)
1951 gnus-newsgroup-name ""))))
1952 (when (and to to-address
1953 (ignore-errors
1954 (gnus-string-equal
1955 ;; only one address in To
1956 (nth 1 (mail-extract-address-components to))
1957 to-address)))
1958 (gnus-article-hide-header "to"))))
1959 ((eq elem 'to-list)
1960 (let ((to (message-fetch-field "to"))
1961 (to-list
1962 (gnus-parameter-to-list
1963 (if (boundp 'gnus-newsgroup-name)
1964 gnus-newsgroup-name ""))))
1965 (when (and to to-list
1966 (ignore-errors
1967 (gnus-string-equal
1968 ;; only one address in To
1969 (nth 1 (mail-extract-address-components to))
1970 to-list)))
1971 (gnus-article-hide-header "to"))))
1972 ((eq elem 'cc-list)
1973 (let ((cc (message-fetch-field "cc"))
1974 (to-list
1975 (gnus-parameter-to-list
1976 (if (boundp 'gnus-newsgroup-name)
1977 gnus-newsgroup-name ""))))
1978 (when (and cc to-list
1979 (ignore-errors
1980 (gnus-string-equal
1981 ;; only one address in CC
1982 (nth 1 (mail-extract-address-components cc))
1983 to-list)))
1984 (gnus-article-hide-header "cc"))))
1985 ((eq elem 'followup-to)
1986 (when (gnus-string-equal
1987 (message-fetch-field "followup-to")
1988 (message-fetch-field "newsgroups"))
1989 (gnus-article-hide-header "followup-to")))
1990 ((eq elem 'reply-to)
1991 (if (gnus-group-find-parameter
1992 gnus-newsgroup-name 'broken-reply-to)
1993 (gnus-article-hide-header "reply-to")
1994 (let ((from (message-fetch-field "from"))
1995 (reply-to (message-fetch-field "reply-to")))
1996 (when
1997 (and
1998 from reply-to
1999 (ignore-errors
2000 (equal
2001 (sort (mapcar
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components from t))
2004 'string<)
2005 (sort (mapcar
2006 (lambda (x) (downcase (cadr x)))
2007 (mail-extract-address-components reply-to t))
2008 'string<))))
2009 (gnus-article-hide-header "reply-to")))))
2010 ((eq elem 'date)
2011 (let ((date (with-current-buffer gnus-original-article-buffer
2012 ;; If date in `gnus-article-buffer' is localized
2013 ;; (`gnus-treat-date-user-defined'),
2014 ;; `days-between' might fail.
2015 (message-fetch-field "date"))))
2016 (when (and date
2017 (< (days-between (current-time-string) date)
2019 (gnus-article-hide-header "date"))))
2020 ((eq elem 'long-to)
2021 (let ((to (message-fetch-field "to"))
2022 (cc (message-fetch-field "cc")))
2023 (when (> (length to) 1024)
2024 (gnus-article-hide-header "to"))
2025 (when (> (length cc) 1024)
2026 (gnus-article-hide-header "cc"))))
2027 ((eq elem 'many-to)
2028 (let ((to-count 0)
2029 (cc-count 0))
2030 (goto-char (point-min))
2031 (while (re-search-forward "^to:" nil t)
2032 (setq to-count (1+ to-count)))
2033 (when (> to-count 1)
2034 (while (> to-count 0)
2035 (goto-char (point-min))
2036 (save-restriction
2037 (re-search-forward "^to:" nil nil to-count)
2038 (forward-line -1)
2039 (narrow-to-region (point) (point-max))
2040 (gnus-article-hide-header "to"))
2041 (setq to-count (1- to-count))))
2042 (goto-char (point-min))
2043 (while (re-search-forward "^cc:" nil t)
2044 (setq cc-count (1+ cc-count)))
2045 (when (> cc-count 1)
2046 (while (> cc-count 0)
2047 (goto-char (point-min))
2048 (save-restriction
2049 (re-search-forward "^cc:" nil nil cc-count)
2050 (forward-line -1)
2051 (narrow-to-region (point) (point-max))
2052 (gnus-article-hide-header "cc"))
2053 (setq cc-count (1- cc-count)))))))))))))
2055 (defun gnus-article-hide-header (header)
2056 (save-excursion
2057 (goto-char (point-min))
2058 (when (re-search-forward (concat "^" header ":") nil t)
2059 (gnus-article-hide-text-type
2060 (point-at-bol)
2061 (progn
2062 (end-of-line)
2063 (if (re-search-forward "^[^ \t]" nil t)
2064 (match-beginning 0)
2065 (point-max)))
2066 'boring-headers))))
2068 (defvar gnus-article-normalized-header-length 40
2069 "Length of normalized headers.")
2071 (defun article-normalize-headers ()
2072 "Make all header lines 40 characters long."
2073 (interactive)
2074 (let ((inhibit-read-only t)
2075 column)
2076 (save-excursion
2077 (save-restriction
2078 (article-narrow-to-head)
2079 (while (not (eobp))
2080 (cond
2081 ((< (setq column (- (point-at-eol) (point)))
2082 gnus-article-normalized-header-length)
2083 (end-of-line)
2084 (insert (make-string
2085 (- gnus-article-normalized-header-length column)
2086 ? )))
2087 ((> column gnus-article-normalized-header-length)
2088 (gnus-put-text-property
2089 (progn
2090 (forward-char gnus-article-normalized-header-length)
2091 (point))
2092 (point-at-eol)
2093 'invisible t))
2095 ;; Do nothing.
2097 (forward-line 1))))))
2099 (defun article-treat-dumbquotes ()
2100 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2101 Note that this function guesses whether a character is a sm*rtq**t* or
2102 not, so it should only be used interactively.
2104 Sm*rtq**t*s are M****s***'s unilateral extension to the
2105 iso-8859-1 character map in an attempt to provide more quoting
2106 characters. If you see something like \\222 or \\264 where
2107 you're expecting some kind of apostrophe or quotation mark, then
2108 try this wash."
2109 (interactive)
2110 (article-translate-strings gnus-article-dumbquotes-map))
2112 (defvar org-entities)
2114 (defun article-treat-non-ascii ()
2115 "Translate many Unicode characters into their ASCII equivalents."
2116 (interactive)
2117 (require 'org-entities)
2118 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2119 (dolist (elem org-entities)
2120 (when (and (listp elem)
2121 (= (length (nth 6 elem)) 1))
2122 (if (featurep 'xemacs)
2123 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2124 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2125 (save-excursion
2126 (when (article-goto-body)
2127 (let ((inhibit-read-only t)
2128 replace props)
2129 (while (not (eobp))
2130 (if (not (setq replace (if (featurep 'xemacs)
2131 (get-char-table (following-char) table)
2132 (aref table (following-char)))))
2133 (forward-char 1)
2134 (if (prog1
2135 (setq props (text-properties-at (point)))
2136 (delete-char 1))
2137 (add-text-properties (point) (progn (insert replace) (point))
2138 props)
2139 (insert replace)))))))))
2141 (defun article-translate-strings (map)
2142 "Translate all string in the body of the article according to MAP.
2143 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2144 (save-excursion
2145 (when (article-goto-body)
2146 (let ((inhibit-read-only t))
2147 (dolist (elem map)
2148 (let ((from (car elem))
2149 (to (cadr elem)))
2150 (save-excursion
2151 (if (stringp from)
2152 (while (search-forward from nil t)
2153 (replace-match to))
2154 (while (not (eobp))
2155 (if (eq (following-char) from)
2156 (progn
2157 (delete-char 1)
2158 (insert to))
2159 (forward-char 1)))))))))))
2161 (defun article-treat-overstrike ()
2162 "Translate overstrikes into bold text."
2163 (interactive)
2164 (save-excursion
2165 (when (article-goto-body)
2166 (let ((inhibit-read-only t))
2167 (while (search-forward "\b" nil t)
2168 (let ((next (char-after))
2169 (previous (char-after (- (point) 2))))
2170 ;; We do the boldification/underlining by hiding the
2171 ;; overstrikes and putting the proper text property
2172 ;; on the letters.
2173 (cond
2174 ((eq next previous)
2175 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2176 (put-text-property (point) (1+ (point)) 'face 'bold))
2177 ((eq next ?_)
2178 (gnus-article-hide-text-type
2179 (1- (point)) (1+ (point)) 'overstrike)
2180 (put-text-property
2181 (- (point) 2) (1- (point)) 'face 'underline))
2182 ((eq previous ?_)
2183 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2184 (put-text-property
2185 (point) (1+ (point)) 'face 'underline)))))))))
2187 (defun article-treat-ansi-sequences ()
2188 "Translate ANSI SGR control sequences into overlays or extents."
2189 (interactive)
2190 (save-excursion
2191 (when (article-goto-body)
2192 (let ((inhibit-read-only t))
2193 (ansi-color-apply-on-region (point) (point-max))))))
2195 (defun gnus-article-treat-unfold-headers ()
2196 "Unfold folded message headers.
2197 Only the headers that fit into the current window width will be
2198 unfolded."
2199 (interactive)
2200 (gnus-with-article-headers
2201 (let (length)
2202 (while (not (eobp))
2203 (save-restriction
2204 (mail-header-narrow-to-field)
2205 (let* ((header (buffer-string))
2206 (unfoldable
2207 (or (equal gnus-article-unfold-long-headers t)
2208 (and (stringp gnus-article-unfold-long-headers)
2209 (string-match gnus-article-unfold-long-headers
2210 header)))))
2211 (with-temp-buffer
2212 (insert header)
2213 (goto-char (point-min))
2214 (while (re-search-forward "\n[\t ]" nil t)
2215 (replace-match " " t t)))
2216 (setq length (- (point-max) (point-min) 1))
2217 (when (or unfoldable
2218 (< length (window-width)))
2219 (while (re-search-forward "\n[\t ]" nil t)
2220 (replace-match " " t t))))
2221 (goto-char (point-max)))))))
2223 (defun gnus-article-treat-fold-headers ()
2224 "Fold message headers."
2225 (interactive)
2226 (gnus-with-article-headers
2227 (while (not (eobp))
2228 (save-restriction
2229 (mail-header-narrow-to-field)
2230 (mail-header-fold-field)
2231 (goto-char (point-max))))))
2233 (defun gnus-treat-smiley ()
2234 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2235 (interactive)
2236 (gnus-with-article-buffer
2237 (if (memq 'smiley gnus-article-wash-types)
2238 (gnus-delete-images 'smiley)
2239 (article-goto-body)
2240 (let ((images (smiley-region (point) (point-max))))
2241 (when images
2242 (gnus-add-wash-type 'smiley)
2243 (dolist (image images)
2244 (gnus-add-image 'smiley image)))))))
2246 (defun gnus-article-remove-images ()
2247 "Remove all images from the article buffer."
2248 (interactive)
2249 (gnus-with-article-buffer
2250 (save-restriction
2251 (widen)
2252 (dolist (elem gnus-article-image-alist)
2253 (gnus-delete-images (car elem))))))
2255 (autoload 'w3m-toggle-inline-images "w3m")
2257 (defun gnus-article-show-images ()
2258 "Show any images that are in the HTML-rendered article buffer.
2259 This only works if the article in question is HTML."
2260 (interactive)
2261 (gnus-with-article-buffer
2262 (save-restriction
2263 (widen)
2264 (if (eq mm-text-html-renderer 'w3m)
2265 (let ((mm-inline-text-html-with-images nil))
2266 (w3m-toggle-inline-images))
2267 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2268 'image-displayer))
2269 (destructuring-bind (start end function) region
2270 (funcall function (get-text-property start 'image-url)
2271 start end)))))))
2273 (defun gnus-article-treat-fold-newsgroups ()
2274 "Unfold folded message headers.
2275 Only the headers that fit into the current window width will be
2276 unfolded."
2277 (interactive)
2278 (gnus-with-article-headers
2279 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2280 (save-restriction
2281 (mail-header-narrow-to-field)
2282 (while (re-search-forward ", *" nil t)
2283 (replace-match ", " t t))
2284 (mail-header-fold-field)
2285 (goto-char (point-max))))))
2287 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2288 "Value of `truncate-lines' in Gnus Article buffer.
2289 Valid values are nil, t, `head', `first', `last', an integer or a
2290 predicate. See Info node `(gnus)Customizing Articles'."
2291 :version "23.1" ;; No Gnus
2292 :group 'gnus-article
2293 ;; :link '(custom-manual "(gnus)Customizing Articles")
2294 :type 'boolean)
2296 (defun gnus-article-toggle-truncate-lines (&optional arg)
2297 "Toggle whether to fold or truncate long lines in article the buffer.
2298 If ARG is non-nil and not a number, toggle
2299 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2300 long lines if and only if arg is positive."
2301 (interactive "P")
2302 (cond
2303 ((and (numberp arg) (> arg 0))
2304 (setq gnus-article-truncate-lines t))
2305 ((numberp arg)
2306 (setq gnus-article-truncate-lines nil))
2307 (arg
2308 (setq gnus-article-truncate-lines
2309 (not gnus-article-truncate-lines))))
2310 (gnus-with-article-buffer
2311 (cond
2312 ((and (numberp arg) (> arg 0))
2313 (setq truncate-lines nil))
2314 ((numberp arg)
2315 (setq truncate-lines t)))
2316 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2317 ;; `toggle-truncate-lines' needs an argument.
2318 (toggle-truncate-lines)))
2320 (defun gnus-article-treat-body-boundary ()
2321 "Place a boundary line at the end of the headers."
2322 (interactive)
2323 (when (and gnus-body-boundary-delimiter
2324 (> (length gnus-body-boundary-delimiter) 0))
2325 (gnus-with-article-headers
2326 (goto-char (point-max))
2327 (let ((start (point)))
2328 (insert "X-Boundary: ")
2329 (gnus-add-text-properties start (point) '(invisible t intangible t))
2330 (insert (let (str (max (window-width)))
2331 (if (featurep 'xemacs)
2332 (setq max (1- max)))
2333 (while (>= max (length str))
2334 (setq str (concat str gnus-body-boundary-delimiter)))
2335 (substring str 0 max))
2336 "\n")
2337 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2339 (defun article-fill-long-lines ()
2340 "Fill lines that are wider than the window width."
2341 (interactive)
2342 (save-excursion
2343 (let ((inhibit-read-only t)
2344 (width (window-width (get-buffer-window (current-buffer)))))
2345 (save-restriction
2346 (article-goto-body)
2347 (let ((adaptive-fill-mode nil)) ;Why? -sm
2348 (while (not (eobp))
2349 (end-of-line)
2350 (when (>= (current-column) (min fill-column width))
2351 (narrow-to-region (min (1+ (point)) (point-max))
2352 (point-at-bol))
2353 (let ((goback (point-marker)))
2354 (fill-paragraph nil)
2355 (goto-char (marker-position goback)))
2356 (widen))
2357 (forward-line 1)))))))
2359 (defun article-capitalize-sentences ()
2360 "Capitalize the first word in each sentence."
2361 (interactive)
2362 (save-excursion
2363 (let ((inhibit-read-only t)
2364 (paragraph-start "^[\n\^L]"))
2365 (article-goto-body)
2366 (while (not (eobp))
2367 (capitalize-word 1)
2368 (forward-sentence)))))
2370 (defun article-remove-cr ()
2371 "Remove trailing CRs and then translate remaining CRs into LFs."
2372 (interactive)
2373 (save-excursion
2374 (let ((inhibit-read-only t))
2375 (goto-char (point-min))
2376 (while (re-search-forward "\r+$" nil t)
2377 (replace-match "" t t))
2378 (goto-char (point-min))
2379 (while (search-forward "\r" nil t)
2380 (replace-match "\n" t t)))))
2382 (defun article-remove-trailing-blank-lines ()
2383 "Remove all trailing blank lines from the article."
2384 (interactive)
2385 (save-excursion
2386 (let ((inhibit-read-only t))
2387 (goto-char (point-max))
2388 (delete-region
2389 (point)
2390 (progn
2391 (while (and (not (bobp))
2392 (looking-at "^[ \t]*$")
2393 (not (gnus-annotation-in-region-p
2394 (point) (point-at-eol))))
2395 (forward-line -1))
2396 (forward-line 1)
2397 (point))))))
2399 (defvar gnus-face-properties-alist)
2401 (defun article-display-face (&optional force)
2402 "Display any Face headers in the header."
2403 (interactive (list 'force))
2404 (let ((wash-face-p buffer-read-only))
2405 (gnus-with-article-headers
2406 ;; When displaying parts, this function can be called several times on
2407 ;; the same article, without any intended toggle semantic (as typing `W
2408 ;; D d' would have). So face deletion must occur only when we come from
2409 ;; an interactive command, that is when the *Article* buffer is
2410 ;; read-only.
2411 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2412 (gnus-delete-images 'face)
2413 (let ((from (message-fetch-field "from"))
2414 face faces)
2415 (save-current-buffer
2416 (when (and wash-face-p
2417 (gnus-buffer-live-p gnus-original-article-buffer)
2418 (not (re-search-forward "^Face:[\t ]*" nil t)))
2419 (set-buffer gnus-original-article-buffer))
2420 (save-restriction
2421 (mail-narrow-to-head)
2422 (when (or force
2423 ;; Check whether this face is censored.
2424 (not (and gnus-article-x-face-too-ugly
2425 (or from
2426 (setq from (message-fetch-field "from")))
2427 (string-match gnus-article-x-face-too-ugly
2428 from))))
2429 (while (gnus-article-goto-header "Face")
2430 (push (mail-header-field-value) faces)))))
2431 (when faces
2432 (goto-char (point-min))
2433 (let (png image)
2434 (unless (setq from (gnus-article-goto-header "from"))
2435 (insert "From:")
2436 (setq from (point))
2437 (insert " [no `from' set]\n"))
2438 (while faces
2439 (when (setq png (gnus-convert-face-to-png (pop faces)))
2440 (setq image
2441 (apply 'gnus-create-image png 'png t
2442 (cdr (assq 'png gnus-face-properties-alist))))
2443 (goto-char from)
2444 (when image
2445 (gnus-add-wash-type 'face)
2446 (gnus-add-image 'face image)
2447 (gnus-put-image image nil 'face)))))))))))
2449 (defun article-display-x-face (&optional force)
2450 "Look for an X-Face header and display it if present."
2451 (interactive (list 'force))
2452 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2453 (gnus-with-article-headers
2454 ;; Delete the old process, if any.
2455 (when (process-status "article-x-face")
2456 (delete-process "article-x-face"))
2457 ;; See the comment in `article-display-face'.
2458 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2459 ;; We have already displayed X-Faces, so we remove them
2460 ;; instead.
2461 (gnus-delete-images 'xface)
2462 ;; Display X-Faces.
2463 (let ((from (message-fetch-field "from"))
2464 x-faces face)
2465 (save-current-buffer
2466 (when (and wash-face-p
2467 (gnus-buffer-live-p gnus-original-article-buffer)
2468 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2469 ;; If type `W f', use gnus-original-article-buffer,
2470 ;; otherwise use the current buffer because displaying
2471 ;; RFC822 parts calls this function too.
2472 (set-buffer gnus-original-article-buffer))
2473 (save-restriction
2474 (mail-narrow-to-head)
2475 (and gnus-article-x-face-command
2476 (or force
2477 ;; Check whether this face is censored.
2478 (not (and gnus-article-x-face-too-ugly
2479 (or from
2480 (setq from (message-fetch-field "from")))
2481 (string-match gnus-article-x-face-too-ugly
2482 from))))
2483 (while (gnus-article-goto-header "X-Face")
2484 (push (mail-header-field-value) x-faces)))))
2485 (when x-faces
2486 ;; We display the face.
2487 (cond ((functionp gnus-article-x-face-command)
2488 ;; The command is a lisp function, so we call it.
2489 (mapc gnus-article-x-face-command x-faces))
2490 ((stringp gnus-article-x-face-command)
2491 ;; The command is a string, so we interpret the command
2492 ;; as a, well, command, and fork it off.
2493 (let ((process-connection-type nil))
2494 (gnus-set-process-query-on-exit-flag
2495 (start-process
2496 "article-x-face" nil shell-file-name
2497 shell-command-switch gnus-article-x-face-command)
2498 nil)
2499 ;; Sending multiple EOFs to xv doesn't work,
2500 ;; so we only do a single external face.
2501 (with-temp-buffer
2502 (insert (car x-faces))
2503 (process-send-region "article-x-face"
2504 (point-min) (point-max)))
2505 (process-send-eof "article-x-face")))
2507 (error "`%s' set to `%s' is not a function"
2508 gnus-article-x-face-command
2509 'gnus-article-x-face-command)))))))))
2511 (defun article-decode-mime-words ()
2512 "Decode all MIME-encoded words in the article."
2513 (interactive)
2514 (gnus-with-article-buffer
2515 (let ((inhibit-point-motion-hooks t)
2516 (mail-parse-charset gnus-newsgroup-charset)
2517 (mail-parse-ignored-charsets
2518 (with-current-buffer gnus-summary-buffer
2519 gnus-newsgroup-ignored-charsets)))
2520 (mail-decode-encoded-word-region (point-min) (point-max)))))
2522 (defun article-decode-charset (&optional prompt)
2523 "Decode charset-encoded text in the article.
2524 If PROMPT (the prefix), prompt for a coding system to use."
2525 (interactive "P")
2526 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2527 (inhibit-read-only t)
2528 (mail-parse-charset gnus-newsgroup-charset)
2529 (mail-parse-ignored-charsets
2530 (save-excursion (condition-case nil
2531 (set-buffer gnus-summary-buffer)
2532 (error))
2533 gnus-newsgroup-ignored-charsets))
2534 ct cte ctl charset format)
2535 (save-excursion
2536 (save-restriction
2537 (article-narrow-to-head)
2538 (setq ct (message-fetch-field "Content-Type" t)
2539 cte (message-fetch-field "Content-Transfer-Encoding" t)
2540 ctl (and ct (mail-header-parse-content-type ct))
2541 charset (cond
2542 (prompt
2543 (mm-read-coding-system "Charset to decode: "))
2544 (ctl
2545 (mail-content-type-get ctl 'charset)))
2546 format (and ctl (mail-content-type-get ctl 'format)))
2547 (when cte
2548 (setq cte (mail-header-strip cte)))
2549 (if (and ctl (not (string-match "/" (car ctl))))
2550 (setq ctl nil))
2551 (goto-char (point-max)))
2552 (forward-line 1)
2553 (save-restriction
2554 (narrow-to-region (point) (point-max))
2555 (when (and (eq mail-parse-charset 'gnus-decoded)
2556 (eq (mm-body-7-or-8) '8bit))
2557 ;; The text code could have been decoded.
2558 (setq charset mail-parse-charset))
2559 (when (and (or (not ctl)
2560 (equal (car ctl) "text/plain"))
2561 (not format)) ;; article with format will decode later.
2562 (mm-decode-body
2563 charset (and cte (intern (downcase
2564 (gnus-strip-whitespace cte))))
2565 (car ctl)))))))
2567 (defun article-decode-encoded-words ()
2568 "Remove encoded-word encoding from headers."
2569 (let ((inhibit-point-motion-hooks t)
2570 (mail-parse-charset gnus-newsgroup-charset)
2571 (mail-parse-ignored-charsets
2572 (save-excursion (condition-case nil
2573 (set-buffer gnus-summary-buffer)
2574 (error))
2575 gnus-newsgroup-ignored-charsets))
2576 (inhibit-read-only t)
2577 end start)
2578 (goto-char (point-min))
2579 (when (search-forward "\n\n" nil 'move)
2580 (forward-line -1))
2581 (setq end (point))
2582 (while (not (bobp))
2583 (while (progn
2584 (forward-line -1)
2585 (and (not (bobp))
2586 (memq (char-after) '(?\t ? )))))
2587 (setq start (point))
2588 (if (looking-at "\
2589 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2590 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2591 (funcall gnus-decode-address-function start end)
2592 (funcall gnus-decode-header-function start end))
2593 (goto-char (setq end start)))))
2595 (defun article-decode-group-name ()
2596 "Decode group names in Newsgroups, Followup-To and Xref headers."
2597 (let ((inhibit-point-motion-hooks t)
2598 (inhibit-read-only t)
2599 (method (gnus-find-method-for-group gnus-newsgroup-name))
2600 regexp)
2601 (when (and (or gnus-group-name-charset-method-alist
2602 gnus-group-name-charset-group-alist)
2603 (gnus-buffer-live-p gnus-original-article-buffer))
2604 (save-restriction
2605 (article-narrow-to-head)
2606 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2607 (with-current-buffer gnus-original-article-buffer
2608 (goto-char (point-min)))
2609 (setq regexp (concat "^" header
2610 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2611 (while (re-search-forward regexp nil t)
2612 (replace-match (save-match-data
2613 (gnus-decode-newsgroups
2614 ;; XXX how to use data in article buffer?
2615 (with-current-buffer gnus-original-article-buffer
2616 (re-search-forward regexp nil t)
2617 (match-string 1))
2618 gnus-newsgroup-name method))
2619 t t nil 1))
2620 (goto-char (point-min)))))))
2622 (autoload 'idna-to-unicode "idna")
2624 (defun article-decode-idna-rhs ()
2625 "Decode IDNA strings in RHS in various headers in current buffer.
2626 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2627 Mail-Reply-To: and Mail-Followup-To:."
2628 (when gnus-use-idna
2629 (save-restriction
2630 (let ((inhibit-point-motion-hooks t)
2631 (inhibit-read-only t))
2632 (article-narrow-to-head)
2633 (goto-char (point-min))
2634 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2635 (let (ace unicode)
2636 (when (save-match-data
2637 (and (setq ace (match-string 1))
2638 (save-excursion
2639 (and (re-search-backward "^[^ \t]" nil t)
2640 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2641 (setq unicode (idna-to-unicode ace))))
2642 (unless (string= ace unicode)
2643 (replace-match unicode nil nil nil 1)))))))))
2645 (defun article-de-quoted-unreadable (&optional force read-charset)
2646 "Translate a quoted-printable-encoded article.
2647 If FORCE, decode the article whether it is marked as quoted-printable
2648 or not.
2649 If READ-CHARSET, ask for a coding system."
2650 (interactive (list 'force current-prefix-arg))
2651 (save-excursion
2652 (let ((inhibit-read-only t) type charset)
2653 (if (gnus-buffer-live-p gnus-original-article-buffer)
2654 (with-current-buffer gnus-original-article-buffer
2655 (setq type
2656 (gnus-fetch-field "content-transfer-encoding"))
2657 (let* ((ct (gnus-fetch-field "content-type"))
2658 (ctl (and ct (mail-header-parse-content-type ct))))
2659 (setq charset (and ctl
2660 (mail-content-type-get ctl 'charset)))
2661 (if (stringp charset)
2662 (setq charset (intern (downcase charset)))))))
2663 (if read-charset
2664 (setq charset (mm-read-coding-system "Charset: " charset)))
2665 (unless charset
2666 (setq charset gnus-newsgroup-charset))
2667 (when (or force
2668 (and type (let ((case-fold-search t))
2669 (string-match "quoted-printable" type))))
2670 (article-goto-body)
2671 (quoted-printable-decode-region
2672 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2674 (defun article-de-base64-unreadable (&optional force read-charset)
2675 "Translate a base64 article.
2676 If FORCE, decode the article whether it is marked as base64 not.
2677 If READ-CHARSET, ask for a coding system."
2678 (interactive (list 'force current-prefix-arg))
2679 (save-excursion
2680 (let ((inhibit-read-only t) type charset)
2681 (if (gnus-buffer-live-p gnus-original-article-buffer)
2682 (with-current-buffer gnus-original-article-buffer
2683 (setq type
2684 (gnus-fetch-field "content-transfer-encoding"))
2685 (let* ((ct (gnus-fetch-field "content-type"))
2686 (ctl (and ct (mail-header-parse-content-type ct))))
2687 (setq charset (and ctl
2688 (mail-content-type-get ctl 'charset)))
2689 (if (stringp charset)
2690 (setq charset (intern (downcase charset)))))))
2691 (if read-charset
2692 (setq charset (mm-read-coding-system "Charset: " charset)))
2693 (unless charset
2694 (setq charset gnus-newsgroup-charset))
2695 (when (or force
2696 (and type (let ((case-fold-search t))
2697 (string-match "base64" type))))
2698 (article-goto-body)
2699 (save-restriction
2700 (narrow-to-region (point) (point-max))
2701 (base64-decode-region (point-min) (point-max))
2702 (mm-decode-coding-region
2703 (point-min) (point-max)
2704 (mm-charset-to-coding-system charset nil t)))))))
2706 (eval-when-compile
2707 (require 'rfc1843))
2709 (defun article-decode-HZ ()
2710 "Translate a HZ-encoded article."
2711 (interactive)
2712 (require 'rfc1843)
2713 (save-excursion
2714 (let ((inhibit-read-only t))
2715 (rfc1843-decode-region (point-min) (point-max)))))
2717 (defun article-unsplit-urls ()
2718 "Remove the newlines that some other mailers insert into URLs."
2719 (interactive)
2720 (save-excursion
2721 (let ((inhibit-read-only t))
2722 (goto-char (point-min))
2723 (while (re-search-forward
2724 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2725 (replace-match "\\1\\3" t)))
2726 (when (gmm-called-interactively-p 'any)
2727 (gnus-treat-article nil))))
2729 (defun article-wash-html ()
2730 "Format an HTML article."
2731 (interactive)
2732 (let ((handles nil)
2733 (buffer-read-only nil))
2734 (when (gnus-buffer-live-p gnus-original-article-buffer)
2735 (with-current-buffer gnus-original-article-buffer
2736 (setq handles (mm-dissect-buffer t t))))
2737 (article-goto-body)
2738 (delete-region (point) (point-max))
2739 (mm-enable-multibyte)
2740 (mm-inline-text-html handles)))
2742 (defvar gnus-article-browse-html-temp-list nil
2743 "List of temporary files created by `gnus-article-browse-html-parts'.
2744 Internal variable.")
2746 (defcustom gnus-article-browse-delete-temp 'ask
2747 "What to do with temporary files from `gnus-article-browse-html-parts'.
2748 If nil, don't delete temporary files. If it is t, delete them on
2749 exit from the summary buffer. If it is the symbol `file', query
2750 on each file, if it is `ask' ask once when exiting from the
2751 summary buffer."
2752 :group 'gnus-article
2753 :version "23.1" ;; No Gnus
2754 :type '(choice (const :tag "Don't delete" nil)
2755 (const :tag "Don't ask" t)
2756 (const :tag "Ask" ask)
2757 (const :tag "Ask for each file" file)))
2759 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2761 (defun gnus-article-browse-delete-temp-files (&optional how)
2762 "Delete temp-files created by `gnus-article-browse-html-parts'."
2763 (when (and gnus-article-browse-html-temp-list
2764 (progn
2765 (or how (setq how gnus-article-browse-delete-temp))
2766 (if (eq how 'ask)
2767 (let ((files (length gnus-article-browse-html-temp-list)))
2768 (or (gnus-y-or-n-p
2769 (if (= files 1)
2770 "Delete the temporary HTML file? "
2771 (format "Delete all %s temporary HTML files? "
2772 files)))
2773 (setq gnus-article-browse-html-temp-list nil)))
2774 how)))
2775 (dolist (file gnus-article-browse-html-temp-list)
2776 (cond ((file-directory-p file)
2777 (when (or (not (eq how 'file))
2778 (gnus-y-or-n-p
2779 (format
2780 "Delete temporary HTML file(s) in directory `%s'? "
2781 (file-name-as-directory file))))
2782 (gnus-delete-directory file)))
2783 ((file-exists-p file)
2784 (when (or (not (eq how 'file))
2785 (gnus-y-or-n-p
2786 (format "Delete temporary HTML file `%s'? " file)))
2787 (delete-file file)))))
2788 ;; Also remove file from the list when not deleted or if file doesn't
2789 ;; exist anymore.
2790 (setq gnus-article-browse-html-temp-list nil))
2791 gnus-article-browse-html-temp-list)
2793 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2794 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2795 Return file name."
2796 (save-match-data
2797 (let (file type)
2798 (catch 'found
2799 (dolist (handle handles)
2800 (cond
2801 ((not (listp handle)))
2802 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2803 ;; may create.
2804 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2805 ((equal (mm-handle-media-supertype handle) "multipart")
2806 (when (setq file (gnus-article-browse-html-save-cid-content
2807 cid handle directory))
2808 (throw 'found file)))
2809 ((equal (concat "<" cid ">") (mm-handle-id handle))
2810 (setq file
2811 (expand-file-name
2812 (or (mm-handle-filename handle)
2813 (concat
2814 (make-temp-name "cid")
2815 (car (rassoc (car (mm-handle-type handle))
2816 mailcap-mime-extensions))))
2817 directory))
2818 (mm-save-part-to-file handle file)
2819 (throw 'found file))))))))
2821 (defun gnus-article-browse-html-parts (list &optional header)
2822 "View all \"text/html\" parts from LIST.
2823 Recurse into multiparts. The optional HEADER that should be a decoded
2824 message header will be added to the bodies of the \"text/html\" parts."
2825 ;; Internal function used by `gnus-article-browse-html-article'.
2826 (let (type file charset content cid-dir tmp-file showed)
2827 ;; Find and show the html-parts.
2828 (dolist (handle list)
2829 ;; If HTML, show it:
2830 (cond ((not (listp handle)))
2831 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2832 (and (equal (car type) "message/external-body")
2833 (or header
2834 (setq file (mm-handle-filename handle)))
2835 (or (mm-handle-cache handle)
2836 (condition-case code
2837 (progn (mm-extern-cache-contents handle) t)
2838 (error
2839 (gnus-message 3 "%s" (error-message-string code))
2840 (when (>= gnus-verbose 3) (sit-for 2))
2841 nil)))
2842 (progn
2843 (setq handle (mm-handle-cache handle)
2844 type (mm-handle-type handle))
2845 (equal (car type) "text/html"))))
2846 (setq charset (mail-content-type-get type 'charset)
2847 content (mm-get-part handle))
2848 (with-temp-buffer
2849 (if (eq charset 'gnus-decoded)
2850 (mm-enable-multibyte)
2851 (mm-disable-multibyte))
2852 (insert content)
2853 ;; resolve cid contents
2854 (let ((case-fold-search t)
2855 cid-file)
2856 (goto-char (point-min))
2857 (while (re-search-forward "\
2858 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2859 nil t)
2860 (unless cid-dir
2861 (setq cid-dir (mm-make-temp-file "cid" t))
2862 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2863 (setq file nil
2864 content nil)
2865 (when (setq cid-file
2866 (gnus-article-browse-html-save-cid-content
2867 (match-string 2)
2868 (with-current-buffer gnus-article-buffer
2869 gnus-article-mime-handles)
2870 cid-dir))
2871 (when (eq system-type 'cygwin)
2872 (setq cid-file
2873 (concat "/" (substring
2874 (with-output-to-string
2875 (call-process "cygpath" nil
2876 standard-output
2877 nil "-m" cid-file))
2878 0 -1))))
2879 (replace-match (concat "file://" cid-file)
2880 nil nil nil 1))))
2881 (unless content (setq content (buffer-string))))
2882 (when (or charset header (not file))
2883 (setq tmp-file (mm-make-temp-file
2884 ;; Do we need to care for 8.3 filenames?
2885 "mm-" nil ".html")))
2886 ;; Add a meta html tag to specify charset and a header.
2887 (cond
2888 (header
2889 (let (title eheader body hcharset coding)
2890 (with-temp-buffer
2891 (mm-enable-multibyte)
2892 (setq case-fold-search t)
2893 (insert header "\n")
2894 (setq title (message-fetch-field "subject"))
2895 (goto-char (point-min))
2896 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2897 nil t)
2898 (replace-match (cond ((match-beginning 1) "&lt;")
2899 ((match-beginning 2) "&gt;")
2900 ((match-beginning 3) "&amp;")
2901 (t "<br>\n"))))
2902 (goto-char (point-min))
2903 (while (re-search-forward "^[\t ]+" nil t)
2904 (dotimes (i (prog1
2905 (current-column)
2906 (delete-region (match-beginning 0)
2907 (match-end 0))))
2908 (insert "&nbsp;")))
2909 (goto-char (point-min))
2910 (insert "<div align=\"left\">\n")
2911 (goto-char (point-max))
2912 (insert "</div>\n<hr>\n")
2913 ;; We have to examine charset one by one since
2914 ;; charset specified in parts might be different.
2915 (if (eq charset 'gnus-decoded)
2916 (setq charset 'utf-8
2917 eheader (mm-encode-coding-string (buffer-string)
2918 charset)
2919 title (when title
2920 (mm-encode-coding-string title charset))
2921 body (mm-encode-coding-string content charset))
2922 (setq hcharset (mm-find-mime-charset-region (point-min)
2923 (point-max)))
2924 (cond ((= (length hcharset) 1)
2925 (setq hcharset (car hcharset)
2926 coding (mm-charset-to-coding-system
2927 hcharset nil t)))
2928 ((> (length hcharset) 1)
2929 (setq hcharset 'utf-8
2930 coding hcharset)))
2931 (if coding
2932 (if charset
2933 (progn
2934 (setq body
2935 (mm-charset-to-coding-system charset
2936 nil t))
2937 (if (eq coding body)
2938 (setq eheader (mm-encode-coding-string
2939 (buffer-string) coding)
2940 title (when title
2941 (mm-encode-coding-string
2942 title coding))
2943 body content)
2944 (setq charset 'utf-8
2945 eheader (mm-encode-coding-string
2946 (buffer-string) charset)
2947 title (when title
2948 (mm-encode-coding-string
2949 title charset))
2950 body (mm-encode-coding-string
2951 (mm-decode-coding-string
2952 content body)
2953 charset))))
2954 (setq charset hcharset
2955 eheader (mm-encode-coding-string
2956 (buffer-string) coding)
2957 title (when title
2958 (mm-encode-coding-string
2959 title coding))
2960 body content))
2961 (setq eheader (mm-string-as-unibyte (buffer-string))
2962 body content)))
2963 (erase-buffer)
2964 (mm-disable-multibyte)
2965 (insert body)
2966 (when charset
2967 (mm-add-meta-html-tag handle charset t))
2968 (when title
2969 (goto-char (point-min))
2970 (unless (search-forward "<title>" nil t)
2971 (re-search-forward "<head>\\s-*" nil t)
2972 (insert "<title>" title "</title>\n")))
2973 (goto-char (point-min))
2974 (or (re-search-forward
2975 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2976 (re-search-forward
2977 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2978 (insert eheader)
2979 (mm-write-region (point-min) (point-max)
2980 tmp-file nil nil nil 'binary t))))
2981 (charset
2982 (mm-with-unibyte-buffer
2983 (insert (if (eq charset 'gnus-decoded)
2984 (mm-encode-coding-string content
2985 (setq charset 'utf-8))
2986 content))
2987 (if (or (mm-add-meta-html-tag handle charset)
2988 (not file))
2989 (mm-write-region (point-min) (point-max)
2990 tmp-file nil nil nil 'binary t)
2991 (setq tmp-file nil))))
2992 (tmp-file
2993 (mm-save-part-to-file handle tmp-file)))
2994 (when tmp-file
2995 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2996 (add-hook 'gnus-summary-prepare-exit-hook
2997 'gnus-article-browse-delete-temp-files)
2998 (add-hook 'gnus-exit-gnus-hook
2999 (lambda ()
3000 (gnus-article-browse-delete-temp-files t)))
3001 ;; FIXME: Warn if there's an <img> tag?
3002 (browse-url-of-file (or tmp-file (expand-file-name file)))
3003 (setq showed t))
3004 ;; If multipart, recurse
3005 ((equal (mm-handle-media-supertype handle) "multipart")
3006 (when (gnus-article-browse-html-parts handle header)
3007 (setq showed t)))
3008 ((equal (mm-handle-media-type handle) "message/rfc822")
3009 (mm-with-multibyte-buffer
3010 (mm-insert-part handle)
3011 (setq handle (mm-dissect-buffer t t))
3012 (when (and (bufferp (car handle))
3013 (stringp (car (mm-handle-type handle))))
3014 (setq handle (list handle)))
3015 (when header
3016 (article-decode-encoded-words)
3017 (let ((gnus-visible-headers
3018 (or (get 'gnus-visible-headers 'standard-value)
3019 gnus-visible-headers)))
3020 (article-hide-headers))
3021 (goto-char (point-min))
3022 (search-forward "\n\n" nil 'move)
3023 (skip-chars-backward "\t\n ")
3024 (setq header (buffer-substring (point-min) (point)))))
3025 (when (prog1
3026 (gnus-article-browse-html-parts handle header)
3027 (mm-destroy-parts handle))
3028 (setq showed t)))))
3029 showed))
3031 (defun gnus-article-browse-html-article (&optional arg)
3032 "View \"text/html\" parts of the current article with a WWW browser.
3033 Inline images embedded in a message using the cid scheme, as they are
3034 generally considered to be safe, will be processed properly.
3035 The message header is added to the beginning of every html part unless
3036 the prefix argument ARG is given.
3038 Warning: Spammers use links to images (using the http scheme) in HTML
3039 articles to verify whether you have read the message. As
3040 `gnus-article-browse-html-article' passes the HTML content to the
3041 browser without eliminating these \"web bugs\" you should only
3042 use it for mails from trusted senders.
3044 If you always want to display HTML parts in the browser, set
3045 `mm-text-html-renderer' to nil.
3047 This command creates temporary files to pass HTML contents including
3048 images if any to the browser, and deletes them when exiting the group
3049 \(if you want)."
3050 ;; Cf. `mm-w3m-safe-url-regexp'
3051 (interactive "P")
3052 (if arg
3053 (gnus-summary-show-article)
3054 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3055 gnus-visible-headers))
3056 ;; As we insert a <hr>, there's no need for the body boundary.
3057 (gnus-treat-body-boundary nil))
3058 (gnus-summary-show-article)))
3059 (with-current-buffer gnus-article-buffer
3060 (let ((header (unless arg
3061 (save-restriction
3062 (widen)
3063 (buffer-substring-no-properties
3064 (goto-char (point-min))
3065 (if (search-forward "\n\n" nil t)
3066 (match-beginning 0)
3067 (goto-char (point-max))
3068 (skip-chars-backward "\t\n ")
3069 (point))))))
3070 parts)
3071 (set-buffer gnus-original-article-buffer)
3072 (setq parts (mm-dissect-buffer t t))
3073 ;; If singlepart, enforce a list.
3074 (when (and (bufferp (car parts))
3075 (stringp (car (mm-handle-type parts))))
3076 (setq parts (list parts)))
3077 ;; Process the list
3078 (unless (gnus-article-browse-html-parts parts header)
3079 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3080 (mm-destroy-parts parts)
3081 (unless arg
3082 (gnus-summary-show-article)))))
3084 (defun article-hide-list-identifiers ()
3085 "Remove list identifiers from the Subject header.
3086 The `gnus-list-identifiers' variable specifies what to do."
3087 (interactive)
3088 (let ((inhibit-point-motion-hooks t)
3089 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3090 (inhibit-read-only t))
3091 (when regexp
3092 (save-excursion
3093 (save-restriction
3094 (article-narrow-to-head)
3095 (goto-char (point-min))
3096 (while (re-search-forward
3097 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3098 nil t)
3099 (delete-region (match-beginning 2) (match-end 0))
3100 (beginning-of-line))
3101 (when (re-search-forward
3102 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3103 (delete-region (match-beginning 1) (match-end 1))))))))
3105 (defun article-hide-pem (&optional arg)
3106 "Toggle hiding of any PEM headers and signatures in the current article.
3107 If given a negative prefix, always show; if given a positive prefix,
3108 always hide."
3109 (interactive (gnus-article-hidden-arg))
3110 (unless (gnus-article-check-hidden-text 'pem arg)
3111 (save-excursion
3112 (let ((inhibit-read-only t) end)
3113 (goto-char (point-min))
3114 ;; Hide the horrendously ugly "header".
3115 (when (and (search-forward
3116 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3117 nil t)
3118 (setq end (1+ (match-beginning 0))))
3119 (gnus-add-wash-type 'pem)
3120 (gnus-article-hide-text-type
3122 (if (search-forward "\n\n" nil t)
3123 (match-end 0)
3124 (point-max))
3125 'pem)
3126 ;; Hide the trailer as well
3127 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3128 nil t)
3129 (gnus-article-hide-text-type
3130 (match-beginning 0) (match-end 0) 'pem)))))))
3132 (defun article-strip-banner ()
3133 "Strip the banners specified by the `banner' group parameter and by
3134 `gnus-article-address-banner-alist'."
3135 (interactive)
3136 (save-excursion
3137 (save-restriction
3138 (let ((inhibit-point-motion-hooks t))
3139 (when (gnus-parameter-banner gnus-newsgroup-name)
3140 (article-really-strip-banner
3141 (gnus-parameter-banner gnus-newsgroup-name)))
3142 (when gnus-article-address-banner-alist
3143 ;; Note that the From header is decoded here, so it is
3144 ;; required that the *-extract-address-components function
3145 ;; supports non-ASCII text.
3146 (let ((from (save-restriction
3147 (widen)
3148 (article-narrow-to-head)
3149 (mail-fetch-field "from"))))
3150 (when (and from
3151 (setq from
3152 (cadr (funcall gnus-extract-address-components
3153 from))))
3154 (catch 'found
3155 (dolist (pair gnus-article-address-banner-alist)
3156 (when (string-match (car pair) from)
3157 (throw 'found
3158 (article-really-strip-banner (cdr pair)))))))))))))
3160 (defun article-really-strip-banner (banner)
3161 "Strip the banner specified by the argument."
3162 (save-excursion
3163 (save-restriction
3164 (let ((inhibit-point-motion-hooks t)
3165 (gnus-signature-limit nil)
3166 (inhibit-read-only t))
3167 (article-goto-body)
3168 (cond
3169 ((eq banner 'signature)
3170 (when (gnus-article-narrow-to-signature)
3171 (widen)
3172 (forward-line -1)
3173 (delete-region (point) (point-max))))
3174 ((symbolp banner)
3175 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3176 (while (re-search-forward banner nil t)
3177 (delete-region (match-beginning 0) (match-end 0)))))
3178 ((stringp banner)
3179 (while (re-search-forward banner nil t)
3180 (delete-region (match-beginning 0) (match-end 0)))))))))
3182 (defun article-babel ()
3183 "Translate article using an online translation service."
3184 (interactive)
3185 (require 'babel)
3186 (gnus-with-article-buffer
3187 (when (article-goto-body)
3188 (let* ((start (point))
3189 (end (point-max))
3190 (orig (buffer-substring start end))
3191 (trans (babel-as-string orig)))
3192 (save-restriction
3193 (narrow-to-region start end)
3194 (delete-region start end)
3195 (insert trans))))))
3197 (defun article-hide-signature (&optional arg)
3198 "Hide the signature in the current article.
3199 If given a negative prefix, always show; if given a positive prefix,
3200 always hide."
3201 (interactive (gnus-article-hidden-arg))
3202 (unless (gnus-article-check-hidden-text 'signature arg)
3203 (save-excursion
3204 (save-restriction
3205 (let ((inhibit-read-only t))
3206 (when (gnus-article-narrow-to-signature)
3207 (gnus-article-hide-text-type
3208 (point-min) (point-max) 'signature))))))
3209 (gnus-set-mode-line 'article))
3211 (defun article-strip-headers-in-body ()
3212 "Strip offensive headers from bodies."
3213 (interactive)
3214 (save-excursion
3215 (article-goto-body)
3216 (let ((case-fold-search t))
3217 (when (looking-at "x-no-archive:")
3218 (gnus-delete-line)))))
3220 (defun article-strip-leading-blank-lines ()
3221 "Remove all blank lines from the beginning of the article."
3222 (interactive)
3223 (save-excursion
3224 (let ((inhibit-point-motion-hooks t)
3225 (inhibit-read-only t))
3226 (when (article-goto-body)
3227 (while (and (not (eobp))
3228 (looking-at "[ \t]*$"))
3229 (gnus-delete-line))))))
3231 (defun article-narrow-to-head ()
3232 "Narrow the buffer to the head of the message.
3233 Point is left at the beginning of the narrowed-to region."
3234 (narrow-to-region
3235 (goto-char (point-min))
3236 (cond
3237 ;; Absolutely no headers displayed.
3238 ((looking-at "\n")
3239 (point))
3240 ;; Normal headers.
3241 ((search-forward "\n\n" nil 1)
3242 (1- (point)))
3243 ;; Nothing but headers.
3245 (point-max))))
3246 (goto-char (point-min)))
3248 (defun article-goto-body ()
3249 "Place point at the start of the body."
3250 (goto-char (point-min))
3251 (cond
3252 ;; This variable is only bound when dealing with separate
3253 ;; MIME body parts.
3254 (article-goto-body-goes-to-point-min-p
3256 ((search-forward "\n\n" nil t)
3259 (goto-char (point-max))
3260 nil)))
3262 (defun article-strip-multiple-blank-lines ()
3263 "Replace consecutive blank lines with one empty line."
3264 (interactive)
3265 (save-excursion
3266 (let ((inhibit-point-motion-hooks t)
3267 (inhibit-read-only t))
3268 ;; First make all blank lines empty.
3269 (article-goto-body)
3270 (while (re-search-forward "^[ \t]+$" nil t)
3271 (unless (gnus-annotation-in-region-p
3272 (match-beginning 0) (match-end 0))
3273 (replace-match "" nil t)))
3274 ;; Then replace multiple empty lines with a single empty line.
3275 (article-goto-body)
3276 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3277 (unless (gnus-annotation-in-region-p
3278 (match-beginning 0) (match-end 0))
3279 (delete-region (match-beginning 1) (match-end 1)))))))
3281 (defun article-strip-leading-space ()
3282 "Remove all white space from the beginning of the lines in the article."
3283 (interactive)
3284 (save-excursion
3285 (let ((inhibit-point-motion-hooks t)
3286 (inhibit-read-only t))
3287 (article-goto-body)
3288 (while (re-search-forward "^[ \t]+" nil t)
3289 (replace-match "" t t)))))
3291 (defun article-strip-trailing-space ()
3292 "Remove all white space from the end of the lines in the article."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "[ \t]+$" nil t)
3299 (replace-match "" t t)))))
3301 (defun article-strip-blank-lines ()
3302 "Strip leading, trailing and multiple blank lines."
3303 (interactive)
3304 (article-strip-leading-blank-lines)
3305 (article-remove-trailing-blank-lines)
3306 (article-strip-multiple-blank-lines))
3308 (defun article-strip-all-blank-lines ()
3309 "Strip all blank lines."
3310 (interactive)
3311 (save-excursion
3312 (let ((inhibit-point-motion-hooks t)
3313 (inhibit-read-only t))
3314 (article-goto-body)
3315 (while (re-search-forward "^[ \t]*\n" nil t)
3316 (replace-match "" t t)))))
3318 (defun gnus-article-narrow-to-signature ()
3319 "Narrow to the signature; return t if a signature is found, else nil."
3320 (let ((inhibit-point-motion-hooks t))
3321 (when (gnus-article-search-signature)
3322 (forward-line 1)
3323 ;; Check whether we have some limits to what we consider
3324 ;; to be a signature.
3325 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3326 (list gnus-signature-limit)))
3327 limit limited)
3328 (while (setq limit (pop limits))
3329 (if (or (and (integerp limit)
3330 (< (- (point-max) (point)) limit))
3331 (and (floatp limit)
3332 (< (count-lines (point) (point-max)) limit))
3333 (and (functionp limit)
3334 (funcall limit))
3335 (and (stringp limit)
3336 (not (re-search-forward limit nil t))))
3337 () ; This limit did not succeed.
3338 (setq limited t
3339 limits nil)))
3340 (unless limited
3341 (narrow-to-region (point) (point-max))
3342 t)))))
3344 (defun gnus-article-search-signature ()
3345 "Search the current buffer for the signature separator.
3346 Put point at the beginning of the signature separator."
3347 (let ((cur (point)))
3348 (goto-char (point-max))
3349 (if (if (stringp gnus-signature-separator)
3350 (re-search-backward gnus-signature-separator nil t)
3351 (let ((seps gnus-signature-separator))
3352 (while (and seps
3353 (not (re-search-backward (car seps) nil t)))
3354 (pop seps))
3355 seps))
3357 (goto-char cur)
3358 nil)))
3360 (defun gnus-article-hidden-arg ()
3361 "Return the current prefix arg as a number, or 0 if no prefix."
3362 (list (if current-prefix-arg
3363 (prefix-numeric-value current-prefix-arg)
3364 0)))
3366 (defun gnus-article-check-hidden-text (type arg)
3367 "Return nil if hiding is necessary.
3368 Arg can be nil or a number. nil and positive means hide, negative
3369 means show, 0 means toggle."
3370 (save-excursion
3371 (save-restriction
3372 (let ((hide (gnus-article-hidden-text-p type)))
3373 (cond
3374 ((or (null arg)
3375 (> arg 0))
3376 nil)
3377 ((< arg 0)
3378 (gnus-article-show-hidden-text type)
3381 (if (eq hide 'hidden)
3382 (progn
3383 (gnus-article-show-hidden-text type)
3385 nil)))))))
3387 (defun gnus-article-hidden-text-p (type)
3388 "Say whether the current buffer contains hidden text of type TYPE."
3389 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3390 (while (and pos
3391 (not (get-text-property pos 'invisible))
3392 (not (get-text-property pos 'dummy-invisible)))
3393 (setq pos
3394 (text-property-any (1+ pos) (point-max) 'article-type type)))
3395 (if pos
3396 'hidden
3397 nil)))
3399 (defun gnus-article-show-hidden-text (type &optional dummy)
3400 "Show all hidden text of type TYPE.
3401 Originally it is hide instead of DUMMY."
3402 (let ((inhibit-read-only t)
3403 (inhibit-point-motion-hooks t))
3404 (gnus-remove-text-properties-when
3405 'article-type type
3406 (point-min) (point-max)
3407 (cons 'article-type (cons type
3408 gnus-hidden-properties)))
3409 (gnus-delete-wash-type type)))
3411 (defconst article-time-units
3412 `((year . ,(* 365.25 24 60 60))
3413 (week . ,(* 7 24 60 60))
3414 (day . ,(* 24 60 60))
3415 (hour . ,(* 60 60))
3416 (minute . 60)
3417 (second . 1))
3418 "Mapping from time units to seconds.")
3420 (defun gnus-article-forward-header ()
3421 "Move point to the start of the next header.
3422 If the current header is a continuation header, this can be several
3423 lines forward."
3424 (let ((ended nil))
3425 (while (not ended)
3426 (forward-line 1)
3427 (if (looking-at "[ \t]+[^ \t]")
3428 (forward-line 1)
3429 (setq ended t)))))
3431 (defun article-treat-date ()
3432 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3433 (with-current-buffer gnus-summary-buffer
3434 gnus-article-date-headers)
3435 gnus-article-date-headers)
3438 (defun article-date-ut (&optional type highlight date-position)
3439 "Convert DATE date to TYPE in the current article.
3440 The default type is `ut'. See `gnus-article-date-headers' for
3441 possible values."
3442 (interactive (list 'ut t))
3443 (let* ((case-fold-search t)
3444 (inhibit-read-only t)
3445 (inhibit-point-motion-hooks t)
3446 (first t)
3447 (visible-date (mail-fetch-field "Date"))
3448 pos date bface eface)
3449 (save-excursion
3450 (if date-position
3451 (progn
3452 (goto-char date-position)
3453 (setq date (get-text-property (point) 'original-date))
3454 (when (looking-at "[^:]+:[\t ]*")
3455 (setq bface (get-text-property (match-beginning 0) 'face)
3456 eface (get-text-property (match-end 0) 'face)))
3457 (delete-region (point)
3458 (progn
3459 (gnus-article-forward-header)
3460 (point)))
3461 (article-transform-date date type bface eface))
3462 (save-restriction
3463 (widen)
3464 (goto-char (point-min))
3465 (while (or (get-text-property (setq pos (point)) 'original-date)
3466 (and (setq pos (next-single-property-change
3467 (point) 'original-date))
3468 (goto-char pos)))
3469 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3470 (1+ (match-beginning 0))
3471 (point-max)))
3472 (while (setq pos (text-property-not-all pos (point-max)
3473 'gnus-date-type nil))
3474 (setq date (get-text-property pos 'original-date))
3475 (goto-char pos)
3476 (when (looking-at "[^:]+:[\t ]*")
3477 (setq bface (get-text-property (match-beginning 0) 'face)
3478 eface (get-text-property (match-end 0) 'face)))
3479 (delete-region pos (or (text-property-any pos (point-max)
3480 'gnus-date-type nil)
3481 (point-max))))
3482 (unless date ;; the 1st time
3483 (goto-char (point-min))
3484 (while (re-search-forward "^Date:[\t ]*" nil t)
3485 (setq date (get-text-property (match-beginning 0)
3486 'original-date)
3487 bface (get-text-property (match-beginning 0) 'face)
3488 eface (get-text-property (match-end 0) 'face))
3489 (delete-region (point-at-bol) (progn
3490 (gnus-article-forward-header)
3491 (point)))))
3492 (when (and (not date)
3493 visible-date)
3494 (setq date visible-date))
3495 (when date
3496 (article-transform-date date type bface eface))
3497 (goto-char (point-max))
3498 (widen)))))))
3500 (defun article-transform-date (date type bface eface)
3501 (dolist (this-type (cond
3502 ((null type)
3503 (list 'ut))
3504 ((atom type)
3505 (list type))
3507 type)))
3508 (goto-char
3509 (prog1
3510 (point)
3511 (add-text-properties
3512 (point)
3513 (progn
3514 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3515 (point))
3516 (list 'original-date date 'gnus-date-type this-type))))
3517 ;; Do highlighting.
3518 (when (looking-at
3519 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3520 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3521 (when (match-beginning 2)
3522 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3523 (while (and (zerop (forward-line 1))
3524 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3525 (when (match-beginning 1)
3526 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3528 (defun article-make-date-line (date type)
3529 "Return a DATE line of TYPE."
3530 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3531 combined-lapsed))
3532 (error "Unknown conversion type: %s" type))
3533 (condition-case ()
3534 (let ((time (ignore-errors (date-to-time date))))
3535 (cond
3536 ;; Convert to the local timezone.
3537 ((eq type 'local)
3538 (concat "Date: " (message-make-date time)))
3539 ;; Convert to Universal Time.
3540 ((eq type 'ut)
3541 (concat "Date: "
3542 (substring
3543 (message-make-date
3544 (let* ((e (parse-time-string date))
3545 (tm (apply 'encode-time e))
3546 (ms (car tm))
3547 (ls (- (cadr tm) (car (current-time-zone time)))))
3548 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3549 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3550 (t (list ms ls)))))
3551 0 -5)
3552 "UT"))
3553 ;; Get the original date from the article.
3554 ((eq type 'original)
3555 (concat "Date: " (if (string-match "\n+$" date)
3556 (substring date 0 (match-beginning 0))
3557 date)))
3558 ;; Let the user define the format.
3559 ((eq type 'user-defined)
3560 (let ((format (or (condition-case nil
3561 (with-current-buffer gnus-summary-buffer
3562 gnus-article-time-format)
3563 (error nil))
3564 gnus-article-time-format)))
3565 (if (functionp format)
3566 (funcall format time)
3567 (concat "Date: " (format-time-string format time)))))
3568 ;; ISO 8601.
3569 ((eq type 'iso8601)
3570 (let ((tz (car (current-time-zone time))))
3571 (concat
3572 "Date: "
3573 (format-time-string "%Y%m%dT%H%M%S" time)
3574 (format "%s%02d%02d"
3575 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3576 (/ (% (abs tz) 3600) 60)))))
3577 ;; Do a lapsed format.
3578 ((eq type 'lapsed)
3579 (concat "Date: " (article-lapsed-string time)))
3580 ;; A combined date/lapsed format.
3581 ((eq type 'combined-lapsed)
3582 (let ((date-string (article-make-date-line date 'original))
3583 (segments 3)
3584 lapsed-string)
3585 (while (and
3586 time
3587 (setq lapsed-string
3588 (concat " (" (article-lapsed-string time segments) ")"))
3589 (> (+ (length date-string)
3590 (length lapsed-string))
3591 (+ fill-column 6))
3592 (> segments 0))
3593 (setq segments (1- segments)))
3594 (if (> segments 0)
3595 (concat date-string lapsed-string)
3596 date-string)))
3597 ;; Display the date in proper English
3598 ((eq type 'english)
3599 (let ((dtime (decode-time time)))
3600 (concat
3601 "Date: the "
3602 (number-to-string (nth 3 dtime))
3603 (let ((digit (% (nth 3 dtime) 10)))
3604 (cond
3605 ((memq (nth 3 dtime) '(11 12 13)) "th")
3606 ((= digit 1) "st")
3607 ((= digit 2) "nd")
3608 ((= digit 3) "rd")
3609 (t "th")))
3610 " of "
3611 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3613 (number-to-string (nth 5 dtime))
3614 " at "
3615 (format "%02d" (nth 2 dtime))
3617 (format "%02d" (nth 1 dtime)))))))
3618 (foo
3619 (format "Date: %s (from Gnus)" date))))
3621 (defun article-lapsed-string (time &optional max-segments)
3622 ;; If the date is seriously mangled, the timezone functions are
3623 ;; liable to bug out, so we ignore all errors.
3624 (let* ((now (current-time))
3625 (real-time (subtract-time now time))
3626 (real-sec (and real-time
3627 (+ (* (float (car real-time)) 65536)
3628 (cadr real-time))))
3629 (sec (and real-time (abs real-sec)))
3630 (segments 0)
3631 num prev)
3632 (unless max-segments
3633 (setq max-segments (length article-time-units)))
3634 (cond
3635 ((null real-time)
3636 "Unknown")
3637 ((zerop sec)
3638 "Now")
3640 (concat
3641 ;; This is a bit convoluted, but basically we go
3642 ;; through the time units for years, weeks, etc,
3643 ;; and divide things to see whether that results
3644 ;; in positive answers.
3645 (mapconcat
3646 (lambda (unit)
3647 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3648 (>= segments max-segments))
3649 ;; The (remaining) seconds are too few to
3650 ;; be divided into this time unit.
3652 ;; It's big enough, so we output it.
3653 (setq sec (- sec (* num (cdr unit))))
3654 (prog1
3655 (concat (if prev ", " "") (int-to-string
3656 (floor num))
3657 " " (symbol-name (car unit))
3658 (if (> num 1) "s" ""))
3659 (setq prev t
3660 segments (1+ segments)))))
3661 article-time-units "")
3662 ;; If dates are odd, then it might appear like the
3663 ;; article was sent in the future.
3664 (if (> real-sec 0)
3665 " ago"
3666 " in the future"))))))
3668 (defun article-date-local (&optional highlight)
3669 "Convert the current article date to the local timezone."
3670 (interactive (list t))
3671 (article-date-ut 'local highlight))
3673 (defun article-date-english (&optional highlight)
3674 "Convert the current article date to something that is proper English."
3675 (interactive (list t))
3676 (article-date-ut 'english highlight))
3678 (defun article-date-original (&optional highlight)
3679 "Convert the current article date to what it was originally.
3680 This is only useful if you have used some other date conversion
3681 function and want to see what the date was before converting."
3682 (interactive (list t))
3683 (article-date-ut 'original highlight))
3685 (defun article-date-lapsed (&optional highlight)
3686 "Convert the current article date to time lapsed since it was sent."
3687 (interactive (list t))
3688 (article-date-ut 'lapsed highlight))
3690 (defun article-date-combined-lapsed (&optional highlight)
3691 "Convert the current article date to time lapsed since it was sent."
3692 (interactive (list t))
3693 (article-date-ut 'combined-lapsed highlight))
3695 (defun article-update-date-lapsed ()
3696 "Function to be run from a timer to update the lapsed time line."
3697 (save-match-data
3698 (let ((buffer (current-buffer)))
3699 (ignore-errors
3700 (walk-windows
3701 (lambda (w)
3702 (set-buffer (window-buffer w))
3703 (when (derived-mode-p 'gnus-article-mode)
3704 (let ((old-line (count-lines (point-min) (point)))
3705 (old-column (- (point) (line-beginning-position)))
3706 (window-start (window-start w))
3707 (pos (point-min))
3708 type next end)
3709 (while (setq pos (text-property-not-all pos (point-max)
3710 'gnus-date-type nil))
3711 (setq next (or (next-single-property-change pos
3712 'gnus-date-type)
3713 (point-max)))
3714 (setq type (get-text-property pos 'gnus-date-type))
3715 (when (memq type '(lapsed combined-lapsed user-defined))
3716 (article-date-ut type t pos)
3717 (setq end (or (next-single-property-change pos
3718 'gnus-date-type)
3719 (point-max)))
3720 (when window-start
3721 (if (/= window-start next)
3722 (setq window-start nil)
3723 (set-window-start w end)))
3724 (setq next end))
3725 (setq pos next))
3726 (goto-char (point-min))
3727 (when (> old-column 0)
3728 (setq old-line (1- old-line)))
3729 (forward-line old-line)
3730 (end-of-line)
3731 (when (> (current-column) old-column)
3732 (beginning-of-line)
3733 (forward-char old-column)))))
3734 nil 'visible))
3735 (set-buffer buffer))))
3737 (defun gnus-start-date-timer (&optional n)
3738 "Start a timer to update the Date headers in the article buffers.
3739 The numerical prefix says how frequently (in seconds) the function
3740 is to run."
3741 (interactive "p")
3742 (unless n
3743 (setq n 1))
3744 (gnus-stop-date-timer)
3745 (setq article-lapsed-timer
3746 (run-at-time 1 n 'article-update-date-lapsed)))
3748 (defun gnus-stop-date-timer ()
3749 "Stop the Date timer."
3750 (interactive)
3751 (when article-lapsed-timer
3752 (nnheader-cancel-timer article-lapsed-timer)
3753 (setq article-lapsed-timer nil)))
3755 (defun article-date-user (&optional highlight)
3756 "Convert the current article date to the user-defined format.
3757 This format is defined by the `gnus-article-time-format' variable."
3758 (interactive (list t))
3759 (article-date-ut 'user highlight))
3761 (defun article-date-iso8601 (&optional highlight)
3762 "Convert the current article date to ISO8601."
3763 (interactive (list t))
3764 (article-date-ut 'iso8601 highlight))
3766 (defmacro gnus-article-save-original-date (&rest forms)
3767 "Save the original date as a text property and evaluate FORMS."
3768 `(let* ((case-fold-search t)
3769 (start (progn
3770 (goto-char (point-min))
3771 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3772 (not (bolp)))
3773 (match-end 0))))
3774 (date (when (and start
3775 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3776 nil t))
3777 (buffer-substring-no-properties start
3778 (match-beginning 0)))))
3779 (goto-char (point-max))
3780 (skip-chars-backward "\n")
3781 (put-text-property (point-min) (point) 'original-date date)
3782 ,@forms
3783 (goto-char (point-max))
3784 (skip-chars-backward "\n")
3785 (put-text-property (point-min) (point) 'original-date date)))
3787 ;; (defun article-show-all ()
3788 ;; "Show all hidden text in the article buffer."
3789 ;; (interactive)
3790 ;; (save-excursion
3791 ;; (let ((inhibit-read-only t))
3792 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3794 (defun article-remove-leading-whitespace ()
3795 "Remove excessive whitespace from all headers."
3796 (interactive)
3797 (save-excursion
3798 (save-restriction
3799 (let ((inhibit-read-only t))
3800 (article-narrow-to-head)
3801 (goto-char (point-min))
3802 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3803 (delete-region (match-beginning 1) (match-end 1)))))))
3805 (defun article-emphasize (&optional arg)
3806 "Emphasize text according to `gnus-emphasis-alist'."
3807 (interactive (gnus-article-hidden-arg))
3808 (unless (gnus-article-check-hidden-text 'emphasis arg)
3809 (save-excursion
3810 (let ((alist (or
3811 (condition-case nil
3812 (with-current-buffer gnus-summary-buffer
3813 gnus-article-emphasis-alist)
3814 (error))
3815 gnus-emphasis-alist))
3816 (inhibit-read-only t)
3817 (props (append '(article-type emphasis)
3818 gnus-hidden-properties))
3819 regexp elem beg invisible visible face)
3820 (article-goto-body)
3821 (setq beg (point))
3822 (while (setq elem (pop alist))
3823 (goto-char beg)
3824 (setq regexp (car elem)
3825 invisible (nth 1 elem)
3826 visible (nth 2 elem)
3827 face (nth 3 elem))
3828 (while (re-search-forward regexp nil t)
3829 (when (and (match-beginning visible) (match-beginning invisible))
3830 (gnus-article-hide-text
3831 (match-beginning invisible) (match-end invisible) props)
3832 (gnus-article-unhide-text-type
3833 (match-beginning visible) (match-end visible) 'emphasis)
3834 (gnus-put-overlay-excluding-newlines
3835 (match-beginning visible) (match-end visible) 'face face)
3836 (gnus-add-wash-type 'emphasis)
3837 (goto-char (match-end invisible)))))))))
3839 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3840 "Setup newsgroup emphasis alist."
3841 (unless gnus-article-emphasis-alist
3842 (let ((name (and gnus-newsgroup-name
3843 (gnus-group-real-name gnus-newsgroup-name))))
3844 (make-local-variable 'gnus-article-emphasis-alist)
3845 (setq gnus-article-emphasis-alist
3846 (nconc
3847 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3848 (while (setq elem (pop alist))
3849 (when (and name (string-match (car elem) name))
3850 (setq alist nil
3851 highlight (copy-sequence (cdr elem)))))
3852 highlight)
3853 (copy-sequence highlight-words)
3854 (if gnus-newsgroup-name
3855 (copy-sequence (gnus-group-find-parameter
3856 gnus-newsgroup-name 'highlight-words t)))
3857 gnus-emphasis-alist)))))
3859 (defvar gnus-summary-article-menu)
3860 (defvar gnus-summary-post-menu)
3862 ;;; Saving functions.
3864 (defun gnus-article-save (save-buffer file &optional num)
3865 "Save the currently selected article."
3866 (when (or (get gnus-default-article-saver :headers)
3867 (not gnus-save-all-headers))
3868 ;; Remove headers according to `gnus-saved-headers' or the value
3869 ;; of the `:headers' property that the saver function might have.
3870 (let ((gnus-visible-headers
3871 (or (symbol-value (get gnus-default-article-saver :headers))
3872 gnus-saved-headers gnus-visible-headers))
3873 ;; Ignore group parameter. See `article-hide-headers'.
3874 (gnus-summary-buffer nil))
3875 (with-current-buffer save-buffer
3876 (article-hide-headers 1 t))))
3877 (save-window-excursion
3878 (if (not gnus-default-article-saver)
3879 (error "No default saver is defined")
3880 ;; !!! Magic! The saving functions all save
3881 ;; `gnus-save-article-buffer' (or so they think), but we
3882 ;; bind that variable to our save-buffer.
3883 (set-buffer gnus-article-buffer)
3884 (let* ((gnus-save-article-buffer save-buffer)
3885 (filename
3886 (cond
3887 ((not gnus-prompt-before-saving) 'default)
3888 ((eq gnus-prompt-before-saving 'always) nil)
3889 (t file)))
3890 (gnus-number-of-articles-to-be-saved
3891 (when (eq gnus-prompt-before-saving t)
3892 num))) ; Magic
3893 (set-buffer gnus-article-current-summary)
3894 (funcall gnus-default-article-saver filename)))))
3896 (defun gnus-read-save-file-name (prompt &optional filename
3897 function group headers variable
3898 dir-var)
3899 (let ((default-name
3900 (funcall function group headers (symbol-value variable)))
3901 result)
3902 (setq result
3903 (expand-file-name
3904 (cond
3905 ((eq filename 'default)
3906 default-name)
3907 ((eq filename t)
3908 default-name)
3909 (filename filename)
3911 (when (symbol-value dir-var)
3912 (setq default-name (expand-file-name
3913 (file-name-nondirectory default-name)
3914 (symbol-value dir-var))))
3915 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3916 (prompt
3917 (format prompt
3918 (if (and gnus-number-of-articles-to-be-saved
3919 (> gnus-number-of-articles-to-be-saved 1))
3920 (format "these %d articles"
3921 gnus-number-of-articles-to-be-saved)
3922 "this article")))
3923 (file
3924 ;; Let the split methods have their say.
3925 (cond
3926 ;; No split name was found.
3927 ((null split-name)
3928 (read-file-name
3929 (concat prompt " (default "
3930 (file-name-nondirectory default-name) "): ")
3931 (file-name-directory default-name)
3932 default-name))
3933 ;; A single group name is returned.
3934 ((stringp split-name)
3935 (setq default-name
3936 (funcall function split-name headers
3937 (symbol-value variable)))
3938 (read-file-name
3939 (concat prompt " (default "
3940 (file-name-nondirectory default-name) "): ")
3941 (file-name-directory default-name)
3942 default-name))
3943 ;; A single split name was found
3944 ((= 1 (length split-name))
3945 (let* ((name (expand-file-name
3946 (car split-name)
3947 gnus-article-save-directory))
3948 (dir (cond ((file-directory-p name)
3949 (file-name-as-directory name))
3950 ((file-exists-p name) name)
3951 (t gnus-article-save-directory))))
3952 (read-file-name
3953 (concat prompt " (default " name "): ")
3954 dir name)))
3955 ;; A list of splits was found.
3957 (setq split-name (nreverse split-name))
3958 (let (result)
3959 (let ((file-name-history
3960 (nconc split-name file-name-history)))
3961 (setq result
3962 (expand-file-name
3963 (read-file-name
3964 (concat prompt " (`M-p' for defaults): ")
3965 gnus-article-save-directory
3966 (car split-name))
3967 gnus-article-save-directory)))
3968 (car (push result file-name-history)))))))
3969 ;; Create the directory.
3970 (gnus-make-directory (file-name-directory file))
3971 ;; If we have read a directory, we append the default file name.
3972 (when (file-directory-p file)
3973 (setq file (expand-file-name (file-name-nondirectory
3974 default-name)
3975 (file-name-as-directory file))))
3976 ;; Possibly translate some characters.
3977 (nnheader-translate-file-chars file))))))
3978 (gnus-make-directory (file-name-directory result))
3979 (when variable
3980 (set variable result))
3981 (when dir-var
3982 (set dir-var (file-name-directory result)))
3983 result))
3985 (defun gnus-article-archive-name (group)
3986 "Return the first instance of an \"Archive-name\" in the current buffer."
3987 (let ((case-fold-search t))
3988 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3989 (nnheader-concat gnus-article-save-directory
3990 (match-string 1)))))
3992 (defun gnus-article-nndoc-name (group)
3993 "If GROUP is an nndoc group, return the name of the parent group."
3994 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3995 (gnus-group-get-parameter group 'save-article-group)))
3997 (defun gnus-summary-save-in-rmail (&optional filename)
3998 "Append this article to Rmail file.
3999 Optional argument FILENAME specifies file name.
4000 Directory to save to is default to `gnus-article-save-directory'."
4001 (setq filename (gnus-read-save-file-name
4002 "Save %s in rmail file" filename
4003 gnus-rmail-save-name gnus-newsgroup-name
4004 gnus-current-headers 'gnus-newsgroup-last-rmail))
4005 (with-current-buffer gnus-save-article-buffer
4006 (save-excursion
4007 (save-restriction
4008 (widen)
4009 ;; Note that unlike gnus-summary-save-in-mail, there is no
4010 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4011 ;; not use Babyl.
4012 (gnus-output-to-rmail filename))))
4013 filename)
4015 (defun gnus-summary-save-in-mail (&optional filename)
4016 "Append this article to Unix mail file.
4017 Optional argument FILENAME specifies file name.
4018 Directory to save to is default to `gnus-article-save-directory'."
4019 (setq filename (gnus-read-save-file-name
4020 "Save %s in Unix mail file" filename
4021 gnus-mail-save-name gnus-newsgroup-name
4022 gnus-current-headers 'gnus-newsgroup-last-mail))
4023 (with-current-buffer gnus-save-article-buffer
4024 (save-excursion
4025 (save-restriction
4026 (widen)
4027 (if (and (file-readable-p filename)
4028 (file-regular-p filename)
4029 (mail-file-babyl-p filename))
4030 (gnus-output-to-rmail filename)
4031 (gnus-output-to-mail filename)))))
4032 filename)
4034 (put 'gnus-summary-save-in-file :decode t)
4035 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4036 (defun gnus-summary-save-in-file (&optional filename overwrite)
4037 "Append this article to file.
4038 Optional argument FILENAME specifies file name.
4039 Directory to save to is default to `gnus-article-save-directory'."
4040 (setq filename (gnus-read-save-file-name
4041 "Save %s in file" filename
4042 gnus-file-save-name gnus-newsgroup-name
4043 gnus-current-headers 'gnus-newsgroup-last-file))
4044 (with-current-buffer gnus-save-article-buffer
4045 (save-excursion
4046 (save-restriction
4047 (widen)
4048 (when (and overwrite
4049 (file-exists-p filename))
4050 (delete-file filename))
4051 (gnus-output-to-file filename))))
4052 filename)
4054 (put 'gnus-summary-write-to-file :decode t)
4055 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4056 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4057 (defun gnus-summary-write-to-file (&optional filename)
4058 "Write this article to a file, overwriting it if the file exists.
4059 Optional argument FILENAME specifies file name.
4060 The directory to save in defaults to `gnus-article-save-directory'."
4061 (setq filename (gnus-read-save-file-name
4062 "Save %s in file" filename
4063 gnus-file-save-name gnus-newsgroup-name
4064 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4065 (gnus-summary-save-in-file filename t))
4067 (put 'gnus-summary-save-body-in-file :decode t)
4068 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4069 "Append this article body to a file.
4070 Optional argument FILENAME specifies file name.
4071 The directory to save in defaults to `gnus-article-save-directory'."
4072 (setq filename (gnus-read-save-file-name
4073 "Save %s body in file" filename
4074 gnus-file-save-name gnus-newsgroup-name
4075 gnus-current-headers 'gnus-newsgroup-last-file))
4076 (with-current-buffer gnus-save-article-buffer
4077 (save-excursion
4078 (save-restriction
4079 (widen)
4080 (when (article-goto-body)
4081 (narrow-to-region (point) (point-max)))
4082 (when (and overwrite
4083 (file-exists-p filename))
4084 (delete-file filename))
4085 (gnus-output-to-file filename))))
4086 filename)
4088 (put 'gnus-summary-write-body-to-file :decode t)
4089 (put 'gnus-summary-write-body-to-file
4090 :function 'gnus-summary-save-body-in-file)
4091 (defun gnus-summary-write-body-to-file (&optional filename)
4092 "Write this article body to a file, overwriting it if the file exists.
4093 Optional argument FILENAME specifies file name.
4094 The directory to save in defaults to `gnus-article-save-directory'."
4095 (setq filename (gnus-read-save-file-name
4096 "Save %s body in file" filename
4097 gnus-file-save-name gnus-newsgroup-name
4098 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4099 (gnus-summary-save-body-in-file filename t))
4101 (put 'gnus-summary-save-in-pipe :decode t)
4102 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4103 (defun gnus-summary-save-in-pipe (&optional command raw)
4104 "Pipe this article to subprocess COMMAND.
4105 Valid values for COMMAND include:
4106 a string
4107 The executable command name and possibly arguments.
4109 You will be prompted for the command in the minibuffer.
4110 the symbol `default'
4111 It will be replaced with the command which the variable
4112 `gnus-summary-pipe-output-default-command' holds or the command
4113 last used for saving.
4114 Non-nil value for RAW overrides `:decode' and `:headers' properties
4115 and the raw article including all headers will be piped."
4116 (let ((article (gnus-summary-article-number))
4117 (decode (unless raw
4118 (get 'gnus-summary-save-in-pipe :decode)))
4119 save-buffer default)
4120 (if article
4121 (if (vectorp (gnus-summary-article-header article))
4122 (save-current-buffer
4123 (gnus-summary-select-article decode decode nil article)
4124 (insert-buffer-substring
4125 (prog1
4126 (if decode
4127 gnus-article-buffer
4128 gnus-original-article-buffer)
4129 (setq save-buffer
4130 (nnheader-set-temp-buffer " *Gnus Save*"))))
4131 ;; Remove unwanted headers.
4132 (when (and (not raw)
4133 (or (get 'gnus-summary-save-in-pipe :headers)
4134 (not gnus-save-all-headers)))
4135 (let ((gnus-visible-headers
4136 (or (symbol-value (get 'gnus-summary-save-in-pipe
4137 :headers))
4138 gnus-saved-headers gnus-visible-headers))
4139 (gnus-summary-buffer nil))
4140 (article-hide-headers 1 t))))
4141 (error "%d is not a real article" article))
4142 (error "No article to pipe"))
4143 (setq default (or gnus-summary-pipe-output-default-command
4144 gnus-last-shell-command))
4145 (unless (stringp command)
4146 (setq command
4147 (if (and (eq command 'default) default)
4148 default
4149 (gnus-read-shell-command "Shell command on this article: "
4150 default))))
4151 (when (string-equal command "")
4152 (if default
4153 (setq command default)
4154 (error "A command is required")))
4155 (with-current-buffer save-buffer
4156 (save-restriction
4157 (widen)
4158 (shell-command-on-region (point-min) (point-max) command nil)))
4159 (gnus-kill-buffer save-buffer))
4160 (setq gnus-summary-pipe-output-default-command command))
4162 (defun gnus-summary-pipe-to-muttprint (&optional command)
4163 "Pipe this article to muttprint."
4164 (unless (stringp command)
4165 (setq command (read-string
4166 "Print using command: " gnus-summary-muttprint-program
4167 nil gnus-summary-muttprint-program)))
4168 (let ((gnus-summary-pipe-output-default-command
4169 gnus-summary-pipe-output-default-command))
4170 (gnus-summary-save-in-pipe command))
4171 (setq gnus-summary-muttprint-program command))
4173 ;;; Article file names when saving.
4175 (defun gnus-capitalize-newsgroup (newsgroup)
4176 "Capitalize NEWSGROUP name."
4177 (when (not (zerop (length newsgroup)))
4178 (concat (char-to-string (upcase (aref newsgroup 0)))
4179 (substring newsgroup 1))))
4181 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4182 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4183 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4184 Otherwise, it is like ~/News/news/group/num."
4185 (let ((default
4186 (expand-file-name
4187 (concat (if (gnus-use-long-file-name 'not-save)
4188 (gnus-capitalize-newsgroup newsgroup)
4189 (gnus-newsgroup-directory-form newsgroup))
4190 "/" (int-to-string (mail-header-number headers)))
4191 gnus-article-save-directory)))
4192 (if (and last-file
4193 (string-equal (file-name-directory default)
4194 (file-name-directory last-file))
4195 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4196 default
4197 (or last-file default))))
4199 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4200 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4201 If variable `gnus-use-long-file-name' is non-nil, it is
4202 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4203 (let ((default
4204 (expand-file-name
4205 (concat (if (gnus-use-long-file-name 'not-save)
4206 newsgroup
4207 (gnus-newsgroup-directory-form newsgroup))
4208 "/" (int-to-string (mail-header-number headers)))
4209 gnus-article-save-directory)))
4210 (if (and last-file
4211 (string-equal (file-name-directory default)
4212 (file-name-directory last-file))
4213 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4214 default
4215 (or last-file default))))
4217 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4218 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4219 If variable `gnus-use-long-file-name' is non-nil, it is
4220 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4221 (or last-file
4222 (expand-file-name
4223 (if (gnus-use-long-file-name 'not-save)
4224 newsgroup
4225 (file-relative-name
4226 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4227 default-directory))
4228 gnus-article-save-directory)))
4230 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4231 "Generate file name from sender."
4232 (let ((from (mail-header-from headers)))
4233 (expand-file-name
4234 (if (and from (string-match "\\([^ <]+\\)@" from))
4235 (match-string 1 from)
4236 "nobody")
4237 gnus-article-save-directory)))
4239 (defun article-verify-x-pgp-sig ()
4240 "Verify X-PGP-Sig."
4241 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4242 (interactive)
4243 (if (gnus-buffer-live-p gnus-original-article-buffer)
4244 (let ((sig (with-current-buffer gnus-original-article-buffer
4245 (gnus-fetch-field "X-PGP-Sig")))
4246 items info headers)
4247 (when (and sig
4248 mml2015-use
4249 (mml2015-clear-verify-function))
4250 (with-temp-buffer
4251 (insert-buffer-substring gnus-original-article-buffer)
4252 (setq items (split-string sig))
4253 (message-narrow-to-head)
4254 (let ((inhibit-point-motion-hooks t)
4255 (case-fold-search t))
4256 ;; Don't verify multiple headers.
4257 (setq headers (mapconcat (lambda (header)
4258 (concat header ": "
4259 (mail-fetch-field header)
4260 "\n"))
4261 (split-string (nth 1 items) ",") "")))
4262 (delete-region (point-min) (point-max))
4263 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4264 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4265 (insert headers)
4266 (widen)
4267 (forward-line)
4268 (while (not (eobp))
4269 (if (looking-at "^-")
4270 (insert "- "))
4271 (forward-line))
4272 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4273 (insert "Version: " (car items) "\n\n")
4274 (insert (mapconcat 'identity (cddr items) "\n"))
4275 (insert "\n-----END PGP SIGNATURE-----\n")
4276 (let ((mm-security-handle (list (format "multipart/signed"))))
4277 (mml2015-clean-buffer)
4278 (let ((coding-system-for-write (or gnus-newsgroup-charset
4279 'iso-8859-1)))
4280 (funcall (mml2015-clear-verify-function)))
4281 (setq info
4282 (or (mm-handle-multipart-ctl-parameter
4283 mm-security-handle 'gnus-details)
4284 (mm-handle-multipart-ctl-parameter
4285 mm-security-handle 'gnus-info)))))
4286 (when info
4287 (let ((inhibit-read-only t) bface eface)
4288 (save-restriction
4289 (message-narrow-to-head)
4290 (goto-char (point-max))
4291 (forward-line -1)
4292 (setq bface (get-text-property (point-at-bol) 'face)
4293 eface (get-text-property (1- (point-at-eol)) 'face))
4294 (message-remove-header "X-Gnus-PGP-Verify")
4295 (if (re-search-forward "^X-PGP-Sig:" nil t)
4296 (forward-line)
4297 (goto-char (point-max)))
4298 (narrow-to-region (point) (point))
4299 (insert "X-Gnus-PGP-Verify: " info "\n")
4300 (goto-char (point-min))
4301 (forward-line)
4302 (while (not (eobp))
4303 (if (not (looking-at "^[ \t]"))
4304 (insert " "))
4305 (forward-line))
4306 ;; Do highlighting.
4307 (goto-char (point-min))
4308 (when (looking-at "\\([^:]+\\): *")
4309 (put-text-property (match-beginning 1) (1+ (match-end 1))
4310 'face bface)
4311 (put-text-property (match-end 0) (point-max)
4312 'face eface)))))))))
4314 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4316 (defun article-verify-cancel-lock ()
4317 "Verify Cancel-Lock header."
4318 (interactive)
4319 (if (gnus-buffer-live-p gnus-original-article-buffer)
4320 (canlock-verify gnus-original-article-buffer)))
4322 (eval-and-compile
4323 (mapc
4324 (lambda (func)
4325 (let (afunc gfunc)
4326 (if (consp func)
4327 (setq afunc (car func)
4328 gfunc (cdr func))
4329 (setq afunc func
4330 gfunc (intern (format "gnus-%s" func))))
4331 (defalias gfunc
4332 (when (fboundp afunc)
4333 `(lambda (&optional interactive &rest args)
4334 ,(documentation afunc t)
4335 (interactive (list t))
4336 (with-current-buffer gnus-article-buffer
4337 (if interactive
4338 (call-interactively ',afunc)
4339 (apply ',afunc args))))))))
4340 '(article-hide-headers
4341 article-verify-x-pgp-sig
4342 article-verify-cancel-lock
4343 article-hide-boring-headers
4344 article-treat-overstrike
4345 article-treat-ansi-sequences
4346 article-fill-long-lines
4347 article-capitalize-sentences
4348 article-remove-cr
4349 article-remove-leading-whitespace
4350 article-display-x-face
4351 article-display-face
4352 article-de-quoted-unreadable
4353 article-de-base64-unreadable
4354 article-decode-HZ
4355 article-wash-html
4356 article-unsplit-urls
4357 article-hide-list-identifiers
4358 article-strip-banner
4359 article-babel
4360 article-hide-pem
4361 article-hide-signature
4362 article-strip-headers-in-body
4363 article-remove-trailing-blank-lines
4364 article-strip-leading-blank-lines
4365 article-strip-multiple-blank-lines
4366 article-strip-leading-space
4367 article-strip-trailing-space
4368 article-strip-blank-lines
4369 article-strip-all-blank-lines
4370 article-date-local
4371 article-date-english
4372 article-date-iso8601
4373 article-date-original
4374 article-treat-date
4375 article-date-ut
4376 article-decode-mime-words
4377 article-decode-charset
4378 article-decode-encoded-words
4379 article-date-user
4380 article-date-lapsed
4381 article-date-combined-lapsed
4382 article-emphasize
4383 article-treat-dumbquotes
4384 article-treat-non-ascii
4385 article-normalize-headers
4386 ;;(article-show-all . gnus-article-show-all-headers)
4390 ;;; Gnus article mode
4393 (put 'gnus-article-mode 'mode-class 'special)
4395 (set-keymap-parent gnus-article-mode-map widget-keymap)
4397 (gnus-define-keys gnus-article-mode-map
4398 " " gnus-article-goto-next-page
4399 [?\S-\ ] gnus-article-goto-prev-page
4400 "\177" gnus-article-goto-prev-page
4401 [delete] gnus-article-goto-prev-page
4402 "\C-c^" gnus-article-refer-article
4403 "h" gnus-article-show-summary
4404 "s" gnus-article-show-summary
4405 "\C-c\C-m" gnus-article-mail
4406 "?" gnus-article-describe-briefly
4407 "<" beginning-of-buffer
4408 ">" end-of-buffer
4409 "\C-c\C-i" gnus-info-find-node
4410 "\C-c\C-b" gnus-bug
4411 "R" gnus-article-reply-with-original
4412 "F" gnus-article-followup-with-original
4413 "\C-hk" gnus-article-describe-key
4414 "\C-hc" gnus-article-describe-key-briefly
4415 "\C-hb" gnus-article-describe-bindings
4417 "e" gnus-article-read-summary-keys
4418 "\C-d" gnus-article-read-summary-keys
4419 "\M-*" gnus-article-read-summary-keys
4420 "\M-#" gnus-article-read-summary-keys
4421 "\M-^" gnus-article-read-summary-keys
4422 "\M-g" gnus-article-read-summary-keys)
4424 (substitute-key-definition
4425 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4427 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4428 "W" gnus-article-wide-reply-with-original)
4429 (if (featurep 'xemacs)
4430 (set-keymap-default-binding gnus-article-send-map
4431 'gnus-article-read-summary-send-keys)
4432 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4434 (defun gnus-article-make-menu-bar ()
4435 (unless (boundp 'gnus-article-commands-menu)
4436 (gnus-summary-make-menu-bar))
4437 (unless (boundp 'gnus-article-article-menu)
4438 (easy-menu-define
4439 gnus-article-article-menu gnus-article-mode-map ""
4440 '("Article"
4441 ["Scroll forwards" gnus-article-goto-next-page t]
4442 ["Scroll backwards" gnus-article-goto-prev-page t]
4443 ["Show summary" gnus-article-show-summary t]
4444 ["Fetch Message-ID at point" gnus-article-refer-article t]
4445 ["Mail to address at point" gnus-article-mail t]
4446 ["Send a bug report" gnus-bug t]))
4448 (easy-menu-define
4449 gnus-article-treatment-menu gnus-article-mode-map ""
4450 ;; Fixme: this should use :active (and maybe :visible).
4451 '("Treatment"
4452 ["Hide headers" gnus-article-hide-headers t]
4453 ["Hide signature" gnus-article-hide-signature t]
4454 ["Hide citation" gnus-article-hide-citation t]
4455 ["Treat overstrike" gnus-article-treat-overstrike t]
4456 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4457 ["Remove carriage return" gnus-article-remove-cr t]
4458 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4459 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4460 ["Remove base64" gnus-article-de-base64-unreadable t]
4461 ["Treat html" gnus-article-wash-html t]
4462 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4463 ["Decode HZ" gnus-article-decode-HZ t]))
4465 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4467 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4469 (gnus-run-hooks 'gnus-article-menu-hook)))
4471 (defvar bookmark-make-record-function)
4472 (defvar shr-put-image-function)
4474 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4475 "Major mode for displaying an article.
4477 All normal editing commands are switched off.
4479 The following commands are available in addition to all summary mode
4480 commands:
4481 \\<gnus-article-mode-map>
4482 \\[gnus-article-next-page]\t Scroll the article one page forwards
4483 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4484 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4485 \\[gnus-article-show-summary]\t Display the summary buffer
4486 \\[gnus-article-mail]\t Send a reply to the address near point
4487 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4488 \\[gnus-info-find-node]\t Go to the Gnus info node"
4489 (gnus-simplify-mode-line)
4490 (make-local-variable 'minor-mode-alist)
4491 (when (gnus-visual-p 'article-menu 'menu)
4492 (gnus-article-make-menu-bar)
4493 (when gnus-summary-tool-bar-map
4494 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4495 (gnus-update-format-specifications nil 'article-mode)
4496 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4497 (set (make-local-variable 'gnus-page-broken) nil)
4498 (make-local-variable 'gnus-article-current-summary)
4499 (make-local-variable 'gnus-article-mime-handles)
4500 (make-local-variable 'gnus-article-decoded-p)
4501 (make-local-variable 'gnus-article-mime-handle-alist)
4502 (make-local-variable 'gnus-article-wash-types)
4503 (make-local-variable 'gnus-article-image-alist)
4504 (make-local-variable 'gnus-article-charset)
4505 (make-local-variable 'gnus-article-ignored-charsets)
4506 (set (make-local-variable 'bookmark-make-record-function)
4507 'gnus-summary-bookmark-make-record)
4508 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4509 ;; face.
4510 (set (make-local-variable 'nobreak-char-display) nil)
4511 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4512 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4513 (setq cursor-in-non-selected-windows nil)
4514 (gnus-set-default-directory)
4515 (buffer-disable-undo)
4516 (setq buffer-read-only t
4517 show-trailing-whitespace nil)
4518 (mm-enable-multibyte))
4520 (defun gnus-article-setup-buffer ()
4521 "Initialize the article buffer."
4522 (let* ((name (if gnus-single-article-buffer "*Article*"
4523 (concat "*Article "
4524 (gnus-group-decoded-name gnus-newsgroup-name)
4525 "*")))
4526 (original
4527 (progn (string-match "\\*Article" name)
4528 (concat " *Original Article"
4529 (substring name (match-end 0))))))
4530 (setq gnus-article-buffer name)
4531 (setq gnus-original-article-buffer original)
4532 (setq gnus-article-mime-handle-alist nil)
4533 (with-current-buffer gnus-summary-buffer
4534 ;; This might be a variable local to the summary buffer.
4535 (unless gnus-single-article-buffer
4536 (setq gnus-article-buffer name)
4537 (setq gnus-original-article-buffer original)
4538 (gnus-set-global-variables)))
4539 (gnus-article-setup-highlight-words)
4540 ;; Init original article buffer.
4541 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4542 (mm-enable-multibyte)
4543 (setq major-mode 'gnus-original-article-mode)
4544 (make-local-variable 'gnus-original-article))
4545 (if (and (get-buffer name)
4546 (with-current-buffer name
4547 (if gnus-article-edit-mode
4548 (if (y-or-n-p "Article mode edit in progress; discard? ")
4549 (progn
4550 (set-buffer-modified-p nil)
4551 (gnus-kill-buffer name)
4552 (message "")
4553 nil)
4554 (error "Action aborted"))
4555 t)))
4556 (let ((summary gnus-summary-buffer))
4557 (with-current-buffer name
4558 (set (make-local-variable 'gnus-article-edit-mode) nil)
4559 (gnus-article-stop-animations)
4560 (when gnus-article-mime-handles
4561 (mm-destroy-parts gnus-article-mime-handles)
4562 (setq gnus-article-mime-handles nil))
4563 ;; Set it to nil in article-buffer!
4564 (setq gnus-article-mime-handle-alist nil)
4565 (buffer-disable-undo)
4566 (setq buffer-read-only t)
4567 (unless (derived-mode-p 'gnus-article-mode)
4568 (gnus-article-mode))
4569 (set (make-local-variable 'gnus-summary-buffer) summary)
4570 (setq truncate-lines gnus-article-truncate-lines)
4571 (current-buffer)))
4572 (let ((summary gnus-summary-buffer))
4573 (with-current-buffer (gnus-get-buffer-create name)
4574 (gnus-article-mode)
4575 (setq truncate-lines gnus-article-truncate-lines)
4576 (set (make-local-variable 'gnus-summary-buffer) summary)
4577 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4578 (when article-lapsed-timer
4579 (gnus-stop-date-timer))
4580 (when gnus-article-update-date-headers
4581 (gnus-start-date-timer gnus-article-update-date-headers))
4582 (current-buffer))))))
4584 (defun gnus-article-stop-animations ()
4585 (dolist (timer (and (boundp 'timer-list)
4586 timer-list))
4587 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4588 (cancel-timer timer))))
4590 (defun gnus-stop-downloads ()
4591 (when (boundp 'url-queue)
4592 (set (intern "url-queue" obarray) nil)))
4594 ;; Set article window start at LINE, where LINE is the number of lines
4595 ;; from the head of the article.
4596 (defun gnus-article-set-window-start (&optional line)
4597 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4598 (when article-window
4599 (set-window-start
4600 article-window
4601 (with-current-buffer gnus-article-buffer
4602 (goto-char (point-min))
4603 (if (not line)
4604 (point-min)
4605 (gnus-message 6 "Moved to bookmark")
4606 (search-forward "\n\n" nil t)
4607 (forward-line line)
4608 (point)))))))
4610 (defun gnus-article-prepare (article &optional all-headers header)
4611 "Prepare ARTICLE in article mode buffer.
4612 ARTICLE should either be an article number or a Message-ID.
4613 If ARTICLE is an id, HEADER should be the article headers.
4614 If ALL-HEADERS is non-nil, no headers are hidden."
4615 (save-excursion
4616 ;; Make sure we start in a summary buffer.
4617 (unless (derived-mode-p 'gnus-summary-mode)
4618 (set-buffer gnus-summary-buffer))
4619 (setq gnus-summary-buffer (current-buffer))
4620 (let* ((gnus-article (if header (mail-header-number header) article))
4621 (summary-buffer (current-buffer))
4622 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4623 (group gnus-newsgroup-name)
4624 result)
4625 (save-excursion
4626 (gnus-article-setup-buffer)
4627 (set-buffer gnus-article-buffer)
4628 ;; Deactivate active regions.
4629 (when (and (boundp 'transient-mark-mode)
4630 transient-mark-mode)
4631 (setq mark-active nil))
4632 (if (not (setq result (let ((inhibit-read-only t))
4633 (gnus-request-article-this-buffer
4634 article group))))
4635 ;; There is no such article.
4636 (save-excursion
4637 (when (and (numberp article)
4638 (not (memq article gnus-newsgroup-sparse)))
4639 (setq gnus-article-current
4640 (cons gnus-newsgroup-name article))
4641 (set-buffer gnus-summary-buffer)
4642 (setq gnus-current-article article)
4643 (if (and (memq article gnus-newsgroup-undownloaded)
4644 (not (gnus-online (gnus-find-method-for-group
4645 gnus-newsgroup-name))))
4646 (progn
4647 (gnus-summary-set-agent-mark article)
4648 (message "Message marked for downloading"))
4649 (gnus-summary-mark-article article gnus-canceled-mark)
4650 (unless (memq article gnus-newsgroup-sparse)
4651 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4652 (if (or (eq result 'pseudo)
4653 (eq result 'nneething))
4654 (progn
4655 (with-current-buffer summary-buffer
4656 (push article gnus-newsgroup-history)
4657 (setq gnus-last-article gnus-current-article
4658 gnus-current-article 0
4659 gnus-current-headers nil
4660 gnus-article-current nil)
4661 (if (eq result 'nneething)
4662 (gnus-configure-windows 'summary)
4663 (gnus-configure-windows 'article))
4664 (gnus-set-global-variables))
4665 (let ((gnus-article-mime-handle-alist-1
4666 gnus-article-mime-handle-alist))
4667 (gnus-set-mode-line 'article)))
4668 ;; The result from the `request' was an actual article -
4669 ;; or at least some text that is now displayed in the
4670 ;; article buffer.
4671 (when (and (numberp article)
4672 (not (eq article gnus-current-article)))
4673 ;; Seems like a new article has been selected.
4674 ;; `gnus-current-article' must be an article number.
4675 (with-current-buffer summary-buffer
4676 (push article gnus-newsgroup-history)
4677 (setq gnus-last-article gnus-current-article
4678 gnus-current-article article
4679 gnus-current-headers
4680 (gnus-summary-article-header gnus-current-article)
4681 gnus-article-current
4682 (cons gnus-newsgroup-name gnus-current-article))
4683 (unless (vectorp gnus-current-headers)
4684 (setq gnus-current-headers nil))
4685 (gnus-summary-goto-subject gnus-current-article)
4686 (when (gnus-summary-show-thread)
4687 ;; If the summary buffer really was folded, the
4688 ;; previous goto may not actually have gone to
4689 ;; the right article, but the thread root instead.
4690 ;; So we go again.
4691 (gnus-summary-goto-subject gnus-current-article))
4692 (gnus-run-hooks 'gnus-mark-article-hook)
4693 (gnus-set-mode-line 'summary)
4694 (when (gnus-visual-p 'article-highlight 'highlight)
4695 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4696 ;; Set the global newsgroup variables here.
4697 (gnus-set-global-variables)
4698 (setq gnus-have-all-headers
4699 (or all-headers gnus-show-all-headers))))
4700 (save-excursion
4701 (gnus-configure-windows 'article))
4702 (when (or (numberp article)
4703 (stringp article))
4704 (gnus-article-prepare-display)
4705 ;; Do page break.
4706 (goto-char (point-min))
4707 (when gnus-break-pages
4708 (gnus-narrow-to-page)))
4709 (let ((gnus-article-mime-handle-alist-1
4710 gnus-article-mime-handle-alist))
4711 (gnus-set-mode-line 'article))
4712 (article-goto-body)
4713 (unless (bobp)
4714 (forward-line -1))
4715 (set-window-point (get-buffer-window (current-buffer)) (point))
4716 (gnus-configure-windows 'article)
4717 (gnus-run-hooks 'gnus-article-prepare-hook)
4718 t))))))
4720 ;;;###autoload
4721 (defun gnus-article-prepare-display ()
4722 "Make the current buffer look like a nice article."
4723 ;; Hooks for getting information from the article.
4724 ;; This hook must be called before being narrowed.
4725 (let ((gnus-article-buffer (current-buffer))
4726 buffer-read-only
4727 (inhibit-read-only t))
4728 (unless (derived-mode-p 'gnus-article-mode)
4729 (gnus-article-mode))
4730 (setq buffer-read-only nil
4731 gnus-article-wash-types nil
4732 gnus-article-image-alist nil)
4733 (gnus-run-hooks 'gnus-tmp-internal-hook)
4734 (when gnus-display-mime-function
4735 (funcall gnus-display-mime-function))
4736 ;; Add attachment buttons to the header.
4737 (when gnus-mime-display-attachment-buttons-in-header
4738 (gnus-mime-buttonize-attachments-in-header))))
4741 ;;; Gnus Sticky Article Mode
4744 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4745 "Mode for sticky articles."
4746 ;; Release bindings that won't work.
4747 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4748 gnus-sticky-article-mode-map)
4749 (substitute-key-definition 'gnus-article-refer-article 'undefined
4750 gnus-sticky-article-mode-map)
4751 (dolist (k '("e" "h" "s" "F" "R"))
4752 (define-key gnus-sticky-article-mode-map k nil))
4753 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4754 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4755 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4756 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4758 (defun gnus-sticky-article (arg)
4759 "Make the current article sticky.
4760 If a prefix ARG is given, ask for a name for this sticky article buffer."
4761 (interactive "P")
4762 (gnus-summary-show-thread)
4763 (gnus-summary-select-article nil nil 'pseudo)
4764 (let (new-art-buf-name)
4765 (gnus-eval-in-buffer-window gnus-article-buffer
4766 (setq new-art-buf-name
4767 (concat
4768 "*Sticky Article: "
4769 (if arg
4770 (read-from-minibuffer "Sticky article buffer name: ")
4771 (gnus-with-article-headers
4772 (gnus-article-goto-header "subject")
4773 (setq new-art-buf-name
4774 (buffer-substring-no-properties
4775 (line-beginning-position) (line-end-position)))
4776 (goto-char (point-min))
4777 (gnus-article-goto-header "from")
4778 (setq new-art-buf-name
4779 (concat
4780 new-art-buf-name ", "
4781 (buffer-substring-no-properties
4782 (line-beginning-position) (line-end-position))))
4783 (goto-char (point-min))
4784 (gnus-article-goto-header "date")
4785 (setq new-art-buf-name
4786 (concat
4787 new-art-buf-name ", "
4788 (buffer-substring-no-properties
4789 (line-beginning-position) (line-end-position))))))
4790 "*"))
4791 (if (and (gnus-buffer-live-p new-art-buf-name)
4792 (with-current-buffer new-art-buf-name
4793 (derived-mode-p 'gnus-sticky-article-mode)))
4794 (switch-to-buffer new-art-buf-name)
4795 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4796 (gnus-sticky-article-mode))
4797 (setq gnus-article-buffer new-art-buf-name))
4798 (gnus-summary-recenter)
4799 (gnus-summary-position-point))
4801 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4802 "Kill the given sticky article BUFFER.
4803 If none is given, assume the current buffer and kill it if it has
4804 `gnus-sticky-article-mode'."
4805 (interactive)
4806 (unless buffer
4807 (setq buffer (current-buffer)))
4808 (with-current-buffer buffer
4809 (when (derived-mode-p 'gnus-sticky-article-mode)
4810 (gnus-kill-buffer buffer))))
4812 (defun gnus-kill-sticky-article-buffers (arg)
4813 "Kill all sticky article buffers.
4814 If a prefix ARG is given, ask for confirmation."
4815 (interactive "P")
4816 (dolist (buf (gnus-buffers))
4817 (with-current-buffer buf
4818 (when (derived-mode-p 'gnus-sticky-article-mode)
4819 (if (not arg)
4820 (gnus-kill-buffer buf)
4821 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4822 (gnus-kill-buffer buf)))))))
4825 ;;; Gnus MIME viewing functions
4828 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4829 "Format of the MIME buttons.
4831 Valid specifiers include:
4832 %t The MIME type
4833 %T MIME type, along with additional info
4834 %n The `name' parameter
4835 %d The description, if any
4836 %l The length of the encoded part
4837 %p The part identifier number
4838 %e Dots if the part isn't displayed
4840 General format specifiers can also be used. See Info node
4841 `(gnus)Formatting Variables'.")
4843 (defvar gnus-mime-button-line-format-alist
4844 '((?t gnus-tmp-type ?s)
4845 (?T gnus-tmp-type-long ?s)
4846 (?n gnus-tmp-name ?s)
4847 (?d gnus-tmp-description ?s)
4848 (?p gnus-tmp-id ?s)
4849 (?l gnus-tmp-length ?d)
4850 (?e gnus-tmp-dots ?s)))
4852 (defvar gnus-mime-button-commands
4853 '((gnus-article-press-button "\r" "Toggle Display")
4854 (gnus-mime-view-part "v" "View Interactively...")
4855 (gnus-mime-view-part-as-type "t" "View As Type...")
4856 (gnus-mime-view-part-as-charset "C" "View As charset...")
4857 (gnus-mime-save-part "o" "Save...")
4858 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4859 (gnus-mime-replace-part "r" "Replace part")
4860 (gnus-mime-delete-part "d" "Delete part")
4861 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4862 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4863 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4864 (gnus-mime-view-part-externally "e" "View Externally")
4865 (gnus-mime-print-part "p" "Print")
4866 (gnus-mime-pipe-part "|" "Pipe To Command...")
4867 (gnus-mime-action-on-part "." "Take action on the part...")))
4869 (defun gnus-article-mime-part-status ()
4870 (if gnus-article-mime-handle-alist-1
4871 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4872 " (1 part)"
4873 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4874 ""))
4876 (defvar gnus-mime-button-map
4877 (let ((map (make-sparse-keymap)))
4878 (define-key map gnus-mouse-2 'gnus-article-push-button)
4879 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4880 (dolist (c gnus-mime-button-commands)
4881 (define-key map (cadr c) (car c)))
4882 map))
4884 (easy-menu-define
4885 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4886 `("MIME Part"
4887 ,@(mapcar (lambda (c)
4888 (vector (caddr c) (car c) :active t))
4889 gnus-mime-button-commands)))
4891 (defvar gnus-url-button-commands
4892 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4894 (defvar gnus-url-button-map
4895 (let ((map (make-sparse-keymap)))
4896 (dolist (c gnus-url-button-commands)
4897 (define-key map (cadr c) (car c)))
4898 map))
4900 (easy-menu-define
4901 gnus-url-button-menu gnus-url-button-map "URL button menu."
4902 `("Url Button"
4903 ,@(mapcar (lambda (c)
4904 (vector (caddr c) (car c) :active t))
4905 gnus-url-button-commands)))
4907 (defmacro gnus-bind-safe-url-regexp (&rest body)
4908 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4909 `(let ((mm-w3m-safe-url-regexp
4910 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4911 (gnus-buffer-live-p
4912 gnus-article-current-summary))
4913 (with-current-buffer gnus-article-current-summary
4914 gnus-newsgroup-name)
4915 gnus-newsgroup-name)))
4916 (if (cond ((not group)
4917 ;; Maybe we're in a mml-preview buffer
4918 ;; and no group is selected.
4920 ((stringp gnus-safe-html-newsgroups)
4921 (string-match gnus-safe-html-newsgroups group))
4922 ((consp gnus-safe-html-newsgroups)
4923 (member group gnus-safe-html-newsgroups)))
4925 mm-w3m-safe-url-regexp))))
4926 ,@body))
4928 (defun gnus-mime-button-menu (event prefix)
4929 "Construct a context-sensitive menu of MIME commands."
4930 (interactive "e\nP")
4931 (save-window-excursion
4932 (let ((pos (event-start event)))
4933 (select-window (posn-window pos))
4934 (goto-char (posn-point pos))
4935 (gnus-article-check-buffer)
4936 (popup-menu gnus-mime-button-menu nil prefix))))
4938 (defun gnus-mime-view-all-parts (&optional handles)
4939 "View all the MIME parts."
4940 (interactive)
4941 (with-current-buffer gnus-article-buffer
4942 (let ((handles (or handles gnus-article-mime-handles))
4943 (mail-parse-charset gnus-newsgroup-charset)
4944 (mail-parse-ignored-charsets
4945 (with-current-buffer gnus-summary-buffer
4946 gnus-newsgroup-ignored-charsets)))
4947 (when handles
4948 (mm-remove-parts handles)
4949 (goto-char (point-min))
4950 (or (search-forward "\n\n") (goto-char (point-max)))
4951 (let ((inhibit-read-only t))
4952 (delete-region (point) (point-max))
4953 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4955 (defun gnus-article-jump-to-part (n)
4956 "Jump to MIME part N."
4957 (interactive "P")
4958 (let ((parts (with-current-buffer gnus-article-buffer
4959 (length gnus-article-mime-handle-alist))))
4960 (when (zerop parts)
4961 (error "No such part"))
4962 (pop-to-buffer gnus-article-buffer)
4963 (or n
4964 (setq n (if (= parts 1)
4966 (read-number (format "Jump to part (1..%s): " parts)))))
4967 (unless (and (integerp n) (<= n parts) (>= n 1))
4968 (setq n
4969 (progn
4970 (gnus-message 7 "Invalid part `%s', using %s instead."
4971 n parts)
4972 parts)))
4973 (gnus-message 9 "Jumping to part %s." n)
4974 (cond ((>= gnus-auto-select-part 1)
4975 (while (and (<= n parts)
4976 (not (gnus-article-goto-part n)))
4977 (setq n (1+ n))))
4978 ((< gnus-auto-select-part 0)
4979 (while (and (>= n 1)
4980 (not (gnus-article-goto-part n)))
4981 (setq n (1- n))))
4983 (gnus-article-goto-part n)))))
4985 (defvar gnus-mime-buttonized-part-id nil
4986 "ID of a mime part that should be buttonized.
4987 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4989 (eval-when-compile
4990 (defsubst gnus-article-edit-part (handles &optional current-id)
4991 "Edit an article in order to delete a mime part.
4992 This function is exclusively used by `gnus-mime-save-part-and-strip'
4993 and `gnus-mime-delete-part', and not provided at run-time normally."
4994 (gnus-article-edit-article
4995 `(lambda ()
4996 (buffer-disable-undo)
4997 (let ((mail-parse-charset (or gnus-article-charset
4998 ',gnus-newsgroup-charset))
4999 (mail-parse-ignored-charsets
5000 (or gnus-article-ignored-charsets
5001 ',gnus-newsgroup-ignored-charsets))
5002 (mbl mml-buffer-list))
5003 (setq mml-buffer-list nil)
5004 ;; A new text must be inserted before deleting existing ones
5005 ;; at the end so as not to move existing markers of which
5006 ;; the insertion type is t.
5007 (delete-region
5008 (point-min)
5009 (prog1
5010 (goto-char (point-max))
5011 (insert-buffer-substring gnus-original-article-buffer)))
5012 (mime-to-mml ',handles)
5013 (setq gnus-article-mime-handles nil)
5014 (let ((mbl1 mml-buffer-list))
5015 (setq mml-buffer-list mbl)
5016 (set (make-local-variable 'mml-buffer-list) mbl1))
5017 (gnus-make-local-hook 'kill-buffer-hook)
5018 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5019 `(lambda (no-highlight)
5020 (let ((mail-parse-charset (or gnus-article-charset
5021 ',gnus-newsgroup-charset))
5022 (message-options message-options)
5023 (message-options-set-recipient)
5024 (mail-parse-ignored-charsets
5025 (or gnus-article-ignored-charsets
5026 ',gnus-newsgroup-ignored-charsets)))
5027 (mml-to-mime)
5028 (mml-destroy-buffers)
5029 (remove-hook 'kill-buffer-hook
5030 'mml-destroy-buffers t)
5031 (kill-local-variable 'mml-buffer-list))
5032 (gnus-summary-edit-article-done
5033 ,(or (mail-header-references gnus-current-headers) "")
5034 ,(gnus-group-read-only-p)
5035 ,gnus-summary-buffer no-highlight))
5037 ;; Force buttonizing this part.
5038 (let ((gnus-mime-buttonized-part-id current-id))
5039 (gnus-article-edit-done))
5040 (gnus-configure-windows 'article)
5041 (when (and current-id (integerp gnus-auto-select-part))
5042 (gnus-article-jump-to-part
5043 (min (max (+ current-id gnus-auto-select-part) 1)
5044 (with-current-buffer gnus-article-buffer
5045 (length gnus-article-mime-handle-alist)))))))
5047 (defun gnus-mime-replace-part (file)
5048 "Replace MIME part under point with an external body."
5049 ;; Useful if file has already been saved to disk
5050 (interactive
5051 (list
5052 (read-file-name "Replace MIME part with file: "
5053 (or mm-default-directory default-directory)
5054 nil nil)))
5055 (gnus-mime-save-part-and-strip file))
5057 (defun gnus-mime-save-part-and-strip (&optional file)
5058 "Save the MIME part under point then replace it with an external body.
5059 If FILE is given, use it for the external part."
5060 (interactive)
5061 (gnus-article-check-buffer)
5062 (when (gnus-group-read-only-p)
5063 (error "The current group does not support deleting of parts"))
5064 (when (mm-complicated-handles gnus-article-mime-handles)
5065 (error "\
5066 The current article has a complicated MIME structure, giving up..."))
5067 (let* ((data (get-text-property (point) 'gnus-data))
5068 (id (get-text-property (point) 'gnus-part))
5069 param
5070 (handles gnus-article-mime-handles))
5071 (unless file
5072 (setq file
5073 (and data (mm-save-part data "Delete MIME part and save to: "))))
5074 (when file
5075 (with-current-buffer (mm-handle-buffer data)
5076 (erase-buffer)
5077 (insert "Content-Type: " (mm-handle-media-type data))
5078 (mml-insert-parameter-string (cdr (mm-handle-type data))
5079 '(charset))
5080 ;; Add a filename for the sake of saving the part again.
5081 (mml-insert-parameter
5082 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5083 (insert "\n")
5084 (insert "Content-ID: " (message-make-message-id) "\n")
5085 (insert "Content-Transfer-Encoding: binary\n")
5086 (insert "\n"))
5087 (setcdr data
5088 (cdr (mm-make-handle nil
5089 `("message/external-body"
5090 (access-type . "LOCAL-FILE")
5091 (name . ,file)))))
5092 ;; (set-buffer gnus-summary-buffer)
5093 (gnus-article-edit-part handles id))))
5095 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5096 ;; parts...>') but with stripping would be nice.
5098 (defun gnus-mime-delete-part ()
5099 "Delete the MIME part under point.
5100 Replace it with some information about the removed part."
5101 (interactive)
5102 (gnus-article-check-buffer)
5103 (when (gnus-group-read-only-p)
5104 (error "The current group does not support deleting of parts"))
5105 (when (mm-complicated-handles gnus-article-mime-handles)
5106 (error "\
5107 The current article has a complicated MIME structure, giving up..."))
5108 (when (or gnus-expert-user
5109 (gnus-yes-or-no-p "\
5110 Deleting parts may malfunction or destroy the article; continue? "))
5111 (let* ((data (get-text-property (point) 'gnus-data))
5112 (id (get-text-property (point) 'gnus-part))
5113 (handles gnus-article-mime-handles)
5114 (description
5115 (let ((desc (mm-handle-description data)))
5116 (when desc
5117 (mail-decode-encoded-word-string desc))))
5118 (filename (or (mm-handle-filename data) "(none)"))
5119 (type (mm-handle-media-type data)))
5120 (unless data
5121 (error "No MIME part under point"))
5122 (with-current-buffer (mm-handle-buffer data)
5123 (let ((bsize (buffer-size)))
5124 (erase-buffer)
5125 (insert
5126 (concat
5127 ",----\n"
5128 "| The following attachment has been deleted:\n"
5129 "|\n"
5130 "| Type: " type "\n"
5131 "| Filename: " filename "\n"
5132 "| Size (encoded): " (format "%s byte%s\n"
5133 bsize (if (= bsize 1)
5135 "s"))
5136 (when description
5137 (concat "| Description: " description "\n"))
5138 "`----\n"))
5139 (setcdr data
5140 (cdr (mm-make-handle
5141 nil `("text/plain" (charset . gnus-decoded)) nil nil
5142 (list "attachment")
5143 (format "Deleted attachment (%s bytes)" bsize))))))
5144 ;; (set-buffer gnus-summary-buffer)
5145 (gnus-article-edit-part handles id))))
5147 (defun gnus-mime-save-part ()
5148 "Save the MIME part under point."
5149 (interactive)
5150 (gnus-article-check-buffer)
5151 (let ((data (get-text-property (point) 'gnus-data)))
5152 (when data
5153 (mm-save-part data))))
5155 (defun gnus-mime-pipe-part (&optional cmd)
5156 "Pipe the MIME part under point to a process.
5157 Use CMD as the process."
5158 (interactive)
5159 (gnus-article-check-buffer)
5160 (let ((data (get-text-property (point) 'gnus-data)))
5161 (when data
5162 (mm-pipe-part data cmd))))
5164 (defun gnus-mime-view-part ()
5165 "Interactively choose a viewing method for the MIME part under point."
5166 (interactive)
5167 (gnus-article-check-buffer)
5168 (let ((data (get-text-property (point) 'gnus-data)))
5169 (when data
5170 (setq gnus-article-mime-handles
5171 (mm-merge-handles
5172 gnus-article-mime-handles (setq data (copy-sequence data))))
5173 (mm-interactively-view-part data))))
5175 (defun gnus-mime-view-part-as-type-internal ()
5176 (gnus-article-check-buffer)
5177 (let* ((handle (get-text-property (point) 'gnus-data))
5178 (name (or
5179 ;; Content-Type: foo/bar; name=...
5180 (mail-content-type-get (mm-handle-type handle) 'name)
5181 ;; Content-Disposition: attachment; filename=...
5182 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5183 (def-type (and name (mm-default-file-encoding name))))
5184 (or (and def-type (cons def-type 0))
5185 (and handle
5186 (equal (mm-handle-media-supertype handle) "text")
5187 '("text/plain" . 0))
5188 '("application/octet-stream" . 0))))
5190 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5191 "Choose a MIME media type, and view the part as such.
5192 If non-nil, PRED is a predicate to use during completion to limit the
5193 available media-types."
5194 (interactive)
5195 (unless mime-type
5196 (setq mime-type
5197 (let ((default (gnus-mime-view-part-as-type-internal)))
5198 (gnus-completing-read
5199 "View as MIME type"
5200 (if pred
5201 (gnus-remove-if-not pred (mailcap-mime-types))
5202 (mailcap-mime-types))
5203 nil nil nil
5204 (car default)))))
5205 (gnus-article-check-buffer)
5206 (let ((handle (get-text-property (point) 'gnus-data)))
5207 (when handle
5208 (when (equal (mm-handle-media-type handle) "message/external-body")
5209 (unless (mm-handle-cache handle)
5210 (mm-extern-cache-contents handle))
5211 (setq handle (mm-handle-cache handle)))
5212 (setq handle
5213 (mm-make-handle (mm-handle-buffer handle)
5214 (cons mime-type (cdr (mm-handle-type handle)))
5215 (mm-handle-encoding handle)
5216 (mm-handle-undisplayer handle)
5217 (mm-handle-disposition handle)
5218 (mm-handle-description handle)
5220 (mm-handle-id handle)))
5221 (setq gnus-article-mime-handles
5222 (mm-merge-handles gnus-article-mime-handles handle))
5223 (when (mm-handle-displayed-p handle)
5224 (mm-remove-part handle))
5225 (gnus-mm-display-part handle))))
5227 (defun gnus-mime-copy-part (&optional handle arg)
5228 "Put the MIME part under point into a new buffer.
5229 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5230 are decompressed."
5231 (interactive (list nil current-prefix-arg))
5232 (gnus-article-check-buffer)
5233 (unless handle
5234 (setq handle (get-text-property (point) 'gnus-data)))
5235 (when handle
5236 (let ((filename (mm-handle-filename handle))
5237 contents dont-decode charset coding-system)
5238 (mm-with-unibyte-buffer
5239 (mm-insert-part handle)
5240 (setq contents (or (condition-case nil
5241 (mm-decompress-buffer filename nil 'sig)
5242 (error
5243 (setq dont-decode t)
5244 nil))
5245 (buffer-string))))
5246 (setq filename (cond (filename (file-name-nondirectory filename))
5247 (dont-decode "*raw data*")
5248 (t "*decoded*")))
5249 (cond
5250 (dont-decode)
5251 ((not arg)
5252 (unless (setq charset (mail-content-type-get
5253 (mm-handle-type handle) 'charset))
5254 (unless (setq coding-system (mm-with-unibyte-buffer
5255 (insert contents)
5256 (mm-find-buffer-file-coding-system)))
5257 (setq charset gnus-newsgroup-charset))))
5258 ((numberp arg)
5259 (setq charset (or (cdr (assq arg
5260 gnus-summary-show-article-charset-alist))
5261 (mm-read-coding-system "Charset: ")))))
5262 (switch-to-buffer (generate-new-buffer filename))
5263 (if (or coding-system
5264 (and charset
5265 (setq coding-system (mm-charset-to-coding-system
5266 charset nil t))
5267 (not (eq coding-system 'ascii))))
5268 (progn
5269 (mm-enable-multibyte)
5270 (insert (mm-decode-coding-string contents coding-system))
5271 (setq buffer-file-coding-system
5272 (if (boundp 'last-coding-system-used)
5273 (symbol-value 'last-coding-system-used)
5274 coding-system)))
5275 (mm-disable-multibyte)
5276 (insert contents)
5277 (setq buffer-file-coding-system mm-binary-coding-system))
5278 ;; We do it this way to make `normal-mode' set the appropriate mode.
5279 (unwind-protect
5280 (progn
5281 (setq buffer-file-name (expand-file-name filename))
5282 (normal-mode))
5283 (setq buffer-file-name nil))
5284 (goto-char (point-min)))))
5286 (defun gnus-mime-print-part (&optional handle filename)
5287 "Print the MIME part under point."
5288 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5289 (gnus-article-check-buffer)
5290 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5291 (contents (and handle (mm-get-part handle)))
5292 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5293 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5294 (when contents
5295 (if printer
5296 (unwind-protect
5297 (progn
5298 (mm-save-part-to-file handle file)
5299 (call-process shell-file-name nil
5300 (generate-new-buffer " *mm*")
5302 shell-command-switch
5303 (mm-mailcap-command
5304 printer file (mm-handle-type handle))))
5305 (delete-file file))
5306 (with-temp-buffer
5307 (insert contents)
5308 (gnus-print-buffer))
5309 (ps-despool filename)))))
5311 (defun gnus-mime-inline-part (&optional handle arg)
5312 "Insert the MIME part under point into the current buffer.
5313 Compressed files like .gz and .bz2 are decompressed."
5314 (interactive (list nil current-prefix-arg))
5315 (gnus-article-check-buffer)
5316 (let* ((inhibit-read-only t)
5317 (b (point))
5318 (btn ;; position where the MIME button exists
5319 (if handle
5320 (if (eq handle (get-text-property b 'gnus-data))
5322 (article-goto-body)
5323 (or (text-property-any (point) (point-max) 'gnus-data handle)
5324 (text-property-any (point-min) (point) 'gnus-data handle)))
5325 (setq handle (get-text-property b 'gnus-data))
5327 start contents charset coding-system)
5328 (when handle
5329 (when (= b (prog1
5331 (setq start (next-single-property-change btn 'gnus-data
5332 nil (point-max))
5333 btn (previous-single-property-change start
5334 'gnus-data))))
5335 (setq b btn))
5336 (if (and (not arg) (mm-handle-undisplayer handle))
5337 (mm-remove-part handle)
5338 (mm-with-unibyte-buffer
5339 (mm-insert-part handle)
5340 (setq contents
5341 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5342 (buffer-string))))
5343 (cond
5344 ((not arg)
5345 (unless (setq charset (mail-content-type-get
5346 (mm-handle-type handle) 'charset))
5347 (unless (setq coding-system
5348 (mm-with-unibyte-buffer
5349 (insert contents)
5350 (mm-find-buffer-file-coding-system)))
5351 (setq charset gnus-newsgroup-charset))))
5352 ((numberp arg)
5353 (if (mm-handle-undisplayer handle)
5354 (mm-remove-part handle))
5355 (setq charset
5356 (or (cdr (assq arg
5357 gnus-summary-show-article-charset-alist))
5358 (mm-read-coding-system "Charset: "))))
5359 ((mm-handle-undisplayer handle)
5360 (mm-remove-part handle)))
5361 (goto-char start)
5362 (unless (bolp)
5363 ;; This is a header button.
5364 (forward-line 1))
5365 (mm-display-inline handle))
5366 ;; Toggle the button appearance between `[button]...' and `[button]'.
5367 (goto-char btn)
5368 (let ((displayed-p (mm-handle-displayed-p handle)))
5369 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5370 (list displayed-p))
5371 (if (featurep 'emacs)
5372 (delete-region
5373 (point)
5374 (next-single-property-change (point) 'gnus-data nil (point-max)))
5375 (let* ((end (next-single-property-change (point) 'gnus-data))
5376 (annots (annotations-at (or end (point-max)))))
5377 (delete-region (point)
5378 (if end
5379 (if annots (1+ end) end)
5380 (point-max)))
5381 (dolist (annot annots)
5382 (set-extent-endpoints annot (point) (point)))))
5383 (setq start (point))
5384 (if (search-backward "\n\n" nil t)
5385 (progn
5386 (goto-char start)
5387 (unless (or displayed-p (eolp))
5388 ;; Add extra newline.
5389 (insert (propertize (buffer-substring (1- start) start)
5390 'gnus-undeletable t))))
5391 ;; We're in the article header.
5392 (delete-char -1)
5393 (dolist (ovl (gnus-overlays-in btn (point)))
5394 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5395 (gnus-overlay-put ovl 'face nil))
5396 (save-restriction
5397 (message-narrow-to-field)
5398 (let ((gnus-treatment-function-alist
5399 '((gnus-treat-highlight-headers
5400 gnus-article-highlight-headers))))
5401 (gnus-treat-article 'head)))))
5402 (goto-char b))))
5404 (defun gnus-mime-set-charset-parameters (handle charset)
5405 "Set CHARSET to parameters in HANDLE.
5406 CHARSET may either be a string or a symbol."
5407 (unless (stringp charset)
5408 (setq charset (symbol-name charset)))
5409 (if (stringp (car handle))
5410 (dolist (h (cdr handle))
5411 (gnus-mime-set-charset-parameters h charset))
5412 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5413 "message/external-body")
5414 (progn
5415 (unless (mm-handle-cache handle)
5416 (mm-extern-cache-contents handle))
5417 (mm-handle-cache handle))
5418 handle)))
5419 (param (assq 'charset (cdr type))))
5420 (if param
5421 (setcdr param charset)
5422 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5424 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5425 "Insert the MIME part under point into the current buffer using the
5426 specified charset."
5427 (interactive (list nil current-prefix-arg))
5428 (gnus-article-check-buffer)
5429 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5430 (fun (get-text-property (point) 'gnus-callback))
5431 (gnus-newsgroup-ignored-charsets 'gnus-all)
5432 charset form preferred parts)
5433 (when handle
5434 (when (prog1
5435 (and fun
5436 (setq charset
5437 (or (cdr (assq
5439 gnus-summary-show-article-charset-alist))
5440 (mm-read-coding-system "Charset: "))))
5441 (if (mm-handle-undisplayer handle)
5442 (mm-remove-part handle)))
5443 (gnus-mime-set-charset-parameters handle charset)
5444 (when (and (consp (setq form (cdr-safe fun)))
5445 (setq form (ignore-errors
5446 (assq 'gnus-mime-display-alternative form)))
5447 (setq preferred (caddr form))
5448 (progn
5449 (when (eq (car preferred) 'quote)
5450 (setq preferred (cadr preferred)))
5451 (not (equal preferred
5452 (get-text-property (point) 'gnus-data))))
5453 (setq parts (get-text-property (point) 'gnus-part))
5454 (setq parts (cdr (assq parts
5455 gnus-article-mime-handle-alist)))
5456 (equal (mm-handle-media-type parts) "multipart/alternative")
5457 (setq parts (reverse (cdr parts))))
5458 (setcar (cddr form)
5459 (list 'quote (or (cadr (member preferred parts))
5460 (car parts)))))
5461 (funcall fun handle)))))
5463 (defun gnus-mime-view-part-externally (&optional handle)
5464 "View the MIME part under point with an external viewer."
5465 (interactive)
5466 (gnus-article-check-buffer)
5467 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5468 (mm-user-display-methods nil)
5469 (mm-inlined-types nil)
5470 (mail-parse-charset gnus-newsgroup-charset)
5471 (mail-parse-ignored-charsets
5472 (with-current-buffer gnus-summary-buffer
5473 gnus-newsgroup-ignored-charsets))
5474 (type (mm-handle-media-type handle))
5475 (method (mailcap-mime-info type))
5476 (mm-enable-external t))
5477 (if (not (stringp method))
5478 (gnus-mime-view-part-as-type
5479 nil (lambda (type) (stringp (mailcap-mime-info type))))
5480 (when handle
5481 (mm-display-part handle nil t)))))
5483 (defun gnus-mime-view-part-internally (&optional handle)
5484 "View the MIME part under point with an internal viewer.
5485 If no internal viewer is available, use an external viewer."
5486 (interactive)
5487 (gnus-article-check-buffer)
5488 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5489 (mm-inlined-types '(".*"))
5490 (mm-inline-large-images t)
5491 (mail-parse-charset gnus-newsgroup-charset)
5492 (mail-parse-ignored-charsets
5493 (with-current-buffer gnus-summary-buffer
5494 gnus-newsgroup-ignored-charsets))
5495 (inhibit-read-only t))
5496 (if (not (mm-inlinable-p handle))
5497 (gnus-mime-view-part-as-type
5498 nil (lambda (type) (mm-inlinable-p handle type)))
5499 (when handle
5500 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5502 (defun gnus-mime-action-on-part (&optional action)
5503 "Do something with the MIME attachment at \(point\)."
5504 (interactive
5505 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5506 (gnus-article-check-buffer)
5507 (let ((action-pair (assoc action gnus-mime-action-alist)))
5508 (if action-pair
5509 (funcall (cdr action-pair)))))
5511 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5512 "Call FUNCTION on MIME part N.
5513 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5514 If INTERACTIVE, call FUNCTION interactively."
5515 (let (window frame)
5516 ;; Check whether the article is displayed.
5517 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5518 (setq window (get-buffer-window gnus-article-buffer t))
5519 (frame-visible-p (setq frame (window-frame window))))
5520 (error "No article is displayed"))
5521 (with-current-buffer gnus-article-buffer
5522 ;; Check whether the article displays the right contents.
5523 (unless (with-current-buffer gnus-summary-buffer
5524 (eq gnus-current-article (gnus-summary-article-number)))
5525 (error "You should select the right article first"))
5526 (if n
5527 (setq n (prefix-numeric-value n))
5528 (let ((pt (point)))
5529 (setq n (or (get-text-property pt 'gnus-part)
5530 (and (not (bobp))
5531 (get-text-property (1- pt) 'gnus-part))
5532 (get-text-property (prog2
5533 (forward-line 1)
5534 (point)
5535 (goto-char pt))
5536 'gnus-part)
5537 (get-text-property
5538 (or (and (setq pt (previous-single-property-change
5539 pt 'gnus-part))
5540 (1- pt))
5541 (next-single-property-change (point) 'gnus-part)
5542 (point))
5543 'gnus-part)
5544 1))))
5545 ;; Check whether the specified part exists.
5546 (when (> n (length gnus-article-mime-handle-alist))
5547 (error "No such part")))
5548 (unless
5549 (progn
5550 ;; To select the window is needed so that the cursor
5551 ;; might be visible on the MIME button.
5552 (select-window (prog1
5553 window
5554 (setq window (selected-window))
5555 ;; Article may be displayed in the other frame.
5556 (gnus-select-frame-set-input-focus
5557 (prog1
5558 frame
5559 (setq frame (selected-frame))))))
5560 (when (gnus-article-goto-part n)
5561 ;; We point the cursor and the arrow at the MIME button
5562 ;; when the `function' prompt the user for something.
5563 (unless (and (pos-visible-in-window-p)
5564 (> (count-lines (point) (window-end))
5565 (/ (1- (window-height)) 3)))
5566 (recenter (/ (1- (window-height)) 3)))
5567 (let ((cursor-in-non-selected-windows t)
5568 (overlay-arrow-string "=>")
5569 (overlay-arrow-position (point-marker)))
5570 (unwind-protect
5571 (cond
5572 ((and no-handle interactive)
5573 (call-interactively function))
5574 (no-handle
5575 (funcall function))
5576 (interactive
5577 (call-interactively
5578 function (get-text-property (point) 'gnus-data)))
5580 (funcall function
5581 (get-text-property (point) 'gnus-data))))
5582 (set-marker overlay-arrow-position nil)
5583 (unless gnus-auto-select-part
5584 (gnus-select-frame-set-input-focus frame)
5585 (select-window window))))
5587 (if gnus-inhibit-mime-unbuttonizing
5588 ;; This is the default though the program shouldn't reach here.
5589 (error "No such part")
5590 ;; The part which doesn't have the MIME button is selected.
5591 ;; So, we display all the buttons and redo it.
5592 (let ((gnus-inhibit-mime-unbuttonizing t))
5593 (gnus-summary-show-article)
5594 (gnus-article-part-wrapper n function no-handle))))))
5596 (defun gnus-article-pipe-part (n)
5597 "Pipe MIME part N, which is the numerical prefix."
5598 (interactive "P")
5599 (gnus-article-part-wrapper n 'mm-pipe-part))
5601 (defun gnus-article-save-part (n)
5602 "Save MIME part N, which is the numerical prefix."
5603 (interactive "P")
5604 (gnus-article-part-wrapper n 'mm-save-part))
5606 (defun gnus-article-interactively-view-part (n)
5607 "View MIME part N interactively, which is the numerical prefix."
5608 (interactive "P")
5609 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5611 (defun gnus-article-copy-part (n)
5612 "Copy MIME part N, which is the numerical prefix."
5613 (interactive "P")
5614 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5616 (defun gnus-article-view-part-as-charset (n)
5617 "View MIME part N using a specified charset.
5618 N is the numerical prefix."
5619 (interactive "P")
5620 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5622 (defun gnus-article-view-part-externally (n)
5623 "View MIME part N externally, which is the numerical prefix."
5624 (interactive "P")
5625 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5627 (defun gnus-article-inline-part (n)
5628 "Inline MIME part N, which is the numerical prefix."
5629 (interactive "P")
5630 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5632 (defun gnus-article-save-part-and-strip (n)
5633 "Save MIME part N and replace it with an external body.
5634 N is the numerical prefix."
5635 (interactive "P")
5636 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5638 (defun gnus-article-replace-part (n)
5639 "Replace MIME part N with an external body.
5640 N is the numerical prefix."
5641 (interactive "P")
5642 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5644 (defun gnus-article-delete-part (n)
5645 "Delete MIME part N and add some information about the removed part.
5646 N is the numerical prefix."
5647 (interactive "P")
5648 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5650 (defun gnus-article-view-part-as-type (n)
5651 "Choose a MIME media type, and view part N as such.
5652 N is the numerical prefix."
5653 (interactive "P")
5654 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5656 (defun gnus-article-mime-match-handle-first (condition)
5657 (if condition
5658 (let (n)
5659 (dolist (ihandle gnus-article-mime-handle-alist)
5660 (if (and (cond
5661 ((functionp condition)
5662 (funcall condition (cdr ihandle)))
5663 ((eq condition 'undisplayed)
5664 (not (or (mm-handle-undisplayer (cdr ihandle))
5665 (equal (mm-handle-media-type (cdr ihandle))
5666 "multipart/alternative"))))
5667 ((eq condition 'undisplayed-alternative)
5668 (not (mm-handle-undisplayer (cdr ihandle))))
5669 (t t))
5670 (gnus-article-goto-part (car ihandle))
5671 (or (not n) (< (car ihandle) n)))
5672 (setq n (car ihandle))))
5673 (or n 1))
5676 (defun gnus-article-view-part (&optional n)
5677 "View MIME part N, which is the numerical prefix.
5678 If the part is already shown, hide the part. If N is nil, view
5679 all parts."
5680 (interactive "P")
5681 (with-current-buffer gnus-article-buffer
5682 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5683 gnus-article-mime-match-handle-function)))
5684 (when (> n (length gnus-article-mime-handle-alist))
5685 (error "No such part"))
5686 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5687 (when (gnus-article-goto-part n)
5688 (if (equal (car handle) "multipart/alternative")
5689 (progn
5690 (beginning-of-line) ;; Make it toggle subparts
5691 (gnus-article-press-button))
5692 (when (eq (gnus-mm-display-part handle) 'internal)
5693 (gnus-set-window-start)))))))
5695 (defsubst gnus-article-mime-total-parts ()
5696 (if (bufferp (car gnus-article-mime-handles))
5697 1 ;; single part
5698 (1- (length gnus-article-mime-handles))))
5700 (defun gnus-mm-display-part (handle)
5701 "Display HANDLE and fix MIME button."
5702 (let ((id (get-text-property (point) 'gnus-part))
5703 (point (point))
5704 (inhibit-read-only t)
5705 (window (selected-window))
5706 (mail-parse-charset gnus-newsgroup-charset)
5707 (mail-parse-ignored-charsets
5708 (if (gnus-buffer-live-p gnus-summary-buffer)
5709 (with-current-buffer gnus-summary-buffer
5710 gnus-newsgroup-ignored-charsets)
5711 nil))
5712 start retval)
5713 (unwind-protect
5714 (progn
5715 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5716 (when win
5717 (select-window win)
5718 (goto-char point)))
5719 (setq start (next-single-property-change point 'gnus-data
5720 nil (point-max))
5721 point (previous-single-property-change start 'gnus-data))
5722 (if (mm-handle-displayed-p handle)
5723 ;; This will remove the part.
5724 (setq retval (mm-display-part handle))
5725 (let ((part (or (and (mm-inlinable-p handle)
5726 (mm-inlined-p handle)
5728 (with-temp-buffer
5729 (gnus-bind-safe-url-regexp
5730 (setq retval (mm-display-part handle)))
5731 (unless (zerop (buffer-size))
5732 (buffer-string))))))
5733 (goto-char start)
5734 (unless (bolp)
5735 ;; This is a header button.
5736 (forward-line 1))
5737 (cond ((stringp part)
5738 (save-restriction
5739 (narrow-to-region (point)
5740 (progn
5741 (insert part)
5742 (unless (bolp) (insert "\n"))
5743 (point)))
5744 (gnus-treat-article nil id
5745 (gnus-article-mime-total-parts)
5746 (mm-handle-media-type handle))
5747 (mm-handle-set-undisplayer
5748 handle
5749 `(lambda ()
5750 (let ((inhibit-read-only t))
5751 (delete-region ,(copy-marker (point-min) t)
5752 ,(point-max-marker)))))))
5753 (part
5754 (mm-display-inline handle))))))
5755 (goto-char point)
5756 ;; Toggle the button appearance between `[button]...' and `[button]'.
5757 (let ((displayed-p (mm-handle-displayed-p handle)))
5758 (gnus-insert-mime-button handle id (list displayed-p))
5759 (if (featurep 'emacs)
5760 (delete-region
5761 (point)
5762 (next-single-property-change (point) 'gnus-data nil (point-max)))
5763 (let* ((end (next-single-property-change (point) 'gnus-data))
5764 (annots (annotations-at (or end (point-max)))))
5765 (delete-region (point)
5766 (if end
5767 (if annots (1+ end) end)
5768 (point-max)))
5769 (dolist (annot annots)
5770 (set-extent-endpoints annot (point) (point)))))
5771 (setq start (point))
5772 (if (search-backward "\n\n" nil t)
5773 (progn
5774 (goto-char start)
5775 (unless (or displayed-p (eolp))
5776 ;; Add extra newline.
5777 (insert (propertize (buffer-substring (1- start) start)
5778 'gnus-undeletable t))))
5779 ;; We're in the article header.
5780 (delete-char -1)
5781 (dolist (ovl (gnus-overlays-in point (point)))
5782 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5783 (gnus-overlay-put ovl 'face nil))
5784 (save-restriction
5785 (message-narrow-to-field)
5786 (let ((gnus-treatment-function-alist
5787 '((gnus-treat-highlight-headers
5788 gnus-article-highlight-headers))))
5789 (gnus-treat-article 'head)))))
5790 (goto-char point)
5791 (if (window-live-p window)
5792 (select-window window)))
5793 retval))
5795 (defun gnus-article-goto-part (n)
5796 "Go to MIME part N."
5797 (when gnus-break-pages
5798 (widen))
5799 (article-goto-body)
5800 (prog1
5801 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5802 ;; There may be header buttons.
5803 (text-property-any (point-min) (point) 'gnus-part n)))
5804 part handle end next handles)
5805 (when start
5806 (goto-char start)
5807 (if (setq handle (get-text-property start 'gnus-data))
5808 start
5809 ;; Go to the displayed subpart, assuming this is
5810 ;; multipart/alternative.
5811 (setq part start
5812 end (point-at-eol))
5813 (while (and (not handle)
5814 part
5815 (< part end)
5816 (setq next (text-property-not-all part end
5817 'gnus-data nil)))
5818 (setq part next
5819 handle (get-text-property part 'gnus-data))
5820 (push (cons handle part) handles)
5821 (unless (mm-handle-displayed-p handle)
5822 (setq handle nil
5823 part (text-property-any part end 'gnus-data nil))))
5824 (unless handle
5825 ;; No subpart is displayed, so we find preferred one.
5826 (setq part
5827 (cdr (assq (mm-preferred-alternative
5828 (nreverse (mapcar 'car handles)))
5829 handles))))
5830 (if part
5831 (goto-char (1+ part))
5832 start))))
5833 (when gnus-break-pages
5834 (gnus-narrow-to-page))))
5836 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5837 (let ((gnus-tmp-name
5838 (or (mm-handle-filename handle)
5839 (mail-content-type-get (mm-handle-type handle) 'url)
5840 ""))
5841 (gnus-tmp-type (mm-handle-media-type handle))
5842 (gnus-tmp-description (or (mm-handle-description handle) ""))
5843 (gnus-tmp-dots
5844 (if (if displayed (car displayed)
5845 (mm-handle-displayed-p handle))
5846 "" "..."))
5847 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5848 (buffer-size)))
5849 gnus-tmp-type-long b e)
5850 (when (string-match ".*/" gnus-tmp-name)
5851 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5852 (setq gnus-tmp-type-long (concat gnus-tmp-type
5853 (and (not (equal gnus-tmp-name ""))
5854 (concat "; " gnus-tmp-name))))
5855 (unless (equal gnus-tmp-description "")
5856 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5857 (setq b (point))
5858 (gnus-eval-format
5859 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5860 `(keymap ,gnus-mime-button-map
5861 gnus-callback gnus-mm-display-part
5862 gnus-part ,gnus-tmp-id
5863 article-type annotation
5864 gnus-data ,handle
5865 rear-nonsticky t))
5866 (setq e (if (bolp)
5867 ;; Exclude a newline.
5868 (1- (point))
5869 (point)))
5870 (when gnus-article-button-face
5871 (gnus-overlay-put (gnus-make-overlay b e nil t)
5872 'face gnus-article-button-face))
5873 (widget-convert-button
5874 'link b e
5875 :mime-handle handle
5876 :action 'gnus-widget-press-button
5877 :button-keymap gnus-mime-button-map
5878 :help-echo
5879 (lambda (widget)
5880 ;; Needed to properly clear the message due to a bug in
5881 ;; wid-edit (XEmacs only).
5882 (if (boundp 'help-echo-owns-message)
5883 (setq help-echo-owns-message t))
5884 (format
5885 "%S: %s the MIME part; %S: more options"
5886 (aref gnus-mouse-2 0)
5887 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5888 "hide" "show")
5889 (aref gnus-down-mouse-3 0))))))
5891 (defun gnus-widget-press-button (elems el)
5892 (goto-char (widget-get elems :from))
5893 (gnus-article-press-button))
5895 (defvar gnus-displaying-mime nil)
5897 (defun gnus-display-mime (&optional ihandles)
5898 "Display the MIME parts."
5899 (save-excursion
5900 (save-selected-window
5901 (let ((window (get-buffer-window gnus-article-buffer))
5902 (point (point)))
5903 (when window
5904 (select-window window)
5905 ;; We have to do this since selecting the window
5906 ;; may change the point. So we set the window point.
5907 (set-window-point window point)))
5908 (let ((handles ihandles)
5909 (inhibit-read-only t)
5910 handle)
5911 (cond (handles)
5912 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5913 (when gnus-article-emulate-mime
5914 (mm-uu-dissect-text-parts handles)))
5915 (gnus-article-emulate-mime
5916 (setq handles (mm-uu-dissect))))
5917 (when (and (not ihandles)
5918 (not gnus-displaying-mime))
5919 ;; Top-level call; we clean up.
5920 (when gnus-article-mime-handles
5921 (mm-destroy-parts gnus-article-mime-handles)
5922 (setq gnus-article-mime-handle-alist nil));; A trick.
5923 (setq gnus-article-mime-handles handles)
5924 ;; We allow users to glean info from the handles.
5925 (when gnus-article-mime-part-function
5926 (gnus-mime-part-function handles)))
5927 (if (and handles
5928 (or (not (stringp (car handles)))
5929 (cdr handles)))
5930 (progn
5931 (when (and (not ihandles)
5932 (not gnus-displaying-mime))
5933 ;; Clean up for mime parts.
5934 (article-goto-body)
5935 (delete-region (point) (point-max)))
5936 (let ((gnus-displaying-mime t))
5937 (gnus-mime-display-part handles)))
5938 (save-restriction
5939 (article-goto-body)
5940 (narrow-to-region (point) (point-max))
5941 (gnus-treat-article nil 1 1 "text/plain")
5942 (widen)))
5943 (unless ihandles
5944 ;; Highlight the headers.
5945 (save-excursion
5946 (save-restriction
5947 (article-goto-body)
5948 (narrow-to-region (point-min) (point))
5949 (gnus-article-save-original-date
5950 (gnus-treat-article 'head)))))))
5951 ;; Cope with broken MIME messages.
5952 (goto-char (point-max))
5953 (unless (bolp)
5954 (insert "\n"))))
5956 (defcustom gnus-mime-display-multipart-as-mixed nil
5957 "Display \"multipart\" parts as \"multipart/mixed\".
5959 If t, it overrides nil values of
5960 `gnus-mime-display-multipart-alternative-as-mixed' and
5961 `gnus-mime-display-multipart-related-as-mixed'."
5962 :group 'gnus-article-mime
5963 :type 'boolean)
5965 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5966 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5967 :version "22.1"
5968 :group 'gnus-article-mime
5969 :type 'boolean)
5971 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5972 "Display \"multipart/related\" parts as \"multipart/mixed\".
5974 If displaying \"text/html\" is discouraged \(see
5975 `mm-discouraged-alternatives'\) images or other material inside a
5976 \"multipart/related\" part might be overlooked when this variable is nil."
5977 :version "22.1"
5978 :group 'gnus-article-mime
5979 :type 'boolean)
5981 (defcustom gnus-mime-display-attachment-buttons-in-header t
5982 "Add attachment buttons in the end of the header of an article.
5983 Since MIME attachments tend to be put at the end of an article, we may
5984 overlook them if there is a huge body. This option offers you a copy
5985 of all non-inlinable MIME parts as buttons shown in front of an article.
5986 If nil, don't show those extra buttons."
5987 :version "25.1"
5988 :group 'gnus-article-mime
5989 :type 'boolean)
5991 (defun gnus-mime-display-part (handle)
5992 (cond
5993 ;; Maybe a broken MIME message.
5994 ((null handle))
5995 ;; Single part.
5996 ((not (stringp (car handle)))
5997 (gnus-mime-display-single handle))
5998 ;; User-defined multipart
5999 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6000 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6001 handle))
6002 ;; multipart/alternative
6003 ((and (equal (car handle) "multipart/alternative")
6004 (not (or gnus-mime-display-multipart-as-mixed
6005 gnus-mime-display-multipart-alternative-as-mixed)))
6006 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6007 (push (cons id handle) gnus-article-mime-handle-alist)
6008 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6009 ;; multipart/related
6010 ((and (equal (car handle) "multipart/related")
6011 (not (or gnus-mime-display-multipart-as-mixed
6012 gnus-mime-display-multipart-related-as-mixed)))
6013 (gnus-mime-display-part (cadr handle)))
6014 ((equal (car handle) "multipart/signed")
6015 (gnus-add-wash-type 'signed)
6016 (gnus-mime-display-security handle))
6017 ((equal (car handle) "multipart/encrypted")
6018 (gnus-add-wash-type 'encrypted)
6019 (gnus-mime-display-security handle))
6020 ;; Other multiparts are handled like multipart/mixed.
6022 (gnus-mime-display-mixed (cdr handle)))))
6024 (defun gnus-mime-part-function (handles)
6025 (if (stringp (car handles))
6026 (mapcar 'gnus-mime-part-function (cdr handles))
6027 (funcall gnus-article-mime-part-function handles)))
6029 (defun gnus-mime-display-mixed (handles)
6030 (mapcar 'gnus-mime-display-part handles))
6032 (defun gnus-mime-display-single (handle)
6033 (let ((type (mm-handle-media-type handle))
6034 (ignored gnus-ignored-mime-types)
6035 (not-attachment t)
6036 display text)
6037 (catch 'ignored
6038 (progn
6039 (while ignored
6040 (when (string-match (pop ignored) type)
6041 (throw 'ignored nil)))
6042 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6043 (with-current-buffer gnus-summary-buffer
6044 gnus-inhibit-images)
6045 gnus-inhibit-images)
6046 (string-match "\\`image/" type)))
6047 (setq not-attachment
6048 (and (not (mm-inline-override-p handle))
6049 (or (not (mm-handle-disposition handle))
6050 (equal (car (mm-handle-disposition handle))
6051 "inline")
6052 (mm-attachment-override-p handle))))
6053 (mm-automatic-display-p handle)
6054 (or (and
6055 (mm-inlinable-p handle)
6056 (mm-inlined-p handle))
6057 (mm-automatic-external-display-p type)))
6058 (setq display t)
6059 (when (equal (mm-handle-media-supertype handle) "text")
6060 (setq text t)))
6061 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6062 beg)
6063 (unless id
6064 (setq id (1+ (length gnus-article-mime-handle-alist)))
6065 (push (cons id handle) gnus-article-mime-handle-alist))
6066 (when (and display
6067 (equal (mm-handle-media-supertype handle) "message"))
6068 (insert-char
6070 (cond ((not (bolp)) 2)
6071 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6072 (t 1))))
6073 (when (or (not display)
6074 (not (gnus-unbuttonized-mime-type-p type))
6075 (eq id gnus-mime-buttonized-part-id))
6076 (gnus-insert-mime-button
6077 handle id (list (or display (and not-attachment text)))))
6078 (setq beg (point))
6079 (cond
6080 (display
6081 (let ((mail-parse-charset gnus-newsgroup-charset)
6082 (mail-parse-ignored-charsets
6083 (save-excursion (condition-case ()
6084 (set-buffer gnus-summary-buffer)
6085 (error))
6086 gnus-newsgroup-ignored-charsets)))
6087 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6088 ((and text not-attachment)
6089 (mm-display-inline handle)))
6090 (goto-char (point-max))
6091 (if (string-match "\\`image/" type)
6092 (gnus-article-insert-newline)
6093 (if (prog1
6094 (= (skip-chars-backward "\n") -1)
6095 (forward-char 1))
6096 (gnus-article-insert-newline)
6097 (put-text-property (point) (point-max) 'gnus-undeletable t))
6098 (goto-char (point-max)))
6099 ;; Do highlighting.
6100 (save-excursion
6101 (save-restriction
6102 (narrow-to-region beg (point))
6103 (if (eq handle gnus-article-mime-handles)
6104 ;; The format=flowed case.
6105 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6106 ;; Don't count signature parts that are never displayed.
6107 ;; The part number should be re-calculated supposing this
6108 ;; might be a message/rfc822 part.
6109 (let (handles)
6110 (dolist (part gnus-article-mime-handles)
6111 (unless (or (stringp part)
6112 (equal (car (mm-handle-type part))
6113 "application/pgp-signature"))
6114 (push part handles)))
6115 (gnus-treat-article
6116 nil (length (memq handle handles)) (length handles)
6117 (mm-handle-media-type handle)))))))))))
6119 (defun gnus-unbuttonized-mime-type-p (type)
6120 "Say whether TYPE is to be unbuttonized."
6121 (unless gnus-inhibit-mime-unbuttonizing
6122 (when (catch 'found
6123 (let ((types gnus-unbuttonized-mime-types))
6124 (while types
6125 (when (string-match (pop types) type)
6126 (throw 'found t)))))
6127 (not (catch 'found
6128 (let ((types gnus-buttonized-mime-types))
6129 (while types
6130 (when (string-match (pop types) type)
6131 (throw 'found t)))))))))
6133 (defun gnus-article-insert-newline ()
6134 "Insert a newline, but mark it as undeletable."
6135 (gnus-put-text-property
6136 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6138 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6139 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6140 (ihandles handles)
6141 (point (point))
6142 handle (inhibit-read-only t) from props begend not-pref)
6143 (save-window-excursion
6144 (save-restriction
6145 (when ibegend
6146 (narrow-to-region (car ibegend)
6147 (or (cdr ibegend)
6148 (progn
6149 (goto-char (car ibegend))
6150 (forward-line 2)
6151 (point))))
6152 (delete-region (point-min) (point-max))
6153 (mm-remove-parts handles))
6154 (setq begend (list (point-marker)))
6155 ;; Do the toggle.
6156 (unless (setq not-pref (cadr (member preferred ihandles)))
6157 (setq not-pref (car ihandles)))
6158 (when (or ibegend
6159 (not preferred)
6160 (not (gnus-unbuttonized-mime-type-p
6161 "multipart/alternative")))
6162 (gnus-add-text-properties
6163 (setq from (point))
6164 (progn
6165 (insert (format "%d. " id))
6166 (point))
6167 `(gnus-callback
6168 (lambda (handles)
6169 (unless ,(not ibegend)
6170 (setq gnus-article-mime-handle-alist
6171 ',gnus-article-mime-handle-alist))
6172 (gnus-mime-display-alternative
6173 ',ihandles ',not-pref ',begend ,id))
6174 keymap ,gnus-mime-button-map
6175 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6176 face ,gnus-article-button-face
6177 gnus-part ,id
6178 article-type multipart
6179 rear-nonsticky t))
6180 (widget-convert-button 'link from (point)
6181 :action 'gnus-widget-press-button
6182 :button-keymap gnus-widget-button-keymap)
6183 ;; Do the handles
6184 (while (setq handle (pop handles))
6185 (gnus-add-text-properties
6186 (setq from (point))
6187 (progn
6188 (insert (format "(%c) %-18s"
6189 (if (equal handle preferred) ?* ? )
6190 (mm-handle-media-type handle)))
6191 (point))
6192 `(gnus-callback
6193 (lambda (handles)
6194 (unless ,(not ibegend)
6195 (setq gnus-article-mime-handle-alist
6196 ',gnus-article-mime-handle-alist))
6197 (gnus-mime-display-alternative
6198 ',ihandles ',handle ',begend ,id))
6199 keymap ,gnus-mime-button-map
6200 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6201 face ,gnus-article-button-face
6202 gnus-part ,id
6203 gnus-data ,handle
6204 rear-nonsticky t))
6205 (widget-convert-button 'link from (point)
6206 :action 'gnus-widget-press-button
6207 :button-keymap gnus-widget-button-keymap)
6208 (insert " "))
6209 (insert "\n\n"))
6210 (when preferred
6211 (if (stringp (car preferred))
6212 (gnus-display-mime preferred)
6213 (let ((mail-parse-charset gnus-newsgroup-charset)
6214 (mail-parse-ignored-charsets
6215 (with-current-buffer gnus-summary-buffer
6216 gnus-newsgroup-ignored-charsets)))
6217 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6218 ;; Do highlighting.
6219 (save-excursion
6220 (save-restriction
6221 (narrow-to-region (car begend) (point-max))
6222 (gnus-treat-article
6223 nil (length gnus-article-mime-handle-alist)
6224 (gnus-article-mime-total-parts)
6225 (mm-handle-media-type preferred))))))
6226 (goto-char (point-max))
6227 (setcdr begend (point-marker)))))
6228 (when ibegend
6229 (goto-char point)))
6230 ;; Redraw attachment buttons in the header.
6231 (when gnus-mime-display-attachment-buttons-in-header
6232 (gnus-mime-buttonize-attachments-in-header)))
6234 (defconst gnus-article-wash-status-strings
6235 (let ((alist '((cite "c" "Possible hidden citation text"
6236 " " "All citation text visible")
6237 (headers "h" "Hidden headers"
6238 " " "All headers visible.")
6239 (pgp "p" "Encrypted or signed message status hidden"
6240 " " "No hidden encryption nor digital signature status")
6241 (signature "s" "Signature has been hidden"
6242 " " "Signature is visible")
6243 (overstrike "o" "Overstrike (^H) characters applied"
6244 " " "No overstrike characters applied")
6245 (emphasis "e" "/*_Emphasis_*/ characters applied"
6246 " " "No /*_emphasis_*/ characters applied")))
6247 result)
6248 (dolist (entry alist result)
6249 (let ((key (nth 0 entry))
6250 (on (copy-sequence (nth 1 entry)))
6251 (on-help (nth 2 entry))
6252 (off (copy-sequence (nth 3 entry)))
6253 (off-help (nth 4 entry)))
6254 (put-text-property 0 1 'help-echo on-help on)
6255 (put-text-property 0 1 'help-echo off-help off)
6256 (push (list key on off) result))))
6257 "Alist of strings describing wash status in the mode line.
6258 Each entry has the form (KEY ON OF), where the KEY is a symbol
6259 representing the particular washing function, ON is the string to use
6260 in the article mode line when the washing function is active, and OFF
6261 is the string to use when it is inactive.")
6263 (defun gnus-article-wash-status-entry (key value)
6264 (let ((entry (assoc key gnus-article-wash-status-strings)))
6265 (if value (nth 1 entry) (nth 2 entry))))
6267 (defun gnus-article-wash-status ()
6268 "Return a string which display status of article washing."
6269 (with-current-buffer gnus-article-buffer
6270 (let ((cite (memq 'cite gnus-article-wash-types))
6271 (headers (memq 'headers gnus-article-wash-types))
6272 (boring (memq 'boring-headers gnus-article-wash-types))
6273 (pgp (memq 'pgp gnus-article-wash-types))
6274 (pem (memq 'pem gnus-article-wash-types))
6275 (signed (memq 'signed gnus-article-wash-types))
6276 (encrypted (memq 'encrypted gnus-article-wash-types))
6277 (signature (memq 'signature gnus-article-wash-types))
6278 (overstrike (memq 'overstrike gnus-article-wash-types))
6279 (emphasis (memq 'emphasis gnus-article-wash-types)))
6280 (concat
6281 (gnus-article-wash-status-entry 'cite cite)
6282 (gnus-article-wash-status-entry 'headers (or headers boring))
6283 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6284 (gnus-article-wash-status-entry 'signature signature)
6285 (gnus-article-wash-status-entry 'overstrike overstrike)
6286 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6288 (defun gnus-add-wash-type (type)
6289 "Add a washing of TYPE to the current status."
6290 (add-to-list 'gnus-article-wash-types type))
6292 (defun gnus-delete-wash-type (type)
6293 "Add a washing of TYPE to the current status."
6294 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6296 (defun gnus-add-image (category image)
6297 "Add IMAGE of CATEGORY to the list of displayed images."
6298 (let ((entry (assq category gnus-article-image-alist)))
6299 (unless entry
6300 (setq entry (list category))
6301 (push entry gnus-article-image-alist))
6302 (nconc entry (list image))))
6304 (defun gnus-delete-images (category)
6305 "Delete all images in CATEGORY."
6306 (let ((entry (assq category gnus-article-image-alist)))
6307 (dolist (image (cdr entry))
6308 (gnus-remove-image image category))
6309 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6310 (gnus-delete-wash-type category)))
6312 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6314 (defun gnus-article-maybe-hide-headers ()
6315 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6316 Provided for backwards compatibility."
6317 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6318 (not (with-current-buffer gnus-summary-buffer
6319 gnus-have-all-headers)))
6320 (not gnus-inhibit-hiding))
6321 (gnus-article-hide-headers)))
6323 (declare-function shr-put-image "shr" (data alt &optional flags))
6325 (defun gnus-shr-put-image (data alt &optional flags)
6326 "Put image DATA with a string ALT. Enable image to be deleted."
6327 (let ((image (if flags
6328 (shr-put-image data (propertize (or alt "*")
6329 'gnus-image-category 'shr)
6330 flags)
6331 ;; Old `shr-put-image' doesn't take the optional `flags'
6332 ;; argument.
6333 (shr-put-image data (propertize (or alt "*")
6334 'gnus-image-category 'shr)))))
6335 (when image
6336 (gnus-add-image 'shr image))))
6338 (defun gnus-article-mime-handles (&optional alist id all)
6339 (if alist
6340 (let ((i 1) newid flat)
6341 (dolist (handle alist flat)
6342 (setq newid (append id (list i))
6343 i (1+ i))
6344 (if (stringp (car handle))
6345 (setq flat (nconc flat (gnus-article-mime-handles
6346 (cdr handle) newid all)))
6347 (delq (rassq handle all) all)
6348 (setq flat (nconc flat (list (cons newid handle)))))))
6349 (let ((flat (list nil)))
6350 ;; Assume that elements of `gnus-article-mime-handle-alist'
6351 ;; are in the decreasing order, but unnumbered subsidiaries
6352 ;; in each element are in the increasing order.
6353 (dolist (handle (reverse gnus-article-mime-handle-alist))
6354 (if (stringp (cadr handle))
6355 (setq flat (nconc flat (gnus-article-mime-handles
6356 (cddr handle) (list (car handle)) flat)))
6357 (delq (rassq (cdr handle) flat) flat)
6358 (setq flat (nconc flat (list (cons (list (car handle))
6359 (cdr handle)))))))
6360 (setq flat (cdr flat))
6361 (mapc (lambda (handle)
6362 (if (cdar handle)
6363 ;; This is a hidden (i.e. unnumbered) handle.
6364 (progn
6365 (setcar handle
6366 (1+ (caar gnus-article-mime-handle-alist)))
6367 (push handle gnus-article-mime-handle-alist))
6368 (setcar handle (caar handle))))
6369 flat)
6370 flat)))
6372 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6373 "Show attachments as buttons in the end of the header of an article.
6374 This function toggles the display when called interactively. Note that
6375 buttons to be added to the header are only the ones that aren't inlined
6376 in the body. Use `gnus-header-face-alist' to highlight buttons."
6377 (interactive (list t))
6378 (gnus-with-article-buffer
6379 (let ((case-fold-search t) buttons handle type st)
6380 (save-excursion
6381 (save-restriction
6382 (widen)
6383 (article-narrow-to-head)
6384 ;; Header buttons exist?
6385 (while (and (not buttons)
6386 (re-search-forward "^attachments?:[\n ]+" nil t))
6387 (when (get-char-property (match-end 0)
6388 'gnus-button-attachment-extra)
6389 (setq buttons (match-beginning 0))))
6390 (widen)
6391 (when buttons
6392 ;; Delete header buttons.
6393 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6394 (match-beginning 0)
6395 (point-max))))
6396 (unless (and interactive buttons)
6397 ;; Find buttons.
6398 (setq buttons nil)
6399 (dolist (button (gnus-article-mime-handles))
6400 (setq handle (cdr button)
6401 type (mm-handle-media-type handle))
6402 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6403 (with-current-buffer gnus-summary-buffer
6404 gnus-inhibit-images)
6405 gnus-inhibit-images)
6406 (string-match "\\`image/" type))
6407 (mm-inline-override-p handle)
6408 (and (mm-handle-disposition handle)
6409 (not (equal (car (mm-handle-disposition handle))
6410 "inline"))
6411 (not (mm-attachment-override-p handle)))
6412 (not (mm-automatic-display-p handle))
6413 (not (or (and (mm-inlinable-p handle)
6414 (mm-inlined-p handle))
6415 (mm-automatic-external-display-p type))))
6416 (push button buttons)))
6417 (when buttons
6418 ;; Add header buttons.
6419 (article-goto-body)
6420 (forward-line -1)
6421 (narrow-to-region (point) (point))
6422 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6423 (dolist (button (nreverse buttons))
6424 (setq st (point))
6425 (insert " ")
6426 (mm-handle-set-undisplayer
6427 (setq handle (copy-sequence (cdr button))) nil)
6428 (gnus-insert-mime-button handle (car button))
6429 (skip-chars-backward "\t\n ")
6430 (delete-region (point) (point-max))
6431 (when (> (current-column) (window-width))
6432 (goto-char st)
6433 (insert "\n")
6434 (end-of-line)))
6435 (insert "\n")
6436 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6437 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6438 (gnus-overlay-put ovl 'face nil))
6439 (let ((gnus-treatment-function-alist
6440 '((gnus-treat-highlight-headers
6441 gnus-article-highlight-headers))))
6442 (gnus-treat-article 'head)))))))))
6444 ;;; Article savers.
6446 (defun gnus-output-to-file (file-name)
6447 "Append the current article to a file named FILE-NAME.
6448 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6449 text and used as the value of the coding cookie which is added to the
6450 top of a file. Otherwise, this function saves a raw article without
6451 the coding cookie."
6452 (let* ((artbuf (current-buffer))
6453 (file-name-coding-system nnmail-pathname-coding-system)
6454 (coding gnus-article-save-coding-system)
6455 (coding-system-for-read (if coding
6456 nil ;; Rely on the coding cookie.
6457 mm-text-coding-system))
6458 (coding-system-for-write (or coding
6459 mm-text-coding-system-for-write
6460 mm-text-coding-system))
6461 (exists (file-exists-p file-name)))
6462 (with-temp-buffer
6463 (when exists
6464 (insert-file-contents file-name)
6465 (goto-char (point-min))
6466 ;; Remove the existing coding cookie.
6467 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6468 (delete-region (match-beginning 0) (match-end 0))))
6469 (goto-char (point-max))
6470 (insert-buffer-substring artbuf)
6471 ;; Append newline at end of the buffer as separator, and then
6472 ;; save it to file.
6473 (goto-char (point-max))
6474 (insert "\n")
6475 (when coding
6476 ;; If the coding system is not suitable to encode the text,
6477 ;; ask a user for a proper one.
6478 (when (fboundp 'select-safe-coding-system)
6479 (setq coding (coding-system-base
6480 (save-window-excursion
6481 (select-safe-coding-system (point-min) (point-max)
6482 coding))))
6483 (setq coding-system-for-write
6484 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6485 coding)))
6486 (goto-char (point-min))
6487 ;; Add the coding cookie.
6488 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6489 coding-system-for-write)))
6490 (if exists
6491 (progn
6492 (write-region (point-min) (point-max) file-name nil 'no-message)
6493 (message "Appended to %s" file-name))
6494 (write-region (point-min) (point-max) file-name))))
6497 (defun gnus-narrow-to-page (&optional arg)
6498 "Narrow the article buffer to a page.
6499 If given a numerical ARG, move forward ARG pages."
6500 (interactive "P")
6501 (setq arg (if arg (prefix-numeric-value arg) 0))
6502 (with-current-buffer gnus-article-buffer
6503 (widen)
6504 ;; Remove any old next/prev buttons.
6505 (when (gnus-visual-p 'page-marker)
6506 (let ((inhibit-read-only t))
6507 (gnus-remove-text-with-property 'gnus-prev)
6508 (gnus-remove-text-with-property 'gnus-next)))
6509 (let (st nd pt)
6510 (when (save-excursion
6511 (cond ((< arg 0)
6512 (if (re-search-backward page-delimiter nil 'move (abs arg))
6513 (prog1
6514 (setq nd (match-beginning 0)
6515 pt nd)
6516 (when (re-search-backward page-delimiter nil t)
6517 (setq st (match-end 0))))
6518 (when (re-search-forward page-delimiter nil t)
6519 (setq nd (match-beginning 0)
6520 pt (point-min)))))
6521 ((> arg 0)
6522 (if (re-search-forward page-delimiter nil 'move arg)
6523 (prog1
6524 (setq st (match-end 0)
6525 pt st)
6526 (when (re-search-forward page-delimiter nil t)
6527 (setq nd (match-beginning 0))))
6528 (when (re-search-backward page-delimiter nil t)
6529 (setq st (match-end 0)
6530 pt (point-max)))))
6532 (when (re-search-backward page-delimiter nil t)
6533 (goto-char (setq st (match-end 0))))
6534 (when (re-search-forward page-delimiter nil t)
6535 (setq nd (match-beginning 0)))
6536 (or st nd))))
6537 (setq gnus-page-broken t)
6538 (when pt (goto-char pt))
6539 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6540 (when (gnus-visual-p 'page-marker)
6541 (save-excursion
6542 (when nd
6543 (goto-char nd)
6544 (gnus-insert-next-page-button))
6545 (when st
6546 (goto-char st)
6547 (gnus-insert-prev-page-button))))))))
6549 ;; Article mode commands
6551 (defun gnus-article-goto-next-page ()
6552 "Show the next page of the article."
6553 (interactive)
6554 (when (gnus-article-next-page)
6555 (goto-char (point-min))
6556 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6559 (defun gnus-article-goto-prev-page ()
6560 "Show the previous page of the article."
6561 (interactive)
6562 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6563 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6564 (gnus-article-prev-page nil)))
6566 ;; This is cleaner but currently breaks `gnus-pick-mode':
6568 ;; (defun gnus-article-goto-next-page ()
6569 ;; "Show the next page of the article."
6570 ;; (interactive)
6571 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6572 ;; (gnus-summary-next-page)))
6574 ;; (defun gnus-article-goto-prev-page ()
6575 ;; "Show the next page of the article."
6576 ;; (interactive)
6577 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6578 ;; (gnus-summary-prev-page)))
6580 (defun gnus-article-next-page (&optional lines)
6581 "Show the next page of the current article.
6582 If end of article, return non-nil. Otherwise return nil.
6583 Argument LINES specifies lines to be scrolled up."
6584 (interactive "p")
6585 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6586 (if (and (not (and gnus-article-over-scroll
6587 (> (count-lines (window-start) (point-max))
6588 (if (featurep 'xemacs)
6589 (or lines (1- (window-height)))
6590 (+ (or lines (1- (window-height))) scroll-margin)))))
6591 (save-excursion
6592 (end-of-line)
6593 (and (pos-visible-in-window-p) ;Not continuation line.
6594 (>= (point) (point-max)))))
6595 ;; Nothing in this page.
6596 (if (or (not gnus-page-broken)
6597 (save-excursion
6598 (save-restriction
6599 (widen)
6600 (forward-line)
6601 (eobp)))) ;Real end-of-buffer?
6602 (progn
6603 (when gnus-article-over-scroll
6604 (gnus-article-next-page-1 lines))
6605 t) ;Nothing more.
6606 (gnus-narrow-to-page 1) ;Go to next page.
6607 nil)
6608 ;; More in this page.
6609 (gnus-article-next-page-1 lines)
6610 nil))
6612 (defun gnus-article-beginning-of-window ()
6613 "Move point to the beginning of the window.
6614 In Emacs, the point is placed at the line number which `scroll-margin'
6615 specifies."
6616 (if (featurep 'xemacs)
6617 (move-to-window-line 0)
6618 ;; There is an obscure bug in Emacs that makes it impossible to
6619 ;; scroll past big pictures in the article buffer. Try to fix
6620 ;; this by adding a sanity check by counting the lines visible.
6621 (when (> (count-lines (window-start) (window-end)) 30)
6622 (move-to-window-line
6623 (min (max 0 scroll-margin)
6624 (max 1 (- (window-height)
6625 (if mode-line-format 1 0)
6626 (if header-line-format 1 0)
6627 2)))))))
6629 (defun gnus-article-next-page-1 (lines)
6630 (condition-case ()
6631 (let ((scroll-in-place nil)
6632 (auto-window-vscroll nil))
6633 (scroll-up lines))
6634 (end-of-buffer
6635 ;; Long lines may cause an end-of-buffer error.
6636 (goto-char (point-max))))
6637 (gnus-article-beginning-of-window))
6639 (defun gnus-article-prev-page (&optional lines)
6640 "Show previous page of current article.
6641 Argument LINES specifies lines to be scrolled down."
6642 (interactive "p")
6643 (move-to-window-line 0)
6644 (if (and gnus-page-broken
6645 (bobp)
6646 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6647 (progn
6648 (gnus-narrow-to-page -1) ;Go to previous page.
6649 (goto-char (point-max))
6650 (recenter (if gnus-article-over-scroll
6651 (if lines
6652 (max (if (featurep 'xemacs)
6653 lines
6654 (+ lines scroll-margin))
6656 (- (window-height) 2))
6657 -1)))
6658 (prog1
6659 (condition-case ()
6660 (let ((scroll-in-place nil))
6661 (scroll-down lines))
6662 (beginning-of-buffer
6663 (goto-char (point-min))))
6664 (gnus-article-beginning-of-window))))
6666 (defun gnus-article-only-boring-p ()
6667 "Decide whether there is only boring text remaining in the article.
6668 Something \"interesting\" is a word of at least two letters that does
6669 not have a face in `gnus-article-boring-faces'."
6670 (when (and gnus-article-skip-boring
6671 (boundp 'gnus-article-boring-faces)
6672 (symbol-value 'gnus-article-boring-faces))
6673 (save-excursion
6674 (let ((inhibit-point-motion-hooks t))
6675 (catch 'only-boring
6676 (while (re-search-forward "\\b\\w\\w" nil t)
6677 (forward-char -1)
6678 (when (not (gnus-intersection
6679 (gnus-faces-at (point))
6680 (symbol-value 'gnus-article-boring-faces)))
6681 (throw 'only-boring nil)))
6682 (throw 'only-boring t))))))
6684 (defun gnus-article-refer-article ()
6685 "Read article specified by message-id around point."
6686 (interactive)
6687 (save-excursion
6688 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6689 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6690 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6691 (let ((msg-id (concat "<" (match-string 0) ">")))
6692 (set-buffer gnus-summary-buffer)
6693 (gnus-summary-refer-article msg-id))
6694 (error "No references around point"))))
6696 (defun gnus-article-show-summary ()
6697 "Reconfigure windows to show summary buffer."
6698 (interactive)
6699 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6700 (error "There is no summary buffer for this article buffer")
6701 (gnus-article-set-globals)
6702 (gnus-configure-windows 'article)
6703 (gnus-summary-goto-subject gnus-current-article)
6704 (gnus-summary-position-point)))
6706 (defun gnus-article-describe-briefly ()
6707 "Describe article mode commands briefly."
6708 (interactive)
6709 (gnus-message 6 "%s" (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")))
6711 (defun gnus-article-check-buffer ()
6712 "Beep if not in an article buffer."
6713 (unless (derived-mode-p 'gnus-article-mode)
6714 (error "Command invoked outside of a Gnus article buffer")))
6716 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6717 "Read a summary buffer key sequence and execute it from the article buffer."
6718 (interactive "P")
6719 (gnus-article-check-buffer)
6720 (let ((nosaves
6721 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6722 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6723 "=" "^" "\M-^" "|"))
6724 (nosave-but-article
6725 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6726 "An" "Ap" [?A (meta return)] [?A delete]))
6727 (nosave-in-article
6728 '("AS" "\C-d"))
6729 (up-to-top
6730 '("n" "Gn" "p" "Gp"))
6731 keys new-sum-point)
6732 (with-current-buffer gnus-article-current-summary
6733 (let (gnus-pick-mode)
6734 (setq unread-command-events (nconc unread-command-events
6735 (list (or key last-command-event)))
6736 keys (if (featurep 'xemacs)
6737 (events-to-keys (read-key-sequence nil t))
6738 (read-key-sequence nil t)))))
6740 (message "")
6742 (cond
6743 ((eq (aref keys (1- (length keys))) ?\C-h)
6744 (gnus-article-describe-bindings (substring keys 0 -1)))
6745 ((or (member keys nosaves)
6746 (member keys nosave-but-article)
6747 (member keys nosave-in-article))
6748 (let (func)
6749 (save-window-excursion
6750 (pop-to-buffer gnus-article-current-summary)
6751 ;; We disable the pick minor mode commands.
6752 (let (gnus-pick-mode)
6753 (setq func (key-binding keys t))))
6754 (if (or (not func)
6755 (numberp func))
6756 (ding)
6757 (unless (member keys nosave-in-article)
6758 (set-buffer gnus-article-current-summary))
6759 (when (and (symbolp func)
6760 (get func 'disabled))
6761 (error "Function %s disabled" func))
6762 (call-interactively func)
6763 (setq new-sum-point (point)))
6764 (when (member keys nosave-but-article)
6765 (pop-to-buffer gnus-article-buffer))))
6767 ;; These commands should restore window configuration.
6768 (let ((obuf (current-buffer))
6769 (owin (current-window-configuration))
6770 win func in-buffer selected new-sum-start new-sum-hscroll err)
6771 (cond (not-restore-window
6772 (pop-to-buffer gnus-article-current-summary)
6773 (setq win (selected-window)))
6774 ((setq win (get-buffer-window gnus-article-current-summary))
6775 (select-window win))
6777 (let ((summary-buffer gnus-article-current-summary))
6778 (gnus-configure-windows 'article)
6779 (unless (setq win (get-buffer-window summary-buffer 'visible))
6780 (let ((gnus-buffer-configuration
6781 '((article ((vertical 1.0
6782 (summary 0.25 point)
6783 (article 1.0)))))))
6784 (gnus-configure-windows 'article))
6785 (setq win (get-buffer-window summary-buffer 'visible)))
6786 (gnus-select-frame-set-input-focus (window-frame win))
6787 (select-window win))))
6788 (setq in-buffer (current-buffer))
6789 ;; We disable the pick minor mode commands.
6790 (setq func (let (gnus-pick-mode)
6791 (key-binding keys t)))
6792 (when (get func 'disabled)
6793 (error "Function %s disabled" func))
6794 (if (and func
6795 (functionp func)
6796 (condition-case code
6797 (progn
6798 (call-interactively func)
6800 (error
6801 (setq err code)
6802 nil)))
6803 (progn
6804 (when (eq win (selected-window))
6805 (setq new-sum-point (point)
6806 new-sum-start (window-start win)
6807 new-sum-hscroll (window-hscroll win)))
6808 (when (or (eq in-buffer (current-buffer))
6809 (when (eq obuf (current-buffer))
6810 (set-buffer in-buffer)
6812 (setq selected (ignore-errors (gnus-summary-select-article)))
6813 (set-buffer obuf)
6814 (unless not-restore-window
6815 (set-window-configuration owin))
6816 (when (and (eq selected 'old)
6817 new-sum-point)
6818 (set-window-start (get-buffer-window (current-buffer))
6820 (set-window-point (get-buffer-window (current-buffer))
6821 (if (article-goto-body)
6822 (1- (point))
6823 (point))))
6824 (when (and (not not-restore-window)
6825 new-sum-point
6826 (window-live-p win)
6827 (with-current-buffer (window-buffer win)
6828 (derived-mode-p 'gnus-summary-mode)))
6829 (set-window-point win new-sum-point)
6830 (set-window-start win new-sum-start)
6831 (set-window-hscroll win new-sum-hscroll))))
6832 (set-window-configuration owin)
6833 (if err
6834 (signal (car err) (cdr err))
6835 (ding))))))))
6837 (defun gnus-article-read-summary-send-keys ()
6838 (interactive)
6839 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6840 (gnus-article-read-summary-keys)))
6842 (defun gnus-article-describe-key (key)
6843 "Display documentation of the function invoked by KEY.
6844 KEY is a string or a vector."
6845 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6846 (read-key-sequence "Describe key: "))))
6847 (gnus-article-check-buffer)
6848 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6849 gnus-article-read-summary-send-keys))
6850 (with-current-buffer gnus-article-current-summary
6851 (setq unread-command-events
6852 (if (featurep 'xemacs)
6853 (append key nil)
6854 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6855 (list 'meta (- x 128))
6857 key)))
6858 (let ((cursor-in-echo-area t)
6859 gnus-pick-mode)
6860 (describe-key (read-key-sequence nil t))))
6861 (describe-key key)))
6863 (defun gnus-article-describe-key-briefly (key &optional insert)
6864 "Display documentation of the function invoked by KEY.
6865 KEY is a string or a vector."
6866 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6867 (read-key-sequence "Describe key: "))
6868 current-prefix-arg))
6869 (gnus-article-check-buffer)
6870 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6871 gnus-article-read-summary-send-keys))
6872 (with-current-buffer gnus-article-current-summary
6873 (setq unread-command-events
6874 (if (featurep 'xemacs)
6875 (append key nil)
6876 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6877 (list 'meta (- x 128))
6879 key)))
6880 (let ((cursor-in-echo-area t)
6881 gnus-pick-mode)
6882 (describe-key-briefly (read-key-sequence nil t) insert)))
6883 (describe-key-briefly key insert)))
6885 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6886 (defvar gnus-agent-summary-mode)
6887 (defvar gnus-draft-mode)
6888 (defvar help-xref-stack-item)
6890 (defun gnus-article-describe-bindings (&optional prefix)
6891 "Show a list of all defined keys, and their definitions.
6892 The optional argument PREFIX, if non-nil, should be a key sequence;
6893 then we display only bindings that start with that prefix."
6894 (interactive)
6895 (gnus-article-check-buffer)
6896 (let ((keymap (copy-keymap gnus-article-mode-map))
6897 (map (copy-keymap gnus-article-send-map))
6898 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6899 parent agent draft)
6900 (define-key keymap "S" map)
6901 (define-key map [t] nil)
6902 (with-current-buffer gnus-article-current-summary
6903 (set-keymap-parent
6904 keymap
6905 (if (setq parent (keymap-parent gnus-article-mode-map))
6906 (prog1
6907 (setq parent (copy-keymap parent))
6908 (set-keymap-parent parent (current-local-map)))
6909 (current-local-map)))
6910 (set-keymap-parent map (key-binding "S"))
6911 (let (key def gnus-pick-mode)
6912 (while sumkeys
6913 (setq key (pop sumkeys))
6914 (cond ((and (vectorp key) (= (length key) 1)
6915 (consp (setq def (aref key 0)))
6916 (numberp (car def)) (numberp (cdr def)))
6917 (when (< (max (car def) (cdr def)) 128)
6918 (setq sumkeys
6919 (append (mapcar
6920 #'vector
6921 (nreverse (gnus-uncompress-range def)))
6922 sumkeys))))
6923 ((setq def (key-binding key))
6924 (unless (eq def 'undefined)
6925 (define-key keymap key def))))))
6926 (when (boundp 'gnus-agent-summary-mode)
6927 (setq agent gnus-agent-summary-mode))
6928 (when (boundp 'gnus-draft-mode)
6929 (setq draft gnus-draft-mode)))
6930 (with-temp-buffer
6931 (use-local-map keymap)
6932 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6933 (set (make-local-variable 'gnus-draft-mode) draft)
6934 (describe-bindings prefix))
6935 (let ((item `((lambda (prefix)
6936 (with-current-buffer ,(current-buffer)
6937 (gnus-article-describe-bindings prefix)))
6938 ,prefix)))
6939 ;; Loading `help-mode' here is necessary if `describe-bindings'
6940 ;; is replaced with something, e.g. `helm-descbinds'.
6941 (require 'help-mode)
6942 (with-current-buffer (let (help-xref-following) (help-buffer))
6943 (setq help-xref-stack-item item)))))
6945 (defun gnus-article-reply-with-original (&optional wide)
6946 "Start composing a reply mail to the current message.
6947 The text in the region will be yanked. If the region isn't active,
6948 the entire article will be yanked."
6949 (interactive)
6950 (let ((article (cdr gnus-article-current))
6951 contents)
6952 (if (not (gnus-region-active-p))
6953 (with-current-buffer gnus-summary-buffer
6954 (gnus-summary-reply (list (list article)) wide))
6955 (setq contents (buffer-substring (point) (mark t)))
6956 ;; Deactivate active regions.
6957 (when (and (boundp 'transient-mark-mode)
6958 transient-mark-mode)
6959 (setq mark-active nil))
6960 (with-current-buffer gnus-summary-buffer
6961 (gnus-summary-reply
6962 (list (list article contents)) wide)))))
6964 (defun gnus-article-wide-reply-with-original ()
6965 "Start composing a wide reply mail to the current message.
6966 The text in the region will be yanked. If the region isn't active,
6967 the entire article will be yanked."
6968 (interactive)
6969 (gnus-article-reply-with-original t))
6971 (defun gnus-article-followup-with-original ()
6972 "Compose a followup to the current article.
6973 The text in the region will be yanked. If the region isn't active,
6974 the entire article will be yanked."
6975 (interactive)
6976 (let ((article (cdr gnus-article-current))
6977 contents)
6978 (if (not (gnus-region-active-p))
6979 (with-current-buffer gnus-summary-buffer
6980 (gnus-summary-followup (list (list article))))
6981 (setq contents (buffer-substring (point) (mark t)))
6982 ;; Deactivate active regions.
6983 (when (and (boundp 'transient-mark-mode)
6984 transient-mark-mode)
6985 (setq mark-active nil))
6986 (with-current-buffer gnus-summary-buffer
6987 (gnus-summary-followup
6988 (list (list article contents)))))))
6990 (defun gnus-article-hide (&optional arg force)
6991 "Hide all the gruft in the current article.
6992 This means that signatures, cited text and (some) headers will be
6993 hidden.
6994 If given a prefix, show the hidden text instead."
6995 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6996 (gnus-article-hide-headers arg)
6997 (gnus-article-hide-list-identifiers arg)
6998 (gnus-article-hide-citation-maybe arg force)
6999 (gnus-article-hide-signature arg))
7001 (defun gnus-check-group-server ()
7002 ;; Make sure the connection to the server is alive.
7003 (unless (gnus-server-opened
7004 (gnus-find-method-for-group gnus-newsgroup-name))
7005 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7006 (gnus-request-group gnus-newsgroup-name t)))
7008 (eval-when-compile
7009 (autoload 'nneething-get-file-name "nneething"))
7011 (defun gnus-request-article-this-buffer (article group)
7012 "Get an article and insert it into this buffer."
7013 (let (do-update-line sparse-header)
7014 (prog1
7015 (save-excursion
7016 (erase-buffer)
7017 (gnus-kill-all-overlays)
7018 (setq group (or group gnus-newsgroup-name))
7020 ;; Using `gnus-request-article' directly will insert the article into
7021 ;; `nntp-server-buffer' - so we'll save some time by not having to
7022 ;; copy it from the server buffer into the article buffer.
7024 ;; We only request an article by message-id when we do not have the
7025 ;; headers for it, so we'll have to get those.
7026 (when (stringp article)
7027 (gnus-read-header article))
7029 ;; If the article number is negative, that means that this article
7030 ;; doesn't belong in this newsgroup (possibly), so we find its
7031 ;; message-id and request it by id instead of number.
7032 (when (and (numberp article)
7033 gnus-summary-buffer
7034 (get-buffer gnus-summary-buffer)
7035 (gnus-buffer-exists-p gnus-summary-buffer))
7036 (with-current-buffer gnus-summary-buffer
7037 (let ((header (gnus-summary-article-header article)))
7038 (when (< article 0)
7039 (cond
7040 ((memq article gnus-newsgroup-sparse)
7041 ;; This is a sparse gap article.
7042 (setq do-update-line article)
7043 (setq article (mail-header-id header))
7044 (setq sparse-header (gnus-read-header article))
7045 (setq gnus-newsgroup-sparse
7046 (delq article gnus-newsgroup-sparse)))
7047 ((vectorp header)
7048 ;; It's a real article.
7049 (setq article (mail-header-id header)))
7051 ;; It is an extracted pseudo-article.
7052 (setq article 'pseudo)
7053 (gnus-request-pseudo-article header))))
7055 (let ((method (gnus-find-method-for-group
7056 gnus-newsgroup-name)))
7057 (when (and (eq (car method) 'nneething)
7058 (vectorp header))
7059 (let ((dir (nneething-get-file-name
7060 (mail-header-id header))))
7061 (when (and (stringp dir)
7062 (file-directory-p dir))
7063 (setq article 'nneething)
7064 (gnus-group-enter-directory dir))))))))
7066 (cond
7067 ;; Refuse to select canceled articles.
7068 ((and (numberp article)
7069 gnus-summary-buffer
7070 (get-buffer gnus-summary-buffer)
7071 (gnus-buffer-exists-p gnus-summary-buffer)
7072 (eq (cdr (with-current-buffer gnus-summary-buffer
7073 (assq article gnus-newsgroup-reads)))
7074 gnus-canceled-mark))
7075 nil)
7076 ;; We first check `gnus-original-article-buffer'.
7077 ((and (get-buffer gnus-original-article-buffer)
7078 (numberp article)
7079 (with-current-buffer gnus-original-article-buffer
7080 (and (equal (car gnus-original-article) group)
7081 (eq (cdr gnus-original-article) article))))
7082 ;; `insert-buffer-substring' would incorrectly use the
7083 ;; equivalent of string-make-multibyte which amount to decoding
7084 ;; with locale-coding-system, causing failure of
7085 ;; subsequent decoding.
7086 (insert (mm-string-to-multibyte
7087 (with-current-buffer gnus-original-article-buffer
7088 (buffer-substring (point-min) (point-max)))))
7089 'article)
7090 ;; Check the backlog.
7091 ((and gnus-keep-backlog
7092 (gnus-backlog-request-article group article (current-buffer)))
7093 'article)
7094 ;; Check asynchronous pre-fetch.
7095 ((gnus-async-request-fetched-article group article (current-buffer))
7096 (gnus-async-prefetch-next group article gnus-summary-buffer)
7097 (when (and (numberp article) gnus-keep-backlog)
7098 (gnus-backlog-enter-article group article (current-buffer)))
7099 'article)
7100 ;; Check the cache.
7101 ((and gnus-use-cache
7102 (numberp article)
7103 (gnus-cache-request-article article group))
7104 'article)
7105 ;; Check the agent cache.
7106 ((gnus-agent-request-article article group)
7107 'article)
7108 ;; Get the article and put into the article buffer.
7109 ((or (stringp article)
7110 (numberp article))
7111 (let ((gnus-override-method gnus-override-method)
7112 (methods (and (stringp article)
7113 (with-current-buffer gnus-summary-buffer
7114 (gnus-refer-article-methods))))
7115 (backend (car (gnus-find-method-for-group
7116 gnus-newsgroup-name)))
7117 result
7118 (inhibit-read-only t))
7119 (when (and (null gnus-override-method)
7120 methods)
7121 (setq gnus-override-method (pop methods)))
7122 (while (not result)
7123 (erase-buffer)
7124 (gnus-kill-all-overlays)
7125 (let ((gnus-newsgroup-name group))
7126 (gnus-check-group-server))
7127 (cond
7128 ((gnus-request-article article group (current-buffer))
7129 (when (numberp article)
7130 (gnus-async-prefetch-next group article
7131 gnus-summary-buffer)
7132 (when gnus-keep-backlog
7133 (gnus-backlog-enter-article
7134 group article (current-buffer)))
7135 (when (and gnus-agent
7136 (gnus-agent-group-covered-p group))
7137 (gnus-agent-store-article article group)))
7138 (setq result 'article))
7139 (methods
7140 (setq gnus-override-method (pop methods)))
7141 ((not (string-match "^400 "
7142 (nnheader-get-report backend)))
7143 ;; If we get 400 server disconnect, reconnect and
7144 ;; retry; otherwise, assume the article has expired.
7145 (setq result 'done))))
7146 (and (eq result 'article) 'article)))
7147 ;; It was a pseudo.
7148 (t article)))
7150 ;; Associate this article with the current summary buffer.
7151 (setq gnus-article-current-summary gnus-summary-buffer)
7153 ;; Take the article from the original article buffer
7154 ;; and place it in the buffer it's supposed to be in.
7155 (when (and (get-buffer gnus-article-buffer)
7156 (equal (buffer-name (current-buffer))
7157 (buffer-name (get-buffer gnus-article-buffer))))
7158 (save-excursion
7159 (if (get-buffer gnus-original-article-buffer)
7160 (set-buffer gnus-original-article-buffer)
7161 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7162 (buffer-disable-undo)
7163 (setq major-mode 'gnus-original-article-mode)
7164 (setq buffer-read-only t))
7165 (let ((inhibit-read-only t))
7166 (erase-buffer)
7167 (insert-buffer-substring gnus-article-buffer))
7168 (setq gnus-original-article (cons group article)))
7170 ;; Decode charsets.
7171 (run-hooks 'gnus-article-decode-hook)
7172 ;; Mark article as decoded or not.
7173 (setq gnus-article-decoded-p gnus-article-decode-hook))
7175 ;; Update sparse articles.
7176 (when (and do-update-line
7177 (or (numberp article)
7178 (stringp article)))
7179 (let ((buf (current-buffer)))
7180 (set-buffer gnus-summary-buffer)
7181 (gnus-summary-update-article do-update-line sparse-header)
7182 (gnus-summary-goto-subject do-update-line nil t)
7183 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7184 (point))
7185 (set-buffer buf))))))
7187 (defun gnus-block-private-groups (group)
7188 (if (or (gnus-news-group-p group)
7189 (gnus-member-of-valid 'global group))
7190 ;; Block nothing in news groups.
7192 ;; Block everything anywhere else.
7193 "."))
7195 (defun gnus-blocked-images ()
7196 (if (functionp gnus-blocked-images)
7197 (funcall gnus-blocked-images gnus-newsgroup-name)
7198 gnus-blocked-images))
7201 ;;; Article editing
7204 (defcustom gnus-article-edit-mode-hook nil
7205 "Hook run in article edit mode buffers."
7206 :group 'gnus-article-various
7207 :type 'hook)
7209 (defvar gnus-article-edit-done-function nil)
7211 (defvar gnus-article-edit-mode-map nil)
7213 ;; Should we be using derived.el for this?
7214 (unless gnus-article-edit-mode-map
7215 (setq gnus-article-edit-mode-map (make-keymap))
7216 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7218 (gnus-define-keys gnus-article-edit-mode-map
7219 "\C-c?" describe-mode
7220 "\C-c\C-c" gnus-article-edit-done
7221 "\C-c\C-k" gnus-article-edit-exit
7222 "\C-c\C-f\C-t" message-goto-to
7223 "\C-c\C-f\C-o" message-goto-from
7224 "\C-c\C-f\C-b" message-goto-bcc
7225 ;;"\C-c\C-f\C-w" message-goto-fcc
7226 "\C-c\C-f\C-c" message-goto-cc
7227 "\C-c\C-f\C-s" message-goto-subject
7228 "\C-c\C-f\C-r" message-goto-reply-to
7229 "\C-c\C-f\C-n" message-goto-newsgroups
7230 "\C-c\C-f\C-d" message-goto-distribution
7231 "\C-c\C-f\C-f" message-goto-followup-to
7232 "\C-c\C-f\C-m" message-goto-mail-followup-to
7233 "\C-c\C-f\C-k" message-goto-keywords
7234 "\C-c\C-f\C-u" message-goto-summary
7235 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7236 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7237 "\C-c\C-b" message-goto-body
7238 "\C-c\C-i" message-goto-signature
7240 "\C-c\C-t" message-insert-to
7241 "\C-c\C-n" message-insert-newsgroups
7242 "\C-c\C-o" message-sort-headers
7243 "\C-c\C-e" message-elide-region
7244 "\C-c\C-v" message-delete-not-region
7245 "\C-c\C-z" message-kill-to-signature
7246 "\M-\r" message-newline-and-reformat
7247 "\C-c\C-a" mml-attach-file
7248 "\C-a" message-beginning-of-line
7249 "\t" message-tab
7250 "\M-;" comment-region)
7252 (gnus-define-keys (gnus-article-edit-wash-map
7253 "\C-c\C-w" gnus-article-edit-mode-map)
7254 "f" gnus-article-edit-full-stops))
7256 (easy-menu-define
7257 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7258 '("Field"
7259 ["Fetch To" message-insert-to t]
7260 ["Fetch Newsgroups" message-insert-newsgroups t]
7261 "----"
7262 ["To" message-goto-to t]
7263 ["From" message-goto-from t]
7264 ["Subject" message-goto-subject t]
7265 ["Cc" message-goto-cc t]
7266 ["Reply-To" message-goto-reply-to t]
7267 ["Summary" message-goto-summary t]
7268 ["Keywords" message-goto-keywords t]
7269 ["Newsgroups" message-goto-newsgroups t]
7270 ["Followup-To" message-goto-followup-to t]
7271 ["Mail-Followup-To" message-goto-mail-followup-to t]
7272 ["Distribution" message-goto-distribution t]
7273 ["Body" message-goto-body t]
7274 ["Signature" message-goto-signature t]))
7276 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7277 "Major mode for editing articles.
7278 This is an extended text-mode.
7280 \\{gnus-article-edit-mode-map}"
7281 (make-local-variable 'gnus-article-edit-done-function)
7282 (make-local-variable 'gnus-prev-winconf)
7283 (set (make-local-variable 'font-lock-defaults)
7284 '(message-font-lock-keywords t))
7285 (set (make-local-variable 'mail-header-separator) "")
7286 (set (make-local-variable 'gnus-article-edit-mode) t)
7287 (easy-menu-add message-mode-field-menu message-mode-map)
7288 (mml-mode)
7289 (setq buffer-read-only nil)
7290 (buffer-enable-undo)
7291 (widen))
7293 (defun gnus-article-edit (&optional force)
7294 "Edit the current article.
7295 This will have permanent effect only in mail groups.
7296 If FORCE is non-nil, allow editing of articles even in read-only
7297 groups."
7298 (interactive "P")
7299 (when (and (not force)
7300 (gnus-group-read-only-p))
7301 (error "The current newsgroup does not support article editing"))
7302 (gnus-article-date-original)
7303 (gnus-article-edit-article
7304 'ignore
7305 `(lambda (no-highlight)
7306 'ignore
7307 (gnus-summary-edit-article-done
7308 ,(or (mail-header-references gnus-current-headers) "")
7309 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7311 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7312 "Start editing the contents of the current article buffer."
7313 (let ((winconf (current-window-configuration)))
7314 (set-buffer gnus-article-buffer)
7315 (let ((message-auto-save-directory
7316 ;; Don't associate the article buffer with a draft file.
7317 nil))
7318 (gnus-article-edit-mode))
7319 (funcall start-func)
7320 (set-buffer-modified-p nil)
7321 (gnus-configure-windows 'edit-article)
7322 (setq gnus-article-edit-done-function exit-func)
7323 (setq gnus-prev-winconf winconf)
7324 (unless quiet
7325 (gnus-message 6 "C-c C-c to end edits"))))
7327 (defun gnus-article-edit-done (&optional arg)
7328 "Update the article edits and exit."
7329 (interactive "P")
7330 (let ((func gnus-article-edit-done-function)
7331 (buf (current-buffer))
7332 (start (window-start))
7333 (p (point))
7334 (winconf gnus-prev-winconf))
7335 (widen) ;; Widen it in case that users narrowed the buffer.
7336 (funcall func arg)
7337 (set-buffer buf)
7338 ;; The cache and backlog have to be flushed somewhat.
7339 (when gnus-keep-backlog
7340 (gnus-backlog-remove-article
7341 (car gnus-article-current) (cdr gnus-article-current)))
7342 ;; Flush original article as well.
7343 (gnus-flush-original-article-buffer)
7344 (when gnus-use-cache
7345 (gnus-cache-update-article
7346 (car gnus-article-current) (cdr gnus-article-current)))
7347 ;; We remove all text props from the article buffer.
7348 (kill-all-local-variables)
7349 (set-text-properties (point-min) (point-max) nil)
7350 (gnus-article-mode)
7351 (set-window-configuration winconf)
7352 (set-buffer buf)
7353 (set-window-start (get-buffer-window buf) start)
7354 (set-window-point (get-buffer-window buf) (point)))
7355 (gnus-summary-show-article))
7357 (defun gnus-flush-original-article-buffer ()
7358 (when (get-buffer gnus-original-article-buffer)
7359 (with-current-buffer gnus-original-article-buffer
7360 (setq gnus-original-article nil))))
7362 (defun gnus-article-edit-exit ()
7363 "Exit the article editing without updating."
7364 (interactive)
7365 (when (or (not (buffer-modified-p))
7366 (yes-or-no-p "Article modified; kill anyway? "))
7367 (let ((curbuf (current-buffer))
7368 (p (point))
7369 (window-start (window-start)))
7370 (erase-buffer)
7371 (if (gnus-buffer-live-p gnus-original-article-buffer)
7372 (insert-buffer-substring gnus-original-article-buffer))
7373 (let ((winconf gnus-prev-winconf))
7374 (kill-all-local-variables)
7375 (gnus-article-mode)
7376 (set-window-configuration winconf)
7377 ;; Tippy-toe some to make sure that point remains where it was.
7378 (save-current-buffer
7379 (set-buffer curbuf)
7380 (set-window-start (get-buffer-window (current-buffer)) window-start)
7381 (goto-char p))))
7382 (gnus-summary-show-article)))
7384 (defun gnus-article-edit-full-stops ()
7385 "Interactively repair spacing at end of sentences."
7386 (interactive)
7387 (save-excursion
7388 (goto-char (point-min))
7389 (search-forward-regexp "^$" nil t)
7390 (let ((case-fold-search nil))
7391 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7394 ;;; Article highlights
7397 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7399 ;;; Internal Variables:
7401 (defcustom gnus-button-url-regexp
7402 (concat
7403 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7404 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7405 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7406 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7407 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7408 (punct "!?:;.,"))
7409 (concat
7410 "\\(?:"
7411 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7412 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7413 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7414 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7415 "\\|"
7416 "[" chars punct "]+" "[" chars "]"
7417 "\\)"))
7418 (concat ;; XEmacs 21.4 doesn't support POSIX.
7419 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7420 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7421 "\\)")
7422 "Regular expression that matches URLs."
7423 :version "24.4"
7424 :group 'gnus-article-buttons
7425 :type 'regexp)
7427 (defcustom gnus-button-valid-fqdn-regexp
7428 message-valid-fqdn-regexp
7429 "Regular expression that matches a valid FQDN."
7430 :version "22.1"
7431 :group 'gnus-article-buttons
7432 :type 'regexp)
7434 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7435 (defcustom gnus-button-valid-localpart-regexp
7436 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7437 "Regular expression that matches a localpart of mail addresses or MIDs."
7438 :version "22.1"
7439 :group 'gnus-article-buttons
7440 :type 'regexp)
7442 (defcustom gnus-button-man-handler 'manual-entry
7443 "Function to use for displaying man pages.
7444 The function must take at least one argument with a string naming the
7445 man page."
7446 :version "22.1"
7447 :type '(choice (function-item :tag "Man" manual-entry)
7448 (function-item :tag "Woman" woman)
7449 (function :tag "Other"))
7450 :group 'gnus-article-buttons)
7452 (defcustom gnus-button-mid-or-mail-regexp
7453 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7454 gnus-button-valid-fqdn-regexp
7455 ">?\\)\\b")
7456 "Regular expression that matches a message ID or a mail address."
7457 :version "22.1"
7458 :group 'gnus-article-buttons
7459 :type 'regexp)
7461 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7462 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7463 Strings like this can be either a message ID or a mail address. If it is one
7464 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7465 message ID or a mail address, respectively. If this variable is set to the
7466 symbol `ask', always query the user what do do. If it is a function, this
7467 function will be called with the string as its only argument. The function
7468 must return `mid', `mail', `invalid' or `ask'."
7469 :version "22.1"
7470 :group 'gnus-article-buttons
7471 :type '(choice (function-item :tag "Heuristic function"
7472 gnus-button-mid-or-mail-heuristic)
7473 (const ask)
7474 (const mid)
7475 (const mail)))
7477 (defcustom gnus-button-mid-or-mail-heuristic-alist
7478 '((-10.0 . ".+\\$.+@")
7479 (-10.0 . "#")
7480 (-10.0 . "\\*")
7481 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7482 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7483 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7484 (-1.0 . "^[^a-z]+@")
7486 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7487 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7488 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7489 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7491 (-2.0 . "^[0-9]")
7492 (-1.0 . "^[0-9][0-9]")
7494 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7495 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7496 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7497 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7499 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7500 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7501 ;; "[0-9]{8,}.*\@"
7502 (-3.0
7503 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7504 ;; "[0-9]{12,}.*\@"
7505 ;; compensation for TDMA dated mail addresses:
7506 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7508 (-20.0 . "\\.fsf@") ;; Gnus
7509 (-20.0 . "^slrn")
7510 (-20.0 . "^Pine")
7511 (-20.0 . "^alpine\\.")
7512 (-20.0 . "_-_") ;; Subject change in thread
7514 (-20.0 . "\\.ln@") ;; leafnode
7515 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7516 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7518 ;; (5.0 . "") ;; $local_part_len <= 7
7519 (10.0 . "^[^0-9]+@")
7520 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7521 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7522 (3.0 . "\@stud")
7524 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7526 (0.5 . "^[A-Z][a-z]")
7527 (0.5 . "^[A-Z][a-z][a-z]")
7528 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7529 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7530 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7532 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7533 address. The REGEXP is processed with `case-fold-search' set to nil."
7534 :version "22.1"
7535 :group 'gnus-article-buttons
7536 :type '(repeat (cons (number :tag "Rate")
7537 (regexp :tag "Regexp"))))
7539 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7540 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7541 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7542 address, `ask' if unsure and `invalid' if the string is invalid."
7543 (let ((case-fold-search nil)
7544 (list gnus-button-mid-or-mail-heuristic-alist)
7545 (result 0) rate regexp lpartlen elem)
7546 (setq lpartlen
7547 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7548 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7549 ;; Certain special cases...
7550 (when (string-match
7551 (concat
7552 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7553 "^[0-9]+\\.[0-9]+@compuserve\\|"
7554 "@public\\.gmane\\.org")
7555 mid-or-mail)
7556 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7557 (setq result 'mail))
7558 (when (string-match "@.*@\\| " mid-or-mail)
7559 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7560 (setq result 'invalid))
7561 ;; Nothing more to do, if result is not a number here...
7562 (when (numberp result)
7563 (while list
7564 (setq elem (car list)
7565 rate (car elem)
7566 regexp (cdr elem)
7567 list (cdr list))
7568 (when (string-match regexp mid-or-mail)
7569 (setq result (+ result rate))
7570 (gnus-message
7571 9 "`%s' matched `%s', rate `%s', result `%s'."
7572 mid-or-mail regexp rate result)))
7573 (when (<= lpartlen 7)
7574 (setq result (+ result 5.0))
7575 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7576 mid-or-mail result))
7577 (when (>= lpartlen 12)
7578 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7579 (cond
7580 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7581 ;; Long local part should contain realname if e-mail address,
7582 ;; too many digits: message-id.
7583 ;; $score -= 5.0 + 0.1 * $local_part_len;
7584 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7585 (setq result (+ result rate))
7586 (gnus-message
7587 9 "Many digits in `%s', rate `%s', result `%s'."
7588 mid-or-mail rate result))
7589 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7590 mid-or-mail)
7591 ;; Too few vowels [^aeiouy]{4,}.*\@
7592 (setq result (+ result -5.0))
7593 (gnus-message
7594 9 "Few vowels in `%s', rate `%s', result `%s'."
7595 mid-or-mail -5.0 result))
7597 (setq result (+ result 5.0))
7598 (gnus-message
7599 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7600 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7601 ;; Maybe we should make this a customizable alist: (condition . 'result)
7602 (cond
7603 ((symbolp result) result)
7604 ;; Now convert number into proper results:
7605 ((< result -10.0) 'mid)
7606 ((> result 10.0) 'mail)
7607 (t 'ask))))
7609 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7610 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7611 (url-mid (concat "news" ":" mid-or-mail))
7612 (url-mailto (concat "mailto" ":" mid-or-mail)))
7613 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7614 (when (fboundp pref)
7615 (setq guessed
7616 ;; get rid of surrounding angles...
7617 (funcall pref
7618 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7619 (if (or (eq 'mid guessed) (eq 'mail guessed))
7620 (setq pref guessed)
7621 (setq pref 'ask)))
7622 (if (eq pref 'ask)
7623 (save-window-excursion
7624 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7625 (setq pref 'mail)
7626 (setq pref 'mid))))
7627 (cond ((eq pref 'mid)
7628 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7629 (gnus-button-handle-news url-mid))
7630 ((eq pref 'mail)
7631 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7632 (gnus-url-mailto url-mailto))
7633 (t (gnus-message 3 "Invalid string.")))))
7635 (defun gnus-button-handle-custom (fun arg)
7636 "Call function FUN on argument ARG.
7637 Both FUN and ARG are supposed to be strings. ARG will be passed
7638 as a symbol to FUN."
7639 (funcall (intern fun)
7640 (if (string-match "^customize-apropos" fun)
7642 (intern arg))))
7644 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7646 (defun gnus-button-handle-describe-function (url)
7647 "Call `describe-function' when pushing the corresponding URL button."
7648 (describe-function
7649 (intern
7650 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7652 (defun gnus-button-handle-describe-variable (url)
7653 "Call `describe-variable' when pushing the corresponding URL button."
7654 (describe-variable
7655 (intern
7656 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7658 (defun gnus-button-handle-symbol (url)
7659 "Display help on variable or function.
7660 Calls `describe-variable' or `describe-function'."
7661 (let ((sym (intern url)))
7662 (cond
7663 ((fboundp sym) (describe-function sym))
7664 ((boundp sym) (describe-variable sym))
7665 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7667 (defun gnus-button-handle-describe-key (url)
7668 "Call `describe-key' when pushing the corresponding URL button."
7669 (let* ((key-string
7670 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7671 (keys (ignore-errors (eval `(kbd ,key-string)))))
7672 (if keys
7673 (describe-key keys)
7674 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7676 (defun gnus-button-handle-apropos (url)
7677 "Call `apropos' when pushing the corresponding URL button."
7678 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7680 (defun gnus-button-handle-apropos-command (url)
7681 "Call `apropos' when pushing the corresponding URL button."
7682 (apropos-command
7683 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7685 (defun gnus-button-handle-apropos-variable (url)
7686 "Call `apropos' when pushing the corresponding URL button."
7687 (funcall
7688 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7689 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7691 (defun gnus-button-handle-apropos-documentation (url)
7692 "Call `apropos' when pushing the corresponding URL button."
7693 (funcall
7694 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7695 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7697 (defun gnus-button-handle-library (url)
7698 "Call `locate-library' when pushing the corresponding URL button."
7699 (gnus-message 9 "url=`%s'" url)
7700 (let* ((lib (locate-library url))
7701 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7702 (if (not lib)
7703 (gnus-message 1 "Cannot locale library `%s'." url)
7704 (find-file-read-only file))))
7706 (defcustom gnus-button-man-level 5
7707 "*Integer that says how many man-related buttons Gnus will show.
7708 The higher the number, the more buttons will appear and the more false
7709 positives are possible. Note that you can set this variable local to
7710 specific groups. Setting it higher in Unix groups is probably a good idea.
7711 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7712 how to set variables in specific groups."
7713 :version "22.1"
7714 :group 'gnus-article-buttons
7715 :link '(custom-manual "(gnus)Group Parameters")
7716 :type 'integer)
7718 (defcustom gnus-button-emacs-level 5
7719 "*Integer that says how many emacs-related buttons Gnus will show.
7720 The higher the number, the more buttons will appear and the more false
7721 positives are possible. Note that you can set this variable local to
7722 specific groups. Setting it higher in Emacs or Gnus related groups is
7723 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7724 `gnus-parameters' on how to set variables in specific groups."
7725 :version "22.1"
7726 :group 'gnus-article-buttons
7727 :link '(custom-manual "(gnus)Group Parameters")
7728 :type 'integer)
7730 (defcustom gnus-button-message-level 5
7731 "*Integer that says how many buttons for news or mail messages will appear.
7732 The higher the number, the more buttons will appear and the more false
7733 positives are possible."
7734 ;; mail addresses, MIDs, URLs for news, ...
7735 :version "22.1"
7736 :group 'gnus-article-buttons
7737 :type 'integer)
7739 (defcustom gnus-button-browse-level 5
7740 "*Integer that says how many buttons for browsing will appear.
7741 The higher the number, the more buttons will appear and the more false
7742 positives are possible."
7743 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7744 :version "22.1"
7745 :group 'gnus-article-buttons
7746 :type 'integer)
7748 (defcustom gnus-button-alist
7749 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7750 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7751 ((concat "\\b\\(nntp\\|news\\):\\("
7752 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7753 0 t gnus-button-handle-news 2)
7754 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7755 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7756 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7757 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7758 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7759 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7760 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7761 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7762 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7763 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7764 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7765 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7766 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7767 ;; RFC 2368 (The mailto URL scheme)
7768 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7769 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7770 ("\\bmailto:\\([^ \n\t]+\\)"
7771 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7772 ;; Info Konqueror style <info:/foo/bar baz>.
7773 ;; Must come before " Gnus home-grown style".
7774 ("\\binfo://?\\([^'\">\n\t]+\\)"
7775 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7776 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7777 ("\\binfo://\\([^'\">\n\t ]+\\)"
7778 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7779 ;; Info GNOME style <info:foo#bar_baz>
7780 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7781 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7782 ;; Info KDE style <info:(foo)bar baz>
7783 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7784 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7785 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7786 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7787 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7788 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7789 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7790 ;; This is custom
7791 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7792 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7793 ;; Emacs help commands
7794 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7795 ;; regexp doesn't match arguments containing ` '.
7796 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7797 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7798 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7799 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7801 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7802 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7803 ;; The following entries may lead to many false positives so don't enable
7804 ;; them by default (use a high button level).
7805 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7806 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7807 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7808 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7809 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7810 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7811 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7812 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7813 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7814 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7815 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7816 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7817 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7818 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7819 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7820 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7821 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7822 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7823 ;; Unlike the other regexps we really have to require quoting
7824 ;; here to determine where it ends.
7825 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7826 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7827 ("<URL: *\\([^\n<>]*\\)>"
7828 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7829 ;; RFC 2396 (2.4.3., delims) ...
7830 ("\"URL: *\\([^\n\"]*\\)\""
7831 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7832 ;; Raw URLs.
7833 (gnus-button-url-regexp
7834 0 (>= gnus-button-browse-level 0) browse-url 0)
7835 ;; man pages
7836 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7837 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7838 gnus-button-handle-man 1)
7839 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7840 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7841 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7842 gnus-button-handle-man 1)
7843 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7844 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7845 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7846 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7847 ;; Recognizing patches to .el files. This is somewhat obscure,
7848 ;; but considering the percentage of Gnus users who hack Emacs
7849 ;; Lisp files...
7850 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7851 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7852 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7853 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7854 ;; MID or mail: To avoid too many false positives we don't try to catch
7855 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7856 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7857 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7858 ;; so that non-ambiguous entries (see above) match first.
7859 (gnus-button-mid-or-mail-regexp
7860 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7861 "*Alist of regexps matching buttons in article bodies.
7863 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7864 REGEXP: is the string (case insensitive) matching text around the button (can
7865 also be Lisp expression evaluating to a string),
7866 BUTTON: is the number of the regexp grouping actually matching the button,
7867 FORM: is a Lisp expression which must eval to true for the button to
7868 be added,
7869 CALLBACK: is the function to call when the user push this button, and each
7870 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7872 CALLBACK can also be a variable, in that case the value of that
7873 variable it the real callback function."
7874 :group 'gnus-article-buttons
7875 :type '(repeat (list (choice regexp variable sexp)
7876 (integer :tag "Button")
7877 (sexp :tag "Form")
7878 (function :tag "Callback")
7879 (repeat :tag "Par"
7880 :inline t
7881 (integer :tag "Regexp group")))))
7882 (put 'gnus-button-alist 'risky-local-variable t)
7884 (defcustom gnus-header-button-alist
7885 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7886 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7887 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7888 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7889 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7890 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7891 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7892 0 (>= gnus-button-browse-level 0) browse-url 0)
7893 ("^Subject:" gnus-button-url-regexp
7894 0 (>= gnus-button-browse-level 0) browse-url 0)
7895 ("^[^:]+:" gnus-button-url-regexp
7896 0 (>= gnus-button-browse-level 0) browse-url 0)
7897 ("^OpenPGP:.*url=" gnus-button-url-regexp
7898 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7899 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7900 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7901 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7902 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7903 "*Alist of headers and regexps to match buttons in article heads.
7905 This alist is very similar to `gnus-button-alist', except that each
7906 alist has an additional HEADER element first in each entry:
7908 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7910 HEADER is a regexp to match a header. For a fuller explanation, see
7911 `gnus-button-alist'."
7912 :group 'gnus-article-buttons
7913 :group 'gnus-article-headers
7914 :type '(repeat (list (regexp :tag "Header")
7915 (choice regexp variable)
7916 (integer :tag "Button")
7917 (sexp :tag "Form")
7918 (function :tag "Callback")
7919 (repeat :tag "Par"
7920 :inline t
7921 (integer :tag "Regexp group")))))
7922 (put 'gnus-header-button-alist 'risky-local-variable t)
7924 ;;; Commands:
7926 (defun gnus-article-push-button (event)
7927 "Check text under the mouse pointer for a callback function.
7928 If the text under the mouse pointer has a `gnus-callback' property,
7929 call it with the value of the `gnus-data' text property."
7930 (interactive "e")
7931 (set-buffer (window-buffer (posn-window (event-start event))))
7932 (let* ((pos (posn-point (event-start event)))
7933 (data (get-text-property pos 'gnus-data))
7934 (fun (get-text-property pos 'gnus-callback)))
7935 (goto-char pos)
7936 (when fun
7937 (funcall fun data))))
7939 (defun gnus-article-press-button ()
7940 "Check text at point for a callback function.
7941 If the text at point has a `gnus-callback' property,
7942 call it with the value of the `gnus-data' text property."
7943 (interactive)
7944 (let ((data (get-text-property (point) 'gnus-data))
7945 (fun (get-text-property (point) 'gnus-callback)))
7946 (when fun
7947 (funcall fun data))))
7949 (defun gnus-article-highlight (&optional force)
7950 "Highlight current article.
7951 This function calls `gnus-article-highlight-headers',
7952 `gnus-article-highlight-citation',
7953 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7954 do the highlighting. See the documentation for those functions."
7955 (interactive (list 'force))
7956 (gnus-article-highlight-headers)
7957 (gnus-article-highlight-citation force)
7958 (gnus-article-highlight-signature)
7959 (gnus-article-add-buttons)
7960 (gnus-article-add-buttons-to-head))
7962 (defun gnus-article-highlight-some (&optional force)
7963 "Highlight current article.
7964 This function calls `gnus-article-highlight-headers',
7965 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7966 do the highlighting. See the documentation for those functions."
7967 (interactive (list 'force))
7968 (gnus-article-highlight-headers)
7969 (gnus-article-highlight-signature)
7970 (gnus-article-add-buttons))
7972 (defun gnus-article-highlight-headers ()
7973 "Highlight article headers as specified by `gnus-header-face-alist'."
7974 (interactive)
7975 (gnus-with-article-headers
7976 (let (regexp header-face field-face from hpoints fpoints)
7977 (dolist (entry gnus-header-face-alist)
7978 (goto-char (point-min))
7979 (setq regexp (concat "^\\("
7980 (if (string-equal "" (nth 0 entry))
7981 "[^\t ]"
7982 (nth 0 entry))
7983 "\\)")
7984 header-face (nth 1 entry)
7985 field-face (nth 2 entry))
7986 (while (and (re-search-forward regexp nil t)
7987 (not (eobp)))
7988 (beginning-of-line)
7989 (setq from (point))
7990 (unless (search-forward ":" nil t)
7991 (forward-char 1))
7992 (when (and header-face
7993 (not (memq (point) hpoints)))
7994 (push (point) hpoints)
7995 (gnus-put-text-property from (point) 'face header-face))
7996 (when (and field-face
7997 (not (memq (setq from (point)) fpoints)))
7998 (push from fpoints)
7999 (if (re-search-forward "^[^ \t]" nil t)
8000 (forward-char -2)
8001 (goto-char (point-max)))
8002 (gnus-put-text-property from (point) 'face field-face)))))))
8004 (defun gnus-article-highlight-signature ()
8005 "Highlight the signature in an article.
8006 It does this by highlighting everything after
8007 `gnus-signature-separator' using the face `gnus-signature'."
8008 (interactive)
8009 (gnus-with-article-buffer
8010 (let ((inhibit-point-motion-hooks t))
8011 (save-restriction
8012 (when (and gnus-signature-face
8013 (gnus-article-narrow-to-signature))
8014 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8015 'face gnus-signature-face)
8016 (widen)
8017 (gnus-article-search-signature)
8018 (let ((start (match-beginning 0))
8019 (end (set-marker (make-marker) (1+ (match-end 0)))))
8020 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8021 end)))))))
8023 (defun gnus-button-in-region-p (b e prop)
8024 "Say whether PROP exists in the region."
8025 (text-property-not-all b e prop nil))
8027 (defun gnus-article-add-buttons ()
8028 "Find external references in the article and make buttons of them.
8029 \"External references\" are things like Message-IDs and URLs, as
8030 specified by `gnus-button-alist'."
8031 (interactive)
8032 (gnus-with-article-buffer
8033 (let ((inhibit-point-motion-hooks t)
8034 (case-fold-search t)
8035 (alist gnus-button-alist)
8036 beg entry regexp)
8037 ;; We skip the headers.
8038 (article-goto-body)
8039 (setq beg (point))
8040 (while (setq entry (pop alist))
8041 (setq regexp (eval (car entry)))
8042 (goto-char beg)
8043 (while (re-search-forward regexp nil t)
8044 (let ((start (match-beginning (nth 1 entry)))
8045 (end (match-end (nth 1 entry)))
8046 (from (match-beginning 0)))
8047 (when (and (eval (nth 2 entry))
8048 (not (gnus-button-in-region-p
8049 start end 'gnus-callback)))
8050 ;; That optional form returned non-nil, so we add the
8051 ;; button.
8052 (setq from (set-marker (make-marker) from))
8053 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8054 (gnus-article-extend-url-button from start end))
8055 (gnus-article-add-button start end
8056 'gnus-button-push (list from entry))
8057 (gnus-put-text-property
8058 start end
8059 'gnus-string (buffer-substring-no-properties
8060 start end))))))))))
8062 (defun gnus-article-extend-url-button (beg start end)
8063 "Extend url button if url is folded into two or more lines.
8064 Return non-nil if button is extended. BEG is a marker that points to
8065 the beginning position of a text containing url. START and END are
8066 the endpoints of a url button before it is extended. The concatenated
8067 url is put as the `gnus-button-url' overlay property on the button."
8068 (let ((opoint (point))
8069 (points (list start end))
8070 url delim regexp)
8071 (prog1
8072 (when (and (progn
8073 (goto-char end)
8074 (not (looking-at "[\t ]*[\">]")))
8075 (progn
8076 (goto-char start)
8077 (string-match
8078 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8079 (buffer-substring (point-at-bol) start)))
8080 (progn
8081 (setq url (list (buffer-substring start end))
8082 delim (if (match-beginning 1) ">" "\""))
8083 (beginning-of-line)
8084 (setq regexp (concat
8085 (when (and (looking-at
8086 message-cite-prefix-regexp)
8087 (< (match-end 0) start))
8088 (regexp-quote (match-string 0)))
8090 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8091 delim "\\)"))
8092 (while (progn
8093 (forward-line 1)
8094 (and (looking-at regexp)
8095 (prog1
8096 (match-beginning 1)
8097 (push (or (match-string 2)
8098 (match-string 1))
8099 url)
8100 (push (setq end (or (match-end 2)
8101 (match-end 1)))
8102 points)
8103 (push (or (match-beginning 2)
8104 (match-beginning 1))
8105 points)))))
8106 (match-beginning 2)))
8107 (let (gnus-article-mouse-face widget-mouse-face)
8108 (while points
8109 (gnus-article-add-button (pop points) (pop points)
8110 'gnus-button-push
8111 (list beg (assq 'gnus-button-url-regexp
8112 gnus-button-alist)))))
8113 (let ((overlay (gnus-make-overlay start end)))
8114 (gnus-overlay-put overlay 'evaporate t)
8115 (gnus-overlay-put overlay 'gnus-button-url
8116 (list (mapconcat 'identity (nreverse url) "")))
8117 (when gnus-article-mouse-face
8118 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8120 (goto-char opoint))))
8122 ;; Add buttons to the head of an article.
8123 (defun gnus-article-add-buttons-to-head ()
8124 "Add buttons to the head of the article."
8125 (interactive)
8126 (gnus-with-article-headers
8127 (let (beg end)
8128 (dolist (entry gnus-header-button-alist)
8129 ;; Each alist entry.
8130 (goto-char (point-min))
8131 (while (re-search-forward (car entry) nil t)
8132 ;; Each header matching the entry.
8133 (setq beg (match-beginning 0))
8134 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8135 (match-beginning 0))
8136 (point-max)))
8137 (goto-char beg)
8138 (while (re-search-forward (eval (nth 1 entry)) end t)
8139 ;; Each match within a header.
8140 (let* ((entry (cdr entry))
8141 (start (match-beginning (nth 1 entry)))
8142 (end (match-end (nth 1 entry)))
8143 (form (nth 2 entry)))
8144 (goto-char (match-end 0))
8145 (when (eval form)
8146 (gnus-article-add-button
8147 start end (nth 3 entry)
8148 (buffer-substring (match-beginning (nth 4 entry))
8149 (match-end (nth 4 entry)))))))
8150 (goto-char end))))))
8152 ;;; External functions:
8154 (defun gnus-article-add-button (from to fun &optional data text)
8155 "Create a button between FROM and TO with callback FUN and data DATA."
8156 (when gnus-article-button-face
8157 (gnus-overlay-put (gnus-make-overlay from to nil t)
8158 'face gnus-article-button-face))
8159 (gnus-add-text-properties
8160 from to
8161 (nconc (and gnus-article-mouse-face
8162 (list gnus-mouse-face-prop gnus-article-mouse-face))
8163 (list 'gnus-callback fun)
8164 (and data (list 'gnus-data data))))
8165 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8166 :help-echo (or text "Follow the link")
8167 :keymap gnus-url-button-map
8168 :button-keymap gnus-widget-button-keymap))
8170 (defun gnus-article-copy-string ()
8171 "Copy the string in the button to the kill ring."
8172 (interactive)
8173 (gnus-article-check-buffer)
8174 (let ((data (get-text-property (point) 'gnus-string)))
8175 (when data
8176 (with-temp-buffer
8177 (insert data)
8178 (copy-region-as-kill (point-min) (point-max))
8179 (message "Copied %s" data)))))
8181 ;;; Internal functions:
8183 (defun gnus-article-set-globals ()
8184 (with-current-buffer gnus-summary-buffer
8185 (gnus-set-global-variables)))
8187 (defun gnus-signature-toggle (end)
8188 (gnus-with-article-buffer
8189 (let ((inhibit-point-motion-hooks t))
8190 (if (text-property-any end (point-max) 'article-type 'signature)
8191 (progn
8192 (gnus-delete-wash-type 'signature)
8193 (gnus-remove-text-properties-when
8194 'article-type 'signature end (point-max)
8195 (cons 'article-type (cons 'signature
8196 gnus-hidden-properties))))
8197 (gnus-add-wash-type 'signature)
8198 (gnus-add-text-properties-when
8199 'article-type nil end (point-max)
8200 (cons 'article-type (cons 'signature
8201 gnus-hidden-properties)))))
8202 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8203 (gnus-set-mode-line 'article))))
8205 (defun gnus-button-push (marker-and-entry)
8206 ;; Push button starting at MARKER.
8207 (save-excursion
8208 (let* ((marker (car marker-and-entry))
8209 (entry (cadr marker-and-entry))
8210 (regexp (car entry))
8211 (inhibit-point-motion-hooks t))
8212 (goto-char marker)
8213 ;; This is obviously true, or something bad is happening :)
8214 ;; But we need it to have the match-data
8215 (when (looking-at (or (if (symbolp regexp)
8216 (symbol-value regexp)
8217 regexp)))
8218 (let ((fun (nth 3 entry))
8219 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8220 (get-char-property marker 'gnus-button-url))
8221 (mapcar (lambda (group)
8222 (let ((string (match-string group)))
8223 (set-text-properties
8224 0 (length string) nil string)
8225 string))
8226 (nthcdr 4 entry)))))
8228 (cond
8229 ((fboundp fun)
8230 (apply fun args))
8231 ((and (boundp fun)
8232 (fboundp (symbol-value fun)))
8233 (apply (symbol-value fun) args))
8235 (gnus-message 1 "You must define `%S' to use this button"
8236 (cons fun args)))))))))
8238 (defun gnus-parse-news-url (url)
8239 (let (scheme server port group message-id articles)
8240 (with-temp-buffer
8241 (insert url)
8242 (goto-char (point-min))
8243 (when (looking-at "\\([A-Za-z]+\\):")
8244 (setq scheme (match-string 1))
8245 (goto-char (match-end 0)))
8246 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8247 (setq server (match-string 1))
8248 (setq port (if (stringp (match-string 3))
8249 (string-to-number (match-string 3))
8250 (match-string 3)))
8251 (goto-char (match-end 0)))
8253 (cond
8254 ((looking-at "\\(.*@.*\\)")
8255 (setq message-id (match-string 1)))
8256 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8257 (setq group (match-string 1)
8258 articles (split-string (match-string 2) "-")))
8259 ((looking-at "\\([^/]+\\)/?")
8260 (setq group (match-string 1)))
8262 (error "Unknown news URL syntax"))))
8263 (list scheme server port group message-id articles)))
8265 (defun gnus-button-handle-news (url)
8266 "Fetch a news URL."
8267 (destructuring-bind (scheme server port group message-id articles)
8268 (gnus-parse-news-url url)
8269 (cond
8270 (message-id
8271 (with-current-buffer gnus-summary-buffer
8272 (if server
8273 (let ((gnus-refer-article-method
8274 (nconc (list (list 'nntp server))
8275 gnus-refer-article-method))
8276 (nntp-port-number (or port "nntp")))
8277 (gnus-message 7 "Fetching %s with %s"
8278 message-id gnus-refer-article-method)
8279 (gnus-summary-refer-article message-id))
8280 (gnus-summary-refer-article message-id))))
8281 (group
8282 (gnus-button-fetch-group url)))))
8284 (defun gnus-button-patch (library line)
8285 "Visit an Emacs Lisp library LIBRARY on line LINE."
8286 (interactive)
8287 (let ((file (locate-library (file-name-nondirectory library))))
8288 (unless file
8289 (error "Couldn't find library %s" library))
8290 (find-file file)
8291 (goto-char (point-min))
8292 (forward-line (1- (string-to-number line)))))
8294 (defun gnus-button-handle-man (url)
8295 "Fetch a man page."
8296 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8297 (when (eq gnus-button-man-handler 'woman)
8298 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8299 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8300 (funcall gnus-button-man-handler url))
8302 (defun gnus-button-handle-info-url (url)
8303 "Fetch an info URL."
8304 (setq url (mm-subst-char-in-string ?+ ?\ url))
8305 (cond
8306 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8307 (gnus-info-find-node
8308 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8309 "Gnus")
8310 ")" (gnus-url-unhex-string (match-string 2 url)))))
8311 ((string-match "([^)\"]+)[^\"]+" url)
8312 (setq url
8313 (gnus-replace-in-string
8314 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8315 (gnus-info-find-node url))
8316 (t (error "Can't parse %s" url))))
8318 (defun gnus-button-handle-info-url-gnome (url)
8319 "Fetch GNOME style info URL."
8320 (setq url (mm-subst-char-in-string ?_ ?\ url))
8321 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8322 (gnus-info-find-node
8323 (concat "("
8324 (gnus-url-unhex-string
8325 (match-string 1 url))
8327 (or (gnus-url-unhex-string
8328 (match-string 2 url))
8329 "Top")))
8330 (error "Can't parse %s" url)))
8332 (defun gnus-button-handle-info-url-kde (url)
8333 "Fetch KDE style info URL."
8334 (gnus-info-find-node (gnus-url-unhex-string url)))
8336 ;; (info) will autoload info.el
8337 (declare-function Info-menu "info" (menu-item &optional fork))
8338 (declare-function Info-index-next "info" (num))
8340 (defun gnus-button-handle-info-keystrokes (url)
8341 "Call `info' when pushing the corresponding URL button."
8342 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8343 (let (node indx comma)
8344 (if (string-match
8345 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8346 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8347 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8348 "\\(?:[ \t\n,]*\\)\\)?")
8349 url)
8350 (setq node (match-string 2 url)
8351 indx (match-string 3 url))
8352 (error "Can't parse %s" url))
8353 (info)
8354 (Info-directory)
8355 (Info-menu node)
8356 (when (> (length indx) 0)
8357 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8358 "\\([ \t\n,]*\\)")
8359 indx)
8360 (setq comma (match-string 2 indx))
8361 (setq indx (match-string 1 indx))
8362 (Info-index indx)
8363 (when comma
8364 (dotimes (i (with-temp-buffer
8365 (insert comma)
8366 ;; Note: the XEmacs version of `how-many' takes
8367 ;; no optional argument.
8368 (goto-char (point-min))
8369 (how-many ",")))
8370 (Info-index-next 1)))
8371 nil)))
8373 (autoload 'pgg-snarf-keys-region "pgg")
8374 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8375 (declare-function pgg-display-output-buffer "pgg" (start end status))
8377 (defun gnus-button-openpgp (url)
8378 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8379 (with-temp-buffer
8380 (mm-url-insert-file-contents-external url)
8381 (pgg-snarf-keys-region (point-min) (point-max))
8382 (pgg-display-output-buffer nil nil nil)))
8384 (defun gnus-button-message-id (message-id)
8385 "Fetch MESSAGE-ID."
8386 (with-current-buffer gnus-summary-buffer
8387 (gnus-summary-refer-article message-id)))
8389 (defun gnus-button-fetch-group (address &rest ignore)
8390 "Fetch GROUP specified by ADDRESS."
8391 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8392 address)
8393 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8394 ;; for nntp:// and news://
8395 (setq address (match-string 3 address)))
8396 (if (not (string-match "[:/]" address))
8397 ;; This is just a simple group url.
8398 (gnus-group-read-ephemeral-group address gnus-select-method)
8399 (if (not
8400 (string-match
8401 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8402 address))
8403 (error "Can't parse %s" address)
8404 (gnus-group-read-ephemeral-group
8405 (match-string 4 address)
8406 `(nntp ,(match-string 1 address)
8407 (nntp-address ,(match-string 1 address))
8408 (nntp-port-number ,(if (match-end 3)
8409 (match-string 3 address)
8410 "nntp")))
8411 nil nil nil
8412 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8414 (defun gnus-url-parse-query-string (query &optional downcase)
8415 (let (retval pairs cur key val)
8416 (setq pairs (split-string query "&"))
8417 (while pairs
8418 (setq cur (car pairs)
8419 pairs (cdr pairs))
8420 (if (not (string-match "=" cur))
8421 nil ; Grace
8422 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8423 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8424 (if downcase
8425 (setq key (downcase key)))
8426 (setq cur (assoc key retval))
8427 (if cur
8428 (setcdr cur (cons val (cdr cur)))
8429 (setq retval (cons (list key val) retval)))))
8430 retval))
8432 (defun gnus-url-mailto (url)
8433 ;; Send mail to someone
8434 (setq url (replace-regexp-in-string "\n" " " url))
8435 (when (string-match "mailto:/*\\(.*\\)" url)
8436 (setq url (substring url (match-beginning 1) nil)))
8437 (let (to args subject func)
8438 (setq args (gnus-url-parse-query-string
8439 (if (string-match "^\\?" url)
8440 (substring url 1)
8441 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8442 (concat "to=" (match-string 1 url) "&"
8443 (match-string 2 url))
8444 (concat "to=" url))))
8445 subject (cdr-safe (assoc "subject" args)))
8446 (gnus-msg-mail)
8447 (while args
8448 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8449 (if (fboundp func)
8450 (funcall func)
8451 (message-position-on-field (caar args)))
8452 (insert (gnus-replace-in-string
8453 (mapconcat 'identity (reverse (cdar args)) ", ")
8454 "\r\n" "\n" t))
8455 (setq args (cdr args)))
8456 (if subject
8457 (message-goto-body)
8458 (message-goto-subject))))
8460 (defun gnus-button-embedded-url (address)
8461 "Activate ADDRESS with `browse-url'."
8462 (browse-url (gnus-strip-whitespace address)))
8464 ;;; Next/prev buttons in the article buffer.
8466 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8467 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8469 (defvar gnus-prev-page-map
8470 (let ((map (make-sparse-keymap)))
8471 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8472 (define-key map "\r" 'gnus-button-prev-page)
8473 map))
8475 (defvar gnus-next-page-map
8476 (let ((map (make-sparse-keymap)))
8477 (define-key map gnus-mouse-2 'gnus-button-next-page)
8478 (define-key map "\r" 'gnus-button-next-page)
8479 map))
8481 (defun gnus-insert-prev-page-button ()
8482 (let ((b (point)) e
8483 (inhibit-read-only t))
8484 (gnus-eval-format
8485 gnus-prev-page-line-format nil
8486 `(keymap ,gnus-prev-page-map
8487 gnus-prev t
8488 gnus-callback gnus-article-button-prev-page
8489 article-type annotation))
8490 (setq e (if (bolp)
8491 ;; Exclude a newline.
8492 (1- (point))
8493 (point)))
8494 (when gnus-article-button-face
8495 (gnus-overlay-put (gnus-make-overlay b e nil t)
8496 'face gnus-article-button-face))
8497 (widget-convert-button
8498 'link b e
8499 :action 'gnus-button-prev-page
8500 :button-keymap gnus-prev-page-map)))
8502 (defun gnus-button-next-page (&optional args more-args)
8503 "Go to the next page."
8504 (interactive)
8505 (let ((win (selected-window)))
8506 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8507 (gnus-article-next-page)
8508 (select-window win)))
8510 (defun gnus-button-prev-page (&optional args more-args)
8511 "Go to the prev page."
8512 (interactive)
8513 (let ((win (selected-window)))
8514 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8515 (gnus-article-prev-page)
8516 (select-window win)))
8518 (defun gnus-insert-next-page-button ()
8519 (let ((b (point)) e
8520 (inhibit-read-only t))
8521 (gnus-eval-format gnus-next-page-line-format nil
8522 `(keymap ,gnus-next-page-map
8523 gnus-next t
8524 gnus-callback gnus-article-button-next-page
8525 article-type annotation))
8526 (setq e (if (bolp)
8527 ;; Exclude a newline.
8528 (1- (point))
8529 (point)))
8530 (when gnus-article-button-face
8531 (gnus-overlay-put (gnus-make-overlay b e nil t)
8532 'face gnus-article-button-face))
8533 (widget-convert-button
8534 'link b e
8535 :action 'gnus-button-next-page
8536 :button-keymap gnus-next-page-map)))
8538 (defun gnus-article-button-next-page (arg)
8539 "Go to the next page."
8540 (interactive "P")
8541 (let ((win (selected-window)))
8542 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8543 (gnus-article-next-page)
8544 (select-window win)))
8546 (defun gnus-article-button-prev-page (arg)
8547 "Go to the prev page."
8548 (interactive "P")
8549 (let ((win (selected-window)))
8550 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8551 (gnus-article-prev-page)
8552 (select-window win)))
8554 (defvar gnus-decode-header-methods
8555 '(mail-decode-encoded-word-region)
8556 "List of methods used to decode headers.
8558 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8559 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8560 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8561 whose names match REGEXP.
8563 For example:
8564 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8565 mail-decode-encoded-word-region
8566 (\"chinese\" . rfc1843-decode-region))
8569 (defvar gnus-decode-header-methods-cache nil)
8571 (defun gnus-multi-decode-header (start end)
8572 "Apply the functions from `gnus-encoded-word-methods' that match."
8573 (unless (and gnus-decode-header-methods-cache
8574 (eq gnus-newsgroup-name
8575 (car gnus-decode-header-methods-cache)))
8576 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8577 (dolist (x gnus-decode-header-methods)
8578 (if (symbolp x)
8579 (nconc gnus-decode-header-methods-cache (list x))
8580 (if (and gnus-newsgroup-name
8581 (string-match (car x) gnus-newsgroup-name))
8582 (nconc gnus-decode-header-methods-cache
8583 (list (cdr x)))))))
8584 (let ((xlist gnus-decode-header-methods-cache))
8585 (pop xlist)
8586 (save-restriction
8587 (narrow-to-region start end)
8588 (while xlist
8589 (funcall (pop xlist) (point-min) (point-max))))))
8592 ;;; Treatment top-level handling.
8595 (defvar gnus-inhibit-article-treatments nil)
8597 (defun gnus-treat-article (gnus-treat-condition
8598 &optional part-number total-parts gnus-treat-type)
8599 (let ((gnus-treat-length (- (point-max) (point-min)))
8600 (alist gnus-treatment-function-alist)
8601 (article-goto-body-goes-to-point-min-p t)
8602 (treated-type
8603 (or (not gnus-treat-type)
8604 (catch 'found
8605 (let ((list gnus-article-treat-types))
8606 (while list
8607 (when (string-match (pop list) gnus-treat-type)
8608 (throw 'found t)))))))
8609 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8610 val elem)
8611 (gnus-run-hooks 'gnus-part-display-hook)
8612 (dolist (elem alist)
8613 (setq val
8614 (save-excursion
8615 (when (gnus-buffer-live-p gnus-summary-buffer)
8616 (set-buffer gnus-summary-buffer))
8617 (symbol-value (car elem))))
8618 (when (and (or (consp val)
8619 treated-type)
8620 (or (not gnus-inhibit-article-treatments)
8621 (eq gnus-treat-condition 'head))
8622 (gnus-treat-predicate val)
8623 (or (not (get (car elem) 'highlight))
8624 highlightp))
8625 (save-restriction
8626 (funcall (cadr elem)))))))
8628 ;; Dynamic variables.
8629 (defvar part-number)
8630 (defvar total-parts)
8631 (defvar gnus-treat-type)
8632 (defvar gnus-treat-condition)
8633 (defvar gnus-treat-length)
8635 (defun gnus-treat-predicate (val)
8636 (cond
8637 ((null val)
8638 nil)
8639 (gnus-treat-condition
8640 (eq gnus-treat-condition val))
8641 ((and (listp val)
8642 (stringp (car val)))
8643 (apply 'gnus-or (mapcar `(lambda (s)
8644 (string-match s ,(or gnus-newsgroup-name "")))
8645 val)))
8646 ((listp val)
8647 (let ((pred (pop val)))
8648 (cond
8649 ((eq pred 'or)
8650 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8651 ((eq pred 'and)
8652 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8653 ((eq pred 'not)
8654 (not (gnus-treat-predicate (car val))))
8655 ((eq pred 'typep)
8656 (equal (car val) gnus-treat-type))
8657 ((functionp pred)
8658 (funcall pred))
8660 (error "%S is not a valid predicate" pred)))))
8661 ((eq val t)
8663 ((eq val 'head)
8664 nil)
8665 ((eq val 'first)
8666 (eq part-number 1))
8667 ((eq val 'last)
8668 (eq part-number total-parts))
8669 ((numberp val)
8670 (< gnus-treat-length val))
8672 (error "%S is not a valid value" val))))
8674 (defun gnus-article-encrypt-body (protocol &optional n)
8675 "Encrypt the article body."
8676 (interactive
8677 (list
8678 (or gnus-article-encrypt-protocol
8679 (gnus-completing-read "Encrypt protocol"
8680 (mapcar 'car gnus-article-encrypt-protocol-alist)
8682 current-prefix-arg))
8683 ;; User might hit `K E' instead of `K e', so prompt once.
8684 (when (and gnus-article-encrypt-protocol
8685 gnus-novice-user)
8686 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8687 (error "Encrypt aborted")))
8688 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8689 (unless func
8690 (error "Can't find the encrypt protocol %s" protocol))
8691 (if (member gnus-newsgroup-name '("nndraft:delayed"
8692 "nndraft:drafts"
8693 "nndraft:queue"))
8694 (error "Can't encrypt the article in group %s"
8695 gnus-newsgroup-name))
8696 (gnus-summary-iterate n
8697 (with-current-buffer gnus-summary-buffer
8698 (let ((mail-parse-charset gnus-newsgroup-charset)
8699 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8700 (summary-buffer gnus-summary-buffer)
8701 references point)
8702 (gnus-set-global-variables)
8703 (when (gnus-group-read-only-p)
8704 (error "The current newsgroup does not support article encrypt"))
8705 (gnus-summary-show-article t)
8706 (setq references
8707 (or (mail-header-references gnus-current-headers) ""))
8708 (set-buffer gnus-article-buffer)
8709 (let* ((inhibit-read-only t)
8710 (headers
8711 (mapcar (lambda (field)
8712 (and (save-restriction
8713 (message-narrow-to-head)
8714 (goto-char (point-min))
8715 (search-forward field nil t))
8716 (prog2
8717 (message-narrow-to-field)
8718 (buffer-string)
8719 (delete-region (point-min) (point-max))
8720 (widen))))
8721 '("Content-Type:" "Content-Transfer-Encoding:"
8722 "Content-Disposition:"))))
8723 (message-narrow-to-head)
8724 (message-remove-header "MIME-Version")
8725 (goto-char (point-max))
8726 (setq point (point))
8727 (insert (apply 'concat headers))
8728 (widen)
8729 (narrow-to-region point (point-max))
8730 (let ((message-options message-options))
8731 (message-options-set 'message-sender user-mail-address)
8732 (message-options-set 'message-recipients user-mail-address)
8733 (message-options-set 'message-sign-encrypt 'not)
8734 (funcall func))
8735 (goto-char (point-min))
8736 (insert "MIME-Version: 1.0\n")
8737 (widen)
8738 (gnus-summary-edit-article-done
8739 references nil summary-buffer t))
8740 (when gnus-keep-backlog
8741 (gnus-backlog-remove-article
8742 (car gnus-article-current) (cdr gnus-article-current)))
8743 (gnus-flush-original-article-buffer)
8744 (when gnus-use-cache
8745 (gnus-cache-update-article
8746 (car gnus-article-current) (cdr gnus-article-current))))))))
8748 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8749 "The following specs can be used:
8750 %t The security MIME type
8751 %i Additional info
8752 %d Details
8753 %D Details if button is pressed")
8755 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8756 "The following specs can be used:
8757 %t The security MIME type
8758 %i Additional info
8759 %d Details
8760 %D Details if button is pressed")
8762 (defvar gnus-mime-security-button-line-format-alist
8763 '((?t gnus-tmp-type ?s)
8764 (?i gnus-tmp-info ?s)
8765 (?d gnus-tmp-details ?s)
8766 (?D gnus-tmp-pressed-details ?s)))
8768 (defvar gnus-mime-security-button-commands
8769 '((gnus-article-press-button "\r" "Show Detail")
8770 (undefined "v")
8771 (undefined "t")
8772 (undefined "C")
8773 (gnus-mime-security-save-part "o" "Save...")
8774 (undefined "\C-o")
8775 (undefined "r")
8776 (undefined "d")
8777 (undefined "c")
8778 (undefined "i")
8779 (undefined "E")
8780 (undefined "e")
8781 (undefined "p")
8782 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8783 (undefined ".")))
8785 (defvar gnus-mime-security-button-map
8786 (let ((map (make-sparse-keymap)))
8787 (define-key map gnus-mouse-2 'gnus-article-push-button)
8788 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8789 (dolist (c gnus-mime-security-button-commands)
8790 (define-key map (cadr c) (car c)))
8791 map))
8793 (easy-menu-define
8794 gnus-mime-security-button-menu gnus-mime-security-button-map
8795 "Security button menu."
8796 `("Security Part"
8797 ,@(delq nil
8798 (mapcar (lambda (c)
8799 (unless (eq (car c) 'undefined)
8800 (vector (caddr c) (car c) :active t)))
8801 gnus-mime-security-button-commands))))
8803 (defun gnus-mime-security-button-menu (event prefix)
8804 "Construct a context-sensitive menu of security commands."
8805 (interactive "e\nP")
8806 (save-window-excursion
8807 (let ((pos (event-start event)))
8808 (select-window (posn-window pos))
8809 (goto-char (posn-point pos))
8810 (gnus-article-check-buffer)
8811 (popup-menu gnus-mime-security-button-menu nil prefix))))
8813 (defvar gnus-mime-security-details-buffer nil)
8815 (defvar gnus-mime-security-button-pressed nil)
8817 (defvar gnus-mime-security-show-details-inline t
8818 "If non-nil, show details in the article buffer.")
8820 (defun gnus-mime-security-verify-or-decrypt (handle)
8821 (mm-remove-parts (cdr handle))
8822 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8823 point (inhibit-read-only t))
8824 (if region
8825 (goto-char (car region)))
8826 (setq point (point))
8827 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8828 (let* ((mm-verify-option 'known)
8829 (mm-decrypt-option 'known)
8830 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8831 (unless (eq nparts (cdr handle))
8832 (mm-destroy-parts (cdr handle))
8833 (setcdr handle nparts))))
8834 (gnus-mime-display-security handle)
8835 (when region
8836 (delete-region (point) (cdr region))
8837 (set-marker (car region) nil)
8838 (set-marker (cdr region) nil))
8839 (goto-char point)))
8841 (defun gnus-mime-security-show-details (handle)
8842 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8843 (if (not details)
8844 (gnus-message 5 "No details.")
8845 (if gnus-mime-security-show-details-inline
8846 (let ((gnus-mime-security-button-pressed
8847 (not (get-text-property (point) 'gnus-mime-details)))
8848 (gnus-mime-security-button-line-format
8849 (get-text-property (point) 'gnus-line-format))
8850 (inhibit-read-only t))
8851 (forward-char -1)
8852 (while (eq (get-text-property (point) 'gnus-line-format)
8853 gnus-mime-security-button-line-format)
8854 (forward-char -1))
8855 (forward-char)
8856 (save-restriction
8857 (narrow-to-region (point) (point))
8858 (gnus-insert-mime-security-button handle))
8859 (delete-region (point)
8860 (or (text-property-not-all
8861 (point) (point-max)
8862 'gnus-line-format
8863 gnus-mime-security-button-line-format)
8864 (point-max))))
8865 ;; Not inlined.
8866 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8867 (with-current-buffer gnus-mime-security-details-buffer
8868 (erase-buffer)
8870 (setq gnus-mime-security-details-buffer
8871 (gnus-get-buffer-create "*MIME Security Details*")))
8872 (with-current-buffer gnus-mime-security-details-buffer
8873 (insert details)
8874 (goto-char (point-min)))
8875 (pop-to-buffer gnus-mime-security-details-buffer)))))
8877 (defun gnus-mime-security-press-button (handle)
8878 (save-excursion
8879 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8880 (gnus-mime-security-show-details handle)
8881 (gnus-mime-security-verify-or-decrypt handle))))
8883 (defun gnus-insert-mime-security-button (handle &optional displayed)
8884 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8885 (gnus-tmp-type
8886 (concat
8887 (or (nth 2 (assoc protocol mm-verify-function-alist))
8888 (nth 2 (assoc protocol mm-decrypt-function-alist))
8889 "Unknown")
8890 (if (equal (car handle) "multipart/signed")
8891 " Signed" " Encrypted")
8892 " Part"))
8893 (gnus-tmp-info
8894 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8895 "Undecided"))
8896 (gnus-tmp-details
8897 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8898 gnus-tmp-pressed-details
8899 b e)
8900 (setq gnus-tmp-details
8901 (if gnus-tmp-details
8902 (concat "\n" gnus-tmp-details)
8903 ""))
8904 (setq gnus-tmp-pressed-details
8905 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8906 (unless (bolp)
8907 (insert "\n"))
8908 (setq b (point))
8909 (gnus-eval-format
8910 gnus-mime-security-button-line-format
8911 gnus-mime-security-button-line-format-alist
8912 `(keymap ,gnus-mime-security-button-map
8913 gnus-callback gnus-mime-security-press-button
8914 gnus-line-format ,gnus-mime-security-button-line-format
8915 gnus-mime-details ,gnus-mime-security-button-pressed
8916 article-type annotation
8917 gnus-data ,handle))
8918 (setq e (if (bolp)
8919 ;; Exclude a newline.
8920 (1- (point))
8921 (point)))
8922 (when gnus-article-button-face
8923 (gnus-overlay-put (gnus-make-overlay b e nil t)
8924 'face gnus-article-button-face))
8925 (widget-convert-button
8926 'link b e
8927 :mime-handle handle
8928 :action 'gnus-widget-press-button
8929 :button-keymap gnus-mime-security-button-map
8930 :help-echo
8931 (lambda (widget)
8932 ;; Needed to properly clear the message due to a bug in
8933 ;; wid-edit (XEmacs only).
8934 (when (boundp 'help-echo-owns-message)
8935 (setq help-echo-owns-message t))
8936 (format
8937 "%S: show detail; %S: more options"
8938 (aref gnus-mouse-2 0)
8939 (aref gnus-down-mouse-3 0))))))
8941 (defun gnus-mime-display-security (handle)
8942 (save-restriction
8943 (narrow-to-region (point) (point))
8944 (unless (gnus-unbuttonized-mime-type-p (car handle))
8945 (gnus-insert-mime-security-button handle))
8946 (gnus-mime-display-part (cadr handle))
8947 (unless (bolp)
8948 (insert "\n"))
8949 (unless (gnus-unbuttonized-mime-type-p (car handle))
8950 (let ((gnus-mime-security-button-line-format
8951 gnus-mime-security-button-end-line-format))
8952 (gnus-insert-mime-security-button handle)))
8953 (mm-set-handle-multipart-parameter
8954 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8955 (goto-char (point-max))))
8957 (defun gnus-mime-security-run-function (function)
8958 "Run FUNCTION with the security part under point."
8959 (gnus-article-check-buffer)
8960 (let ((data (get-text-property (point) 'gnus-data))
8961 buffer handle)
8962 (when (and (stringp (car-safe data))
8963 (setq buffer (mm-handle-multipart-original-buffer data))
8964 (setq handle (cadr data)))
8965 (if (bufferp (mm-handle-buffer handle))
8966 (progn
8967 (setq handle (cons buffer (copy-sequence (cdr handle))))
8968 (mm-handle-set-undisplayer handle nil))
8969 (setq handle (mm-make-handle
8970 buffer
8971 (mm-handle-multipart-ctl-parameter handle 'protocol)
8972 nil nil nil nil nil nil)))
8973 (funcall function handle))))
8975 (defun gnus-mime-security-save-part ()
8976 "Save the security part under point."
8977 (interactive)
8978 (gnus-mime-security-run-function 'mm-save-part))
8980 (defun gnus-mime-security-pipe-part ()
8981 "Pipe the security part under point to a process."
8982 (interactive)
8983 (gnus-mime-security-run-function 'mm-pipe-part))
8985 (gnus-ems-redefine)
8987 (provide 'gnus-art)
8989 (run-hooks 'gnus-art-load-hook)
8991 ;;; gnus-art.el ends here