Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs
[emacs.git] / lisp / gnus / gnus-art.el
blobce0ff2ee8c08ee495205b39a2d4ebc996b95c93b
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2017 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")
53 (autoload 'url-expand-file-name "url-expand")
55 (defgroup gnus-article nil
56 "Article display."
57 :link '(custom-manual "(gnus)Article Buffer")
58 :group 'gnus)
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
63 :group 'gnus-article)
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
73 :group 'gnus-article
74 :group 'gnus-visual)
76 (defgroup gnus-article-signature nil
77 "Article signatures."
78 :link '(custom-manual "(gnus)Article Signature")
79 :group 'gnus-article)
81 (defgroup gnus-article-headers nil
82 "Article headers."
83 :link '(custom-manual "(gnus)Hiding Headers")
84 :group 'gnus-article)
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
89 :group 'gnus-article)
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
94 :group 'gnus-article)
96 (defgroup gnus-article-saving nil
97 "Saving articles."
98 :link '(custom-manual "(gnus)Saving Articles")
99 :group 'gnus-article)
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
117 (mapcar
118 (lambda (header)
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
165 (repeat regexp))
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^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:"
170 "All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(choice
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
177 (or (stringp value)
178 (widget-editable-list-match widget value)))
179 regexp)
180 (const :tag "Use gnus-ignored-headers" nil)
181 regexp)
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
226 :version "22.1"
227 :type 'boolean
228 :group 'gnus-article-hiding)
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236 (regexp)
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
249 This can also be a list of the above values."
250 :type '(choice (const nil)
251 (integer :value 200)
252 (number :value 4.0)
253 function
254 (regexp :value ".*")
255 (repeat (choice (const nil)
256 (integer :value 200)
257 (number :value 4.0)
258 function
259 (regexp :value ".*"))))
260 :group 'gnus-article-signature)
262 (defcustom gnus-hidden-properties
263 ;; We use to have `intangible' here as well, but Emacs's command loop moves
264 ;; point out of invisible text anyway, so `intangible' is clearly not
265 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
266 '(invisible t)
267 "Property list to use for hiding text."
268 :type 'plist
269 :group 'gnus-article-hiding)
271 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
272 ;; frames in a session.
273 (defcustom gnus-article-x-face-command
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
276 "{ echo \
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -")
279 "String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
284 function)
285 :version "21.1"
286 :group 'gnus-picon
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
296 For example,
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
298 :version "21.1"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
303 banner
304 :variable-document
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
307 :parameter-type
308 '(choice :tag "Banner"
309 :value nil
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
312 regexp
313 (const :tag "None" nil))
314 :parameter-document
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
321 directly.")
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 :type '(repeat
334 (cons
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
339 regexp
340 (const :tag "None" nil))))
341 :version "22.1"
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
345 `(let ((format "\
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 ,@body))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
364 "\\'"))
365 pattern)
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
368 (= (nth 2 value) 2)
369 (nth 3 value))
370 value))))
372 (defcustom gnus-emphasis-alist
373 (let ((types
374 '(("\\*" "\\*" bold nil 2)
375 ("_" "_" underline)
376 ("/" "/" italic)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
381 (nconc
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
385 (or (nth 3 spec) 2)
386 (or (nth 4 spec) 3)
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
388 types))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
407 :type
408 '(repeat
409 (menu-choice
410 :format "%[Customizing Style%]\n%v"
411 :indent 2
412 (group :tag "Default"
413 :value ("" 0 0 default)
414 :value-create
415 (lambda (widget)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
418 :args))
419 :value)))
420 (if (not (eq (nth 2 value) 'default))
421 (widget-put
422 widget
423 :value
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
426 regexp
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
429 face)
430 (group :tag "Simple"
431 :value (("_" . "_") nil default)
432 (cons :format "%v"
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
437 face)))
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
443 value)))
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
451 :version "21.1"
452 :group 'gnus-article-emphasis
453 :type 'regexp)
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
486 "Face used for displaying strike-through text (-word-)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-highlight-words
490 '((t (:background "black" :foreground "yellow")))
491 "Face used for displaying highlighted words."
492 :group 'gnus-article-emphasis)
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495 "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
498 The variable can also be function, which should return a complete Date
499 header. The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501 :type '(choice string function)
502 :link '(custom-manual "(gnus)Article Date")
503 :group 'gnus-article-washing)
505 (defcustom gnus-save-all-headers t
506 "If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
509 might have."
510 :group 'gnus-article-saving
511 :type 'boolean)
513 (defcustom gnus-prompt-before-saving 'always
514 "This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files. If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles. If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521 :group 'gnus-article-saving
522 :type '(choice (item always)
523 (item :tag "never" nil)
524 (sexp :tag "once" :format "%t\n" :value t)))
526 (defcustom gnus-article-show-cursor nil
527 "If non-nil, show the cursor in the Article buffer even when not selected."
528 :version "25.1"
529 :group 'gnus-article
530 :type 'bool)
532 (defcustom gnus-saved-headers gnus-visible-headers
533 "Headers to keep if `gnus-save-all-headers' is nil.
534 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
535 If that variable is nil, however, all headers that match this regexp
536 will be kept while the rest will be deleted before saving. This and
537 `gnus-save-all-headers' will be overridden by the `:headers' property
538 that the symbol of the saver function, which is specified by
539 `gnus-default-article-saver', might have."
540 :group 'gnus-article-saving
541 :type 'regexp)
543 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
544 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
545 "A function to save articles in your favorite format.
546 The function will be called by way of the `gnus-summary-save-article'
547 command, and friends such as `gnus-summary-save-article-rmail'.
549 Gnus provides the following functions:
551 * gnus-summary-save-in-rmail (Rmail format)
552 * gnus-summary-save-in-mail (Unix mail format)
553 * gnus-summary-save-in-folder (MH folder)
554 * gnus-summary-save-in-file (article format)
555 * gnus-summary-save-body-in-file (article body)
556 * gnus-summary-save-in-vm (use VM's folder format)
557 * gnus-summary-write-to-file (article format -- overwrite)
558 * gnus-summary-write-body-to-file (article body -- overwrite)
559 * gnus-summary-save-in-pipe (article format)
561 The symbol of each function may have the following properties:
563 * :decode
564 The value non-nil means save decoded articles. This is meaningful
565 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
566 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
567 `gnus-summary-save-in-pipe'.
569 * :function
570 The value specifies an alternative function which appends, not
571 overwrites, articles to a file. This implies that when saving many
572 articles at a time, `gnus-prompt-before-saving' is bound to t and all
573 articles are saved in a single file. This is meaningful only with
574 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
576 * :headers
577 The value specifies the symbol of a variable of which the value
578 specifies headers to be saved. If it is omitted,
579 `gnus-save-all-headers' and `gnus-saved-headers' control what
580 headers should be saved."
581 :group 'gnus-article-saving
582 :type '(radio (function-item gnus-summary-save-in-rmail)
583 (function-item gnus-summary-save-in-mail)
584 (function-item gnus-summary-save-in-folder)
585 (function-item gnus-summary-save-in-file)
586 (function-item gnus-summary-save-body-in-file)
587 (function-item gnus-summary-save-in-vm)
588 (function-item gnus-summary-write-to-file)
589 (function-item gnus-summary-write-body-to-file)
590 (function-item gnus-summary-save-in-pipe)
591 (function)))
593 (defcustom gnus-article-save-coding-system
594 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
595 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
596 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
597 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
598 "Coding system used to save decoded articles to a file.
600 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
601 which can safely encode any characters in text. This is used by the
602 commands including:
604 * gnus-summary-save-article-file
605 * gnus-summary-save-article-body-file
606 * gnus-summary-write-article-file
607 * gnus-summary-write-article-body-file
609 and the functions to which you may set `gnus-default-article-saver':
611 * gnus-summary-save-in-file
612 * gnus-summary-save-body-in-file
613 * gnus-summary-write-to-file
614 * gnus-summary-write-body-to-file
616 Those commands and functions save just text displayed in the article
617 buffer to a file if the value of this variable is non-nil. Note that
618 buttonized MIME parts will be lost in a saved file in that case.
619 Otherwise, raw articles will be saved."
620 :group 'gnus-article-saving
621 :type `(choice
622 :format "%{%t%}:\n %[Value Menu%] %v"
623 (const :tag "Save raw articles" nil)
624 ,@(delq nil
625 (mapcar
626 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
627 '((const :tag "UTF-8" utf-8)
628 (const :tag "iso-2022-7bit" iso-2022-7bit)
629 (const :tag "Emacs internal" emacs-mule)
630 (const :tag "escape-quoted" escape-quoted))))
631 (symbol :tag "Coding system")))
633 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Rmail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
637 :type 'function)
639 (defcustom gnus-mail-save-name 'gnus-plain-save-name
640 "A function generating a file name to save articles in Unix mail format.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
642 :group 'gnus-article-saving
643 :type 'function)
645 (defcustom gnus-folder-save-name 'gnus-folder-save-name
646 "A function generating a file name to save articles in MH folder.
647 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
648 :group 'gnus-article-saving
649 :type 'function)
651 (defcustom gnus-file-save-name 'gnus-numeric-save-name
652 "A function generating a file name to save articles in article format.
653 The function is called with NEWSGROUP, HEADERS, and optional
654 LAST-FILE."
655 :group 'gnus-article-saving
656 :type 'function)
658 (defcustom gnus-split-methods
659 '((gnus-article-archive-name)
660 (gnus-article-nndoc-name))
661 "Variable used to suggest where articles are to be saved.
662 For instance, if you would like to save articles related to Gnus in
663 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
664 you could set this variable to something like:
666 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
667 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
669 This variable is an alist where the key is the match and the
670 value is a list of possible files to save in if the match is
671 non-nil.
673 If the match is a string, it is used as a regexp match on the
674 article. If the match is a symbol, that symbol will be funcalled
675 from the buffer of the article to be saved with the newsgroup as the
676 parameter. If it is a list, it will be evalled in the same buffer.
678 If this form or function returns a string, this string will be used as a
679 possible file name; and if it returns a non-nil list, that list will be
680 used as possible file names."
681 :group 'gnus-article-saving
682 :type '(repeat (choice (list :value (fun) function)
683 (cons :value ("" "") regexp (repeat string))
684 (sexp :value nil))))
686 (defcustom gnus-page-delimiter "^\^L"
687 "Regexp describing what to use as article page delimiters.
688 The default value is \"^\^L\", which is a form linefeed at the
689 beginning of a line."
690 :type 'regexp
691 :group 'gnus-article-various)
693 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
694 "The format specification for the article mode line.
695 See `gnus-summary-mode-line-format' for a closer description.
697 The following additional specs are available:
699 %w The article washing status.
700 %m The number of MIME parts in the article."
701 :version "24.1"
702 :type 'string
703 :group 'gnus-article-various)
705 (defcustom gnus-article-mode-hook nil
706 "A hook for Gnus article mode."
707 :type 'hook
708 :group 'gnus-article-various)
710 (defcustom gnus-article-menu-hook nil
711 "Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
876 (png . nil))
877 "Alist of image types and properties applied to Face and X-Face images.
878 Here are examples:
880 ;; Specify the altitude of Face images in the From header.
881 \(setq gnus-face-properties-alist
882 \\='((pbm . (:face gnus-x-face :ascent 80))
883 (png . (:ascent 80))))
885 ;; Show Face images as pressed buttons.
886 \(setq gnus-face-properties-alist
887 \\='((pbm . (:face gnus-x-face :relief -2))
888 (png . (:relief -2))))
890 See the manual for the valid properties for various image types.
891 Currently, `pbm' is used for X-Face images and `png' is used for Face
892 images in Emacs."
893 :version "23.1" ;; No Gnus
894 :group 'gnus-article-headers
895 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
897 (defcustom gnus-article-decode-hook
898 '(article-decode-charset article-decode-encoded-words
899 article-decode-group-name article-decode-idna-rhs)
900 "Hook run to decode charsets in articles."
901 :group 'gnus-article-headers
902 :type 'hook)
904 (defcustom gnus-display-mime-function 'gnus-display-mime
905 "Function to display MIME articles."
906 :group 'gnus-article-mime
907 :type 'function)
909 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
910 "Function used to decode headers.")
912 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
913 "Function used to decode addresses.")
915 (defvar gnus-article-dumbquotes-map
916 '((?\200 "EUR")
917 (?\202 ",")
918 (?\203 "f")
919 (?\204 ",,")
920 (?\205 "...")
921 (?\213 "<")
922 (?\214 "OE")
923 (?\221 "`")
924 (?\222 "'")
925 (?\223 "``")
926 (?\224 "\"")
927 (?\225 "*")
928 (?\226 "-")
929 (?\227 "--")
930 (?\230 "~")
931 (?\231 "(TM)")
932 (?\233 ">")
933 (?\234 "oe")
934 (?\264 "'"))
935 "Table for MS-to-Latin1 translation.")
937 (defcustom gnus-ignored-mime-types nil
938 "List of MIME types that should be ignored by Gnus."
939 :version "21.1"
940 :group 'gnus-article-mime
941 :type '(repeat regexp))
943 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
944 "List of MIME types that should not be given buttons when rendered inline.
945 See also `gnus-buttonized-mime-types' which may override this variable.
946 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
947 :version "21.1"
948 :group 'gnus-article-mime
949 :type '(repeat regexp))
951 (defcustom gnus-buttonized-mime-types nil
952 "List of MIME types that should be given buttons when rendered inline.
953 If set, this variable overrides `gnus-unbuttonized-mime-types'.
954 To see e.g. security buttons you could set this to
955 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
956 this list to display radio buttons that allow you to choose one of two
957 media types those mails include. See also `mm-discouraged-alternatives'.
958 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
959 :version "22.1"
960 :group 'gnus-article-mime
961 :type '(repeat regexp))
963 (defcustom gnus-inhibit-mime-unbuttonizing nil
964 "If non-nil, all MIME parts get buttons.
965 When nil (the default value), then some MIME parts do not get buttons,
966 as described by the variables `gnus-buttonized-mime-types' and
967 `gnus-unbuttonized-mime-types'."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type 'boolean)
972 (defcustom gnus-body-boundary-delimiter "_"
973 "String used to delimit header and body.
974 This variable is used by `gnus-article-treat-body-boundary' which can
975 be controlled by `gnus-treat-body-boundary'."
976 :version "22.1"
977 :group 'gnus-article-various
978 :type '(choice (item :tag "None" :value nil)
979 string))
981 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
982 "/usr/share/picons")
983 "Defines the location of the faces database.
984 For information on obtaining this database of pretty pictures, please
985 see http://www.cs.indiana.edu/picons/ftp/index.html"
986 :version "22.1"
987 :type '(repeat directory)
988 :link '(url-link :tag "download"
989 "http://www.cs.indiana.edu/picons/ftp/index.html")
990 :link '(custom-manual "(gnus)Picons")
991 :group 'gnus-picon)
993 (defun gnus-picons-installed-p ()
994 "Say whether picons are installed on your machine."
995 (let ((installed nil))
996 (dolist (database gnus-picon-databases)
997 (when (file-exists-p database)
998 (setq installed t)))
999 installed))
1001 (defcustom gnus-article-mime-part-function nil
1002 "Function called with a MIME handle as the argument.
1003 This is meant for people who want to do something automatic based
1004 on parts -- for instance, adding Vcard info to a database."
1005 :group 'gnus-article-mime
1006 :type '(choice (const nil)
1007 function))
1009 (defcustom gnus-mime-multipart-functions nil
1010 "An alist of MIME types to functions to display them."
1011 :version "21.1"
1012 :group 'gnus-article-mime
1013 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1015 (defcustom gnus-article-date-headers '(combined-lapsed)
1016 "A list of Date header formats to display.
1017 Valid formats are `ut' (Universal Time), `local' (local time
1018 zone), `english' (readable English), `lapsed' (elapsed time),
1019 `combined-lapsed' (both the original date and the elapsed time),
1020 `original' (the original date header), `iso8601' (ISO8601
1021 format), and `user-defined' (a user-defined format defined by the
1022 `gnus-article-time-format' variable).
1024 You have as many date headers as you want in the article buffer.
1025 Some of these headers are updated automatically. See
1026 `gnus-article-update-date-headers' for details."
1027 :version "24.1"
1028 :group 'gnus-article-headers
1029 :type '(set
1030 (const :tag "Universal time (UT)" ut)
1031 (const :tag "Local time zone" local)
1032 (const :tag "Readable English" english)
1033 (const :tag "Elapsed time" lapsed)
1034 (const :tag "Original and elapsed time" combined-lapsed)
1035 (const :tag "Original date header" original)
1036 (const :tag "ISO8601 format" iso8601)
1037 (const :tag "User-defined" user-defined)))
1039 (defcustom gnus-article-update-date-headers nil
1040 "A number that says how often to update the date header (in seconds).
1041 If nil, don't update it at all."
1042 :version "24.1"
1043 :group 'gnus-article-headers
1044 :type '(choice
1045 (item :tag "Don't update" :value nil)
1046 integer))
1048 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1049 "Function called with a MIME handle as the argument.
1050 This is meant for people who want to view first matched part.
1051 For `undisplayed-alternative' (default), the first undisplayed
1052 part or alternative part is used. For `undisplayed', the first
1053 undisplayed part is used. For a function, the first part which
1054 the function return t is used. For nil, the first part is
1055 used."
1056 :version "21.1"
1057 :group 'gnus-article-mime
1058 :type '(choice
1059 (item :tag "first" :value nil)
1060 (item :tag "undisplayed" :value undisplayed)
1061 (item :tag "undisplayed or alternative"
1062 :value undisplayed-alternative)
1063 (function)))
1065 (defcustom gnus-mime-action-alist
1066 '(("save to file" . gnus-mime-save-part)
1067 ("save and strip" . gnus-mime-save-part-and-strip)
1068 ("replace with file" . gnus-mime-replace-part)
1069 ("delete part" . gnus-mime-delete-part)
1070 ("display as text" . gnus-mime-inline-part)
1071 ("view the part" . gnus-mime-view-part)
1072 ("pipe to command" . gnus-mime-pipe-part)
1073 ("toggle display" . gnus-article-press-button)
1074 ("toggle display" . gnus-article-view-part-as-charset)
1075 ("view as type" . gnus-mime-view-part-as-type)
1076 ("view internally" . gnus-mime-view-part-internally)
1077 ("view externally" . gnus-mime-view-part-externally))
1078 "An alist of actions that run on the MIME attachment."
1079 :group 'gnus-article-mime
1080 :type '(repeat (cons (string :tag "name")
1081 (function))))
1083 (defcustom gnus-auto-select-part 1
1084 "Advance to next MIME part when deleting or stripping parts.
1086 When 0, point will be placed on the same part as before. When
1087 positive (negative), move point forward (backwards) this many
1088 parts. When nil, redisplay article."
1089 :version "23.1" ;; No Gnus
1090 :group 'gnus-article-mime
1091 :type '(choice (const nil :tag "Redisplay article.")
1092 (const 1 :tag "Next part.")
1093 (const 0 :tag "Current part.")
1094 integer))
1097 ;;; The treatment variables
1100 (defvar gnus-part-display-hook nil
1101 "Hook called on parts that are to receive treatment.")
1103 (defvar gnus-article-treat-custom
1104 '(choice (const :tag "Off" nil)
1105 (const :tag "On" t)
1106 (const :tag "Header" head)
1107 (const :tag "First" first)
1108 (const :tag "Last" last)
1109 (integer :tag "Less")
1110 (repeat :tag "Groups" regexp)
1111 (sexp :tag "Predicate")))
1113 (defvar gnus-article-treat-head-custom
1114 '(choice (const :tag "Off" nil)
1115 (const :tag "Header" head)))
1117 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1118 "text/x-patch" "text/html")
1119 "Part types eligible for treatment.")
1121 (defvar gnus-inhibit-treatment nil
1122 "Whether to inhibit treatment.")
1124 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1125 "Highlight the signature.
1126 Valid values are nil, t, `head', `first', `last', an integer or a
1127 predicate. See Info node `(gnus)Customizing Articles'."
1128 :group 'gnus-article-treat
1129 :link '(custom-manual "(gnus)Customizing Articles")
1130 :type gnus-article-treat-custom)
1131 (put 'gnus-treat-highlight-signature 'highlight t)
1133 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1134 "Add buttons.
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-buttonize 'highlight t)
1142 (defcustom gnus-treat-buttonize-head 'head
1143 "Add buttons to the head.
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-head-custom)
1149 (put 'gnus-treat-buttonize-head 'highlight t)
1151 (defcustom gnus-treat-date 'head
1152 "Display dates according to the `gnus-article-date-headers' variable.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :version "24.1"
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-head-custom)
1160 (defcustom gnus-treat-emphasize 50000
1161 "Emphasize text.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-custom)
1167 (put 'gnus-treat-emphasize 'highlight t)
1169 (defcustom gnus-treat-strip-cr nil
1170 "Remove carriage returns.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :version "22.1"
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1178 (defcustom gnus-treat-unsplit-urls nil
1179 "Remove newlines from within URLs.
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-leading-whitespace nil
1188 "Remove leading whitespace in headers.
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-hide-headers 'head
1197 "Hide headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :group 'gnus-article-treat
1201 :link '(custom-manual "(gnus)Customizing Articles")
1202 :type gnus-article-treat-head-custom)
1204 (defcustom gnus-treat-hide-boring-headers nil
1205 "Hide boring headers.
1206 Valid values are nil, t, `head', `first', `last', an integer or a
1207 predicate. See Info node `(gnus)Customizing Articles'."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-head-custom)
1212 (defcustom gnus-treat-hide-signature nil
1213 "Hide the signature.
1214 Valid values are nil, t, `head', `first', `last', an integer or a
1215 predicate. See Info node `(gnus)Customizing Articles'."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-custom)
1220 (defcustom gnus-treat-fill-article nil
1221 "Fill the article.
1222 Valid values are nil, t, `head', `first', `last', an integer or a
1223 predicate. See Info node `(gnus)Customizing Articles'."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1228 (defcustom gnus-treat-hide-citation nil
1229 "Hide cited text.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'.
1233 See `gnus-article-highlight-citation' for variables used to
1234 control what it hides."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (defcustom gnus-treat-hide-citation-maybe nil
1240 "Hide cited text according to certain conditions.
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'.
1244 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1245 how to control what it hides."
1246 :group 'gnus-article-treat
1247 :link '(custom-manual "(gnus)Customizing Articles")
1248 :type gnus-article-treat-custom)
1250 (defcustom gnus-treat-strip-list-identifiers 'head
1251 "Strip list identifiers from `gnus-list-identifiers'.
1252 Valid values are nil, t, `head', `first', `last', an integer or a
1253 predicate. See Info node `(gnus)Customizing Articles'."
1254 :version "21.1"
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (gnus-define-group-parameter
1260 list-identifier
1261 :variable-document
1262 "Alist of regexps and correspondent identifiers."
1263 :variable-group gnus-article-washing
1264 :parameter-type
1265 '(choice :tag "Identifier"
1266 :value nil
1267 (symbol :tag "Item in `gnus-list-identifiers'" none)
1268 regexp
1269 (const :tag "None" nil))
1270 :parameter-document
1271 "If non-nil, specify how to remove `identifiers' from articles' subject.
1273 Any symbol is used to look up a regular expression to match the
1274 banner in `gnus-list-identifiers'. A string is used as a regular
1275 expression to match the identifier directly.")
1277 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1278 "Gnus 5.10 (Emacs 22.1)")
1280 (defcustom gnus-treat-strip-pem nil
1281 "Strip PEM signatures.
1282 Valid values are nil, t, `head', `first', `last', an integer or a
1283 predicate. See Info node `(gnus)Customizing Articles'."
1284 :group 'gnus-article-treat
1285 :link '(custom-manual "(gnus)Customizing Articles")
1286 :type gnus-article-treat-custom)
1288 (defcustom gnus-treat-strip-banner t
1289 "Strip banners from articles.
1290 The banner to be stripped is specified in the `banner' group parameter.
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-highlight-headers 'head
1298 "Highlight the headers.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-head-custom)
1304 (put 'gnus-treat-highlight-headers 'highlight t)
1306 (defcustom gnus-treat-highlight-citation t
1307 "Highlight cited text.
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-custom)
1313 (put 'gnus-treat-highlight-citation 'highlight t)
1315 (defcustom gnus-treat-strip-headers-in-body t
1316 "Strip the X-No-Archive header line from the beginning of the body.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :version "21.1"
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1324 (defcustom gnus-treat-strip-trailing-blank-lines nil
1325 "Strip trailing blank lines.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'.
1329 When set to t, it also strips trailing blanks in all MIME parts.
1330 Consider to use `last' instead."
1331 :group 'gnus-article-treat
1332 :link '(custom-manual "(gnus)Customizing Articles")
1333 :type gnus-article-treat-custom)
1335 (defcustom gnus-treat-strip-leading-blank-lines nil
1336 "Strip leading blank lines.
1337 Valid values are nil, t, `head', `first', `last', an integer or a
1338 predicate. See Info node `(gnus)Customizing Articles'.
1340 When set to t, it also strips trailing blanks in all MIME parts."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-multiple-blank-lines nil
1346 "Strip multiple blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1353 (defcustom gnus-treat-unfold-headers 'head
1354 "Unfold folded header lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :version "22.1"
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1362 (defcustom gnus-article-unfold-long-headers nil
1363 "If non-nil, allow unfolding headers even if the header is long.
1364 If it is a regexp, only long headers matching this regexp are unfolded.
1365 If it is t, all long headers are unfolded.
1367 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1368 :version "23.1" ;; No Gnus
1369 :group 'gnus-article-treat
1370 :type '(choice (const nil)
1371 (const :tag "all" t)
1372 (regexp)))
1374 (defcustom gnus-treat-fold-headers nil
1375 "Fold headers.
1376 Valid values are nil, t, `head', `first', `last', an integer or a
1377 predicate. See Info node `(gnus)Customizing Articles'."
1378 :version "22.1"
1379 :group 'gnus-article-treat
1380 :link '(custom-manual "(gnus)Customizing Articles")
1381 :type gnus-article-treat-custom)
1383 (defcustom gnus-treat-fold-newsgroups 'head
1384 "Fold the Newsgroups and Followup-To 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-overstrike t
1393 "Treat overstrike highlighting.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1399 (put 'gnus-treat-overstrike 'highlight t)
1401 (defcustom gnus-treat-ansi-sequences t
1402 "Treat ANSI SGR control sequences.
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)
1409 (make-obsolete-variable 'gnus-treat-display-xface
1410 'gnus-treat-display-x-face "Emacs 22.1")
1412 (defcustom gnus-treat-display-x-face
1413 (and (not noninteractive)
1414 (gnus-image-type-available-p 'xbm)
1415 (condition-case nil
1416 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1417 (executable-find "icontopbm"))
1418 ;; shell-command-to-string may signal an error, e.g. if
1419 ;; shell-file-name is not found.
1420 (error nil))
1421 'head)
1422 "Display X-Face headers.
1423 Valid values are nil and `head'.
1424 See Info node `(gnus)Customizing Articles' and Info node
1425 `(gnus)X-Face' for details."
1426 :group 'gnus-article-treat
1427 :version "21.1"
1428 :link '(custom-manual "(gnus)Customizing Articles")
1429 :link '(custom-manual "(gnus)X-Face")
1430 :type gnus-article-treat-head-custom
1431 :set (lambda (symbol value)
1432 (set-default
1433 symbol
1434 (cond ((or (boundp symbol) (get symbol 'saved-value))
1435 value)
1436 ((boundp 'gnus-treat-display-xface)
1437 (message "\
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (default-value 'gnus-treat-display-xface))
1441 ((get 'gnus-treat-display-xface 'saved-value)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1447 value)))))
1448 (put 'gnus-treat-display-x-face 'highlight t)
1450 (defcustom gnus-treat-display-face
1451 (and (not noninteractive)
1452 (gnus-image-type-available-p 'png)
1453 'head)
1454 "Display Face headers.
1455 Valid values are nil, t, `head', `first', `last', an integer or a
1456 predicate. See Info node `(gnus)Customizing Articles' and Info
1457 node `(gnus)Face' for details."
1458 :group 'gnus-article-treat
1459 :version "22.1"
1460 :link '(custom-manual "(gnus)Customizing Articles")
1461 :link '(custom-manual "(gnus)X-Face")
1462 :type gnus-article-treat-head-custom)
1463 (put 'gnus-treat-display-face 'highlight t)
1465 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1466 "Display smileys.
1467 Valid values are nil, t, `head', `first', `last', an integer or a
1468 predicate. See Info node `(gnus)Customizing Articles' and Info
1469 node `(gnus)Smileys' for details."
1470 :group 'gnus-article-treat
1471 :version "21.1"
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :link '(custom-manual "(gnus)Smileys")
1474 :type gnus-article-treat-custom)
1475 (put 'gnus-treat-display-smileys 'highlight t)
1477 (defcustom gnus-treat-from-picon
1478 (if (and (gnus-image-type-available-p 'xpm)
1479 (gnus-picons-installed-p))
1480 'head nil)
1481 "Display picons in the From header.
1482 Valid values are nil, t, `head', `first', `last', an integer or a
1483 predicate. See Info node `(gnus)Customizing Articles' and Info
1484 node `(gnus)Picons' for details."
1485 :version "22.1"
1486 :group 'gnus-article-treat
1487 :group 'gnus-picon
1488 :link '(custom-manual "(gnus)Customizing Articles")
1489 :link '(custom-manual "(gnus)Picons")
1490 :type gnus-article-treat-head-custom)
1491 (put 'gnus-treat-from-picon 'highlight t)
1493 (defcustom gnus-treat-mail-picon
1494 (if (and (gnus-image-type-available-p 'xpm)
1495 (gnus-picons-installed-p))
1496 'head nil)
1497 "Display picons in To and Cc headers.
1498 Valid values are nil, t, `head', `first', `last', an integer or a
1499 predicate. See Info node `(gnus)Customizing Articles' and Info
1500 node `(gnus)Picons' for details."
1501 :version "22.1"
1502 :group 'gnus-article-treat
1503 :group 'gnus-picon
1504 :link '(custom-manual "(gnus)Customizing Articles")
1505 :link '(custom-manual "(gnus)Picons")
1506 :type gnus-article-treat-head-custom)
1507 (put 'gnus-treat-mail-picon 'highlight t)
1509 (defcustom gnus-treat-newsgroups-picon
1510 (if (and (gnus-image-type-available-p 'xpm)
1511 (gnus-picons-installed-p))
1512 'head nil)
1513 "Display picons in the Newsgroups and Followup-To headers.
1514 Valid values are nil, t, `head', `first', `last', an integer or a
1515 predicate. See Info node `(gnus)Customizing Articles' and Info
1516 node `(gnus)Picons' for details."
1517 :version "22.1"
1518 :group 'gnus-article-treat
1519 :group 'gnus-picon
1520 :link '(custom-manual "(gnus)Customizing Articles")
1521 :link '(custom-manual "(gnus)Picons")
1522 :type gnus-article-treat-head-custom)
1523 (put 'gnus-treat-newsgroups-picon 'highlight t)
1525 (defcustom gnus-treat-from-gravatar nil
1526 "Display gravatars in the From header.
1527 Valid values are nil, t, `head', `first', `last', an integer or a
1528 predicate. See Info node `(gnus)Customizing Articles' and Info
1529 node `(gnus)Gravatars' for details."
1530 :version "24.1"
1531 :group 'gnus-article-treat
1532 :group 'gnus-gravatar
1533 :link '(custom-manual "(gnus)Customizing Articles")
1534 :link '(custom-manual "(gnus)Gravatars")
1535 :type gnus-article-treat-head-custom)
1536 (put 'gnus-treat-from-gravatar 'highlight t)
1538 (defcustom gnus-treat-mail-gravatar nil
1539 "Display gravatars in To and Cc headers.
1540 Valid values are nil, t, `head', `first', `last', an integer or a
1541 predicate. See Info node `(gnus)Customizing Articles' and Info
1542 node `(gnus)Gravatars' for details."
1543 :version "24.1"
1544 :group 'gnus-article-treat
1545 :group 'gnus-gravatar
1546 :link '(custom-manual "(gnus)Customizing Articles")
1547 :link '(custom-manual "(gnus)Gravatars")
1548 :type gnus-article-treat-head-custom)
1549 (put 'gnus-treat-mail-gravatar 'highlight t)
1551 (defcustom gnus-treat-body-boundary
1552 (if (or gnus-treat-newsgroups-picon
1553 gnus-treat-mail-picon
1554 gnus-treat-from-picon
1555 gnus-treat-from-gravatar
1556 gnus-treat-mail-gravatar)
1557 ;; If there's much decoration, the user might prefer a boundary.
1558 'head
1559 nil)
1560 "Draw a boundary at the end of the headers.
1561 Valid values are nil and `head'.
1562 See Info node `(gnus)Customizing Articles' for details."
1563 :version "22.1"
1564 :group 'gnus-article-treat
1565 :link '(custom-manual "(gnus)Customizing Articles")
1566 :type gnus-article-treat-head-custom)
1568 (defcustom gnus-treat-capitalize-sentences nil
1569 "Capitalize sentence-starting words.
1570 Valid values are nil, t, `head', `first', `last', an integer or a
1571 predicate. See Info node `(gnus)Customizing Articles'."
1572 :version "21.1"
1573 :group 'gnus-article-treat
1574 :link '(custom-manual "(gnus)Customizing Articles")
1575 :type gnus-article-treat-custom)
1577 (defcustom gnus-treat-wash-html nil
1578 "Format as HTML.
1579 Valid values are nil, t, `head', `first', `last', an integer or a
1580 predicate. See Info node `(gnus)Customizing Articles'."
1581 :version "22.1"
1582 :group 'gnus-article-treat
1583 :link '(custom-manual "(gnus)Customizing Articles")
1584 :type gnus-article-treat-custom)
1586 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1587 "Fill long lines.
1588 Valid values are nil, t, `head', `first', `last', an integer or a
1589 predicate. See Info node `(gnus)Customizing Articles'."
1590 :version "24.1"
1591 :group 'gnus-article-treat
1592 :link '(custom-manual "(gnus)Customizing Articles")
1593 :type gnus-article-treat-custom)
1595 (defcustom gnus-treat-x-pgp-sig nil
1596 "Verify X-PGP-Sig.
1597 To automatically treat X-PGP-Sig, set it to head.
1598 Valid values are nil, t, `head', `first', `last', an integer or a
1599 predicate. See Info node `(gnus)Customizing Articles'."
1600 :version "22.1"
1601 :group 'gnus-article-treat
1602 :group 'mime-security
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1606 (defvar gnus-article-encrypt-protocol-alist
1607 '(("PGP" . mml2015-self-encrypt)))
1609 ;; Set to nil if more than one protocol added to
1610 ;; gnus-article-encrypt-protocol-alist.
1611 (defcustom gnus-article-encrypt-protocol "PGP"
1612 "The protocol used for encrypt articles.
1613 It is a string, such as \"PGP\". If nil, ask user."
1614 :version "22.1"
1615 :type 'string
1616 :group 'mime-security)
1618 (defcustom gnus-use-idna t
1619 "Whether IDNA decoding of headers is used when viewing messages."
1620 :version "26.1"
1621 :group 'gnus-article-headers
1622 :type 'boolean)
1624 (defcustom gnus-article-over-scroll nil
1625 "If non-nil, allow scrolling the article buffer even when there no more text."
1626 :version "22.1"
1627 :group 'gnus-article
1628 :type 'boolean)
1630 (defcustom gnus-inhibit-images nil
1631 "Non-nil means inhibit displaying of images inline in the article body."
1632 :version "24.1"
1633 :group 'gnus-article
1634 :type 'boolean)
1636 (defcustom gnus-blocked-images 'gnus-block-private-groups
1637 "Images that have URLs matching this regexp will be blocked.
1638 This can also be a function to be evaluated. If so, it will be
1639 called with the group name as the parameter, and should return a
1640 regexp."
1641 :version "24.1"
1642 :group 'gnus-art
1643 :type '(choice (const :tag "Allow all" nil)
1644 (regexp :tag "Regular expression")
1645 (function :tag "Use a function")))
1647 ;;; Internal variables
1649 (defvar gnus-english-month-names
1650 '("January" "February" "March" "April" "May" "June" "July" "August"
1651 "September" "October" "November" "December"))
1653 (defvar article-goto-body-goes-to-point-min-p nil)
1654 (defvar gnus-article-wash-types nil)
1655 (defvar gnus-article-emphasis-alist nil)
1656 (defvar gnus-article-image-alist nil)
1658 (defvar gnus-article-mime-handle-alist-1 nil)
1659 (defvar gnus-treatment-function-alist
1660 '((gnus-treat-strip-cr gnus-article-remove-cr)
1661 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1662 (gnus-treat-strip-banner gnus-article-strip-banner)
1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1665 (gnus-treat-buttonize gnus-article-add-buttons)
1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1667 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1668 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1669 (gnus-treat-display-x-face gnus-article-display-x-face)
1670 (gnus-treat-display-face gnus-article-display-face)
1671 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1672 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1673 (gnus-treat-hide-signature gnus-article-hide-signature)
1674 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1675 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1676 (gnus-treat-from-picon gnus-treat-from-picon)
1677 (gnus-treat-mail-picon gnus-treat-mail-picon)
1678 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1679 (gnus-treat-strip-pem gnus-article-hide-pem)
1680 (gnus-treat-date gnus-article-treat-date)
1681 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1682 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1683 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1684 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1685 (gnus-treat-strip-trailing-blank-lines
1686 gnus-article-remove-trailing-blank-lines)
1687 (gnus-treat-strip-leading-blank-lines
1688 gnus-article-strip-leading-blank-lines)
1689 (gnus-treat-strip-multiple-blank-lines
1690 gnus-article-strip-multiple-blank-lines)
1691 (gnus-treat-overstrike gnus-article-treat-overstrike)
1692 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1693 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1694 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1695 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1696 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1697 (gnus-treat-display-smileys gnus-treat-smiley)
1698 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1699 (gnus-treat-wash-html gnus-article-wash-html)
1700 (gnus-treat-emphasize gnus-article-emphasize)
1701 (gnus-treat-hide-citation gnus-article-hide-citation)
1702 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1703 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1704 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1706 (defvar gnus-article-mime-handle-alist nil)
1707 (defvar article-lapsed-timer nil)
1708 (defvar gnus-article-current-summary nil)
1710 (defvar gnus-article-mode-syntax-table
1711 (let ((table (copy-syntax-table text-mode-syntax-table)))
1712 ;; This causes the citation match run O(2^n).
1713 ;; (modify-syntax-entry ?- "w" table)
1714 (modify-syntax-entry ?> ")<" table)
1715 (modify-syntax-entry ?< "(>" table)
1716 ;; make M-. in article buffers work for `foo' strings,
1717 ;; and still allow C-s C-w to yank ' to the search ring
1718 (modify-syntax-entry ?' "'" table)
1719 (modify-syntax-entry ?` "'" table)
1720 table)
1721 "Syntax table used in article mode buffers.
1722 Initialized from `text-mode-syntax-table'.")
1724 (defvar gnus-save-article-buffer nil)
1726 (defvar gnus-number-of-articles-to-be-saved nil)
1728 (defvar gnus-inhibit-hiding nil)
1730 (defvar gnus-article-edit-mode nil)
1732 ;;; Macros for dealing with the article buffer.
1734 (defmacro gnus-with-article-headers (&rest forms)
1735 `(with-current-buffer gnus-article-buffer
1736 (save-restriction
1737 (let ((inhibit-read-only t)
1738 (inhibit-point-motion-hooks t)
1739 (case-fold-search t))
1740 (article-narrow-to-head)
1741 ,@forms))))
1743 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1744 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1746 (defmacro gnus-with-article-buffer (&rest forms)
1747 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1748 (with-current-buffer gnus-article-buffer
1749 (let ((inhibit-read-only t))
1750 ,@forms))))
1752 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1753 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1755 (defun gnus-article-goto-header (header)
1756 "Go to HEADER, which is a regular expression."
1757 (re-search-forward (concat "^\\(" header "\\):") nil t))
1759 (defsubst gnus-article-hide-text (b e props)
1760 "Set text PROPS on the B to E region."
1761 (gnus-add-text-properties-when 'article-type nil b e props))
1763 (defsubst gnus-article-unhide-text (b e)
1764 "Remove hidden text properties from region between B and E."
1765 (remove-text-properties b e gnus-hidden-properties))
1767 (defun gnus-article-hide-text-type (b e type)
1768 "Hide text of TYPE between B and E."
1769 (gnus-add-wash-type type)
1770 (gnus-article-hide-text
1771 b e (cons 'article-type (cons type gnus-hidden-properties))))
1773 (defun gnus-article-unhide-text-type (b e type)
1774 "Unhide text of TYPE between B and E."
1775 (gnus-delete-wash-type type)
1776 (remove-text-properties
1777 b e (cons 'article-type (cons type gnus-hidden-properties))))
1779 (defun gnus-article-delete-text-of-type (type)
1780 "Delete text of TYPE in the current buffer."
1781 (save-excursion
1782 (let ((b (point-min)))
1783 (if (eq type 'multipart)
1784 ;; Remove MIME buttons associated with multipart/alternative parts.
1785 (progn
1786 (goto-char b)
1787 (while (if (get-text-property (point) 'gnus-part)
1788 (setq b (point))
1789 (when (setq b (next-single-property-change (point)
1790 'gnus-part))
1791 (goto-char b)
1793 (end-of-line)
1794 (skip-chars-forward "\n")
1795 (when (eq (get-text-property b 'article-type) 'multipart)
1796 (delete-region b (point)))))
1797 (while (setq b (text-property-any b (point-max) 'article-type type))
1798 (delete-region
1799 b (or (text-property-not-all b (point-max) 'article-type type)
1800 (point-max))))))))
1802 (defun gnus-article-delete-invisible-text ()
1803 "Delete all invisible text in the current buffer."
1804 (save-excursion
1805 (let ((b (point-min)))
1806 (while (setq b (text-property-any b (point-max) 'invisible t))
1807 (delete-region
1808 b (or (text-property-not-all b (point-max) 'invisible t)
1809 (point-max)))))))
1811 (defsubst gnus-article-header-rank ()
1812 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1813 (let ((list gnus-sorted-header-list)
1814 (i 1))
1815 (while list
1816 (if (looking-at (car list))
1817 (setq list nil)
1818 (setq list (cdr list))
1819 (incf i)))
1822 (defun article-hide-headers (&optional _arg _delete)
1823 "Hide unwanted headers and possibly sort them as well."
1824 (interactive)
1825 ;; This function might be inhibited.
1826 (unless gnus-inhibit-hiding
1827 (let ((inhibit-read-only t)
1828 (case-fold-search t)
1829 (max (1+ (length gnus-sorted-header-list)))
1830 (inhibit-point-motion-hooks t)
1831 (cur (current-buffer))
1832 ignored visible beg)
1833 (save-excursion
1834 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1835 ;; group parameters, so we should go to the summary buffer.
1836 (when (prog1
1837 (condition-case nil
1838 (progn (set-buffer gnus-summary-buffer) t)
1839 (error nil))
1840 (setq ignored (when (not gnus-visible-headers)
1841 (cond ((stringp gnus-ignored-headers)
1842 gnus-ignored-headers)
1843 ((listp gnus-ignored-headers)
1844 (mapconcat 'identity
1845 gnus-ignored-headers
1846 "\\|"))))
1847 visible (cond ((stringp gnus-visible-headers)
1848 gnus-visible-headers)
1849 ((and gnus-visible-headers
1850 (listp gnus-visible-headers))
1851 (mapconcat 'identity
1852 gnus-visible-headers
1853 "\\|")))))
1854 (set-buffer cur))
1855 (save-restriction
1856 ;; First we narrow to just the headers.
1857 (article-narrow-to-head)
1858 ;; Hide any "From " lines at the beginning of (mail) articles.
1859 (while (looking-at "From ")
1860 (forward-line 1))
1861 (unless (bobp)
1862 (delete-region (point-min) (point)))
1863 ;; Then treat the rest of the header lines.
1864 ;; Then we use the two regular expressions
1865 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1866 ;; select which header lines is to remain visible in the
1867 ;; article buffer.
1868 (while (re-search-forward "^[^ \t:]*:" nil t)
1869 (beginning-of-line)
1870 ;; Mark the rank of the header.
1871 (put-text-property
1872 (point) (1+ (point)) 'message-rank
1873 (if (or (and visible (looking-at visible))
1874 (and ignored
1875 (not (looking-at ignored))))
1876 (gnus-article-header-rank)
1877 (+ 2 max)))
1878 (forward-line 1))
1879 (message-sort-headers-1)
1880 (when (setq beg (text-property-any
1881 (point-min) (point-max) 'message-rank (+ 2 max)))
1882 ;; We delete the unwanted headers.
1883 (gnus-add-wash-type 'headers)
1884 (add-text-properties (point-min) (+ 5 (point-min))
1885 '(article-type headers dummy-invisible t))
1886 (delete-region beg (point-max))))))))
1888 (defun article-hide-boring-headers (&optional arg)
1889 "Toggle hiding of headers that aren't very interesting.
1890 If given a negative prefix, always show; if given a positive prefix,
1891 always hide."
1892 (interactive (gnus-article-hidden-arg))
1893 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1894 (not gnus-show-all-headers))
1895 (save-excursion
1896 (save-restriction
1897 (let ((inhibit-read-only t)
1898 (inhibit-point-motion-hooks t))
1899 (article-narrow-to-head)
1900 (dolist (elem gnus-boring-article-headers)
1901 (goto-char (point-min))
1902 (cond
1903 ;; Hide empty headers.
1904 ((eq elem 'empty)
1905 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1906 (forward-line -1)
1907 (gnus-article-hide-text-type
1908 (point-at-bol)
1909 (progn
1910 (end-of-line)
1911 (if (re-search-forward "^[^ \t]" nil t)
1912 (match-beginning 0)
1913 (point-max)))
1914 'boring-headers)))
1915 ;; Hide boring Newsgroups header.
1916 ((eq elem 'newsgroups)
1917 (when (gnus-string-equal
1918 (gnus-fetch-field "newsgroups")
1919 (gnus-group-real-name
1920 (if (boundp 'gnus-newsgroup-name)
1921 gnus-newsgroup-name
1922 "")))
1923 (gnus-article-hide-header "newsgroups")))
1924 ((eq elem 'to-address)
1925 (let ((to (message-fetch-field "to"))
1926 (to-address
1927 (gnus-parameter-to-address
1928 (if (boundp 'gnus-newsgroup-name)
1929 gnus-newsgroup-name ""))))
1930 (when (and to to-address
1931 (ignore-errors
1932 (gnus-string-equal
1933 ;; only one address in To
1934 (nth 1 (mail-extract-address-components to))
1935 to-address)))
1936 (gnus-article-hide-header "to"))))
1937 ((eq elem 'to-list)
1938 (let ((to (message-fetch-field "to"))
1939 (to-list
1940 (gnus-parameter-to-list
1941 (if (boundp 'gnus-newsgroup-name)
1942 gnus-newsgroup-name ""))))
1943 (when (and to to-list
1944 (ignore-errors
1945 (gnus-string-equal
1946 ;; only one address in To
1947 (nth 1 (mail-extract-address-components to))
1948 to-list)))
1949 (gnus-article-hide-header "to"))))
1950 ((eq elem 'cc-list)
1951 (let ((cc (message-fetch-field "cc"))
1952 (to-list
1953 (gnus-parameter-to-list
1954 (if (boundp 'gnus-newsgroup-name)
1955 gnus-newsgroup-name ""))))
1956 (when (and cc to-list
1957 (ignore-errors
1958 (gnus-string-equal
1959 ;; only one address in CC
1960 (nth 1 (mail-extract-address-components cc))
1961 to-list)))
1962 (gnus-article-hide-header "cc"))))
1963 ((eq elem 'followup-to)
1964 (when (gnus-string-equal
1965 (message-fetch-field "followup-to")
1966 (message-fetch-field "newsgroups"))
1967 (gnus-article-hide-header "followup-to")))
1968 ((eq elem 'reply-to)
1969 (if (gnus-group-find-parameter
1970 gnus-newsgroup-name 'broken-reply-to)
1971 (gnus-article-hide-header "reply-to")
1972 (let ((from (message-fetch-field "from"))
1973 (reply-to (message-fetch-field "reply-to")))
1974 (when
1975 (and
1976 from reply-to
1977 (ignore-errors
1978 (equal
1979 (sort (mapcar
1980 (lambda (x) (downcase (cadr x)))
1981 (mail-extract-address-components from t))
1982 'string<)
1983 (sort (mapcar
1984 (lambda (x) (downcase (cadr x)))
1985 (mail-extract-address-components reply-to t))
1986 'string<))))
1987 (gnus-article-hide-header "reply-to")))))
1988 ((eq elem 'date)
1989 (let ((date (with-current-buffer gnus-original-article-buffer
1990 ;; If date in `gnus-article-buffer' is localized
1991 ;; (`gnus-treat-date-user-defined'),
1992 ;; `days-between' might fail.
1993 (message-fetch-field "date"))))
1994 (when (and date
1995 (< (days-between (current-time-string) date)
1997 (gnus-article-hide-header "date"))))
1998 ((eq elem 'long-to)
1999 (let ((to (message-fetch-field "to"))
2000 (cc (message-fetch-field "cc")))
2001 (when (> (length to) 1024)
2002 (gnus-article-hide-header "to"))
2003 (when (> (length cc) 1024)
2004 (gnus-article-hide-header "cc"))))
2005 ((eq elem 'many-to)
2006 (let ((to-count 0)
2007 (cc-count 0))
2008 (goto-char (point-min))
2009 (while (re-search-forward "^to:" nil t)
2010 (setq to-count (1+ to-count)))
2011 (when (> to-count 1)
2012 (while (> to-count 0)
2013 (goto-char (point-min))
2014 (save-restriction
2015 (re-search-forward "^to:" nil nil to-count)
2016 (forward-line -1)
2017 (narrow-to-region (point) (point-max))
2018 (gnus-article-hide-header "to"))
2019 (setq to-count (1- to-count))))
2020 (goto-char (point-min))
2021 (while (re-search-forward "^cc:" nil t)
2022 (setq cc-count (1+ cc-count)))
2023 (when (> cc-count 1)
2024 (while (> cc-count 0)
2025 (goto-char (point-min))
2026 (save-restriction
2027 (re-search-forward "^cc:" nil nil cc-count)
2028 (forward-line -1)
2029 (narrow-to-region (point) (point-max))
2030 (gnus-article-hide-header "cc"))
2031 (setq cc-count (1- cc-count)))))))))))))
2033 (defun gnus-article-hide-header (header)
2034 (save-excursion
2035 (goto-char (point-min))
2036 (when (re-search-forward (concat "^" header ":") nil t)
2037 (gnus-article-hide-text-type
2038 (point-at-bol)
2039 (progn
2040 (end-of-line)
2041 (if (re-search-forward "^[^ \t]" nil t)
2042 (match-beginning 0)
2043 (point-max)))
2044 'boring-headers))))
2046 (defvar gnus-article-normalized-header-length 40
2047 "Length of normalized headers.")
2049 (defun article-normalize-headers ()
2050 "Make all header lines 40 characters long."
2051 (interactive)
2052 (let ((inhibit-read-only t)
2053 column)
2054 (save-excursion
2055 (save-restriction
2056 (article-narrow-to-head)
2057 (while (not (eobp))
2058 (cond
2059 ((< (setq column (- (point-at-eol) (point)))
2060 gnus-article-normalized-header-length)
2061 (end-of-line)
2062 (insert (make-string
2063 (- gnus-article-normalized-header-length column)
2064 ? )))
2065 ((> column gnus-article-normalized-header-length)
2066 (put-text-property
2067 (progn
2068 (forward-char gnus-article-normalized-header-length)
2069 (point))
2070 (point-at-eol)
2071 'invisible t))
2073 ;; Do nothing.
2075 (forward-line 1))))))
2077 (defun article-treat-dumbquotes ()
2078 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2079 Note that this function guesses whether a character is a sm*rtq**t* or
2080 not, so it should only be used interactively.
2082 Sm*rtq**t*s are M****s***'s unilateral extension to the
2083 iso-8859-1 character map in an attempt to provide more quoting
2084 characters. If you see something like \\222 or \\264 where
2085 you're expecting some kind of apostrophe or quotation mark, then
2086 try this wash."
2087 (interactive)
2088 (article-translate-strings gnus-article-dumbquotes-map))
2090 (defvar org-entities)
2092 (defun article-treat-non-ascii ()
2093 "Translate many Unicode characters into their ASCII equivalents."
2094 (interactive)
2095 (require 'org-entities)
2096 (let ((table (make-char-table nil)))
2097 (dolist (elem org-entities)
2098 (when (and (listp elem)
2099 (= (length (nth 6 elem)) 1))
2100 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))
2101 (save-excursion
2102 (when (article-goto-body)
2103 (let ((inhibit-read-only t)
2104 replace props)
2105 (while (not (eobp))
2106 (if (not (setq replace (aref table (following-char))))
2107 (forward-char 1)
2108 (if (prog1
2109 (setq props (text-properties-at (point)))
2110 (delete-char 1))
2111 (add-text-properties (point) (progn (insert replace) (point))
2112 props)
2113 (insert replace)))))))))
2115 (defun article-translate-strings (map)
2116 "Translate all string in the body of the article according to MAP.
2117 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t))
2121 (dolist (elem map)
2122 (let ((from (car elem))
2123 (to (cadr elem)))
2124 (save-excursion
2125 (if (stringp from)
2126 (while (search-forward from nil t)
2127 (replace-match to))
2128 (while (not (eobp))
2129 (if (eq (following-char) from)
2130 (progn
2131 (delete-char 1)
2132 (insert to))
2133 (forward-char 1)))))))))))
2135 (defun article-treat-overstrike ()
2136 "Translate overstrikes into bold text."
2137 (interactive)
2138 (save-excursion
2139 (when (article-goto-body)
2140 (let ((inhibit-read-only t))
2141 (while (search-forward "\b" nil t)
2142 (let ((next (char-after))
2143 (previous (char-after (- (point) 2))))
2144 ;; We do the boldification/underlining by hiding the
2145 ;; overstrikes and putting the proper text property
2146 ;; on the letters.
2147 (cond
2148 ((eq next previous)
2149 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2150 (put-text-property (point) (1+ (point)) 'face 'bold))
2151 ((eq next ?_)
2152 (gnus-article-hide-text-type
2153 (1- (point)) (1+ (point)) 'overstrike)
2154 (put-text-property
2155 (- (point) 2) (1- (point)) 'face 'underline))
2156 ((eq previous ?_)
2157 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2158 (put-text-property
2159 (point) (1+ (point)) 'face 'underline)))))))))
2161 (defun article-treat-ansi-sequences ()
2162 "Translate ANSI SGR control sequences into overlays or extents."
2163 (interactive)
2164 (save-excursion
2165 (when (article-goto-body)
2166 (let ((inhibit-read-only t))
2167 (ansi-color-apply-on-region (point) (point-max))))))
2169 (defun gnus-article-treat-unfold-headers ()
2170 "Unfold folded message headers.
2171 Only the headers that fit into the current window width will be
2172 unfolded."
2173 (interactive)
2174 (gnus-with-article-headers
2175 (let (length)
2176 (while (not (eobp))
2177 (save-restriction
2178 (mail-header-narrow-to-field)
2179 (let* ((header (buffer-string))
2180 (unfoldable
2181 (or (equal gnus-article-unfold-long-headers t)
2182 (and (stringp gnus-article-unfold-long-headers)
2183 (string-match gnus-article-unfold-long-headers
2184 header)))))
2185 (with-temp-buffer
2186 (insert header)
2187 (goto-char (point-min))
2188 (while (re-search-forward "\n[\t ]" nil t)
2189 (replace-match " " t t)))
2190 (setq length (- (point-max) (point-min) 1))
2191 (when (or unfoldable
2192 (< length (window-width)))
2193 (while (re-search-forward "\n[\t ]" nil t)
2194 (replace-match " " t t))))
2195 (goto-char (point-max)))))))
2197 (defun gnus-article-treat-fold-headers ()
2198 "Fold message headers."
2199 (interactive)
2200 (gnus-with-article-headers
2201 (while (not (eobp))
2202 (save-restriction
2203 (mail-header-narrow-to-field)
2204 (mail-header-fold-field)
2205 (goto-char (point-max))))))
2207 (defun gnus-treat-smiley ()
2208 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2209 (interactive)
2210 (gnus-with-article-buffer
2211 (if (memq 'smiley gnus-article-wash-types)
2212 (gnus-delete-images 'smiley)
2213 (article-goto-body)
2214 (let ((images (smiley-region (point) (point-max))))
2215 (when images
2216 (gnus-add-wash-type 'smiley)
2217 (dolist (image images)
2218 (gnus-add-image 'smiley image)))))))
2220 (defun gnus-article-remove-images ()
2221 "Remove all images from the article buffer."
2222 (interactive)
2223 (gnus-with-article-buffer
2224 (save-restriction
2225 (widen)
2226 (dolist (elem gnus-article-image-alist)
2227 (gnus-delete-images (car elem))))))
2229 (autoload 'w3m-toggle-inline-images "w3m")
2231 (defun gnus-article-show-images ()
2232 "Show any images that are in the HTML-rendered article buffer.
2233 This only works if the article in question is HTML."
2234 (interactive)
2235 (gnus-with-article-buffer
2236 (save-restriction
2237 (widen)
2238 (if (eq mm-text-html-renderer 'w3m)
2239 (w3m-toggle-inline-images)
2240 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2241 'image-displayer))
2242 (destructuring-bind (start end function) region
2243 (funcall function (get-text-property start 'image-url)
2244 start end)))))))
2246 (defun gnus-article-treat-fold-newsgroups ()
2247 "Unfold folded message headers.
2248 Only the headers that fit into the current window width will be
2249 unfolded."
2250 (interactive)
2251 (gnus-with-article-headers
2252 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2253 (save-restriction
2254 (mail-header-narrow-to-field)
2255 (while (re-search-forward ", *" nil t)
2256 (replace-match ", " t t))
2257 (mail-header-fold-field)
2258 (goto-char (point-max))))))
2260 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2261 "Value of `truncate-lines' in Gnus Article buffer.
2262 Valid values are nil, t, `head', `first', `last', an integer or a
2263 predicate. See Info node `(gnus)Customizing Articles'."
2264 :version "23.1" ;; No Gnus
2265 :group 'gnus-article
2266 ;; :link '(custom-manual "(gnus)Customizing Articles")
2267 :type 'boolean)
2269 (defun gnus-article-toggle-truncate-lines (&optional arg)
2270 "Toggle whether to fold or truncate long lines in article the buffer.
2271 If ARG is non-nil and not a number, toggle
2272 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2273 long lines if and only if arg is positive."
2274 (interactive "P")
2275 (cond
2276 ((and (numberp arg) (> arg 0))
2277 (setq gnus-article-truncate-lines t))
2278 ((numberp arg)
2279 (setq gnus-article-truncate-lines nil))
2280 (arg
2281 (setq gnus-article-truncate-lines
2282 (not gnus-article-truncate-lines))))
2283 (gnus-with-article-buffer
2284 (cond
2285 ((and (numberp arg) (> arg 0))
2286 (setq truncate-lines nil))
2287 ((numberp arg)
2288 (setq truncate-lines t)))
2289 (toggle-truncate-lines)))
2291 (defun gnus-article-treat-body-boundary ()
2292 "Place a boundary line at the end of the headers."
2293 (interactive)
2294 (when (and gnus-body-boundary-delimiter
2295 (> (length gnus-body-boundary-delimiter) 0))
2296 (gnus-with-article-headers
2297 (goto-char (point-max))
2298 (let ((start (point)))
2299 (insert "X-Boundary: ")
2300 (add-text-properties start (point) gnus-hidden-properties)
2301 (insert (let (str (max (window-width)))
2302 (while (>= max (length str))
2303 (setq str (concat str gnus-body-boundary-delimiter)))
2304 (substring str 0 max))
2305 "\n")
2306 (put-text-property start (point) 'gnus-decoration 'header)))))
2308 (defun article-fill-long-lines ()
2309 "Fill lines that are wider than the window width."
2310 (interactive)
2311 (save-excursion
2312 (let ((inhibit-read-only t)
2313 (width (window-width (get-buffer-window (current-buffer)))))
2314 (save-restriction
2315 (article-goto-body)
2316 (let ((adaptive-fill-mode nil)) ;Why? -sm
2317 (while (not (eobp))
2318 (end-of-line)
2319 (when (>= (current-column) (min fill-column width))
2320 (narrow-to-region (min (1+ (point)) (point-max))
2321 (point-at-bol))
2322 (let ((goback (point-marker)))
2323 (fill-paragraph nil)
2324 (goto-char (marker-position goback)))
2325 (widen))
2326 (forward-line 1)))))))
2328 (defun article-capitalize-sentences ()
2329 "Capitalize the first word in each sentence."
2330 (interactive)
2331 (save-excursion
2332 (let ((inhibit-read-only t)
2333 (paragraph-start "^[\n\^L]"))
2334 (article-goto-body)
2335 (while (not (eobp))
2336 (capitalize-word 1)
2337 (forward-sentence)))))
2339 (defun article-remove-cr ()
2340 "Remove trailing CRs and then translate remaining CRs into LFs."
2341 (interactive)
2342 (save-excursion
2343 (let ((inhibit-read-only t))
2344 (goto-char (point-min))
2345 (while (re-search-forward "\r+$" nil t)
2346 (replace-match "" t t))
2347 (goto-char (point-min))
2348 (while (search-forward "\r" nil t)
2349 (replace-match "\n" t t)))))
2351 (defun article-remove-trailing-blank-lines ()
2352 "Remove all trailing blank lines from the article."
2353 (interactive)
2354 (save-excursion
2355 (let ((inhibit-read-only t))
2356 (goto-char (point-max))
2357 (delete-region
2358 (point)
2359 (progn
2360 (while (and (not (bobp))
2361 (looking-at "^[ \t]*$")
2362 (not (gnus-annotation-in-region-p
2363 (point) (point-at-eol))))
2364 (forward-line -1))
2365 (forward-line 1)
2366 (point))))))
2368 (defvar gnus-face-properties-alist)
2370 (defun article-display-face (&optional force)
2371 "Display any Face headers in the header."
2372 (interactive (list 'force))
2373 (let ((wash-face-p buffer-read-only))
2374 (gnus-with-article-headers
2375 ;; When displaying parts, this function can be called several times on
2376 ;; the same article, without any intended toggle semantic (as typing `W
2377 ;; D d' would have). So face deletion must occur only when we come from
2378 ;; an interactive command, that is when the *Article* buffer is
2379 ;; read-only.
2380 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2381 (gnus-delete-images 'face)
2382 (let ((from (message-fetch-field "from"))
2383 faces)
2384 (save-current-buffer
2385 (when (and wash-face-p
2386 (gnus-buffer-live-p gnus-original-article-buffer)
2387 (not (re-search-forward "^Face:[\t ]*" nil t)))
2388 (set-buffer gnus-original-article-buffer))
2389 (save-restriction
2390 (mail-narrow-to-head)
2391 (when (or force
2392 ;; Check whether this face is censored.
2393 (not (and gnus-article-x-face-too-ugly
2394 (or from
2395 (setq from (message-fetch-field "from")))
2396 (string-match gnus-article-x-face-too-ugly
2397 from))))
2398 (while (gnus-article-goto-header "Face")
2399 (push (mail-header-field-value) faces)))))
2400 (when faces
2401 (goto-char (point-min))
2402 (let (png image)
2403 (unless (setq from (gnus-article-goto-header "from"))
2404 (insert "From:")
2405 (setq from (point))
2406 (insert " [no 'from' set]\n"))
2407 (while faces
2408 (when (setq png (gnus-convert-face-to-png (pop faces)))
2409 (setq image
2410 (apply 'gnus-create-image png 'png t
2411 (cdr (assq 'png gnus-face-properties-alist))))
2412 (goto-char from)
2413 (when image
2414 (gnus-add-wash-type 'face)
2415 (gnus-add-image 'face image)
2416 (gnus-put-image image nil 'face)))))))))))
2418 (defun article-display-x-face (&optional force)
2419 "Look for an X-Face header and display it if present."
2420 (interactive (list 'force))
2421 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2422 (gnus-with-article-headers
2423 ;; Delete the old process, if any.
2424 (when (process-status "article-x-face")
2425 (delete-process "article-x-face"))
2426 ;; See the comment in `article-display-face'.
2427 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2428 ;; We have already displayed X-Faces, so we remove them
2429 ;; instead.
2430 (gnus-delete-images 'xface)
2431 ;; Display X-Faces.
2432 (let ((from (message-fetch-field "from"))
2433 x-faces)
2434 (save-current-buffer
2435 (when (and wash-face-p
2436 (gnus-buffer-live-p gnus-original-article-buffer)
2437 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2438 ;; If type `W f', use gnus-original-article-buffer,
2439 ;; otherwise use the current buffer because displaying
2440 ;; RFC822 parts calls this function too.
2441 (set-buffer gnus-original-article-buffer))
2442 (save-restriction
2443 (mail-narrow-to-head)
2444 (and gnus-article-x-face-command
2445 (or force
2446 ;; Check whether this face is censored.
2447 (not (and gnus-article-x-face-too-ugly
2448 (or from
2449 (setq from (message-fetch-field "from")))
2450 (string-match gnus-article-x-face-too-ugly
2451 from))))
2452 (while (gnus-article-goto-header "X-Face")
2453 (push (mail-header-field-value) x-faces)))))
2454 (when x-faces
2455 ;; We display the face.
2456 (cond ((functionp gnus-article-x-face-command)
2457 ;; The command is a lisp function, so we call it.
2458 (mapc gnus-article-x-face-command x-faces))
2459 ((stringp gnus-article-x-face-command)
2460 ;; The command is a string, so we interpret the command
2461 ;; as a, well, command, and fork it off.
2462 (let ((process-connection-type nil))
2463 (set-process-query-on-exit-flag
2464 (start-process
2465 "article-x-face" nil shell-file-name
2466 shell-command-switch gnus-article-x-face-command)
2467 nil)
2468 ;; Sending multiple EOFs to xv doesn't work,
2469 ;; so we only do a single external face.
2470 (with-temp-buffer
2471 (insert (car x-faces))
2472 (process-send-region "article-x-face"
2473 (point-min) (point-max)))
2474 (process-send-eof "article-x-face")))
2476 (error "`%s' set to `%s' is not a function"
2477 gnus-article-x-face-command
2478 'gnus-article-x-face-command)))))))))
2480 (defun article-decode-mime-words ()
2481 "Decode all MIME-encoded words in the article."
2482 (interactive)
2483 (gnus-with-article-buffer
2484 (let ((inhibit-point-motion-hooks t)
2485 (mail-parse-charset gnus-newsgroup-charset)
2486 (mail-parse-ignored-charsets
2487 (with-current-buffer gnus-summary-buffer
2488 gnus-newsgroup-ignored-charsets)))
2489 (mail-decode-encoded-word-region (point-min) (point-max)))))
2491 (defun article-decode-charset (&optional prompt)
2492 "Decode charset-encoded text in the article.
2493 If PROMPT (the prefix), prompt for a coding system to use."
2494 (interactive "P")
2495 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2496 (inhibit-read-only t)
2497 (mail-parse-charset gnus-newsgroup-charset)
2498 (mail-parse-ignored-charsets
2499 (save-excursion (condition-case nil
2500 (set-buffer gnus-summary-buffer)
2501 (error))
2502 gnus-newsgroup-ignored-charsets))
2503 ct cte ctl charset format)
2504 (save-excursion
2505 (save-restriction
2506 (article-narrow-to-head)
2507 (setq ct (message-fetch-field "Content-Type" t)
2508 cte (message-fetch-field "Content-Transfer-Encoding" t)
2509 ctl (and ct (mail-header-parse-content-type ct))
2510 charset (cond
2511 (prompt
2512 (read-coding-system "Charset to decode: "))
2513 (ctl
2514 (mail-content-type-get ctl 'charset)))
2515 format (and ctl (mail-content-type-get ctl 'format)))
2516 (when cte
2517 (setq cte (mail-header-strip-cte cte)))
2518 (if (and ctl (not (string-match "/" (car ctl))))
2519 (setq ctl nil))
2520 (goto-char (point-max)))
2521 (forward-line 1)
2522 (save-restriction
2523 (narrow-to-region (point) (point-max))
2524 (when (and (eq mail-parse-charset 'gnus-decoded)
2525 (eq (mm-body-7-or-8) '8bit))
2526 ;; The text code could have been decoded.
2527 (setq charset mail-parse-charset))
2528 (when (and (or (not ctl)
2529 (equal (car ctl) "text/plain"))
2530 (not format)) ;; article with format will decode later.
2531 (mm-decode-body
2532 charset (and cte (intern (downcase cte)))
2533 (car ctl)))))))
2535 (defun article-decode-encoded-words ()
2536 "Remove encoded-word encoding from headers."
2537 (let ((inhibit-point-motion-hooks t)
2538 (mail-parse-charset gnus-newsgroup-charset)
2539 (mail-parse-ignored-charsets
2540 (save-excursion (condition-case nil
2541 (set-buffer gnus-summary-buffer)
2542 (error))
2543 gnus-newsgroup-ignored-charsets))
2544 (inhibit-read-only t)
2545 end start)
2546 (goto-char (point-min))
2547 (when (search-forward "\n\n" nil 'move)
2548 (forward-line -1))
2549 (setq end (point))
2550 (while (not (bobp))
2551 (while (progn
2552 (forward-line -1)
2553 (and (not (bobp))
2554 (memq (char-after) '(?\t ? )))))
2555 (setq start (point))
2556 (if (looking-at "\
2557 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2558 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2559 (funcall gnus-decode-address-function start end)
2560 (funcall gnus-decode-header-function start end))
2561 (goto-char (setq end start)))))
2563 (defun article-decode-group-name ()
2564 "Decode group names in Newsgroups, Followup-To and Xref headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (inhibit-read-only t)
2567 (method (gnus-find-method-for-group gnus-newsgroup-name))
2568 regexp)
2569 (when (and (or gnus-group-name-charset-method-alist
2570 gnus-group-name-charset-group-alist)
2571 (gnus-buffer-live-p gnus-original-article-buffer))
2572 (save-restriction
2573 (article-narrow-to-head)
2574 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2575 (with-current-buffer gnus-original-article-buffer
2576 (goto-char (point-min)))
2577 (setq regexp (concat "^" header
2578 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2579 (while (re-search-forward regexp nil t)
2580 (replace-match (save-match-data
2581 (gnus-decode-newsgroups
2582 ;; XXX how to use data in article buffer?
2583 (with-current-buffer gnus-original-article-buffer
2584 (re-search-forward regexp nil t)
2585 (match-string 1))
2586 gnus-newsgroup-name method))
2587 t t nil 1))
2588 (goto-char (point-min)))))))
2590 (defun article-decode-idna-rhs ()
2591 "Decode IDNA strings in RHS in various headers in current buffer.
2592 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2593 Mail-Reply-To: and Mail-Followup-To:."
2594 (when gnus-use-idna
2595 (save-restriction
2596 (let ((inhibit-point-motion-hooks t)
2597 (inhibit-read-only t))
2598 (article-narrow-to-head)
2599 (goto-char (point-min))
2600 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2601 (let (ace unicode)
2602 (when (save-match-data
2603 (and (setq ace (match-string 1))
2604 (save-excursion
2605 (and (re-search-backward "^[^ \t]" nil t)
2606 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2607 (setq unicode (puny-decode-domain ace))))
2608 (unless (string= ace unicode)
2609 (replace-match unicode nil nil nil 1)))))))))
2611 (defun article-de-quoted-unreadable (&optional force read-charset)
2612 "Translate a quoted-printable-encoded article.
2613 If FORCE, decode the article whether it is marked as quoted-printable
2614 or not.
2615 If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
2617 (save-excursion
2618 (let ((inhibit-read-only t) type charset)
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2621 (setq type
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
2624 (ctl (and ct (mail-header-parse-content-type ct))))
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
2629 (if read-charset
2630 (setq charset (read-coding-system "Charset: " charset)))
2631 (unless charset
2632 (setq charset gnus-newsgroup-charset))
2633 (when (or force
2634 (and type (let ((case-fold-search t))
2635 (string-match "quoted-printable" type))))
2636 (article-goto-body)
2637 (quoted-printable-decode-region
2638 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2640 (defun article-de-base64-unreadable (&optional force read-charset)
2641 "Translate a base64 article.
2642 If FORCE, decode the article whether it is marked as base64 not.
2643 If READ-CHARSET, ask for a coding system."
2644 (interactive (list 'force current-prefix-arg))
2645 (save-excursion
2646 (let ((inhibit-read-only t) type charset)
2647 (if (gnus-buffer-live-p gnus-original-article-buffer)
2648 (with-current-buffer gnus-original-article-buffer
2649 (setq type
2650 (gnus-fetch-field "content-transfer-encoding"))
2651 (let* ((ct (gnus-fetch-field "content-type"))
2652 (ctl (and ct (mail-header-parse-content-type ct))))
2653 (setq charset (and ctl
2654 (mail-content-type-get ctl 'charset)))
2655 (if (stringp charset)
2656 (setq charset (intern (downcase charset)))))))
2657 (if read-charset
2658 (setq charset (read-coding-system "Charset: " charset)))
2659 (unless charset
2660 (setq charset gnus-newsgroup-charset))
2661 (when (or force
2662 (and type (let ((case-fold-search t))
2663 (string-match "base64" type))))
2664 (article-goto-body)
2665 (save-restriction
2666 (narrow-to-region (point) (point-max))
2667 (base64-decode-region (point-min) (point-max))
2668 (decode-coding-region
2669 (point-min) (point-max)
2670 (mm-charset-to-coding-system charset nil t)))))))
2672 (declare-function rfc1843-decode-region "rfc1843" (from to))
2674 (defun article-decode-HZ ()
2675 "Translate a HZ-encoded article."
2676 (interactive)
2677 (require 'rfc1843)
2678 (save-excursion
2679 (let ((inhibit-read-only t))
2680 (rfc1843-decode-region (point-min) (point-max)))))
2682 (defun article-unsplit-urls ()
2683 "Remove the newlines that some other mailers insert into URLs."
2684 (interactive)
2685 (save-excursion
2686 (let ((inhibit-read-only t))
2687 (goto-char (point-min))
2688 (while (re-search-forward
2689 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2690 (replace-match "\\1\\3" t)))
2691 (when (called-interactively-p 'any)
2692 (gnus-treat-article nil))))
2694 (defun article-wash-html ()
2695 "Format an HTML article."
2696 (interactive)
2697 (let ((handles nil)
2698 (buffer-read-only nil))
2699 (when (gnus-buffer-live-p gnus-original-article-buffer)
2700 (with-current-buffer gnus-original-article-buffer
2701 (setq handles (mm-dissect-buffer t t))))
2702 (article-goto-body)
2703 (delete-region (point) (point-max))
2704 (mm-enable-multibyte)
2705 (mm-inline-text-html handles)))
2707 (defvar gnus-article-browse-html-temp-list nil
2708 "List of temporary files created by `gnus-article-browse-html-parts'.
2709 Internal variable.")
2711 (defcustom gnus-article-browse-delete-temp 'ask
2712 "What to do with temporary files from `gnus-article-browse-html-parts'.
2713 If nil, don't delete temporary files. If it is t, delete them on
2714 exit from the summary buffer. If it is the symbol `file', query
2715 on each file, if it is `ask' ask once when exiting from the
2716 summary buffer."
2717 :group 'gnus-article
2718 :version "23.1" ;; No Gnus
2719 :type '(choice (const :tag "Don't delete" nil)
2720 (const :tag "Don't ask" t)
2721 (const :tag "Ask" ask)
2722 (const :tag "Ask for each file" file)))
2724 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2726 (defun gnus-article-browse-delete-temp-files (&optional how)
2727 "Delete temp-files created by `gnus-article-browse-html-parts'."
2728 (when (and gnus-article-browse-html-temp-list
2729 (progn
2730 (or how (setq how gnus-article-browse-delete-temp))
2731 (if (eq how 'ask)
2732 (let ((files (length gnus-article-browse-html-temp-list)))
2733 (or (gnus-y-or-n-p
2734 (if (= files 1)
2735 "Delete the temporary HTML file? "
2736 (format "Delete all %s temporary HTML files? "
2737 files)))
2738 (setq gnus-article-browse-html-temp-list nil)))
2739 how)))
2740 (dolist (file gnus-article-browse-html-temp-list)
2741 (cond ((file-directory-p file)
2742 (when (or (not (eq how 'file))
2743 (gnus-y-or-n-p
2744 (format-message
2745 "Delete temporary HTML file(s) in directory `%s'? "
2746 (file-name-as-directory file))))
2747 (gnus-delete-directory file)))
2748 ((file-exists-p file)
2749 (when (or (not (eq how 'file))
2750 (gnus-y-or-n-p
2751 (format "Delete temporary HTML file `%s'? " file)))
2752 (delete-file file)))))
2753 ;; Also remove file from the list when not deleted or if file doesn't
2754 ;; exist anymore.
2755 (setq gnus-article-browse-html-temp-list nil))
2756 gnus-article-browse-html-temp-list)
2758 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2759 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2760 Return file name relative to the parent of DIRECTORY."
2761 (save-match-data
2762 (let (file afile)
2763 (catch 'found
2764 (dolist (handle handles)
2765 (cond
2766 ((not (listp handle)))
2767 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2768 ;; may create.
2769 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2770 ((equal (mm-handle-media-supertype handle) "multipart")
2771 (when (setq file (gnus-article-browse-html-save-cid-content
2772 cid handle directory))
2773 (throw 'found file)))
2774 ((equal (concat "<" cid ">") (mm-handle-id handle))
2775 (setq file (or (mm-handle-filename handle)
2776 (concat
2777 (make-temp-name "cid")
2778 (car (rassoc (car (mm-handle-type handle))
2779 mailcap-mime-extensions))))
2780 afile (expand-file-name file directory))
2781 (mm-save-part-to-file handle afile)
2782 (throw 'found (concat (file-name-nondirectory
2783 (directory-file-name directory))
2784 "/" file)))))))))
2786 (defun gnus-article-browse-html-parts (list &optional header)
2787 "View all \"text/html\" parts from LIST.
2788 Recurse into multiparts. The optional HEADER that should be a decoded
2789 message header will be added to the bodies of the \"text/html\" parts."
2790 ;; Internal function used by `gnus-article-browse-html-article'.
2791 (let (type file charset content cid-dir tmp-file showed)
2792 ;; Find and show the html-parts.
2793 (dolist (handle list)
2794 ;; If HTML, show it:
2795 (cond ((not (listp handle)))
2796 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2797 (and (equal (car type) "message/external-body")
2798 (or header
2799 (setq file (mm-handle-filename handle)))
2800 (or (mm-handle-cache handle)
2801 (condition-case code
2802 (progn (mm-extern-cache-contents handle) t)
2803 (error
2804 (gnus-message 3 "%s" (error-message-string code))
2805 (when (>= gnus-verbose 3) (sit-for 2))
2806 nil)))
2807 (progn
2808 (setq handle (mm-handle-cache handle)
2809 type (mm-handle-type handle))
2810 (equal (car type) "text/html"))))
2811 (setq charset (mail-content-type-get type 'charset)
2812 content (mm-get-part handle))
2813 (with-temp-buffer
2814 (if (eq charset 'gnus-decoded)
2815 (mm-enable-multibyte)
2816 (mm-disable-multibyte))
2817 (insert content)
2818 ;; resolve cid contents
2819 (let ((case-fold-search t)
2820 st base regexp cid-file)
2821 (goto-char (point-min))
2822 (when (and (re-search-forward "<head[\t\n >]" nil t)
2823 (progn
2824 (setq st (match-end 0))
2825 (re-search-forward "</head[\t\n >]" nil t))
2826 (re-search-backward "<base\
2827 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2828 (setq base (match-string 1))
2829 (replace-match "<!--\\&-->")
2830 (setq st (point))
2831 (dolist (tag '(("a" . "href") ("form" . "action")
2832 ("img" . "src")))
2833 (setq regexp (concat "<" (car tag)
2834 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2835 (cdr tag) "=\"\\([^\"]+\\)"))
2836 (while (re-search-forward regexp nil t)
2837 (insert (prog1
2838 (condition-case nil
2839 (save-match-data
2840 (url-expand-file-name (match-string 1)
2841 base))
2842 (error (match-string 1)))
2843 (delete-region (match-beginning 1)
2844 (match-end 1)))))
2845 (goto-char st)))
2846 (while (re-search-forward "\
2847 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2848 nil t)
2849 (unless cid-dir
2850 (setq cid-dir (make-temp-file "cid" t))
2851 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2852 (setq file nil
2853 content nil)
2854 (when (setq cid-file
2855 (gnus-article-browse-html-save-cid-content
2856 (match-string 2)
2857 (with-current-buffer gnus-article-buffer
2858 gnus-article-mime-handles)
2859 cid-dir))
2860 (replace-match cid-file nil nil nil 1))))
2861 (unless content (setq content (buffer-string))))
2862 (when (or charset header (not file))
2863 (setq tmp-file (make-temp-file
2864 ;; Do we need to care for 8.3 filenames?
2865 "mm-" nil ".html")))
2866 ;; Add a meta html tag to specify charset and a header.
2867 (cond
2868 (header
2869 (let (title eheader body hcharset coding)
2870 (with-temp-buffer
2871 (mm-enable-multibyte)
2872 (setq case-fold-search t)
2873 (insert header "\n")
2874 (setq title (message-fetch-field "subject"))
2875 (goto-char (point-min))
2876 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2877 nil t)
2878 (replace-match (cond ((match-beginning 1) "&lt;")
2879 ((match-beginning 2) "&gt;")
2880 ((match-beginning 3) "&amp;")
2881 (t "<br>\n"))))
2882 (goto-char (point-min))
2883 (while (re-search-forward "^[\t ]+" nil t)
2884 (dotimes (i (prog1
2885 (current-column)
2886 (delete-region (match-beginning 0)
2887 (match-end 0))))
2888 (insert "&nbsp;")))
2889 (goto-char (point-min))
2890 (insert "<div align=\"left\">\n")
2891 (goto-char (point-max))
2892 (insert "</div>\n<hr>\n")
2893 ;; We have to examine charset one by one since
2894 ;; charset specified in parts might be different.
2895 (if (eq charset 'gnus-decoded)
2896 (setq charset 'utf-8
2897 eheader (encode-coding-string (buffer-string)
2898 charset)
2899 title (when title
2900 (encode-coding-string title charset))
2901 body (encode-coding-string content charset))
2902 (setq hcharset (mm-find-mime-charset-region (point-min)
2903 (point-max)))
2904 (cond ((= (length hcharset) 1)
2905 (setq hcharset (car hcharset)
2906 coding (mm-charset-to-coding-system
2907 hcharset nil t)))
2908 ((> (length hcharset) 1)
2909 (setq hcharset 'utf-8
2910 coding hcharset)))
2911 (if coding
2912 (if charset
2913 (progn
2914 (setq body
2915 (mm-charset-to-coding-system charset
2916 nil t))
2917 (if (eq coding body)
2918 (setq eheader (encode-coding-string
2919 (buffer-string) coding)
2920 title (when title
2921 (encode-coding-string
2922 title coding))
2923 body content)
2924 (setq charset 'utf-8
2925 eheader (encode-coding-string
2926 (buffer-string) charset)
2927 title (when title
2928 (encode-coding-string
2929 title charset))
2930 body (encode-coding-string
2931 (decode-coding-string
2932 content body)
2933 charset))))
2934 (setq charset hcharset
2935 eheader (encode-coding-string
2936 (buffer-string) coding)
2937 title (when title
2938 (encode-coding-string
2939 title coding))
2940 body content))
2941 (setq eheader (string-as-unibyte (buffer-string))
2942 body content)))
2943 (erase-buffer)
2944 (mm-disable-multibyte)
2945 (insert body)
2946 (when charset
2947 (mm-add-meta-html-tag handle charset t))
2948 (when title
2949 (goto-char (point-min))
2950 (unless (search-forward "<title>" nil t)
2951 (re-search-forward "<head>\\s-*" nil t)
2952 (insert "<title>" title "</title>\n")))
2953 (goto-char (point-min))
2954 (or (re-search-forward
2955 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2956 (re-search-forward
2957 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2958 (insert eheader)
2959 (mm-write-region (point-min) (point-max)
2960 tmp-file nil nil nil 'binary t))))
2961 (charset
2962 (mm-with-unibyte-buffer
2963 (insert (if (eq charset 'gnus-decoded)
2964 (encode-coding-string content
2965 (setq charset 'utf-8))
2966 content))
2967 (if (or (mm-add-meta-html-tag handle charset)
2968 (not file))
2969 (mm-write-region (point-min) (point-max)
2970 tmp-file nil nil nil 'binary t)
2971 (setq tmp-file nil))))
2972 (tmp-file
2973 (mm-save-part-to-file handle tmp-file)))
2974 (when tmp-file
2975 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2976 (add-hook 'gnus-summary-prepare-exit-hook
2977 'gnus-article-browse-delete-temp-files)
2978 (add-hook 'gnus-exit-gnus-hook
2979 (lambda ()
2980 (gnus-article-browse-delete-temp-files t)))
2981 ;; FIXME: Warn if there's an <img> tag?
2982 (browse-url-of-file (or tmp-file (expand-file-name file)))
2983 (setq showed t))
2984 ;; If multipart, recurse
2985 ((equal (mm-handle-media-supertype handle) "multipart")
2986 (when (gnus-article-browse-html-parts handle header)
2987 (setq showed t)))
2988 ((equal (mm-handle-media-type handle) "message/rfc822")
2989 (mm-with-multibyte-buffer
2990 (mm-insert-part handle)
2991 (setq handle (mm-dissect-buffer t t))
2992 (when (and (bufferp (car handle))
2993 (stringp (car (mm-handle-type handle))))
2994 (setq handle (list handle)))
2995 (when header
2996 (article-decode-encoded-words)
2997 (let ((gnus-visible-headers
2998 (or (get 'gnus-visible-headers 'standard-value)
2999 gnus-visible-headers)))
3000 (article-hide-headers))
3001 (goto-char (point-min))
3002 (search-forward "\n\n" nil 'move)
3003 (skip-chars-backward "\t\n ")
3004 (setq header (buffer-substring (point-min) (point)))))
3005 (when (prog1
3006 (gnus-article-browse-html-parts handle header)
3007 (mm-destroy-parts handle))
3008 (setq showed t)))))
3009 showed))
3011 (defun gnus-article-browse-html-article (&optional arg)
3012 "View \"text/html\" parts of the current article with a WWW browser.
3013 Inline images embedded in a message using the cid scheme, as they are
3014 generally considered to be safe, will be processed properly.
3015 The message header is added to the beginning of every html part unless
3016 the prefix argument ARG is given.
3018 Warning: Spammers use links to images (using the http scheme) in HTML
3019 articles to verify whether you have read the message. As
3020 `gnus-article-browse-html-article' passes the HTML content to the
3021 browser without eliminating these \"web bugs\" you should only
3022 use it for mails from trusted senders.
3024 If you always want to display HTML parts in the browser, set
3025 `mm-text-html-renderer' to nil.
3027 This command creates temporary files to pass HTML contents including
3028 images if any to the browser, and deletes them when exiting the group
3029 \(if you want)."
3030 ;; Cf. `mm-w3m-safe-url-regexp'
3031 (interactive "P")
3032 (if arg
3033 (gnus-summary-show-article)
3034 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3035 gnus-visible-headers))
3036 ;; As we insert a <hr>, there's no need for the body boundary.
3037 (gnus-treat-body-boundary nil))
3038 (gnus-summary-show-article)))
3039 (with-current-buffer gnus-article-buffer
3040 (let ((header (unless arg
3041 (save-restriction
3042 (widen)
3043 (buffer-substring-no-properties
3044 (goto-char (point-min))
3045 (if (search-forward "\n\n" nil t)
3046 (match-beginning 0)
3047 (goto-char (point-max))
3048 (skip-chars-backward "\t\n ")
3049 (point))))))
3050 parts)
3051 (set-buffer gnus-original-article-buffer)
3052 (setq parts (mm-dissect-buffer t t))
3053 ;; If singlepart, enforce a list.
3054 (when (and (bufferp (car parts))
3055 (stringp (car (mm-handle-type parts))))
3056 (setq parts (list parts)))
3057 ;; Process the list
3058 (unless (gnus-article-browse-html-parts parts header)
3059 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3060 (mm-destroy-parts parts)
3061 (unless arg
3062 (gnus-summary-show-article)))))
3064 (defun article-hide-list-identifiers ()
3065 "Remove list identifiers from the Subject header.
3066 The `gnus-list-identifiers' variable specifies what to do."
3067 (interactive)
3068 (let ((inhibit-point-motion-hooks t)
3069 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3070 (inhibit-read-only t))
3071 (when regexp
3072 (save-excursion
3073 (save-restriction
3074 (article-narrow-to-head)
3075 (goto-char (point-min))
3076 (while (re-search-forward
3077 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3078 nil t)
3079 (delete-region (match-beginning 2) (match-end 0))
3080 (beginning-of-line))
3081 (when (re-search-forward
3082 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3083 (delete-region (match-beginning 1) (match-end 1))))))))
3085 (defun article-hide-pem (&optional arg)
3086 "Toggle hiding of any PEM headers and signatures in the current article.
3087 If given a negative prefix, always show; if given a positive prefix,
3088 always hide."
3089 (interactive (gnus-article-hidden-arg))
3090 (unless (gnus-article-check-hidden-text 'pem arg)
3091 (save-excursion
3092 (let ((inhibit-read-only t) end)
3093 (goto-char (point-min))
3094 ;; Hide the horrendously ugly "header".
3095 (when (and (search-forward
3096 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3097 nil t)
3098 (setq end (1+ (match-beginning 0))))
3099 (gnus-add-wash-type 'pem)
3100 (gnus-article-hide-text-type
3102 (if (search-forward "\n\n" nil t)
3103 (match-end 0)
3104 (point-max))
3105 'pem)
3106 ;; Hide the trailer as well
3107 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3108 nil t)
3109 (gnus-article-hide-text-type
3110 (match-beginning 0) (match-end 0) 'pem)))))))
3112 (defun article-strip-banner ()
3113 "Strip the banners specified by the `banner' group parameter and by
3114 `gnus-article-address-banner-alist'."
3115 (interactive)
3116 (save-excursion
3117 (save-restriction
3118 (let ((inhibit-point-motion-hooks t))
3119 (when (gnus-parameter-banner gnus-newsgroup-name)
3120 (article-really-strip-banner
3121 (gnus-parameter-banner gnus-newsgroup-name)))
3122 (when gnus-article-address-banner-alist
3123 ;; Note that the From header is decoded here, so it is
3124 ;; required that the *-extract-address-components function
3125 ;; supports non-ASCII text.
3126 (let ((from (save-restriction
3127 (widen)
3128 (article-narrow-to-head)
3129 (mail-fetch-field "from"))))
3130 (when (and from
3131 (setq from
3132 (cadr (funcall gnus-extract-address-components
3133 from))))
3134 (catch 'found
3135 (dolist (pair gnus-article-address-banner-alist)
3136 (when (string-match (car pair) from)
3137 (throw 'found
3138 (article-really-strip-banner (cdr pair)))))))))))))
3140 (defun article-really-strip-banner (banner)
3141 "Strip the banner specified by the argument."
3142 (save-excursion
3143 (save-restriction
3144 (let ((inhibit-point-motion-hooks t)
3145 (gnus-signature-limit nil)
3146 (inhibit-read-only t))
3147 (article-goto-body)
3148 (cond
3149 ((eq banner 'signature)
3150 (when (gnus-article-narrow-to-signature)
3151 (widen)
3152 (forward-line -1)
3153 (delete-region (point) (point-max))))
3154 ((symbolp banner)
3155 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3156 (while (re-search-forward banner nil t)
3157 (delete-region (match-beginning 0) (match-end 0)))))
3158 ((stringp banner)
3159 (while (re-search-forward banner nil t)
3160 (delete-region (match-beginning 0) (match-end 0)))))))))
3162 (defun article-babel ()
3163 "Translate article using an online translation service."
3164 (interactive)
3165 (require 'babel)
3166 (gnus-with-article-buffer
3167 (when (article-goto-body)
3168 (let* ((start (point))
3169 (end (point-max))
3170 (orig (buffer-substring start end))
3171 (trans (babel-as-string orig)))
3172 (save-restriction
3173 (narrow-to-region start end)
3174 (delete-region start end)
3175 (insert trans))))))
3177 (defun article-hide-signature (&optional arg)
3178 "Hide the signature in the current article.
3179 If given a negative prefix, always show; if given a positive prefix,
3180 always hide."
3181 (interactive (gnus-article-hidden-arg))
3182 (unless (gnus-article-check-hidden-text 'signature arg)
3183 (save-excursion
3184 (save-restriction
3185 (let ((inhibit-read-only t))
3186 (when (gnus-article-narrow-to-signature)
3187 (gnus-article-hide-text-type
3188 (point-min) (point-max) 'signature))))))
3189 (gnus-set-mode-line 'article))
3191 (defun article-strip-headers-in-body ()
3192 "Strip offensive headers from bodies."
3193 (interactive)
3194 (save-excursion
3195 (article-goto-body)
3196 (let ((case-fold-search t))
3197 (when (looking-at "x-no-archive:")
3198 (gnus-delete-line)))))
3200 (defun article-strip-leading-blank-lines ()
3201 "Remove all blank lines from the beginning of the article."
3202 (interactive)
3203 (save-excursion
3204 (let ((inhibit-point-motion-hooks t)
3205 (inhibit-read-only t))
3206 (when (article-goto-body)
3207 (while (and (not (eobp))
3208 (looking-at "[ \t]*$"))
3209 (gnus-delete-line))))))
3211 (defun article-narrow-to-head ()
3212 "Narrow the buffer to the head of the message.
3213 Point is left at the beginning of the narrowed-to region."
3214 (narrow-to-region
3215 (goto-char (point-min))
3216 (cond
3217 ;; Absolutely no headers displayed.
3218 ((looking-at "\n")
3219 (point))
3220 ;; Normal headers.
3221 ((search-forward "\n\n" nil 1)
3222 (1- (point)))
3223 ;; Nothing but headers.
3225 (point-max))))
3226 (goto-char (point-min)))
3228 (defun article-goto-body ()
3229 "Place point at the start of the body."
3230 (goto-char (point-min))
3231 (cond
3232 ;; This variable is only bound when dealing with separate
3233 ;; MIME body parts.
3234 (article-goto-body-goes-to-point-min-p
3236 ((search-forward "\n\n" nil t)
3239 (goto-char (point-max))
3240 nil)))
3242 (defun article-strip-multiple-blank-lines ()
3243 "Replace consecutive blank lines with one empty line."
3244 (interactive)
3245 (save-excursion
3246 (let ((inhibit-point-motion-hooks t)
3247 (inhibit-read-only t))
3248 ;; First make all blank lines empty.
3249 (article-goto-body)
3250 (while (re-search-forward "^[ \t]+$" nil t)
3251 (unless (gnus-annotation-in-region-p
3252 (match-beginning 0) (match-end 0))
3253 (replace-match "" nil t)))
3254 ;; Then replace multiple empty lines with a single empty line.
3255 (article-goto-body)
3256 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3257 (unless (gnus-annotation-in-region-p
3258 (match-beginning 0) (match-end 0))
3259 (delete-region (match-beginning 1) (match-end 1)))))))
3261 (defun article-strip-leading-space ()
3262 "Remove all white space from the beginning of the lines in the article."
3263 (interactive)
3264 (save-excursion
3265 (let ((inhibit-point-motion-hooks t)
3266 (inhibit-read-only t))
3267 (article-goto-body)
3268 (while (re-search-forward "^[ \t]+" nil t)
3269 (replace-match "" t t)))))
3271 (defun article-strip-trailing-space ()
3272 "Remove all white space from the end of the lines in the article."
3273 (interactive)
3274 (save-excursion
3275 (let ((inhibit-point-motion-hooks t)
3276 (inhibit-read-only t))
3277 (article-goto-body)
3278 (while (re-search-forward "[ \t]+$" nil t)
3279 (replace-match "" t t)))))
3281 (defun article-strip-blank-lines ()
3282 "Strip leading, trailing and multiple blank lines."
3283 (interactive)
3284 (article-strip-leading-blank-lines)
3285 (article-remove-trailing-blank-lines)
3286 (article-strip-multiple-blank-lines))
3288 (defun article-strip-all-blank-lines ()
3289 "Strip all blank lines."
3290 (interactive)
3291 (save-excursion
3292 (let ((inhibit-point-motion-hooks t)
3293 (inhibit-read-only t))
3294 (article-goto-body)
3295 (while (re-search-forward "^[ \t]*\n" nil t)
3296 (replace-match "" t t)))))
3298 (defun gnus-article-narrow-to-signature ()
3299 "Narrow to the signature; return t if a signature is found, else nil."
3300 (let ((inhibit-point-motion-hooks t))
3301 (when (gnus-article-search-signature)
3302 (forward-line 1)
3303 ;; Check whether we have some limits to what we consider
3304 ;; to be a signature.
3305 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3306 (list gnus-signature-limit)))
3307 limit limited)
3308 (while (setq limit (pop limits))
3309 (if (or (and (integerp limit)
3310 (< (- (point-max) (point)) limit))
3311 (and (floatp limit)
3312 (< (count-lines (point) (point-max)) limit))
3313 (and (functionp limit)
3314 (funcall limit))
3315 (and (stringp limit)
3316 (not (re-search-forward limit nil t))))
3317 () ; This limit did not succeed.
3318 (setq limited t
3319 limits nil)))
3320 (unless limited
3321 (narrow-to-region (point) (point-max))
3322 t)))))
3324 (defun gnus-article-search-signature ()
3325 "Search the current buffer for the signature separator.
3326 Put point at the beginning of the signature separator."
3327 (let ((cur (point)))
3328 (goto-char (point-max))
3329 (if (if (stringp gnus-signature-separator)
3330 (re-search-backward gnus-signature-separator nil t)
3331 (let ((seps gnus-signature-separator))
3332 (while (and seps
3333 (not (re-search-backward (car seps) nil t)))
3334 (pop seps))
3335 seps))
3337 (goto-char cur)
3338 nil)))
3340 (defun gnus-article-hidden-arg ()
3341 "Return the current prefix arg as a number, or 0 if no prefix."
3342 (list (if current-prefix-arg
3343 (prefix-numeric-value current-prefix-arg)
3344 0)))
3346 (defun gnus-article-check-hidden-text (type arg)
3347 "Return nil if hiding is necessary.
3348 Arg can be nil or a number. nil and positive means hide, negative
3349 means show, 0 means toggle."
3350 (save-excursion
3351 (save-restriction
3352 (let ((hide (gnus-article-hidden-text-p type)))
3353 (cond
3354 ((or (null arg)
3355 (> arg 0))
3356 nil)
3357 ((< arg 0)
3358 (gnus-article-show-hidden-text type)
3361 (if (eq hide 'hidden)
3362 (progn
3363 (gnus-article-show-hidden-text type)
3365 nil)))))))
3367 (defun gnus-article-hidden-text-p (type)
3368 "Say whether the current buffer contains hidden text of type TYPE."
3369 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3370 (while (and pos
3371 (not (get-text-property pos 'invisible))
3372 (not (get-text-property pos 'dummy-invisible)))
3373 (setq pos
3374 (text-property-any (1+ pos) (point-max) 'article-type type)))
3375 (if pos
3376 'hidden
3377 nil)))
3379 (defun gnus-article-show-hidden-text (type &optional _dummy)
3380 "Show all hidden text of type TYPE.
3381 Originally it is hide instead of DUMMY."
3382 (let ((inhibit-read-only t)
3383 (inhibit-point-motion-hooks t))
3384 (gnus-remove-text-properties-when
3385 'article-type type
3386 (point-min) (point-max)
3387 (cons 'article-type (cons type
3388 gnus-hidden-properties)))
3389 (gnus-delete-wash-type type)))
3391 (defconst article-time-units
3392 `((year . ,(* 365.25 24 60 60))
3393 (week . ,(* 7 24 60 60))
3394 (day . ,(* 24 60 60))
3395 (hour . ,(* 60 60))
3396 (minute . 60)
3397 (second . 1))
3398 "Mapping from time units to seconds.")
3400 (defun gnus-article-forward-header ()
3401 "Move point to the start of the next header.
3402 If the current header is a continuation header, this can be several
3403 lines forward."
3404 (let ((ended nil))
3405 (while (not ended)
3406 (forward-line 1)
3407 (if (looking-at "[ \t]+[^ \t]")
3408 (forward-line 1)
3409 (setq ended t)))))
3411 (defun article-treat-date ()
3412 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3413 (with-current-buffer gnus-summary-buffer
3414 gnus-article-date-headers)
3415 gnus-article-date-headers)
3418 (defun article-date-ut (&optional type _highlight date-position)
3419 "Convert DATE date to TYPE in the current article.
3420 The default type is `ut'. See `gnus-article-date-headers' for
3421 possible values."
3422 (interactive (list 'ut t))
3423 (let* ((case-fold-search t)
3424 (inhibit-read-only t)
3425 (inhibit-point-motion-hooks t)
3426 (visible-date (mail-fetch-field "Date"))
3427 pos date bface eface)
3428 (save-excursion
3429 (if date-position
3430 (progn
3431 (goto-char date-position)
3432 (setq date (get-text-property (point) 'original-date))
3433 (beginning-of-line)
3434 (when (looking-at "[^:]+:[\t ]*")
3435 (setq bface (get-text-property (match-beginning 0) 'face)
3436 eface (get-text-property (match-end 0) 'face)))
3437 (goto-char date-position)
3438 (delete-region
3439 (or (and (bolp) date-position)
3440 ;; There might be space(s) added for line unfolding.
3441 (and (get-text-property date-position 'gnus-date-type)
3442 (< (skip-chars-backward "\t ") 0)
3443 (text-property-any (point) date-position
3444 'gnus-date-type nil))
3445 date-position)
3446 (progn (gnus-article-forward-header) (point)))
3447 (article-transform-date date type bface eface))
3448 (save-restriction
3449 (widen)
3450 (goto-char (point-min))
3451 (while (or (get-text-property (setq pos (point)) 'original-date)
3452 (and (setq pos (next-single-property-change
3453 (point) 'original-date))
3454 (goto-char pos)))
3455 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3456 (1+ (match-beginning 0))
3457 (point-max)))
3458 (while (setq pos (text-property-not-all pos (point-max)
3459 'gnus-date-type nil))
3460 (setq date (get-text-property pos 'original-date))
3461 (goto-char pos)
3462 (when (looking-at "[^:]+:[\t ]*")
3463 (setq bface (get-text-property (match-beginning 0) 'face)
3464 eface (get-text-property (match-end 0) 'face)))
3465 ;; Note: a feature like `gnus-treat-unfold-headers' breaks
3466 ;; the continuity of text props of a multi-line Date header,
3467 ;; that a user-defined date format might create, by adding
3468 ;; spaces. So, don't rely on gnus-date-type or original-date
3469 ;; text prop in case of searching for the header boundary.
3470 (delete-region pos (progn
3471 (gnus-article-forward-header)
3472 (point))))
3473 (unless date ;; the 1st time
3474 (goto-char (point-min))
3475 (while (re-search-forward "^Date:[\t ]*" nil t)
3476 (setq date (get-text-property (match-beginning 0)
3477 'original-date)
3478 bface (get-text-property (match-beginning 0) 'face)
3479 eface (get-text-property (match-end 0) 'face))
3480 (delete-region (point-at-bol) (progn
3481 (gnus-article-forward-header)
3482 (point)))))
3483 (when (and (not date)
3484 visible-date)
3485 (setq date visible-date))
3486 (when date
3487 (article-transform-date date type bface eface))
3488 (goto-char (point-max))
3489 (widen)))))))
3491 (defun article-transform-date (date type bface eface)
3492 (let (begin date-line)
3493 (dolist (this-type (cond ((null type)
3494 (list 'ut))
3495 ((atom type)
3496 (list type))
3498 type)))
3499 (setq begin (point)
3500 date-line (article-make-date-line date (or this-type 'ut)))
3501 (if (and (eq this-type 'user-defined) (bolp)
3502 ;; Test if this is not a continuation.
3503 (not (get-text-property
3504 (prog2 (end-of-line 0) (point) (goto-char begin))
3505 'gnus-date-type)))
3506 (progn
3507 (string-match "\\`\\([^\t\n :]+:\\)?[\t ]*" date-line)
3508 (if (match-beginning 1)
3509 (insert date-line "\n")
3510 ;; This user-defined date seems to intend to be a continuation
3511 ;; line of a multi-line Date header like this:
3512 ;; Date: Thu, Jan 1 00:00:00 1970 +0000
3513 ;; (47 years, 5 months, 20 days ago)
3514 (insert "Date: " (substring date-line (match-end 0)) "\n")))
3515 (insert date-line "\n"))
3516 (add-text-properties begin (point) (list 'original-date date
3517 'gnus-date-type this-type))
3518 (goto-char begin)
3519 ;; Do highlighting.
3520 (beginning-of-line)
3521 (looking-at
3522 "\\([^\n:]+:\\)?[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3523 (when (and bface (match-beginning 1))
3524 (put-text-property (match-beginning 1) (match-end 1) 'face bface))
3525 (when (match-beginning 2)
3526 (when eface
3527 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3528 (while (and (zerop (forward-line 1))
3529 (looking-at
3530 "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3531 (when (and eface (match-beginning 1))
3532 (put-text-property (match-beginning 1) (match-end 1)
3533 'face eface)))))))
3535 (defun article-make-date-line (date type)
3536 "Return a DATE line of TYPE."
3537 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3538 combined-lapsed))
3539 (error "Unknown conversion type: %s" type))
3540 (condition-case ()
3541 (let ((time (ignore-errors (date-to-time date))))
3542 (cond
3543 ;; Convert to the local timezone.
3544 ((eq type 'local)
3545 (concat "Date: " (message-make-date time)))
3546 ;; Convert to Universal Time.
3547 ((eq type 'ut)
3548 (concat "Date: "
3549 (substring
3550 (message-make-date
3551 (let* ((e (parse-time-string date))
3552 (tm (apply 'encode-time e))
3553 (ms (car tm))
3554 (ls (- (cadr tm) (car (current-time-zone time)))))
3555 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3556 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3557 (t (list ms ls)))))
3558 0 -5)
3559 "UT"))
3560 ;; Get the original date from the article.
3561 ((eq type 'original)
3562 (concat "Date: " (if (string-match "\n+$" date)
3563 (substring date 0 (match-beginning 0))
3564 date)))
3565 ;; Let the user define the format.
3566 ((eq type 'user-defined)
3567 (let ((format (or (condition-case nil
3568 (with-current-buffer gnus-summary-buffer
3569 gnus-article-time-format)
3570 (error nil))
3571 gnus-article-time-format)))
3572 (if (functionp format)
3573 (funcall format time)
3574 (concat "Date: " (format-time-string format time)))))
3575 ;; ISO 8601.
3576 ((eq type 'iso8601)
3577 (let ((tz (car (current-time-zone time))))
3578 (concat
3579 "Date: "
3580 (format-time-string "%Y%m%dT%H%M%S" time)
3581 (format "%s%02d%02d"
3582 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3583 (/ (% (abs tz) 3600) 60)))))
3584 ;; Do a lapsed format.
3585 ((eq type 'lapsed)
3586 (concat "Date: " (article-lapsed-string time)))
3587 ;; A combined date/lapsed format.
3588 ((eq type 'combined-lapsed)
3589 (let ((date-string (article-make-date-line date 'original))
3590 (segments 3)
3591 lapsed-string)
3592 (while (and
3593 time
3594 (setq lapsed-string
3595 (concat " (" (article-lapsed-string time segments) ")"))
3596 (> (+ (length date-string)
3597 (length lapsed-string))
3598 (+ fill-column 6))
3599 (> segments 0))
3600 (setq segments (1- segments)))
3601 (if (> segments 0)
3602 (concat date-string lapsed-string)
3603 date-string)))
3604 ;; Display the date in proper English
3605 ((eq type 'english)
3606 (let ((dtime (decode-time time)))
3607 (concat
3608 "Date: the "
3609 (number-to-string (nth 3 dtime))
3610 (let ((digit (% (nth 3 dtime) 10)))
3611 (cond
3612 ((memq (nth 3 dtime) '(11 12 13)) "th")
3613 ((= digit 1) "st")
3614 ((= digit 2) "nd")
3615 ((= digit 3) "rd")
3616 (t "th")))
3617 " of "
3618 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3620 (number-to-string (nth 5 dtime))
3621 " at "
3622 (format "%02d" (nth 2 dtime))
3624 (format "%02d" (nth 1 dtime)))))))
3625 (foo
3626 (format "Date: %s (from Gnus)" date))))
3628 (defun article-lapsed-string (time &optional max-segments)
3629 ;; If the date is seriously mangled, the timezone functions are
3630 ;; liable to bug out, so we ignore all errors.
3631 (let* ((now (current-time))
3632 (real-time (time-subtract now time))
3633 (real-sec (and real-time
3634 (+ (* (float (car real-time)) 65536)
3635 (cadr real-time))))
3636 (sec (and real-time (abs real-sec)))
3637 (segments 0)
3638 num prev)
3639 (unless max-segments
3640 (setq max-segments (length article-time-units)))
3641 (cond
3642 ((null real-time)
3643 "Unknown")
3644 ((zerop sec)
3645 "Now")
3647 (concat
3648 ;; This is a bit convoluted, but basically we go
3649 ;; through the time units for years, weeks, etc,
3650 ;; and divide things to see whether that results
3651 ;; in positive answers.
3652 (mapconcat
3653 (lambda (unit)
3654 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3655 (>= segments max-segments))
3656 ;; The (remaining) seconds are too few to
3657 ;; be divided into this time unit.
3659 ;; It's big enough, so we output it.
3660 (setq sec (- sec (* num (cdr unit))))
3661 (prog1
3662 (concat (if prev ", " "") (int-to-string
3663 (floor num))
3664 " " (symbol-name (car unit))
3665 (if (> num 1) "s" ""))
3666 (setq prev t
3667 segments (1+ segments)))))
3668 article-time-units "")
3669 ;; If dates are odd, then it might appear like the
3670 ;; article was sent in the future.
3671 (if (> real-sec 0)
3672 " ago"
3673 " in the future"))))))
3675 (defun article-date-local (&optional highlight)
3676 "Convert the current article date to the local timezone."
3677 (interactive (list t))
3678 (article-date-ut 'local highlight))
3680 (defun article-date-english (&optional highlight)
3681 "Convert the current article date to something that is proper English."
3682 (interactive (list t))
3683 (article-date-ut 'english highlight))
3685 (defun article-date-original (&optional highlight)
3686 "Convert the current article date to what it was originally.
3687 This is only useful if you have used some other date conversion
3688 function and want to see what the date was before converting."
3689 (interactive (list t))
3690 (article-date-ut 'original highlight))
3692 (defun article-date-lapsed (&optional highlight)
3693 "Convert the current article date to time lapsed since it was sent."
3694 (interactive (list t))
3695 (article-date-ut 'lapsed highlight))
3697 (defun article-date-combined-lapsed (&optional highlight)
3698 "Convert the current article date to time lapsed since it was sent."
3699 (interactive (list t))
3700 (article-date-ut 'combined-lapsed highlight))
3702 (defun article-update-date-lapsed ()
3703 "Function to be run from a timer to update the lapsed time line."
3704 (save-match-data
3705 (let ((buffer (current-buffer)))
3706 (ignore-errors
3707 (walk-windows
3708 (lambda (w)
3709 (set-buffer (window-buffer w))
3710 (when (derived-mode-p 'gnus-article-mode)
3711 (let ((old-line (count-lines (point-min) (point)))
3712 (old-column (- (point) (line-beginning-position)))
3713 (window-start (window-start w))
3714 (pos (point-min))
3715 type next end)
3716 (while (setq pos (text-property-not-all pos (point-max)
3717 'gnus-date-type nil))
3718 (setq next (or (next-single-property-change pos
3719 'gnus-date-type)
3720 (point-max)))
3721 (setq type (get-text-property pos 'gnus-date-type))
3722 (when (memq type '(lapsed combined-lapsed user-defined))
3723 (article-date-ut type t pos)
3724 (setq end (or (next-single-property-change pos
3725 'gnus-date-type)
3726 (point-max)))
3727 (when window-start
3728 (if (/= window-start next)
3729 (setq window-start nil)
3730 (set-window-start w end)))
3731 (setq next end))
3732 (setq pos next))
3733 (goto-char (point-min))
3734 (when (> old-column 0)
3735 (setq old-line (1- old-line)))
3736 (forward-line old-line)
3737 (end-of-line)
3738 (when (> (current-column) old-column)
3739 (beginning-of-line)
3740 (forward-char old-column)))))
3741 nil 'visible))
3742 (set-buffer buffer))))
3744 (defun gnus-start-date-timer (&optional n)
3745 "Start a timer to update the Date headers in the article buffers.
3746 The numerical prefix says how frequently (in seconds) the function
3747 is to run."
3748 (interactive "p")
3749 (unless n
3750 (setq n 1))
3751 (gnus-stop-date-timer)
3752 (setq article-lapsed-timer
3753 (run-at-time 1 n 'article-update-date-lapsed)))
3755 (defun gnus-stop-date-timer ()
3756 "Stop the Date timer."
3757 (interactive)
3758 (when article-lapsed-timer
3759 (nnheader-cancel-timer article-lapsed-timer)
3760 (setq article-lapsed-timer nil)))
3762 (defun article-date-user (&optional highlight)
3763 "Convert the current article date to the user-defined format.
3764 This format is defined by the `gnus-article-time-format' variable."
3765 (interactive (list t))
3766 (article-date-ut 'user-defined highlight))
3768 (defun article-date-iso8601 (&optional highlight)
3769 "Convert the current article date to ISO8601."
3770 (interactive (list t))
3771 (article-date-ut 'iso8601 highlight))
3773 (defmacro gnus-article-save-original-date (&rest forms)
3774 "Save the original date as a text property and evaluate FORMS."
3775 `(let* ((case-fold-search t)
3776 (start (progn
3777 (goto-char (point-min))
3778 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3779 (not (bolp)))
3780 (match-end 0))))
3781 (date (when (and start
3782 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3783 nil t))
3784 (buffer-substring-no-properties start
3785 (match-beginning 0)))))
3786 (goto-char (point-max))
3787 (skip-chars-backward "\n")
3788 (put-text-property (point-min) (point) 'original-date date)
3789 ,@forms
3790 (goto-char (point-max))
3791 (skip-chars-backward "\n")
3792 (put-text-property (point-min) (point) 'original-date date)))
3794 ;; (defun article-show-all ()
3795 ;; "Show all hidden text in the article buffer."
3796 ;; (interactive)
3797 ;; (save-excursion
3798 ;; (let ((inhibit-read-only t))
3799 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3801 (defun article-remove-leading-whitespace ()
3802 "Remove excessive whitespace from all headers."
3803 (interactive)
3804 (save-excursion
3805 (save-restriction
3806 (let ((inhibit-read-only t))
3807 (article-narrow-to-head)
3808 (goto-char (point-min))
3809 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3810 (delete-region (match-beginning 1) (match-end 1)))))))
3812 (defun article-emphasize (&optional arg)
3813 "Emphasize text according to `gnus-emphasis-alist'."
3814 (interactive (gnus-article-hidden-arg))
3815 (unless (gnus-article-check-hidden-text 'emphasis arg)
3816 (save-excursion
3817 (let ((alist (or
3818 (condition-case nil
3819 (with-current-buffer gnus-summary-buffer
3820 gnus-article-emphasis-alist)
3821 (error))
3822 gnus-emphasis-alist))
3823 (inhibit-read-only t)
3824 (props (append '(article-type emphasis)
3825 gnus-hidden-properties))
3826 regexp elem beg invisible visible face)
3827 (article-goto-body)
3828 (setq beg (point))
3829 (while (setq elem (pop alist))
3830 (goto-char beg)
3831 (setq regexp (car elem)
3832 invisible (nth 1 elem)
3833 visible (nth 2 elem)
3834 face (nth 3 elem))
3835 (while (re-search-forward regexp nil t)
3836 (when (and (match-beginning visible) (match-beginning invisible))
3837 (gnus-article-hide-text
3838 (match-beginning invisible) (match-end invisible) props)
3839 (gnus-article-unhide-text-type
3840 (match-beginning visible) (match-end visible) 'emphasis)
3841 (gnus-put-overlay-excluding-newlines
3842 (match-beginning visible) (match-end visible) 'face face)
3843 (gnus-add-wash-type 'emphasis)
3844 (goto-char (match-end invisible)))))))))
3846 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3847 "Setup newsgroup emphasis alist."
3848 (unless gnus-article-emphasis-alist
3849 (let ((name (and gnus-newsgroup-name
3850 (gnus-group-real-name gnus-newsgroup-name))))
3851 (make-local-variable 'gnus-article-emphasis-alist)
3852 (setq gnus-article-emphasis-alist
3853 (nconc
3854 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3855 (while (setq elem (pop alist))
3856 (when (and name (string-match (car elem) name))
3857 (setq alist nil
3858 highlight (copy-sequence (cdr elem)))))
3859 highlight)
3860 (copy-sequence highlight-words)
3861 (if gnus-newsgroup-name
3862 (copy-sequence (gnus-group-find-parameter
3863 gnus-newsgroup-name 'highlight-words t)))
3864 gnus-emphasis-alist)))))
3866 (defvar gnus-summary-article-menu)
3867 (defvar gnus-summary-post-menu)
3869 ;;; Saving functions.
3871 (defun gnus-article-save (save-buffer file &optional num)
3872 "Save the currently selected article."
3873 (when (or (get gnus-default-article-saver :headers)
3874 (not gnus-save-all-headers))
3875 ;; Remove headers according to `gnus-saved-headers' or the value
3876 ;; of the `:headers' property that the saver function might have.
3877 (let ((gnus-visible-headers
3878 (or (symbol-value (get gnus-default-article-saver :headers))
3879 gnus-saved-headers gnus-visible-headers))
3880 ;; Ignore group parameter. See `article-hide-headers'.
3881 (gnus-summary-buffer nil))
3882 (with-current-buffer save-buffer
3883 (article-hide-headers 1 t))))
3884 (save-window-excursion
3885 (if (not gnus-default-article-saver)
3886 (error "No default saver is defined")
3887 ;; !!! Magic! The saving functions all save
3888 ;; `gnus-save-article-buffer' (or so they think), but we
3889 ;; bind that variable to our save-buffer.
3890 (set-buffer gnus-article-buffer)
3891 (let* ((gnus-save-article-buffer save-buffer)
3892 (filename
3893 (cond
3894 ((not gnus-prompt-before-saving) 'default)
3895 ((eq gnus-prompt-before-saving 'always) nil)
3896 (t file)))
3897 (gnus-number-of-articles-to-be-saved
3898 (when (eq gnus-prompt-before-saving t)
3899 num))) ; Magic
3900 (set-buffer gnus-article-current-summary)
3901 (funcall gnus-default-article-saver filename)))))
3903 (defun gnus-read-save-file-name (prompt &optional filename
3904 function group headers variable
3905 dir-var)
3906 (let ((default-name
3907 (funcall function group headers (symbol-value variable)))
3908 result)
3909 (setq result
3910 (expand-file-name
3911 (cond
3912 ((eq filename 'default)
3913 default-name)
3914 ((eq filename t)
3915 default-name)
3916 (filename filename)
3918 (when (symbol-value dir-var)
3919 (setq default-name (expand-file-name
3920 (file-name-nondirectory default-name)
3921 (symbol-value dir-var))))
3922 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3923 (prompt
3924 (format prompt
3925 (if (and gnus-number-of-articles-to-be-saved
3926 (> gnus-number-of-articles-to-be-saved 1))
3927 (format "these %d articles"
3928 gnus-number-of-articles-to-be-saved)
3929 "this article")))
3930 (file
3931 ;; Let the split methods have their say.
3932 (cond
3933 ;; No split name was found.
3934 ((null split-name)
3935 (read-file-name
3936 (concat prompt " (default "
3937 (file-name-nondirectory default-name) "): ")
3938 (file-name-directory default-name)
3939 default-name))
3940 ;; A single group name is returned.
3941 ((stringp split-name)
3942 (setq default-name
3943 (funcall function split-name headers
3944 (symbol-value variable)))
3945 (read-file-name
3946 (concat prompt " (default "
3947 (file-name-nondirectory default-name) "): ")
3948 (file-name-directory default-name)
3949 default-name))
3950 ;; A single split name was found
3951 ((= 1 (length split-name))
3952 (let* ((name (expand-file-name
3953 (car split-name)
3954 gnus-article-save-directory))
3955 (dir (cond ((file-directory-p name)
3956 (file-name-as-directory name))
3957 ((file-exists-p name) name)
3958 (t gnus-article-save-directory))))
3959 (read-file-name
3960 (concat prompt " (default " name "): ")
3961 dir name)))
3962 ;; A list of splits was found.
3964 (setq split-name (nreverse split-name))
3965 (let (result)
3966 (let ((file-name-history
3967 (nconc split-name file-name-history)))
3968 (setq result
3969 (expand-file-name
3970 (read-file-name
3971 (concat prompt " (`M-p' for defaults): ")
3972 gnus-article-save-directory
3973 (car split-name))
3974 gnus-article-save-directory)))
3975 (car (push result file-name-history)))))))
3976 ;; Create the directory.
3977 (gnus-make-directory (file-name-directory file))
3978 ;; If we have read a directory, we append the default file name.
3979 (when (file-directory-p file)
3980 (setq file (expand-file-name (file-name-nondirectory
3981 default-name)
3982 (file-name-as-directory file))))
3983 ;; Possibly translate some characters.
3984 (nnheader-translate-file-chars file))))))
3985 (gnus-make-directory (file-name-directory result))
3986 (when variable
3987 (set variable result))
3988 (when dir-var
3989 (set dir-var (file-name-directory result)))
3990 result))
3992 (defun gnus-article-archive-name (_group)
3993 "Return the first instance of an \"Archive-name\" in the current buffer."
3994 (let ((case-fold-search t))
3995 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3996 (nnheader-concat gnus-article-save-directory
3997 (match-string 1)))))
3999 (defun gnus-article-nndoc-name (group)
4000 "If GROUP is an nndoc group, return the name of the parent group."
4001 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4002 (gnus-group-get-parameter group 'save-article-group)))
4004 (defun gnus-summary-save-in-rmail (&optional filename)
4005 "Append this article to Rmail file.
4006 Optional argument FILENAME specifies file name.
4007 Directory to save to is default to `gnus-article-save-directory'."
4008 (setq filename (gnus-read-save-file-name
4009 "Save %s in rmail file" filename
4010 gnus-rmail-save-name gnus-newsgroup-name
4011 gnus-current-headers 'gnus-newsgroup-last-rmail))
4012 (with-current-buffer gnus-save-article-buffer
4013 (save-excursion
4014 (save-restriction
4015 (widen)
4016 ;; Note that unlike gnus-summary-save-in-mail, there is no
4017 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4018 ;; not use Babyl.
4019 (gnus-output-to-rmail filename))))
4020 filename)
4022 (defun gnus-summary-save-in-mail (&optional filename)
4023 "Append this article to Unix mail file.
4024 Optional argument FILENAME specifies file name.
4025 Directory to save to is default to `gnus-article-save-directory'."
4026 (setq filename (gnus-read-save-file-name
4027 "Save %s in Unix mail file" filename
4028 gnus-mail-save-name gnus-newsgroup-name
4029 gnus-current-headers 'gnus-newsgroup-last-mail))
4030 (with-current-buffer gnus-save-article-buffer
4031 (save-excursion
4032 (save-restriction
4033 (widen)
4034 (if (and (file-readable-p filename)
4035 (file-regular-p filename)
4036 (mail-file-babyl-p filename))
4037 (gnus-output-to-rmail filename)
4038 (gnus-output-to-mail filename)))))
4039 filename)
4041 (put 'gnus-summary-save-in-file :decode t)
4042 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4043 (defun gnus-summary-save-in-file (&optional filename overwrite)
4044 "Append this article to file.
4045 Optional argument FILENAME specifies file name.
4046 Directory to save to is default to `gnus-article-save-directory'."
4047 (setq filename (gnus-read-save-file-name
4048 "Save %s in file" filename
4049 gnus-file-save-name gnus-newsgroup-name
4050 gnus-current-headers 'gnus-newsgroup-last-file))
4051 (with-current-buffer gnus-save-article-buffer
4052 (save-excursion
4053 (save-restriction
4054 (widen)
4055 (when (and overwrite
4056 (file-exists-p filename))
4057 (delete-file filename))
4058 (gnus-output-to-file filename))))
4059 filename)
4061 (put 'gnus-summary-write-to-file :decode t)
4062 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4063 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4064 (defun gnus-summary-write-to-file (&optional filename)
4065 "Write this article to a file, overwriting it if the file exists.
4066 Optional argument FILENAME specifies file name.
4067 The directory to save in defaults to `gnus-article-save-directory'."
4068 (setq filename (gnus-read-save-file-name
4069 "Save %s in file" filename
4070 gnus-file-save-name gnus-newsgroup-name
4071 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4072 (gnus-summary-save-in-file filename t))
4074 (put 'gnus-summary-save-body-in-file :decode t)
4075 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4076 "Append this article body to a file.
4077 Optional argument FILENAME specifies file name.
4078 The directory to save in defaults to `gnus-article-save-directory'."
4079 (setq filename (gnus-read-save-file-name
4080 "Save %s body in file" filename
4081 gnus-file-save-name gnus-newsgroup-name
4082 gnus-current-headers 'gnus-newsgroup-last-file))
4083 (with-current-buffer gnus-save-article-buffer
4084 (save-excursion
4085 (save-restriction
4086 (widen)
4087 (when (article-goto-body)
4088 (narrow-to-region (point) (point-max)))
4089 (when (and overwrite
4090 (file-exists-p filename))
4091 (delete-file filename))
4092 (gnus-output-to-file filename))))
4093 filename)
4095 (put 'gnus-summary-write-body-to-file :decode t)
4096 (put 'gnus-summary-write-body-to-file
4097 :function 'gnus-summary-save-body-in-file)
4098 (defun gnus-summary-write-body-to-file (&optional filename)
4099 "Write this article body to a file, overwriting it if the file exists.
4100 Optional argument FILENAME specifies file name.
4101 The directory to save in defaults to `gnus-article-save-directory'."
4102 (setq filename (gnus-read-save-file-name
4103 "Save %s body in file" filename
4104 gnus-file-save-name gnus-newsgroup-name
4105 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4106 (gnus-summary-save-body-in-file filename t))
4108 (put 'gnus-summary-save-in-pipe :decode t)
4109 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4110 (defun gnus-summary-save-in-pipe (&optional command raw)
4111 "Pipe this article to subprocess COMMAND.
4112 Valid values for COMMAND include:
4113 a string
4114 The executable command name and possibly arguments.
4116 You will be prompted for the command in the minibuffer.
4117 the symbol `default'
4118 It will be replaced with the command which the variable
4119 `gnus-summary-pipe-output-default-command' holds or the command
4120 last used for saving.
4121 Non-nil value for RAW overrides `:decode' and `:headers' properties
4122 and the raw article including all headers will be piped."
4123 (let ((article (gnus-summary-article-number))
4124 (decode (unless raw
4125 (get 'gnus-summary-save-in-pipe :decode)))
4126 save-buffer default)
4127 (if article
4128 (if (vectorp (gnus-summary-article-header article))
4129 (save-current-buffer
4130 (gnus-summary-select-article decode decode nil article)
4131 (insert-buffer-substring
4132 (prog1
4133 (if decode
4134 gnus-article-buffer
4135 gnus-original-article-buffer)
4136 (setq save-buffer
4137 (nnheader-set-temp-buffer " *Gnus Save*"))))
4138 ;; Remove unwanted headers.
4139 (when (and (not raw)
4140 (or (get 'gnus-summary-save-in-pipe :headers)
4141 (not gnus-save-all-headers)))
4142 (let ((gnus-visible-headers
4143 (or (symbol-value (get 'gnus-summary-save-in-pipe
4144 :headers))
4145 gnus-saved-headers gnus-visible-headers))
4146 (gnus-summary-buffer nil))
4147 (article-hide-headers 1 t))))
4148 (error "%d is not a real article" article))
4149 (error "No article to pipe"))
4150 (setq default (or gnus-summary-pipe-output-default-command
4151 gnus-last-shell-command))
4152 (unless (stringp command)
4153 (setq command
4154 (if (and (eq command 'default) default)
4155 default
4156 (read-shell-command "Shell command on this article: " default))))
4157 (when (string-equal command "")
4158 (if default
4159 (setq command default)
4160 (error "A command is required")))
4161 (with-current-buffer save-buffer
4162 (save-restriction
4163 (widen)
4164 (shell-command-on-region (point-min) (point-max) command nil)))
4165 (gnus-kill-buffer save-buffer))
4166 (setq gnus-summary-pipe-output-default-command command))
4168 (defun gnus-summary-pipe-to-muttprint (&optional command)
4169 "Pipe this article to muttprint."
4170 (unless (stringp command)
4171 (setq command (read-string
4172 "Print using command: " gnus-summary-muttprint-program
4173 nil gnus-summary-muttprint-program)))
4174 (let ((gnus-summary-pipe-output-default-command
4175 gnus-summary-pipe-output-default-command))
4176 (gnus-summary-save-in-pipe command))
4177 (setq gnus-summary-muttprint-program command))
4179 ;;; Article file names when saving.
4181 (defun gnus-capitalize-newsgroup (newsgroup)
4182 "Capitalize NEWSGROUP name."
4183 (when (not (zerop (length newsgroup)))
4184 (concat (char-to-string (upcase (aref newsgroup 0)))
4185 (substring newsgroup 1))))
4187 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4188 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4189 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4190 Otherwise, it is like ~/News/news/group/num."
4191 (let ((default
4192 (expand-file-name
4193 (concat (if (gnus-use-long-file-name 'not-save)
4194 (gnus-capitalize-newsgroup newsgroup)
4195 (gnus-newsgroup-directory-form newsgroup))
4196 "/" (int-to-string (mail-header-number headers)))
4197 gnus-article-save-directory)))
4198 (if (and last-file
4199 (string-equal (file-name-directory default)
4200 (file-name-directory last-file))
4201 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4202 default
4203 (or last-file default))))
4205 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4206 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4207 If variable `gnus-use-long-file-name' is non-nil, it is
4208 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4209 (let ((default
4210 (expand-file-name
4211 (concat (if (gnus-use-long-file-name 'not-save)
4212 newsgroup
4213 (gnus-newsgroup-directory-form newsgroup))
4214 "/" (int-to-string (mail-header-number headers)))
4215 gnus-article-save-directory)))
4216 (if (and last-file
4217 (string-equal (file-name-directory default)
4218 (file-name-directory last-file))
4219 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4220 default
4221 (or last-file default))))
4223 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4224 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4225 If variable `gnus-use-long-file-name' is non-nil, it is
4226 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4227 (or last-file
4228 (expand-file-name
4229 (if (gnus-use-long-file-name 'not-save)
4230 newsgroup
4231 (file-relative-name
4232 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4233 default-directory))
4234 gnus-article-save-directory)))
4236 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4237 "Generate file name from sender."
4238 (let ((from (mail-header-from headers)))
4239 (expand-file-name
4240 (if (and from (string-match "\\([^ <]+\\)@" from))
4241 (match-string 1 from)
4242 "nobody")
4243 gnus-article-save-directory)))
4245 (defun article-verify-x-pgp-sig ()
4246 "Verify X-PGP-Sig."
4247 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4248 (interactive)
4249 (if (gnus-buffer-live-p gnus-original-article-buffer)
4250 (let ((sig (with-current-buffer gnus-original-article-buffer
4251 (gnus-fetch-field "X-PGP-Sig")))
4252 items info headers)
4253 (when (and sig
4254 mml2015-use
4255 (mml2015-clear-verify-function))
4256 (with-temp-buffer
4257 (insert-buffer-substring gnus-original-article-buffer)
4258 (setq items (split-string sig))
4259 (message-narrow-to-head)
4260 (let ((inhibit-point-motion-hooks t)
4261 (case-fold-search t))
4262 ;; Don't verify multiple headers.
4263 (setq headers (mapconcat (lambda (header)
4264 (concat header ": "
4265 (mail-fetch-field header)
4266 "\n"))
4267 (split-string (nth 1 items) ",") "")))
4268 (delete-region (point-min) (point-max))
4269 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4270 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4271 (insert headers)
4272 (widen)
4273 (forward-line)
4274 (while (not (eobp))
4275 (if (looking-at "^-")
4276 (insert "- "))
4277 (forward-line))
4278 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4279 (insert "Version: " (car items) "\n\n")
4280 (insert (mapconcat 'identity (cddr items) "\n"))
4281 (insert "\n-----END PGP SIGNATURE-----\n")
4282 (let ((mm-security-handle (list (format "multipart/signed"))))
4283 (mml2015-clean-buffer)
4284 (let ((coding-system-for-write (or gnus-newsgroup-charset
4285 'iso-8859-1)))
4286 (funcall (mml2015-clear-verify-function)))
4287 (setq info
4288 (or (mm-handle-multipart-ctl-parameter
4289 mm-security-handle 'gnus-details)
4290 (mm-handle-multipart-ctl-parameter
4291 mm-security-handle 'gnus-info)))))
4292 (when info
4293 (let ((inhibit-read-only t) bface eface)
4294 (save-restriction
4295 (message-narrow-to-head)
4296 (goto-char (point-max))
4297 (forward-line -1)
4298 (setq bface (get-text-property (point-at-bol) 'face)
4299 eface (get-text-property (1- (point-at-eol)) 'face))
4300 (message-remove-header "X-Gnus-PGP-Verify")
4301 (if (re-search-forward "^X-PGP-Sig:" nil t)
4302 (forward-line)
4303 (goto-char (point-max)))
4304 (narrow-to-region (point) (point))
4305 (insert "X-Gnus-PGP-Verify: " info "\n")
4306 (goto-char (point-min))
4307 (forward-line)
4308 (while (not (eobp))
4309 (if (not (looking-at "^[ \t]"))
4310 (insert " "))
4311 (forward-line))
4312 ;; Do highlighting.
4313 (goto-char (point-min))
4314 (when (looking-at "\\([^:]+\\): *")
4315 (put-text-property (match-beginning 1) (1+ (match-end 1))
4316 'face bface)
4317 (put-text-property (match-end 0) (point-max)
4318 'face eface)))))))))
4320 (defun article-verify-cancel-lock ()
4321 "Verify Cancel-Lock header."
4322 (interactive)
4323 (if (gnus-buffer-live-p gnus-original-article-buffer)
4324 (canlock-verify gnus-original-article-buffer)))
4326 (eval-and-compile
4327 (mapc
4328 (lambda (func)
4329 (let (afunc gfunc)
4330 (if (consp func)
4331 (setq afunc (car func)
4332 gfunc (cdr func))
4333 (setq afunc func
4334 gfunc (intern (format "gnus-%s" func))))
4335 (defalias gfunc
4336 (when (fboundp afunc)
4337 `(lambda (&optional interactive &rest args)
4338 ,(documentation afunc t)
4339 (interactive (list t))
4340 (with-current-buffer gnus-article-buffer
4341 (if interactive
4342 (call-interactively ',afunc)
4343 (apply ',afunc args))))))))
4344 '(article-hide-headers
4345 article-verify-x-pgp-sig
4346 article-verify-cancel-lock
4347 article-hide-boring-headers
4348 article-treat-overstrike
4349 article-treat-ansi-sequences
4350 article-fill-long-lines
4351 article-capitalize-sentences
4352 article-remove-cr
4353 article-remove-leading-whitespace
4354 article-display-x-face
4355 article-display-face
4356 article-de-quoted-unreadable
4357 article-de-base64-unreadable
4358 article-decode-HZ
4359 article-wash-html
4360 article-unsplit-urls
4361 article-hide-list-identifiers
4362 article-strip-banner
4363 article-babel
4364 article-hide-pem
4365 article-hide-signature
4366 article-strip-headers-in-body
4367 article-remove-trailing-blank-lines
4368 article-strip-leading-blank-lines
4369 article-strip-multiple-blank-lines
4370 article-strip-leading-space
4371 article-strip-trailing-space
4372 article-strip-blank-lines
4373 article-strip-all-blank-lines
4374 article-date-local
4375 article-date-english
4376 article-date-iso8601
4377 article-date-original
4378 article-treat-date
4379 article-date-ut
4380 article-decode-mime-words
4381 article-decode-charset
4382 article-decode-encoded-words
4383 article-date-user
4384 article-date-lapsed
4385 article-date-combined-lapsed
4386 article-emphasize
4387 article-treat-dumbquotes
4388 article-treat-non-ascii
4389 article-normalize-headers
4390 ;;(article-show-all . gnus-article-show-all-headers)
4394 ;;; Gnus article mode
4397 (put 'gnus-article-mode 'mode-class 'special)
4399 (set-keymap-parent gnus-article-mode-map widget-keymap)
4401 (gnus-define-keys gnus-article-mode-map
4402 " " gnus-article-goto-next-page
4403 [?\S-\ ] gnus-article-goto-prev-page
4404 "\177" gnus-article-goto-prev-page
4405 [delete] gnus-article-goto-prev-page
4406 "\C-c^" gnus-article-refer-article
4407 "h" gnus-article-show-summary
4408 "s" gnus-article-show-summary
4409 "\C-c\C-m" gnus-article-mail
4410 "?" gnus-article-describe-briefly
4411 "<" beginning-of-buffer
4412 ">" end-of-buffer
4413 "\C-c\C-i" gnus-info-find-node
4414 "\C-c\C-b" gnus-bug
4415 "R" gnus-article-reply-with-original
4416 "F" gnus-article-followup-with-original
4417 "\C-hk" gnus-article-describe-key
4418 "\C-hc" gnus-article-describe-key-briefly
4419 "\C-hb" gnus-article-describe-bindings
4421 "e" gnus-article-read-summary-keys
4422 "\C-d" gnus-article-read-summary-keys
4423 "\M-*" gnus-article-read-summary-keys
4424 "\M-#" gnus-article-read-summary-keys
4425 "\M-^" gnus-article-read-summary-keys
4426 "\M-g" gnus-article-read-summary-keys)
4428 (substitute-key-definition
4429 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4431 (defvar gnus-article-send-map)
4432 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4433 "W" gnus-article-wide-reply-with-original
4434 [t] gnus-article-read-summary-send-keys)
4436 (defun gnus-article-make-menu-bar ()
4437 (unless (boundp 'gnus-article-commands-menu)
4438 (gnus-summary-make-menu-bar))
4439 (unless (boundp 'gnus-article-article-menu)
4440 (easy-menu-define
4441 gnus-article-article-menu gnus-article-mode-map ""
4442 '("Article"
4443 ["Scroll forwards" gnus-article-goto-next-page t]
4444 ["Scroll backwards" gnus-article-goto-prev-page t]
4445 ["Show summary" gnus-article-show-summary t]
4446 ["Fetch Message-ID at point" gnus-article-refer-article t]
4447 ["Mail to address at point" gnus-article-mail t]
4448 ["Send a bug report" gnus-bug t]))
4450 (easy-menu-define
4451 gnus-article-treatment-menu gnus-article-mode-map ""
4452 ;; Fixme: this should use :active (and maybe :visible).
4453 '("Treatment"
4454 ["Hide headers" gnus-article-hide-headers t]
4455 ["Hide signature" gnus-article-hide-signature t]
4456 ["Hide citation" gnus-article-hide-citation t]
4457 ["Treat overstrike" gnus-article-treat-overstrike t]
4458 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4459 ["Remove carriage return" gnus-article-remove-cr t]
4460 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4461 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4462 ["Remove base64" gnus-article-de-base64-unreadable t]
4463 ["Treat html" gnus-article-wash-html t]
4464 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4465 ["Decode HZ" gnus-article-decode-HZ t]))
4467 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4469 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4471 (gnus-run-hooks 'gnus-article-menu-hook)))
4473 (defvar bookmark-make-record-function)
4474 (defvar shr-put-image-function)
4476 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4477 "Major mode for displaying an article.
4479 All normal editing commands are switched off.
4481 The following commands are available in addition to all summary mode
4482 commands:
4483 \\<gnus-article-mode-map>
4484 \\[gnus-article-next-page]\t Scroll the article one page forwards
4485 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4486 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4487 \\[gnus-article-show-summary]\t Display the summary buffer
4488 \\[gnus-article-mail]\t Send a reply to the address near point
4489 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4490 \\[gnus-info-find-node]\t Go to the Gnus info node"
4491 (gnus-simplify-mode-line)
4492 (make-local-variable 'minor-mode-alist)
4493 (when (gnus-visual-p 'article-menu 'menu)
4494 (gnus-article-make-menu-bar)
4495 (when gnus-summary-tool-bar-map
4496 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4497 (gnus-update-format-specifications nil 'article-mode)
4498 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4499 (set (make-local-variable 'gnus-page-broken) nil)
4500 (make-local-variable 'gnus-article-current-summary)
4501 (make-local-variable 'gnus-article-mime-handles)
4502 (make-local-variable 'gnus-article-decoded-p)
4503 (make-local-variable 'gnus-article-mime-handle-alist)
4504 (make-local-variable 'gnus-article-wash-types)
4505 (make-local-variable 'gnus-article-image-alist)
4506 (make-local-variable 'gnus-article-charset)
4507 (make-local-variable 'gnus-article-ignored-charsets)
4508 (set (make-local-variable 'bookmark-make-record-function)
4509 'gnus-summary-bookmark-make-record)
4510 ;; Prevent Emacs from displaying non-break space with
4511 ;; `nobreak-space' face.
4512 (set (make-local-variable 'nobreak-char-display) nil)
4513 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4514 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4515 (unless gnus-article-show-cursor
4516 (setq cursor-in-non-selected-windows nil))
4517 (gnus-set-default-directory)
4518 (buffer-disable-undo)
4519 (setq buffer-read-only t
4520 show-trailing-whitespace nil)
4521 (mm-enable-multibyte))
4523 (defun gnus-article-setup-buffer ()
4524 "Initialize the article buffer."
4525 (let* ((name (if gnus-single-article-buffer "*Article*"
4526 (concat "*Article "
4527 (gnus-group-decoded-name gnus-newsgroup-name)
4528 "*")))
4529 (original
4530 (progn (string-match "\\*Article" name)
4531 (concat " *Original Article"
4532 (substring name (match-end 0))))))
4533 (setq gnus-article-buffer name)
4534 (setq gnus-original-article-buffer original)
4535 (setq gnus-article-mime-handle-alist nil)
4536 (with-current-buffer gnus-summary-buffer
4537 ;; This might be a variable local to the summary buffer.
4538 (unless gnus-single-article-buffer
4539 (setq gnus-article-buffer name)
4540 (setq gnus-original-article-buffer original)
4541 (gnus-set-global-variables)))
4542 (gnus-article-setup-highlight-words)
4543 ;; Init original article buffer.
4544 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4545 (mm-enable-multibyte)
4546 (setq major-mode 'gnus-original-article-mode)
4547 (make-local-variable 'gnus-original-article))
4548 (if (and (get-buffer name)
4549 (with-current-buffer name
4550 (if gnus-article-edit-mode
4551 (if (y-or-n-p "Article mode edit in progress; discard? ")
4552 (progn
4553 (set-buffer-modified-p nil)
4554 (gnus-kill-buffer name)
4555 (message "")
4556 nil)
4557 (error "Action aborted"))
4558 t)))
4559 (let ((summary gnus-summary-buffer))
4560 (with-current-buffer name
4561 (set (make-local-variable 'gnus-article-edit-mode) nil)
4562 (gnus-article-stop-animations)
4563 (when gnus-article-mime-handles
4564 (mm-destroy-parts gnus-article-mime-handles)
4565 (setq gnus-article-mime-handles nil))
4566 ;; Set it to nil in article-buffer!
4567 (setq gnus-article-mime-handle-alist nil)
4568 (buffer-disable-undo)
4569 (setq buffer-read-only t)
4570 (unless (derived-mode-p 'gnus-article-mode)
4571 (gnus-article-mode))
4572 (set (make-local-variable 'gnus-summary-buffer) summary)
4573 (setq truncate-lines gnus-article-truncate-lines)
4574 (current-buffer)))
4575 (let ((summary gnus-summary-buffer))
4576 (with-current-buffer (gnus-get-buffer-create name)
4577 (gnus-article-mode)
4578 (setq truncate-lines gnus-article-truncate-lines)
4579 (set (make-local-variable 'gnus-summary-buffer) summary)
4580 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4581 (when article-lapsed-timer
4582 (gnus-stop-date-timer))
4583 (when gnus-article-update-date-headers
4584 (gnus-start-date-timer gnus-article-update-date-headers))
4585 (current-buffer))))))
4587 (defun gnus-article-stop-animations ()
4588 (dolist (timer (and (boundp 'timer-list)
4589 timer-list))
4590 (when (eq (timer--function timer) 'image-animate-timeout)
4591 (cancel-timer timer))))
4593 (defun gnus-stop-downloads ()
4594 (when (boundp 'url-queue)
4595 (set (intern "url-queue" obarray) nil)))
4597 ;; Set article window start at LINE, where LINE is the number of lines
4598 ;; from the head of the article.
4599 (defun gnus-article-set-window-start (&optional line)
4600 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4601 (when article-window
4602 (set-window-start
4603 article-window
4604 (with-current-buffer gnus-article-buffer
4605 (goto-char (point-min))
4606 (if (not line)
4607 (point-min)
4608 (gnus-message 6 "Moved to bookmark")
4609 (search-forward "\n\n" nil t)
4610 (forward-line line)
4611 (point)))))))
4613 (defvar gnus-tmp-internal-hook)
4615 (defun gnus-article-prepare (article &optional all-headers _header)
4616 "Prepare ARTICLE in article mode buffer.
4617 ARTICLE should either be an article number or a Message-ID.
4618 If ARTICLE is an id, HEADER should be the article headers.
4619 If ALL-HEADERS is non-nil, no headers are hidden."
4620 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4621 ;; Make sure we start in a summary buffer.
4622 (unless (derived-mode-p 'gnus-summary-mode)
4623 (set-buffer gnus-summary-buffer))
4624 (setq gnus-summary-buffer (current-buffer))
4625 (let* ((summary-buffer (current-buffer))
4626 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4627 (group gnus-newsgroup-name)
4628 result)
4629 (save-excursion
4630 (gnus-article-setup-buffer)
4631 (set-buffer gnus-article-buffer)
4632 ;; Deactivate active regions.
4633 (when transient-mark-mode
4634 (setq mark-active nil))
4635 (if (not (setq result (let ((inhibit-read-only t))
4636 (gnus-request-article-this-buffer
4637 article group))))
4638 ;; There is no such article.
4639 (save-excursion
4640 (when (and (numberp article)
4641 (not (memq article gnus-newsgroup-sparse)))
4642 (setq gnus-article-current
4643 (cons gnus-newsgroup-name article))
4644 (set-buffer gnus-summary-buffer)
4645 (setq gnus-current-article article)
4646 (if (and (memq article gnus-newsgroup-undownloaded)
4647 (not (gnus-online (gnus-find-method-for-group
4648 gnus-newsgroup-name))))
4649 (progn
4650 (gnus-summary-set-agent-mark article)
4651 (message "Message marked for downloading"))
4652 (gnus-summary-mark-article article gnus-canceled-mark)
4653 (unless (memq article gnus-newsgroup-sparse)
4654 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4655 (if (or (eq result 'pseudo)
4656 (eq result 'nneething))
4657 (progn
4658 (with-current-buffer summary-buffer
4659 (push article gnus-newsgroup-history)
4660 (setq gnus-last-article gnus-current-article
4661 gnus-current-article 0
4662 gnus-current-headers nil
4663 gnus-article-current nil)
4664 (if (eq result 'nneething)
4665 (gnus-configure-windows 'summary)
4666 (gnus-configure-windows 'article))
4667 (gnus-set-global-variables))
4668 (let ((gnus-article-mime-handle-alist-1
4669 gnus-article-mime-handle-alist))
4670 (gnus-set-mode-line 'article)))
4671 ;; The result from the `request' was an actual article -
4672 ;; or at least some text that is now displayed in the
4673 ;; article buffer.
4674 (when (and (numberp article)
4675 (not (eq article gnus-current-article)))
4676 ;; Seems like a new article has been selected.
4677 ;; `gnus-current-article' must be an article number.
4678 (with-current-buffer summary-buffer
4679 (push article gnus-newsgroup-history)
4680 (setq gnus-last-article gnus-current-article
4681 gnus-current-article article
4682 gnus-current-headers
4683 (gnus-summary-article-header gnus-current-article)
4684 gnus-article-current
4685 (cons gnus-newsgroup-name gnus-current-article))
4686 (unless (vectorp gnus-current-headers)
4687 (setq gnus-current-headers nil))
4688 (gnus-summary-goto-subject gnus-current-article)
4689 (when (gnus-summary-show-thread)
4690 ;; If the summary buffer really was folded, the
4691 ;; previous goto may not actually have gone to
4692 ;; the right article, but the thread root instead.
4693 ;; So we go again.
4694 (gnus-summary-goto-subject gnus-current-article))
4695 (gnus-run-hooks 'gnus-mark-article-hook)
4696 (gnus-set-mode-line 'summary)
4697 (when (gnus-visual-p 'article-highlight 'highlight)
4698 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4699 ;; Set the global newsgroup variables here.
4700 (gnus-set-global-variables)
4701 (setq gnus-have-all-headers
4702 (or all-headers gnus-show-all-headers))))
4703 (save-excursion
4704 (gnus-configure-windows 'article))
4705 (when (or (numberp article)
4706 (stringp article))
4707 (gnus-article-prepare-display)
4708 ;; Do page break.
4709 (goto-char (point-min))
4710 (when gnus-break-pages
4711 (gnus-narrow-to-page)))
4712 (let ((gnus-article-mime-handle-alist-1
4713 gnus-article-mime-handle-alist))
4714 (gnus-set-mode-line 'article))
4715 (article-goto-body)
4716 (unless (bobp)
4717 (forward-line -1))
4718 (set-window-point (get-buffer-window (current-buffer)) (point))
4719 (gnus-configure-windows 'article)
4720 (gnus-run-hooks 'gnus-article-prepare-hook)
4721 t))))))
4723 (defvar gnus-mime-display-attachment-buttons-in-header)
4725 ;;;###autoload
4726 (defun gnus-article-prepare-display ()
4727 "Make the current buffer look like a nice article."
4728 ;; Hooks for getting information from the article.
4729 ;; This hook must be called before being narrowed.
4730 (let ((gnus-article-buffer (current-buffer))
4731 buffer-read-only
4732 (inhibit-read-only t))
4733 (unless (derived-mode-p 'gnus-article-mode)
4734 (gnus-article-mode))
4735 (setq buffer-read-only nil
4736 gnus-article-wash-types nil
4737 gnus-article-image-alist nil)
4738 (gnus-run-hooks 'gnus-tmp-internal-hook)
4739 (when gnus-display-mime-function
4740 (funcall gnus-display-mime-function))
4741 ;; Add attachment buttons to the header.
4742 (when gnus-mime-display-attachment-buttons-in-header
4743 (gnus-mime-buttonize-attachments-in-header))))
4746 ;;; Gnus Sticky Article Mode
4749 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4750 "Mode for sticky articles."
4751 ;; Release bindings that won't work.
4752 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4753 gnus-sticky-article-mode-map)
4754 (substitute-key-definition 'gnus-article-refer-article 'undefined
4755 gnus-sticky-article-mode-map)
4756 (dolist (k '("e" "h" "s" "F" "R"))
4757 (define-key gnus-sticky-article-mode-map k nil))
4758 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4759 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4760 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4761 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4763 (defun gnus-sticky-article (arg)
4764 "Make the current article sticky.
4765 If a prefix ARG is given, ask for a name for this sticky article buffer."
4766 (interactive "P")
4767 (gnus-summary-show-thread)
4768 (gnus-summary-select-article nil nil 'pseudo)
4769 (let (new-art-buf-name)
4770 (gnus-eval-in-buffer-window gnus-article-buffer
4771 (setq new-art-buf-name
4772 (concat
4773 "*Sticky Article: "
4774 (if arg
4775 (read-from-minibuffer "Sticky article buffer name: ")
4776 (gnus-with-article-headers
4777 (gnus-article-goto-header "subject")
4778 (setq new-art-buf-name
4779 (buffer-substring-no-properties
4780 (line-beginning-position) (line-end-position)))
4781 (goto-char (point-min))
4782 (gnus-article-goto-header "from")
4783 (setq new-art-buf-name
4784 (concat
4785 new-art-buf-name ", "
4786 (buffer-substring-no-properties
4787 (line-beginning-position) (line-end-position))))
4788 (goto-char (point-min))
4789 (gnus-article-goto-header "date")
4790 (setq new-art-buf-name
4791 (concat
4792 new-art-buf-name ", "
4793 (buffer-substring-no-properties
4794 (line-beginning-position) (line-end-position))))))
4795 "*"))
4796 (if (and (gnus-buffer-live-p new-art-buf-name)
4797 (with-current-buffer new-art-buf-name
4798 (derived-mode-p 'gnus-sticky-article-mode)))
4799 (switch-to-buffer new-art-buf-name)
4800 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4801 (gnus-sticky-article-mode))
4802 (setq gnus-article-buffer new-art-buf-name))
4803 (gnus-summary-recenter)
4804 (gnus-summary-position-point))
4806 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4807 "Kill the given sticky article BUFFER.
4808 If none is given, assume the current buffer and kill it if it has
4809 `gnus-sticky-article-mode'."
4810 (interactive)
4811 (unless buffer
4812 (setq buffer (current-buffer)))
4813 (with-current-buffer buffer
4814 (when (derived-mode-p 'gnus-sticky-article-mode)
4815 (gnus-kill-buffer buffer))))
4817 (defun gnus-kill-sticky-article-buffers (arg)
4818 "Kill all sticky article buffers.
4819 If a prefix ARG is given, ask for confirmation."
4820 (interactive "P")
4821 (dolist (buf (gnus-buffers))
4822 (with-current-buffer buf
4823 (when (derived-mode-p 'gnus-sticky-article-mode)
4824 (if (not arg)
4825 (gnus-kill-buffer buf)
4826 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4827 (gnus-kill-buffer buf)))))))
4830 ;;; Gnus MIME viewing functions
4833 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4834 "Format of the MIME buttons.
4836 Valid specifiers include:
4837 %t The MIME type
4838 %T MIME type, along with additional info
4839 %n The `name' parameter
4840 %d The description, if any
4841 %l The length of the encoded part
4842 %p The part identifier number
4843 %e Dots if the part isn't displayed
4845 General format specifiers can also be used. See Info node
4846 `(gnus)Formatting Variables'.")
4848 (defvar gnus-tmp-type)
4849 (defvar gnus-tmp-type-long)
4850 (defvar gnus-tmp-name)
4851 (defvar gnus-tmp-description)
4852 (defvar gnus-tmp-id)
4853 (defvar gnus-tmp-length)
4854 (defvar gnus-tmp-dots)
4855 (defvar gnus-tmp-info)
4856 (defvar gnus-tmp-pressed-details)
4858 (defvar gnus-mime-button-line-format-alist
4859 '((?t gnus-tmp-type ?s)
4860 (?T gnus-tmp-type-long ?s)
4861 (?n gnus-tmp-name ?s)
4862 (?d gnus-tmp-description ?s)
4863 (?p gnus-tmp-id ?s)
4864 (?l gnus-tmp-length ?d)
4865 (?e gnus-tmp-dots ?s)))
4867 (defvar gnus-mime-button-commands
4868 '((gnus-article-press-button "\r" "Toggle Display")
4869 (gnus-mime-view-part "v" "View Interactively...")
4870 (gnus-mime-view-part-as-type "t" "View As Type...")
4871 (gnus-mime-view-part-as-charset "C" "View As charset...")
4872 (gnus-mime-save-part "o" "Save...")
4873 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4874 (gnus-mime-replace-part "r" "Replace part")
4875 (gnus-mime-delete-part "d" "Delete part")
4876 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4877 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4878 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4879 (gnus-mime-view-part-externally "e" "View Externally")
4880 (gnus-mime-print-part "p" "Print")
4881 (gnus-mime-pipe-part "|" "Pipe To Command...")
4882 (gnus-mime-action-on-part "." "Take action on the part...")))
4884 (defun gnus-article-mime-part-status ()
4885 (if gnus-article-mime-handle-alist-1
4886 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4887 " (1 part)"
4888 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4889 ""))
4891 (defvar gnus-mime-button-map
4892 (let ((map (make-sparse-keymap)))
4893 (define-key map [mouse-2] 'gnus-article-push-button)
4894 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4895 (dolist (c gnus-mime-button-commands)
4896 (define-key map (cadr c) (car c)))
4897 map))
4899 (easy-menu-define
4900 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4901 `("MIME Part"
4902 ,@(mapcar (lambda (c)
4903 (vector (caddr c) (car c) :active t))
4904 gnus-mime-button-commands)))
4906 (defvar gnus-url-button-commands
4907 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4909 (defvar gnus-url-button-map
4910 (let ((map (make-sparse-keymap)))
4911 (dolist (c gnus-url-button-commands)
4912 (define-key map (cadr c) (car c)))
4913 map))
4915 (easy-menu-define
4916 gnus-url-button-menu gnus-url-button-map "URL button menu."
4917 `("Url Button"
4918 ,@(mapcar (lambda (c)
4919 (vector (caddr c) (car c) :active t))
4920 gnus-url-button-commands)))
4922 (defmacro gnus-bind-mm-vars (&rest body)
4923 "Bind some mm-* variables and execute BODY."
4924 `(let (mm-html-inhibit-images
4925 mm-html-blocked-images
4926 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4927 (with-current-buffer
4928 (cond ((derived-mode-p 'gnus-article-mode)
4929 (if (gnus-buffer-live-p gnus-article-current-summary)
4930 gnus-article-current-summary
4931 ;; Maybe we're in a mml-preview buffer
4932 ;; and no group is selected.
4933 (current-buffer)))
4934 ((gnus-buffer-live-p gnus-summary-buffer)
4935 gnus-summary-buffer)
4936 (t (current-buffer)))
4937 (setq mm-html-inhibit-images gnus-inhibit-images
4938 mm-html-blocked-images (gnus-blocked-images))
4939 (when (or (not gnus-newsgroup-name)
4940 (and (stringp gnus-safe-html-newsgroups)
4941 (string-match gnus-safe-html-newsgroups
4942 gnus-newsgroup-name))
4943 (and (consp gnus-safe-html-newsgroups)
4944 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4945 (setq mm-w3m-safe-url-regexp nil)))
4946 ,@body))
4948 (defun gnus-mime-button-menu (event prefix)
4949 "Construct a context-sensitive menu of MIME commands."
4950 (interactive "e\nP")
4951 (save-window-excursion
4952 (let ((pos (event-start event)))
4953 (select-window (posn-window pos))
4954 (goto-char (posn-point pos))
4955 (gnus-article-check-buffer)
4956 (popup-menu gnus-mime-button-menu nil prefix))))
4958 (defun gnus-mime-view-all-parts (&optional handles)
4959 "View all the MIME parts."
4960 (interactive)
4961 (with-current-buffer gnus-article-buffer
4962 (let ((handles (or handles gnus-article-mime-handles))
4963 (mail-parse-charset gnus-newsgroup-charset)
4964 (mail-parse-ignored-charsets
4965 (with-current-buffer gnus-summary-buffer
4966 gnus-newsgroup-ignored-charsets)))
4967 (when handles
4968 (mm-remove-parts handles)
4969 (goto-char (point-min))
4970 (or (search-forward "\n\n") (goto-char (point-max)))
4971 (let ((inhibit-read-only t))
4972 (delete-region (point) (point-max))
4973 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4975 (defun gnus-article-jump-to-part (n)
4976 "Jump to MIME part N."
4977 (interactive "P")
4978 (let ((parts (with-current-buffer gnus-article-buffer
4979 (length gnus-article-mime-handle-alist))))
4980 (when (zerop parts)
4981 (error "No such part"))
4982 (pop-to-buffer gnus-article-buffer)
4983 (or n
4984 (setq n (if (= parts 1)
4986 (read-number (format "Jump to part (1..%s): " parts)))))
4987 (unless (and (integerp n) (<= n parts) (>= n 1))
4988 (setq n
4989 (progn
4990 (gnus-message 7 "Invalid part `%s', using %s instead."
4991 n parts)
4992 parts)))
4993 (gnus-message 9 "Jumping to part %s." n)
4994 (cond ((>= gnus-auto-select-part 1)
4995 (while (and (<= n parts)
4996 (not (gnus-article-goto-part n)))
4997 (setq n (1+ n))))
4998 ((< gnus-auto-select-part 0)
4999 (while (and (>= n 1)
5000 (not (gnus-article-goto-part n)))
5001 (setq n (1- n))))
5003 (gnus-article-goto-part n)))))
5005 (defvar gnus-mime-buttonized-part-id nil
5006 "ID of a mime part that should be buttonized.
5007 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5009 (eval-when-compile
5010 (defsubst gnus-article-edit-part (handles &optional current-id)
5011 "Edit an article in order to delete a mime part.
5012 This function is exclusively used by `gnus-mime-save-part-and-strip'
5013 and `gnus-mime-delete-part', and not provided at run-time normally."
5014 (gnus-article-edit-article
5015 `(lambda ()
5016 (buffer-disable-undo)
5017 (let ((mail-parse-charset (or gnus-article-charset
5018 ',gnus-newsgroup-charset))
5019 (mail-parse-ignored-charsets
5020 (or gnus-article-ignored-charsets
5021 ',gnus-newsgroup-ignored-charsets))
5022 (mbl mml-buffer-list))
5023 (setq mml-buffer-list nil)
5024 ;; A new text must be inserted before deleting existing ones
5025 ;; at the end so as not to move existing markers of which
5026 ;; the insertion type is t.
5027 (delete-region
5028 (point-min)
5029 (prog1
5030 (goto-char (point-max))
5031 (insert-buffer-substring gnus-original-article-buffer)))
5032 (mime-to-mml ',handles)
5033 (setq gnus-article-mime-handles nil)
5034 (let ((mbl1 mml-buffer-list))
5035 (setq mml-buffer-list mbl)
5036 (set (make-local-variable 'mml-buffer-list) mbl1))
5037 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5038 `(lambda (no-highlight)
5039 (let ((mail-parse-charset (or gnus-article-charset
5040 ',gnus-newsgroup-charset))
5041 (message-options message-options)
5042 (message-options-set-recipient)
5043 (mail-parse-ignored-charsets
5044 (or gnus-article-ignored-charsets
5045 ',gnus-newsgroup-ignored-charsets)))
5046 (mml-to-mime)
5047 (mml-destroy-buffers)
5048 (remove-hook 'kill-buffer-hook
5049 'mml-destroy-buffers t)
5050 (kill-local-variable 'mml-buffer-list))
5051 (gnus-summary-edit-article-done
5052 ,(or (mail-header-references gnus-current-headers) "")
5053 ,(gnus-group-read-only-p)
5054 ,gnus-summary-buffer no-highlight))
5056 ;; Force buttonizing this part.
5057 (let ((gnus-mime-buttonized-part-id current-id))
5058 (gnus-article-edit-done))
5059 (gnus-configure-windows 'article)
5060 (sit-for 0)
5061 (let ((handles (with-current-buffer gnus-article-buffer
5062 gnus-article-mime-handle-alist)))
5063 ;; `handles' will be nil if there is the only one part
5064 ;; in the article and is deleted.
5065 (when (and handles current-id (integerp gnus-auto-select-part))
5066 (gnus-article-jump-to-part
5067 (min (max (+ current-id gnus-auto-select-part) 1)
5068 (length handles)))))))
5070 (defun gnus-mime-replace-part (file)
5071 "Replace MIME part under point with an external body."
5072 ;; Useful if file has already been saved to disk
5073 (interactive
5074 (list
5075 (read-file-name "Replace MIME part with file: "
5076 (or mm-default-directory default-directory)
5077 nil nil)))
5078 (gnus-mime-save-part-and-strip file))
5080 (defun gnus-mime-save-part-and-strip (&optional file)
5081 "Save the MIME part under point then replace it with an external body.
5082 If FILE is given, use it for the external part."
5083 (interactive)
5084 (gnus-article-check-buffer)
5085 (when (gnus-group-read-only-p)
5086 (error "The current group does not support deleting of parts"))
5087 (when (mm-complicated-handles gnus-article-mime-handles)
5088 (error "\
5089 The current article has a complicated MIME structure, giving up..."))
5090 (let* ((data (get-text-property (point) 'gnus-data))
5091 (id (get-text-property (point) 'gnus-part))
5092 (handles gnus-article-mime-handles))
5093 (unless file
5094 (setq file
5095 (and data (mm-save-part data "Delete MIME part and save to: "))))
5096 (when file
5097 (with-current-buffer (mm-handle-buffer data)
5098 (erase-buffer)
5099 (insert "Content-Type: " (mm-handle-media-type data))
5100 (mml-insert-parameter-string (cdr (mm-handle-type data))
5101 '(charset))
5102 ;; Add a filename for the sake of saving the part again.
5103 (mml-insert-parameter
5104 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5105 (insert "\n")
5106 (insert "Content-ID: " (message-make-message-id) "\n")
5107 (insert "Content-Transfer-Encoding: binary\n")
5108 (insert "\n"))
5109 (setcdr data
5110 (cdr (mm-make-handle nil
5111 `("message/external-body"
5112 (access-type . "LOCAL-FILE")
5113 (name . ,file)))))
5114 ;; (set-buffer gnus-summary-buffer)
5115 (gnus-article-edit-part handles id))))
5117 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5118 ;; parts...>') but with stripping would be nice.
5120 (defun gnus-mime-delete-part ()
5121 "Delete the MIME part under point.
5122 Replace it with some information about the removed part."
5123 (interactive)
5124 (gnus-article-check-buffer)
5125 (when (gnus-group-read-only-p)
5126 (error "The current group does not support deleting of parts"))
5127 (when (mm-complicated-handles gnus-article-mime-handles)
5128 (error "\
5129 The current article has a complicated MIME structure, giving up..."))
5130 (when (or gnus-expert-user
5131 (gnus-yes-or-no-p "\
5132 Deleting parts may malfunction or destroy the article; continue? "))
5133 (let* ((data (get-text-property (point) 'gnus-data))
5134 (id (get-text-property (point) 'gnus-part))
5135 (handles gnus-article-mime-handles)
5136 (description
5137 (let ((desc (mm-handle-description data)))
5138 (when desc
5139 (mail-decode-encoded-word-string desc))))
5140 (filename (or (mm-handle-filename data) "(none)"))
5141 (type (mm-handle-media-type data)))
5142 (unless data
5143 (error "No MIME part under point"))
5144 (with-current-buffer (mm-handle-buffer data)
5145 (let ((bsize (buffer-size)))
5146 (erase-buffer)
5147 (insert
5148 (concat
5149 ",----\n"
5150 "| The following attachment has been deleted:\n"
5151 "|\n"
5152 "| Type: " type "\n"
5153 "| Filename: " filename "\n"
5154 "| Size (encoded): " (format "%s byte%s\n"
5155 bsize (if (= bsize 1)
5157 "s"))
5158 (when description
5159 (concat "| Description: " description "\n"))
5160 "`----\n"))
5161 (setcdr data
5162 (cdr (mm-make-handle
5163 nil `("text/plain" (charset . gnus-decoded)) nil nil
5164 (list "attachment")
5165 (format "Deleted attachment (%s bytes)" bsize))))))
5166 ;; (set-buffer gnus-summary-buffer)
5167 (gnus-article-edit-part handles id))))
5169 (defun gnus-mime-save-part ()
5170 "Save the MIME part under point."
5171 (interactive)
5172 (gnus-article-check-buffer)
5173 (let ((data (get-text-property (point) 'gnus-data)))
5174 (when data
5175 (mm-save-part data))))
5177 (defun gnus-mime-pipe-part (&optional cmd)
5178 "Pipe the MIME part under point to a process.
5179 Use CMD as the process."
5180 (interactive)
5181 (gnus-article-check-buffer)
5182 (let ((data (get-text-property (point) 'gnus-data)))
5183 (when data
5184 (mm-pipe-part data cmd))))
5186 (defun gnus-mime-view-part ()
5187 "Interactively choose a viewing method for the MIME part under point."
5188 (interactive)
5189 (gnus-article-check-buffer)
5190 (let ((data (get-text-property (point) 'gnus-data)))
5191 (when data
5192 (setq gnus-article-mime-handles
5193 (mm-merge-handles
5194 gnus-article-mime-handles (setq data (copy-sequence data))))
5195 (mm-interactively-view-part data))))
5197 (defun gnus-mime-view-part-as-type-internal ()
5198 (gnus-article-check-buffer)
5199 (let* ((handle (get-text-property (point) 'gnus-data))
5200 (name (or
5201 ;; Content-Type: foo/bar; name=...
5202 (mail-content-type-get (mm-handle-type handle) 'name)
5203 ;; Content-Disposition: attachment; filename=...
5204 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5205 (def-type (and name (mm-default-file-encoding name))))
5206 (or (and def-type (cons def-type 0))
5207 (and handle
5208 (equal (mm-handle-media-supertype handle) "text")
5209 '("text/plain" . 0))
5210 '("application/octet-stream" . 0))))
5212 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5213 "Choose a MIME media type, and view the part as such.
5214 If non-nil, PRED is a predicate to use during completion to limit the
5215 available media-types."
5216 (interactive)
5217 (unless mime-type
5218 (setq mime-type
5219 (let ((default (gnus-mime-view-part-as-type-internal)))
5220 (gnus-completing-read
5221 "View as MIME type"
5222 (if pred
5223 (gnus-remove-if-not pred (mailcap-mime-types))
5224 (mailcap-mime-types))
5225 nil nil nil
5226 (car default)))))
5227 (gnus-article-check-buffer)
5228 (let ((handle (get-text-property (point) 'gnus-data)))
5229 (when handle
5230 (when (equal (mm-handle-media-type handle) "message/external-body")
5231 (unless (mm-handle-cache handle)
5232 (mm-extern-cache-contents handle))
5233 (setq handle (mm-handle-cache handle)))
5234 (setq handle
5235 (mm-make-handle (mm-handle-buffer handle)
5236 (cons mime-type (cdr (mm-handle-type handle)))
5237 (mm-handle-encoding handle)
5238 (mm-handle-undisplayer handle)
5239 (mm-handle-disposition handle)
5240 (mm-handle-description handle)
5242 (mm-handle-id handle)))
5243 (setq gnus-article-mime-handles
5244 (mm-merge-handles gnus-article-mime-handles handle))
5245 (when (mm-handle-displayed-p handle)
5246 (mm-remove-part handle))
5247 (gnus-mm-display-part handle))))
5249 (defun gnus-mime-copy-part (&optional handle arg)
5250 "Put the MIME part under point into a new buffer.
5251 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5252 are decompressed."
5253 (interactive (list nil current-prefix-arg))
5254 (gnus-article-check-buffer)
5255 (unless handle
5256 (setq handle (get-text-property (point) 'gnus-data)))
5257 (when handle
5258 (let ((filename (mm-handle-filename handle))
5259 contents dont-decode charset coding-system)
5260 (mm-with-unibyte-buffer
5261 (mm-insert-part handle)
5262 (setq contents (or (condition-case nil
5263 (mm-decompress-buffer filename nil 'sig)
5264 (error
5265 (setq dont-decode t)
5266 nil))
5267 (buffer-string))))
5268 (setq filename (cond (filename (file-name-nondirectory filename))
5269 (dont-decode "*raw data*")
5270 (t "*decoded*")))
5271 (cond
5272 (dont-decode)
5273 ((not arg)
5274 (unless (setq charset (mail-content-type-get
5275 (mm-handle-type handle) 'charset))
5276 (unless (setq coding-system (mm-with-unibyte-buffer
5277 (insert contents)
5278 (mm-find-buffer-file-coding-system)))
5279 (setq charset gnus-newsgroup-charset))))
5280 ((numberp arg)
5281 (setq charset (or (cdr (assq arg
5282 gnus-summary-show-article-charset-alist))
5283 (read-coding-system "Charset: ")))))
5284 (switch-to-buffer (generate-new-buffer filename))
5285 (if (or coding-system
5286 (and charset
5287 (setq coding-system (mm-charset-to-coding-system
5288 charset nil t))
5289 (not (eq coding-system 'ascii))))
5290 (progn
5291 (mm-enable-multibyte)
5292 (insert (decode-coding-string contents coding-system))
5293 (setq buffer-file-coding-system last-coding-system-used))
5294 (mm-disable-multibyte)
5295 (insert contents)
5296 (setq buffer-file-coding-system mm-binary-coding-system))
5297 ;; We do it this way to make `normal-mode' set the appropriate mode.
5298 (unwind-protect
5299 (progn
5300 (setq buffer-file-name (expand-file-name filename))
5301 (normal-mode))
5302 (setq buffer-file-name nil))
5303 (goto-char (point-min)))))
5305 (defun gnus-mime-print-part (&optional handle filename)
5306 "Print the MIME part under point."
5307 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5308 (gnus-article-check-buffer)
5309 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5310 (contents (and handle (mm-get-part handle)))
5311 (file (make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5312 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5313 (when contents
5314 (if printer
5315 (unwind-protect
5316 (progn
5317 (mm-save-part-to-file handle file)
5318 (call-process shell-file-name nil
5319 (generate-new-buffer " *mm*")
5321 shell-command-switch
5322 (mm-mailcap-command
5323 printer file (mm-handle-type handle))))
5324 (delete-file file))
5325 (with-temp-buffer
5326 (insert contents)
5327 (gnus-print-buffer))
5328 (ps-despool filename)))))
5330 (defun gnus-mime-inline-part (&optional handle arg)
5331 "Insert the MIME part under point into the current buffer.
5332 Compressed files like .gz and .bz2 are decompressed."
5333 (interactive (list nil current-prefix-arg))
5334 (gnus-article-check-buffer)
5335 (let* ((inhibit-read-only t)
5336 (b (point))
5337 (btn ;; position where the MIME button exists
5338 (if handle
5339 (if (eq handle (get-text-property b 'gnus-data))
5341 (article-goto-body)
5342 (or (text-property-any (point) (point-max) 'gnus-data handle)
5343 (text-property-any (point-min) (point) 'gnus-data handle)))
5344 (setq handle (get-text-property b 'gnus-data))
5346 start)
5347 (when handle
5348 (when (= b (prog1
5350 (setq start (next-single-property-change btn 'gnus-data
5351 nil (point-max))
5352 btn (previous-single-property-change start
5353 'gnus-data))))
5354 (setq b btn))
5355 (if (and (not arg) (mm-handle-undisplayer handle))
5356 (progn
5357 (setq b (copy-marker b)
5358 btn (copy-marker btn))
5359 (mm-remove-part handle))
5360 (cond
5361 ((not arg) nil)
5362 ((numberp arg)
5363 (if (mm-handle-undisplayer handle)
5364 (mm-remove-part handle)))
5365 ((mm-handle-undisplayer handle)
5366 (mm-remove-part handle)))
5367 (goto-char start)
5368 (unless (bolp)
5369 ;; This is a header button.
5370 (forward-line 1))
5371 (mm-display-inline handle))
5372 ;; Toggle the button appearance between `[button]...' and `[button]'.
5373 (when (markerp btn)
5374 (setq btn (prog1 (marker-position btn)
5375 (set-marker btn nil))))
5376 (goto-char btn)
5377 (let ((displayed-p (mm-handle-displayed-p handle)))
5378 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5379 (list displayed-p))
5380 (delete-region
5381 (point)
5382 (next-single-property-change (point) 'gnus-data nil (point-max)))
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 (overlays-in btn (point)))
5394 (overlay-put ovl 'gnus-button-attachment-extra t)
5395 (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 (when (markerp b)
5403 (setq b (prog1 (marker-position b)
5404 (set-marker b nil))))
5405 (goto-char b))))
5407 (defun gnus-mime-set-charset-parameters (handle charset)
5408 "Set CHARSET to parameters in HANDLE.
5409 CHARSET may either be a string or a symbol."
5410 (unless (stringp charset)
5411 (setq charset (symbol-name charset)))
5412 (if (stringp (car handle))
5413 (dolist (h (cdr handle))
5414 (gnus-mime-set-charset-parameters h charset))
5415 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5416 "message/external-body")
5417 (progn
5418 (unless (mm-handle-cache handle)
5419 (mm-extern-cache-contents handle))
5420 (mm-handle-cache handle))
5421 handle)))
5422 (param (assq 'charset (cdr type))))
5423 (if param
5424 (setcdr param charset)
5425 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5427 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5428 "Insert the MIME part under point into the current buffer using the
5429 specified charset."
5430 (interactive (list nil current-prefix-arg))
5431 (gnus-article-check-buffer)
5432 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5433 (fun (get-text-property (point) 'gnus-callback))
5434 (gnus-newsgroup-ignored-charsets 'gnus-all)
5435 charset form preferred parts)
5436 (when handle
5437 (when (prog1
5438 (and fun
5439 (setq charset
5440 (or (cdr (assq
5442 gnus-summary-show-article-charset-alist))
5443 (read-coding-system "Charset: "))))
5444 (if (mm-handle-undisplayer handle)
5445 (mm-remove-part handle)))
5446 (gnus-mime-set-charset-parameters handle charset)
5447 (when (and (consp (setq form (cdr-safe fun)))
5448 (setq form (ignore-errors
5449 (assq 'gnus-mime-display-alternative form)))
5450 (setq preferred (caddr form))
5451 (progn
5452 (when (eq (car preferred) 'quote)
5453 (setq preferred (cadr preferred)))
5454 (not (equal preferred
5455 (get-text-property (point) 'gnus-data))))
5456 (setq parts (get-text-property (point) 'gnus-part))
5457 (setq parts (cdr (assq parts
5458 gnus-article-mime-handle-alist)))
5459 (equal (mm-handle-media-type parts) "multipart/alternative")
5460 (setq parts (reverse (cdr parts))))
5461 (setcar (cddr form)
5462 (list 'quote (or (cadr (member preferred parts))
5463 (car parts)))))
5464 (funcall fun handle)))))
5466 (defun gnus-mime-view-part-externally (&optional handle)
5467 "View the MIME part under point with an external viewer."
5468 (interactive)
5469 (gnus-article-check-buffer)
5470 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5471 (mm-inlined-types nil)
5472 (mail-parse-charset gnus-newsgroup-charset)
5473 (mail-parse-ignored-charsets
5474 (with-current-buffer gnus-summary-buffer
5475 gnus-newsgroup-ignored-charsets))
5476 (type (mm-handle-media-type handle))
5477 (method (mailcap-mime-info type))
5478 (mm-enable-external t))
5479 (if (not (stringp method))
5480 (gnus-mime-view-part-as-type
5481 nil (lambda (type) (stringp (mailcap-mime-info type))))
5482 (when handle
5483 (mm-display-part handle nil t)))))
5485 (defun gnus-mime-view-part-internally (&optional handle)
5486 "View the MIME part under point with an internal viewer.
5487 If no internal viewer is available, use an external viewer."
5488 (interactive)
5489 (gnus-article-check-buffer)
5490 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5491 (mm-inlined-types '(".*"))
5492 (mm-inline-large-images t)
5493 (mail-parse-charset gnus-newsgroup-charset)
5494 (mail-parse-ignored-charsets
5495 (with-current-buffer gnus-summary-buffer
5496 gnus-newsgroup-ignored-charsets))
5497 (inhibit-read-only t))
5498 (if (not (mm-inlinable-p handle))
5499 (gnus-mime-view-part-as-type
5500 nil (lambda (type) (mm-inlinable-p handle type)))
5501 (when handle
5502 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5504 (defun gnus-mime-action-on-part (&optional action)
5505 "Do something with the MIME attachment at (point)."
5506 (interactive
5507 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5508 (gnus-article-check-buffer)
5509 (let ((action-pair (assoc action gnus-mime-action-alist)))
5510 (if action-pair
5511 (funcall (cdr action-pair)))))
5513 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5514 "Call FUNCTION on MIME part N.
5515 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5516 If INTERACTIVE, call FUNCTION interactively."
5517 (let (window frame)
5518 ;; Check whether the article is displayed.
5519 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5520 (setq window (get-buffer-window gnus-article-buffer t))
5521 (frame-visible-p (setq frame (window-frame window))))
5522 (error "No article is displayed"))
5523 (with-current-buffer gnus-article-buffer
5524 ;; Check whether the article displays the right contents.
5525 (unless (with-current-buffer gnus-summary-buffer
5526 (eq gnus-current-article (gnus-summary-article-number)))
5527 (error "You should select the right article first"))
5528 (if n
5529 (setq n (prefix-numeric-value n))
5530 (let ((pt (point)))
5531 (setq n (or (get-text-property pt 'gnus-part)
5532 (and (not (bobp))
5533 (get-text-property (1- pt) 'gnus-part))
5534 (get-text-property (prog2
5535 (forward-line 1)
5536 (point)
5537 (goto-char pt))
5538 'gnus-part)
5539 (get-text-property
5540 (or (and (setq pt (previous-single-property-change
5541 pt 'gnus-part))
5542 (1- pt))
5543 (next-single-property-change (point) 'gnus-part)
5544 (point))
5545 'gnus-part)
5546 1))))
5547 ;; Check whether the specified part exists.
5548 (when (> n (length gnus-article-mime-handle-alist))
5549 (error "No such part")))
5550 (unless
5551 (progn
5552 ;; To select the window is needed so that the cursor
5553 ;; might be visible on the MIME button.
5554 (select-window (prog1
5555 window
5556 (setq window (selected-window))
5557 ;; Article may be displayed in the other frame.
5558 (select-frame-set-input-focus
5559 (prog1
5560 frame
5561 (setq frame (selected-frame))))))
5562 (when (gnus-article-goto-part n)
5563 ;; We point the cursor and the arrow at the MIME button
5564 ;; when the `function' prompt the user for something.
5565 (unless (and (pos-visible-in-window-p)
5566 (> (count-lines (point) (window-end))
5567 (/ (1- (window-height)) 3)))
5568 (recenter (/ (1- (window-height)) 3)))
5569 (let ((cursor-in-non-selected-windows t)
5570 (overlay-arrow-string "=>")
5571 (overlay-arrow-position (point-marker)))
5572 (unwind-protect
5573 (cond
5574 ((and no-handle interactive)
5575 (call-interactively function))
5576 (no-handle
5577 (funcall function))
5578 (interactive
5579 (call-interactively
5580 function (get-text-property (point) 'gnus-data)))
5582 (funcall function
5583 (get-text-property (point) 'gnus-data))))
5584 (set-marker overlay-arrow-position nil)
5585 (unless gnus-auto-select-part
5586 (select-frame-set-input-focus frame)
5587 (select-window window))))
5589 (if gnus-inhibit-mime-unbuttonizing
5590 ;; This is the default though the program shouldn't reach here.
5591 (error "No such part")
5592 ;; The part which doesn't have the MIME button is selected.
5593 ;; So, we display all the buttons and redo it.
5594 (let ((gnus-inhibit-mime-unbuttonizing t))
5595 (gnus-summary-show-article)
5596 (gnus-article-part-wrapper n function no-handle))))))
5598 (defun gnus-article-pipe-part (n)
5599 "Pipe MIME part N, which is the numerical prefix."
5600 (interactive "P")
5601 (gnus-article-part-wrapper n 'mm-pipe-part))
5603 (defun gnus-article-save-part (n)
5604 "Save MIME part N, which is the numerical prefix."
5605 (interactive "P")
5606 (gnus-article-part-wrapper n 'mm-save-part))
5608 (defun gnus-article-interactively-view-part (n)
5609 "View MIME part N interactively, which is the numerical prefix."
5610 (interactive "P")
5611 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5613 (defun gnus-article-copy-part (n)
5614 "Copy MIME part N, which is the numerical prefix."
5615 (interactive "P")
5616 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5618 (defun gnus-article-view-part-as-charset (n)
5619 "View MIME part N using a specified charset.
5620 N is the numerical prefix."
5621 (interactive "P")
5622 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5624 (defun gnus-article-view-part-externally (n)
5625 "View MIME part N externally, which is the numerical prefix."
5626 (interactive "P")
5627 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5629 (defun gnus-article-inline-part (n)
5630 "Inline MIME part N, which is the numerical prefix."
5631 (interactive "P")
5632 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5634 (defun gnus-article-save-part-and-strip (n)
5635 "Save MIME part N and replace it with an external body.
5636 N is the numerical prefix."
5637 (interactive "P")
5638 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5640 (defun gnus-article-replace-part (n)
5641 "Replace MIME part N with an external body.
5642 N is the numerical prefix."
5643 (interactive "P")
5644 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5646 (defun gnus-article-delete-part (n)
5647 "Delete MIME part N and add some information about the removed part.
5648 N is the numerical prefix."
5649 (interactive "P")
5650 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5652 (defun gnus-article-view-part-as-type (n)
5653 "Choose a MIME media type, and view part N as such.
5654 N is the numerical prefix."
5655 (interactive "P")
5656 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5658 (defun gnus-article-mime-match-handle-first (condition)
5659 (if condition
5660 (let (n)
5661 (dolist (ihandle gnus-article-mime-handle-alist)
5662 (if (and (cond
5663 ((functionp condition)
5664 (funcall condition (cdr ihandle)))
5665 ((eq condition 'undisplayed)
5666 (not (or (mm-handle-undisplayer (cdr ihandle))
5667 (equal (mm-handle-media-type (cdr ihandle))
5668 "multipart/alternative"))))
5669 ((eq condition 'undisplayed-alternative)
5670 (not (mm-handle-undisplayer (cdr ihandle))))
5671 (t t))
5672 (gnus-article-goto-part (car ihandle))
5673 (or (not n) (< (car ihandle) n)))
5674 (setq n (car ihandle))))
5675 (or n 1))
5678 (defun gnus-article-view-part (&optional n)
5679 "View MIME part N, which is the numerical prefix.
5680 If the part is already shown, hide the part. If N is nil, view
5681 all parts."
5682 (interactive "P")
5683 (with-current-buffer gnus-article-buffer
5684 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5685 gnus-article-mime-match-handle-function)))
5686 (when (> n (length gnus-article-mime-handle-alist))
5687 (error "No such part"))
5688 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5689 (when (gnus-article-goto-part n)
5690 (if (equal (car handle) "multipart/alternative")
5691 (progn
5692 (beginning-of-line) ;; Make it toggle subparts
5693 (gnus-article-press-button))
5694 (when (eq (gnus-mm-display-part handle) 'internal)
5695 (gnus-set-window-start)))))))
5697 (defsubst gnus-article-mime-total-parts ()
5698 (if (bufferp (car gnus-article-mime-handles))
5699 1 ;; single part
5700 (1- (length gnus-article-mime-handles))))
5702 (defun gnus-mm-display-part (handle)
5703 "Display HANDLE and fix MIME button."
5704 (let ((id (get-text-property (point) 'gnus-part))
5705 (point (point))
5706 (inhibit-read-only t)
5707 (window (selected-window))
5708 (mail-parse-charset gnus-newsgroup-charset)
5709 (mail-parse-ignored-charsets
5710 (if (gnus-buffer-live-p gnus-summary-buffer)
5711 (with-current-buffer gnus-summary-buffer
5712 gnus-newsgroup-ignored-charsets)
5713 nil))
5714 start retval)
5715 (unwind-protect
5716 (progn
5717 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5718 (when win
5719 (select-window win)
5720 (goto-char point)))
5721 (setq start (next-single-property-change point 'gnus-data
5722 nil (point-max))
5723 point (previous-single-property-change start 'gnus-data))
5724 (if (mm-handle-displayed-p handle)
5725 ;; This will remove the part.
5726 (setq point (copy-marker point)
5727 retval (mm-display-part handle))
5728 (let ((part (or (and (mm-inlinable-p handle)
5729 (mm-inlined-p handle)
5731 (with-temp-buffer
5732 (gnus-bind-mm-vars
5733 (setq retval (mm-display-part handle)))
5734 (unless (zerop (buffer-size))
5735 (buffer-string))))))
5736 (goto-char start)
5737 (unless (bolp)
5738 ;; This is a header button.
5739 (forward-line 1))
5740 (cond ((stringp part)
5741 (save-restriction
5742 (narrow-to-region (point)
5743 (progn
5744 (insert part)
5745 (unless (bolp) (insert "\n"))
5746 (point)))
5747 (gnus-treat-article nil id
5748 (gnus-article-mime-total-parts)
5749 (mm-handle-media-type handle))
5750 (mm-handle-set-undisplayer
5751 handle
5752 `(lambda ()
5753 (let ((inhibit-read-only t))
5754 (delete-region ,(copy-marker (point-min) t)
5755 ,(point-max-marker)))))))
5756 (part
5757 (mm-display-inline handle))))))
5758 (when (markerp point)
5759 (setq point (prog1 (marker-position point)
5760 (set-marker point nil))))
5761 (goto-char point)
5762 ;; Toggle the button appearance between `[button]...' and `[button]'.
5763 (let ((displayed-p (mm-handle-displayed-p handle)))
5764 (gnus-insert-mime-button handle id (list displayed-p))
5765 (delete-region
5766 (point)
5767 (next-single-property-change (point) 'gnus-data nil (point-max)))
5768 (setq start (point))
5769 (if (search-backward "\n\n" nil t)
5770 (progn
5771 (goto-char start)
5772 (unless (or displayed-p (eolp))
5773 ;; Add extra newline.
5774 (insert (propertize (buffer-substring (1- start) start)
5775 'gnus-undeletable t))))
5776 ;; We're in the article header.
5777 (delete-char -1)
5778 (dolist (ovl (overlays-in point (point)))
5779 (overlay-put ovl 'gnus-button-attachment-extra t)
5780 (overlay-put ovl 'face nil))
5781 (save-restriction
5782 (message-narrow-to-field)
5783 (let ((gnus-treatment-function-alist
5784 '((gnus-treat-highlight-headers
5785 gnus-article-highlight-headers))))
5786 (gnus-treat-article 'head)))))
5787 (goto-char point)
5788 (if (window-live-p window)
5789 (select-window window)))
5790 retval))
5792 (defun gnus-article-goto-part (n)
5793 "Go to MIME part N."
5794 (when gnus-break-pages
5795 (widen))
5796 (article-goto-body)
5797 (prog1
5798 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5799 ;; There may be header buttons.
5800 (text-property-any (point-min) (point) 'gnus-part n)))
5801 part handle end next handles)
5802 (when start
5803 (goto-char start)
5804 (if (setq handle (get-text-property start 'gnus-data))
5805 start
5806 ;; Go to the displayed subpart, assuming this is
5807 ;; multipart/alternative.
5808 (setq part start
5809 end (point-at-eol))
5810 (while (and (not handle)
5811 part
5812 (< part end)
5813 (setq next (text-property-not-all part end
5814 'gnus-data nil)))
5815 (setq part next
5816 handle (get-text-property part 'gnus-data))
5817 (push (cons handle part) handles)
5818 (unless (mm-handle-displayed-p handle)
5819 (setq handle nil
5820 part (text-property-any part end 'gnus-data nil))))
5821 (unless handle
5822 ;; No subpart is displayed, so we find preferred one.
5823 (setq part
5824 (cdr (assq (mm-preferred-alternative
5825 (nreverse (mapcar 'car handles)))
5826 handles))))
5827 (if part
5828 (goto-char (1+ part))
5829 start))))
5830 (when gnus-break-pages
5831 (gnus-narrow-to-page))))
5833 (defun gnus-insert-mime-button (handle id &optional displayed)
5834 (let ((gnus-tmp-name
5835 (or (mm-handle-filename handle)
5836 (mail-content-type-get (mm-handle-type handle) 'url)
5837 ""))
5838 (gnus-tmp-id id)
5839 (gnus-tmp-type (mm-handle-media-type handle))
5840 (gnus-tmp-description (or (mm-handle-description handle) ""))
5841 (gnus-tmp-dots
5842 (if (if displayed (car displayed)
5843 (mm-handle-displayed-p handle))
5844 "" "..."))
5845 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5846 (buffer-size)))
5847 gnus-tmp-type-long b e)
5848 (when (string-match ".*/" gnus-tmp-name)
5849 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5850 (setq gnus-tmp-type-long (concat gnus-tmp-type
5851 (and (not (equal gnus-tmp-name ""))
5852 (concat "; " gnus-tmp-name))))
5853 (unless (equal gnus-tmp-description "")
5854 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5855 (setq b (point))
5856 (gnus-eval-format
5857 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5858 `(keymap ,gnus-mime-button-map
5859 gnus-callback gnus-mm-display-part
5860 gnus-part ,gnus-tmp-id
5861 article-type annotation
5862 gnus-data ,handle
5863 rear-nonsticky t))
5864 (setq e (if (bolp)
5865 ;; Exclude a newline.
5866 (1- (point))
5867 (point)))
5868 (when gnus-article-button-face
5869 (overlay-put (make-overlay b e nil t)
5870 'face gnus-article-button-face))
5871 (widget-convert-button
5872 'link b e
5873 :mime-handle handle
5874 :action 'gnus-widget-press-button
5875 :button-keymap gnus-mime-button-map
5876 :help-echo
5877 (lambda (widget)
5878 (format
5879 "%S: %s the MIME part; %S: more options"
5880 'mouse-2
5881 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5882 "hide" "show")
5883 'down-mouse-3)))))
5885 (defun gnus-widget-press-button (elems _el)
5886 (goto-char (widget-get elems :from))
5887 (gnus-article-press-button))
5889 (defvar gnus-displaying-mime nil)
5891 (defun gnus-display-mime (&optional ihandles)
5892 "Display the MIME parts."
5893 (save-excursion
5894 (save-selected-window
5895 (let ((window (get-buffer-window gnus-article-buffer))
5896 (point (point)))
5897 (when window
5898 (select-window window)
5899 ;; We have to do this since selecting the window
5900 ;; may change the point. So we set the window point.
5901 (set-window-point window point)))
5902 (let ((handles ihandles)
5903 (inhibit-read-only t))
5904 (cond (handles)
5905 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5906 (when gnus-article-emulate-mime
5907 (mm-uu-dissect-text-parts handles)))
5908 (gnus-article-emulate-mime
5909 (setq handles (mm-uu-dissect))))
5910 (when (and (not ihandles)
5911 (not gnus-displaying-mime))
5912 ;; Top-level call; we clean up.
5913 (when gnus-article-mime-handles
5914 (mm-destroy-parts gnus-article-mime-handles)
5915 (setq gnus-article-mime-handle-alist nil));; A trick.
5916 (setq gnus-article-mime-handles handles)
5917 ;; We allow users to glean info from the handles.
5918 (when gnus-article-mime-part-function
5919 (gnus-mime-part-function handles)))
5920 (if (and handles
5921 (or (not (stringp (car handles)))
5922 (cdr handles)))
5923 (progn
5924 (when (and (not ihandles)
5925 (not gnus-displaying-mime))
5926 ;; Clean up for mime parts.
5927 (article-goto-body)
5928 (delete-region (point) (point-max)))
5929 (let ((gnus-displaying-mime t))
5930 (gnus-mime-display-part handles)))
5931 (save-restriction
5932 (article-goto-body)
5933 (narrow-to-region (point) (point-max))
5934 (gnus-treat-article nil 1 1 "text/plain")
5935 (widen)))
5936 (unless ihandles
5937 ;; Highlight the headers.
5938 (save-excursion
5939 (save-restriction
5940 (article-goto-body)
5941 (narrow-to-region (point-min) (point))
5942 (gnus-article-save-original-date
5943 (gnus-treat-article 'head)))))))
5944 ;; Cope with broken MIME messages.
5945 (goto-char (point-max))
5946 (unless (bolp)
5947 (insert "\n"))))
5949 (defcustom gnus-mime-display-multipart-as-mixed nil
5950 "Display \"multipart\" parts as \"multipart/mixed\".
5952 If t, it overrides nil values of
5953 `gnus-mime-display-multipart-alternative-as-mixed' and
5954 `gnus-mime-display-multipart-related-as-mixed'."
5955 :group 'gnus-article-mime
5956 :type 'boolean)
5958 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5959 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5960 :version "22.1"
5961 :group 'gnus-article-mime
5962 :type 'boolean)
5964 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5965 "Display \"multipart/related\" parts as \"multipart/mixed\".
5967 If displaying \"text/html\" is discouraged \(see
5968 `mm-discouraged-alternatives') images or other material inside a
5969 \"multipart/related\" part might be overlooked when this variable is nil."
5970 :version "22.1"
5971 :group 'gnus-article-mime
5972 :type 'boolean)
5974 (defcustom gnus-mime-display-attachment-buttons-in-header t
5975 "Add attachment buttons in the end of the header of an article.
5976 Since MIME attachments tend to be put at the end of an article, we may
5977 overlook them if there is a huge body. This option offers you a copy
5978 of all non-inlinable MIME parts as buttons shown in front of an article.
5979 If nil, don't show those extra buttons."
5980 :version "25.1"
5981 :group 'gnus-article-mime
5982 :type 'boolean)
5984 (defun gnus-mime-display-part (handle)
5985 (cond
5986 ;; Maybe a broken MIME message.
5987 ((null handle))
5988 ;; Single part.
5989 ((not (stringp (car handle)))
5990 (gnus-mime-display-single handle))
5991 ;; User-defined multipart
5992 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5993 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5994 handle))
5995 ;; multipart/alternative
5996 ((and (equal (car handle) "multipart/alternative")
5997 (not (or gnus-mime-display-multipart-as-mixed
5998 gnus-mime-display-multipart-alternative-as-mixed)))
5999 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6000 (push (cons id handle) gnus-article-mime-handle-alist)
6001 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6002 ;; multipart/related
6003 ((and (equal (car handle) "multipart/related")
6004 (not (or gnus-mime-display-multipart-as-mixed
6005 gnus-mime-display-multipart-related-as-mixed)))
6006 (gnus-mime-display-part (cadr handle)))
6007 ((equal (car handle) "multipart/signed")
6008 (gnus-add-wash-type 'signed)
6009 (gnus-mime-display-security handle))
6010 ((equal (car handle) "multipart/encrypted")
6011 (gnus-add-wash-type 'encrypted)
6012 (gnus-mime-display-security handle))
6013 ;; Other multiparts are handled like multipart/mixed.
6015 (gnus-mime-display-mixed (cdr handle)))))
6017 (defun gnus-mime-part-function (handles)
6018 (if (stringp (car handles))
6019 (mapcar 'gnus-mime-part-function (cdr handles))
6020 (funcall gnus-article-mime-part-function handles)))
6022 (defun gnus-mime-display-mixed (handles)
6023 (mapcar 'gnus-mime-display-part handles))
6025 (defun gnus-mime-display-single (handle)
6026 (let ((type (mm-handle-media-type handle))
6027 (ignored gnus-ignored-mime-types)
6028 (not-attachment t)
6029 display text)
6030 (catch 'ignored
6031 (progn
6032 (while ignored
6033 (when (string-match (pop ignored) type)
6034 (throw 'ignored nil)))
6035 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6036 (with-current-buffer gnus-summary-buffer
6037 gnus-inhibit-images)
6038 gnus-inhibit-images)
6039 (string-match "\\`image/" type)))
6040 (setq not-attachment
6041 (and (not (mm-inline-override-p handle))
6042 (or (not (mm-handle-disposition handle))
6043 (equal (car (mm-handle-disposition handle))
6044 "inline")
6045 (mm-attachment-override-p handle))))
6046 (mm-automatic-display-p handle)
6047 (or (and
6048 (mm-inlinable-p handle)
6049 (mm-inlined-p handle))
6050 (mm-automatic-external-display-p type)))
6051 (setq display t)
6052 (when (equal (mm-handle-media-supertype handle) "text")
6053 (setq text t)))
6054 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6055 beg)
6056 (unless id
6057 (setq id (1+ (length gnus-article-mime-handle-alist)))
6058 (push (cons id handle) gnus-article-mime-handle-alist))
6059 (when (and display
6060 (equal (mm-handle-media-supertype handle) "message"))
6061 (insert-char
6063 (cond ((not (bolp)) 2)
6064 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6065 (t 1))))
6066 (when (or (not display)
6067 (not (gnus-unbuttonized-mime-type-p type))
6068 (eq id gnus-mime-buttonized-part-id))
6069 (gnus-insert-mime-button
6070 handle id (list (or display (and not-attachment text)))))
6071 (setq beg (point))
6072 (cond
6073 (display
6074 (let ((mail-parse-charset gnus-newsgroup-charset)
6075 (mail-parse-ignored-charsets
6076 (save-excursion (condition-case ()
6077 (set-buffer gnus-summary-buffer)
6078 (error))
6079 gnus-newsgroup-ignored-charsets)))
6080 (gnus-bind-mm-vars (mm-display-part handle t))))
6081 ((and text not-attachment)
6082 (mm-display-inline handle)))
6083 (goto-char (point-max))
6084 (if (string-match "\\`image/" type)
6085 (gnus-article-insert-newline)
6086 (if (prog1
6087 (= (skip-chars-backward "\n") -1)
6088 (unless (eobp) (forward-char 1)))
6089 (gnus-article-insert-newline)
6090 (put-text-property (point) (point-max) 'gnus-undeletable t))
6091 (goto-char (point-max)))
6092 ;; Do highlighting.
6093 (save-excursion
6094 (save-restriction
6095 (narrow-to-region beg (point))
6096 (if (eq handle gnus-article-mime-handles)
6097 ;; The format=flowed case.
6098 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6099 ;; Don't count signature parts that are never displayed.
6100 ;; The part number should be re-calculated supposing this
6101 ;; might be a message/rfc822 part.
6102 (let (handles)
6103 (dolist (part gnus-article-mime-handles)
6104 (unless (or (stringp part)
6105 (equal (car (mm-handle-type part))
6106 "application/pgp-signature"))
6107 (push part handles)))
6108 (gnus-treat-article
6109 nil (length (memq handle handles)) (length handles)
6110 (mm-handle-media-type handle)))))))))))
6112 (defun gnus-unbuttonized-mime-type-p (type)
6113 "Say whether TYPE is to be unbuttonized."
6114 (unless gnus-inhibit-mime-unbuttonizing
6115 (when (catch 'found
6116 (let ((types gnus-unbuttonized-mime-types))
6117 (while types
6118 (when (string-match (pop types) type)
6119 (throw 'found t)))))
6120 (not (catch 'found
6121 (let ((types gnus-buttonized-mime-types))
6122 (while types
6123 (when (string-match (pop types) type)
6124 (throw 'found t)))))))))
6126 (defun gnus-article-insert-newline ()
6127 "Insert a newline, but mark it as undeletable."
6128 (put-text-property (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6130 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6131 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6132 (ihandles handles)
6133 (point (point))
6134 handle (inhibit-read-only t) from begend not-pref)
6135 (save-window-excursion
6136 (save-restriction
6137 (when ibegend
6138 (narrow-to-region (car ibegend)
6139 (or (cdr ibegend)
6140 (progn
6141 (goto-char (car ibegend))
6142 (forward-line 2)
6143 (point))))
6144 (delete-region (point-min) (point-max))
6145 (mm-remove-parts handles))
6146 (setq begend (list (point-marker)))
6147 ;; Do the toggle.
6148 (unless (setq not-pref (cadr (member preferred ihandles)))
6149 (setq not-pref (car ihandles)))
6150 (when (or ibegend
6151 (not preferred)
6152 (not (gnus-unbuttonized-mime-type-p
6153 "multipart/alternative")))
6154 (add-text-properties
6155 (setq from (point))
6156 (progn
6157 (insert (format "%d. " id))
6158 (point))
6159 `(gnus-callback
6160 (lambda (handles)
6161 (unless ,(not ibegend)
6162 (setq gnus-article-mime-handle-alist
6163 ',gnus-article-mime-handle-alist))
6164 (gnus-mime-display-alternative
6165 ',ihandles ',not-pref ',begend ,id))
6166 keymap ,gnus-mime-button-map
6167 mouse-face ,gnus-article-mouse-face
6168 face ,gnus-article-button-face
6169 gnus-part ,id
6170 article-type multipart
6171 rear-nonsticky t))
6172 (widget-convert-button 'link from (point)
6173 :action 'gnus-widget-press-button)
6174 ;; Do the handles
6175 (while (setq handle (pop handles))
6176 (add-text-properties
6177 (setq from (point))
6178 (progn
6179 (insert (format "(%c) %-18s"
6180 (if (equal handle preferred) ?* ? )
6181 (mm-handle-media-type handle)))
6182 (point))
6183 `(gnus-callback
6184 (lambda (handles)
6185 (unless ,(not ibegend)
6186 (setq gnus-article-mime-handle-alist
6187 ',gnus-article-mime-handle-alist))
6188 (gnus-mime-display-alternative
6189 ',ihandles ',handle ',begend ,id))
6190 keymap ,gnus-mime-button-map
6191 mouse-face ,gnus-article-mouse-face
6192 face ,gnus-article-button-face
6193 gnus-part ,id
6194 gnus-data ,handle
6195 rear-nonsticky t))
6196 (widget-convert-button 'link from (point)
6197 :action 'gnus-widget-press-button)
6198 (insert " "))
6199 (insert "\n\n"))
6200 (when preferred
6201 (if (stringp (car preferred))
6202 (gnus-display-mime preferred)
6203 (let ((mail-parse-charset gnus-newsgroup-charset)
6204 (mail-parse-ignored-charsets
6205 (with-current-buffer gnus-summary-buffer
6206 gnus-newsgroup-ignored-charsets)))
6207 (gnus-bind-mm-vars (mm-display-part preferred))
6208 ;; Do highlighting.
6209 (save-excursion
6210 (save-restriction
6211 (narrow-to-region (car begend) (point-max))
6212 (gnus-treat-article
6213 nil (length gnus-article-mime-handle-alist)
6214 (gnus-article-mime-total-parts)
6215 (mm-handle-media-type preferred))))))
6216 (goto-char (point-max))
6217 (setcdr begend (point-marker)))))
6218 (when ibegend
6219 (goto-char point)))
6220 ;; Redraw attachment buttons in the header.
6221 (when gnus-mime-display-attachment-buttons-in-header
6222 (gnus-mime-buttonize-attachments-in-header)))
6224 (defconst gnus-article-wash-status-strings
6225 (let ((alist '((cite "c" "Possible hidden citation text"
6226 " " "All citation text visible")
6227 (headers "h" "Hidden headers"
6228 " " "All headers visible.")
6229 (pgp "p" "Encrypted or signed message status hidden"
6230 " " "No hidden encryption nor digital signature status")
6231 (signature "s" "Signature has been hidden"
6232 " " "Signature is visible")
6233 (overstrike "o" "Overstrike (^H) characters applied"
6234 " " "No overstrike characters applied")
6235 (emphasis "e" "/*_Emphasis_*/ characters applied"
6236 " " "No /*_emphasis_*/ characters applied")))
6237 result)
6238 (dolist (entry alist result)
6239 (let ((key (nth 0 entry))
6240 (on (copy-sequence (nth 1 entry)))
6241 (on-help (nth 2 entry))
6242 (off (copy-sequence (nth 3 entry)))
6243 (off-help (nth 4 entry)))
6244 (put-text-property 0 1 'help-echo on-help on)
6245 (put-text-property 0 1 'help-echo off-help off)
6246 (push (list key on off) result))))
6247 "Alist of strings describing wash status in the mode line.
6248 Each entry has the form (KEY ON OF), where the KEY is a symbol
6249 representing the particular washing function, ON is the string to use
6250 in the article mode line when the washing function is active, and OFF
6251 is the string to use when it is inactive.")
6253 (defun gnus-article-wash-status-entry (key value)
6254 (let ((entry (assoc key gnus-article-wash-status-strings)))
6255 (if value (nth 1 entry) (nth 2 entry))))
6257 (defun gnus-article-wash-status ()
6258 "Return a string which display status of article washing."
6259 (with-current-buffer gnus-article-buffer
6260 (let ((cite (memq 'cite gnus-article-wash-types))
6261 (headers (memq 'headers gnus-article-wash-types))
6262 (boring (memq 'boring-headers gnus-article-wash-types))
6263 (pgp (memq 'pgp gnus-article-wash-types))
6264 (pem (memq 'pem gnus-article-wash-types))
6265 (signed (memq 'signed gnus-article-wash-types))
6266 (encrypted (memq 'encrypted gnus-article-wash-types))
6267 (signature (memq 'signature gnus-article-wash-types))
6268 (overstrike (memq 'overstrike gnus-article-wash-types))
6269 (emphasis (memq 'emphasis gnus-article-wash-types)))
6270 (concat
6271 (gnus-article-wash-status-entry 'cite cite)
6272 (gnus-article-wash-status-entry 'headers (or headers boring))
6273 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6274 (gnus-article-wash-status-entry 'signature signature)
6275 (gnus-article-wash-status-entry 'overstrike overstrike)
6276 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6278 (defun gnus-add-wash-type (type)
6279 "Add a washing of TYPE to the current status."
6280 (add-to-list 'gnus-article-wash-types type))
6282 (defun gnus-delete-wash-type (type)
6283 "Add a washing of TYPE to the current status."
6284 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6286 (defun gnus-add-image (category image)
6287 "Add IMAGE of CATEGORY to the list of displayed images."
6288 (let ((entry (assq category gnus-article-image-alist)))
6289 (unless entry
6290 (setq entry (list category))
6291 (push entry gnus-article-image-alist))
6292 (nconc entry (list image))))
6294 (defun gnus-delete-images (category)
6295 "Delete all images in CATEGORY."
6296 (let ((entry (assq category gnus-article-image-alist)))
6297 (dolist (image (cdr entry))
6298 (gnus-remove-image image category))
6299 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6300 (gnus-delete-wash-type category)))
6302 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6304 (defun gnus-article-maybe-hide-headers ()
6305 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6306 Provided for backwards compatibility."
6307 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6308 (not (with-current-buffer gnus-summary-buffer
6309 gnus-have-all-headers)))
6310 (not gnus-inhibit-hiding))
6311 (article-hide-headers)))
6313 (declare-function shr-put-image "shr" (data alt &optional flags))
6315 (defun gnus-shr-put-image (data alt &optional flags)
6316 "Put image DATA with a string ALT. Enable image to be deleted."
6317 (let ((image (if flags
6318 (shr-put-image data (propertize (or alt "*")
6319 'gnus-image-category 'shr)
6320 flags)
6321 ;; Old `shr-put-image' doesn't take the optional `flags'
6322 ;; argument.
6323 (shr-put-image data (propertize (or alt "*")
6324 'gnus-image-category 'shr)))))
6325 (when image
6326 (gnus-add-image 'shr image))))
6328 (defun gnus-article-mime-handles (&optional alist id all)
6329 (if alist
6330 (let ((i 1) newid flat)
6331 (dolist (handle alist flat)
6332 (setq newid (append id (list i))
6333 i (1+ i))
6334 (if (stringp (car handle))
6335 (setq flat (nconc flat (gnus-article-mime-handles
6336 (cdr handle) newid all)))
6337 (delq (rassq handle all) all)
6338 (setq flat (nconc flat (list (cons newid handle)))))))
6339 (let ((flat (list nil)))
6340 ;; Assume that elements of `gnus-article-mime-handle-alist'
6341 ;; are in the decreasing order, but unnumbered subsidiaries
6342 ;; in each element are in the increasing order.
6343 (dolist (handle (reverse gnus-article-mime-handle-alist))
6344 (if (stringp (cadr handle))
6345 (setq flat (nconc flat (gnus-article-mime-handles
6346 (cddr handle) (list (car handle)) flat)))
6347 (delq (rassq (cdr handle) flat) flat)
6348 (setq flat (nconc flat (list (cons (list (car handle))
6349 (cdr handle)))))))
6350 (setq flat (cdr flat))
6351 (mapc (lambda (handle)
6352 (if (cdar handle)
6353 ;; This is a hidden (i.e. unnumbered) handle.
6354 (progn
6355 (setcar handle
6356 (1+ (caar gnus-article-mime-handle-alist)))
6357 (push handle gnus-article-mime-handle-alist))
6358 (setcar handle (caar handle))))
6359 flat)
6360 flat)))
6362 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6363 "Show attachments as buttons in the end of the header of an article.
6364 This function toggles the display when called interactively. Note that
6365 buttons to be added to the header are only the ones that aren't inlined
6366 in the body. Use `gnus-header-face-alist' to highlight buttons."
6367 (interactive (list t))
6368 (gnus-with-article-buffer
6369 (let ((case-fold-search t) buttons handle type st)
6370 (save-excursion
6371 (save-restriction
6372 (widen)
6373 (article-narrow-to-head)
6374 ;; Header buttons exist?
6375 (while (and (not buttons)
6376 (re-search-forward "^attachments?:[\n ]+" nil t))
6377 (when (get-char-property (match-end 0)
6378 'gnus-button-attachment-extra)
6379 (setq buttons (match-beginning 0))))
6380 (widen)
6381 (when buttons
6382 ;; Delete header buttons.
6383 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6384 (match-beginning 0)
6385 (point-max))))
6386 (unless (and interactive buttons)
6387 ;; Find buttons.
6388 (setq buttons nil)
6389 (dolist (button (gnus-article-mime-handles))
6390 (setq handle (cdr button)
6391 type (mm-handle-media-type handle))
6392 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6393 (with-current-buffer gnus-summary-buffer
6394 gnus-inhibit-images)
6395 gnus-inhibit-images)
6396 (string-match "\\`image/" type))
6397 (mm-inline-override-p handle)
6398 (and (mm-handle-disposition handle)
6399 (not (equal (car (mm-handle-disposition handle))
6400 "inline"))
6401 (not (mm-attachment-override-p handle)))
6402 (not (mm-automatic-display-p handle))
6403 (not (or (and (mm-inlinable-p handle)
6404 (mm-inlined-p handle))
6405 (mm-automatic-external-display-p type))))
6406 (push button buttons)))
6407 (when buttons
6408 ;; Add header buttons.
6409 (article-goto-body)
6410 (forward-line -1)
6411 (narrow-to-region (point) (point))
6412 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6413 (dolist (button (nreverse buttons))
6414 (setq st (point))
6415 (insert " ")
6416 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6417 (gnus-insert-mime-button handle (car button))
6418 (skip-chars-backward "\t\n ")
6419 (delete-region (point) (point-max))
6420 (when (> (current-column) (window-width))
6421 (goto-char st)
6422 (insert "\n")
6423 (end-of-line)))
6424 (insert "\n")
6425 (dolist (ovl (overlays-in (point-min) (point)))
6426 (overlay-put ovl 'gnus-button-attachment-extra t)
6427 (overlay-put ovl 'face nil))
6428 (let ((gnus-treatment-function-alist
6429 '((gnus-treat-highlight-headers
6430 gnus-article-highlight-headers))))
6431 (gnus-treat-article 'head)))))))))
6433 ;;; Article savers.
6435 (defun gnus-output-to-file (file-name)
6436 "Append the current article to a file named FILE-NAME.
6437 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6438 text and used as the value of the coding cookie which is added to the
6439 top of a file. Otherwise, this function saves a raw article without
6440 the coding cookie."
6441 (let* ((artbuf (current-buffer))
6442 (file-name-coding-system nnmail-pathname-coding-system)
6443 (coding gnus-article-save-coding-system)
6444 (coding-system-for-read (if coding
6445 nil ;; Rely on the coding cookie.
6446 mm-text-coding-system))
6447 (coding-system-for-write (or coding
6448 mm-text-coding-system-for-write
6449 mm-text-coding-system))
6450 (exists (file-exists-p file-name)))
6451 (with-temp-buffer
6452 (when exists
6453 (insert-file-contents file-name)
6454 (goto-char (point-min))
6455 ;; Remove the existing coding cookie.
6456 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6457 (delete-region (match-beginning 0) (match-end 0))))
6458 (goto-char (point-max))
6459 (insert-buffer-substring artbuf)
6460 ;; Append newline at end of the buffer as separator, and then
6461 ;; save it to file.
6462 (goto-char (point-max))
6463 (insert "\n")
6464 (when coding
6465 ;; If the coding system is not suitable to encode the text,
6466 ;; ask a user for a proper one.
6467 (setq coding (coding-system-base
6468 (save-window-excursion
6469 (select-safe-coding-system (point-min) (point-max)
6470 coding))))
6471 (setq coding-system-for-write
6472 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6473 coding))
6474 (goto-char (point-min))
6475 ;; Add the coding cookie.
6476 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6477 coding-system-for-write)))
6478 (if exists
6479 (progn
6480 (write-region (point-min) (point-max) file-name nil 'no-message)
6481 (message "Appended to %s" file-name))
6482 (write-region (point-min) (point-max) file-name))))
6485 (defun gnus-narrow-to-page (&optional arg)
6486 "Narrow the article buffer to a page.
6487 If given a numerical ARG, move forward ARG pages."
6488 (interactive "P")
6489 (setq arg (if arg (prefix-numeric-value arg) 0))
6490 (with-current-buffer gnus-article-buffer
6491 (widen)
6492 ;; Remove any old next/prev buttons.
6493 (when (gnus-visual-p 'page-marker)
6494 (let ((inhibit-read-only t))
6495 (gnus-remove-text-with-property 'gnus-prev)
6496 (gnus-remove-text-with-property 'gnus-next)))
6497 (let (st nd pt)
6498 (when (save-excursion
6499 (cond ((< arg 0)
6500 (if (re-search-backward page-delimiter nil 'move (abs arg))
6501 (prog1
6502 (setq nd (match-beginning 0)
6503 pt nd)
6504 (when (re-search-backward page-delimiter nil t)
6505 (setq st (match-end 0))))
6506 (when (re-search-forward page-delimiter nil t)
6507 (setq nd (match-beginning 0)
6508 pt (point-min)))))
6509 ((> arg 0)
6510 (if (re-search-forward page-delimiter nil 'move arg)
6511 (prog1
6512 (setq st (match-end 0)
6513 pt st)
6514 (when (re-search-forward page-delimiter nil t)
6515 (setq nd (match-beginning 0))))
6516 (when (re-search-backward page-delimiter nil t)
6517 (setq st (match-end 0)
6518 pt (point-max)))))
6520 (when (re-search-backward page-delimiter nil t)
6521 (goto-char (setq st (match-end 0))))
6522 (when (re-search-forward page-delimiter nil t)
6523 (setq nd (match-beginning 0)))
6524 (or st nd))))
6525 (setq gnus-page-broken t)
6526 (when pt (goto-char pt))
6527 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6528 (when (gnus-visual-p 'page-marker)
6529 (save-excursion
6530 (when nd
6531 (goto-char nd)
6532 (gnus-insert-next-page-button))
6533 (when st
6534 (goto-char st)
6535 (gnus-insert-prev-page-button))))))))
6537 ;; Article mode commands
6539 (defun gnus-article-goto-next-page ()
6540 "Show the next page of the article."
6541 (interactive)
6542 (when (gnus-article-next-page)
6543 (goto-char (point-min))
6544 (gnus-article-read-summary-keys nil ?n)))
6547 (defun gnus-article-goto-prev-page ()
6548 "Show the previous page of the article."
6549 (interactive)
6550 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6551 (gnus-article-read-summary-keys nil ?p)
6552 (gnus-article-prev-page nil)))
6554 ;; This is cleaner but currently breaks `gnus-pick-mode':
6556 ;; (defun gnus-article-goto-next-page ()
6557 ;; "Show the next page of the article."
6558 ;; (interactive)
6559 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6560 ;; (gnus-summary-next-page)))
6562 ;; (defun gnus-article-goto-prev-page ()
6563 ;; "Show the next page of the article."
6564 ;; (interactive)
6565 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6566 ;; (gnus-summary-prev-page)))
6568 (defun gnus-article-next-page (&optional lines)
6569 "Show the next page of the current article.
6570 If end of article, return non-nil. Otherwise return nil.
6571 Argument LINES specifies lines to be scrolled up."
6572 (interactive "p")
6573 (move-to-window-line (- -1 scroll-margin))
6574 (if (and (not (and gnus-article-over-scroll
6575 (> (count-lines (window-start) (point-max))
6576 (+ (or lines (1- (window-height))) scroll-margin))))
6577 (save-excursion
6578 (end-of-line)
6579 (and (pos-visible-in-window-p) ;Not continuation line.
6580 (>= (point) (point-max)))))
6581 ;; Nothing in this page.
6582 (if (or (not gnus-page-broken)
6583 (save-excursion
6584 (save-restriction
6585 (widen)
6586 (forward-line)
6587 (eobp)))) ;Real end-of-buffer?
6588 (progn
6589 (when gnus-article-over-scroll
6590 (gnus-article-next-page-1 lines))
6591 t) ;Nothing more.
6592 (gnus-narrow-to-page 1) ;Go to next page.
6593 nil)
6594 ;; More in this page.
6595 (gnus-article-next-page-1 lines)
6596 nil))
6598 (defun gnus-article-beginning-of-window ()
6599 "Move point to the beginning of the window.
6600 The point is placed at the line number which `scroll-margin'
6601 specifies."
6602 ;; There is an obscure bug in Emacs that makes it impossible to
6603 ;; scroll past big pictures in the article buffer. Try to fix
6604 ;; this by adding a sanity check by counting the lines visible.
6605 (when (> (count-lines (window-start) (window-end)) 30)
6606 (move-to-window-line
6607 (min (max 0 scroll-margin)
6608 (max 1 (- (window-height)
6609 (if mode-line-format 1 0)
6610 (if header-line-format 1 0)
6611 2))))))
6613 (defvar scroll-in-place)
6615 (defun gnus-article-next-page-1 (lines)
6616 (condition-case ()
6617 (let ((scroll-in-place nil)
6618 (auto-window-vscroll nil))
6619 (scroll-up lines))
6620 (end-of-buffer
6621 ;; Long lines may cause an end-of-buffer error.
6622 (goto-char (point-max))))
6623 (gnus-article-beginning-of-window))
6625 (defun gnus-article-prev-page (&optional lines)
6626 "Show previous page of current article.
6627 Argument LINES specifies lines to be scrolled down."
6628 (interactive "p")
6629 (move-to-window-line 0)
6630 (if (and gnus-page-broken
6631 (bobp)
6632 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6633 (progn
6634 (gnus-narrow-to-page -1) ;Go to previous page.
6635 (goto-char (point-max))
6636 (recenter (if gnus-article-over-scroll
6637 (if lines
6638 (max (+ lines scroll-margin) 3)
6639 (- (window-height) 2))
6640 -1)))
6641 (prog1
6642 (condition-case ()
6643 (let ((scroll-in-place nil))
6644 (scroll-down lines))
6645 (beginning-of-buffer
6646 (goto-char (point-min))))
6647 (gnus-article-beginning-of-window))))
6649 (defun gnus-article-only-boring-p ()
6650 "Decide whether there is only boring text remaining in the article.
6651 Something \"interesting\" is a word of at least two letters that does
6652 not have a face in `gnus-article-boring-faces'."
6653 (when (and gnus-article-skip-boring
6654 (boundp 'gnus-article-boring-faces)
6655 (symbol-value 'gnus-article-boring-faces))
6656 (save-excursion
6657 (let ((inhibit-point-motion-hooks t))
6658 (catch 'only-boring
6659 (while (re-search-forward "\\b\\w\\w" nil t)
6660 (forward-char -1)
6661 (when (not (gnus-intersection
6662 (gnus-faces-at (point))
6663 (symbol-value 'gnus-article-boring-faces)))
6664 (throw 'only-boring nil)))
6665 (throw 'only-boring t))))))
6667 (defun gnus-article-refer-article ()
6668 "Read article specified by message-id around point."
6669 (interactive)
6670 (save-excursion
6671 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6672 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6673 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6674 (let ((msg-id (concat "<" (match-string 0) ">")))
6675 (set-buffer gnus-summary-buffer)
6676 (gnus-summary-refer-article msg-id))
6677 (error "No references around point"))))
6679 (defun gnus-article-show-summary ()
6680 "Reconfigure windows to show summary buffer."
6681 (interactive)
6682 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6683 (error "There is no summary buffer for this article buffer")
6684 (gnus-article-set-globals)
6685 (gnus-configure-windows 'article)
6686 (gnus-summary-goto-subject gnus-current-article)
6687 (gnus-summary-position-point)))
6689 (defun gnus-article-describe-briefly ()
6690 "Describe article mode commands briefly."
6691 (interactive)
6692 (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")))
6694 (defun gnus-article-check-buffer ()
6695 "Beep if not in an article buffer."
6696 (unless (derived-mode-p 'gnus-article-mode)
6697 (error "Command invoked outside of a Gnus article buffer")))
6699 (defvar gnus-pick-mode)
6701 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6702 "Read a summary buffer key sequence and execute it from the article buffer."
6703 (interactive "P")
6704 (gnus-article-check-buffer)
6705 (let ((nosaves
6706 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f" "WDD" "WDW"
6707 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6708 "=" "^" "\M-^" "|"))
6709 (nosave-but-article
6710 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6711 "An" "Ap" [?A (meta return)] [?A delete]))
6712 (nosave-in-article
6713 '("AS" "\C-d"))
6714 keys new-sum-point)
6715 (with-current-buffer gnus-article-current-summary
6716 (let (gnus-pick-mode)
6717 (setq unread-command-events (nconc unread-command-events
6718 (list (or key last-command-event)))
6719 keys (read-key-sequence nil t))))
6721 (message "")
6723 (cond
6724 ((eq (aref keys (1- (length keys))) ?\C-h)
6725 (gnus-article-describe-bindings (substring keys 0 -1)))
6726 ((or (member keys nosaves)
6727 (member keys nosave-but-article)
6728 (member keys nosave-in-article))
6729 (let (func)
6730 (save-window-excursion
6731 (pop-to-buffer gnus-article-current-summary)
6732 ;; We disable the pick minor mode commands.
6733 (let (gnus-pick-mode)
6734 (setq func (key-binding keys t))))
6735 (if (or (not func)
6736 (numberp func))
6737 (ding)
6738 (unless (member keys nosave-in-article)
6739 (set-buffer gnus-article-current-summary))
6740 (when (and (symbolp func)
6741 (get func 'disabled))
6742 (error "Function %s disabled" func))
6743 (call-interactively func)
6744 (setq new-sum-point (point)))
6745 (when (member keys nosave-but-article)
6746 (pop-to-buffer gnus-article-buffer))))
6748 ;; These commands should restore window configuration.
6749 (let ((obuf (current-buffer))
6750 (owin (current-window-configuration))
6751 win func in-buffer selected new-sum-start new-sum-hscroll err)
6752 (cond (not-restore-window
6753 (pop-to-buffer gnus-article-current-summary)
6754 (setq win (selected-window)))
6755 ((setq win (get-buffer-window gnus-article-current-summary))
6756 (select-window win))
6758 (let ((summary-buffer gnus-article-current-summary))
6759 (gnus-configure-windows 'article)
6760 (unless (setq win (get-buffer-window summary-buffer 'visible))
6761 (let ((gnus-buffer-configuration
6762 '((article ((vertical 1.0
6763 (summary 0.25 point)
6764 (article 1.0)))))))
6765 (gnus-configure-windows 'article))
6766 (setq win (get-buffer-window summary-buffer 'visible)))
6767 (select-frame-set-input-focus (window-frame win))
6768 (select-window win))))
6769 (setq in-buffer (current-buffer))
6770 ;; We disable the pick minor mode commands.
6771 (setq func (let (gnus-pick-mode)
6772 (key-binding keys t)))
6773 (when (get func 'disabled)
6774 (error "Function %s disabled" func))
6775 (if (and func
6776 (functionp func)
6777 (condition-case code
6778 (progn
6779 (call-interactively func)
6781 (error
6782 (setq err code)
6783 nil)))
6784 (progn
6785 (when (eq win (selected-window))
6786 (setq new-sum-point (point)
6787 new-sum-start (window-start win)
6788 new-sum-hscroll (window-hscroll win)))
6789 (when (or (eq in-buffer (current-buffer))
6790 (when (eq obuf (current-buffer))
6791 (set-buffer in-buffer)
6793 (setq selected (ignore-errors (gnus-summary-select-article)))
6794 (set-buffer obuf)
6795 (unless not-restore-window
6796 (set-window-configuration owin))
6797 (when (and (eq selected 'old)
6798 new-sum-point)
6799 (set-window-start (get-buffer-window (current-buffer))
6801 (set-window-point (get-buffer-window (current-buffer))
6802 (if (article-goto-body)
6803 (1- (point))
6804 (point))))
6805 (when (and (not not-restore-window)
6806 new-sum-point
6807 (window-live-p win)
6808 (with-current-buffer (window-buffer win)
6809 (derived-mode-p 'gnus-summary-mode)))
6810 (set-window-point win new-sum-point)
6811 (set-window-start win new-sum-start)
6812 (set-window-hscroll win new-sum-hscroll))))
6813 (set-window-configuration owin)
6814 (if err
6815 (signal (car err) (cdr err))
6816 (ding))))))))
6818 (defun gnus-article-read-summary-send-keys ()
6819 (interactive)
6820 (let ((unread-command-events (list ?S)))
6821 (gnus-article-read-summary-keys)))
6823 (defun gnus-article-describe-key (key)
6824 "Display documentation of the function invoked by KEY.
6825 KEY is a string or a vector."
6826 (interactive (list (let ((cursor-in-echo-area t))
6827 (read-key-sequence "Describe key: "))))
6828 (gnus-article-check-buffer)
6829 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6830 gnus-article-read-summary-send-keys))
6831 (with-current-buffer gnus-article-current-summary
6832 (setq unread-command-events
6833 (nconc
6834 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6835 (list 'meta (- x 128))
6837 key)
6838 unread-command-events))
6839 (let ((cursor-in-echo-area t)
6840 gnus-pick-mode)
6841 (describe-key (read-key-sequence nil t))))
6842 (describe-key key)))
6844 (defun gnus-article-describe-key-briefly (key &optional insert)
6845 "Display documentation of the function invoked by KEY.
6846 KEY is a string or a vector."
6847 (interactive (list (let ((cursor-in-echo-area t))
6848 (read-key-sequence "Describe key: "))
6849 current-prefix-arg))
6850 (gnus-article-check-buffer)
6851 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6852 gnus-article-read-summary-send-keys))
6853 (with-current-buffer gnus-article-current-summary
6854 (setq unread-command-events
6855 (nconc
6856 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6857 (list 'meta (- x 128))
6859 key)
6860 unread-command-events))
6861 (let ((cursor-in-echo-area t)
6862 gnus-pick-mode)
6863 (describe-key-briefly (read-key-sequence nil t) insert)))
6864 (describe-key-briefly key insert)))
6866 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6867 (defvar gnus-agent-summary-mode)
6868 (defvar gnus-draft-mode)
6869 (defvar help-xref-stack-item)
6870 (defvar help-xref-following)
6872 (defun gnus-article-describe-bindings (&optional prefix)
6873 "Show a list of all defined keys, and their definitions.
6874 The optional argument PREFIX, if non-nil, should be a key sequence;
6875 then we display only bindings that start with that prefix."
6876 (interactive)
6877 (gnus-article-check-buffer)
6878 (let ((keymap (copy-keymap gnus-article-mode-map))
6879 (map (copy-keymap gnus-article-send-map))
6880 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6881 (summap (make-sparse-keymap))
6882 parent agent draft)
6883 (define-key keymap "S" map)
6884 (define-key map [t] nil)
6885 (define-key summap [t] 'undefined)
6886 (with-current-buffer gnus-article-current-summary
6887 (dolist (key sumkeys)
6888 (define-key summap key (key-binding key (current-local-map))))
6889 (set-keymap-parent
6890 keymap
6891 (if (setq parent (keymap-parent gnus-article-mode-map))
6892 (prog1
6893 (setq parent (copy-keymap parent))
6894 (set-keymap-parent parent summap))
6895 summap))
6896 (set-keymap-parent map (key-binding "S"))
6897 (let (key def gnus-pick-mode)
6898 (while sumkeys
6899 (setq key (pop sumkeys))
6900 (cond ((and (vectorp key) (= (length key) 1)
6901 (consp (setq def (aref key 0)))
6902 (numberp (car def)) (numberp (cdr def)))
6903 (when (< (max (car def) (cdr def)) 128)
6904 (setq sumkeys
6905 (append (mapcar
6906 #'vector
6907 (nreverse (gnus-uncompress-range def)))
6908 sumkeys))))
6909 ((setq def (key-binding key))
6910 (unless (eq def 'undefined)
6911 (define-key keymap key def))))))
6912 (when (boundp 'gnus-agent-summary-mode)
6913 (setq agent gnus-agent-summary-mode))
6914 (when (boundp 'gnus-draft-mode)
6915 (setq draft gnus-draft-mode)))
6916 (with-temp-buffer
6917 (use-local-map keymap)
6918 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6919 (set (make-local-variable 'gnus-draft-mode) draft)
6920 (describe-bindings prefix))
6921 (let ((item `((lambda (prefix)
6922 (with-current-buffer ,(current-buffer)
6923 (gnus-article-describe-bindings prefix)))
6924 ,prefix)))
6925 ;; Loading `help-mode' here is necessary if `describe-bindings'
6926 ;; is replaced with something, e.g. `helm-descbinds'.
6927 (require 'help-mode)
6928 (with-current-buffer (let (help-xref-following) (help-buffer))
6929 (setq help-xref-stack-item item)))))
6931 (defun gnus-article-reply-with-original (&optional wide)
6932 "Start composing a reply mail to the current message.
6933 The text in the region will be yanked. If the region isn't active,
6934 the entire article will be yanked."
6935 (interactive)
6936 (let ((article (cdr gnus-article-current))
6937 contents)
6938 (if (not (and transient-mark-mode mark-active))
6939 (with-current-buffer gnus-summary-buffer
6940 (gnus-summary-reply (list (list article)) wide))
6941 (setq contents (buffer-substring (point) (mark t)))
6942 ;; Deactivate active regions.
6943 (when transient-mark-mode
6944 (setq mark-active nil))
6945 (with-current-buffer gnus-summary-buffer
6946 (gnus-summary-reply
6947 (list (list article contents)) wide)))))
6949 (defun gnus-article-wide-reply-with-original ()
6950 "Start composing a wide reply mail to the current message.
6951 The text in the region will be yanked. If the region isn't active,
6952 the entire article will be yanked."
6953 (interactive)
6954 (gnus-article-reply-with-original t))
6956 (defun gnus-article-followup-with-original ()
6957 "Compose a followup to the current article.
6958 The text in the region will be yanked. If the region isn't active,
6959 the entire article will be yanked."
6960 (interactive)
6961 (let ((article (cdr gnus-article-current))
6962 contents)
6963 (if (not (and transient-mark-mode mark-active))
6964 (with-current-buffer gnus-summary-buffer
6965 (gnus-summary-followup (list (list article))))
6966 (setq contents (buffer-substring (point) (mark t)))
6967 ;; Deactivate active regions.
6968 (when transient-mark-mode
6969 (setq mark-active nil))
6970 (with-current-buffer gnus-summary-buffer
6971 (gnus-summary-followup
6972 (list (list article contents)))))))
6974 (defun gnus-article-hide (&optional arg force)
6975 "Hide all the gruft in the current article.
6976 This means that signatures, cited text and (some) headers will be
6977 hidden.
6978 If given a prefix, show the hidden text instead."
6979 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6980 (gnus-with-article-buffer
6981 (article-hide-headers arg)
6982 (article-hide-list-identifiers)
6983 (gnus-article-hide-citation-maybe arg force)
6984 (article-hide-signature arg)))
6986 (defun gnus-check-group-server ()
6987 ;; Make sure the connection to the server is alive.
6988 (unless (gnus-server-opened
6989 (gnus-find-method-for-group gnus-newsgroup-name))
6990 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6991 (gnus-request-group gnus-newsgroup-name t)))
6993 (declare-function nneething-get-file-name "nneething" (id))
6995 (defun gnus-request-article-this-buffer (article group)
6996 "Get an article and insert it into this buffer."
6997 (let (do-update-line sparse-header)
6998 (prog1
6999 (save-excursion
7000 (erase-buffer)
7001 (gnus-kill-all-overlays)
7002 (setq group (or group gnus-newsgroup-name))
7004 ;; Using `gnus-request-article' directly will insert the article into
7005 ;; `nntp-server-buffer' - so we'll save some time by not having to
7006 ;; copy it from the server buffer into the article buffer.
7008 ;; We only request an article by message-id when we do not have the
7009 ;; headers for it, so we'll have to get those.
7010 (when (stringp article)
7011 (gnus-read-header article))
7013 ;; If the article number is negative, that means that this article
7014 ;; doesn't belong in this newsgroup (possibly), so we find its
7015 ;; message-id and request it by id instead of number.
7016 (when (and (numberp article)
7017 gnus-summary-buffer
7018 (get-buffer gnus-summary-buffer)
7019 (gnus-buffer-exists-p gnus-summary-buffer))
7020 (with-current-buffer gnus-summary-buffer
7021 (let ((header (gnus-summary-article-header article)))
7022 (when (< article 0)
7023 (cond
7024 ((memq article gnus-newsgroup-sparse)
7025 ;; This is a sparse gap article.
7026 (setq do-update-line article)
7027 (setq gnus-newsgroup-sparse
7028 (delq article gnus-newsgroup-sparse))
7029 (setq article (mail-header-id header))
7030 (setq sparse-header (gnus-read-header article)))
7031 ((vectorp header)
7032 ;; It's a real article.
7033 (setq article (mail-header-id header)))
7035 ;; It is an extracted pseudo-article.
7036 (setq article 'pseudo)
7037 (gnus-request-pseudo-article header))))
7039 (let ((method (gnus-find-method-for-group
7040 gnus-newsgroup-name)))
7041 (when (and (eq (car method) 'nneething)
7042 (vectorp header))
7043 (let ((dir (nneething-get-file-name
7044 (mail-header-id header))))
7045 (when (and (stringp dir)
7046 (file-directory-p dir))
7047 (setq article 'nneething)
7048 (gnus-group-enter-directory dir))))))))
7050 (cond
7051 ;; Refuse to select canceled articles.
7052 ((and (numberp article)
7053 gnus-summary-buffer
7054 (get-buffer gnus-summary-buffer)
7055 (gnus-buffer-exists-p gnus-summary-buffer)
7056 (eq (cdr (with-current-buffer gnus-summary-buffer
7057 (assq article gnus-newsgroup-reads)))
7058 gnus-canceled-mark))
7059 nil)
7060 ;; We first check `gnus-original-article-buffer'.
7061 ((and (get-buffer gnus-original-article-buffer)
7062 (numberp article)
7063 (with-current-buffer gnus-original-article-buffer
7064 (and (equal (car gnus-original-article) group)
7065 (eq (cdr gnus-original-article) article))))
7066 ;; `insert-buffer-substring' would incorrectly use the
7067 ;; equivalent of string-make-multibyte which amount to decoding
7068 ;; with locale-coding-system, causing failure of
7069 ;; subsequent decoding.
7070 (insert (string-to-multibyte
7071 (with-current-buffer gnus-original-article-buffer
7072 (buffer-substring (point-min) (point-max)))))
7073 'article)
7074 ;; Check the backlog.
7075 ((and gnus-keep-backlog
7076 (gnus-backlog-request-article group article (current-buffer)))
7077 'article)
7078 ;; Check asynchronous pre-fetch.
7079 ((gnus-async-request-fetched-article group article (current-buffer))
7080 (gnus-async-prefetch-next group article gnus-summary-buffer)
7081 (when (and (numberp article) gnus-keep-backlog)
7082 (gnus-backlog-enter-article group article (current-buffer)))
7083 'article)
7084 ;; Check the cache.
7085 ((and gnus-use-cache
7086 (numberp article)
7087 (gnus-cache-request-article article group))
7088 'article)
7089 ;; Check the agent cache.
7090 ((gnus-agent-request-article article group)
7091 'article)
7092 ;; Get the article and put into the article buffer.
7093 ((or (stringp article)
7094 (numberp article))
7095 (let ((gnus-override-method gnus-override-method)
7096 (methods (and (stringp article)
7097 (with-current-buffer gnus-summary-buffer
7098 (gnus-refer-article-methods))))
7099 (backend (car (gnus-find-method-for-group
7100 gnus-newsgroup-name)))
7101 result
7102 (inhibit-read-only t))
7103 (when (and (null gnus-override-method)
7104 methods)
7105 (setq gnus-override-method (pop methods)))
7106 (while (not result)
7107 (erase-buffer)
7108 (gnus-kill-all-overlays)
7109 (let ((gnus-newsgroup-name group))
7110 (gnus-check-group-server))
7111 (cond
7112 ((gnus-request-article article group (current-buffer))
7113 (when (numberp article)
7114 (gnus-async-prefetch-next group article
7115 gnus-summary-buffer)
7116 (when gnus-keep-backlog
7117 (gnus-backlog-enter-article
7118 group article (current-buffer)))
7119 (when (and gnus-agent
7120 (gnus-agent-group-covered-p group))
7121 (gnus-agent-store-article article group)))
7122 (setq result 'article))
7123 (methods
7124 (setq gnus-override-method (pop methods)))
7125 ((not (string-match "^400 "
7126 (nnheader-get-report backend)))
7127 ;; If we get 400 server disconnect, reconnect and
7128 ;; retry; otherwise, assume the article has expired.
7129 (setq result 'done))))
7130 (and (eq result 'article) 'article)))
7131 ;; It was a pseudo.
7132 (t article)))
7134 ;; Associate this article with the current summary buffer.
7135 (setq gnus-article-current-summary gnus-summary-buffer)
7137 ;; Take the article from the original article buffer
7138 ;; and place it in the buffer it's supposed to be in.
7139 (when (and (get-buffer gnus-article-buffer)
7140 (equal (buffer-name (current-buffer))
7141 (buffer-name (get-buffer gnus-article-buffer))))
7142 (save-excursion
7143 (if (get-buffer gnus-original-article-buffer)
7144 (set-buffer gnus-original-article-buffer)
7145 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7146 (buffer-disable-undo)
7147 (setq major-mode 'gnus-original-article-mode)
7148 (setq buffer-read-only t))
7149 (let ((inhibit-read-only t))
7150 (erase-buffer)
7151 (insert-buffer-substring gnus-article-buffer))
7152 (setq gnus-original-article (cons group article)))
7154 ;; Decode charsets.
7155 (run-hooks 'gnus-article-decode-hook)
7156 ;; Mark article as decoded or not.
7157 (setq gnus-article-decoded-p gnus-article-decode-hook))
7159 ;; Update sparse articles.
7160 (when (and do-update-line
7161 (or (numberp article)
7162 (stringp article)))
7163 (let ((buf (current-buffer)))
7164 (set-buffer gnus-summary-buffer)
7165 (gnus-summary-update-article do-update-line sparse-header)
7166 (gnus-summary-goto-subject do-update-line nil t)
7167 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7168 (point))
7169 (set-buffer buf))))))
7171 (defun gnus-block-private-groups (group)
7172 "Allows images in newsgroups to be shown, blocks images in all
7173 other groups."
7174 (if (or (gnus-news-group-p group)
7175 (gnus-member-of-valid 'global group))
7176 ;; Block nothing in news groups.
7178 ;; Block everything anywhere else.
7179 "."))
7181 (defun gnus-blocked-images ()
7182 (if (functionp gnus-blocked-images)
7183 (funcall gnus-blocked-images gnus-newsgroup-name)
7184 gnus-blocked-images))
7187 ;;; Article editing
7190 (defcustom gnus-article-edit-mode-hook nil
7191 "Hook run in article edit mode buffers."
7192 :group 'gnus-article-various
7193 :type 'hook)
7195 (defvar gnus-article-edit-done-function nil)
7197 (defvar gnus-article-edit-mode-map nil)
7199 ;; Should we be using derived.el for this?
7200 (unless gnus-article-edit-mode-map
7201 (setq gnus-article-edit-mode-map (make-keymap))
7202 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7204 (gnus-define-keys gnus-article-edit-mode-map
7205 "\C-c?" describe-mode
7206 "\C-c\C-c" gnus-article-edit-done
7207 "\C-c\C-k" gnus-article-edit-exit
7208 "\C-c\C-f\C-t" message-goto-to
7209 "\C-c\C-f\C-o" message-goto-from
7210 "\C-c\C-f\C-b" message-goto-bcc
7211 ;;"\C-c\C-f\C-w" message-goto-fcc
7212 "\C-c\C-f\C-c" message-goto-cc
7213 "\C-c\C-f\C-s" message-goto-subject
7214 "\C-c\C-f\C-r" message-goto-reply-to
7215 "\C-c\C-f\C-n" message-goto-newsgroups
7216 "\C-c\C-f\C-d" message-goto-distribution
7217 "\C-c\C-f\C-f" message-goto-followup-to
7218 "\C-c\C-f\C-m" message-goto-mail-followup-to
7219 "\C-c\C-f\C-k" message-goto-keywords
7220 "\C-c\C-f\C-u" message-goto-summary
7221 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7222 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7223 "\C-c\C-b" message-goto-body
7224 "\C-c\C-i" message-goto-signature
7226 "\C-c\C-t" message-insert-to
7227 "\C-c\C-n" message-insert-newsgroups
7228 "\C-c\C-o" message-sort-headers
7229 "\C-c\C-e" message-elide-region
7230 "\C-c\C-v" message-delete-not-region
7231 "\C-c\C-z" message-kill-to-signature
7232 "\M-\r" message-newline-and-reformat
7233 "\C-c\C-a" mml-attach-file
7234 "\C-a" message-beginning-of-line
7235 "\t" message-tab
7236 "\M-;" comment-region)
7238 (gnus-define-keys (gnus-article-edit-wash-map
7239 "\C-c\C-w" gnus-article-edit-mode-map)
7240 "f" gnus-article-edit-full-stops))
7242 (easy-menu-define
7243 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7244 '("Field"
7245 ["Fetch To" message-insert-to t]
7246 ["Fetch Newsgroups" message-insert-newsgroups t]
7247 "----"
7248 ["To" message-goto-to t]
7249 ["From" message-goto-from t]
7250 ["Subject" message-goto-subject t]
7251 ["Cc" message-goto-cc t]
7252 ["Reply-To" message-goto-reply-to t]
7253 ["Summary" message-goto-summary t]
7254 ["Keywords" message-goto-keywords t]
7255 ["Newsgroups" message-goto-newsgroups t]
7256 ["Followup-To" message-goto-followup-to t]
7257 ["Mail-Followup-To" message-goto-mail-followup-to t]
7258 ["Distribution" message-goto-distribution t]
7259 ["Body" message-goto-body t]
7260 ["Signature" message-goto-signature t]))
7262 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7263 "Major mode for editing articles.
7264 This is an extended text-mode.
7266 \\{gnus-article-edit-mode-map}"
7267 (make-local-variable 'gnus-article-edit-done-function)
7268 (make-local-variable 'gnus-prev-winconf)
7269 (set (make-local-variable 'font-lock-defaults)
7270 '(message-font-lock-keywords t))
7271 (set (make-local-variable 'mail-header-separator) "")
7272 (set (make-local-variable 'gnus-article-edit-mode) t)
7273 (easy-menu-add message-mode-field-menu message-mode-map)
7274 (mml-mode)
7275 (setq buffer-read-only nil)
7276 (buffer-enable-undo)
7277 (widen))
7279 (defun gnus-article-edit (&optional force)
7280 "Edit the current article.
7281 This will have permanent effect only in mail groups.
7282 If FORCE is non-nil, allow editing of articles even in read-only
7283 groups."
7284 (interactive "P")
7285 (when (and (not force)
7286 (gnus-group-read-only-p))
7287 (error "The current newsgroup does not support article editing"))
7288 (gnus-with-article-buffer
7289 (article-date-original))
7290 (gnus-article-edit-article
7291 'ignore
7292 `(lambda (no-highlight)
7293 'ignore
7294 (gnus-summary-edit-article-done
7295 ,(or (mail-header-references gnus-current-headers) "")
7296 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7298 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7299 "Start editing the contents of the current article buffer."
7300 (let ((winconf (current-window-configuration)))
7301 (set-buffer gnus-article-buffer)
7302 (let ((message-auto-save-directory
7303 ;; Don't associate the article buffer with a draft file.
7304 nil))
7305 (gnus-article-edit-mode))
7306 (funcall start-func)
7307 (set-buffer-modified-p nil)
7308 (gnus-configure-windows 'edit-article)
7309 (setq gnus-article-edit-done-function exit-func)
7310 (setq gnus-prev-winconf winconf)
7311 (unless quiet
7312 (gnus-message 6 "C-c C-c to end edits"))))
7314 (defun gnus-article-edit-done (&optional arg)
7315 "Update the article edits and exit."
7316 (interactive "P")
7317 (let ((func gnus-article-edit-done-function)
7318 (buf (current-buffer))
7319 (start (window-start))
7320 (winconf gnus-prev-winconf))
7321 (widen) ;; Widen it in case that users narrowed the buffer.
7322 (funcall func arg)
7323 (set-buffer buf)
7324 ;; The cache and backlog have to be flushed somewhat.
7325 (when gnus-keep-backlog
7326 (gnus-backlog-remove-article
7327 (car gnus-article-current) (cdr gnus-article-current)))
7328 ;; Flush original article as well.
7329 (gnus-flush-original-article-buffer)
7330 (when gnus-use-cache
7331 (gnus-cache-update-article
7332 (car gnus-article-current) (cdr gnus-article-current)))
7333 ;; We remove all text props from the article buffer.
7334 (kill-all-local-variables)
7335 (set-text-properties (point-min) (point-max) nil)
7336 (gnus-article-mode)
7337 (set-window-configuration winconf)
7338 (set-buffer buf)
7339 (set-window-start (get-buffer-window buf) start)
7340 (set-window-point (get-buffer-window buf) (point)))
7341 (gnus-summary-show-article))
7343 (defun gnus-flush-original-article-buffer ()
7344 (when (get-buffer gnus-original-article-buffer)
7345 (with-current-buffer gnus-original-article-buffer
7346 (setq gnus-original-article nil))))
7348 (defun gnus-article-edit-exit ()
7349 "Exit the article editing without updating."
7350 (interactive)
7351 (when (or (not (buffer-modified-p))
7352 (yes-or-no-p "Article modified; kill anyway? "))
7353 (let ((curbuf (current-buffer))
7354 (p (point))
7355 (window-start (window-start)))
7356 (erase-buffer)
7357 (if (gnus-buffer-live-p gnus-original-article-buffer)
7358 (insert-buffer-substring gnus-original-article-buffer))
7359 (let ((winconf gnus-prev-winconf))
7360 (kill-all-local-variables)
7361 (gnus-article-mode)
7362 (set-window-configuration winconf)
7363 ;; Tippy-toe some to make sure that point remains where it was.
7364 (save-current-buffer
7365 (set-buffer curbuf)
7366 (set-window-start (get-buffer-window (current-buffer)) window-start)
7367 (goto-char p))))
7368 (gnus-summary-show-article)))
7370 (defun gnus-article-edit-full-stops ()
7371 "Interactively repair spacing at end of sentences."
7372 (interactive)
7373 (save-excursion
7374 (goto-char (point-min))
7375 (search-forward-regexp "^$" nil t)
7376 (let ((case-fold-search nil))
7377 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7380 ;;; Article highlights
7383 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7385 ;;; Internal Variables:
7387 (defcustom gnus-button-url-regexp
7388 (concat
7389 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7390 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7391 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7392 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7393 (punct "!?:;.,"))
7394 (concat
7395 "\\(?:"
7396 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7397 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7398 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7399 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7400 "\\|"
7401 "[" chars punct "]+" "[" chars "]"
7402 "\\)"))
7403 "\\)")
7404 "Regular expression that matches URLs."
7405 :version "24.4"
7406 :group 'gnus-article-buttons
7407 :type 'regexp)
7409 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7410 "Regular expression that matches a valid FQDN."
7411 :version "26.1"
7412 :group 'gnus-article-buttons
7413 :type 'regexp)
7415 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7416 (defcustom gnus-button-valid-localpart-regexp
7417 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7418 "Regular expression that matches a localpart of mail addresses or MIDs."
7419 :version "22.1"
7420 :group 'gnus-article-buttons
7421 :type 'regexp)
7423 (defcustom gnus-button-man-handler 'manual-entry
7424 "Function to use for displaying man pages.
7425 The function must take at least one argument with a string naming the
7426 man page."
7427 :version "22.1"
7428 :type '(choice (function-item :tag "Man" manual-entry)
7429 (function-item :tag "Woman" woman)
7430 (function :tag "Other"))
7431 :group 'gnus-article-buttons)
7433 (defcustom gnus-button-mid-or-mail-regexp
7434 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7435 gnus-button-valid-fqdn-regexp
7436 ">?\\)\\b")
7437 "Regular expression that matches a message ID or a mail address."
7438 :version "22.1"
7439 :group 'gnus-article-buttons
7440 :type 'regexp)
7442 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7443 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7444 Strings like this can be either a message ID or a mail address. If it is one
7445 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7446 message ID or a mail address, respectively. If this variable is set to the
7447 symbol `ask', always query the user what do do. If it is a function, this
7448 function will be called with the string as its only argument. The function
7449 must return `mid', `mail', `invalid' or `ask'."
7450 :version "22.1"
7451 :group 'gnus-article-buttons
7452 :type '(choice (function-item :tag "Heuristic function"
7453 gnus-button-mid-or-mail-heuristic)
7454 (const ask)
7455 (const mid)
7456 (const mail)))
7458 (defcustom gnus-button-mid-or-mail-heuristic-alist
7459 '((-10.0 . ".+\\$.+@")
7460 (-10.0 . "#")
7461 (-10.0 . "\\*")
7462 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7463 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7464 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7465 (-1.0 . "^[^a-z]+@")
7467 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7468 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7469 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7470 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7472 (-2.0 . "^[0-9]")
7473 (-1.0 . "^[0-9][0-9]")
7475 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7476 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7477 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7478 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7480 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7481 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7482 ;; "[0-9]{8,}.*\@"
7483 (-3.0
7484 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7485 ;; "[0-9]{12,}.*\@"
7486 ;; compensation for TDMA dated mail addresses:
7487 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7489 (-20.0 . "\\.fsf@") ;; Gnus
7490 (-20.0 . "^slrn")
7491 (-20.0 . "^Pine")
7492 (-20.0 . "^alpine\\.")
7493 (-20.0 . "_-_") ;; Subject change in thread
7495 (-20.0 . "\\.ln@") ;; leafnode
7496 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7497 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7499 ;; (5.0 . "") ;; $local_part_len <= 7
7500 (10.0 . "^[^0-9]+@")
7501 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7502 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7503 (3.0 . "@stud")
7505 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7507 (0.5 . "^[A-Z][a-z]")
7508 (0.5 . "^[A-Z][a-z][a-z]")
7509 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7510 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7511 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7513 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7514 address. The REGEXP is processed with `case-fold-search' set to nil."
7515 :version "22.1"
7516 :group 'gnus-article-buttons
7517 :type '(repeat (cons (number :tag "Rate")
7518 (regexp :tag "Regexp"))))
7520 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7521 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7522 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7523 address, `ask' if unsure and `invalid' if the string is invalid."
7524 (let ((case-fold-search nil)
7525 (list gnus-button-mid-or-mail-heuristic-alist)
7526 (result 0) rate regexp lpartlen elem)
7527 (setq lpartlen
7528 (length (replace-regexp-in-string "^\\(.*\\)@.*$" "\\1" mid-or-mail)))
7529 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7530 ;; Certain special cases...
7531 (when (string-match
7532 (concat
7533 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7534 "^[0-9]+\\.[0-9]+@compuserve\\|"
7535 "@public\\.gmane\\.org")
7536 mid-or-mail)
7537 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7538 (setq result 'mail))
7539 (when (string-match "@.*@\\| " mid-or-mail)
7540 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7541 (setq result 'invalid))
7542 ;; Nothing more to do, if result is not a number here...
7543 (when (numberp result)
7544 (while list
7545 (setq elem (car list)
7546 rate (car elem)
7547 regexp (cdr elem)
7548 list (cdr list))
7549 (when (string-match regexp mid-or-mail)
7550 (setq result (+ result rate))
7551 (gnus-message
7552 9 "`%s' matched `%s', rate `%s', result `%s'."
7553 mid-or-mail regexp rate result)))
7554 (when (<= lpartlen 7)
7555 (setq result (+ result 5.0))
7556 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7557 mid-or-mail result))
7558 (when (>= lpartlen 12)
7559 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7560 (cond
7561 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7562 ;; Long local part should contain realname if e-mail address,
7563 ;; too many digits: message-id.
7564 ;; $score -= 5.0 + 0.1 * $local_part_len;
7565 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7566 (setq result (+ result rate))
7567 (gnus-message
7568 9 "Many digits in `%s', rate `%s', result `%s'."
7569 mid-or-mail rate result))
7570 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7571 mid-or-mail)
7572 ;; Too few vowels [^aeiouy]{4,}.*@
7573 (setq result (+ result -5.0))
7574 (gnus-message
7575 9 "Few vowels in `%s', rate `%s', result `%s'."
7576 mid-or-mail -5.0 result))
7578 (setq result (+ result 5.0))
7579 (gnus-message
7580 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7581 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7582 ;; Maybe we should make this a customizable alist: (condition . 'result)
7583 (cond
7584 ((symbolp result) result)
7585 ;; Now convert number into proper results:
7586 ((< result -10.0) 'mid)
7587 ((> result 10.0) 'mail)
7588 (t 'ask))))
7590 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7591 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7592 (url-mid (concat "news" ":" mid-or-mail))
7593 (url-mailto (concat "mailto" ":" mid-or-mail)))
7594 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7595 (when (fboundp pref)
7596 (setq guessed
7597 ;; get rid of surrounding angles...
7598 (funcall pref
7599 (replace-regexp-in-string "^<\\|>$" "" mid-or-mail)))
7600 (if (or (eq 'mid guessed) (eq 'mail guessed))
7601 (setq pref guessed)
7602 (setq pref 'ask)))
7603 (if (eq pref 'ask)
7604 (save-window-excursion
7605 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7606 (setq pref 'mail)
7607 (setq pref 'mid))))
7608 (cond ((eq pref 'mid)
7609 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7610 (gnus-button-handle-news url-mid))
7611 ((eq pref 'mail)
7612 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7613 (gnus-url-mailto url-mailto))
7614 (t (gnus-message 3 "Invalid string.")))))
7616 (defun gnus-button-handle-custom (fun arg)
7617 "Call function FUN on argument ARG.
7618 Both FUN and ARG are supposed to be strings. ARG will be passed
7619 as a symbol to FUN."
7620 (funcall (intern fun)
7621 (if (string-match "^customize-apropos" fun)
7623 (intern arg))))
7625 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7627 (defun gnus-button-handle-describe-function (url)
7628 "Call `describe-function' when pushing the corresponding URL button."
7629 (describe-function
7630 (intern
7631 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7633 (defun gnus-button-handle-describe-variable (url)
7634 "Call `describe-variable' when pushing the corresponding URL button."
7635 (describe-variable
7636 (intern
7637 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7639 (defun gnus-button-handle-symbol (url)
7640 "Display help on variable or function.
7641 Calls `describe-variable' or `describe-function'."
7642 (let ((sym (intern url)))
7643 (cond
7644 ((fboundp sym) (describe-function sym))
7645 ((boundp sym) (describe-variable sym))
7646 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7648 (defun gnus-button-handle-describe-key (url)
7649 "Call `describe-key' when pushing the corresponding URL button."
7650 (let* ((key-string
7651 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))
7652 (keys (ignore-errors (eval `(kbd ,key-string)))))
7653 (if keys
7654 (describe-key keys)
7655 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7657 (defun gnus-button-handle-apropos (url)
7658 "Call `apropos' when pushing the corresponding URL button."
7659 (apropos (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7661 (defun gnus-button-handle-apropos-command (url)
7662 "Call `apropos' when pushing the corresponding URL button."
7663 (apropos-command
7664 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7666 (defun gnus-button-handle-apropos-variable (url)
7667 "Call `apropos' when pushing the corresponding URL button."
7668 (apropos-variable
7669 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7671 (defun gnus-button-handle-apropos-documentation (url)
7672 "Call `apropos' when pushing the corresponding URL button."
7673 (apropos-documentation
7674 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7676 (defun gnus-button-handle-library (url)
7677 "Call `locate-library' when pushing the corresponding URL button."
7678 (gnus-message 9 "url=`%s'" url)
7679 (let* ((lib (locate-library url))
7680 (file (replace-regexp-in-string "\\.elc" ".el" (or lib ""))))
7681 (if (not lib)
7682 (gnus-message 1 "Cannot locate library `%s'." url)
7683 (find-file-read-only file))))
7685 (defcustom gnus-button-man-level 5
7686 "Integer that says how many man-related buttons Gnus will show.
7687 The higher the number, the more buttons will appear and the more false
7688 positives are possible. Note that you can set this variable local to
7689 specific groups. Setting it higher in Unix groups is probably a good idea.
7690 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7691 how to set variables in specific groups."
7692 :version "22.1"
7693 :group 'gnus-article-buttons
7694 :link '(custom-manual "(gnus)Group Parameters")
7695 :type 'integer)
7697 (defcustom gnus-button-emacs-level 5
7698 "Integer that says how many emacs-related buttons Gnus will show.
7699 The higher the number, the more buttons will appear and the more false
7700 positives are possible. Note that you can set this variable local to
7701 specific groups. Setting it higher in Emacs or Gnus related groups is
7702 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7703 `gnus-parameters' on how to set variables in specific groups."
7704 :version "22.1"
7705 :group 'gnus-article-buttons
7706 :link '(custom-manual "(gnus)Group Parameters")
7707 :type 'integer)
7709 (defcustom gnus-button-message-level 5
7710 "Integer that says how many buttons for news or mail messages will appear.
7711 The higher the number, the more buttons will appear and the more false
7712 positives are possible."
7713 ;; mail addresses, MIDs, URLs for news, ...
7714 :version "22.1"
7715 :group 'gnus-article-buttons
7716 :type 'integer)
7718 (defcustom gnus-button-browse-level 5
7719 "Integer that says how many buttons for browsing will appear.
7720 The higher the number, the more buttons will appear and the more false
7721 positives are possible."
7722 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7723 :version "22.1"
7724 :group 'gnus-article-buttons
7725 :type 'integer)
7727 (defcustom gnus-button-alist
7728 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7729 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7730 ((concat "\\b\\(nntp\\|news\\):\\("
7731 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7732 0 t gnus-button-handle-news 2)
7733 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7734 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7735 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7736 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7737 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7738 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7739 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7740 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7741 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7742 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7743 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7744 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7745 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7746 ;; RFC 2368 (The mailto URL scheme)
7747 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7748 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7749 ("\\bmailto:\\([^ \n\t]+\\)"
7750 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7751 ;; Info Konqueror style <info:/foo/bar baz>.
7752 ;; Must come before " Gnus home-grown style".
7753 ("\\binfo://?\\([^'\">\n\t]+\\)"
7754 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7755 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7756 ("\\binfo://\\([^'\">\n\t ]+\\)"
7757 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7758 ;; Info GNOME style <info:foo#bar_baz>
7759 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7760 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7761 ;; Info KDE style <info:(foo)bar baz>
7762 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7763 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7764 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7765 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7766 ("\\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,]*\\)\\)?"
7767 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7768 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7769 ;; This is custom
7770 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7771 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7772 ;; Emacs help commands
7773 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7774 ;; regexp doesn't match arguments containing ` '.
7775 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7776 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7777 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7778 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7779 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7780 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7781 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7782 ;; The following entries may lead to many false positives so don't enable
7783 ;; them by default (use a high button level).
7784 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7785 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7786 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7787 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7788 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7789 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7790 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7791 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7792 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7793 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7794 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7795 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7796 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7797 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7798 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7799 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7801 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7802 ;; Unlike the other regexps we really have to require quoting
7803 ;; here to determine where it ends.
7804 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7805 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7806 ("<URL: *\\([^\n<>]*\\)>"
7807 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7808 ;; RFC 2396 (2.4.3., delims) ...
7809 ("\"URL: *\\([^\n\"]*\\)\""
7810 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7811 ;; Raw URLs.
7812 (gnus-button-url-regexp
7813 0 (>= gnus-button-browse-level 0) browse-url 0)
7814 ;; man pages
7815 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7816 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7817 gnus-button-handle-man 1)
7818 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7819 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7820 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7821 gnus-button-handle-man 1)
7822 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7823 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7824 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7825 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7826 ;; Recognizing patches to .el files. This is somewhat obscure,
7827 ;; but considering the percentage of Gnus users who hack Emacs
7828 ;; Lisp files...
7829 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7830 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7831 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7832 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7833 ;; MID or mail: To avoid too many false positives we don't try to catch
7834 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7835 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7836 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7837 ;; so that non-ambiguous entries (see above) match first.
7838 (gnus-button-mid-or-mail-regexp
7839 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7840 "Alist of regexps matching buttons in article bodies.
7842 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7843 REGEXP: is the string (case insensitive) matching text around the button (can
7844 also be Lisp expression evaluating to a string),
7845 BUTTON: is the number of the regexp grouping actually matching the button,
7846 FORM: is a Lisp expression which must eval to true for the button to
7847 be added,
7848 CALLBACK: is the function to call when the user push this button, and each
7849 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7851 CALLBACK can also be a variable, in that case the value of that
7852 variable it the real callback function."
7853 :group 'gnus-article-buttons
7854 :type '(repeat (list (choice regexp variable sexp)
7855 (integer :tag "Button")
7856 (sexp :tag "Form")
7857 (function :tag "Callback")
7858 (repeat :tag "Par"
7859 :inline t
7860 (integer :tag "Regexp group")))))
7861 (put 'gnus-button-alist 'risky-local-variable t)
7863 (defcustom gnus-header-button-alist
7864 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7865 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7866 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7867 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7868 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7869 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7870 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7871 0 (>= gnus-button-browse-level 0) browse-url 0)
7872 ("^Subject:" gnus-button-url-regexp
7873 0 (>= gnus-button-browse-level 0) browse-url 0)
7874 ("^[^:]+:" gnus-button-url-regexp
7875 0 (>= gnus-button-browse-level 0) browse-url 0)
7876 ("^OpenPGP:.*url=" gnus-button-url-regexp
7877 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7878 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7879 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7880 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7881 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7882 "Alist of headers and regexps to match buttons in article heads.
7884 This alist is very similar to `gnus-button-alist', except that each
7885 alist has an additional HEADER element first in each entry:
7887 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7889 HEADER is a regexp to match a header. For a fuller explanation, see
7890 `gnus-button-alist'."
7891 :group 'gnus-article-buttons
7892 :group 'gnus-article-headers
7893 :type '(repeat (list (regexp :tag "Header")
7894 (choice regexp variable)
7895 (integer :tag "Button")
7896 (sexp :tag "Form")
7897 (function :tag "Callback")
7898 (repeat :tag "Par"
7899 :inline t
7900 (integer :tag "Regexp group")))))
7901 (put 'gnus-header-button-alist 'risky-local-variable t)
7903 ;;; Commands:
7905 (defun gnus-article-push-button (event)
7906 "Check text under the mouse pointer for a callback function.
7907 If the text under the mouse pointer has a `gnus-callback' property,
7908 call it with the value of the `gnus-data' text property."
7909 (interactive "e")
7910 (set-buffer (window-buffer (posn-window (event-start event))))
7911 (let* ((pos (posn-point (event-start event)))
7912 (data (get-text-property pos 'gnus-data))
7913 (fun (get-text-property pos 'gnus-callback)))
7914 (goto-char pos)
7915 (when fun
7916 (funcall fun data))))
7918 (defun gnus-article-press-button ()
7919 "Check text at point for a callback function.
7920 If the text at point has a `gnus-callback' property,
7921 call it with the value of the `gnus-data' text property."
7922 (interactive)
7923 (let ((data (get-text-property (point) 'gnus-data))
7924 (fun (get-text-property (point) 'gnus-callback)))
7925 (when fun
7926 (funcall fun data))))
7928 (defun gnus-article-highlight (&optional force)
7929 "Highlight current article.
7930 This function calls `gnus-article-highlight-headers',
7931 `gnus-article-highlight-citation',
7932 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7933 do the highlighting. See the documentation for those functions."
7934 (interactive (list 'force))
7935 (gnus-article-highlight-headers)
7936 (gnus-article-highlight-citation force)
7937 (gnus-article-highlight-signature)
7938 (gnus-article-add-buttons)
7939 (gnus-article-add-buttons-to-head))
7941 (defun gnus-article-highlight-some (&optional _force)
7942 "Highlight current article.
7943 This function calls `gnus-article-highlight-headers',
7944 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7945 do the highlighting. See the documentation for those functions."
7946 (interactive (list 'force))
7947 (gnus-article-highlight-headers)
7948 (gnus-article-highlight-signature)
7949 (gnus-article-add-buttons))
7951 (defun gnus-article-highlight-headers ()
7952 "Highlight article headers as specified by `gnus-header-face-alist'."
7953 (interactive)
7954 (gnus-with-article-headers
7955 (let (regexp header-face field-face from hpoints fpoints)
7956 (dolist (entry gnus-header-face-alist)
7957 (goto-char (point-min))
7958 (setq regexp (concat "^\\("
7959 (if (string-equal "" (nth 0 entry))
7960 "[^\t ]"
7961 (nth 0 entry))
7962 "\\)")
7963 header-face (nth 1 entry)
7964 field-face (nth 2 entry))
7965 (while (and (re-search-forward regexp nil t)
7966 (not (eobp)))
7967 (beginning-of-line)
7968 (setq from (point))
7969 (unless (search-forward ":" nil t)
7970 (forward-char 1))
7971 (when (and header-face
7972 (not (memq (point) hpoints)))
7973 (push (point) hpoints)
7974 (put-text-property from (point) 'face header-face))
7975 (when (and field-face
7976 (not (memq (setq from (point)) fpoints)))
7977 (push from fpoints)
7978 (if (re-search-forward "^[^ \t]" nil t)
7979 (forward-char -2)
7980 (goto-char (point-max)))
7981 (put-text-property from (point) 'face field-face)))))))
7983 (defun gnus-article-highlight-signature ()
7984 "Highlight the signature in an article.
7985 It does this by highlighting everything after
7986 `gnus-signature-separator' using the face `gnus-signature'."
7987 (interactive)
7988 (gnus-with-article-buffer
7989 (let ((inhibit-point-motion-hooks t))
7990 (save-restriction
7991 (when (and gnus-signature-face
7992 (gnus-article-narrow-to-signature))
7993 (overlay-put (make-overlay (point-min) (point-max) nil t)
7994 'face gnus-signature-face)
7995 (widen)
7996 (gnus-article-search-signature)
7997 (let ((start (match-beginning 0))
7998 (end (set-marker (make-marker) (1+ (match-end 0)))))
7999 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8000 end)))))))
8002 (defun gnus-button-in-region-p (b e prop)
8003 "Say whether PROP exists in the region."
8004 (text-property-not-all b e prop nil))
8006 (defun gnus-article-add-buttons ()
8007 "Find external references in the article and make buttons of them.
8008 \"External references\" are things like Message-IDs and URLs, as
8009 specified by `gnus-button-alist'."
8010 (interactive)
8011 (gnus-with-article-buffer
8012 (let ((inhibit-point-motion-hooks t)
8013 (case-fold-search t)
8014 (alist gnus-button-alist)
8015 beg entry regexp)
8016 ;; We skip the headers.
8017 (article-goto-body)
8018 (setq beg (point))
8019 (while (setq entry (pop alist))
8020 (setq regexp (eval (car entry)))
8021 (goto-char beg)
8022 (while (re-search-forward regexp nil t)
8023 (let ((start (match-beginning (nth 1 entry)))
8024 (end (match-end (nth 1 entry)))
8025 (from (match-beginning 0)))
8026 (when (and (eval (nth 2 entry))
8027 (not (gnus-button-in-region-p
8028 start end 'gnus-callback)))
8029 ;; That optional form returned non-nil, so we add the
8030 ;; button.
8031 (setq from (set-marker (make-marker) from))
8032 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8033 (gnus-article-extend-url-button from start end))
8034 (gnus-article-add-button start end
8035 'gnus-button-push (list from entry))
8036 (put-text-property
8037 start end
8038 'gnus-string (buffer-substring-no-properties
8039 start end))))))))))
8041 (defun gnus-article-extend-url-button (beg start end)
8042 "Extend url button if url is folded into two or more lines.
8043 Return non-nil if button is extended. BEG is a marker that points to
8044 the beginning position of a text containing url. START and END are
8045 the endpoints of a url button before it is extended. The concatenated
8046 url is put as the `gnus-button-url' overlay property on the button."
8047 (let ((opoint (point))
8048 (points (list start end))
8049 url delim regexp)
8050 (prog1
8051 (when (and (progn
8052 (goto-char end)
8053 (not (looking-at "[\t ]*[\">]")))
8054 (progn
8055 (goto-char start)
8056 (string-match
8057 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8058 (buffer-substring (point-at-bol) start)))
8059 (progn
8060 (setq url (list (buffer-substring start end))
8061 delim (if (match-beginning 1) ">" "\""))
8062 (beginning-of-line)
8063 (setq regexp (concat
8064 (when (and (looking-at
8065 message-cite-prefix-regexp)
8066 (< (match-end 0) start))
8067 (regexp-quote (match-string 0)))
8069 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8070 delim "\\)"))
8071 (while (progn
8072 (forward-line 1)
8073 (and (looking-at regexp)
8074 (prog1
8075 (match-beginning 1)
8076 (push (or (match-string 2)
8077 (match-string 1))
8078 url)
8079 (push (setq end (or (match-end 2)
8080 (match-end 1)))
8081 points)
8082 (push (or (match-beginning 2)
8083 (match-beginning 1))
8084 points)))))
8085 (match-beginning 2)))
8086 (let (gnus-article-mouse-face widget-mouse-face)
8087 (while points
8088 (gnus-article-add-button (pop points) (pop points)
8089 'gnus-button-push
8090 (list beg (assq 'gnus-button-url-regexp
8091 gnus-button-alist)))))
8092 (let ((overlay (make-overlay start end)))
8093 (overlay-put overlay 'evaporate t)
8094 (overlay-put overlay 'gnus-button-url
8095 (list (mapconcat 'identity (nreverse url) "")))
8096 (when gnus-article-mouse-face
8097 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8099 (goto-char opoint))))
8101 ;; Add buttons to the head of an article.
8102 (defun gnus-article-add-buttons-to-head ()
8103 "Add buttons to the head of the article."
8104 (interactive)
8105 (gnus-with-article-headers
8106 (let (beg end)
8107 (dolist (entry gnus-header-button-alist)
8108 ;; Each alist entry.
8109 (goto-char (point-min))
8110 (while (re-search-forward (car entry) nil t)
8111 ;; Each header matching the entry.
8112 (setq beg (match-beginning 0))
8113 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8114 (match-beginning 0))
8115 (point-max)))
8116 (goto-char beg)
8117 (while (re-search-forward (eval (nth 1 entry)) end t)
8118 ;; Each match within a header.
8119 (let* ((entry (cdr entry))
8120 (start (match-beginning (nth 1 entry)))
8121 (end (match-end (nth 1 entry)))
8122 (form (nth 2 entry)))
8123 (goto-char (match-end 0))
8124 (when (eval form)
8125 (gnus-article-add-button
8126 start end (nth 3 entry)
8127 (buffer-substring (match-beginning (nth 4 entry))
8128 (match-end (nth 4 entry)))))))
8129 (goto-char end))))))
8131 ;;; External functions:
8133 (defun gnus-article-add-button (from to fun &optional data text)
8134 "Create a button between FROM and TO with callback FUN and data DATA."
8135 (when gnus-article-button-face
8136 (overlay-put (make-overlay from to nil t)
8137 'face gnus-article-button-face))
8138 (add-text-properties
8139 from to
8140 (nconc (and gnus-article-mouse-face
8141 (list 'mouse-face gnus-article-mouse-face))
8142 (list 'gnus-callback fun)
8143 (and data (list 'gnus-data data))))
8144 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8145 :help-echo (or text "Follow the link")
8146 :keymap gnus-url-button-map))
8148 (defun gnus-article-copy-string ()
8149 "Copy the string in the button to the kill ring."
8150 (interactive)
8151 (gnus-article-check-buffer)
8152 (let ((data (get-text-property (point) 'gnus-string)))
8153 (when data
8154 (with-temp-buffer
8155 (insert data)
8156 (copy-region-as-kill (point-min) (point-max))
8157 (message "Copied %s" data)))))
8159 ;;; Internal functions:
8161 (defun gnus-article-set-globals ()
8162 (with-current-buffer gnus-summary-buffer
8163 (gnus-set-global-variables)))
8165 (defun gnus-signature-toggle (end)
8166 (gnus-with-article-buffer
8167 (let ((inhibit-point-motion-hooks t))
8168 (if (text-property-any end (point-max) 'article-type 'signature)
8169 (progn
8170 (gnus-delete-wash-type 'signature)
8171 (gnus-remove-text-properties-when
8172 'article-type 'signature end (point-max)
8173 (cons 'article-type (cons 'signature
8174 gnus-hidden-properties))))
8175 (gnus-add-wash-type 'signature)
8176 (gnus-add-text-properties-when
8177 'article-type nil end (point-max)
8178 (cons 'article-type (cons 'signature
8179 gnus-hidden-properties)))))
8180 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8181 (gnus-set-mode-line 'article))))
8183 (defun gnus-button-push (marker-and-entry)
8184 ;; Push button starting at MARKER.
8185 (save-excursion
8186 (let* ((marker (car marker-and-entry))
8187 (entry (cadr marker-and-entry))
8188 (regexp (car entry))
8189 (inhibit-point-motion-hooks t))
8190 (goto-char marker)
8191 ;; This is obviously true, or something bad is happening :)
8192 ;; But we need it to have the match-data
8193 (when (looking-at (or (if (symbolp regexp)
8194 (symbol-value regexp)
8195 regexp)))
8196 (let ((fun (nth 3 entry))
8197 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8198 (get-char-property marker 'gnus-button-url))
8199 (mapcar (lambda (group)
8200 (let ((string (match-string group)))
8201 (set-text-properties
8202 0 (length string) nil string)
8203 string))
8204 (nthcdr 4 entry)))))
8206 (cond
8207 ((fboundp fun)
8208 (apply fun args))
8209 ((and (boundp fun)
8210 (fboundp (symbol-value fun)))
8211 (apply (symbol-value fun) args))
8213 (gnus-message 1 "You must define `%S' to use this button"
8214 (cons fun args)))))))))
8216 (defun gnus-parse-news-url (url)
8217 (let (scheme server port group message-id articles)
8218 (with-temp-buffer
8219 (insert url)
8220 (goto-char (point-min))
8221 (when (looking-at "\\([A-Za-z]+\\):")
8222 (setq scheme (match-string 1))
8223 (goto-char (match-end 0)))
8224 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8225 (setq server (match-string 1))
8226 (setq port (if (stringp (match-string 3))
8227 (string-to-number (match-string 3))
8228 (match-string 3)))
8229 (goto-char (match-end 0)))
8231 (cond
8232 ((looking-at "\\(.*@.*\\)")
8233 (setq message-id (match-string 1)))
8234 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8235 (setq group (match-string 1)
8236 articles (split-string (match-string 2) "-")))
8237 ((looking-at "\\([^/]+\\)/?")
8238 (setq group (match-string 1)))
8240 (error "Unknown news URL syntax"))))
8241 (list scheme server port group message-id articles)))
8243 (defvar nntp-port-number)
8245 (defun gnus-button-handle-news (url)
8246 "Fetch a news URL."
8247 (destructuring-bind (_scheme server port group message-id _articles)
8248 (gnus-parse-news-url url)
8249 (cond
8250 (message-id
8251 (with-current-buffer gnus-summary-buffer
8252 (if server
8253 (let ((gnus-refer-article-method
8254 (nconc (list (list 'nntp server))
8255 gnus-refer-article-method))
8256 (nntp-port-number (or port "nntp")))
8257 (gnus-message 7 "Fetching %s with %s"
8258 message-id gnus-refer-article-method)
8259 (gnus-summary-refer-article message-id))
8260 (gnus-summary-refer-article message-id))))
8261 (group
8262 (gnus-button-fetch-group url)))))
8264 (defun gnus-button-patch (library line)
8265 "Visit an Emacs Lisp library LIBRARY on line LINE."
8266 (interactive)
8267 (let ((file (locate-library (file-name-nondirectory library))))
8268 (unless file
8269 (error "Couldn't find library %s" library))
8270 (find-file file)
8271 (goto-char (point-min))
8272 (forward-line (1- (string-to-number line)))))
8274 (defun gnus-button-handle-man (url)
8275 "Fetch a man page."
8276 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8277 (when (eq gnus-button-man-handler 'woman)
8278 (setq url (replace-regexp-in-string "([1-9][X1a-z]*).*\\'" "" url)))
8279 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8280 (funcall gnus-button-man-handler url))
8282 (defun gnus-button-handle-info-url (url)
8283 "Fetch an info URL."
8284 (setq url (subst-char-in-string ?+ ?\ url))
8285 (cond
8286 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8287 (gnus-info-find-node
8288 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8289 "Gnus")
8290 ")" (gnus-url-unhex-string (match-string 2 url)))))
8291 ((string-match "([^)\"]+)[^\"]+" url)
8292 (setq url
8293 (replace-regexp-in-string
8294 "\"" "" (replace-regexp-in-string "[\n\t ]+" " " url)))
8295 (gnus-info-find-node url))
8296 (t (error "Can't parse %s" url))))
8298 (defun gnus-button-handle-info-url-gnome (url)
8299 "Fetch GNOME style info URL."
8300 (setq url (subst-char-in-string ?_ ?\ url))
8301 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8302 (gnus-info-find-node
8303 (concat "("
8304 (gnus-url-unhex-string
8305 (match-string 1 url))
8307 (or (gnus-url-unhex-string
8308 (match-string 2 url))
8309 "Top")))
8310 (error "Can't parse %s" url)))
8312 (defun gnus-button-handle-info-url-kde (url)
8313 "Fetch KDE style info URL."
8314 (gnus-info-find-node (gnus-url-unhex-string url)))
8316 ;; (info) will autoload info.el
8317 (declare-function Info-menu "info" (menu-item &optional fork))
8318 (declare-function Info-index-next "info" (num))
8320 (defun gnus-button-handle-info-keystrokes (url)
8321 "Call `info' when pushing the corresponding URL button."
8322 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8323 (let (node indx comma)
8324 (if (string-match
8325 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8326 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8327 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8328 "\\(?:[ \t\n,]*\\)\\)?")
8329 url)
8330 (setq node (match-string 2 url)
8331 indx (match-string 3 url))
8332 (error "Can't parse %s" url))
8333 (info)
8334 (Info-directory)
8335 (Info-menu node)
8336 (when (> (length indx) 0)
8337 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8338 "\\([ \t\n,]*\\)")
8339 indx)
8340 (setq comma (match-string 2 indx))
8341 (setq indx (match-string 1 indx))
8342 (Info-index indx)
8343 (when comma
8344 (dotimes (i (with-temp-buffer
8345 (insert comma)
8346 ;; Note: the XEmacs version of `how-many' takes
8347 ;; no optional argument.
8348 (goto-char (point-min))
8349 (how-many ",")))
8350 (Info-index-next 1)))
8351 nil)))
8353 (autoload 'pgg-snarf-keys-region "pgg")
8354 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8355 (declare-function pgg-display-output-buffer "pgg" (start end status))
8357 (defun gnus-button-openpgp (url)
8358 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8359 (with-temp-buffer
8360 (mm-url-insert-file-contents-external url)
8361 (pgg-snarf-keys-region (point-min) (point-max))
8362 (pgg-display-output-buffer nil nil nil)))
8364 (defun gnus-button-message-id (message-id)
8365 "Fetch MESSAGE-ID."
8366 (with-current-buffer gnus-summary-buffer
8367 (gnus-summary-refer-article message-id)))
8369 (defun gnus-button-fetch-group (address &rest _ignore)
8370 "Fetch GROUP specified by ADDRESS."
8371 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8372 address)
8373 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8374 ;; for nntp:// and news://
8375 (setq address (match-string 3 address)))
8376 (if (not (string-match "[:/]" address))
8377 ;; This is just a simple group url.
8378 (gnus-group-read-ephemeral-group address gnus-select-method)
8379 (if (not
8380 (string-match
8381 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8382 address))
8383 (error "Can't parse %s" address)
8384 (gnus-group-read-ephemeral-group
8385 (match-string 4 address)
8386 `(nntp ,(match-string 1 address)
8387 (nntp-address ,(match-string 1 address))
8388 (nntp-port-number ,(if (match-end 3)
8389 (match-string 3 address)
8390 "nntp")))
8391 nil nil nil
8392 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8394 (defun gnus-url-parse-query-string (query &optional downcase)
8395 (let (retval pairs cur key val)
8396 (setq pairs (split-string query "&"))
8397 (while pairs
8398 (setq cur (car pairs)
8399 pairs (cdr pairs))
8400 (if (not (string-match "=" cur))
8401 nil ; Grace
8402 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8403 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8404 (if downcase
8405 (setq key (downcase key)))
8406 (setq cur (assoc key retval))
8407 (if cur
8408 (setcdr cur (cons val (cdr cur)))
8409 (setq retval (cons (list key val) retval)))))
8410 retval))
8412 (defun gnus-url-mailto (url)
8413 ;; Send mail to someone
8414 (setq url (replace-regexp-in-string "\n" " " url))
8415 (when (string-match "mailto:/*\\(.*\\)" url)
8416 (setq url (substring url (match-beginning 1) nil)))
8417 (let* ((args (gnus-url-parse-query-string
8418 (if (string-match "^\\?" url)
8419 (substring url 1)
8420 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8421 (concat "to=" (match-string 1 url) "&"
8422 (match-string 2 url))
8423 (concat "to=" url)))))
8424 (subject (cdr-safe (assoc "subject" args)))
8425 func)
8426 (gnus-msg-mail)
8427 (while args
8428 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8429 (if (fboundp func)
8430 (funcall func)
8431 (message-position-on-field (caar args)))
8432 (insert (replace-regexp-in-string
8433 "\r\n" "\n"
8434 (mapconcat 'identity (reverse (cdar args)) ", ") nil t))
8435 (setq args (cdr args)))
8436 (if subject
8437 (message-goto-body)
8438 (message-goto-subject))))
8440 (defun gnus-button-embedded-url (address)
8441 "Activate ADDRESS with `browse-url'."
8442 (browse-url (gnus-strip-whitespace address)))
8444 ;;; Next/prev buttons in the article buffer.
8446 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8447 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8449 (defvar gnus-prev-page-map
8450 (let ((map (make-sparse-keymap)))
8451 (define-key map [mouse-2] 'gnus-button-prev-page)
8452 (define-key map "\r" 'gnus-button-prev-page)
8453 map))
8455 (defvar gnus-next-page-map
8456 (let ((map (make-sparse-keymap)))
8457 (define-key map [mouse-2] 'gnus-button-next-page)
8458 (define-key map "\r" 'gnus-button-next-page)
8459 map))
8461 (defun gnus-insert-prev-page-button ()
8462 (let ((b (point)) e
8463 (inhibit-read-only t))
8464 (gnus-eval-format
8465 gnus-prev-page-line-format nil
8466 `(keymap ,gnus-prev-page-map
8467 gnus-prev t
8468 gnus-callback gnus-article-button-prev-page
8469 article-type annotation))
8470 (setq e (if (bolp)
8471 ;; Exclude a newline.
8472 (1- (point))
8473 (point)))
8474 (when gnus-article-button-face
8475 (overlay-put (make-overlay b e nil t)
8476 'face gnus-article-button-face))
8477 (widget-convert-button
8478 'link b e
8479 :action 'gnus-button-prev-page
8480 :button-keymap gnus-prev-page-map)))
8482 (defun gnus-button-next-page (&optional _args _more-args)
8483 "Go to the next page."
8484 (interactive)
8485 (let ((win (selected-window)))
8486 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8487 (gnus-article-next-page)
8488 (select-window win)))
8490 (defun gnus-button-prev-page (&optional _args _more-args)
8491 "Go to the prev page."
8492 (interactive)
8493 (let ((win (selected-window)))
8494 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8495 (gnus-article-prev-page)
8496 (select-window win)))
8498 (defun gnus-insert-next-page-button ()
8499 (let ((b (point)) e
8500 (inhibit-read-only t))
8501 (gnus-eval-format gnus-next-page-line-format nil
8502 `(keymap ,gnus-next-page-map
8503 gnus-next t
8504 gnus-callback gnus-article-button-next-page
8505 article-type annotation))
8506 (setq e (if (bolp)
8507 ;; Exclude a newline.
8508 (1- (point))
8509 (point)))
8510 (when gnus-article-button-face
8511 (overlay-put (make-overlay b e nil t)
8512 'face gnus-article-button-face))
8513 (widget-convert-button
8514 'link b e
8515 :action 'gnus-button-next-page
8516 :button-keymap gnus-next-page-map)))
8518 (defun gnus-article-button-next-page (_arg)
8519 "Go to the next page."
8520 (interactive "P")
8521 (let ((win (selected-window)))
8522 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8523 (gnus-article-next-page)
8524 (select-window win)))
8526 (defun gnus-article-button-prev-page (_arg)
8527 "Go to the prev page."
8528 (interactive "P")
8529 (let ((win (selected-window)))
8530 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8531 (gnus-article-prev-page)
8532 (select-window win)))
8534 (defvar gnus-decode-header-methods
8535 '(mail-decode-encoded-word-region)
8536 "List of methods used to decode headers.
8538 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8539 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8540 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8541 whose names match REGEXP.
8543 For example:
8544 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8545 mail-decode-encoded-word-region
8546 (\"chinese\" . rfc1843-decode-region))
8549 (defvar gnus-decode-header-methods-cache nil)
8551 (defun gnus-multi-decode-header (start end)
8552 "Apply the functions from `gnus-encoded-word-methods' that match."
8553 (unless (and gnus-decode-header-methods-cache
8554 (eq gnus-newsgroup-name
8555 (car gnus-decode-header-methods-cache)))
8556 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8557 (dolist (x gnus-decode-header-methods)
8558 (if (symbolp x)
8559 (nconc gnus-decode-header-methods-cache (list x))
8560 (if (and gnus-newsgroup-name
8561 (string-match (car x) gnus-newsgroup-name))
8562 (nconc gnus-decode-header-methods-cache
8563 (list (cdr x)))))))
8564 (let ((xlist gnus-decode-header-methods-cache))
8565 (pop xlist)
8566 (save-restriction
8567 (narrow-to-region start end)
8568 (while xlist
8569 (funcall (pop xlist) (point-min) (point-max))))))
8572 ;;; Treatment top-level handling.
8575 (defvar gnus-inhibit-article-treatments nil)
8577 ;; Dynamic variables.
8578 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8579 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8580 (defvar gnus-treat-type)
8581 (defvar gnus-treat-condition)
8582 (defvar gnus-treat-length)
8584 (defun gnus-treat-article (condition
8585 &optional part-num total type)
8586 (let ((gnus-treat-condition condition)
8587 (part-number part-num)
8588 (total-parts total)
8589 (gnus-treat-type type)
8590 (gnus-treat-length (- (point-max) (point-min)))
8591 (alist gnus-treatment-function-alist)
8592 (article-goto-body-goes-to-point-min-p t)
8593 (treated-type
8594 (or (not type)
8595 (catch 'found
8596 (let ((list gnus-article-treat-types))
8597 (while list
8598 (when (string-match (pop list) type)
8599 (throw 'found t)))))))
8600 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8601 val)
8602 (gnus-run-hooks 'gnus-part-display-hook)
8603 (dolist (elem alist)
8604 (setq val
8605 (save-excursion
8606 (when (gnus-buffer-live-p gnus-summary-buffer)
8607 (set-buffer gnus-summary-buffer))
8608 (symbol-value (car elem))))
8609 (when (and (or (consp val)
8610 treated-type)
8611 (or (not gnus-inhibit-article-treatments)
8612 (eq gnus-treat-condition 'head))
8613 (gnus-treat-predicate val)
8614 (or (not (get (car elem) 'highlight))
8615 highlightp))
8616 (save-restriction
8617 (funcall (cadr elem)))))))
8619 (defun gnus-treat-predicate (val)
8620 (cond
8621 ((null val)
8622 nil)
8623 (gnus-treat-condition
8624 (eq gnus-treat-condition val))
8625 ((and (listp val)
8626 (stringp (car val)))
8627 (apply 'gnus-or (mapcar `(lambda (s)
8628 (string-match s ,(or gnus-newsgroup-name "")))
8629 val)))
8630 ((listp val)
8631 (let ((pred (pop val)))
8632 (cond
8633 ((eq pred 'or)
8634 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8635 ((eq pred 'and)
8636 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8637 ((eq pred 'not)
8638 (not (gnus-treat-predicate (car val))))
8639 ((eq pred 'typep)
8640 (equal (car val) gnus-treat-type))
8641 ((functionp pred)
8642 (funcall pred))
8644 (error "%S is not a valid predicate" pred)))))
8645 ((eq val t)
8647 ((eq val 'head)
8648 nil)
8649 ((eq val 'first)
8650 (eq part-number 1))
8651 ((eq val 'last)
8652 (eq part-number total-parts))
8653 ((numberp val)
8654 (< gnus-treat-length val))
8656 (error "%S is not a valid value" val))))
8658 (defun gnus-article-encrypt-body (protocol &optional n)
8659 "Encrypt the article body."
8660 (interactive
8661 (list
8662 (or gnus-article-encrypt-protocol
8663 (gnus-completing-read "Encrypt protocol"
8664 (mapcar 'car gnus-article-encrypt-protocol-alist)
8666 current-prefix-arg))
8667 ;; User might hit `K E' instead of `K e', so prompt once.
8668 (when (and gnus-article-encrypt-protocol
8669 gnus-novice-user)
8670 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8671 (error "Encrypt aborted")))
8672 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8673 (unless func
8674 (error "Can't find the encrypt protocol %s" protocol))
8675 (if (member gnus-newsgroup-name '("nndraft:delayed"
8676 "nndraft:drafts"
8677 "nndraft:queue"))
8678 (error "Can't encrypt the article in group %s"
8679 gnus-newsgroup-name))
8680 (gnus-summary-iterate n
8681 (with-current-buffer gnus-summary-buffer
8682 (let ((mail-parse-charset gnus-newsgroup-charset)
8683 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8684 (summary-buffer gnus-summary-buffer)
8685 references point)
8686 (gnus-set-global-variables)
8687 (when (gnus-group-read-only-p)
8688 (error "The current newsgroup does not support article encrypt"))
8689 (gnus-summary-show-article t)
8690 (setq references
8691 (or (mail-header-references gnus-current-headers) ""))
8692 (set-buffer gnus-article-buffer)
8693 (let* ((inhibit-read-only t)
8694 (headers
8695 (mapcar (lambda (field)
8696 (and (save-restriction
8697 (message-narrow-to-head)
8698 (goto-char (point-min))
8699 (search-forward field nil t))
8700 (prog2
8701 (message-narrow-to-field)
8702 (buffer-string)
8703 (delete-region (point-min) (point-max))
8704 (widen))))
8705 '("Content-Type:" "Content-Transfer-Encoding:"
8706 "Content-Disposition:"))))
8707 (message-narrow-to-head)
8708 (message-remove-header "MIME-Version")
8709 (goto-char (point-max))
8710 (setq point (point))
8711 (insert (apply 'concat headers))
8712 (widen)
8713 (narrow-to-region point (point-max))
8714 (let ((message-options message-options))
8715 (message-options-set 'message-sender user-mail-address)
8716 (message-options-set 'message-recipients user-mail-address)
8717 (message-options-set 'message-sign-encrypt 'not)
8718 (funcall func))
8719 (goto-char (point-min))
8720 (insert "MIME-Version: 1.0\n")
8721 (widen)
8722 (gnus-summary-edit-article-done
8723 references nil summary-buffer t))
8724 (when gnus-keep-backlog
8725 (gnus-backlog-remove-article
8726 (car gnus-article-current) (cdr gnus-article-current)))
8727 (gnus-flush-original-article-buffer)
8728 (when gnus-use-cache
8729 (gnus-cache-update-article
8730 (car gnus-article-current) (cdr gnus-article-current))))))))
8732 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8733 "The following specs can be used:
8734 %t The security MIME type
8735 %i Additional info
8736 %d Details
8737 %D Details if button is pressed")
8739 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8740 "The following specs can be used:
8741 %t The security MIME type
8742 %i Additional info
8743 %d Details
8744 %D Details if button is pressed")
8746 (defvar gnus-mime-security-button-line-format-alist
8747 '((?t gnus-tmp-type ?s)
8748 (?i gnus-tmp-info ?s)
8749 (?d gnus-tmp-details ?s)
8750 (?D gnus-tmp-pressed-details ?s)))
8752 (defvar gnus-mime-security-button-commands
8753 '((gnus-article-press-button "\r" "Show Detail")
8754 (undefined "v")
8755 (undefined "t")
8756 (undefined "C")
8757 (gnus-mime-security-save-part "o" "Save...")
8758 (undefined "\C-o")
8759 (undefined "r")
8760 (undefined "d")
8761 (undefined "c")
8762 (undefined "i")
8763 (undefined "E")
8764 (undefined "e")
8765 (undefined "p")
8766 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8767 (undefined ".")))
8769 (defvar gnus-mime-security-button-map
8770 (let ((map (make-sparse-keymap)))
8771 (define-key map [mouse-2] 'gnus-article-push-button)
8772 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8773 (dolist (c gnus-mime-security-button-commands)
8774 (define-key map (cadr c) (car c)))
8775 map))
8777 (easy-menu-define
8778 gnus-mime-security-button-menu gnus-mime-security-button-map
8779 "Security button menu."
8780 `("Security Part"
8781 ,@(delq nil
8782 (mapcar (lambda (c)
8783 (unless (eq (car c) 'undefined)
8784 (vector (caddr c) (car c) :active t)))
8785 gnus-mime-security-button-commands))))
8787 (defun gnus-mime-security-button-menu (event prefix)
8788 "Construct a context-sensitive menu of security commands."
8789 (interactive "e\nP")
8790 (save-window-excursion
8791 (let ((pos (event-start event)))
8792 (select-window (posn-window pos))
8793 (goto-char (posn-point pos))
8794 (gnus-article-check-buffer)
8795 (popup-menu gnus-mime-security-button-menu nil prefix))))
8797 (defvar gnus-mime-security-details-buffer nil)
8799 (defvar gnus-mime-security-button-pressed nil)
8801 (defvar gnus-mime-security-show-details-inline t
8802 "If non-nil, show details in the article buffer.")
8804 (defun gnus-mime-security-verify-or-decrypt (handle)
8805 (mm-remove-parts (cdr handle))
8806 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8807 point (inhibit-read-only t))
8808 (if region
8809 (goto-char (car region)))
8810 (setq point (point))
8811 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8812 (let* ((mm-verify-option 'known)
8813 (mm-decrypt-option 'known)
8814 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8815 (unless (eq nparts (cdr handle))
8816 (mm-destroy-parts (cdr handle))
8817 (setcdr handle nparts))))
8818 (gnus-mime-display-security handle)
8819 (when region
8820 (delete-region (point) (cdr region))
8821 (set-marker (car region) nil)
8822 (set-marker (cdr region) nil))
8823 (goto-char point)))
8825 (defun gnus-mime-security-show-details (handle)
8826 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8827 (if (not details)
8828 (gnus-message 5 "No details.")
8829 (if gnus-mime-security-show-details-inline
8830 (let ((gnus-mime-security-button-pressed
8831 (not (get-text-property (point) 'gnus-mime-details)))
8832 (gnus-mime-security-button-line-format
8833 (get-text-property (point) 'gnus-line-format))
8834 (inhibit-read-only t))
8835 (forward-char -1)
8836 (while (eq (get-text-property (point) 'gnus-line-format)
8837 gnus-mime-security-button-line-format)
8838 (forward-char -1))
8839 (forward-char)
8840 (save-restriction
8841 (narrow-to-region (point) (point))
8842 (gnus-insert-mime-security-button handle))
8843 (delete-region (point)
8844 (or (text-property-not-all
8845 (point) (point-max)
8846 'gnus-line-format
8847 gnus-mime-security-button-line-format)
8848 (point-max))))
8849 ;; Not inlined.
8850 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8851 (with-current-buffer gnus-mime-security-details-buffer
8852 (erase-buffer)
8854 (setq gnus-mime-security-details-buffer
8855 (gnus-get-buffer-create "*MIME Security Details*")))
8856 (with-current-buffer gnus-mime-security-details-buffer
8857 (insert details)
8858 (goto-char (point-min)))
8859 (pop-to-buffer gnus-mime-security-details-buffer)))))
8861 (defun gnus-mime-security-press-button (handle)
8862 (save-excursion
8863 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8864 (gnus-mime-security-show-details handle)
8865 (gnus-mime-security-verify-or-decrypt handle))))
8867 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8868 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8869 (gnus-tmp-type
8870 (concat
8871 (or (nth 2 (assoc protocol mm-verify-function-alist))
8872 (nth 2 (assoc protocol mm-decrypt-function-alist))
8873 "Unknown")
8874 (if (equal (car handle) "multipart/signed")
8875 " Signed" " Encrypted")
8876 " Part"))
8877 (gnus-tmp-info
8878 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8879 "Undecided"))
8880 (gnus-tmp-details
8881 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8882 gnus-tmp-pressed-details
8883 b e)
8884 (setq gnus-tmp-details
8885 (if gnus-tmp-details
8886 (concat "\n" gnus-tmp-details)
8887 ""))
8888 (setq gnus-tmp-pressed-details
8889 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8890 (unless (bolp)
8891 (insert "\n"))
8892 (setq b (point))
8893 (gnus-eval-format
8894 gnus-mime-security-button-line-format
8895 gnus-mime-security-button-line-format-alist
8896 `(keymap ,gnus-mime-security-button-map
8897 gnus-callback gnus-mime-security-press-button
8898 gnus-line-format ,gnus-mime-security-button-line-format
8899 gnus-mime-details ,gnus-mime-security-button-pressed
8900 article-type annotation
8901 gnus-data ,handle))
8902 (setq e (if (bolp)
8903 ;; Exclude a newline.
8904 (1- (point))
8905 (point)))
8906 (when gnus-article-button-face
8907 (overlay-put (make-overlay b e nil t)
8908 'face gnus-article-button-face))
8909 (widget-convert-button
8910 'link b e
8911 :mime-handle handle
8912 :action 'gnus-widget-press-button
8913 :button-keymap gnus-mime-security-button-map
8914 :help-echo
8915 (lambda (_widget)
8916 (format
8917 "%S: show detail; %S: more options"
8918 'mouse-2
8919 'down-mouse-3)))))
8921 (defun gnus-mime-display-security (handle)
8922 (save-restriction
8923 (narrow-to-region (point) (point))
8924 (unless (gnus-unbuttonized-mime-type-p (car handle))
8925 (gnus-insert-mime-security-button handle))
8926 (gnus-mime-display-part (cadr handle))
8927 (unless (bolp)
8928 (insert "\n"))
8929 (unless (gnus-unbuttonized-mime-type-p (car handle))
8930 (let ((gnus-mime-security-button-line-format
8931 gnus-mime-security-button-end-line-format))
8932 (gnus-insert-mime-security-button handle)))
8933 (mm-set-handle-multipart-parameter
8934 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8935 (goto-char (point-max))))
8937 (defun gnus-mime-security-run-function (function)
8938 "Run FUNCTION with the security part under point."
8939 (gnus-article-check-buffer)
8940 (let ((data (get-text-property (point) 'gnus-data))
8941 buffer handle)
8942 (when (and (stringp (car-safe data))
8943 (setq buffer (mm-handle-multipart-original-buffer data))
8944 (setq handle (cadr data)))
8945 (if (bufferp (mm-handle-buffer handle))
8946 (progn
8947 (setq handle (cons buffer (copy-sequence (cdr handle))))
8948 (mm-handle-set-undisplayer handle nil))
8949 (setq handle (mm-make-handle
8950 buffer
8951 (mm-handle-multipart-ctl-parameter handle 'protocol)
8952 nil nil nil nil nil nil)))
8953 (funcall function handle))))
8955 (defun gnus-mime-security-save-part ()
8956 "Save the security part under point."
8957 (interactive)
8958 (gnus-mime-security-run-function 'mm-save-part))
8960 (defun gnus-mime-security-pipe-part ()
8961 "Pipe the security part under point to a process."
8962 (interactive)
8963 (gnus-mime-security-run-function 'mm-pipe-part))
8965 (provide 'gnus-art)
8967 (run-hooks 'gnus-art-load-hook)
8969 ;;; gnus-art.el ends here