* mail/rmail.el (rmail-show-message-1): When displaying a mime message,
[emacs.git] / lisp / gnus / gnus-art.el
blob5ec1268aee7941cd3960a5d314c264593566de03
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2015 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 :group 'gnus-article-signature)
257 (defcustom gnus-hidden-properties
258 (if (featurep 'xemacs)
259 ;; `intangible' is evil, but I keep it here in case it's useful.
260 '(invisible t intangible t)
261 ;; Emacs's command loop moves point out of invisible text anyway, so
262 ;; `intangible' is clearly not needed there.
263 '(invisible t))
264 "Property list to use for hiding text."
265 :type 'sexp
266 :group 'gnus-article-hiding)
268 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
269 ;; frames in a session.
270 (defcustom gnus-article-x-face-command
271 (if (featurep 'xemacs)
272 (if (or (gnus-image-type-available-p 'xface)
273 (gnus-image-type-available-p 'pbm))
274 'gnus-display-x-face-in-from
275 "{ echo \
276 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
277 ; uncompface; } | icontopbm | ee -")
278 (if (gnus-image-type-available-p 'pbm)
279 'gnus-display-x-face-in-from
280 "{ echo \
281 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
282 ; uncompface; } | icontopbm | display -"))
283 "*String or function to be executed to display an X-Face header.
284 If it is a string, the command will be executed in a sub-shell
285 asynchronously. The compressed face will be piped to this command."
286 :type `(choice string
287 (function-item gnus-display-x-face-in-from)
288 function)
289 :version "21.1"
290 :group 'gnus-picon
291 :group 'gnus-article-washing)
293 (defcustom gnus-article-x-face-too-ugly nil
294 "Regexp matching posters whose face shouldn't be shown automatically."
295 :type '(choice regexp (const nil))
296 :group 'gnus-article-washing)
298 (defcustom gnus-article-banner-alist nil
299 "Banner alist for stripping.
300 For example,
301 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
302 :version "21.1"
303 :type '(repeat (cons symbol regexp))
304 :group 'gnus-article-washing)
306 (gnus-define-group-parameter
307 banner
308 :variable-document
309 "Alist of regexps (to match group names) and banner."
310 :variable-group gnus-article-washing
311 :parameter-type
312 '(choice :tag "Banner"
313 :value nil
314 (const :tag "Remove signature" signature)
315 (symbol :tag "Item in `gnus-article-banner-alist'" none)
316 regexp
317 (const :tag "None" nil))
318 :parameter-document
319 "If non-nil, specify how to remove `banners' from articles.
321 Symbol `signature' means to remove signatures delimited by
322 `gnus-signature-separator'. Any other symbol is used to look up a
323 regular expression to match the banner in `gnus-article-banner-alist'.
324 A string is used as a regular expression to match the banner
325 directly.")
327 (defcustom gnus-article-address-banner-alist nil
328 "Alist of mail addresses and banners.
329 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
330 to match a mail address in the From: header, BANNER is one of a symbol
331 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
332 If ADDRESS matches author's mail address, it will remove things like
333 advertisements. For example:
335 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
337 :type '(repeat
338 (cons
339 (regexp :tag "Address")
340 (choice :tag "Banner" :value nil
341 (const :tag "Remove signature" signature)
342 (symbol :tag "Item in `gnus-article-banner-alist'" none)
343 regexp
344 (const :tag "None" nil))))
345 :version "22.1"
346 :group 'gnus-article-washing)
348 (defmacro gnus-emphasis-custom-with-format (&rest body)
349 `(let ((format "\
350 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
351 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
352 ,@body))
354 (defun gnus-emphasis-custom-value-to-external (value)
355 (gnus-emphasis-custom-with-format
356 (if (consp (car value))
357 (list (format format (car (car value)) (cdr (car value)))
359 (if (nth 1 value) 2 3)
360 (nth 2 value))
361 value)))
363 (defun gnus-emphasis-custom-value-to-internal (value)
364 (gnus-emphasis-custom-with-format
365 (let ((regexp (concat "\\`"
366 (format (regexp-quote format)
367 "\\([^()]+\\)" "\\([^()]+\\)")
368 "\\'"))
369 pattern)
370 (if (string-match regexp (setq pattern (car value)))
371 (list (cons (match-string 1 pattern) (match-string 2 pattern))
372 (= (nth 2 value) 2)
373 (nth 3 value))
374 value))))
376 (defcustom gnus-emphasis-alist
377 (let ((types
378 '(("\\*" "\\*" bold nil 2)
379 ("_" "_" underline)
380 ("/" "/" italic)
381 ("_/" "/_" underline-italic)
382 ("_\\*" "\\*_" underline-bold)
383 ("\\*/" "/\\*" bold-italic)
384 ("_\\*/" "/\\*_" underline-bold-italic))))
385 (nconc
386 (gnus-emphasis-custom-with-format
387 (mapcar (lambda (spec)
388 (list (format format (car spec) (cadr spec))
389 (or (nth 3 spec) 2)
390 (or (nth 4 spec) 3)
391 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
392 types))
393 '(;; I've never seen anyone use this strikethru convention whereas I've
394 ;; several times seen it triggered by normal text. --Stef
395 ;; Miles suggests that this form is sometimes used but for italics,
396 ;; so maybe we should map it to `italic'.
397 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
398 ;; 2 3 gnus-emphasis-strikethru)
399 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
400 2 3 gnus-emphasis-underline))))
401 "*Alist that says how to fontify certain phrases.
402 Each item looks like this:
404 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
406 The first element is a regular expression to be matched. The second
407 is a number that says what regular expression grouping used to find
408 the entire emphasized word. The third is a number that says what
409 regexp grouping should be displayed and highlighted. The fourth
410 is the face used for highlighting."
411 :type
412 '(repeat
413 (menu-choice
414 :format "%[Customizing Style%]\n%v"
415 :indent 2
416 (group :tag "Default"
417 :value ("" 0 0 default)
418 :value-create
419 (lambda (widget)
420 (let ((value (widget-get
421 (cadr (widget-get (widget-get widget :parent)
422 :args))
423 :value)))
424 (if (not (eq (nth 2 value) 'default))
425 (widget-put
426 widget
427 :value
428 (gnus-emphasis-custom-value-to-external value))))
429 (widget-group-value-create widget))
430 regexp
431 (integer :format "Match group: %v")
432 (integer :format "Emphasize group: %v")
433 face)
434 (group :tag "Simple"
435 :value (("_" . "_") nil default)
436 (cons :format "%v"
437 (regexp :format "Start regexp: %v")
438 (regexp :format "End regexp: %v"))
439 (boolean :format "Show start and end patterns: %[%v%]\n"
440 :on " On " :off " Off ")
441 face)))
442 :get (lambda (symbol)
443 (mapcar 'gnus-emphasis-custom-value-to-internal
444 (default-value symbol)))
445 :set (lambda (symbol value)
446 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
447 value)))
448 :group 'gnus-article-emphasis)
450 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
451 "A regexp to describe whitespace which should not be emphasized.
452 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
453 The former avoids underlining of leading and trailing whitespace,
454 and the latter avoids underlining any whitespace at all."
455 :version "21.1"
456 :group 'gnus-article-emphasis
457 :type 'regexp)
459 (defface gnus-emphasis-bold '((t (:bold t)))
460 "Face used for displaying strong emphasized text (*word*)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-italic '((t (:italic t)))
464 "Face used for displaying italic emphasized text (/word/)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline '((t (:underline t)))
468 "Face used for displaying underlined emphasized text (_word_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
472 "Face used for displaying underlined bold emphasized text (_*word*_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
476 "Face used for displaying underlined italic emphasized text (_/word/_)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
480 "Face used for displaying bold italic emphasized text (/*word*/)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-underline-bold-italic
484 '((t (:bold t :italic t :underline t)))
485 "Face used for displaying underlined bold italic emphasized text.
486 Example: (_/*word*/_)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
490 '((t (:strikethru t)))
491 '((t (:strike-through t))))
492 "Face used for displaying strike-through text (-word-)."
493 :group 'gnus-article-emphasis)
495 (defface gnus-emphasis-highlight-words
496 '((t (:background "black" :foreground "yellow")))
497 "Face used for displaying highlighted words."
498 :group 'gnus-article-emphasis)
500 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
501 "Format for display of Date headers in article bodies.
502 See `format-time-string' for the possible values.
504 The variable can also be function, which should return a complete Date
505 header. The function is called with one argument, the time, which can
506 be fed to `format-time-string'."
507 :type '(choice string function)
508 :link '(custom-manual "(gnus)Article Date")
509 :group 'gnus-article-washing)
511 (defcustom gnus-save-all-headers t
512 "*If non-nil, don't remove any headers before saving.
513 This will be overridden by the `:headers' property that the symbol of
514 the saver function, which is specified by `gnus-default-article-saver',
515 might have."
516 :group 'gnus-article-saving
517 :type 'boolean)
519 (defcustom gnus-prompt-before-saving 'always
520 "*This variable says how much prompting is to be done when saving articles.
521 If it is nil, no prompting will be done, and the articles will be
522 saved to the default files. If this variable is `always', each and
523 every article that is saved will be preceded by a prompt, even when
524 saving large batches of articles. If this variable is neither nil not
525 `always', there the user will be prompted once for a file name for
526 each invocation of the saving commands."
527 :group 'gnus-article-saving
528 :type '(choice (item always)
529 (item :tag "never" nil)
530 (sexp :tag "once" :format "%t\n" :value t)))
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 (when (featurep 'xemacs)
711 ;; Extracted from gnus-xmas-define in order to preserve user settings
712 (when (fboundp 'turn-off-scroll-in-place)
713 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
714 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
715 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
717 (defcustom gnus-article-menu-hook nil
718 "*Hook run after the creation of the article mode menu."
719 :type 'hook
720 :group 'gnus-article-various)
722 (defcustom gnus-article-prepare-hook nil
723 "*A hook called after an article has been prepared in the article buffer."
724 :type 'hook
725 :group 'gnus-article-various)
727 (defcustom gnus-copy-article-ignored-headers nil
728 "List of headers to be removed when copying an article.
729 Each element is a regular expression."
730 :version "23.1" ;; No Gnus
731 :type '(repeat regexp)
732 :group 'gnus-article-various)
734 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
735 "Gnus 5.10 (Emacs 22.1)")
737 (defface gnus-button
738 '((t (:weight bold)))
739 "Face used for highlighting a button in the article buffer."
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-button-face 'gnus-button
743 "Face used for highlighting buttons in the article buffer.
745 An article button is a piece of text that you can activate by pressing
746 `RET' or `mouse-2' above it."
747 :type 'face
748 :group 'gnus-article-buttons)
750 (defcustom gnus-article-mouse-face 'highlight
751 "Face used for mouse highlighting in the article buffer.
753 Article buttons will be displayed in this face when the cursor is
754 above them."
755 :type 'face
756 :group 'gnus-article-buttons)
758 (defcustom gnus-signature-face 'gnus-signature
759 "Face used for highlighting a signature in the article buffer.
760 Obsolete; use the face `gnus-signature' for customizations instead."
761 :type 'face
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
765 (defface gnus-signature
766 '((t
767 (:italic t)))
768 "Face used for highlighting a signature in the article buffer."
769 :group 'gnus-article-highlight
770 :group 'gnus-article-signature)
771 ;; backward-compatibility alias
772 (put 'gnus-signature-face 'face-alias 'gnus-signature)
773 (put 'gnus-signature-face 'obsolete-face "22.1")
775 (defface gnus-header-from
776 '((((class color)
777 (background dark))
778 (:foreground "PaleGreen1"))
779 (((class color)
780 (background light))
781 (:foreground "red3"))
783 (:italic t)))
784 "Face used for displaying from headers."
785 :group 'gnus-article-headers
786 :group 'gnus-article-highlight)
787 ;; backward-compatibility alias
788 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
789 (put 'gnus-header-from-face 'obsolete-face "22.1")
791 (defface gnus-header-subject
792 '((((class color)
793 (background dark))
794 (:foreground "SeaGreen1"))
795 (((class color)
796 (background light))
797 (:foreground "red4"))
799 (:bold t :italic t)))
800 "Face used for displaying subject headers."
801 :group 'gnus-article-headers
802 :group 'gnus-article-highlight)
803 ;; backward-compatibility alias
804 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
805 (put 'gnus-header-subject-face 'obsolete-face "22.1")
807 (defface gnus-header-newsgroups
808 '((((class color)
809 (background dark))
810 (:foreground "yellow" :italic t))
811 (((class color)
812 (background light))
813 (:foreground "MidnightBlue" :italic t))
815 (:italic t)))
816 "Face used for displaying newsgroups headers.
817 In the default setup this face is only used for crossposted
818 articles."
819 :group 'gnus-article-headers
820 :group 'gnus-article-highlight)
821 ;; backward-compatibility alias
822 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
823 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
825 (defface gnus-header-name
826 '((((class color)
827 (background dark))
828 (:foreground "SpringGreen2"))
829 (((class color)
830 (background light))
831 (:foreground "maroon"))
833 (:bold t)))
834 "Face used for displaying header names."
835 :group 'gnus-article-headers
836 :group 'gnus-article-highlight)
837 ;; backward-compatibility alias
838 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
839 (put 'gnus-header-name-face 'obsolete-face "22.1")
841 (defface gnus-header-content
842 '((((class color)
843 (background dark))
844 (:foreground "SpringGreen1" :italic t))
845 (((class color)
846 (background light))
847 (:foreground "indianred4" :italic t))
849 (:italic t))) "Face used for displaying header content."
850 :group 'gnus-article-headers
851 :group 'gnus-article-highlight)
852 ;; backward-compatibility alias
853 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
854 (put 'gnus-header-content-face 'obsolete-face "22.1")
856 (defcustom gnus-header-face-alist
857 '(("From" nil gnus-header-from)
858 ("Subject" nil gnus-header-subject)
859 ("Newsgroups:.*," nil gnus-header-newsgroups)
860 ("" gnus-header-name gnus-header-content))
861 "*Controls highlighting of article headers.
863 An alist of the form (HEADER NAME CONTENT).
865 HEADER is a regular expression which should match the name of a
866 header and NAME and CONTENT are either face names or nil.
868 The name of each header field will be displayed using the face
869 specified by the first element in the list where HEADER matches
870 the header name and NAME is non-nil. Similarly, the content will
871 be displayed by the first non-nil matching CONTENT face."
872 :group 'gnus-article-headers
873 :group 'gnus-article-highlight
874 :type '(repeat (list (regexp :tag "Header")
875 (choice :tag "Name"
876 (item :tag "skip" nil)
877 (face :value default))
878 (choice :tag "Content"
879 (item :tag "skip" nil)
880 (face :value default)))))
882 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
883 '((xface . (:face gnus-x-face)))
884 '((pbm . (:face gnus-x-face))
885 (png . nil)))
886 "Alist of image types and properties applied to Face and X-Face images.
887 Here are examples:
889 ;; Specify the altitude of Face images in the From header.
890 \(setq gnus-face-properties-alist
891 '((pbm . (:face gnus-x-face :ascent 80))
892 (png . (:ascent 80))))
894 ;; Show Face images as pressed buttons.
895 \(setq gnus-face-properties-alist
896 '((pbm . (:face gnus-x-face :relief -2))
897 (png . (:relief -2))))
899 See the manual for the valid properties for various image types.
900 Currently, `pbm' is used for X-Face images and `png' is used for Face
901 images in Emacs. Only the `:face' property is effective on the `xface'
902 image type in XEmacs if it is built with the libcompface library."
903 :version "23.1" ;; No Gnus
904 :group 'gnus-article-headers
905 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
907 (defcustom gnus-article-decode-hook
908 '(article-decode-charset article-decode-encoded-words
909 article-decode-group-name article-decode-idna-rhs)
910 "*Hook run to decode charsets in articles."
911 :group 'gnus-article-headers
912 :type 'hook)
914 (defcustom gnus-display-mime-function 'gnus-display-mime
915 "Function to display MIME articles."
916 :group 'gnus-article-mime
917 :type 'function)
919 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
920 "Function used to decode headers.")
922 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
923 "Function used to decode addresses.")
925 (defvar gnus-article-dumbquotes-map
926 '((?\200 "EUR")
927 (?\202 ",")
928 (?\203 "f")
929 (?\204 ",,")
930 (?\205 "...")
931 (?\213 "<")
932 (?\214 "OE")
933 (?\221 "`")
934 (?\222 "'")
935 (?\223 "``")
936 (?\224 "\"")
937 (?\225 "*")
938 (?\226 "-")
939 (?\227 "--")
940 (?\230 "~")
941 (?\231 "(TM)")
942 (?\233 ">")
943 (?\234 "oe")
944 (?\264 "'"))
945 "Table for MS-to-Latin1 translation.")
947 (defcustom gnus-ignored-mime-types nil
948 "List of MIME types that should be ignored by Gnus."
949 :version "21.1"
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
953 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
954 "List of MIME types that should not be given buttons when rendered inline.
955 See also `gnus-buttonized-mime-types' which may override this variable.
956 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
957 :version "21.1"
958 :group 'gnus-article-mime
959 :type '(repeat regexp))
961 (defcustom gnus-buttonized-mime-types nil
962 "List of MIME types that should be given buttons when rendered inline.
963 If set, this variable overrides `gnus-unbuttonized-mime-types'.
964 To see e.g. security buttons you could set this to
965 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
966 this list to display radio buttons that allow you to choose one of two
967 media types those mails include. See also `mm-discouraged-alternatives'.
968 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
969 :version "22.1"
970 :group 'gnus-article-mime
971 :type '(repeat regexp))
973 (defcustom gnus-inhibit-mime-unbuttonizing nil
974 "If non-nil, all MIME parts get buttons.
975 When nil (the default value), then some MIME parts do not get buttons,
976 as described by the variables `gnus-buttonized-mime-types' and
977 `gnus-unbuttonized-mime-types'."
978 :version "22.1"
979 :group 'gnus-article-mime
980 :type 'boolean)
982 (defcustom gnus-body-boundary-delimiter "_"
983 "String used to delimit header and body.
984 This variable is used by `gnus-article-treat-body-boundary' which can
985 be controlled by `gnus-treat-body-boundary'."
986 :version "22.1"
987 :group 'gnus-article-various
988 :type '(choice (item :tag "None" :value nil)
989 string))
991 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
992 "/usr/share/picons")
993 "Defines the location of the faces database.
994 For information on obtaining this database of pretty pictures, please
995 see http://www.cs.indiana.edu/picons/ftp/index.html"
996 :version "22.1"
997 :type '(repeat directory)
998 :link '(url-link :tag "download"
999 "http://www.cs.indiana.edu/picons/ftp/index.html")
1000 :link '(custom-manual "(gnus)Picons")
1001 :group 'gnus-picon)
1003 (defun gnus-picons-installed-p ()
1004 "Say whether picons are installed on your machine."
1005 (let ((installed nil))
1006 (dolist (database gnus-picon-databases)
1007 (when (file-exists-p database)
1008 (setq installed t)))
1009 installed))
1011 (defcustom gnus-article-mime-part-function nil
1012 "Function called with a MIME handle as the argument.
1013 This is meant for people who want to do something automatic based
1014 on parts -- for instance, adding Vcard info to a database."
1015 :group 'gnus-article-mime
1016 :type '(choice (const nil)
1017 function))
1019 (defcustom gnus-mime-multipart-functions nil
1020 "An alist of MIME types to functions to display them."
1021 :version "21.1"
1022 :group 'gnus-article-mime
1023 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1025 (defcustom gnus-article-date-headers '(combined-lapsed)
1026 "A list of Date header formats to display.
1027 Valid formats are `ut' (universal time), `local' (local time
1028 zone), `english' (readable English), `lapsed' (elapsed time),
1029 `combined-lapsed' (both the original date and the elapsed time),
1030 `original' (the original date header), `iso8601' (ISO8601
1031 format), and `user-defined' (a user-defined format defined by the
1032 `gnus-article-time-format' variable).
1034 You have as many date headers as you want in the article buffer.
1035 Some of these headers are updated automatically. See
1036 `gnus-article-update-date-headers' for details."
1037 :version "24.1"
1038 :group 'gnus-article-headers
1039 :type '(set
1040 (const :tag "Universal time (UT)" ut)
1041 (const :tag "Local time zone" local)
1042 (const :tag "Readable English" english)
1043 (const :tag "Elapsed time" lapsed)
1044 (const :tag "Original and elapsed time" combined-lapsed)
1045 (const :tag "Original date header" original)
1046 (const :tag "ISO8601 format" iso8601)
1047 (const :tag "User-defined" user-defined)))
1049 (defcustom gnus-article-update-date-headers nil
1050 "A number that says how often to update the date header (in seconds).
1051 If nil, don't update it at all."
1052 :version "24.1"
1053 :group 'gnus-article-headers
1054 :type '(choice
1055 (item :tag "Don't update" :value nil)
1056 integer))
1058 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1059 "Function called with a MIME handle as the argument.
1060 This is meant for people who want to view first matched part.
1061 For `undisplayed-alternative' (default), the first undisplayed
1062 part or alternative part is used. For `undisplayed', the first
1063 undisplayed part is used. For a function, the first part which
1064 the function return t is used. For nil, the first part is
1065 used."
1066 :version "21.1"
1067 :group 'gnus-article-mime
1068 :type '(choice
1069 (item :tag "first" :value nil)
1070 (item :tag "undisplayed" :value undisplayed)
1071 (item :tag "undisplayed or alternative"
1072 :value undisplayed-alternative)
1073 (function)))
1075 (defcustom gnus-mime-action-alist
1076 '(("save to file" . gnus-mime-save-part)
1077 ("save and strip" . gnus-mime-save-part-and-strip)
1078 ("replace with file" . gnus-mime-replace-part)
1079 ("delete part" . gnus-mime-delete-part)
1080 ("display as text" . gnus-mime-inline-part)
1081 ("view the part" . gnus-mime-view-part)
1082 ("pipe to command" . gnus-mime-pipe-part)
1083 ("toggle display" . gnus-article-press-button)
1084 ("toggle display" . gnus-article-view-part-as-charset)
1085 ("view as type" . gnus-mime-view-part-as-type)
1086 ("view internally" . gnus-mime-view-part-internally)
1087 ("view externally" . gnus-mime-view-part-externally))
1088 "An alist of actions that run on the MIME attachment."
1089 :group 'gnus-article-mime
1090 :type '(repeat (cons (string :tag "name")
1091 (function))))
1093 (defcustom gnus-auto-select-part 1
1094 "Advance to next MIME part when deleting or stripping parts.
1096 When 0, point will be placed on the same part as before. When
1097 positive (negative), move point forward (backwards) this many
1098 parts. When nil, redisplay article."
1099 :version "23.1" ;; No Gnus
1100 :group 'gnus-article-mime
1101 :type '(choice (const nil :tag "Redisplay article.")
1102 (const 1 :tag "Next part.")
1103 (const 0 :tag "Current part.")
1104 integer))
1107 ;;; The treatment variables
1110 (defvar gnus-part-display-hook nil
1111 "Hook called on parts that are to receive treatment.")
1113 (defvar gnus-article-treat-custom
1114 '(choice (const :tag "Off" nil)
1115 (const :tag "On" t)
1116 (const :tag "Header" head)
1117 (const :tag "First" first)
1118 (const :tag "Last" last)
1119 (integer :tag "Less")
1120 (repeat :tag "Groups" regexp)
1121 (sexp :tag "Predicate")))
1123 (defvar gnus-article-treat-head-custom
1124 '(choice (const :tag "Off" nil)
1125 (const :tag "Header" head)))
1127 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1128 "text/x-patch" "text/html")
1129 "Part types eligible for treatment.")
1131 (defvar gnus-inhibit-treatment nil
1132 "Whether to inhibit treatment.")
1134 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1135 "Highlight the signature.
1136 Valid values are nil, t, `head', `first', `last', an integer or a
1137 predicate. See Info node `(gnus)Customizing Articles'."
1138 :group 'gnus-article-treat
1139 :link '(custom-manual "(gnus)Customizing Articles")
1140 :type gnus-article-treat-custom)
1141 (put 'gnus-treat-highlight-signature 'highlight t)
1143 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1144 "Add buttons.
1145 Valid values are nil, t, `head', `first', `last', an integer or a
1146 predicate. See Info node `(gnus)Customizing Articles'."
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1150 (put 'gnus-treat-buttonize 'highlight t)
1152 (defcustom gnus-treat-buttonize-head 'head
1153 "Add buttons to the head.
1154 Valid values are nil, t, `head', `first', `last', an integer or a
1155 predicate. See Info node `(gnus)Customizing Articles'."
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-head-custom)
1159 (put 'gnus-treat-buttonize-head 'highlight t)
1161 (defcustom gnus-treat-date 'head
1162 "Display dates according to the `gnus-article-date-headers' variable.
1163 Valid values are nil, t, `head', `first', `last', an integer or a
1164 predicate. See Info node `(gnus)Customizing Articles'."
1165 :version "24.1"
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-head-custom)
1170 (defcustom gnus-treat-emphasize 50000
1171 "Emphasize text.
1172 Valid values are nil, t, `head', `first', `last', an integer or a
1173 predicate. See Info node `(gnus)Customizing Articles'."
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1177 (put 'gnus-treat-emphasize 'highlight t)
1179 (defcustom gnus-treat-strip-cr nil
1180 "Remove carriage returns.
1181 Valid values are nil, t, `head', `first', `last', an integer or a
1182 predicate. See Info node `(gnus)Customizing Articles'."
1183 :version "22.1"
1184 :group 'gnus-article-treat
1185 :link '(custom-manual "(gnus)Customizing Articles")
1186 :type gnus-article-treat-custom)
1188 (defcustom gnus-treat-unsplit-urls nil
1189 "Remove newlines from within URLs.
1190 Valid values are nil, t, `head', `first', `last', an integer or a
1191 predicate. See Info node `(gnus)Customizing Articles'."
1192 :version "22.1"
1193 :group 'gnus-article-treat
1194 :link '(custom-manual "(gnus)Customizing Articles")
1195 :type gnus-article-treat-custom)
1197 (defcustom gnus-treat-leading-whitespace nil
1198 "Remove leading whitespace in headers.
1199 Valid values are nil, t, `head', `first', `last', an integer or a
1200 predicate. See Info node `(gnus)Customizing Articles'."
1201 :version "22.1"
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-hide-headers 'head
1207 "Hide headers.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :group 'gnus-article-treat
1211 :link '(custom-manual "(gnus)Customizing Articles")
1212 :type gnus-article-treat-head-custom)
1214 (defcustom gnus-treat-hide-boring-headers nil
1215 "Hide boring headers.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-head-custom)
1222 (defcustom gnus-treat-hide-signature nil
1223 "Hide the signature.
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-fill-article nil
1231 "Fill the article.
1232 Valid values are nil, t, `head', `first', `last', an integer or a
1233 predicate. See Info node `(gnus)Customizing Articles'."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (defcustom gnus-treat-hide-citation nil
1239 "Hide cited text.
1240 Valid values are nil, t, `head', `first', `last', an integer or a
1241 predicate. See Info node `(gnus)Customizing Articles'.
1243 See `gnus-article-highlight-citation' for variables used to
1244 control what it hides."
1245 :group 'gnus-article-treat
1246 :link '(custom-manual "(gnus)Customizing Articles")
1247 :type gnus-article-treat-custom)
1249 (defcustom gnus-treat-hide-citation-maybe nil
1250 "Hide cited text according to certain conditions.
1251 Valid values are nil, t, `head', `first', `last', an integer or a
1252 predicate. See Info node `(gnus)Customizing Articles'.
1254 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1255 how to control what it hides."
1256 :group 'gnus-article-treat
1257 :link '(custom-manual "(gnus)Customizing Articles")
1258 :type gnus-article-treat-custom)
1260 (defcustom gnus-treat-strip-list-identifiers 'head
1261 "Strip list identifiers from `gnus-list-identifiers`.
1262 Valid values are nil, t, `head', `first', `last', an integer or a
1263 predicate. See Info node `(gnus)Customizing Articles'."
1264 :version "21.1"
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-custom)
1269 (gnus-define-group-parameter
1270 list-identifier
1271 :variable-document
1272 "Alist of regexps and correspondent identifiers."
1273 :variable-group gnus-article-washing
1274 :parameter-type
1275 '(choice :tag "Identifier"
1276 :value nil
1277 (symbol :tag "Item in `gnus-list-identifiers'" none)
1278 regexp
1279 (const :tag "None" nil))
1280 :parameter-document
1281 "If non-nil, specify how to remove `identifiers' from articles' subject.
1283 Any symbol is used to look up a regular expression to match the
1284 banner in `gnus-list-identifiers'. A string is used as a regular
1285 expression to match the identifier directly.")
1287 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1288 "Gnus 5.10 (Emacs 22.1)")
1290 (defcustom gnus-treat-strip-pem nil
1291 "Strip PEM signatures.
1292 Valid values are nil, t, `head', `first', `last', an integer or a
1293 predicate. See Info node `(gnus)Customizing Articles'."
1294 :group 'gnus-article-treat
1295 :link '(custom-manual "(gnus)Customizing Articles")
1296 :type gnus-article-treat-custom)
1298 (defcustom gnus-treat-strip-banner t
1299 "Strip banners from articles.
1300 The banner to be stripped is specified in the `banner' group parameter.
1301 Valid values are nil, t, `head', `first', `last', an integer or a
1302 predicate. See Info node `(gnus)Customizing Articles'."
1303 :group 'gnus-article-treat
1304 :link '(custom-manual "(gnus)Customizing Articles")
1305 :type gnus-article-treat-custom)
1307 (defcustom gnus-treat-highlight-headers 'head
1308 "Highlight the headers.
1309 Valid values are nil, t, `head', `first', `last', an integer or a
1310 predicate. See Info node `(gnus)Customizing Articles'."
1311 :group 'gnus-article-treat
1312 :link '(custom-manual "(gnus)Customizing Articles")
1313 :type gnus-article-treat-head-custom)
1314 (put 'gnus-treat-highlight-headers 'highlight t)
1316 (defcustom gnus-treat-highlight-citation t
1317 "Highlight cited text.
1318 Valid values are nil, t, `head', `first', `last', an integer or a
1319 predicate. See Info node `(gnus)Customizing Articles'."
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1323 (put 'gnus-treat-highlight-citation 'highlight t)
1325 (defcustom gnus-treat-strip-headers-in-body t
1326 "Strip the X-No-Archive header line from the beginning of the body.
1327 Valid values are nil, t, `head', `first', `last', an integer or a
1328 predicate. See Info node `(gnus)Customizing Articles'."
1329 :version "21.1"
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1334 (defcustom gnus-treat-strip-trailing-blank-lines nil
1335 "Strip trailing blank lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'.
1339 When set to t, it also strips trailing blanks in all MIME parts.
1340 Consider to use `last' instead."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-leading-blank-lines nil
1346 "Strip leading blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'.
1350 When set to t, it also strips trailing blanks in all MIME parts."
1351 :group 'gnus-article-treat
1352 :link '(custom-manual "(gnus)Customizing Articles")
1353 :type gnus-article-treat-custom)
1355 (defcustom gnus-treat-strip-multiple-blank-lines nil
1356 "Strip multiple blank lines.
1357 Valid values are nil, t, `head', `first', `last', an integer or a
1358 predicate. See Info node `(gnus)Customizing Articles'."
1359 :group 'gnus-article-treat
1360 :link '(custom-manual "(gnus)Customizing Articles")
1361 :type gnus-article-treat-custom)
1363 (defcustom gnus-treat-unfold-headers 'head
1364 "Unfold folded header lines.
1365 Valid values are nil, t, `head', `first', `last', an integer or a
1366 predicate. See Info node `(gnus)Customizing Articles'."
1367 :version "22.1"
1368 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :type gnus-article-treat-custom)
1372 (defcustom gnus-article-unfold-long-headers nil
1373 "If non-nil, allow unfolding headers even if the header is long.
1374 If it is a regexp, only long headers matching this regexp are unfolded.
1375 If it is t, all long headers are unfolded.
1377 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1378 :version "23.1" ;; No Gnus
1379 :group 'gnus-article-treat
1380 :type '(choice (const nil)
1381 (const :tag "all" t)
1382 (regexp)))
1384 (defcustom gnus-treat-fold-headers nil
1385 "Fold headers.
1386 Valid values are nil, t, `head', `first', `last', an integer or a
1387 predicate. See Info node `(gnus)Customizing Articles'."
1388 :version "22.1"
1389 :group 'gnus-article-treat
1390 :link '(custom-manual "(gnus)Customizing Articles")
1391 :type gnus-article-treat-custom)
1393 (defcustom gnus-treat-fold-newsgroups 'head
1394 "Fold the Newsgroups and Followup-To headers.
1395 Valid values are nil, t, `head', `first', `last', an integer or a
1396 predicate. See Info node `(gnus)Customizing Articles'."
1397 :version "22.1"
1398 :group 'gnus-article-treat
1399 :link '(custom-manual "(gnus)Customizing Articles")
1400 :type gnus-article-treat-custom)
1402 (defcustom gnus-treat-overstrike t
1403 "Treat overstrike highlighting.
1404 Valid values are nil, t, `head', `first', `last', an integer or a
1405 predicate. See Info node `(gnus)Customizing Articles'."
1406 :group 'gnus-article-treat
1407 :link '(custom-manual "(gnus)Customizing Articles")
1408 :type gnus-article-treat-custom)
1409 (put 'gnus-treat-overstrike 'highlight t)
1411 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1412 "Treat ANSI SGR control sequences.
1413 Valid values are nil, t, `head', `first', `last', an integer or a
1414 predicate. See Info node `(gnus)Customizing Articles'."
1415 :group 'gnus-article-treat
1416 :link '(custom-manual "(gnus)Customizing Articles")
1417 :type gnus-article-treat-custom)
1419 (make-obsolete-variable 'gnus-treat-display-xface
1420 'gnus-treat-display-x-face "Emacs 22.1")
1422 (defcustom gnus-treat-display-x-face
1423 (and (not noninteractive)
1424 (gnus-image-type-available-p 'xbm)
1425 (if (featurep 'xemacs)
1426 (featurep 'xface)
1427 (condition-case nil
1428 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1429 (executable-find "icontopbm"))
1430 ;; shell-command-to-string may signal an error, e.g. if
1431 ;; shell-file-name is not found.
1432 (error nil)))
1433 'head)
1434 "Display X-Face headers.
1435 Valid values are nil and `head'.
1436 See Info node `(gnus)Customizing Articles' and Info node
1437 `(gnus)X-Face' for details."
1438 :group 'gnus-article-treat
1439 :version "21.1"
1440 :link '(custom-manual "(gnus)Customizing Articles")
1441 :link '(custom-manual "(gnus)X-Face")
1442 :type gnus-article-treat-head-custom
1443 :set (lambda (symbol value)
1444 (set-default
1445 symbol
1446 (cond ((or (boundp symbol) (get symbol 'saved-value))
1447 value)
1448 ((boundp 'gnus-treat-display-xface)
1449 (message "\
1450 ** gnus-treat-display-xface is an obsolete variable;\
1451 use gnus-treat-display-x-face instead")
1452 (default-value 'gnus-treat-display-xface))
1453 ((get 'gnus-treat-display-xface 'saved-value)
1454 (message "\
1455 ** gnus-treat-display-xface is an obsolete variable;\
1456 use gnus-treat-display-x-face instead")
1457 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1459 value)))))
1460 (put 'gnus-treat-display-x-face 'highlight t)
1462 (defcustom gnus-treat-display-face
1463 (and (not noninteractive)
1464 (gnus-image-type-available-p 'png)
1465 'head)
1466 "Display Face headers.
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)Face' for details."
1470 :group 'gnus-article-treat
1471 :version "22.1"
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :link '(custom-manual "(gnus)X-Face")
1474 :type gnus-article-treat-head-custom)
1475 (put 'gnus-treat-display-face 'highlight t)
1477 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1478 "Display smileys.
1479 Valid values are nil, t, `head', `first', `last', an integer or a
1480 predicate. See Info node `(gnus)Customizing Articles' and Info
1481 node `(gnus)Smileys' for details."
1482 :group 'gnus-article-treat
1483 :version "21.1"
1484 :link '(custom-manual "(gnus)Customizing Articles")
1485 :link '(custom-manual "(gnus)Smileys")
1486 :type gnus-article-treat-custom)
1487 (put 'gnus-treat-display-smileys 'highlight t)
1489 (defcustom gnus-treat-from-picon
1490 (if (and (gnus-image-type-available-p 'xpm)
1491 (gnus-picons-installed-p))
1492 'head nil)
1493 "Display picons in the From header.
1494 Valid values are nil, t, `head', `first', `last', an integer or a
1495 predicate. See Info node `(gnus)Customizing Articles' and Info
1496 node `(gnus)Picons' for details."
1497 :version "22.1"
1498 :group 'gnus-article-treat
1499 :group 'gnus-picon
1500 :link '(custom-manual "(gnus)Customizing Articles")
1501 :link '(custom-manual "(gnus)Picons")
1502 :type gnus-article-treat-head-custom)
1503 (put 'gnus-treat-from-picon 'highlight t)
1505 (defcustom gnus-treat-mail-picon
1506 (if (and (gnus-image-type-available-p 'xpm)
1507 (gnus-picons-installed-p))
1508 'head nil)
1509 "Display picons in To and Cc headers.
1510 Valid values are nil, t, `head', `first', `last', an integer or a
1511 predicate. See Info node `(gnus)Customizing Articles' and Info
1512 node `(gnus)Picons' for details."
1513 :version "22.1"
1514 :group 'gnus-article-treat
1515 :group 'gnus-picon
1516 :link '(custom-manual "(gnus)Customizing Articles")
1517 :link '(custom-manual "(gnus)Picons")
1518 :type gnus-article-treat-head-custom)
1519 (put 'gnus-treat-mail-picon 'highlight t)
1521 (defcustom gnus-treat-newsgroups-picon
1522 (if (and (gnus-image-type-available-p 'xpm)
1523 (gnus-picons-installed-p))
1524 'head nil)
1525 "Display picons in the Newsgroups and Followup-To headers.
1526 Valid values are nil, t, `head', `first', `last', an integer or a
1527 predicate. See Info node `(gnus)Customizing Articles' and Info
1528 node `(gnus)Picons' for details."
1529 :version "22.1"
1530 :group 'gnus-article-treat
1531 :group 'gnus-picon
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :link '(custom-manual "(gnus)Picons")
1534 :type gnus-article-treat-head-custom)
1535 (put 'gnus-treat-newsgroups-picon 'highlight t)
1537 (defcustom gnus-treat-from-gravatar nil
1538 "Display gravatars in the From header.
1539 Valid values are nil, t, `head', `first', `last', an integer or a
1540 predicate. See Info node `(gnus)Customizing Articles' and Info
1541 node `(gnus)Gravatars' for details."
1542 :version "24.1"
1543 :group 'gnus-article-treat
1544 :group 'gnus-gravatar
1545 :link '(custom-manual "(gnus)Customizing Articles")
1546 :link '(custom-manual "(gnus)Gravatars")
1547 :type gnus-article-treat-head-custom)
1548 (put 'gnus-treat-from-gravatar 'highlight t)
1550 (defcustom gnus-treat-mail-gravatar nil
1551 "Display gravatars in To and Cc headers.
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles' and Info
1554 node `(gnus)Gravatars' for details."
1555 :version "24.1"
1556 :group 'gnus-article-treat
1557 :group 'gnus-gravatar
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :link '(custom-manual "(gnus)Gravatars")
1560 :type gnus-article-treat-head-custom)
1561 (put 'gnus-treat-mail-gravatar 'highlight t)
1563 (defcustom gnus-treat-body-boundary
1564 (if (or gnus-treat-newsgroups-picon
1565 gnus-treat-mail-picon
1566 gnus-treat-from-picon
1567 gnus-treat-from-gravatar
1568 gnus-treat-mail-gravatar)
1569 ;; If there's much decoration, the user might prefer a boundary.
1570 'head
1571 nil)
1572 "Draw a boundary at the end of the headers.
1573 Valid values are nil and `head'.
1574 See Info node `(gnus)Customizing Articles' for details."
1575 :version "22.1"
1576 :group 'gnus-article-treat
1577 :link '(custom-manual "(gnus)Customizing Articles")
1578 :type gnus-article-treat-head-custom)
1580 (defcustom gnus-treat-capitalize-sentences nil
1581 "Capitalize sentence-starting words.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1584 :version "21.1"
1585 :group 'gnus-article-treat
1586 :link '(custom-manual "(gnus)Customizing Articles")
1587 :type gnus-article-treat-custom)
1589 (defcustom gnus-treat-wash-html nil
1590 "Format as HTML.
1591 Valid values are nil, t, `head', `first', `last', an integer or a
1592 predicate. See Info node `(gnus)Customizing Articles'."
1593 :version "22.1"
1594 :group 'gnus-article-treat
1595 :link '(custom-manual "(gnus)Customizing Articles")
1596 :type gnus-article-treat-custom)
1598 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1599 "Fill long lines.
1600 Valid values are nil, t, `head', `first', `last', an integer or a
1601 predicate. See Info node `(gnus)Customizing Articles'."
1602 :version "24.1"
1603 :group 'gnus-article-treat
1604 :link '(custom-manual "(gnus)Customizing Articles")
1605 :type gnus-article-treat-custom)
1607 (defcustom gnus-treat-x-pgp-sig nil
1608 "Verify X-PGP-Sig.
1609 To automatically treat X-PGP-Sig, set it to head.
1610 Valid values are nil, t, `head', `first', `last', an integer or a
1611 predicate. See Info node `(gnus)Customizing Articles'."
1612 :version "22.1"
1613 :group 'gnus-article-treat
1614 :group 'mime-security
1615 :link '(custom-manual "(gnus)Customizing Articles")
1616 :type gnus-article-treat-custom)
1618 (defvar gnus-article-encrypt-protocol-alist
1619 '(("PGP" . mml2015-self-encrypt)))
1621 ;; Set to nil if more than one protocol added to
1622 ;; gnus-article-encrypt-protocol-alist.
1623 (defcustom gnus-article-encrypt-protocol "PGP"
1624 "The protocol used for encrypt articles.
1625 It is a string, such as \"PGP\". If nil, ask user."
1626 :version "22.1"
1627 :type 'string
1628 :group 'mime-security)
1630 (defvar idna-program)
1632 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1633 (mm-coding-system-p 'utf-8)
1634 idna-program
1635 (executable-find idna-program))
1636 "Whether IDNA decoding of headers is used when viewing messages.
1637 This requires GNU Libidn, and by default only enabled if it is found."
1638 :version "22.1"
1639 :group 'gnus-article-headers
1640 :type 'boolean)
1642 (defcustom gnus-article-over-scroll nil
1643 "If non-nil, allow scrolling the article buffer even when there no more text."
1644 :version "22.1"
1645 :group 'gnus-article
1646 :type 'boolean)
1648 (defcustom gnus-inhibit-images nil
1649 "Non-nil means inhibit displaying of images inline in the article body."
1650 :version "24.1"
1651 :group 'gnus-article
1652 :type 'boolean)
1654 (defcustom gnus-blocked-images 'gnus-block-private-groups
1655 "Images that have URLs matching this regexp will be blocked.
1656 This can also be a function to be evaluated. If so, it will be
1657 called with the group name as the parameter, and should return a
1658 regexp."
1659 :version "24.1"
1660 :group 'gnus-art
1661 :type '(choice regexp function))
1663 ;;; Internal variables
1665 (defvar gnus-english-month-names
1666 '("January" "February" "March" "April" "May" "June" "July" "August"
1667 "September" "October" "November" "December"))
1669 (defvar article-goto-body-goes-to-point-min-p nil)
1670 (defvar gnus-article-wash-types nil)
1671 (defvar gnus-article-emphasis-alist nil)
1672 (defvar gnus-article-image-alist nil)
1674 (defvar gnus-article-mime-handle-alist-1 nil)
1675 (defvar gnus-treatment-function-alist
1676 '((gnus-treat-strip-cr gnus-article-remove-cr)
1677 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1678 (gnus-treat-strip-banner gnus-article-strip-banner)
1679 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1680 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1681 (gnus-treat-buttonize gnus-article-add-buttons)
1682 (gnus-treat-fill-article gnus-article-fill-cited-article)
1683 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1684 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1685 (gnus-treat-display-x-face gnus-article-display-x-face)
1686 (gnus-treat-display-face gnus-article-display-face)
1687 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1688 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1689 (gnus-treat-hide-signature gnus-article-hide-signature)
1690 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1691 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1692 (gnus-treat-from-picon gnus-treat-from-picon)
1693 (gnus-treat-mail-picon gnus-treat-mail-picon)
1694 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1695 (gnus-treat-strip-pem gnus-article-hide-pem)
1696 (gnus-treat-date gnus-article-treat-date)
1697 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1698 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1699 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1700 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1701 (gnus-treat-strip-trailing-blank-lines
1702 gnus-article-remove-trailing-blank-lines)
1703 (gnus-treat-strip-leading-blank-lines
1704 gnus-article-strip-leading-blank-lines)
1705 (gnus-treat-strip-multiple-blank-lines
1706 gnus-article-strip-multiple-blank-lines)
1707 (gnus-treat-overstrike gnus-article-treat-overstrike)
1708 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1709 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1710 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1711 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1712 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1713 (gnus-treat-display-smileys gnus-treat-smiley)
1714 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1715 (gnus-treat-wash-html gnus-article-wash-html)
1716 (gnus-treat-emphasize gnus-article-emphasize)
1717 (gnus-treat-hide-citation gnus-article-hide-citation)
1718 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1719 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1720 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1722 (defvar gnus-article-mime-handle-alist nil)
1723 (defvar article-lapsed-timer nil)
1724 (defvar gnus-article-current-summary nil)
1726 (defvar gnus-article-mode-syntax-table
1727 (let ((table (copy-syntax-table text-mode-syntax-table)))
1728 ;; This causes the citation match run O(2^n).
1729 ;; (modify-syntax-entry ?- "w" table)
1730 (modify-syntax-entry ?> ")<" table)
1731 (modify-syntax-entry ?< "(>" table)
1732 ;; make M-. in article buffers work for `foo' strings
1733 (modify-syntax-entry ?' " " table)
1734 (modify-syntax-entry ?` " " table)
1735 table)
1736 "Syntax table used in article mode buffers.
1737 Initialized from `text-mode-syntax-table.")
1739 (defvar gnus-save-article-buffer nil)
1741 (defvar gnus-number-of-articles-to-be-saved nil)
1743 (defvar gnus-inhibit-hiding nil)
1745 (defvar gnus-article-edit-mode nil)
1747 ;;; Macros for dealing with the article buffer.
1749 (defmacro gnus-with-article-headers (&rest forms)
1750 `(with-current-buffer gnus-article-buffer
1751 (save-restriction
1752 (let ((inhibit-read-only t)
1753 (inhibit-point-motion-hooks t)
1754 (case-fold-search t))
1755 (article-narrow-to-head)
1756 ,@forms))))
1758 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1759 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1761 (defmacro gnus-with-article-buffer (&rest forms)
1762 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1763 (with-current-buffer gnus-article-buffer
1764 (let ((inhibit-read-only t))
1765 ,@forms))))
1767 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1768 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1770 (defun gnus-article-goto-header (header)
1771 "Go to HEADER, which is a regular expression."
1772 (re-search-forward (concat "^\\(" header "\\):") nil t))
1774 (defsubst gnus-article-hide-text (b e props)
1775 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1776 (gnus-add-text-properties-when 'article-type nil b e props)
1777 (when (memq 'intangible props)
1778 (put-text-property
1779 (max (1- b) (point-min))
1780 b 'intangible (cddr (memq 'intangible props)))))
1782 (defsubst gnus-article-unhide-text (b e)
1783 "Remove hidden text properties from region between B and E."
1784 (remove-text-properties b e gnus-hidden-properties)
1785 (when (memq 'intangible gnus-hidden-properties)
1786 (put-text-property (max (1- b) (point-min))
1787 b 'intangible nil)))
1789 (defun gnus-article-hide-text-type (b e type)
1790 "Hide text of TYPE between B and E."
1791 (gnus-add-wash-type type)
1792 (gnus-article-hide-text
1793 b e (cons 'article-type (cons type gnus-hidden-properties))))
1795 (defun gnus-article-unhide-text-type (b e type)
1796 "Unhide text of TYPE between B and E."
1797 (gnus-delete-wash-type type)
1798 (remove-text-properties
1799 b e (cons 'article-type (cons type gnus-hidden-properties)))
1800 (when (memq 'intangible gnus-hidden-properties)
1801 (put-text-property (max (1- b) (point-min))
1802 b 'intangible nil)))
1804 (defun gnus-article-delete-text-of-type (type)
1805 "Delete text of TYPE in the current buffer."
1806 (save-excursion
1807 (let ((b (point-min)))
1808 (if (eq type 'multipart)
1809 ;; Remove MIME buttons associated with multipart/alternative parts.
1810 (progn
1811 (goto-char b)
1812 (while (if (get-text-property (point) 'gnus-part)
1813 (setq b (point))
1814 (when (setq b (next-single-property-change (point)
1815 'gnus-part))
1816 (goto-char b)
1818 (end-of-line)
1819 (skip-chars-forward "\n")
1820 (when (eq (get-text-property b 'article-type) 'multipart)
1821 (delete-region b (point)))))
1822 (while (setq b (text-property-any b (point-max) 'article-type type))
1823 (delete-region
1824 b (or (text-property-not-all b (point-max) 'article-type type)
1825 (point-max))))))))
1827 (defun gnus-article-delete-invisible-text ()
1828 "Delete all invisible text in the current buffer."
1829 (save-excursion
1830 (let ((b (point-min)))
1831 (while (setq b (text-property-any b (point-max) 'invisible t))
1832 (delete-region
1833 b (or (text-property-not-all b (point-max) 'invisible t)
1834 (point-max)))))))
1836 (defsubst gnus-article-header-rank ()
1837 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1838 (let ((list gnus-sorted-header-list)
1839 (i 1))
1840 (while list
1841 (if (looking-at (car list))
1842 (setq list nil)
1843 (setq list (cdr list))
1844 (incf i)))
1847 (defun article-hide-headers (&optional _arg _delete)
1848 "Hide unwanted headers and possibly sort them as well."
1849 (interactive)
1850 ;; This function might be inhibited.
1851 (unless gnus-inhibit-hiding
1852 (let ((inhibit-read-only t)
1853 (case-fold-search t)
1854 (max (1+ (length gnus-sorted-header-list)))
1855 (inhibit-point-motion-hooks t)
1856 (cur (current-buffer))
1857 ignored visible beg)
1858 (save-excursion
1859 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1860 ;; group parameters, so we should go to the summary buffer.
1861 (when (prog1
1862 (condition-case nil
1863 (progn (set-buffer gnus-summary-buffer) t)
1864 (error nil))
1865 (setq ignored (when (not gnus-visible-headers)
1866 (cond ((stringp gnus-ignored-headers)
1867 gnus-ignored-headers)
1868 ((listp gnus-ignored-headers)
1869 (mapconcat 'identity
1870 gnus-ignored-headers
1871 "\\|"))))
1872 visible (cond ((stringp gnus-visible-headers)
1873 gnus-visible-headers)
1874 ((and gnus-visible-headers
1875 (listp gnus-visible-headers))
1876 (mapconcat 'identity
1877 gnus-visible-headers
1878 "\\|")))))
1879 (set-buffer cur))
1880 (save-restriction
1881 ;; First we narrow to just the headers.
1882 (article-narrow-to-head)
1883 ;; Hide any "From " lines at the beginning of (mail) articles.
1884 (while (looking-at "From ")
1885 (forward-line 1))
1886 (unless (bobp)
1887 (delete-region (point-min) (point)))
1888 ;; Then treat the rest of the header lines.
1889 ;; Then we use the two regular expressions
1890 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1891 ;; select which header lines is to remain visible in the
1892 ;; article buffer.
1893 (while (re-search-forward "^[^ \t:]*:" nil t)
1894 (beginning-of-line)
1895 ;; Mark the rank of the header.
1896 (put-text-property
1897 (point) (1+ (point)) 'message-rank
1898 (if (or (and visible (looking-at visible))
1899 (and ignored
1900 (not (looking-at ignored))))
1901 (gnus-article-header-rank)
1902 (+ 2 max)))
1903 (forward-line 1))
1904 (message-sort-headers-1)
1905 (when (setq beg (text-property-any
1906 (point-min) (point-max) 'message-rank (+ 2 max)))
1907 ;; We delete the unwanted headers.
1908 (gnus-add-wash-type 'headers)
1909 (add-text-properties (point-min) (+ 5 (point-min))
1910 '(article-type headers dummy-invisible t))
1911 (delete-region beg (point-max))))))))
1913 (defun article-hide-boring-headers (&optional arg)
1914 "Toggle hiding of headers that aren't very interesting.
1915 If given a negative prefix, always show; if given a positive prefix,
1916 always hide."
1917 (interactive (gnus-article-hidden-arg))
1918 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1919 (not gnus-show-all-headers))
1920 (save-excursion
1921 (save-restriction
1922 (let ((inhibit-read-only t)
1923 (inhibit-point-motion-hooks t))
1924 (article-narrow-to-head)
1925 (dolist (elem gnus-boring-article-headers)
1926 (goto-char (point-min))
1927 (cond
1928 ;; Hide empty headers.
1929 ((eq elem 'empty)
1930 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1931 (forward-line -1)
1932 (gnus-article-hide-text-type
1933 (point-at-bol)
1934 (progn
1935 (end-of-line)
1936 (if (re-search-forward "^[^ \t]" nil t)
1937 (match-beginning 0)
1938 (point-max)))
1939 'boring-headers)))
1940 ;; Hide boring Newsgroups header.
1941 ((eq elem 'newsgroups)
1942 (when (gnus-string-equal
1943 (gnus-fetch-field "newsgroups")
1944 (gnus-group-real-name
1945 (if (boundp 'gnus-newsgroup-name)
1946 gnus-newsgroup-name
1947 "")))
1948 (gnus-article-hide-header "newsgroups")))
1949 ((eq elem 'to-address)
1950 (let ((to (message-fetch-field "to"))
1951 (to-address
1952 (gnus-parameter-to-address
1953 (if (boundp 'gnus-newsgroup-name)
1954 gnus-newsgroup-name ""))))
1955 (when (and to to-address
1956 (ignore-errors
1957 (gnus-string-equal
1958 ;; only one address in To
1959 (nth 1 (mail-extract-address-components to))
1960 to-address)))
1961 (gnus-article-hide-header "to"))))
1962 ((eq elem 'to-list)
1963 (let ((to (message-fetch-field "to"))
1964 (to-list
1965 (gnus-parameter-to-list
1966 (if (boundp 'gnus-newsgroup-name)
1967 gnus-newsgroup-name ""))))
1968 (when (and to to-list
1969 (ignore-errors
1970 (gnus-string-equal
1971 ;; only one address in To
1972 (nth 1 (mail-extract-address-components to))
1973 to-list)))
1974 (gnus-article-hide-header "to"))))
1975 ((eq elem 'cc-list)
1976 (let ((cc (message-fetch-field "cc"))
1977 (to-list
1978 (gnus-parameter-to-list
1979 (if (boundp 'gnus-newsgroup-name)
1980 gnus-newsgroup-name ""))))
1981 (when (and cc to-list
1982 (ignore-errors
1983 (gnus-string-equal
1984 ;; only one address in CC
1985 (nth 1 (mail-extract-address-components cc))
1986 to-list)))
1987 (gnus-article-hide-header "cc"))))
1988 ((eq elem 'followup-to)
1989 (when (gnus-string-equal
1990 (message-fetch-field "followup-to")
1991 (message-fetch-field "newsgroups"))
1992 (gnus-article-hide-header "followup-to")))
1993 ((eq elem 'reply-to)
1994 (if (gnus-group-find-parameter
1995 gnus-newsgroup-name 'broken-reply-to)
1996 (gnus-article-hide-header "reply-to")
1997 (let ((from (message-fetch-field "from"))
1998 (reply-to (message-fetch-field "reply-to")))
1999 (when
2000 (and
2001 from reply-to
2002 (ignore-errors
2003 (equal
2004 (sort (mapcar
2005 (lambda (x) (downcase (cadr x)))
2006 (mail-extract-address-components from t))
2007 'string<)
2008 (sort (mapcar
2009 (lambda (x) (downcase (cadr x)))
2010 (mail-extract-address-components reply-to t))
2011 'string<))))
2012 (gnus-article-hide-header "reply-to")))))
2013 ((eq elem 'date)
2014 (let ((date (with-current-buffer gnus-original-article-buffer
2015 ;; If date in `gnus-article-buffer' is localized
2016 ;; (`gnus-treat-date-user-defined'),
2017 ;; `days-between' might fail.
2018 (message-fetch-field "date"))))
2019 (when (and date
2020 (< (days-between (current-time-string) date)
2022 (gnus-article-hide-header "date"))))
2023 ((eq elem 'long-to)
2024 (let ((to (message-fetch-field "to"))
2025 (cc (message-fetch-field "cc")))
2026 (when (> (length to) 1024)
2027 (gnus-article-hide-header "to"))
2028 (when (> (length cc) 1024)
2029 (gnus-article-hide-header "cc"))))
2030 ((eq elem 'many-to)
2031 (let ((to-count 0)
2032 (cc-count 0))
2033 (goto-char (point-min))
2034 (while (re-search-forward "^to:" nil t)
2035 (setq to-count (1+ to-count)))
2036 (when (> to-count 1)
2037 (while (> to-count 0)
2038 (goto-char (point-min))
2039 (save-restriction
2040 (re-search-forward "^to:" nil nil to-count)
2041 (forward-line -1)
2042 (narrow-to-region (point) (point-max))
2043 (gnus-article-hide-header "to"))
2044 (setq to-count (1- to-count))))
2045 (goto-char (point-min))
2046 (while (re-search-forward "^cc:" nil t)
2047 (setq cc-count (1+ cc-count)))
2048 (when (> cc-count 1)
2049 (while (> cc-count 0)
2050 (goto-char (point-min))
2051 (save-restriction
2052 (re-search-forward "^cc:" nil nil cc-count)
2053 (forward-line -1)
2054 (narrow-to-region (point) (point-max))
2055 (gnus-article-hide-header "cc"))
2056 (setq cc-count (1- cc-count)))))))))))))
2058 (defun gnus-article-hide-header (header)
2059 (save-excursion
2060 (goto-char (point-min))
2061 (when (re-search-forward (concat "^" header ":") nil t)
2062 (gnus-article-hide-text-type
2063 (point-at-bol)
2064 (progn
2065 (end-of-line)
2066 (if (re-search-forward "^[^ \t]" nil t)
2067 (match-beginning 0)
2068 (point-max)))
2069 'boring-headers))))
2071 (defvar gnus-article-normalized-header-length 40
2072 "Length of normalized headers.")
2074 (defun article-normalize-headers ()
2075 "Make all header lines 40 characters long."
2076 (interactive)
2077 (let ((inhibit-read-only t)
2078 column)
2079 (save-excursion
2080 (save-restriction
2081 (article-narrow-to-head)
2082 (while (not (eobp))
2083 (cond
2084 ((< (setq column (- (point-at-eol) (point)))
2085 gnus-article-normalized-header-length)
2086 (end-of-line)
2087 (insert (make-string
2088 (- gnus-article-normalized-header-length column)
2089 ? )))
2090 ((> column gnus-article-normalized-header-length)
2091 (gnus-put-text-property
2092 (progn
2093 (forward-char gnus-article-normalized-header-length)
2094 (point))
2095 (point-at-eol)
2096 'invisible t))
2098 ;; Do nothing.
2100 (forward-line 1))))))
2102 (defun article-treat-dumbquotes ()
2103 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2104 Note that this function guesses whether a character is a sm*rtq**t* or
2105 not, so it should only be used interactively.
2107 Sm*rtq**t*s are M****s***'s unilateral extension to the
2108 iso-8859-1 character map in an attempt to provide more quoting
2109 characters. If you see something like \\222 or \\264 where
2110 you're expecting some kind of apostrophe or quotation mark, then
2111 try this wash."
2112 (interactive)
2113 (article-translate-strings gnus-article-dumbquotes-map))
2115 (defvar org-entities)
2117 (defun article-treat-non-ascii ()
2118 "Translate many Unicode characters into their ASCII equivalents."
2119 (interactive)
2120 (require 'org-entities)
2121 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2122 (dolist (elem org-entities)
2123 (when (and (listp elem)
2124 (= (length (nth 6 elem)) 1))
2125 (if (featurep 'xemacs)
2126 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2127 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2128 (save-excursion
2129 (when (article-goto-body)
2130 (let ((inhibit-read-only t)
2131 replace props)
2132 (while (not (eobp))
2133 (if (not (setq replace (if (featurep 'xemacs)
2134 (get-char-table (following-char) table)
2135 (aref table (following-char)))))
2136 (forward-char 1)
2137 (if (prog1
2138 (setq props (text-properties-at (point)))
2139 (delete-char 1))
2140 (add-text-properties (point) (progn (insert replace) (point))
2141 props)
2142 (insert replace)))))))))
2144 (defun article-translate-strings (map)
2145 "Translate all string in the body of the article according to MAP.
2146 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2147 (save-excursion
2148 (when (article-goto-body)
2149 (let ((inhibit-read-only t))
2150 (dolist (elem map)
2151 (let ((from (car elem))
2152 (to (cadr elem)))
2153 (save-excursion
2154 (if (stringp from)
2155 (while (search-forward from nil t)
2156 (replace-match to))
2157 (while (not (eobp))
2158 (if (eq (following-char) from)
2159 (progn
2160 (delete-char 1)
2161 (insert to))
2162 (forward-char 1)))))))))))
2164 (defun article-treat-overstrike ()
2165 "Translate overstrikes into bold text."
2166 (interactive)
2167 (save-excursion
2168 (when (article-goto-body)
2169 (let ((inhibit-read-only t))
2170 (while (search-forward "\b" nil t)
2171 (let ((next (char-after))
2172 (previous (char-after (- (point) 2))))
2173 ;; We do the boldification/underlining by hiding the
2174 ;; overstrikes and putting the proper text property
2175 ;; on the letters.
2176 (cond
2177 ((eq next previous)
2178 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2179 (put-text-property (point) (1+ (point)) 'face 'bold))
2180 ((eq next ?_)
2181 (gnus-article-hide-text-type
2182 (1- (point)) (1+ (point)) 'overstrike)
2183 (put-text-property
2184 (- (point) 2) (1- (point)) 'face 'underline))
2185 ((eq previous ?_)
2186 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2187 (put-text-property
2188 (point) (1+ (point)) 'face 'underline)))))))))
2190 (defun article-treat-ansi-sequences ()
2191 "Translate ANSI SGR control sequences into overlays or extents."
2192 (interactive)
2193 (save-excursion
2194 (when (article-goto-body)
2195 (let ((inhibit-read-only t))
2196 (ansi-color-apply-on-region (point) (point-max))))))
2198 (defun gnus-article-treat-unfold-headers ()
2199 "Unfold folded message headers.
2200 Only the headers that fit into the current window width will be
2201 unfolded."
2202 (interactive)
2203 (gnus-with-article-headers
2204 (let (length)
2205 (while (not (eobp))
2206 (save-restriction
2207 (mail-header-narrow-to-field)
2208 (let* ((header (buffer-string))
2209 (unfoldable
2210 (or (equal gnus-article-unfold-long-headers t)
2211 (and (stringp gnus-article-unfold-long-headers)
2212 (string-match gnus-article-unfold-long-headers
2213 header)))))
2214 (with-temp-buffer
2215 (insert header)
2216 (goto-char (point-min))
2217 (while (re-search-forward "\n[\t ]" nil t)
2218 (replace-match " " t t)))
2219 (setq length (- (point-max) (point-min) 1))
2220 (when (or unfoldable
2221 (< length (window-width)))
2222 (while (re-search-forward "\n[\t ]" nil t)
2223 (replace-match " " t t))))
2224 (goto-char (point-max)))))))
2226 (defun gnus-article-treat-fold-headers ()
2227 "Fold message headers."
2228 (interactive)
2229 (gnus-with-article-headers
2230 (while (not (eobp))
2231 (save-restriction
2232 (mail-header-narrow-to-field)
2233 (mail-header-fold-field)
2234 (goto-char (point-max))))))
2236 (defun gnus-treat-smiley ()
2237 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2238 (interactive)
2239 (gnus-with-article-buffer
2240 (if (memq 'smiley gnus-article-wash-types)
2241 (gnus-delete-images 'smiley)
2242 (article-goto-body)
2243 (let ((images (smiley-region (point) (point-max))))
2244 (when images
2245 (gnus-add-wash-type 'smiley)
2246 (dolist (image images)
2247 (gnus-add-image 'smiley image)))))))
2249 (defun gnus-article-remove-images ()
2250 "Remove all images from the article buffer."
2251 (interactive)
2252 (gnus-with-article-buffer
2253 (save-restriction
2254 (widen)
2255 (dolist (elem gnus-article-image-alist)
2256 (gnus-delete-images (car elem))))))
2258 (autoload 'w3m-toggle-inline-images "w3m")
2260 (defun gnus-article-show-images ()
2261 "Show any images that are in the HTML-rendered article buffer.
2262 This only works if the article in question is HTML."
2263 (interactive)
2264 (gnus-with-article-buffer
2265 (save-restriction
2266 (widen)
2267 (if (eq mm-text-html-renderer 'w3m)
2268 (let ((mm-inline-text-html-with-images nil))
2269 (w3m-toggle-inline-images))
2270 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2271 'image-displayer))
2272 (destructuring-bind (start end function) region
2273 (funcall function (get-text-property start 'image-url)
2274 start end)))))))
2276 (defun gnus-article-treat-fold-newsgroups ()
2277 "Unfold folded message headers.
2278 Only the headers that fit into the current window width will be
2279 unfolded."
2280 (interactive)
2281 (gnus-with-article-headers
2282 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2283 (save-restriction
2284 (mail-header-narrow-to-field)
2285 (while (re-search-forward ", *" nil t)
2286 (replace-match ", " t t))
2287 (mail-header-fold-field)
2288 (goto-char (point-max))))))
2290 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2291 "Value of `truncate-lines' in Gnus Article buffer.
2292 Valid values are nil, t, `head', `first', `last', an integer or a
2293 predicate. See Info node `(gnus)Customizing Articles'."
2294 :version "23.1" ;; No Gnus
2295 :group 'gnus-article
2296 ;; :link '(custom-manual "(gnus)Customizing Articles")
2297 :type 'boolean)
2299 (defun gnus-article-toggle-truncate-lines (&optional arg)
2300 "Toggle whether to fold or truncate long lines in article the buffer.
2301 If ARG is non-nil and not a number, toggle
2302 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2303 long lines if and only if arg is positive."
2304 (interactive "P")
2305 (cond
2306 ((and (numberp arg) (> arg 0))
2307 (setq gnus-article-truncate-lines t))
2308 ((numberp arg)
2309 (setq gnus-article-truncate-lines nil))
2310 (arg
2311 (setq gnus-article-truncate-lines
2312 (not gnus-article-truncate-lines))))
2313 (gnus-with-article-buffer
2314 (cond
2315 ((and (numberp arg) (> arg 0))
2316 (setq truncate-lines nil))
2317 ((numberp arg)
2318 (setq truncate-lines t)))
2319 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2320 ;; `toggle-truncate-lines' needs an argument.
2321 (toggle-truncate-lines)))
2323 (defun gnus-article-treat-body-boundary ()
2324 "Place a boundary line at the end of the headers."
2325 (interactive)
2326 (when (and gnus-body-boundary-delimiter
2327 (> (length gnus-body-boundary-delimiter) 0))
2328 (gnus-with-article-headers
2329 (goto-char (point-max))
2330 (let ((start (point)))
2331 (insert "X-Boundary: ")
2332 (gnus-add-text-properties start (point) '(invisible t intangible t))
2333 (insert (let (str (max (window-width)))
2334 (if (featurep 'xemacs)
2335 (setq max (1- max)))
2336 (while (>= max (length str))
2337 (setq str (concat str gnus-body-boundary-delimiter)))
2338 (substring str 0 max))
2339 "\n")
2340 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2342 (defun article-fill-long-lines ()
2343 "Fill lines that are wider than the window width."
2344 (interactive)
2345 (save-excursion
2346 (let ((inhibit-read-only t)
2347 (width (window-width (get-buffer-window (current-buffer)))))
2348 (save-restriction
2349 (article-goto-body)
2350 (let ((adaptive-fill-mode nil)) ;Why? -sm
2351 (while (not (eobp))
2352 (end-of-line)
2353 (when (>= (current-column) (min fill-column width))
2354 (narrow-to-region (min (1+ (point)) (point-max))
2355 (point-at-bol))
2356 (let ((goback (point-marker)))
2357 (fill-paragraph nil)
2358 (goto-char (marker-position goback)))
2359 (widen))
2360 (forward-line 1)))))))
2362 (defun article-capitalize-sentences ()
2363 "Capitalize the first word in each sentence."
2364 (interactive)
2365 (save-excursion
2366 (let ((inhibit-read-only t)
2367 (paragraph-start "^[\n\^L]"))
2368 (article-goto-body)
2369 (while (not (eobp))
2370 (capitalize-word 1)
2371 (forward-sentence)))))
2373 (defun article-remove-cr ()
2374 "Remove trailing CRs and then translate remaining CRs into LFs."
2375 (interactive)
2376 (save-excursion
2377 (let ((inhibit-read-only t))
2378 (goto-char (point-min))
2379 (while (re-search-forward "\r+$" nil t)
2380 (replace-match "" t t))
2381 (goto-char (point-min))
2382 (while (search-forward "\r" nil t)
2383 (replace-match "\n" t t)))))
2385 (defun article-remove-trailing-blank-lines ()
2386 "Remove all trailing blank lines from the article."
2387 (interactive)
2388 (save-excursion
2389 (let ((inhibit-read-only t))
2390 (goto-char (point-max))
2391 (delete-region
2392 (point)
2393 (progn
2394 (while (and (not (bobp))
2395 (looking-at "^[ \t]*$")
2396 (not (gnus-annotation-in-region-p
2397 (point) (point-at-eol))))
2398 (forward-line -1))
2399 (forward-line 1)
2400 (point))))))
2402 (defvar gnus-face-properties-alist)
2404 (defun article-display-face (&optional force)
2405 "Display any Face headers in the header."
2406 (interactive (list 'force))
2407 (let ((wash-face-p buffer-read-only))
2408 (gnus-with-article-headers
2409 ;; When displaying parts, this function can be called several times on
2410 ;; the same article, without any intended toggle semantic (as typing `W
2411 ;; D d' would have). So face deletion must occur only when we come from
2412 ;; an interactive command, that is when the *Article* buffer is
2413 ;; read-only.
2414 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2415 (gnus-delete-images 'face)
2416 (let ((from (message-fetch-field "from"))
2417 faces)
2418 (save-current-buffer
2419 (when (and wash-face-p
2420 (gnus-buffer-live-p gnus-original-article-buffer)
2421 (not (re-search-forward "^Face:[\t ]*" nil t)))
2422 (set-buffer gnus-original-article-buffer))
2423 (save-restriction
2424 (mail-narrow-to-head)
2425 (when (or force
2426 ;; Check whether this face is censored.
2427 (not (and gnus-article-x-face-too-ugly
2428 (or from
2429 (setq from (message-fetch-field "from")))
2430 (string-match gnus-article-x-face-too-ugly
2431 from))))
2432 (while (gnus-article-goto-header "Face")
2433 (push (mail-header-field-value) faces)))))
2434 (when faces
2435 (goto-char (point-min))
2436 (let (png image)
2437 (unless (setq from (gnus-article-goto-header "from"))
2438 (insert "From:")
2439 (setq from (point))
2440 (insert " [no `from' set]\n"))
2441 (while faces
2442 (when (setq png (gnus-convert-face-to-png (pop faces)))
2443 (setq image
2444 (apply 'gnus-create-image png 'png t
2445 (cdr (assq 'png gnus-face-properties-alist))))
2446 (goto-char from)
2447 (when image
2448 (gnus-add-wash-type 'face)
2449 (gnus-add-image 'face image)
2450 (gnus-put-image image nil 'face)))))))))))
2452 (defun article-display-x-face (&optional force)
2453 "Look for an X-Face header and display it if present."
2454 (interactive (list 'force))
2455 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2456 (gnus-with-article-headers
2457 ;; Delete the old process, if any.
2458 (when (process-status "article-x-face")
2459 (delete-process "article-x-face"))
2460 ;; See the comment in `article-display-face'.
2461 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2462 ;; We have already displayed X-Faces, so we remove them
2463 ;; instead.
2464 (gnus-delete-images 'xface)
2465 ;; Display X-Faces.
2466 (let ((from (message-fetch-field "from"))
2467 x-faces)
2468 (save-current-buffer
2469 (when (and wash-face-p
2470 (gnus-buffer-live-p gnus-original-article-buffer)
2471 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2472 ;; If type `W f', use gnus-original-article-buffer,
2473 ;; otherwise use the current buffer because displaying
2474 ;; RFC822 parts calls this function too.
2475 (set-buffer gnus-original-article-buffer))
2476 (save-restriction
2477 (mail-narrow-to-head)
2478 (and gnus-article-x-face-command
2479 (or force
2480 ;; Check whether this face is censored.
2481 (not (and gnus-article-x-face-too-ugly
2482 (or from
2483 (setq from (message-fetch-field "from")))
2484 (string-match gnus-article-x-face-too-ugly
2485 from))))
2486 (while (gnus-article-goto-header "X-Face")
2487 (push (mail-header-field-value) x-faces)))))
2488 (when x-faces
2489 ;; We display the face.
2490 (cond ((functionp gnus-article-x-face-command)
2491 ;; The command is a lisp function, so we call it.
2492 (mapc gnus-article-x-face-command x-faces))
2493 ((stringp gnus-article-x-face-command)
2494 ;; The command is a string, so we interpret the command
2495 ;; as a, well, command, and fork it off.
2496 (let ((process-connection-type nil))
2497 (gnus-set-process-query-on-exit-flag
2498 (start-process
2499 "article-x-face" nil shell-file-name
2500 shell-command-switch gnus-article-x-face-command)
2501 nil)
2502 ;; Sending multiple EOFs to xv doesn't work,
2503 ;; so we only do a single external face.
2504 (with-temp-buffer
2505 (insert (car x-faces))
2506 (process-send-region "article-x-face"
2507 (point-min) (point-max)))
2508 (process-send-eof "article-x-face")))
2510 (error "`%s' set to `%s' is not a function"
2511 gnus-article-x-face-command
2512 'gnus-article-x-face-command)))))))))
2514 (defun article-decode-mime-words ()
2515 "Decode all MIME-encoded words in the article."
2516 (interactive)
2517 (gnus-with-article-buffer
2518 (let ((inhibit-point-motion-hooks t)
2519 (mail-parse-charset gnus-newsgroup-charset)
2520 (mail-parse-ignored-charsets
2521 (with-current-buffer gnus-summary-buffer
2522 gnus-newsgroup-ignored-charsets)))
2523 (mail-decode-encoded-word-region (point-min) (point-max)))))
2525 (defun article-decode-charset (&optional prompt)
2526 "Decode charset-encoded text in the article.
2527 If PROMPT (the prefix), prompt for a coding system to use."
2528 (interactive "P")
2529 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2530 (inhibit-read-only t)
2531 (mail-parse-charset gnus-newsgroup-charset)
2532 (mail-parse-ignored-charsets
2533 (save-excursion (condition-case nil
2534 (set-buffer gnus-summary-buffer)
2535 (error))
2536 gnus-newsgroup-ignored-charsets))
2537 ct cte ctl charset format)
2538 (save-excursion
2539 (save-restriction
2540 (article-narrow-to-head)
2541 (setq ct (message-fetch-field "Content-Type" t)
2542 cte (message-fetch-field "Content-Transfer-Encoding" t)
2543 ctl (and ct (mail-header-parse-content-type ct))
2544 charset (cond
2545 (prompt
2546 (mm-read-coding-system "Charset to decode: "))
2547 (ctl
2548 (mail-content-type-get ctl 'charset)))
2549 format (and ctl (mail-content-type-get ctl 'format)))
2550 (when cte
2551 (setq cte (mail-header-strip cte)))
2552 (if (and ctl (not (string-match "/" (car ctl))))
2553 (setq ctl nil))
2554 (goto-char (point-max)))
2555 (forward-line 1)
2556 (save-restriction
2557 (narrow-to-region (point) (point-max))
2558 (when (and (eq mail-parse-charset 'gnus-decoded)
2559 (eq (mm-body-7-or-8) '8bit))
2560 ;; The text code could have been decoded.
2561 (setq charset mail-parse-charset))
2562 (when (and (or (not ctl)
2563 (equal (car ctl) "text/plain"))
2564 (not format)) ;; article with format will decode later.
2565 (mm-decode-body
2566 charset (and cte (intern (downcase
2567 (gnus-strip-whitespace cte))))
2568 (car ctl)))))))
2570 (defun article-decode-encoded-words ()
2571 "Remove encoded-word encoding from headers."
2572 (let ((inhibit-point-motion-hooks t)
2573 (mail-parse-charset gnus-newsgroup-charset)
2574 (mail-parse-ignored-charsets
2575 (save-excursion (condition-case nil
2576 (set-buffer gnus-summary-buffer)
2577 (error))
2578 gnus-newsgroup-ignored-charsets))
2579 (inhibit-read-only t)
2580 end start)
2581 (goto-char (point-min))
2582 (when (search-forward "\n\n" nil 'move)
2583 (forward-line -1))
2584 (setq end (point))
2585 (while (not (bobp))
2586 (while (progn
2587 (forward-line -1)
2588 (and (not (bobp))
2589 (memq (char-after) '(?\t ? )))))
2590 (setq start (point))
2591 (if (looking-at "\
2592 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2593 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2594 (funcall gnus-decode-address-function start end)
2595 (funcall gnus-decode-header-function start end))
2596 (goto-char (setq end start)))))
2598 (defun article-decode-group-name ()
2599 "Decode group names in Newsgroups, Followup-To and Xref headers."
2600 (let ((inhibit-point-motion-hooks t)
2601 (inhibit-read-only t)
2602 (method (gnus-find-method-for-group gnus-newsgroup-name))
2603 regexp)
2604 (when (and (or gnus-group-name-charset-method-alist
2605 gnus-group-name-charset-group-alist)
2606 (gnus-buffer-live-p gnus-original-article-buffer))
2607 (save-restriction
2608 (article-narrow-to-head)
2609 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2610 (with-current-buffer gnus-original-article-buffer
2611 (goto-char (point-min)))
2612 (setq regexp (concat "^" header
2613 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2614 (while (re-search-forward regexp nil t)
2615 (replace-match (save-match-data
2616 (gnus-decode-newsgroups
2617 ;; XXX how to use data in article buffer?
2618 (with-current-buffer gnus-original-article-buffer
2619 (re-search-forward regexp nil t)
2620 (match-string 1))
2621 gnus-newsgroup-name method))
2622 t t nil 1))
2623 (goto-char (point-min)))))))
2625 (autoload 'idna-to-unicode "idna")
2627 (defun article-decode-idna-rhs ()
2628 "Decode IDNA strings in RHS in various headers in current buffer.
2629 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2630 Mail-Reply-To: and Mail-Followup-To:."
2631 (when gnus-use-idna
2632 (save-restriction
2633 (let ((inhibit-point-motion-hooks t)
2634 (inhibit-read-only t))
2635 (article-narrow-to-head)
2636 (goto-char (point-min))
2637 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2638 (let (ace unicode)
2639 (when (save-match-data
2640 (and (setq ace (match-string 1))
2641 (save-excursion
2642 (and (re-search-backward "^[^ \t]" nil t)
2643 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2644 (setq unicode (idna-to-unicode ace))))
2645 (unless (string= ace unicode)
2646 (replace-match unicode nil nil nil 1)))))))))
2648 (defun article-de-quoted-unreadable (&optional force read-charset)
2649 "Translate a quoted-printable-encoded article.
2650 If FORCE, decode the article whether it is marked as quoted-printable
2651 or not.
2652 If READ-CHARSET, ask for a coding system."
2653 (interactive (list 'force current-prefix-arg))
2654 (save-excursion
2655 (let ((inhibit-read-only t) type charset)
2656 (if (gnus-buffer-live-p gnus-original-article-buffer)
2657 (with-current-buffer gnus-original-article-buffer
2658 (setq type
2659 (gnus-fetch-field "content-transfer-encoding"))
2660 (let* ((ct (gnus-fetch-field "content-type"))
2661 (ctl (and ct (mail-header-parse-content-type ct))))
2662 (setq charset (and ctl
2663 (mail-content-type-get ctl 'charset)))
2664 (if (stringp charset)
2665 (setq charset (intern (downcase charset)))))))
2666 (if read-charset
2667 (setq charset (mm-read-coding-system "Charset: " charset)))
2668 (unless charset
2669 (setq charset gnus-newsgroup-charset))
2670 (when (or force
2671 (and type (let ((case-fold-search t))
2672 (string-match "quoted-printable" type))))
2673 (article-goto-body)
2674 (quoted-printable-decode-region
2675 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2677 (defun article-de-base64-unreadable (&optional force read-charset)
2678 "Translate a base64 article.
2679 If FORCE, decode the article whether it is marked as base64 not.
2680 If READ-CHARSET, ask for a coding system."
2681 (interactive (list 'force current-prefix-arg))
2682 (save-excursion
2683 (let ((inhibit-read-only t) type charset)
2684 (if (gnus-buffer-live-p gnus-original-article-buffer)
2685 (with-current-buffer gnus-original-article-buffer
2686 (setq type
2687 (gnus-fetch-field "content-transfer-encoding"))
2688 (let* ((ct (gnus-fetch-field "content-type"))
2689 (ctl (and ct (mail-header-parse-content-type ct))))
2690 (setq charset (and ctl
2691 (mail-content-type-get ctl 'charset)))
2692 (if (stringp charset)
2693 (setq charset (intern (downcase charset)))))))
2694 (if read-charset
2695 (setq charset (mm-read-coding-system "Charset: " charset)))
2696 (unless charset
2697 (setq charset gnus-newsgroup-charset))
2698 (when (or force
2699 (and type (let ((case-fold-search t))
2700 (string-match "base64" type))))
2701 (article-goto-body)
2702 (save-restriction
2703 (narrow-to-region (point) (point-max))
2704 (base64-decode-region (point-min) (point-max))
2705 (mm-decode-coding-region
2706 (point-min) (point-max)
2707 (mm-charset-to-coding-system charset nil t)))))))
2709 (eval-when-compile
2710 (require 'rfc1843))
2712 (defun article-decode-HZ ()
2713 "Translate a HZ-encoded article."
2714 (interactive)
2715 (require 'rfc1843)
2716 (save-excursion
2717 (let ((inhibit-read-only t))
2718 (rfc1843-decode-region (point-min) (point-max)))))
2720 (defun article-unsplit-urls ()
2721 "Remove the newlines that some other mailers insert into URLs."
2722 (interactive)
2723 (save-excursion
2724 (let ((inhibit-read-only t))
2725 (goto-char (point-min))
2726 (while (re-search-forward
2727 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2728 (replace-match "\\1\\3" t)))
2729 (when (gmm-called-interactively-p 'any)
2730 (gnus-treat-article nil))))
2732 (defun article-wash-html ()
2733 "Format an HTML article."
2734 (interactive)
2735 (let ((handles nil)
2736 (buffer-read-only nil))
2737 (when (gnus-buffer-live-p gnus-original-article-buffer)
2738 (with-current-buffer gnus-original-article-buffer
2739 (setq handles (mm-dissect-buffer t t))))
2740 (article-goto-body)
2741 (delete-region (point) (point-max))
2742 (mm-enable-multibyte)
2743 (mm-inline-text-html handles)))
2745 (defvar gnus-article-browse-html-temp-list nil
2746 "List of temporary files created by `gnus-article-browse-html-parts'.
2747 Internal variable.")
2749 (defcustom gnus-article-browse-delete-temp 'ask
2750 "What to do with temporary files from `gnus-article-browse-html-parts'.
2751 If nil, don't delete temporary files. If it is t, delete them on
2752 exit from the summary buffer. If it is the symbol `file', query
2753 on each file, if it is `ask' ask once when exiting from the
2754 summary buffer."
2755 :group 'gnus-article
2756 :version "23.1" ;; No Gnus
2757 :type '(choice (const :tag "Don't delete" nil)
2758 (const :tag "Don't ask" t)
2759 (const :tag "Ask" ask)
2760 (const :tag "Ask for each file" file)))
2762 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2764 (defun gnus-article-browse-delete-temp-files (&optional how)
2765 "Delete temp-files created by `gnus-article-browse-html-parts'."
2766 (when (and gnus-article-browse-html-temp-list
2767 (progn
2768 (or how (setq how gnus-article-browse-delete-temp))
2769 (if (eq how 'ask)
2770 (let ((files (length gnus-article-browse-html-temp-list)))
2771 (or (gnus-y-or-n-p
2772 (if (= files 1)
2773 "Delete the temporary HTML file? "
2774 (format "Delete all %s temporary HTML files? "
2775 files)))
2776 (setq gnus-article-browse-html-temp-list nil)))
2777 how)))
2778 (dolist (file gnus-article-browse-html-temp-list)
2779 (cond ((file-directory-p file)
2780 (when (or (not (eq how 'file))
2781 (gnus-y-or-n-p
2782 (format
2783 "Delete temporary HTML file(s) in directory `%s'? "
2784 (file-name-as-directory file))))
2785 (gnus-delete-directory file)))
2786 ((file-exists-p file)
2787 (when (or (not (eq how 'file))
2788 (gnus-y-or-n-p
2789 (format "Delete temporary HTML file `%s'? " file)))
2790 (delete-file file)))))
2791 ;; Also remove file from the list when not deleted or if file doesn't
2792 ;; exist anymore.
2793 (setq gnus-article-browse-html-temp-list nil))
2794 gnus-article-browse-html-temp-list)
2796 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2797 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2798 Return file name relative to the parent of DIRECTORY."
2799 (save-match-data
2800 (let (file afile)
2801 (catch 'found
2802 (dolist (handle handles)
2803 (cond
2804 ((not (listp handle)))
2805 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2806 ;; may create.
2807 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2808 ((equal (mm-handle-media-supertype handle) "multipart")
2809 (when (setq file (gnus-article-browse-html-save-cid-content
2810 cid handle directory))
2811 (throw 'found file)))
2812 ((equal (concat "<" cid ">") (mm-handle-id handle))
2813 (setq file (or (mm-handle-filename handle)
2814 (concat
2815 (make-temp-name "cid")
2816 (car (rassoc (car (mm-handle-type handle))
2817 mailcap-mime-extensions))))
2818 afile (expand-file-name file directory))
2819 (mm-save-part-to-file handle afile)
2820 (throw 'found (concat (file-name-nondirectory
2821 (directory-file-name directory))
2822 "/" file)))))))))
2824 (defun gnus-article-browse-html-parts (list &optional header)
2825 "View all \"text/html\" parts from LIST.
2826 Recurse into multiparts. The optional HEADER that should be a decoded
2827 message header will be added to the bodies of the \"text/html\" parts."
2828 ;; Internal function used by `gnus-article-browse-html-article'.
2829 (let (type file charset content cid-dir tmp-file showed)
2830 ;; Find and show the html-parts.
2831 (dolist (handle list)
2832 ;; If HTML, show it:
2833 (cond ((not (listp handle)))
2834 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2835 (and (equal (car type) "message/external-body")
2836 (or header
2837 (setq file (mm-handle-filename handle)))
2838 (or (mm-handle-cache handle)
2839 (condition-case code
2840 (progn (mm-extern-cache-contents handle) t)
2841 (error
2842 (gnus-message 3 "%s" (error-message-string code))
2843 (when (>= gnus-verbose 3) (sit-for 2))
2844 nil)))
2845 (progn
2846 (setq handle (mm-handle-cache handle)
2847 type (mm-handle-type handle))
2848 (equal (car type) "text/html"))))
2849 (setq charset (mail-content-type-get type 'charset)
2850 content (mm-get-part handle))
2851 (with-temp-buffer
2852 (if (eq charset 'gnus-decoded)
2853 (mm-enable-multibyte)
2854 (mm-disable-multibyte))
2855 (insert content)
2856 ;; resolve cid contents
2857 (let ((case-fold-search t)
2858 st base regexp cid-file)
2859 (goto-char (point-min))
2860 (when (and (re-search-forward "<head[\t\n >]" nil t)
2861 (progn
2862 (setq st (match-end 0))
2863 (re-search-forward "</head[\t\n >]" nil t))
2864 (re-search-backward "<base\
2865 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2866 (setq base (match-string 1))
2867 (replace-match "<!--\\&-->")
2868 (setq st (point))
2869 (dolist (tag '(("a" . "href") ("form" . "action")
2870 ("img" . "src")))
2871 (setq regexp (concat "<" (car tag)
2872 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2873 (cdr tag) "=\"\\([^\"]+\\)"))
2874 (while (re-search-forward regexp nil t)
2875 (insert (prog1
2876 (condition-case nil
2877 (save-match-data
2878 (url-expand-file-name (match-string 1)
2879 base))
2880 (error (match-string 1)))
2881 (delete-region (match-beginning 1)
2882 (match-end 1)))))
2883 (goto-char st)))
2884 (while (re-search-forward "\
2885 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2886 nil t)
2887 (unless cid-dir
2888 (setq cid-dir (mm-make-temp-file "cid" t))
2889 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2890 (setq file nil
2891 content nil)
2892 (when (setq cid-file
2893 (gnus-article-browse-html-save-cid-content
2894 (match-string 2)
2895 (with-current-buffer gnus-article-buffer
2896 gnus-article-mime-handles)
2897 cid-dir))
2898 (replace-match cid-file nil nil nil 1))))
2899 (unless content (setq content (buffer-string))))
2900 (when (or charset header (not file))
2901 (setq tmp-file (mm-make-temp-file
2902 ;; Do we need to care for 8.3 filenames?
2903 "mm-" nil ".html")))
2904 ;; Add a meta html tag to specify charset and a header.
2905 (cond
2906 (header
2907 (let (title eheader body hcharset coding)
2908 (with-temp-buffer
2909 (mm-enable-multibyte)
2910 (setq case-fold-search t)
2911 (insert header "\n")
2912 (setq title (message-fetch-field "subject"))
2913 (goto-char (point-min))
2914 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2915 nil t)
2916 (replace-match (cond ((match-beginning 1) "&lt;")
2917 ((match-beginning 2) "&gt;")
2918 ((match-beginning 3) "&amp;")
2919 (t "<br>\n"))))
2920 (goto-char (point-min))
2921 (while (re-search-forward "^[\t ]+" nil t)
2922 (dotimes (i (prog1
2923 (current-column)
2924 (delete-region (match-beginning 0)
2925 (match-end 0))))
2926 (insert "&nbsp;")))
2927 (goto-char (point-min))
2928 (insert "<div align=\"left\">\n")
2929 (goto-char (point-max))
2930 (insert "</div>\n<hr>\n")
2931 ;; We have to examine charset one by one since
2932 ;; charset specified in parts might be different.
2933 (if (eq charset 'gnus-decoded)
2934 (setq charset 'utf-8
2935 eheader (mm-encode-coding-string (buffer-string)
2936 charset)
2937 title (when title
2938 (mm-encode-coding-string title charset))
2939 body (mm-encode-coding-string content charset))
2940 (setq hcharset (mm-find-mime-charset-region (point-min)
2941 (point-max)))
2942 (cond ((= (length hcharset) 1)
2943 (setq hcharset (car hcharset)
2944 coding (mm-charset-to-coding-system
2945 hcharset nil t)))
2946 ((> (length hcharset) 1)
2947 (setq hcharset 'utf-8
2948 coding hcharset)))
2949 (if coding
2950 (if charset
2951 (progn
2952 (setq body
2953 (mm-charset-to-coding-system charset
2954 nil t))
2955 (if (eq coding body)
2956 (setq eheader (mm-encode-coding-string
2957 (buffer-string) coding)
2958 title (when title
2959 (mm-encode-coding-string
2960 title coding))
2961 body content)
2962 (setq charset 'utf-8
2963 eheader (mm-encode-coding-string
2964 (buffer-string) charset)
2965 title (when title
2966 (mm-encode-coding-string
2967 title charset))
2968 body (mm-encode-coding-string
2969 (mm-decode-coding-string
2970 content body)
2971 charset))))
2972 (setq charset hcharset
2973 eheader (mm-encode-coding-string
2974 (buffer-string) coding)
2975 title (when title
2976 (mm-encode-coding-string
2977 title coding))
2978 body content))
2979 (setq eheader (mm-string-as-unibyte (buffer-string))
2980 body content)))
2981 (erase-buffer)
2982 (mm-disable-multibyte)
2983 (insert body)
2984 (when charset
2985 (mm-add-meta-html-tag handle charset t))
2986 (when title
2987 (goto-char (point-min))
2988 (unless (search-forward "<title>" nil t)
2989 (re-search-forward "<head>\\s-*" nil t)
2990 (insert "<title>" title "</title>\n")))
2991 (goto-char (point-min))
2992 (or (re-search-forward
2993 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2994 (re-search-forward
2995 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2996 (insert eheader)
2997 (mm-write-region (point-min) (point-max)
2998 tmp-file nil nil nil 'binary t))))
2999 (charset
3000 (mm-with-unibyte-buffer
3001 (insert (if (eq charset 'gnus-decoded)
3002 (mm-encode-coding-string content
3003 (setq charset 'utf-8))
3004 content))
3005 (if (or (mm-add-meta-html-tag handle charset)
3006 (not file))
3007 (mm-write-region (point-min) (point-max)
3008 tmp-file nil nil nil 'binary t)
3009 (setq tmp-file nil))))
3010 (tmp-file
3011 (mm-save-part-to-file handle tmp-file)))
3012 (when tmp-file
3013 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3014 (add-hook 'gnus-summary-prepare-exit-hook
3015 'gnus-article-browse-delete-temp-files)
3016 (add-hook 'gnus-exit-gnus-hook
3017 (lambda ()
3018 (gnus-article-browse-delete-temp-files t)))
3019 ;; FIXME: Warn if there's an <img> tag?
3020 (browse-url-of-file (or tmp-file (expand-file-name file)))
3021 (setq showed t))
3022 ;; If multipart, recurse
3023 ((equal (mm-handle-media-supertype handle) "multipart")
3024 (when (gnus-article-browse-html-parts handle header)
3025 (setq showed t)))
3026 ((equal (mm-handle-media-type handle) "message/rfc822")
3027 (mm-with-multibyte-buffer
3028 (mm-insert-part handle)
3029 (setq handle (mm-dissect-buffer t t))
3030 (when (and (bufferp (car handle))
3031 (stringp (car (mm-handle-type handle))))
3032 (setq handle (list handle)))
3033 (when header
3034 (article-decode-encoded-words)
3035 (let ((gnus-visible-headers
3036 (or (get 'gnus-visible-headers 'standard-value)
3037 gnus-visible-headers)))
3038 (article-hide-headers))
3039 (goto-char (point-min))
3040 (search-forward "\n\n" nil 'move)
3041 (skip-chars-backward "\t\n ")
3042 (setq header (buffer-substring (point-min) (point)))))
3043 (when (prog1
3044 (gnus-article-browse-html-parts handle header)
3045 (mm-destroy-parts handle))
3046 (setq showed t)))))
3047 showed))
3049 (defun gnus-article-browse-html-article (&optional arg)
3050 "View \"text/html\" parts of the current article with a WWW browser.
3051 Inline images embedded in a message using the cid scheme, as they are
3052 generally considered to be safe, will be processed properly.
3053 The message header is added to the beginning of every html part unless
3054 the prefix argument ARG is given.
3056 Warning: Spammers use links to images (using the http scheme) in HTML
3057 articles to verify whether you have read the message. As
3058 `gnus-article-browse-html-article' passes the HTML content to the
3059 browser without eliminating these \"web bugs\" you should only
3060 use it for mails from trusted senders.
3062 If you always want to display HTML parts in the browser, set
3063 `mm-text-html-renderer' to nil.
3065 This command creates temporary files to pass HTML contents including
3066 images if any to the browser, and deletes them when exiting the group
3067 \(if you want)."
3068 ;; Cf. `mm-w3m-safe-url-regexp'
3069 (interactive "P")
3070 (if arg
3071 (gnus-summary-show-article)
3072 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3073 gnus-visible-headers))
3074 ;; As we insert a <hr>, there's no need for the body boundary.
3075 (gnus-treat-body-boundary nil))
3076 (gnus-summary-show-article)))
3077 (with-current-buffer gnus-article-buffer
3078 (let ((header (unless arg
3079 (save-restriction
3080 (widen)
3081 (buffer-substring-no-properties
3082 (goto-char (point-min))
3083 (if (search-forward "\n\n" nil t)
3084 (match-beginning 0)
3085 (goto-char (point-max))
3086 (skip-chars-backward "\t\n ")
3087 (point))))))
3088 parts)
3089 (set-buffer gnus-original-article-buffer)
3090 (setq parts (mm-dissect-buffer t t))
3091 ;; If singlepart, enforce a list.
3092 (when (and (bufferp (car parts))
3093 (stringp (car (mm-handle-type parts))))
3094 (setq parts (list parts)))
3095 ;; Process the list
3096 (unless (gnus-article-browse-html-parts parts header)
3097 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3098 (mm-destroy-parts parts)
3099 (unless arg
3100 (gnus-summary-show-article)))))
3102 (defun article-hide-list-identifiers ()
3103 "Remove list identifiers from the Subject header.
3104 The `gnus-list-identifiers' variable specifies what to do."
3105 (interactive)
3106 (let ((inhibit-point-motion-hooks t)
3107 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3108 (inhibit-read-only t))
3109 (when regexp
3110 (save-excursion
3111 (save-restriction
3112 (article-narrow-to-head)
3113 (goto-char (point-min))
3114 (while (re-search-forward
3115 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3116 nil t)
3117 (delete-region (match-beginning 2) (match-end 0))
3118 (beginning-of-line))
3119 (when (re-search-forward
3120 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3121 (delete-region (match-beginning 1) (match-end 1))))))))
3123 (defun article-hide-pem (&optional arg)
3124 "Toggle hiding of any PEM headers and signatures in the current article.
3125 If given a negative prefix, always show; if given a positive prefix,
3126 always hide."
3127 (interactive (gnus-article-hidden-arg))
3128 (unless (gnus-article-check-hidden-text 'pem arg)
3129 (save-excursion
3130 (let ((inhibit-read-only t) end)
3131 (goto-char (point-min))
3132 ;; Hide the horrendously ugly "header".
3133 (when (and (search-forward
3134 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3135 nil t)
3136 (setq end (1+ (match-beginning 0))))
3137 (gnus-add-wash-type 'pem)
3138 (gnus-article-hide-text-type
3140 (if (search-forward "\n\n" nil t)
3141 (match-end 0)
3142 (point-max))
3143 'pem)
3144 ;; Hide the trailer as well
3145 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3146 nil t)
3147 (gnus-article-hide-text-type
3148 (match-beginning 0) (match-end 0) 'pem)))))))
3150 (defun article-strip-banner ()
3151 "Strip the banners specified by the `banner' group parameter and by
3152 `gnus-article-address-banner-alist'."
3153 (interactive)
3154 (save-excursion
3155 (save-restriction
3156 (let ((inhibit-point-motion-hooks t))
3157 (when (gnus-parameter-banner gnus-newsgroup-name)
3158 (article-really-strip-banner
3159 (gnus-parameter-banner gnus-newsgroup-name)))
3160 (when gnus-article-address-banner-alist
3161 ;; Note that the From header is decoded here, so it is
3162 ;; required that the *-extract-address-components function
3163 ;; supports non-ASCII text.
3164 (let ((from (save-restriction
3165 (widen)
3166 (article-narrow-to-head)
3167 (mail-fetch-field "from"))))
3168 (when (and from
3169 (setq from
3170 (cadr (funcall gnus-extract-address-components
3171 from))))
3172 (catch 'found
3173 (dolist (pair gnus-article-address-banner-alist)
3174 (when (string-match (car pair) from)
3175 (throw 'found
3176 (article-really-strip-banner (cdr pair)))))))))))))
3178 (defun article-really-strip-banner (banner)
3179 "Strip the banner specified by the argument."
3180 (save-excursion
3181 (save-restriction
3182 (let ((inhibit-point-motion-hooks t)
3183 (gnus-signature-limit nil)
3184 (inhibit-read-only t))
3185 (article-goto-body)
3186 (cond
3187 ((eq banner 'signature)
3188 (when (gnus-article-narrow-to-signature)
3189 (widen)
3190 (forward-line -1)
3191 (delete-region (point) (point-max))))
3192 ((symbolp banner)
3193 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3194 (while (re-search-forward banner nil t)
3195 (delete-region (match-beginning 0) (match-end 0)))))
3196 ((stringp banner)
3197 (while (re-search-forward banner nil t)
3198 (delete-region (match-beginning 0) (match-end 0)))))))))
3200 (defun article-babel ()
3201 "Translate article using an online translation service."
3202 (interactive)
3203 (require 'babel)
3204 (gnus-with-article-buffer
3205 (when (article-goto-body)
3206 (let* ((start (point))
3207 (end (point-max))
3208 (orig (buffer-substring start end))
3209 (trans (babel-as-string orig)))
3210 (save-restriction
3211 (narrow-to-region start end)
3212 (delete-region start end)
3213 (insert trans))))))
3215 (defun article-hide-signature (&optional arg)
3216 "Hide the signature in the current article.
3217 If given a negative prefix, always show; if given a positive prefix,
3218 always hide."
3219 (interactive (gnus-article-hidden-arg))
3220 (unless (gnus-article-check-hidden-text 'signature arg)
3221 (save-excursion
3222 (save-restriction
3223 (let ((inhibit-read-only t))
3224 (when (gnus-article-narrow-to-signature)
3225 (gnus-article-hide-text-type
3226 (point-min) (point-max) 'signature))))))
3227 (gnus-set-mode-line 'article))
3229 (defun article-strip-headers-in-body ()
3230 "Strip offensive headers from bodies."
3231 (interactive)
3232 (save-excursion
3233 (article-goto-body)
3234 (let ((case-fold-search t))
3235 (when (looking-at "x-no-archive:")
3236 (gnus-delete-line)))))
3238 (defun article-strip-leading-blank-lines ()
3239 "Remove all blank lines from the beginning of the article."
3240 (interactive)
3241 (save-excursion
3242 (let ((inhibit-point-motion-hooks t)
3243 (inhibit-read-only t))
3244 (when (article-goto-body)
3245 (while (and (not (eobp))
3246 (looking-at "[ \t]*$"))
3247 (gnus-delete-line))))))
3249 (defun article-narrow-to-head ()
3250 "Narrow the buffer to the head of the message.
3251 Point is left at the beginning of the narrowed-to region."
3252 (narrow-to-region
3253 (goto-char (point-min))
3254 (cond
3255 ;; Absolutely no headers displayed.
3256 ((looking-at "\n")
3257 (point))
3258 ;; Normal headers.
3259 ((search-forward "\n\n" nil 1)
3260 (1- (point)))
3261 ;; Nothing but headers.
3263 (point-max))))
3264 (goto-char (point-min)))
3266 (defun article-goto-body ()
3267 "Place point at the start of the body."
3268 (goto-char (point-min))
3269 (cond
3270 ;; This variable is only bound when dealing with separate
3271 ;; MIME body parts.
3272 (article-goto-body-goes-to-point-min-p
3274 ((search-forward "\n\n" nil t)
3277 (goto-char (point-max))
3278 nil)))
3280 (defun article-strip-multiple-blank-lines ()
3281 "Replace consecutive blank lines with one empty line."
3282 (interactive)
3283 (save-excursion
3284 (let ((inhibit-point-motion-hooks t)
3285 (inhibit-read-only t))
3286 ;; First make all blank lines empty.
3287 (article-goto-body)
3288 (while (re-search-forward "^[ \t]+$" nil t)
3289 (unless (gnus-annotation-in-region-p
3290 (match-beginning 0) (match-end 0))
3291 (replace-match "" nil t)))
3292 ;; Then replace multiple empty lines with a single empty line.
3293 (article-goto-body)
3294 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3295 (unless (gnus-annotation-in-region-p
3296 (match-beginning 0) (match-end 0))
3297 (delete-region (match-beginning 1) (match-end 1)))))))
3299 (defun article-strip-leading-space ()
3300 "Remove all white space from the beginning of the lines in the article."
3301 (interactive)
3302 (save-excursion
3303 (let ((inhibit-point-motion-hooks t)
3304 (inhibit-read-only t))
3305 (article-goto-body)
3306 (while (re-search-forward "^[ \t]+" nil t)
3307 (replace-match "" t t)))))
3309 (defun article-strip-trailing-space ()
3310 "Remove all white space from the end of the lines in the article."
3311 (interactive)
3312 (save-excursion
3313 (let ((inhibit-point-motion-hooks t)
3314 (inhibit-read-only t))
3315 (article-goto-body)
3316 (while (re-search-forward "[ \t]+$" nil t)
3317 (replace-match "" t t)))))
3319 (defun article-strip-blank-lines ()
3320 "Strip leading, trailing and multiple blank lines."
3321 (interactive)
3322 (article-strip-leading-blank-lines)
3323 (article-remove-trailing-blank-lines)
3324 (article-strip-multiple-blank-lines))
3326 (defun article-strip-all-blank-lines ()
3327 "Strip all blank lines."
3328 (interactive)
3329 (save-excursion
3330 (let ((inhibit-point-motion-hooks t)
3331 (inhibit-read-only t))
3332 (article-goto-body)
3333 (while (re-search-forward "^[ \t]*\n" nil t)
3334 (replace-match "" t t)))))
3336 (defun gnus-article-narrow-to-signature ()
3337 "Narrow to the signature; return t if a signature is found, else nil."
3338 (let ((inhibit-point-motion-hooks t))
3339 (when (gnus-article-search-signature)
3340 (forward-line 1)
3341 ;; Check whether we have some limits to what we consider
3342 ;; to be a signature.
3343 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3344 (list gnus-signature-limit)))
3345 limit limited)
3346 (while (setq limit (pop limits))
3347 (if (or (and (integerp limit)
3348 (< (- (point-max) (point)) limit))
3349 (and (floatp limit)
3350 (< (count-lines (point) (point-max)) limit))
3351 (and (functionp limit)
3352 (funcall limit))
3353 (and (stringp limit)
3354 (not (re-search-forward limit nil t))))
3355 () ; This limit did not succeed.
3356 (setq limited t
3357 limits nil)))
3358 (unless limited
3359 (narrow-to-region (point) (point-max))
3360 t)))))
3362 (defun gnus-article-search-signature ()
3363 "Search the current buffer for the signature separator.
3364 Put point at the beginning of the signature separator."
3365 (let ((cur (point)))
3366 (goto-char (point-max))
3367 (if (if (stringp gnus-signature-separator)
3368 (re-search-backward gnus-signature-separator nil t)
3369 (let ((seps gnus-signature-separator))
3370 (while (and seps
3371 (not (re-search-backward (car seps) nil t)))
3372 (pop seps))
3373 seps))
3375 (goto-char cur)
3376 nil)))
3378 (defun gnus-article-hidden-arg ()
3379 "Return the current prefix arg as a number, or 0 if no prefix."
3380 (list (if current-prefix-arg
3381 (prefix-numeric-value current-prefix-arg)
3382 0)))
3384 (defun gnus-article-check-hidden-text (type arg)
3385 "Return nil if hiding is necessary.
3386 Arg can be nil or a number. nil and positive means hide, negative
3387 means show, 0 means toggle."
3388 (save-excursion
3389 (save-restriction
3390 (let ((hide (gnus-article-hidden-text-p type)))
3391 (cond
3392 ((or (null arg)
3393 (> arg 0))
3394 nil)
3395 ((< arg 0)
3396 (gnus-article-show-hidden-text type)
3399 (if (eq hide 'hidden)
3400 (progn
3401 (gnus-article-show-hidden-text type)
3403 nil)))))))
3405 (defun gnus-article-hidden-text-p (type)
3406 "Say whether the current buffer contains hidden text of type TYPE."
3407 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3408 (while (and pos
3409 (not (get-text-property pos 'invisible))
3410 (not (get-text-property pos 'dummy-invisible)))
3411 (setq pos
3412 (text-property-any (1+ pos) (point-max) 'article-type type)))
3413 (if pos
3414 'hidden
3415 nil)))
3417 (defun gnus-article-show-hidden-text (type &optional _dummy)
3418 "Show all hidden text of type TYPE.
3419 Originally it is hide instead of DUMMY."
3420 (let ((inhibit-read-only t)
3421 (inhibit-point-motion-hooks t))
3422 (gnus-remove-text-properties-when
3423 'article-type type
3424 (point-min) (point-max)
3425 (cons 'article-type (cons type
3426 gnus-hidden-properties)))
3427 (gnus-delete-wash-type type)))
3429 (defconst article-time-units
3430 `((year . ,(* 365.25 24 60 60))
3431 (week . ,(* 7 24 60 60))
3432 (day . ,(* 24 60 60))
3433 (hour . ,(* 60 60))
3434 (minute . 60)
3435 (second . 1))
3436 "Mapping from time units to seconds.")
3438 (defun gnus-article-forward-header ()
3439 "Move point to the start of the next header.
3440 If the current header is a continuation header, this can be several
3441 lines forward."
3442 (let ((ended nil))
3443 (while (not ended)
3444 (forward-line 1)
3445 (if (looking-at "[ \t]+[^ \t]")
3446 (forward-line 1)
3447 (setq ended t)))))
3449 (defun article-treat-date ()
3450 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3451 (with-current-buffer gnus-summary-buffer
3452 gnus-article-date-headers)
3453 gnus-article-date-headers)
3456 (defun article-date-ut (&optional type _highlight date-position)
3457 "Convert DATE date to TYPE in the current article.
3458 The default type is `ut'. See `gnus-article-date-headers' for
3459 possible values."
3460 (interactive (list 'ut t))
3461 (let* ((case-fold-search t)
3462 (inhibit-read-only t)
3463 (inhibit-point-motion-hooks t)
3464 (visible-date (mail-fetch-field "Date"))
3465 pos date bface eface)
3466 (save-excursion
3467 (if date-position
3468 (progn
3469 (goto-char date-position)
3470 (setq date (get-text-property (point) 'original-date))
3471 (when (looking-at "[^:]+:[\t ]*")
3472 (setq bface (get-text-property (match-beginning 0) 'face)
3473 eface (get-text-property (match-end 0) 'face)))
3474 (delete-region (point)
3475 (progn
3476 (gnus-article-forward-header)
3477 (point)))
3478 (article-transform-date date type bface eface))
3479 (save-restriction
3480 (widen)
3481 (goto-char (point-min))
3482 (while (or (get-text-property (setq pos (point)) 'original-date)
3483 (and (setq pos (next-single-property-change
3484 (point) 'original-date))
3485 (goto-char pos)))
3486 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3487 (1+ (match-beginning 0))
3488 (point-max)))
3489 (while (setq pos (text-property-not-all pos (point-max)
3490 'gnus-date-type nil))
3491 (setq date (get-text-property pos 'original-date))
3492 (goto-char pos)
3493 (when (looking-at "[^:]+:[\t ]*")
3494 (setq bface (get-text-property (match-beginning 0) 'face)
3495 eface (get-text-property (match-end 0) 'face)))
3496 (delete-region pos (or (text-property-any pos (point-max)
3497 'gnus-date-type nil)
3498 (point-max))))
3499 (unless date ;; the 1st time
3500 (goto-char (point-min))
3501 (while (re-search-forward "^Date:[\t ]*" nil t)
3502 (setq date (get-text-property (match-beginning 0)
3503 'original-date)
3504 bface (get-text-property (match-beginning 0) 'face)
3505 eface (get-text-property (match-end 0) 'face))
3506 (delete-region (point-at-bol) (progn
3507 (gnus-article-forward-header)
3508 (point)))))
3509 (when (and (not date)
3510 visible-date)
3511 (setq date visible-date))
3512 (when date
3513 (article-transform-date date type bface eface))
3514 (goto-char (point-max))
3515 (widen)))))))
3517 (defun article-transform-date (date type bface eface)
3518 (dolist (this-type (cond
3519 ((null type)
3520 (list 'ut))
3521 ((atom type)
3522 (list type))
3524 type)))
3525 (goto-char
3526 (prog1
3527 (point)
3528 (add-text-properties
3529 (point)
3530 (progn
3531 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3532 (point))
3533 (list 'original-date date 'gnus-date-type this-type))))
3534 ;; Do highlighting.
3535 (when (looking-at
3536 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3537 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3538 (when (match-beginning 2)
3539 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3540 (while (and (zerop (forward-line 1))
3541 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3542 (when (match-beginning 1)
3543 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3545 (defun article-make-date-line (date type)
3546 "Return a DATE line of TYPE."
3547 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3548 combined-lapsed))
3549 (error "Unknown conversion type: %s" type))
3550 (condition-case ()
3551 (let ((time (ignore-errors (date-to-time date))))
3552 (cond
3553 ;; Convert to the local timezone.
3554 ((eq type 'local)
3555 (concat "Date: " (message-make-date time)))
3556 ;; Convert to Universal Time.
3557 ((eq type 'ut)
3558 (concat "Date: "
3559 (substring
3560 (message-make-date
3561 (let* ((e (parse-time-string date))
3562 (tm (apply 'encode-time e))
3563 (ms (car tm))
3564 (ls (- (cadr tm) (car (current-time-zone time)))))
3565 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3566 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3567 (t (list ms ls)))))
3568 0 -5)
3569 "UT"))
3570 ;; Get the original date from the article.
3571 ((eq type 'original)
3572 (concat "Date: " (if (string-match "\n+$" date)
3573 (substring date 0 (match-beginning 0))
3574 date)))
3575 ;; Let the user define the format.
3576 ((eq type 'user-defined)
3577 (let ((format (or (condition-case nil
3578 (with-current-buffer gnus-summary-buffer
3579 gnus-article-time-format)
3580 (error nil))
3581 gnus-article-time-format)))
3582 (if (functionp format)
3583 (funcall format time)
3584 (concat "Date: " (format-time-string format time)))))
3585 ;; ISO 8601.
3586 ((eq type 'iso8601)
3587 (let ((tz (car (current-time-zone time))))
3588 (concat
3589 "Date: "
3590 (format-time-string "%Y%m%dT%H%M%S" time)
3591 (format "%s%02d%02d"
3592 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3593 (/ (% (abs tz) 3600) 60)))))
3594 ;; Do a lapsed format.
3595 ((eq type 'lapsed)
3596 (concat "Date: " (article-lapsed-string time)))
3597 ;; A combined date/lapsed format.
3598 ((eq type 'combined-lapsed)
3599 (let ((date-string (article-make-date-line date 'original))
3600 (segments 3)
3601 lapsed-string)
3602 (while (and
3603 time
3604 (setq lapsed-string
3605 (concat " (" (article-lapsed-string time segments) ")"))
3606 (> (+ (length date-string)
3607 (length lapsed-string))
3608 (+ fill-column 6))
3609 (> segments 0))
3610 (setq segments (1- segments)))
3611 (if (> segments 0)
3612 (concat date-string lapsed-string)
3613 date-string)))
3614 ;; Display the date in proper English
3615 ((eq type 'english)
3616 (let ((dtime (decode-time time)))
3617 (concat
3618 "Date: the "
3619 (number-to-string (nth 3 dtime))
3620 (let ((digit (% (nth 3 dtime) 10)))
3621 (cond
3622 ((memq (nth 3 dtime) '(11 12 13)) "th")
3623 ((= digit 1) "st")
3624 ((= digit 2) "nd")
3625 ((= digit 3) "rd")
3626 (t "th")))
3627 " of "
3628 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3630 (number-to-string (nth 5 dtime))
3631 " at "
3632 (format "%02d" (nth 2 dtime))
3634 (format "%02d" (nth 1 dtime)))))))
3635 (foo
3636 (format "Date: %s (from Gnus)" date))))
3638 (defun article-lapsed-string (time &optional max-segments)
3639 ;; If the date is seriously mangled, the timezone functions are
3640 ;; liable to bug out, so we ignore all errors.
3641 (let* ((now (current-time))
3642 (real-time (subtract-time now time))
3643 (real-sec (and real-time
3644 (+ (* (float (car real-time)) 65536)
3645 (cadr real-time))))
3646 (sec (and real-time (abs real-sec)))
3647 (segments 0)
3648 num prev)
3649 (unless max-segments
3650 (setq max-segments (length article-time-units)))
3651 (cond
3652 ((null real-time)
3653 "Unknown")
3654 ((zerop sec)
3655 "Now")
3657 (concat
3658 ;; This is a bit convoluted, but basically we go
3659 ;; through the time units for years, weeks, etc,
3660 ;; and divide things to see whether that results
3661 ;; in positive answers.
3662 (mapconcat
3663 (lambda (unit)
3664 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3665 (>= segments max-segments))
3666 ;; The (remaining) seconds are too few to
3667 ;; be divided into this time unit.
3669 ;; It's big enough, so we output it.
3670 (setq sec (- sec (* num (cdr unit))))
3671 (prog1
3672 (concat (if prev ", " "") (int-to-string
3673 (floor num))
3674 " " (symbol-name (car unit))
3675 (if (> num 1) "s" ""))
3676 (setq prev t
3677 segments (1+ segments)))))
3678 article-time-units "")
3679 ;; If dates are odd, then it might appear like the
3680 ;; article was sent in the future.
3681 (if (> real-sec 0)
3682 " ago"
3683 " in the future"))))))
3685 (defun article-date-local (&optional highlight)
3686 "Convert the current article date to the local timezone."
3687 (interactive (list t))
3688 (article-date-ut 'local highlight))
3690 (defun article-date-english (&optional highlight)
3691 "Convert the current article date to something that is proper English."
3692 (interactive (list t))
3693 (article-date-ut 'english highlight))
3695 (defun article-date-original (&optional highlight)
3696 "Convert the current article date to what it was originally.
3697 This is only useful if you have used some other date conversion
3698 function and want to see what the date was before converting."
3699 (interactive (list t))
3700 (article-date-ut 'original highlight))
3702 (defun article-date-lapsed (&optional highlight)
3703 "Convert the current article date to time lapsed since it was sent."
3704 (interactive (list t))
3705 (article-date-ut 'lapsed highlight))
3707 (defun article-date-combined-lapsed (&optional highlight)
3708 "Convert the current article date to time lapsed since it was sent."
3709 (interactive (list t))
3710 (article-date-ut 'combined-lapsed highlight))
3712 (defun article-update-date-lapsed ()
3713 "Function to be run from a timer to update the lapsed time line."
3714 (save-match-data
3715 (let ((buffer (current-buffer)))
3716 (ignore-errors
3717 (walk-windows
3718 (lambda (w)
3719 (set-buffer (window-buffer w))
3720 (when (derived-mode-p 'gnus-article-mode)
3721 (let ((old-line (count-lines (point-min) (point)))
3722 (old-column (- (point) (line-beginning-position)))
3723 (window-start (window-start w))
3724 (pos (point-min))
3725 type next end)
3726 (while (setq pos (text-property-not-all pos (point-max)
3727 'gnus-date-type nil))
3728 (setq next (or (next-single-property-change pos
3729 'gnus-date-type)
3730 (point-max)))
3731 (setq type (get-text-property pos 'gnus-date-type))
3732 (when (memq type '(lapsed combined-lapsed user-defined))
3733 (article-date-ut type t pos)
3734 (setq end (or (next-single-property-change pos
3735 'gnus-date-type)
3736 (point-max)))
3737 (when window-start
3738 (if (/= window-start next)
3739 (setq window-start nil)
3740 (set-window-start w end)))
3741 (setq next end))
3742 (setq pos next))
3743 (goto-char (point-min))
3744 (when (> old-column 0)
3745 (setq old-line (1- old-line)))
3746 (forward-line old-line)
3747 (end-of-line)
3748 (when (> (current-column) old-column)
3749 (beginning-of-line)
3750 (forward-char old-column)))))
3751 nil 'visible))
3752 (set-buffer buffer))))
3754 (defun gnus-start-date-timer (&optional n)
3755 "Start a timer to update the Date headers in the article buffers.
3756 The numerical prefix says how frequently (in seconds) the function
3757 is to run."
3758 (interactive "p")
3759 (unless n
3760 (setq n 1))
3761 (gnus-stop-date-timer)
3762 (setq article-lapsed-timer
3763 (run-at-time 1 n 'article-update-date-lapsed)))
3765 (defun gnus-stop-date-timer ()
3766 "Stop the Date timer."
3767 (interactive)
3768 (when article-lapsed-timer
3769 (nnheader-cancel-timer article-lapsed-timer)
3770 (setq article-lapsed-timer nil)))
3772 (defun article-date-user (&optional highlight)
3773 "Convert the current article date to the user-defined format.
3774 This format is defined by the `gnus-article-time-format' variable."
3775 (interactive (list t))
3776 (article-date-ut 'user highlight))
3778 (defun article-date-iso8601 (&optional highlight)
3779 "Convert the current article date to ISO8601."
3780 (interactive (list t))
3781 (article-date-ut 'iso8601 highlight))
3783 (defmacro gnus-article-save-original-date (&rest forms)
3784 "Save the original date as a text property and evaluate FORMS."
3785 `(let* ((case-fold-search t)
3786 (start (progn
3787 (goto-char (point-min))
3788 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3789 (not (bolp)))
3790 (match-end 0))))
3791 (date (when (and start
3792 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3793 nil t))
3794 (buffer-substring-no-properties start
3795 (match-beginning 0)))))
3796 (goto-char (point-max))
3797 (skip-chars-backward "\n")
3798 (put-text-property (point-min) (point) 'original-date date)
3799 ,@forms
3800 (goto-char (point-max))
3801 (skip-chars-backward "\n")
3802 (put-text-property (point-min) (point) 'original-date date)))
3804 ;; (defun article-show-all ()
3805 ;; "Show all hidden text in the article buffer."
3806 ;; (interactive)
3807 ;; (save-excursion
3808 ;; (let ((inhibit-read-only t))
3809 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3811 (defun article-remove-leading-whitespace ()
3812 "Remove excessive whitespace from all headers."
3813 (interactive)
3814 (save-excursion
3815 (save-restriction
3816 (let ((inhibit-read-only t))
3817 (article-narrow-to-head)
3818 (goto-char (point-min))
3819 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3820 (delete-region (match-beginning 1) (match-end 1)))))))
3822 (defun article-emphasize (&optional arg)
3823 "Emphasize text according to `gnus-emphasis-alist'."
3824 (interactive (gnus-article-hidden-arg))
3825 (unless (gnus-article-check-hidden-text 'emphasis arg)
3826 (save-excursion
3827 (let ((alist (or
3828 (condition-case nil
3829 (with-current-buffer gnus-summary-buffer
3830 gnus-article-emphasis-alist)
3831 (error))
3832 gnus-emphasis-alist))
3833 (inhibit-read-only t)
3834 (props (append '(article-type emphasis)
3835 gnus-hidden-properties))
3836 regexp elem beg invisible visible face)
3837 (article-goto-body)
3838 (setq beg (point))
3839 (while (setq elem (pop alist))
3840 (goto-char beg)
3841 (setq regexp (car elem)
3842 invisible (nth 1 elem)
3843 visible (nth 2 elem)
3844 face (nth 3 elem))
3845 (while (re-search-forward regexp nil t)
3846 (when (and (match-beginning visible) (match-beginning invisible))
3847 (gnus-article-hide-text
3848 (match-beginning invisible) (match-end invisible) props)
3849 (gnus-article-unhide-text-type
3850 (match-beginning visible) (match-end visible) 'emphasis)
3851 (gnus-put-overlay-excluding-newlines
3852 (match-beginning visible) (match-end visible) 'face face)
3853 (gnus-add-wash-type 'emphasis)
3854 (goto-char (match-end invisible)))))))))
3856 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3857 "Setup newsgroup emphasis alist."
3858 (unless gnus-article-emphasis-alist
3859 (let ((name (and gnus-newsgroup-name
3860 (gnus-group-real-name gnus-newsgroup-name))))
3861 (make-local-variable 'gnus-article-emphasis-alist)
3862 (setq gnus-article-emphasis-alist
3863 (nconc
3864 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3865 (while (setq elem (pop alist))
3866 (when (and name (string-match (car elem) name))
3867 (setq alist nil
3868 highlight (copy-sequence (cdr elem)))))
3869 highlight)
3870 (copy-sequence highlight-words)
3871 (if gnus-newsgroup-name
3872 (copy-sequence (gnus-group-find-parameter
3873 gnus-newsgroup-name 'highlight-words t)))
3874 gnus-emphasis-alist)))))
3876 (defvar gnus-summary-article-menu)
3877 (defvar gnus-summary-post-menu)
3879 ;;; Saving functions.
3881 (defun gnus-article-save (save-buffer file &optional num)
3882 "Save the currently selected article."
3883 (when (or (get gnus-default-article-saver :headers)
3884 (not gnus-save-all-headers))
3885 ;; Remove headers according to `gnus-saved-headers' or the value
3886 ;; of the `:headers' property that the saver function might have.
3887 (let ((gnus-visible-headers
3888 (or (symbol-value (get gnus-default-article-saver :headers))
3889 gnus-saved-headers gnus-visible-headers))
3890 ;; Ignore group parameter. See `article-hide-headers'.
3891 (gnus-summary-buffer nil))
3892 (with-current-buffer save-buffer
3893 (article-hide-headers 1 t))))
3894 (save-window-excursion
3895 (if (not gnus-default-article-saver)
3896 (error "No default saver is defined")
3897 ;; !!! Magic! The saving functions all save
3898 ;; `gnus-save-article-buffer' (or so they think), but we
3899 ;; bind that variable to our save-buffer.
3900 (set-buffer gnus-article-buffer)
3901 (let* ((gnus-save-article-buffer save-buffer)
3902 (filename
3903 (cond
3904 ((not gnus-prompt-before-saving) 'default)
3905 ((eq gnus-prompt-before-saving 'always) nil)
3906 (t file)))
3907 (gnus-number-of-articles-to-be-saved
3908 (when (eq gnus-prompt-before-saving t)
3909 num))) ; Magic
3910 (set-buffer gnus-article-current-summary)
3911 (funcall gnus-default-article-saver filename)))))
3913 (defun gnus-read-save-file-name (prompt &optional filename
3914 function group headers variable
3915 dir-var)
3916 (let ((default-name
3917 (funcall function group headers (symbol-value variable)))
3918 result)
3919 (setq result
3920 (expand-file-name
3921 (cond
3922 ((eq filename 'default)
3923 default-name)
3924 ((eq filename t)
3925 default-name)
3926 (filename filename)
3928 (when (symbol-value dir-var)
3929 (setq default-name (expand-file-name
3930 (file-name-nondirectory default-name)
3931 (symbol-value dir-var))))
3932 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3933 (prompt
3934 (format prompt
3935 (if (and gnus-number-of-articles-to-be-saved
3936 (> gnus-number-of-articles-to-be-saved 1))
3937 (format "these %d articles"
3938 gnus-number-of-articles-to-be-saved)
3939 "this article")))
3940 (file
3941 ;; Let the split methods have their say.
3942 (cond
3943 ;; No split name was found.
3944 ((null split-name)
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 group name is returned.
3951 ((stringp split-name)
3952 (setq default-name
3953 (funcall function split-name headers
3954 (symbol-value variable)))
3955 (read-file-name
3956 (concat prompt " (default "
3957 (file-name-nondirectory default-name) "): ")
3958 (file-name-directory default-name)
3959 default-name))
3960 ;; A single split name was found
3961 ((= 1 (length split-name))
3962 (let* ((name (expand-file-name
3963 (car split-name)
3964 gnus-article-save-directory))
3965 (dir (cond ((file-directory-p name)
3966 (file-name-as-directory name))
3967 ((file-exists-p name) name)
3968 (t gnus-article-save-directory))))
3969 (read-file-name
3970 (concat prompt " (default " name "): ")
3971 dir name)))
3972 ;; A list of splits was found.
3974 (setq split-name (nreverse split-name))
3975 (let (result)
3976 (let ((file-name-history
3977 (nconc split-name file-name-history)))
3978 (setq result
3979 (expand-file-name
3980 (read-file-name
3981 (concat prompt " (`M-p' for defaults): ")
3982 gnus-article-save-directory
3983 (car split-name))
3984 gnus-article-save-directory)))
3985 (car (push result file-name-history)))))))
3986 ;; Create the directory.
3987 (gnus-make-directory (file-name-directory file))
3988 ;; If we have read a directory, we append the default file name.
3989 (when (file-directory-p file)
3990 (setq file (expand-file-name (file-name-nondirectory
3991 default-name)
3992 (file-name-as-directory file))))
3993 ;; Possibly translate some characters.
3994 (nnheader-translate-file-chars file))))))
3995 (gnus-make-directory (file-name-directory result))
3996 (when variable
3997 (set variable result))
3998 (when dir-var
3999 (set dir-var (file-name-directory result)))
4000 result))
4002 (defun gnus-article-archive-name (_group)
4003 "Return the first instance of an \"Archive-name\" in the current buffer."
4004 (let ((case-fold-search t))
4005 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
4006 (nnheader-concat gnus-article-save-directory
4007 (match-string 1)))))
4009 (defun gnus-article-nndoc-name (group)
4010 "If GROUP is an nndoc group, return the name of the parent group."
4011 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4012 (gnus-group-get-parameter group 'save-article-group)))
4014 (defun gnus-summary-save-in-rmail (&optional filename)
4015 "Append this article to Rmail file.
4016 Optional argument FILENAME specifies file name.
4017 Directory to save to is default to `gnus-article-save-directory'."
4018 (setq filename (gnus-read-save-file-name
4019 "Save %s in rmail file" filename
4020 gnus-rmail-save-name gnus-newsgroup-name
4021 gnus-current-headers 'gnus-newsgroup-last-rmail))
4022 (with-current-buffer gnus-save-article-buffer
4023 (save-excursion
4024 (save-restriction
4025 (widen)
4026 ;; Note that unlike gnus-summary-save-in-mail, there is no
4027 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4028 ;; not use Babyl.
4029 (gnus-output-to-rmail filename))))
4030 filename)
4032 (defun gnus-summary-save-in-mail (&optional filename)
4033 "Append this article to Unix mail file.
4034 Optional argument FILENAME specifies file name.
4035 Directory to save to is default to `gnus-article-save-directory'."
4036 (setq filename (gnus-read-save-file-name
4037 "Save %s in Unix mail file" filename
4038 gnus-mail-save-name gnus-newsgroup-name
4039 gnus-current-headers 'gnus-newsgroup-last-mail))
4040 (with-current-buffer gnus-save-article-buffer
4041 (save-excursion
4042 (save-restriction
4043 (widen)
4044 (if (and (file-readable-p filename)
4045 (file-regular-p filename)
4046 (mail-file-babyl-p filename))
4047 (gnus-output-to-rmail filename)
4048 (gnus-output-to-mail filename)))))
4049 filename)
4051 (put 'gnus-summary-save-in-file :decode t)
4052 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4053 (defun gnus-summary-save-in-file (&optional filename overwrite)
4054 "Append this article to file.
4055 Optional argument FILENAME specifies file name.
4056 Directory to save to is default to `gnus-article-save-directory'."
4057 (setq filename (gnus-read-save-file-name
4058 "Save %s in file" filename
4059 gnus-file-save-name gnus-newsgroup-name
4060 gnus-current-headers 'gnus-newsgroup-last-file))
4061 (with-current-buffer gnus-save-article-buffer
4062 (save-excursion
4063 (save-restriction
4064 (widen)
4065 (when (and overwrite
4066 (file-exists-p filename))
4067 (delete-file filename))
4068 (gnus-output-to-file filename))))
4069 filename)
4071 (put 'gnus-summary-write-to-file :decode t)
4072 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4073 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4074 (defun gnus-summary-write-to-file (&optional filename)
4075 "Write this article to a file, overwriting it if the file exists.
4076 Optional argument FILENAME specifies file name.
4077 The directory to save in defaults to `gnus-article-save-directory'."
4078 (setq filename (gnus-read-save-file-name
4079 "Save %s in file" filename
4080 gnus-file-save-name gnus-newsgroup-name
4081 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4082 (gnus-summary-save-in-file filename t))
4084 (put 'gnus-summary-save-body-in-file :decode t)
4085 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4086 "Append this article body to a file.
4087 Optional argument FILENAME specifies file name.
4088 The directory to save in defaults to `gnus-article-save-directory'."
4089 (setq filename (gnus-read-save-file-name
4090 "Save %s body in file" filename
4091 gnus-file-save-name gnus-newsgroup-name
4092 gnus-current-headers 'gnus-newsgroup-last-file))
4093 (with-current-buffer gnus-save-article-buffer
4094 (save-excursion
4095 (save-restriction
4096 (widen)
4097 (when (article-goto-body)
4098 (narrow-to-region (point) (point-max)))
4099 (when (and overwrite
4100 (file-exists-p filename))
4101 (delete-file filename))
4102 (gnus-output-to-file filename))))
4103 filename)
4105 (put 'gnus-summary-write-body-to-file :decode t)
4106 (put 'gnus-summary-write-body-to-file
4107 :function 'gnus-summary-save-body-in-file)
4108 (defun gnus-summary-write-body-to-file (&optional filename)
4109 "Write this article body to a file, overwriting it if the file exists.
4110 Optional argument FILENAME specifies file name.
4111 The directory to save in defaults to `gnus-article-save-directory'."
4112 (setq filename (gnus-read-save-file-name
4113 "Save %s body in file" filename
4114 gnus-file-save-name gnus-newsgroup-name
4115 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4116 (gnus-summary-save-body-in-file filename t))
4118 (put 'gnus-summary-save-in-pipe :decode t)
4119 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4120 (defun gnus-summary-save-in-pipe (&optional command raw)
4121 "Pipe this article to subprocess COMMAND.
4122 Valid values for COMMAND include:
4123 a string
4124 The executable command name and possibly arguments.
4126 You will be prompted for the command in the minibuffer.
4127 the symbol `default'
4128 It will be replaced with the command which the variable
4129 `gnus-summary-pipe-output-default-command' holds or the command
4130 last used for saving.
4131 Non-nil value for RAW overrides `:decode' and `:headers' properties
4132 and the raw article including all headers will be piped."
4133 (let ((article (gnus-summary-article-number))
4134 (decode (unless raw
4135 (get 'gnus-summary-save-in-pipe :decode)))
4136 save-buffer default)
4137 (if article
4138 (if (vectorp (gnus-summary-article-header article))
4139 (save-current-buffer
4140 (gnus-summary-select-article decode decode nil article)
4141 (insert-buffer-substring
4142 (prog1
4143 (if decode
4144 gnus-article-buffer
4145 gnus-original-article-buffer)
4146 (setq save-buffer
4147 (nnheader-set-temp-buffer " *Gnus Save*"))))
4148 ;; Remove unwanted headers.
4149 (when (and (not raw)
4150 (or (get 'gnus-summary-save-in-pipe :headers)
4151 (not gnus-save-all-headers)))
4152 (let ((gnus-visible-headers
4153 (or (symbol-value (get 'gnus-summary-save-in-pipe
4154 :headers))
4155 gnus-saved-headers gnus-visible-headers))
4156 (gnus-summary-buffer nil))
4157 (article-hide-headers 1 t))))
4158 (error "%d is not a real article" article))
4159 (error "No article to pipe"))
4160 (setq default (or gnus-summary-pipe-output-default-command
4161 gnus-last-shell-command))
4162 (unless (stringp command)
4163 (setq command
4164 (if (and (eq command 'default) default)
4165 default
4166 (gnus-read-shell-command "Shell command on this article: "
4167 default))))
4168 (when (string-equal command "")
4169 (if default
4170 (setq command default)
4171 (error "A command is required")))
4172 (with-current-buffer save-buffer
4173 (save-restriction
4174 (widen)
4175 (shell-command-on-region (point-min) (point-max) command nil)))
4176 (gnus-kill-buffer save-buffer))
4177 (setq gnus-summary-pipe-output-default-command command))
4179 (defun gnus-summary-pipe-to-muttprint (&optional command)
4180 "Pipe this article to muttprint."
4181 (unless (stringp command)
4182 (setq command (read-string
4183 "Print using command: " gnus-summary-muttprint-program
4184 nil gnus-summary-muttprint-program)))
4185 (let ((gnus-summary-pipe-output-default-command
4186 gnus-summary-pipe-output-default-command))
4187 (gnus-summary-save-in-pipe command))
4188 (setq gnus-summary-muttprint-program command))
4190 ;;; Article file names when saving.
4192 (defun gnus-capitalize-newsgroup (newsgroup)
4193 "Capitalize NEWSGROUP name."
4194 (when (not (zerop (length newsgroup)))
4195 (concat (char-to-string (upcase (aref newsgroup 0)))
4196 (substring newsgroup 1))))
4198 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4199 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4200 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4201 Otherwise, it is like ~/News/news/group/num."
4202 (let ((default
4203 (expand-file-name
4204 (concat (if (gnus-use-long-file-name 'not-save)
4205 (gnus-capitalize-newsgroup newsgroup)
4206 (gnus-newsgroup-directory-form newsgroup))
4207 "/" (int-to-string (mail-header-number headers)))
4208 gnus-article-save-directory)))
4209 (if (and last-file
4210 (string-equal (file-name-directory default)
4211 (file-name-directory last-file))
4212 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4213 default
4214 (or last-file default))))
4216 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4217 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4218 If variable `gnus-use-long-file-name' is non-nil, it is
4219 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4220 (let ((default
4221 (expand-file-name
4222 (concat (if (gnus-use-long-file-name 'not-save)
4223 newsgroup
4224 (gnus-newsgroup-directory-form newsgroup))
4225 "/" (int-to-string (mail-header-number headers)))
4226 gnus-article-save-directory)))
4227 (if (and last-file
4228 (string-equal (file-name-directory default)
4229 (file-name-directory last-file))
4230 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4231 default
4232 (or last-file default))))
4234 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4235 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4236 If variable `gnus-use-long-file-name' is non-nil, it is
4237 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4238 (or last-file
4239 (expand-file-name
4240 (if (gnus-use-long-file-name 'not-save)
4241 newsgroup
4242 (file-relative-name
4243 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4244 default-directory))
4245 gnus-article-save-directory)))
4247 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4248 "Generate file name from sender."
4249 (let ((from (mail-header-from headers)))
4250 (expand-file-name
4251 (if (and from (string-match "\\([^ <]+\\)@" from))
4252 (match-string 1 from)
4253 "nobody")
4254 gnus-article-save-directory)))
4256 (defun article-verify-x-pgp-sig ()
4257 "Verify X-PGP-Sig."
4258 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4259 (interactive)
4260 (if (gnus-buffer-live-p gnus-original-article-buffer)
4261 (let ((sig (with-current-buffer gnus-original-article-buffer
4262 (gnus-fetch-field "X-PGP-Sig")))
4263 items info headers)
4264 (when (and sig
4265 mml2015-use
4266 (mml2015-clear-verify-function))
4267 (with-temp-buffer
4268 (insert-buffer-substring gnus-original-article-buffer)
4269 (setq items (split-string sig))
4270 (message-narrow-to-head)
4271 (let ((inhibit-point-motion-hooks t)
4272 (case-fold-search t))
4273 ;; Don't verify multiple headers.
4274 (setq headers (mapconcat (lambda (header)
4275 (concat header ": "
4276 (mail-fetch-field header)
4277 "\n"))
4278 (split-string (nth 1 items) ",") "")))
4279 (delete-region (point-min) (point-max))
4280 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4281 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4282 (insert headers)
4283 (widen)
4284 (forward-line)
4285 (while (not (eobp))
4286 (if (looking-at "^-")
4287 (insert "- "))
4288 (forward-line))
4289 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4290 (insert "Version: " (car items) "\n\n")
4291 (insert (mapconcat 'identity (cddr items) "\n"))
4292 (insert "\n-----END PGP SIGNATURE-----\n")
4293 (let ((mm-security-handle (list (format "multipart/signed"))))
4294 (mml2015-clean-buffer)
4295 (let ((coding-system-for-write (or gnus-newsgroup-charset
4296 'iso-8859-1)))
4297 (funcall (mml2015-clear-verify-function)))
4298 (setq info
4299 (or (mm-handle-multipart-ctl-parameter
4300 mm-security-handle 'gnus-details)
4301 (mm-handle-multipart-ctl-parameter
4302 mm-security-handle 'gnus-info)))))
4303 (when info
4304 (let ((inhibit-read-only t) bface eface)
4305 (save-restriction
4306 (message-narrow-to-head)
4307 (goto-char (point-max))
4308 (forward-line -1)
4309 (setq bface (get-text-property (point-at-bol) 'face)
4310 eface (get-text-property (1- (point-at-eol)) 'face))
4311 (message-remove-header "X-Gnus-PGP-Verify")
4312 (if (re-search-forward "^X-PGP-Sig:" nil t)
4313 (forward-line)
4314 (goto-char (point-max)))
4315 (narrow-to-region (point) (point))
4316 (insert "X-Gnus-PGP-Verify: " info "\n")
4317 (goto-char (point-min))
4318 (forward-line)
4319 (while (not (eobp))
4320 (if (not (looking-at "^[ \t]"))
4321 (insert " "))
4322 (forward-line))
4323 ;; Do highlighting.
4324 (goto-char (point-min))
4325 (when (looking-at "\\([^:]+\\): *")
4326 (put-text-property (match-beginning 1) (1+ (match-end 1))
4327 'face bface)
4328 (put-text-property (match-end 0) (point-max)
4329 'face eface)))))))))
4331 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4333 (defun article-verify-cancel-lock ()
4334 "Verify Cancel-Lock header."
4335 (interactive)
4336 (if (gnus-buffer-live-p gnus-original-article-buffer)
4337 (canlock-verify gnus-original-article-buffer)))
4339 (eval-and-compile
4340 (mapc
4341 (lambda (func)
4342 (let (afunc gfunc)
4343 (if (consp func)
4344 (setq afunc (car func)
4345 gfunc (cdr func))
4346 (setq afunc func
4347 gfunc (intern (format "gnus-%s" func))))
4348 (defalias gfunc
4349 (when (fboundp afunc)
4350 `(lambda (&optional interactive &rest args)
4351 ,(documentation afunc t)
4352 (interactive (list t))
4353 (with-current-buffer gnus-article-buffer
4354 (if interactive
4355 (call-interactively ',afunc)
4356 (apply ',afunc args))))))))
4357 '(article-hide-headers
4358 article-verify-x-pgp-sig
4359 article-verify-cancel-lock
4360 article-hide-boring-headers
4361 article-treat-overstrike
4362 article-treat-ansi-sequences
4363 article-fill-long-lines
4364 article-capitalize-sentences
4365 article-remove-cr
4366 article-remove-leading-whitespace
4367 article-display-x-face
4368 article-display-face
4369 article-de-quoted-unreadable
4370 article-de-base64-unreadable
4371 article-decode-HZ
4372 article-wash-html
4373 article-unsplit-urls
4374 article-hide-list-identifiers
4375 article-strip-banner
4376 article-babel
4377 article-hide-pem
4378 article-hide-signature
4379 article-strip-headers-in-body
4380 article-remove-trailing-blank-lines
4381 article-strip-leading-blank-lines
4382 article-strip-multiple-blank-lines
4383 article-strip-leading-space
4384 article-strip-trailing-space
4385 article-strip-blank-lines
4386 article-strip-all-blank-lines
4387 article-date-local
4388 article-date-english
4389 article-date-iso8601
4390 article-date-original
4391 article-treat-date
4392 article-date-ut
4393 article-decode-mime-words
4394 article-decode-charset
4395 article-decode-encoded-words
4396 article-date-user
4397 article-date-lapsed
4398 article-date-combined-lapsed
4399 article-emphasize
4400 article-treat-dumbquotes
4401 article-treat-non-ascii
4402 article-normalize-headers
4403 ;;(article-show-all . gnus-article-show-all-headers)
4407 ;;; Gnus article mode
4410 (put 'gnus-article-mode 'mode-class 'special)
4412 (set-keymap-parent gnus-article-mode-map widget-keymap)
4414 (gnus-define-keys gnus-article-mode-map
4415 " " gnus-article-goto-next-page
4416 [?\S-\ ] gnus-article-goto-prev-page
4417 "\177" gnus-article-goto-prev-page
4418 [delete] gnus-article-goto-prev-page
4419 "\C-c^" gnus-article-refer-article
4420 "h" gnus-article-show-summary
4421 "s" gnus-article-show-summary
4422 "\C-c\C-m" gnus-article-mail
4423 "?" gnus-article-describe-briefly
4424 "<" beginning-of-buffer
4425 ">" end-of-buffer
4426 "\C-c\C-i" gnus-info-find-node
4427 "\C-c\C-b" gnus-bug
4428 "R" gnus-article-reply-with-original
4429 "F" gnus-article-followup-with-original
4430 "\C-hk" gnus-article-describe-key
4431 "\C-hc" gnus-article-describe-key-briefly
4432 "\C-hb" gnus-article-describe-bindings
4434 "e" gnus-article-read-summary-keys
4435 "\C-d" gnus-article-read-summary-keys
4436 "\M-*" gnus-article-read-summary-keys
4437 "\M-#" gnus-article-read-summary-keys
4438 "\M-^" gnus-article-read-summary-keys
4439 "\M-g" gnus-article-read-summary-keys)
4441 (substitute-key-definition
4442 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4444 (defvar gnus-article-send-map)
4446 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4447 "W" gnus-article-wide-reply-with-original)
4448 (if (featurep 'xemacs)
4449 (set-keymap-default-binding gnus-article-send-map
4450 'gnus-article-read-summary-send-keys)
4451 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4453 (defun gnus-article-make-menu-bar ()
4454 (unless (boundp 'gnus-article-commands-menu)
4455 (gnus-summary-make-menu-bar))
4456 (unless (boundp 'gnus-article-article-menu)
4457 (easy-menu-define
4458 gnus-article-article-menu gnus-article-mode-map ""
4459 '("Article"
4460 ["Scroll forwards" gnus-article-goto-next-page t]
4461 ["Scroll backwards" gnus-article-goto-prev-page t]
4462 ["Show summary" gnus-article-show-summary t]
4463 ["Fetch Message-ID at point" gnus-article-refer-article t]
4464 ["Mail to address at point" gnus-article-mail t]
4465 ["Send a bug report" gnus-bug t]))
4467 (easy-menu-define
4468 gnus-article-treatment-menu gnus-article-mode-map ""
4469 ;; Fixme: this should use :active (and maybe :visible).
4470 '("Treatment"
4471 ["Hide headers" gnus-article-hide-headers t]
4472 ["Hide signature" gnus-article-hide-signature t]
4473 ["Hide citation" gnus-article-hide-citation t]
4474 ["Treat overstrike" gnus-article-treat-overstrike t]
4475 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4476 ["Remove carriage return" gnus-article-remove-cr t]
4477 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4478 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4479 ["Remove base64" gnus-article-de-base64-unreadable t]
4480 ["Treat html" gnus-article-wash-html t]
4481 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4482 ["Decode HZ" gnus-article-decode-HZ t]))
4484 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4486 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4488 (gnus-run-hooks 'gnus-article-menu-hook)))
4490 (defvar bookmark-make-record-function)
4491 (defvar shr-put-image-function)
4493 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4494 "Major mode for displaying an article.
4496 All normal editing commands are switched off.
4498 The following commands are available in addition to all summary mode
4499 commands:
4500 \\<gnus-article-mode-map>
4501 \\[gnus-article-next-page]\t Scroll the article one page forwards
4502 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4503 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4504 \\[gnus-article-show-summary]\t Display the summary buffer
4505 \\[gnus-article-mail]\t Send a reply to the address near point
4506 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4507 \\[gnus-info-find-node]\t Go to the Gnus info node"
4508 (gnus-simplify-mode-line)
4509 (make-local-variable 'minor-mode-alist)
4510 (when (gnus-visual-p 'article-menu 'menu)
4511 (gnus-article-make-menu-bar)
4512 (when gnus-summary-tool-bar-map
4513 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4514 (gnus-update-format-specifications nil 'article-mode)
4515 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4516 (set (make-local-variable 'gnus-page-broken) nil)
4517 (make-local-variable 'gnus-article-current-summary)
4518 (make-local-variable 'gnus-article-mime-handles)
4519 (make-local-variable 'gnus-article-decoded-p)
4520 (make-local-variable 'gnus-article-mime-handle-alist)
4521 (make-local-variable 'gnus-article-wash-types)
4522 (make-local-variable 'gnus-article-image-alist)
4523 (make-local-variable 'gnus-article-charset)
4524 (make-local-variable 'gnus-article-ignored-charsets)
4525 (set (make-local-variable 'bookmark-make-record-function)
4526 'gnus-summary-bookmark-make-record)
4527 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4528 ;; face.
4529 (set (make-local-variable 'nobreak-char-display) nil)
4530 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4531 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4532 (setq cursor-in-non-selected-windows nil)
4533 (gnus-set-default-directory)
4534 (buffer-disable-undo)
4535 (setq buffer-read-only t
4536 show-trailing-whitespace nil)
4537 (mm-enable-multibyte))
4539 (defun gnus-article-setup-buffer ()
4540 "Initialize the article buffer."
4541 (let* ((name (if gnus-single-article-buffer "*Article*"
4542 (concat "*Article "
4543 (gnus-group-decoded-name gnus-newsgroup-name)
4544 "*")))
4545 (original
4546 (progn (string-match "\\*Article" name)
4547 (concat " *Original Article"
4548 (substring name (match-end 0))))))
4549 (setq gnus-article-buffer name)
4550 (setq gnus-original-article-buffer original)
4551 (setq gnus-article-mime-handle-alist nil)
4552 (with-current-buffer gnus-summary-buffer
4553 ;; This might be a variable local to the summary buffer.
4554 (unless gnus-single-article-buffer
4555 (setq gnus-article-buffer name)
4556 (setq gnus-original-article-buffer original)
4557 (gnus-set-global-variables)))
4558 (gnus-article-setup-highlight-words)
4559 ;; Init original article buffer.
4560 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4561 (mm-enable-multibyte)
4562 (setq major-mode 'gnus-original-article-mode)
4563 (make-local-variable 'gnus-original-article))
4564 (if (and (get-buffer name)
4565 (with-current-buffer name
4566 (if gnus-article-edit-mode
4567 (if (y-or-n-p "Article mode edit in progress; discard? ")
4568 (progn
4569 (set-buffer-modified-p nil)
4570 (gnus-kill-buffer name)
4571 (message "")
4572 nil)
4573 (error "Action aborted"))
4574 t)))
4575 (let ((summary gnus-summary-buffer))
4576 (with-current-buffer name
4577 (set (make-local-variable 'gnus-article-edit-mode) nil)
4578 (gnus-article-stop-animations)
4579 (when gnus-article-mime-handles
4580 (mm-destroy-parts gnus-article-mime-handles)
4581 (setq gnus-article-mime-handles nil))
4582 ;; Set it to nil in article-buffer!
4583 (setq gnus-article-mime-handle-alist nil)
4584 (buffer-disable-undo)
4585 (setq buffer-read-only t)
4586 (unless (derived-mode-p 'gnus-article-mode)
4587 (gnus-article-mode))
4588 (set (make-local-variable 'gnus-summary-buffer) summary)
4589 (setq truncate-lines gnus-article-truncate-lines)
4590 (current-buffer)))
4591 (let ((summary gnus-summary-buffer))
4592 (with-current-buffer (gnus-get-buffer-create name)
4593 (gnus-article-mode)
4594 (setq truncate-lines gnus-article-truncate-lines)
4595 (set (make-local-variable 'gnus-summary-buffer) summary)
4596 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4597 (when article-lapsed-timer
4598 (gnus-stop-date-timer))
4599 (when gnus-article-update-date-headers
4600 (gnus-start-date-timer gnus-article-update-date-headers))
4601 (current-buffer))))))
4603 (defun gnus-article-stop-animations ()
4604 (dolist (timer (and (boundp 'timer-list)
4605 timer-list))
4606 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4607 (cancel-timer timer))))
4609 (defun gnus-stop-downloads ()
4610 (when (boundp 'url-queue)
4611 (set (intern "url-queue" obarray) nil)))
4613 ;; Set article window start at LINE, where LINE is the number of lines
4614 ;; from the head of the article.
4615 (defun gnus-article-set-window-start (&optional line)
4616 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4617 (when article-window
4618 (set-window-start
4619 article-window
4620 (with-current-buffer gnus-article-buffer
4621 (goto-char (point-min))
4622 (if (not line)
4623 (point-min)
4624 (gnus-message 6 "Moved to bookmark")
4625 (search-forward "\n\n" nil t)
4626 (forward-line line)
4627 (point)))))))
4629 (defvar gnus-tmp-internal-hook)
4631 (defun gnus-article-prepare (article &optional all-headers _header)
4632 "Prepare ARTICLE in article mode buffer.
4633 ARTICLE should either be an article number or a Message-ID.
4634 If ARTICLE is an id, HEADER should be the article headers.
4635 If ALL-HEADERS is non-nil, no headers are hidden."
4636 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4637 ;; Make sure we start in a summary buffer.
4638 (unless (derived-mode-p 'gnus-summary-mode)
4639 (set-buffer gnus-summary-buffer))
4640 (setq gnus-summary-buffer (current-buffer))
4641 (let* ((summary-buffer (current-buffer))
4642 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4643 (group gnus-newsgroup-name)
4644 result)
4645 (save-excursion
4646 (gnus-article-setup-buffer)
4647 (set-buffer gnus-article-buffer)
4648 ;; Deactivate active regions.
4649 (when (and (boundp 'transient-mark-mode)
4650 transient-mark-mode)
4651 (setq mark-active nil))
4652 (if (not (setq result (let ((inhibit-read-only t))
4653 (gnus-request-article-this-buffer
4654 article group))))
4655 ;; There is no such article.
4656 (save-excursion
4657 (when (and (numberp article)
4658 (not (memq article gnus-newsgroup-sparse)))
4659 (setq gnus-article-current
4660 (cons gnus-newsgroup-name article))
4661 (set-buffer gnus-summary-buffer)
4662 (setq gnus-current-article article)
4663 (if (and (memq article gnus-newsgroup-undownloaded)
4664 (not (gnus-online (gnus-find-method-for-group
4665 gnus-newsgroup-name))))
4666 (progn
4667 (gnus-summary-set-agent-mark article)
4668 (message "Message marked for downloading"))
4669 (gnus-summary-mark-article article gnus-canceled-mark)
4670 (unless (memq article gnus-newsgroup-sparse)
4671 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4672 (if (or (eq result 'pseudo)
4673 (eq result 'nneething))
4674 (progn
4675 (with-current-buffer summary-buffer
4676 (push article gnus-newsgroup-history)
4677 (setq gnus-last-article gnus-current-article
4678 gnus-current-article 0
4679 gnus-current-headers nil
4680 gnus-article-current nil)
4681 (if (eq result 'nneething)
4682 (gnus-configure-windows 'summary)
4683 (gnus-configure-windows 'article))
4684 (gnus-set-global-variables))
4685 (let ((gnus-article-mime-handle-alist-1
4686 gnus-article-mime-handle-alist))
4687 (gnus-set-mode-line 'article)))
4688 ;; The result from the `request' was an actual article -
4689 ;; or at least some text that is now displayed in the
4690 ;; article buffer.
4691 (when (and (numberp article)
4692 (not (eq article gnus-current-article)))
4693 ;; Seems like a new article has been selected.
4694 ;; `gnus-current-article' must be an article number.
4695 (with-current-buffer summary-buffer
4696 (push article gnus-newsgroup-history)
4697 (setq gnus-last-article gnus-current-article
4698 gnus-current-article article
4699 gnus-current-headers
4700 (gnus-summary-article-header gnus-current-article)
4701 gnus-article-current
4702 (cons gnus-newsgroup-name gnus-current-article))
4703 (unless (vectorp gnus-current-headers)
4704 (setq gnus-current-headers nil))
4705 (gnus-summary-goto-subject gnus-current-article)
4706 (when (gnus-summary-show-thread)
4707 ;; If the summary buffer really was folded, the
4708 ;; previous goto may not actually have gone to
4709 ;; the right article, but the thread root instead.
4710 ;; So we go again.
4711 (gnus-summary-goto-subject gnus-current-article))
4712 (gnus-run-hooks 'gnus-mark-article-hook)
4713 (gnus-set-mode-line 'summary)
4714 (when (gnus-visual-p 'article-highlight 'highlight)
4715 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4716 ;; Set the global newsgroup variables here.
4717 (gnus-set-global-variables)
4718 (setq gnus-have-all-headers
4719 (or all-headers gnus-show-all-headers))))
4720 (save-excursion
4721 (gnus-configure-windows 'article))
4722 (when (or (numberp article)
4723 (stringp article))
4724 (gnus-article-prepare-display)
4725 ;; Do page break.
4726 (goto-char (point-min))
4727 (when gnus-break-pages
4728 (gnus-narrow-to-page)))
4729 (let ((gnus-article-mime-handle-alist-1
4730 gnus-article-mime-handle-alist))
4731 (gnus-set-mode-line 'article))
4732 (article-goto-body)
4733 (unless (bobp)
4734 (forward-line -1))
4735 (set-window-point (get-buffer-window (current-buffer)) (point))
4736 (gnus-configure-windows 'article)
4737 (gnus-run-hooks 'gnus-article-prepare-hook)
4738 t))))))
4740 (defvar gnus-mime-display-attachment-buttons-in-header)
4742 ;;;###autoload
4743 (defun gnus-article-prepare-display ()
4744 "Make the current buffer look like a nice article."
4745 ;; Hooks for getting information from the article.
4746 ;; This hook must be called before being narrowed.
4747 (let ((gnus-article-buffer (current-buffer))
4748 buffer-read-only
4749 (inhibit-read-only t))
4750 (unless (derived-mode-p 'gnus-article-mode)
4751 (gnus-article-mode))
4752 (setq buffer-read-only nil
4753 gnus-article-wash-types nil
4754 gnus-article-image-alist nil)
4755 (gnus-run-hooks 'gnus-tmp-internal-hook)
4756 (when gnus-display-mime-function
4757 (funcall gnus-display-mime-function))
4758 ;; Add attachment buttons to the header.
4759 (when gnus-mime-display-attachment-buttons-in-header
4760 (gnus-mime-buttonize-attachments-in-header))))
4763 ;;; Gnus Sticky Article Mode
4766 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4767 "Mode for sticky articles."
4768 ;; Release bindings that won't work.
4769 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4770 gnus-sticky-article-mode-map)
4771 (substitute-key-definition 'gnus-article-refer-article 'undefined
4772 gnus-sticky-article-mode-map)
4773 (dolist (k '("e" "h" "s" "F" "R"))
4774 (define-key gnus-sticky-article-mode-map k nil))
4775 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4776 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4777 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4778 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4780 (defun gnus-sticky-article (arg)
4781 "Make the current article sticky.
4782 If a prefix ARG is given, ask for a name for this sticky article buffer."
4783 (interactive "P")
4784 (gnus-summary-show-thread)
4785 (gnus-summary-select-article nil nil 'pseudo)
4786 (let (new-art-buf-name)
4787 (gnus-eval-in-buffer-window gnus-article-buffer
4788 (setq new-art-buf-name
4789 (concat
4790 "*Sticky Article: "
4791 (if arg
4792 (read-from-minibuffer "Sticky article buffer name: ")
4793 (gnus-with-article-headers
4794 (gnus-article-goto-header "subject")
4795 (setq new-art-buf-name
4796 (buffer-substring-no-properties
4797 (line-beginning-position) (line-end-position)))
4798 (goto-char (point-min))
4799 (gnus-article-goto-header "from")
4800 (setq new-art-buf-name
4801 (concat
4802 new-art-buf-name ", "
4803 (buffer-substring-no-properties
4804 (line-beginning-position) (line-end-position))))
4805 (goto-char (point-min))
4806 (gnus-article-goto-header "date")
4807 (setq new-art-buf-name
4808 (concat
4809 new-art-buf-name ", "
4810 (buffer-substring-no-properties
4811 (line-beginning-position) (line-end-position))))))
4812 "*"))
4813 (if (and (gnus-buffer-live-p new-art-buf-name)
4814 (with-current-buffer new-art-buf-name
4815 (derived-mode-p 'gnus-sticky-article-mode)))
4816 (switch-to-buffer new-art-buf-name)
4817 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4818 (gnus-sticky-article-mode))
4819 (setq gnus-article-buffer new-art-buf-name))
4820 (gnus-summary-recenter)
4821 (gnus-summary-position-point))
4823 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4824 "Kill the given sticky article BUFFER.
4825 If none is given, assume the current buffer and kill it if it has
4826 `gnus-sticky-article-mode'."
4827 (interactive)
4828 (unless buffer
4829 (setq buffer (current-buffer)))
4830 (with-current-buffer buffer
4831 (when (derived-mode-p 'gnus-sticky-article-mode)
4832 (gnus-kill-buffer buffer))))
4834 (defun gnus-kill-sticky-article-buffers (arg)
4835 "Kill all sticky article buffers.
4836 If a prefix ARG is given, ask for confirmation."
4837 (interactive "P")
4838 (dolist (buf (gnus-buffers))
4839 (with-current-buffer buf
4840 (when (derived-mode-p 'gnus-sticky-article-mode)
4841 (if (not arg)
4842 (gnus-kill-buffer buf)
4843 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4844 (gnus-kill-buffer buf)))))))
4847 ;;; Gnus MIME viewing functions
4850 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4851 "Format of the MIME buttons.
4853 Valid specifiers include:
4854 %t The MIME type
4855 %T MIME type, along with additional info
4856 %n The `name' parameter
4857 %d The description, if any
4858 %l The length of the encoded part
4859 %p The part identifier number
4860 %e Dots if the part isn't displayed
4862 General format specifiers can also be used. See Info node
4863 `(gnus)Formatting Variables'.")
4865 (defvar gnus-tmp-type)
4866 (defvar gnus-tmp-type-long)
4867 (defvar gnus-tmp-name)
4868 (defvar gnus-tmp-description)
4869 (defvar gnus-tmp-id)
4870 (defvar gnus-tmp-length)
4871 (defvar gnus-tmp-dots)
4872 (defvar gnus-tmp-info)
4873 (defvar gnus-tmp-pressed-details)
4875 (defvar gnus-mime-button-line-format-alist
4876 '((?t gnus-tmp-type ?s)
4877 (?T gnus-tmp-type-long ?s)
4878 (?n gnus-tmp-name ?s)
4879 (?d gnus-tmp-description ?s)
4880 (?p gnus-tmp-id ?s)
4881 (?l gnus-tmp-length ?d)
4882 (?e gnus-tmp-dots ?s)))
4884 (defvar gnus-mime-button-commands
4885 '((gnus-article-press-button "\r" "Toggle Display")
4886 (gnus-mime-view-part "v" "View Interactively...")
4887 (gnus-mime-view-part-as-type "t" "View As Type...")
4888 (gnus-mime-view-part-as-charset "C" "View As charset...")
4889 (gnus-mime-save-part "o" "Save...")
4890 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4891 (gnus-mime-replace-part "r" "Replace part")
4892 (gnus-mime-delete-part "d" "Delete part")
4893 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4894 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4895 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4896 (gnus-mime-view-part-externally "e" "View Externally")
4897 (gnus-mime-print-part "p" "Print")
4898 (gnus-mime-pipe-part "|" "Pipe To Command...")
4899 (gnus-mime-action-on-part "." "Take action on the part...")))
4901 (defun gnus-article-mime-part-status ()
4902 (if gnus-article-mime-handle-alist-1
4903 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4904 " (1 part)"
4905 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4906 ""))
4908 (defvar gnus-mime-button-map
4909 (let ((map (make-sparse-keymap)))
4910 (define-key map gnus-mouse-2 'gnus-article-push-button)
4911 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4912 (dolist (c gnus-mime-button-commands)
4913 (define-key map (cadr c) (car c)))
4914 map))
4916 (easy-menu-define
4917 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4918 `("MIME Part"
4919 ,@(mapcar (lambda (c)
4920 (vector (caddr c) (car c) :active t))
4921 gnus-mime-button-commands)))
4923 (defvar gnus-url-button-commands
4924 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4926 (defvar gnus-url-button-map
4927 (let ((map (make-sparse-keymap)))
4928 (dolist (c gnus-url-button-commands)
4929 (define-key map (cadr c) (car c)))
4930 map))
4932 (easy-menu-define
4933 gnus-url-button-menu gnus-url-button-map "URL button menu."
4934 `("Url Button"
4935 ,@(mapcar (lambda (c)
4936 (vector (caddr c) (car c) :active t))
4937 gnus-url-button-commands)))
4939 (defmacro gnus-bind-safe-url-regexp (&rest body)
4940 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4941 `(let ((mm-w3m-safe-url-regexp
4942 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4943 (gnus-buffer-live-p
4944 gnus-article-current-summary))
4945 (with-current-buffer gnus-article-current-summary
4946 gnus-newsgroup-name)
4947 gnus-newsgroup-name)))
4948 (if (cond ((not group)
4949 ;; Maybe we're in a mml-preview buffer
4950 ;; and no group is selected.
4952 ((stringp gnus-safe-html-newsgroups)
4953 (string-match gnus-safe-html-newsgroups group))
4954 ((consp gnus-safe-html-newsgroups)
4955 (member group gnus-safe-html-newsgroups)))
4957 mm-w3m-safe-url-regexp))))
4958 ,@body))
4960 (defun gnus-mime-button-menu (event prefix)
4961 "Construct a context-sensitive menu of MIME commands."
4962 (interactive "e\nP")
4963 (save-window-excursion
4964 (let ((pos (event-start event)))
4965 (select-window (posn-window pos))
4966 (goto-char (posn-point pos))
4967 (gnus-article-check-buffer)
4968 (popup-menu gnus-mime-button-menu nil prefix))))
4970 (defun gnus-mime-view-all-parts (&optional handles)
4971 "View all the MIME parts."
4972 (interactive)
4973 (with-current-buffer gnus-article-buffer
4974 (let ((handles (or handles gnus-article-mime-handles))
4975 (mail-parse-charset gnus-newsgroup-charset)
4976 (mail-parse-ignored-charsets
4977 (with-current-buffer gnus-summary-buffer
4978 gnus-newsgroup-ignored-charsets)))
4979 (when handles
4980 (mm-remove-parts handles)
4981 (goto-char (point-min))
4982 (or (search-forward "\n\n") (goto-char (point-max)))
4983 (let ((inhibit-read-only t))
4984 (delete-region (point) (point-max))
4985 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4987 (defun gnus-article-jump-to-part (n)
4988 "Jump to MIME part N."
4989 (interactive "P")
4990 (let ((parts (with-current-buffer gnus-article-buffer
4991 (length gnus-article-mime-handle-alist))))
4992 (when (zerop parts)
4993 (error "No such part"))
4994 (pop-to-buffer gnus-article-buffer)
4995 (or n
4996 (setq n (if (= parts 1)
4998 (read-number (format "Jump to part (1..%s): " parts)))))
4999 (unless (and (integerp n) (<= n parts) (>= n 1))
5000 (setq n
5001 (progn
5002 (gnus-message 7 "Invalid part `%s', using %s instead."
5003 n parts)
5004 parts)))
5005 (gnus-message 9 "Jumping to part %s." n)
5006 (cond ((>= gnus-auto-select-part 1)
5007 (while (and (<= n parts)
5008 (not (gnus-article-goto-part n)))
5009 (setq n (1+ n))))
5010 ((< gnus-auto-select-part 0)
5011 (while (and (>= n 1)
5012 (not (gnus-article-goto-part n)))
5013 (setq n (1- n))))
5015 (gnus-article-goto-part n)))))
5017 (defvar gnus-mime-buttonized-part-id nil
5018 "ID of a mime part that should be buttonized.
5019 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5021 (eval-when-compile
5022 (defsubst gnus-article-edit-part (handles &optional current-id)
5023 "Edit an article in order to delete a mime part.
5024 This function is exclusively used by `gnus-mime-save-part-and-strip'
5025 and `gnus-mime-delete-part', and not provided at run-time normally."
5026 (gnus-article-edit-article
5027 `(lambda ()
5028 (buffer-disable-undo)
5029 (let ((mail-parse-charset (or gnus-article-charset
5030 ',gnus-newsgroup-charset))
5031 (mail-parse-ignored-charsets
5032 (or gnus-article-ignored-charsets
5033 ',gnus-newsgroup-ignored-charsets))
5034 (mbl mml-buffer-list))
5035 (setq mml-buffer-list nil)
5036 ;; A new text must be inserted before deleting existing ones
5037 ;; at the end so as not to move existing markers of which
5038 ;; the insertion type is t.
5039 (delete-region
5040 (point-min)
5041 (prog1
5042 (goto-char (point-max))
5043 (insert-buffer-substring gnus-original-article-buffer)))
5044 (mime-to-mml ',handles)
5045 (setq gnus-article-mime-handles nil)
5046 (let ((mbl1 mml-buffer-list))
5047 (setq mml-buffer-list mbl)
5048 (set (make-local-variable 'mml-buffer-list) mbl1))
5049 (gnus-make-local-hook 'kill-buffer-hook)
5050 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5051 `(lambda (no-highlight)
5052 (let ((mail-parse-charset (or gnus-article-charset
5053 ',gnus-newsgroup-charset))
5054 (message-options message-options)
5055 (message-options-set-recipient)
5056 (mail-parse-ignored-charsets
5057 (or gnus-article-ignored-charsets
5058 ',gnus-newsgroup-ignored-charsets)))
5059 (mml-to-mime)
5060 (mml-destroy-buffers)
5061 (remove-hook 'kill-buffer-hook
5062 'mml-destroy-buffers t)
5063 (kill-local-variable 'mml-buffer-list))
5064 (gnus-summary-edit-article-done
5065 ,(or (mail-header-references gnus-current-headers) "")
5066 ,(gnus-group-read-only-p)
5067 ,gnus-summary-buffer no-highlight))
5069 ;; Force buttonizing this part.
5070 (let ((gnus-mime-buttonized-part-id current-id))
5071 (gnus-article-edit-done))
5072 (gnus-configure-windows 'article)
5073 (sit-for 0)
5074 (when (and current-id (integerp gnus-auto-select-part))
5075 (gnus-article-jump-to-part
5076 (min (max (+ current-id gnus-auto-select-part) 1)
5077 (with-current-buffer gnus-article-buffer
5078 (length gnus-article-mime-handle-alist)))))))
5080 (defun gnus-mime-replace-part (file)
5081 "Replace MIME part under point with an external body."
5082 ;; Useful if file has already been saved to disk
5083 (interactive
5084 (list
5085 (read-file-name "Replace MIME part with file: "
5086 (or mm-default-directory default-directory)
5087 nil nil)))
5088 (gnus-mime-save-part-and-strip file))
5090 (defun gnus-mime-save-part-and-strip (&optional file)
5091 "Save the MIME part under point then replace it with an external body.
5092 If FILE is given, use it for the external part."
5093 (interactive)
5094 (gnus-article-check-buffer)
5095 (when (gnus-group-read-only-p)
5096 (error "The current group does not support deleting of parts"))
5097 (when (mm-complicated-handles gnus-article-mime-handles)
5098 (error "\
5099 The current article has a complicated MIME structure, giving up..."))
5100 (let* ((data (get-text-property (point) 'gnus-data))
5101 (id (get-text-property (point) 'gnus-part))
5102 (handles gnus-article-mime-handles))
5103 (unless file
5104 (setq file
5105 (and data (mm-save-part data "Delete MIME part and save to: "))))
5106 (when file
5107 (with-current-buffer (mm-handle-buffer data)
5108 (erase-buffer)
5109 (insert "Content-Type: " (mm-handle-media-type data))
5110 (mml-insert-parameter-string (cdr (mm-handle-type data))
5111 '(charset))
5112 ;; Add a filename for the sake of saving the part again.
5113 (mml-insert-parameter
5114 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5115 (insert "\n")
5116 (insert "Content-ID: " (message-make-message-id) "\n")
5117 (insert "Content-Transfer-Encoding: binary\n")
5118 (insert "\n"))
5119 (setcdr data
5120 (cdr (mm-make-handle nil
5121 `("message/external-body"
5122 (access-type . "LOCAL-FILE")
5123 (name . ,file)))))
5124 ;; (set-buffer gnus-summary-buffer)
5125 (gnus-article-edit-part handles id))))
5127 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5128 ;; parts...>') but with stripping would be nice.
5130 (defun gnus-mime-delete-part ()
5131 "Delete the MIME part under point.
5132 Replace it with some information about the removed part."
5133 (interactive)
5134 (gnus-article-check-buffer)
5135 (when (gnus-group-read-only-p)
5136 (error "The current group does not support deleting of parts"))
5137 (when (mm-complicated-handles gnus-article-mime-handles)
5138 (error "\
5139 The current article has a complicated MIME structure, giving up..."))
5140 (when (or gnus-expert-user
5141 (gnus-yes-or-no-p "\
5142 Deleting parts may malfunction or destroy the article; continue? "))
5143 (let* ((data (get-text-property (point) 'gnus-data))
5144 (id (get-text-property (point) 'gnus-part))
5145 (handles gnus-article-mime-handles)
5146 (description
5147 (let ((desc (mm-handle-description data)))
5148 (when desc
5149 (mail-decode-encoded-word-string desc))))
5150 (filename (or (mm-handle-filename data) "(none)"))
5151 (type (mm-handle-media-type data)))
5152 (unless data
5153 (error "No MIME part under point"))
5154 (with-current-buffer (mm-handle-buffer data)
5155 (let ((bsize (buffer-size)))
5156 (erase-buffer)
5157 (insert
5158 (concat
5159 ",----\n"
5160 "| The following attachment has been deleted:\n"
5161 "|\n"
5162 "| Type: " type "\n"
5163 "| Filename: " filename "\n"
5164 "| Size (encoded): " (format "%s byte%s\n"
5165 bsize (if (= bsize 1)
5167 "s"))
5168 (when description
5169 (concat "| Description: " description "\n"))
5170 "`----\n"))
5171 (setcdr data
5172 (cdr (mm-make-handle
5173 nil `("text/plain" (charset . gnus-decoded)) nil nil
5174 (list "attachment")
5175 (format "Deleted attachment (%s bytes)" bsize))))))
5176 ;; (set-buffer gnus-summary-buffer)
5177 (gnus-article-edit-part handles id))))
5179 (defun gnus-mime-save-part ()
5180 "Save the MIME part under point."
5181 (interactive)
5182 (gnus-article-check-buffer)
5183 (let ((data (get-text-property (point) 'gnus-data)))
5184 (when data
5185 (mm-save-part data))))
5187 (defun gnus-mime-pipe-part (&optional cmd)
5188 "Pipe the MIME part under point to a process.
5189 Use CMD as the process."
5190 (interactive)
5191 (gnus-article-check-buffer)
5192 (let ((data (get-text-property (point) 'gnus-data)))
5193 (when data
5194 (mm-pipe-part data cmd))))
5196 (defun gnus-mime-view-part ()
5197 "Interactively choose a viewing method for the MIME part under point."
5198 (interactive)
5199 (gnus-article-check-buffer)
5200 (let ((data (get-text-property (point) 'gnus-data)))
5201 (when data
5202 (setq gnus-article-mime-handles
5203 (mm-merge-handles
5204 gnus-article-mime-handles (setq data (copy-sequence data))))
5205 (mm-interactively-view-part data))))
5207 (defun gnus-mime-view-part-as-type-internal ()
5208 (gnus-article-check-buffer)
5209 (let* ((handle (get-text-property (point) 'gnus-data))
5210 (name (or
5211 ;; Content-Type: foo/bar; name=...
5212 (mail-content-type-get (mm-handle-type handle) 'name)
5213 ;; Content-Disposition: attachment; filename=...
5214 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5215 (def-type (and name (mm-default-file-encoding name))))
5216 (or (and def-type (cons def-type 0))
5217 (and handle
5218 (equal (mm-handle-media-supertype handle) "text")
5219 '("text/plain" . 0))
5220 '("application/octet-stream" . 0))))
5222 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5223 "Choose a MIME media type, and view the part as such.
5224 If non-nil, PRED is a predicate to use during completion to limit the
5225 available media-types."
5226 (interactive)
5227 (unless mime-type
5228 (setq mime-type
5229 (let ((default (gnus-mime-view-part-as-type-internal)))
5230 (gnus-completing-read
5231 "View as MIME type"
5232 (if pred
5233 (gnus-remove-if-not pred (mailcap-mime-types))
5234 (mailcap-mime-types))
5235 nil nil nil
5236 (car default)))))
5237 (gnus-article-check-buffer)
5238 (let ((handle (get-text-property (point) 'gnus-data)))
5239 (when handle
5240 (when (equal (mm-handle-media-type handle) "message/external-body")
5241 (unless (mm-handle-cache handle)
5242 (mm-extern-cache-contents handle))
5243 (setq handle (mm-handle-cache handle)))
5244 (setq handle
5245 (mm-make-handle (mm-handle-buffer handle)
5246 (cons mime-type (cdr (mm-handle-type handle)))
5247 (mm-handle-encoding handle)
5248 (mm-handle-undisplayer handle)
5249 (mm-handle-disposition handle)
5250 (mm-handle-description handle)
5252 (mm-handle-id handle)))
5253 (setq gnus-article-mime-handles
5254 (mm-merge-handles gnus-article-mime-handles handle))
5255 (when (mm-handle-displayed-p handle)
5256 (mm-remove-part handle))
5257 (gnus-mm-display-part handle))))
5259 (defun gnus-mime-copy-part (&optional handle arg)
5260 "Put the MIME part under point into a new buffer.
5261 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5262 are decompressed."
5263 (interactive (list nil current-prefix-arg))
5264 (gnus-article-check-buffer)
5265 (unless handle
5266 (setq handle (get-text-property (point) 'gnus-data)))
5267 (when handle
5268 (let ((filename (mm-handle-filename handle))
5269 contents dont-decode charset coding-system)
5270 (mm-with-unibyte-buffer
5271 (mm-insert-part handle)
5272 (setq contents (or (condition-case nil
5273 (mm-decompress-buffer filename nil 'sig)
5274 (error
5275 (setq dont-decode t)
5276 nil))
5277 (buffer-string))))
5278 (setq filename (cond (filename (file-name-nondirectory filename))
5279 (dont-decode "*raw data*")
5280 (t "*decoded*")))
5281 (cond
5282 (dont-decode)
5283 ((not arg)
5284 (unless (setq charset (mail-content-type-get
5285 (mm-handle-type handle) 'charset))
5286 (unless (setq coding-system (mm-with-unibyte-buffer
5287 (insert contents)
5288 (mm-find-buffer-file-coding-system)))
5289 (setq charset gnus-newsgroup-charset))))
5290 ((numberp arg)
5291 (setq charset (or (cdr (assq arg
5292 gnus-summary-show-article-charset-alist))
5293 (mm-read-coding-system "Charset: ")))))
5294 (switch-to-buffer (generate-new-buffer filename))
5295 (if (or coding-system
5296 (and charset
5297 (setq coding-system (mm-charset-to-coding-system
5298 charset nil t))
5299 (not (eq coding-system 'ascii))))
5300 (progn
5301 (mm-enable-multibyte)
5302 (insert (mm-decode-coding-string contents coding-system))
5303 (setq buffer-file-coding-system
5304 (if (boundp 'last-coding-system-used)
5305 (symbol-value 'last-coding-system-used)
5306 coding-system)))
5307 (mm-disable-multibyte)
5308 (insert contents)
5309 (setq buffer-file-coding-system mm-binary-coding-system))
5310 ;; We do it this way to make `normal-mode' set the appropriate mode.
5311 (unwind-protect
5312 (progn
5313 (setq buffer-file-name (expand-file-name filename))
5314 (normal-mode))
5315 (setq buffer-file-name nil))
5316 (goto-char (point-min)))))
5318 (defun gnus-mime-print-part (&optional handle filename)
5319 "Print the MIME part under point."
5320 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5321 (gnus-article-check-buffer)
5322 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5323 (contents (and handle (mm-get-part handle)))
5324 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5325 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5326 (when contents
5327 (if printer
5328 (unwind-protect
5329 (progn
5330 (mm-save-part-to-file handle file)
5331 (call-process shell-file-name nil
5332 (generate-new-buffer " *mm*")
5334 shell-command-switch
5335 (mm-mailcap-command
5336 printer file (mm-handle-type handle))))
5337 (delete-file file))
5338 (with-temp-buffer
5339 (insert contents)
5340 (gnus-print-buffer))
5341 (ps-despool filename)))))
5343 (defun gnus-mime-inline-part (&optional handle arg)
5344 "Insert the MIME part under point into the current buffer.
5345 Compressed files like .gz and .bz2 are decompressed."
5346 (interactive (list nil current-prefix-arg))
5347 (gnus-article-check-buffer)
5348 (let* ((inhibit-read-only t)
5349 (b (point))
5350 (btn ;; position where the MIME button exists
5351 (if handle
5352 (if (eq handle (get-text-property b 'gnus-data))
5354 (article-goto-body)
5355 (or (text-property-any (point) (point-max) 'gnus-data handle)
5356 (text-property-any (point-min) (point) 'gnus-data handle)))
5357 (setq handle (get-text-property b 'gnus-data))
5359 start)
5360 (when handle
5361 (when (= b (prog1
5363 (setq start (next-single-property-change btn 'gnus-data
5364 nil (point-max))
5365 btn (previous-single-property-change start
5366 'gnus-data))))
5367 (setq b btn))
5368 (if (and (not arg) (mm-handle-undisplayer handle))
5369 (progn
5370 (setq b (copy-marker b)
5371 btn (copy-marker btn))
5372 (mm-remove-part handle))
5373 (cond
5374 ((not arg) nil)
5375 ((numberp arg)
5376 (if (mm-handle-undisplayer handle)
5377 (mm-remove-part handle)))
5378 ((mm-handle-undisplayer handle)
5379 (mm-remove-part handle)))
5380 (goto-char start)
5381 (unless (bolp)
5382 ;; This is a header button.
5383 (forward-line 1))
5384 (mm-display-inline handle))
5385 ;; Toggle the button appearance between `[button]...' and `[button]'.
5386 (when (markerp btn)
5387 (setq btn (prog1 (marker-position btn)
5388 (set-marker btn nil))))
5389 (goto-char btn)
5390 (let ((displayed-p (mm-handle-displayed-p handle)))
5391 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5392 (list displayed-p))
5393 (if (featurep 'emacs)
5394 (delete-region
5395 (point)
5396 (next-single-property-change (point) 'gnus-data nil (point-max)))
5397 (let* ((end (next-single-property-change (point) 'gnus-data))
5398 (annots (annotations-at (or end (point-max)))))
5399 (delete-region (point)
5400 (if end
5401 (if annots (1+ end) end)
5402 (point-max)))
5403 (dolist (annot annots)
5404 (set-extent-endpoints annot (point) (point)))))
5405 (setq start (point))
5406 (if (search-backward "\n\n" nil t)
5407 (progn
5408 (goto-char start)
5409 (unless (or displayed-p (eolp))
5410 ;; Add extra newline.
5411 (insert (propertize (buffer-substring (1- start) start)
5412 'gnus-undeletable t))))
5413 ;; We're in the article header.
5414 (delete-char -1)
5415 (dolist (ovl (gnus-overlays-in btn (point)))
5416 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5417 (gnus-overlay-put ovl 'face nil))
5418 (save-restriction
5419 (message-narrow-to-field)
5420 (let ((gnus-treatment-function-alist
5421 '((gnus-treat-highlight-headers
5422 gnus-article-highlight-headers))))
5423 (gnus-treat-article 'head)))))
5424 (when (markerp b)
5425 (setq b (prog1 (marker-position b)
5426 (set-marker b nil))))
5427 (goto-char b))))
5429 (defun gnus-mime-set-charset-parameters (handle charset)
5430 "Set CHARSET to parameters in HANDLE.
5431 CHARSET may either be a string or a symbol."
5432 (unless (stringp charset)
5433 (setq charset (symbol-name charset)))
5434 (if (stringp (car handle))
5435 (dolist (h (cdr handle))
5436 (gnus-mime-set-charset-parameters h charset))
5437 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5438 "message/external-body")
5439 (progn
5440 (unless (mm-handle-cache handle)
5441 (mm-extern-cache-contents handle))
5442 (mm-handle-cache handle))
5443 handle)))
5444 (param (assq 'charset (cdr type))))
5445 (if param
5446 (setcdr param charset)
5447 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5449 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5450 "Insert the MIME part under point into the current buffer using the
5451 specified charset."
5452 (interactive (list nil current-prefix-arg))
5453 (gnus-article-check-buffer)
5454 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5455 (fun (get-text-property (point) 'gnus-callback))
5456 (gnus-newsgroup-ignored-charsets 'gnus-all)
5457 charset form preferred parts)
5458 (when handle
5459 (when (prog1
5460 (and fun
5461 (setq charset
5462 (or (cdr (assq
5464 gnus-summary-show-article-charset-alist))
5465 (mm-read-coding-system "Charset: "))))
5466 (if (mm-handle-undisplayer handle)
5467 (mm-remove-part handle)))
5468 (gnus-mime-set-charset-parameters handle charset)
5469 (when (and (consp (setq form (cdr-safe fun)))
5470 (setq form (ignore-errors
5471 (assq 'gnus-mime-display-alternative form)))
5472 (setq preferred (caddr form))
5473 (progn
5474 (when (eq (car preferred) 'quote)
5475 (setq preferred (cadr preferred)))
5476 (not (equal preferred
5477 (get-text-property (point) 'gnus-data))))
5478 (setq parts (get-text-property (point) 'gnus-part))
5479 (setq parts (cdr (assq parts
5480 gnus-article-mime-handle-alist)))
5481 (equal (mm-handle-media-type parts) "multipart/alternative")
5482 (setq parts (reverse (cdr parts))))
5483 (setcar (cddr form)
5484 (list 'quote (or (cadr (member preferred parts))
5485 (car parts)))))
5486 (funcall fun handle)))))
5488 (defun gnus-mime-view-part-externally (&optional handle)
5489 "View the MIME part under point with an external viewer."
5490 (interactive)
5491 (gnus-article-check-buffer)
5492 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5493 (mm-inlined-types nil)
5494 (mail-parse-charset gnus-newsgroup-charset)
5495 (mail-parse-ignored-charsets
5496 (with-current-buffer gnus-summary-buffer
5497 gnus-newsgroup-ignored-charsets))
5498 (type (mm-handle-media-type handle))
5499 (method (mailcap-mime-info type))
5500 (mm-enable-external t))
5501 (if (not (stringp method))
5502 (gnus-mime-view-part-as-type
5503 nil (lambda (type) (stringp (mailcap-mime-info type))))
5504 (when handle
5505 (mm-display-part handle nil t)))))
5507 (defun gnus-mime-view-part-internally (&optional handle)
5508 "View the MIME part under point with an internal viewer.
5509 If no internal viewer is available, use an external viewer."
5510 (interactive)
5511 (gnus-article-check-buffer)
5512 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5513 (mm-inlined-types '(".*"))
5514 (mm-inline-large-images t)
5515 (mail-parse-charset gnus-newsgroup-charset)
5516 (mail-parse-ignored-charsets
5517 (with-current-buffer gnus-summary-buffer
5518 gnus-newsgroup-ignored-charsets))
5519 (inhibit-read-only t))
5520 (if (not (mm-inlinable-p handle))
5521 (gnus-mime-view-part-as-type
5522 nil (lambda (type) (mm-inlinable-p handle type)))
5523 (when handle
5524 (gnus-bind-safe-url-regexp
5525 (mm-display-part handle nil t))))))
5527 (defun gnus-mime-action-on-part (&optional action)
5528 "Do something with the MIME attachment at \(point\)."
5529 (interactive
5530 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5531 (gnus-article-check-buffer)
5532 (let ((action-pair (assoc action gnus-mime-action-alist)))
5533 (if action-pair
5534 (funcall (cdr action-pair)))))
5536 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5537 "Call FUNCTION on MIME part N.
5538 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5539 If INTERACTIVE, call FUNCTION interactively."
5540 (let (window frame)
5541 ;; Check whether the article is displayed.
5542 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5543 (setq window (get-buffer-window gnus-article-buffer t))
5544 (frame-visible-p (setq frame (window-frame window))))
5545 (error "No article is displayed"))
5546 (with-current-buffer gnus-article-buffer
5547 ;; Check whether the article displays the right contents.
5548 (unless (with-current-buffer gnus-summary-buffer
5549 (eq gnus-current-article (gnus-summary-article-number)))
5550 (error "You should select the right article first"))
5551 (if n
5552 (setq n (prefix-numeric-value n))
5553 (let ((pt (point)))
5554 (setq n (or (get-text-property pt 'gnus-part)
5555 (and (not (bobp))
5556 (get-text-property (1- pt) 'gnus-part))
5557 (get-text-property (prog2
5558 (forward-line 1)
5559 (point)
5560 (goto-char pt))
5561 'gnus-part)
5562 (get-text-property
5563 (or (and (setq pt (previous-single-property-change
5564 pt 'gnus-part))
5565 (1- pt))
5566 (next-single-property-change (point) 'gnus-part)
5567 (point))
5568 'gnus-part)
5569 1))))
5570 ;; Check whether the specified part exists.
5571 (when (> n (length gnus-article-mime-handle-alist))
5572 (error "No such part")))
5573 (unless
5574 (progn
5575 ;; To select the window is needed so that the cursor
5576 ;; might be visible on the MIME button.
5577 (select-window (prog1
5578 window
5579 (setq window (selected-window))
5580 ;; Article may be displayed in the other frame.
5581 (gnus-select-frame-set-input-focus
5582 (prog1
5583 frame
5584 (setq frame (selected-frame))))))
5585 (when (gnus-article-goto-part n)
5586 ;; We point the cursor and the arrow at the MIME button
5587 ;; when the `function' prompt the user for something.
5588 (unless (and (pos-visible-in-window-p)
5589 (> (count-lines (point) (window-end))
5590 (/ (1- (window-height)) 3)))
5591 (recenter (/ (1- (window-height)) 3)))
5592 (let ((cursor-in-non-selected-windows t)
5593 (overlay-arrow-string "=>")
5594 (overlay-arrow-position (point-marker)))
5595 (unwind-protect
5596 (cond
5597 ((and no-handle interactive)
5598 (call-interactively function))
5599 (no-handle
5600 (funcall function))
5601 (interactive
5602 (call-interactively
5603 function (get-text-property (point) 'gnus-data)))
5605 (funcall function
5606 (get-text-property (point) 'gnus-data))))
5607 (set-marker overlay-arrow-position nil)
5608 (unless gnus-auto-select-part
5609 (gnus-select-frame-set-input-focus frame)
5610 (select-window window))))
5612 (if gnus-inhibit-mime-unbuttonizing
5613 ;; This is the default though the program shouldn't reach here.
5614 (error "No such part")
5615 ;; The part which doesn't have the MIME button is selected.
5616 ;; So, we display all the buttons and redo it.
5617 (let ((gnus-inhibit-mime-unbuttonizing t))
5618 (gnus-summary-show-article)
5619 (gnus-article-part-wrapper n function no-handle))))))
5621 (defun gnus-article-pipe-part (n)
5622 "Pipe MIME part N, which is the numerical prefix."
5623 (interactive "P")
5624 (gnus-article-part-wrapper n 'mm-pipe-part))
5626 (defun gnus-article-save-part (n)
5627 "Save MIME part N, which is the numerical prefix."
5628 (interactive "P")
5629 (gnus-article-part-wrapper n 'mm-save-part))
5631 (defun gnus-article-interactively-view-part (n)
5632 "View MIME part N interactively, which is the numerical prefix."
5633 (interactive "P")
5634 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5636 (defun gnus-article-copy-part (n)
5637 "Copy MIME part N, which is the numerical prefix."
5638 (interactive "P")
5639 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5641 (defun gnus-article-view-part-as-charset (n)
5642 "View MIME part N using a specified charset.
5643 N is the numerical prefix."
5644 (interactive "P")
5645 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5647 (defun gnus-article-view-part-externally (n)
5648 "View MIME part N externally, which is the numerical prefix."
5649 (interactive "P")
5650 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5652 (defun gnus-article-inline-part (n)
5653 "Inline MIME part N, which is the numerical prefix."
5654 (interactive "P")
5655 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5657 (defun gnus-article-save-part-and-strip (n)
5658 "Save MIME part N and replace it with an external body.
5659 N is the numerical prefix."
5660 (interactive "P")
5661 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5663 (defun gnus-article-replace-part (n)
5664 "Replace MIME part N with an external body.
5665 N is the numerical prefix."
5666 (interactive "P")
5667 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5669 (defun gnus-article-delete-part (n)
5670 "Delete MIME part N and add some information about the removed part.
5671 N is the numerical prefix."
5672 (interactive "P")
5673 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5675 (defun gnus-article-view-part-as-type (n)
5676 "Choose a MIME media type, and view part N as such.
5677 N is the numerical prefix."
5678 (interactive "P")
5679 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5681 (defun gnus-article-mime-match-handle-first (condition)
5682 (if condition
5683 (let (n)
5684 (dolist (ihandle gnus-article-mime-handle-alist)
5685 (if (and (cond
5686 ((functionp condition)
5687 (funcall condition (cdr ihandle)))
5688 ((eq condition 'undisplayed)
5689 (not (or (mm-handle-undisplayer (cdr ihandle))
5690 (equal (mm-handle-media-type (cdr ihandle))
5691 "multipart/alternative"))))
5692 ((eq condition 'undisplayed-alternative)
5693 (not (mm-handle-undisplayer (cdr ihandle))))
5694 (t t))
5695 (gnus-article-goto-part (car ihandle))
5696 (or (not n) (< (car ihandle) n)))
5697 (setq n (car ihandle))))
5698 (or n 1))
5701 (defun gnus-article-view-part (&optional n)
5702 "View MIME part N, which is the numerical prefix.
5703 If the part is already shown, hide the part. If N is nil, view
5704 all parts."
5705 (interactive "P")
5706 (with-current-buffer gnus-article-buffer
5707 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5708 gnus-article-mime-match-handle-function)))
5709 (when (> n (length gnus-article-mime-handle-alist))
5710 (error "No such part"))
5711 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5712 (when (gnus-article-goto-part n)
5713 (if (equal (car handle) "multipart/alternative")
5714 (progn
5715 (beginning-of-line) ;; Make it toggle subparts
5716 (gnus-article-press-button))
5717 (when (eq (gnus-mm-display-part handle) 'internal)
5718 (gnus-set-window-start)))))))
5720 (defsubst gnus-article-mime-total-parts ()
5721 (if (bufferp (car gnus-article-mime-handles))
5722 1 ;; single part
5723 (1- (length gnus-article-mime-handles))))
5725 (defun gnus-mm-display-part (handle)
5726 "Display HANDLE and fix MIME button."
5727 (let ((id (get-text-property (point) 'gnus-part))
5728 (point (point))
5729 (inhibit-read-only t)
5730 (window (selected-window))
5731 (mail-parse-charset gnus-newsgroup-charset)
5732 (mail-parse-ignored-charsets
5733 (if (gnus-buffer-live-p gnus-summary-buffer)
5734 (with-current-buffer gnus-summary-buffer
5735 gnus-newsgroup-ignored-charsets)
5736 nil))
5737 start retval)
5738 (unwind-protect
5739 (progn
5740 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5741 (when win
5742 (select-window win)
5743 (goto-char point)))
5744 (setq start (next-single-property-change point 'gnus-data
5745 nil (point-max))
5746 point (previous-single-property-change start 'gnus-data))
5747 (if (mm-handle-displayed-p handle)
5748 ;; This will remove the part.
5749 (setq point (copy-marker point)
5750 retval (mm-display-part handle))
5751 (let ((part (or (and (mm-inlinable-p handle)
5752 (mm-inlined-p handle)
5754 (with-temp-buffer
5755 (gnus-bind-safe-url-regexp
5756 (setq retval (mm-display-part handle)))
5757 (unless (zerop (buffer-size))
5758 (buffer-string))))))
5759 (goto-char start)
5760 (unless (bolp)
5761 ;; This is a header button.
5762 (forward-line 1))
5763 (cond ((stringp part)
5764 (save-restriction
5765 (narrow-to-region (point)
5766 (progn
5767 (insert part)
5768 (unless (bolp) (insert "\n"))
5769 (point)))
5770 (gnus-treat-article nil id
5771 (gnus-article-mime-total-parts)
5772 (mm-handle-media-type handle))
5773 (mm-handle-set-undisplayer
5774 handle
5775 `(lambda ()
5776 (let ((inhibit-read-only t))
5777 (delete-region ,(copy-marker (point-min) t)
5778 ,(point-max-marker)))))))
5779 (part
5780 (mm-display-inline handle))))))
5781 (when (markerp point)
5782 (setq point (prog1 (marker-position point)
5783 (set-marker point nil))))
5784 (goto-char point)
5785 ;; Toggle the button appearance between `[button]...' and `[button]'.
5786 (let ((displayed-p (mm-handle-displayed-p handle)))
5787 (gnus-insert-mime-button handle id (list displayed-p))
5788 (if (featurep 'emacs)
5789 (delete-region
5790 (point)
5791 (next-single-property-change (point) 'gnus-data nil (point-max)))
5792 (let* ((end (next-single-property-change (point) 'gnus-data))
5793 (annots (annotations-at (or end (point-max)))))
5794 (delete-region (point)
5795 (if end
5796 (if annots (1+ end) end)
5797 (point-max)))
5798 (dolist (annot annots)
5799 (set-extent-endpoints annot (point) (point)))))
5800 (setq start (point))
5801 (if (search-backward "\n\n" nil t)
5802 (progn
5803 (goto-char start)
5804 (unless (or displayed-p (eolp))
5805 ;; Add extra newline.
5806 (insert (propertize (buffer-substring (1- start) start)
5807 'gnus-undeletable t))))
5808 ;; We're in the article header.
5809 (delete-char -1)
5810 (dolist (ovl (gnus-overlays-in point (point)))
5811 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5812 (gnus-overlay-put ovl 'face nil))
5813 (save-restriction
5814 (message-narrow-to-field)
5815 (let ((gnus-treatment-function-alist
5816 '((gnus-treat-highlight-headers
5817 gnus-article-highlight-headers))))
5818 (gnus-treat-article 'head)))))
5819 (goto-char point)
5820 (if (window-live-p window)
5821 (select-window window)))
5822 retval))
5824 (defun gnus-article-goto-part (n)
5825 "Go to MIME part N."
5826 (when gnus-break-pages
5827 (widen))
5828 (article-goto-body)
5829 (prog1
5830 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5831 ;; There may be header buttons.
5832 (text-property-any (point-min) (point) 'gnus-part n)))
5833 part handle end next handles)
5834 (when start
5835 (goto-char start)
5836 (if (setq handle (get-text-property start 'gnus-data))
5837 start
5838 ;; Go to the displayed subpart, assuming this is
5839 ;; multipart/alternative.
5840 (setq part start
5841 end (point-at-eol))
5842 (while (and (not handle)
5843 part
5844 (< part end)
5845 (setq next (text-property-not-all part end
5846 'gnus-data nil)))
5847 (setq part next
5848 handle (get-text-property part 'gnus-data))
5849 (push (cons handle part) handles)
5850 (unless (mm-handle-displayed-p handle)
5851 (setq handle nil
5852 part (text-property-any part end 'gnus-data nil))))
5853 (unless handle
5854 ;; No subpart is displayed, so we find preferred one.
5855 (setq part
5856 (cdr (assq (mm-preferred-alternative
5857 (nreverse (mapcar 'car handles)))
5858 handles))))
5859 (if part
5860 (goto-char (1+ part))
5861 start))))
5862 (when gnus-break-pages
5863 (gnus-narrow-to-page))))
5865 (defun gnus-insert-mime-button (handle id &optional displayed)
5866 (let ((gnus-tmp-name
5867 (or (mm-handle-filename handle)
5868 (mail-content-type-get (mm-handle-type handle) 'url)
5869 ""))
5870 (gnus-tmp-id id)
5871 (gnus-tmp-type (mm-handle-media-type handle))
5872 (gnus-tmp-description (or (mm-handle-description handle) ""))
5873 (gnus-tmp-dots
5874 (if (if displayed (car displayed)
5875 (mm-handle-displayed-p handle))
5876 "" "..."))
5877 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5878 (buffer-size)))
5879 gnus-tmp-type-long b e)
5880 (when (string-match ".*/" gnus-tmp-name)
5881 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5882 (setq gnus-tmp-type-long (concat gnus-tmp-type
5883 (and (not (equal gnus-tmp-name ""))
5884 (concat "; " gnus-tmp-name))))
5885 (unless (equal gnus-tmp-description "")
5886 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5887 (setq b (point))
5888 (gnus-eval-format
5889 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5890 `(keymap ,gnus-mime-button-map
5891 gnus-callback gnus-mm-display-part
5892 gnus-part ,gnus-tmp-id
5893 article-type annotation
5894 gnus-data ,handle
5895 rear-nonsticky t))
5896 (setq e (if (bolp)
5897 ;; Exclude a newline.
5898 (1- (point))
5899 (point)))
5900 (when gnus-article-button-face
5901 (gnus-overlay-put (gnus-make-overlay b e nil t)
5902 'face gnus-article-button-face))
5903 (widget-convert-button
5904 'link b e
5905 :mime-handle handle
5906 :action 'gnus-widget-press-button
5907 :button-keymap gnus-mime-button-map
5908 :help-echo
5909 (lambda (widget)
5910 ;; Needed to properly clear the message due to a bug in
5911 ;; wid-edit (XEmacs only).
5912 (if (boundp 'help-echo-owns-message)
5913 (setq help-echo-owns-message t))
5914 (format
5915 "%S: %s the MIME part; %S: more options"
5916 (aref gnus-mouse-2 0)
5917 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5918 "hide" "show")
5919 (aref gnus-down-mouse-3 0))))))
5921 (defun gnus-widget-press-button (elems _el)
5922 (goto-char (widget-get elems :from))
5923 (gnus-article-press-button))
5925 (defvar gnus-displaying-mime nil)
5927 (defun gnus-display-mime (&optional ihandles)
5928 "Display the MIME parts."
5929 (save-excursion
5930 (save-selected-window
5931 (let ((window (get-buffer-window gnus-article-buffer))
5932 (point (point)))
5933 (when window
5934 (select-window window)
5935 ;; We have to do this since selecting the window
5936 ;; may change the point. So we set the window point.
5937 (set-window-point window point)))
5938 (let ((handles ihandles)
5939 (inhibit-read-only t))
5940 (cond (handles)
5941 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5942 (when gnus-article-emulate-mime
5943 (mm-uu-dissect-text-parts handles)))
5944 (gnus-article-emulate-mime
5945 (setq handles (mm-uu-dissect))))
5946 (when (and (not ihandles)
5947 (not gnus-displaying-mime))
5948 ;; Top-level call; we clean up.
5949 (when gnus-article-mime-handles
5950 (mm-destroy-parts gnus-article-mime-handles)
5951 (setq gnus-article-mime-handle-alist nil));; A trick.
5952 (setq gnus-article-mime-handles handles)
5953 ;; We allow users to glean info from the handles.
5954 (when gnus-article-mime-part-function
5955 (gnus-mime-part-function handles)))
5956 (if (and handles
5957 (or (not (stringp (car handles)))
5958 (cdr handles)))
5959 (progn
5960 (when (and (not ihandles)
5961 (not gnus-displaying-mime))
5962 ;; Clean up for mime parts.
5963 (article-goto-body)
5964 (delete-region (point) (point-max)))
5965 (let ((gnus-displaying-mime t))
5966 (gnus-mime-display-part handles)))
5967 (save-restriction
5968 (article-goto-body)
5969 (narrow-to-region (point) (point-max))
5970 (gnus-treat-article nil 1 1 "text/plain")
5971 (widen)))
5972 (unless ihandles
5973 ;; Highlight the headers.
5974 (save-excursion
5975 (save-restriction
5976 (article-goto-body)
5977 (narrow-to-region (point-min) (point))
5978 (gnus-article-save-original-date
5979 (gnus-treat-article 'head)))))))
5980 ;; Cope with broken MIME messages.
5981 (goto-char (point-max))
5982 (unless (bolp)
5983 (insert "\n"))))
5985 (defcustom gnus-mime-display-multipart-as-mixed nil
5986 "Display \"multipart\" parts as \"multipart/mixed\".
5988 If t, it overrides nil values of
5989 `gnus-mime-display-multipart-alternative-as-mixed' and
5990 `gnus-mime-display-multipart-related-as-mixed'."
5991 :group 'gnus-article-mime
5992 :type 'boolean)
5994 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5995 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5996 :version "22.1"
5997 :group 'gnus-article-mime
5998 :type 'boolean)
6000 (defcustom gnus-mime-display-multipart-related-as-mixed nil
6001 "Display \"multipart/related\" parts as \"multipart/mixed\".
6003 If displaying \"text/html\" is discouraged \(see
6004 `mm-discouraged-alternatives'\) images or other material inside a
6005 \"multipart/related\" part might be overlooked when this variable is nil."
6006 :version "22.1"
6007 :group 'gnus-article-mime
6008 :type 'boolean)
6010 (defcustom gnus-mime-display-attachment-buttons-in-header t
6011 "Add attachment buttons in the end of the header of an article.
6012 Since MIME attachments tend to be put at the end of an article, we may
6013 overlook them if there is a huge body. This option offers you a copy
6014 of all non-inlinable MIME parts as buttons shown in front of an article.
6015 If nil, don't show those extra buttons."
6016 :version "25.1"
6017 :group 'gnus-article-mime
6018 :type 'boolean)
6020 (defun gnus-mime-display-part (handle)
6021 (cond
6022 ;; Maybe a broken MIME message.
6023 ((null handle))
6024 ;; Single part.
6025 ((not (stringp (car handle)))
6026 (gnus-mime-display-single handle))
6027 ;; User-defined multipart
6028 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6029 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6030 handle))
6031 ;; multipart/alternative
6032 ((and (equal (car handle) "multipart/alternative")
6033 (not (or gnus-mime-display-multipart-as-mixed
6034 gnus-mime-display-multipart-alternative-as-mixed)))
6035 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6036 (push (cons id handle) gnus-article-mime-handle-alist)
6037 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6038 ;; multipart/related
6039 ((and (equal (car handle) "multipart/related")
6040 (not (or gnus-mime-display-multipart-as-mixed
6041 gnus-mime-display-multipart-related-as-mixed)))
6042 (gnus-mime-display-part (cadr handle)))
6043 ((equal (car handle) "multipart/signed")
6044 (gnus-add-wash-type 'signed)
6045 (gnus-mime-display-security handle))
6046 ((equal (car handle) "multipart/encrypted")
6047 (gnus-add-wash-type 'encrypted)
6048 (gnus-mime-display-security handle))
6049 ;; Other multiparts are handled like multipart/mixed.
6051 (gnus-mime-display-mixed (cdr handle)))))
6053 (defun gnus-mime-part-function (handles)
6054 (if (stringp (car handles))
6055 (mapcar 'gnus-mime-part-function (cdr handles))
6056 (funcall gnus-article-mime-part-function handles)))
6058 (defun gnus-mime-display-mixed (handles)
6059 (mapcar 'gnus-mime-display-part handles))
6061 (defun gnus-mime-display-single (handle)
6062 (let ((type (mm-handle-media-type handle))
6063 (ignored gnus-ignored-mime-types)
6064 (not-attachment t)
6065 display text)
6066 (catch 'ignored
6067 (progn
6068 (while ignored
6069 (when (string-match (pop ignored) type)
6070 (throw 'ignored nil)))
6071 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6072 (with-current-buffer gnus-summary-buffer
6073 gnus-inhibit-images)
6074 gnus-inhibit-images)
6075 (string-match "\\`image/" type)))
6076 (setq not-attachment
6077 (and (not (mm-inline-override-p handle))
6078 (or (not (mm-handle-disposition handle))
6079 (equal (car (mm-handle-disposition handle))
6080 "inline")
6081 (mm-attachment-override-p handle))))
6082 (mm-automatic-display-p handle)
6083 (or (and
6084 (mm-inlinable-p handle)
6085 (mm-inlined-p handle))
6086 (mm-automatic-external-display-p type)))
6087 (setq display t)
6088 (when (equal (mm-handle-media-supertype handle) "text")
6089 (setq text t)))
6090 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6091 beg)
6092 (unless id
6093 (setq id (1+ (length gnus-article-mime-handle-alist)))
6094 (push (cons id handle) gnus-article-mime-handle-alist))
6095 (when (and display
6096 (equal (mm-handle-media-supertype handle) "message"))
6097 (insert-char
6099 (cond ((not (bolp)) 2)
6100 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6101 (t 1))))
6102 (when (or (not display)
6103 (not (gnus-unbuttonized-mime-type-p type))
6104 (eq id gnus-mime-buttonized-part-id))
6105 (gnus-insert-mime-button
6106 handle id (list (or display (and not-attachment text)))))
6107 (setq beg (point))
6108 (cond
6109 (display
6110 (let ((mail-parse-charset gnus-newsgroup-charset)
6111 (mail-parse-ignored-charsets
6112 (save-excursion (condition-case ()
6113 (set-buffer gnus-summary-buffer)
6114 (error))
6115 gnus-newsgroup-ignored-charsets)))
6116 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6117 ((and text not-attachment)
6118 (mm-display-inline handle)))
6119 (goto-char (point-max))
6120 (if (string-match "\\`image/" type)
6121 (gnus-article-insert-newline)
6122 (if (prog1
6123 (= (skip-chars-backward "\n") -1)
6124 (unless (eobp) (forward-char 1)))
6125 (gnus-article-insert-newline)
6126 (put-text-property (point) (point-max) 'gnus-undeletable t))
6127 (goto-char (point-max)))
6128 ;; Do highlighting.
6129 (save-excursion
6130 (save-restriction
6131 (narrow-to-region beg (point))
6132 (if (eq handle gnus-article-mime-handles)
6133 ;; The format=flowed case.
6134 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6135 ;; Don't count signature parts that are never displayed.
6136 ;; The part number should be re-calculated supposing this
6137 ;; might be a message/rfc822 part.
6138 (let (handles)
6139 (dolist (part gnus-article-mime-handles)
6140 (unless (or (stringp part)
6141 (equal (car (mm-handle-type part))
6142 "application/pgp-signature"))
6143 (push part handles)))
6144 (gnus-treat-article
6145 nil (length (memq handle handles)) (length handles)
6146 (mm-handle-media-type handle)))))))))))
6148 (defun gnus-unbuttonized-mime-type-p (type)
6149 "Say whether TYPE is to be unbuttonized."
6150 (unless gnus-inhibit-mime-unbuttonizing
6151 (when (catch 'found
6152 (let ((types gnus-unbuttonized-mime-types))
6153 (while types
6154 (when (string-match (pop types) type)
6155 (throw 'found t)))))
6156 (not (catch 'found
6157 (let ((types gnus-buttonized-mime-types))
6158 (while types
6159 (when (string-match (pop types) type)
6160 (throw 'found t)))))))))
6162 (defun gnus-article-insert-newline ()
6163 "Insert a newline, but mark it as undeletable."
6164 (gnus-put-text-property
6165 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6167 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6168 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6169 (ihandles handles)
6170 (point (point))
6171 handle (inhibit-read-only t) from begend not-pref)
6172 (save-window-excursion
6173 (save-restriction
6174 (when ibegend
6175 (narrow-to-region (car ibegend)
6176 (or (cdr ibegend)
6177 (progn
6178 (goto-char (car ibegend))
6179 (forward-line 2)
6180 (point))))
6181 (delete-region (point-min) (point-max))
6182 (mm-remove-parts handles))
6183 (setq begend (list (point-marker)))
6184 ;; Do the toggle.
6185 (unless (setq not-pref (cadr (member preferred ihandles)))
6186 (setq not-pref (car ihandles)))
6187 (when (or ibegend
6188 (not preferred)
6189 (not (gnus-unbuttonized-mime-type-p
6190 "multipart/alternative")))
6191 (gnus-add-text-properties
6192 (setq from (point))
6193 (progn
6194 (insert (format "%d. " id))
6195 (point))
6196 `(gnus-callback
6197 (lambda (handles)
6198 (unless ,(not ibegend)
6199 (setq gnus-article-mime-handle-alist
6200 ',gnus-article-mime-handle-alist))
6201 (gnus-mime-display-alternative
6202 ',ihandles ',not-pref ',begend ,id))
6203 keymap ,gnus-mime-button-map
6204 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6205 face ,gnus-article-button-face
6206 gnus-part ,id
6207 article-type multipart
6208 rear-nonsticky t))
6209 (widget-convert-button 'link from (point)
6210 :action 'gnus-widget-press-button
6211 :button-keymap gnus-widget-button-keymap)
6212 ;; Do the handles
6213 (while (setq handle (pop handles))
6214 (gnus-add-text-properties
6215 (setq from (point))
6216 (progn
6217 (insert (format "(%c) %-18s"
6218 (if (equal handle preferred) ?* ? )
6219 (mm-handle-media-type handle)))
6220 (point))
6221 `(gnus-callback
6222 (lambda (handles)
6223 (unless ,(not ibegend)
6224 (setq gnus-article-mime-handle-alist
6225 ',gnus-article-mime-handle-alist))
6226 (gnus-mime-display-alternative
6227 ',ihandles ',handle ',begend ,id))
6228 keymap ,gnus-mime-button-map
6229 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6230 face ,gnus-article-button-face
6231 gnus-part ,id
6232 gnus-data ,handle
6233 rear-nonsticky t))
6234 (widget-convert-button 'link from (point)
6235 :action 'gnus-widget-press-button
6236 :button-keymap gnus-widget-button-keymap)
6237 (insert " "))
6238 (insert "\n\n"))
6239 (when preferred
6240 (if (stringp (car preferred))
6241 (gnus-display-mime preferred)
6242 (let ((mail-parse-charset gnus-newsgroup-charset)
6243 (mail-parse-ignored-charsets
6244 (with-current-buffer gnus-summary-buffer
6245 gnus-newsgroup-ignored-charsets)))
6246 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6247 ;; Do highlighting.
6248 (save-excursion
6249 (save-restriction
6250 (narrow-to-region (car begend) (point-max))
6251 (gnus-treat-article
6252 nil (length gnus-article-mime-handle-alist)
6253 (gnus-article-mime-total-parts)
6254 (mm-handle-media-type preferred))))))
6255 (goto-char (point-max))
6256 (setcdr begend (point-marker)))))
6257 (when ibegend
6258 (goto-char point)))
6259 ;; Redraw attachment buttons in the header.
6260 (when gnus-mime-display-attachment-buttons-in-header
6261 (gnus-mime-buttonize-attachments-in-header)))
6263 (defconst gnus-article-wash-status-strings
6264 (let ((alist '((cite "c" "Possible hidden citation text"
6265 " " "All citation text visible")
6266 (headers "h" "Hidden headers"
6267 " " "All headers visible.")
6268 (pgp "p" "Encrypted or signed message status hidden"
6269 " " "No hidden encryption nor digital signature status")
6270 (signature "s" "Signature has been hidden"
6271 " " "Signature is visible")
6272 (overstrike "o" "Overstrike (^H) characters applied"
6273 " " "No overstrike characters applied")
6274 (emphasis "e" "/*_Emphasis_*/ characters applied"
6275 " " "No /*_emphasis_*/ characters applied")))
6276 result)
6277 (dolist (entry alist result)
6278 (let ((key (nth 0 entry))
6279 (on (copy-sequence (nth 1 entry)))
6280 (on-help (nth 2 entry))
6281 (off (copy-sequence (nth 3 entry)))
6282 (off-help (nth 4 entry)))
6283 (put-text-property 0 1 'help-echo on-help on)
6284 (put-text-property 0 1 'help-echo off-help off)
6285 (push (list key on off) result))))
6286 "Alist of strings describing wash status in the mode line.
6287 Each entry has the form (KEY ON OF), where the KEY is a symbol
6288 representing the particular washing function, ON is the string to use
6289 in the article mode line when the washing function is active, and OFF
6290 is the string to use when it is inactive.")
6292 (defun gnus-article-wash-status-entry (key value)
6293 (let ((entry (assoc key gnus-article-wash-status-strings)))
6294 (if value (nth 1 entry) (nth 2 entry))))
6296 (defun gnus-article-wash-status ()
6297 "Return a string which display status of article washing."
6298 (with-current-buffer gnus-article-buffer
6299 (let ((cite (memq 'cite gnus-article-wash-types))
6300 (headers (memq 'headers gnus-article-wash-types))
6301 (boring (memq 'boring-headers gnus-article-wash-types))
6302 (pgp (memq 'pgp gnus-article-wash-types))
6303 (pem (memq 'pem gnus-article-wash-types))
6304 (signed (memq 'signed gnus-article-wash-types))
6305 (encrypted (memq 'encrypted gnus-article-wash-types))
6306 (signature (memq 'signature gnus-article-wash-types))
6307 (overstrike (memq 'overstrike gnus-article-wash-types))
6308 (emphasis (memq 'emphasis gnus-article-wash-types)))
6309 (concat
6310 (gnus-article-wash-status-entry 'cite cite)
6311 (gnus-article-wash-status-entry 'headers (or headers boring))
6312 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6313 (gnus-article-wash-status-entry 'signature signature)
6314 (gnus-article-wash-status-entry 'overstrike overstrike)
6315 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6317 (defun gnus-add-wash-type (type)
6318 "Add a washing of TYPE to the current status."
6319 (add-to-list 'gnus-article-wash-types type))
6321 (defun gnus-delete-wash-type (type)
6322 "Add a washing of TYPE to the current status."
6323 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6325 (defun gnus-add-image (category image)
6326 "Add IMAGE of CATEGORY to the list of displayed images."
6327 (let ((entry (assq category gnus-article-image-alist)))
6328 (unless entry
6329 (setq entry (list category))
6330 (push entry gnus-article-image-alist))
6331 (nconc entry (list image))))
6333 (defun gnus-delete-images (category)
6334 "Delete all images in CATEGORY."
6335 (let ((entry (assq category gnus-article-image-alist)))
6336 (dolist (image (cdr entry))
6337 (gnus-remove-image image category))
6338 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6339 (gnus-delete-wash-type category)))
6341 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6343 (defun gnus-article-maybe-hide-headers ()
6344 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6345 Provided for backwards compatibility."
6346 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6347 (not (with-current-buffer gnus-summary-buffer
6348 gnus-have-all-headers)))
6349 (not gnus-inhibit-hiding))
6350 (gnus-article-hide-headers)))
6352 (declare-function shr-put-image "shr" (data alt &optional flags))
6354 (defun gnus-shr-put-image (data alt &optional flags)
6355 "Put image DATA with a string ALT. Enable image to be deleted."
6356 (let ((image (if flags
6357 (shr-put-image data (propertize (or alt "*")
6358 'gnus-image-category 'shr)
6359 flags)
6360 ;; Old `shr-put-image' doesn't take the optional `flags'
6361 ;; argument.
6362 (shr-put-image data (propertize (or alt "*")
6363 'gnus-image-category 'shr)))))
6364 (when image
6365 (gnus-add-image 'shr image))))
6367 (defun gnus-article-mime-handles (&optional alist id all)
6368 (if alist
6369 (let ((i 1) newid flat)
6370 (dolist (handle alist flat)
6371 (setq newid (append id (list i))
6372 i (1+ i))
6373 (if (stringp (car handle))
6374 (setq flat (nconc flat (gnus-article-mime-handles
6375 (cdr handle) newid all)))
6376 (delq (rassq handle all) all)
6377 (setq flat (nconc flat (list (cons newid handle)))))))
6378 (let ((flat (list nil)))
6379 ;; Assume that elements of `gnus-article-mime-handle-alist'
6380 ;; are in the decreasing order, but unnumbered subsidiaries
6381 ;; in each element are in the increasing order.
6382 (dolist (handle (reverse gnus-article-mime-handle-alist))
6383 (if (stringp (cadr handle))
6384 (setq flat (nconc flat (gnus-article-mime-handles
6385 (cddr handle) (list (car handle)) flat)))
6386 (delq (rassq (cdr handle) flat) flat)
6387 (setq flat (nconc flat (list (cons (list (car handle))
6388 (cdr handle)))))))
6389 (setq flat (cdr flat))
6390 (mapc (lambda (handle)
6391 (if (cdar handle)
6392 ;; This is a hidden (i.e. unnumbered) handle.
6393 (progn
6394 (setcar handle
6395 (1+ (caar gnus-article-mime-handle-alist)))
6396 (push handle gnus-article-mime-handle-alist))
6397 (setcar handle (caar handle))))
6398 flat)
6399 flat)))
6401 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6402 "Show attachments as buttons in the end of the header of an article.
6403 This function toggles the display when called interactively. Note that
6404 buttons to be added to the header are only the ones that aren't inlined
6405 in the body. Use `gnus-header-face-alist' to highlight buttons."
6406 (interactive (list t))
6407 (gnus-with-article-buffer
6408 (let ((case-fold-search t) buttons handle type st)
6409 (save-excursion
6410 (save-restriction
6411 (widen)
6412 (article-narrow-to-head)
6413 ;; Header buttons exist?
6414 (while (and (not buttons)
6415 (re-search-forward "^attachments?:[\n ]+" nil t))
6416 (when (get-char-property (match-end 0)
6417 'gnus-button-attachment-extra)
6418 (setq buttons (match-beginning 0))))
6419 (widen)
6420 (when buttons
6421 ;; Delete header buttons.
6422 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6423 (match-beginning 0)
6424 (point-max))))
6425 (unless (and interactive buttons)
6426 ;; Find buttons.
6427 (setq buttons nil)
6428 (dolist (button (gnus-article-mime-handles))
6429 (setq handle (cdr button)
6430 type (mm-handle-media-type handle))
6431 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6432 (with-current-buffer gnus-summary-buffer
6433 gnus-inhibit-images)
6434 gnus-inhibit-images)
6435 (string-match "\\`image/" type))
6436 (mm-inline-override-p handle)
6437 (and (mm-handle-disposition handle)
6438 (not (equal (car (mm-handle-disposition handle))
6439 "inline"))
6440 (not (mm-attachment-override-p handle)))
6441 (not (mm-automatic-display-p handle))
6442 (not (or (and (mm-inlinable-p handle)
6443 (mm-inlined-p handle))
6444 (mm-automatic-external-display-p type))))
6445 (push button buttons)))
6446 (when buttons
6447 ;; Add header buttons.
6448 (article-goto-body)
6449 (forward-line -1)
6450 (narrow-to-region (point) (point))
6451 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6452 (dolist (button (nreverse buttons))
6453 (setq st (point))
6454 (insert " ")
6455 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6456 (gnus-insert-mime-button handle (car button))
6457 (skip-chars-backward "\t\n ")
6458 (delete-region (point) (point-max))
6459 (when (> (current-column) (window-width))
6460 (goto-char st)
6461 (insert "\n")
6462 (end-of-line)))
6463 (insert "\n")
6464 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6465 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6466 (gnus-overlay-put ovl 'face nil))
6467 (let ((gnus-treatment-function-alist
6468 '((gnus-treat-highlight-headers
6469 gnus-article-highlight-headers))))
6470 (gnus-treat-article 'head)))))))))
6472 ;;; Article savers.
6474 (defun gnus-output-to-file (file-name)
6475 "Append the current article to a file named FILE-NAME.
6476 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6477 text and used as the value of the coding cookie which is added to the
6478 top of a file. Otherwise, this function saves a raw article without
6479 the coding cookie."
6480 (let* ((artbuf (current-buffer))
6481 (file-name-coding-system nnmail-pathname-coding-system)
6482 (coding gnus-article-save-coding-system)
6483 (coding-system-for-read (if coding
6484 nil ;; Rely on the coding cookie.
6485 mm-text-coding-system))
6486 (coding-system-for-write (or coding
6487 mm-text-coding-system-for-write
6488 mm-text-coding-system))
6489 (exists (file-exists-p file-name)))
6490 (with-temp-buffer
6491 (when exists
6492 (insert-file-contents file-name)
6493 (goto-char (point-min))
6494 ;; Remove the existing coding cookie.
6495 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6496 (delete-region (match-beginning 0) (match-end 0))))
6497 (goto-char (point-max))
6498 (insert-buffer-substring artbuf)
6499 ;; Append newline at end of the buffer as separator, and then
6500 ;; save it to file.
6501 (goto-char (point-max))
6502 (insert "\n")
6503 (when coding
6504 ;; If the coding system is not suitable to encode the text,
6505 ;; ask a user for a proper one.
6506 (when (fboundp 'select-safe-coding-system)
6507 (setq coding (coding-system-base
6508 (save-window-excursion
6509 (select-safe-coding-system (point-min) (point-max)
6510 coding))))
6511 (setq coding-system-for-write
6512 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6513 coding)))
6514 (goto-char (point-min))
6515 ;; Add the coding cookie.
6516 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6517 coding-system-for-write)))
6518 (if exists
6519 (progn
6520 (write-region (point-min) (point-max) file-name nil 'no-message)
6521 (message "Appended to %s" file-name))
6522 (write-region (point-min) (point-max) file-name))))
6525 (defun gnus-narrow-to-page (&optional arg)
6526 "Narrow the article buffer to a page.
6527 If given a numerical ARG, move forward ARG pages."
6528 (interactive "P")
6529 (setq arg (if arg (prefix-numeric-value arg) 0))
6530 (with-current-buffer gnus-article-buffer
6531 (widen)
6532 ;; Remove any old next/prev buttons.
6533 (when (gnus-visual-p 'page-marker)
6534 (let ((inhibit-read-only t))
6535 (gnus-remove-text-with-property 'gnus-prev)
6536 (gnus-remove-text-with-property 'gnus-next)))
6537 (let (st nd pt)
6538 (when (save-excursion
6539 (cond ((< arg 0)
6540 (if (re-search-backward page-delimiter nil 'move (abs arg))
6541 (prog1
6542 (setq nd (match-beginning 0)
6543 pt nd)
6544 (when (re-search-backward page-delimiter nil t)
6545 (setq st (match-end 0))))
6546 (when (re-search-forward page-delimiter nil t)
6547 (setq nd (match-beginning 0)
6548 pt (point-min)))))
6549 ((> arg 0)
6550 (if (re-search-forward page-delimiter nil 'move arg)
6551 (prog1
6552 (setq st (match-end 0)
6553 pt st)
6554 (when (re-search-forward page-delimiter nil t)
6555 (setq nd (match-beginning 0))))
6556 (when (re-search-backward page-delimiter nil t)
6557 (setq st (match-end 0)
6558 pt (point-max)))))
6560 (when (re-search-backward page-delimiter nil t)
6561 (goto-char (setq st (match-end 0))))
6562 (when (re-search-forward page-delimiter nil t)
6563 (setq nd (match-beginning 0)))
6564 (or st nd))))
6565 (setq gnus-page-broken t)
6566 (when pt (goto-char pt))
6567 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6568 (when (gnus-visual-p 'page-marker)
6569 (save-excursion
6570 (when nd
6571 (goto-char nd)
6572 (gnus-insert-next-page-button))
6573 (when st
6574 (goto-char st)
6575 (gnus-insert-prev-page-button))))))))
6577 ;; Article mode commands
6579 (defun gnus-article-goto-next-page ()
6580 "Show the next page of the article."
6581 (interactive)
6582 (when (gnus-article-next-page)
6583 (goto-char (point-min))
6584 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6587 (defun gnus-article-goto-prev-page ()
6588 "Show the previous page of the article."
6589 (interactive)
6590 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6591 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6592 (gnus-article-prev-page nil)))
6594 ;; This is cleaner but currently breaks `gnus-pick-mode':
6596 ;; (defun gnus-article-goto-next-page ()
6597 ;; "Show the next page of the article."
6598 ;; (interactive)
6599 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6600 ;; (gnus-summary-next-page)))
6602 ;; (defun gnus-article-goto-prev-page ()
6603 ;; "Show the next page of the article."
6604 ;; (interactive)
6605 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6606 ;; (gnus-summary-prev-page)))
6608 (defun gnus-article-next-page (&optional lines)
6609 "Show the next page of the current article.
6610 If end of article, return non-nil. Otherwise return nil.
6611 Argument LINES specifies lines to be scrolled up."
6612 (interactive "p")
6613 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6614 (if (and (not (and gnus-article-over-scroll
6615 (> (count-lines (window-start) (point-max))
6616 (if (featurep 'xemacs)
6617 (or lines (1- (window-height)))
6618 (+ (or lines (1- (window-height))) scroll-margin)))))
6619 (save-excursion
6620 (end-of-line)
6621 (and (pos-visible-in-window-p) ;Not continuation line.
6622 (>= (point) (point-max)))))
6623 ;; Nothing in this page.
6624 (if (or (not gnus-page-broken)
6625 (save-excursion
6626 (save-restriction
6627 (widen)
6628 (forward-line)
6629 (eobp)))) ;Real end-of-buffer?
6630 (progn
6631 (when gnus-article-over-scroll
6632 (gnus-article-next-page-1 lines))
6633 t) ;Nothing more.
6634 (gnus-narrow-to-page 1) ;Go to next page.
6635 nil)
6636 ;; More in this page.
6637 (gnus-article-next-page-1 lines)
6638 nil))
6640 (defun gnus-article-beginning-of-window ()
6641 "Move point to the beginning of the window.
6642 In Emacs, the point is placed at the line number which `scroll-margin'
6643 specifies."
6644 (if (featurep 'xemacs)
6645 (move-to-window-line 0)
6646 ;; There is an obscure bug in Emacs that makes it impossible to
6647 ;; scroll past big pictures in the article buffer. Try to fix
6648 ;; this by adding a sanity check by counting the lines visible.
6649 (when (> (count-lines (window-start) (window-end)) 30)
6650 (move-to-window-line
6651 (min (max 0 scroll-margin)
6652 (max 1 (- (window-height)
6653 (if mode-line-format 1 0)
6654 (if header-line-format 1 0)
6655 2)))))))
6657 (defvar scroll-in-place)
6659 (defun gnus-article-next-page-1 (lines)
6660 (condition-case ()
6661 (let ((scroll-in-place nil)
6662 (auto-window-vscroll nil))
6663 (scroll-up lines))
6664 (end-of-buffer
6665 ;; Long lines may cause an end-of-buffer error.
6666 (goto-char (point-max))))
6667 (gnus-article-beginning-of-window))
6669 (defun gnus-article-prev-page (&optional lines)
6670 "Show previous page of current article.
6671 Argument LINES specifies lines to be scrolled down."
6672 (interactive "p")
6673 (move-to-window-line 0)
6674 (if (and gnus-page-broken
6675 (bobp)
6676 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6677 (progn
6678 (gnus-narrow-to-page -1) ;Go to previous page.
6679 (goto-char (point-max))
6680 (recenter (if gnus-article-over-scroll
6681 (if lines
6682 (max (if (featurep 'xemacs)
6683 lines
6684 (+ lines scroll-margin))
6686 (- (window-height) 2))
6687 -1)))
6688 (prog1
6689 (condition-case ()
6690 (let ((scroll-in-place nil))
6691 (scroll-down lines))
6692 (beginning-of-buffer
6693 (goto-char (point-min))))
6694 (gnus-article-beginning-of-window))))
6696 (defun gnus-article-only-boring-p ()
6697 "Decide whether there is only boring text remaining in the article.
6698 Something \"interesting\" is a word of at least two letters that does
6699 not have a face in `gnus-article-boring-faces'."
6700 (when (and gnus-article-skip-boring
6701 (boundp 'gnus-article-boring-faces)
6702 (symbol-value 'gnus-article-boring-faces))
6703 (save-excursion
6704 (let ((inhibit-point-motion-hooks t))
6705 (catch 'only-boring
6706 (while (re-search-forward "\\b\\w\\w" nil t)
6707 (forward-char -1)
6708 (when (not (gnus-intersection
6709 (gnus-faces-at (point))
6710 (symbol-value 'gnus-article-boring-faces)))
6711 (throw 'only-boring nil)))
6712 (throw 'only-boring t))))))
6714 (defun gnus-article-refer-article ()
6715 "Read article specified by message-id around point."
6716 (interactive)
6717 (save-excursion
6718 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6719 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6720 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6721 (let ((msg-id (concat "<" (match-string 0) ">")))
6722 (set-buffer gnus-summary-buffer)
6723 (gnus-summary-refer-article msg-id))
6724 (error "No references around point"))))
6726 (defun gnus-article-show-summary ()
6727 "Reconfigure windows to show summary buffer."
6728 (interactive)
6729 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6730 (error "There is no summary buffer for this article buffer")
6731 (gnus-article-set-globals)
6732 (gnus-configure-windows 'article)
6733 (gnus-summary-goto-subject gnus-current-article)
6734 (gnus-summary-position-point)))
6736 (defun gnus-article-describe-briefly ()
6737 "Describe article mode commands briefly."
6738 (interactive)
6739 (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")))
6741 (defun gnus-article-check-buffer ()
6742 "Beep if not in an article buffer."
6743 (unless (derived-mode-p 'gnus-article-mode)
6744 (error "Command invoked outside of a Gnus article buffer")))
6746 (defvar gnus-pick-mode)
6748 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6749 "Read a summary buffer key sequence and execute it from the article buffer."
6750 (interactive "P")
6751 (gnus-article-check-buffer)
6752 (let ((nosaves
6753 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6754 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6755 "=" "^" "\M-^" "|"))
6756 (nosave-but-article
6757 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6758 "An" "Ap" [?A (meta return)] [?A delete]))
6759 (nosave-in-article
6760 '("AS" "\C-d"))
6761 keys new-sum-point)
6762 (with-current-buffer gnus-article-current-summary
6763 (let (gnus-pick-mode)
6764 (setq unread-command-events (nconc unread-command-events
6765 (list (or key last-command-event)))
6766 keys (if (featurep 'xemacs)
6767 (events-to-keys (read-key-sequence nil t))
6768 (read-key-sequence nil t)))))
6770 (message "")
6772 (cond
6773 ((eq (aref keys (1- (length keys))) ?\C-h)
6774 (gnus-article-describe-bindings (substring keys 0 -1)))
6775 ((or (member keys nosaves)
6776 (member keys nosave-but-article)
6777 (member keys nosave-in-article))
6778 (let (func)
6779 (save-window-excursion
6780 (pop-to-buffer gnus-article-current-summary)
6781 ;; We disable the pick minor mode commands.
6782 (let (gnus-pick-mode)
6783 (setq func (key-binding keys t))))
6784 (if (or (not func)
6785 (numberp func))
6786 (ding)
6787 (unless (member keys nosave-in-article)
6788 (set-buffer gnus-article-current-summary))
6789 (when (and (symbolp func)
6790 (get func 'disabled))
6791 (error "Function %s disabled" func))
6792 (call-interactively func)
6793 (setq new-sum-point (point)))
6794 (when (member keys nosave-but-article)
6795 (pop-to-buffer gnus-article-buffer))))
6797 ;; These commands should restore window configuration.
6798 (let ((obuf (current-buffer))
6799 (owin (current-window-configuration))
6800 win func in-buffer selected new-sum-start new-sum-hscroll err)
6801 (cond (not-restore-window
6802 (pop-to-buffer gnus-article-current-summary)
6803 (setq win (selected-window)))
6804 ((setq win (get-buffer-window gnus-article-current-summary))
6805 (select-window win))
6807 (let ((summary-buffer gnus-article-current-summary))
6808 (gnus-configure-windows 'article)
6809 (unless (setq win (get-buffer-window summary-buffer 'visible))
6810 (let ((gnus-buffer-configuration
6811 '((article ((vertical 1.0
6812 (summary 0.25 point)
6813 (article 1.0)))))))
6814 (gnus-configure-windows 'article))
6815 (setq win (get-buffer-window summary-buffer 'visible)))
6816 (gnus-select-frame-set-input-focus (window-frame win))
6817 (select-window win))))
6818 (setq in-buffer (current-buffer))
6819 ;; We disable the pick minor mode commands.
6820 (setq func (let (gnus-pick-mode)
6821 (key-binding keys t)))
6822 (when (get func 'disabled)
6823 (error "Function %s disabled" func))
6824 (if (and func
6825 (functionp func)
6826 (condition-case code
6827 (progn
6828 (call-interactively func)
6830 (error
6831 (setq err code)
6832 nil)))
6833 (progn
6834 (when (eq win (selected-window))
6835 (setq new-sum-point (point)
6836 new-sum-start (window-start win)
6837 new-sum-hscroll (window-hscroll win)))
6838 (when (or (eq in-buffer (current-buffer))
6839 (when (eq obuf (current-buffer))
6840 (set-buffer in-buffer)
6842 (setq selected (ignore-errors (gnus-summary-select-article)))
6843 (set-buffer obuf)
6844 (unless not-restore-window
6845 (set-window-configuration owin))
6846 (when (and (eq selected 'old)
6847 new-sum-point)
6848 (set-window-start (get-buffer-window (current-buffer))
6850 (set-window-point (get-buffer-window (current-buffer))
6851 (if (article-goto-body)
6852 (1- (point))
6853 (point))))
6854 (when (and (not not-restore-window)
6855 new-sum-point
6856 (window-live-p win)
6857 (with-current-buffer (window-buffer win)
6858 (derived-mode-p 'gnus-summary-mode)))
6859 (set-window-point win new-sum-point)
6860 (set-window-start win new-sum-start)
6861 (set-window-hscroll win new-sum-hscroll))))
6862 (set-window-configuration owin)
6863 (if err
6864 (signal (car err) (cdr err))
6865 (ding))))))))
6867 (defun gnus-article-read-summary-send-keys ()
6868 (interactive)
6869 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6870 (gnus-article-read-summary-keys)))
6872 (defun gnus-article-describe-key (key)
6873 "Display documentation of the function invoked by KEY.
6874 KEY is a string or a vector."
6875 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6876 (read-key-sequence "Describe key: "))))
6877 (gnus-article-check-buffer)
6878 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6879 gnus-article-read-summary-send-keys))
6880 (with-current-buffer gnus-article-current-summary
6881 (setq unread-command-events
6882 (if (featurep 'xemacs)
6883 (append key nil)
6884 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6885 (list 'meta (- x 128))
6887 key)))
6888 (let ((cursor-in-echo-area t)
6889 gnus-pick-mode)
6890 (describe-key (read-key-sequence nil t))))
6891 (describe-key key)))
6893 (defun gnus-article-describe-key-briefly (key &optional insert)
6894 "Display documentation of the function invoked by KEY.
6895 KEY is a string or a vector."
6896 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6897 (read-key-sequence "Describe key: "))
6898 current-prefix-arg))
6899 (gnus-article-check-buffer)
6900 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6901 gnus-article-read-summary-send-keys))
6902 (with-current-buffer gnus-article-current-summary
6903 (setq unread-command-events
6904 (if (featurep 'xemacs)
6905 (append key nil)
6906 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6907 (list 'meta (- x 128))
6909 key)))
6910 (let ((cursor-in-echo-area t)
6911 gnus-pick-mode)
6912 (describe-key-briefly (read-key-sequence nil t) insert)))
6913 (describe-key-briefly key insert)))
6915 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6916 (defvar gnus-agent-summary-mode)
6917 (defvar gnus-draft-mode)
6918 (defvar help-xref-stack-item)
6919 (defvar help-xref-following)
6921 (defun gnus-article-describe-bindings (&optional prefix)
6922 "Show a list of all defined keys, and their definitions.
6923 The optional argument PREFIX, if non-nil, should be a key sequence;
6924 then we display only bindings that start with that prefix."
6925 (interactive)
6926 (gnus-article-check-buffer)
6927 (let ((keymap (copy-keymap gnus-article-mode-map))
6928 (map (copy-keymap gnus-article-send-map))
6929 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6930 parent agent draft)
6931 (define-key keymap "S" map)
6932 (define-key map [t] nil)
6933 (with-current-buffer gnus-article-current-summary
6934 (set-keymap-parent
6935 keymap
6936 (if (setq parent (keymap-parent gnus-article-mode-map))
6937 (prog1
6938 (setq parent (copy-keymap parent))
6939 (set-keymap-parent parent (current-local-map)))
6940 (current-local-map)))
6941 (set-keymap-parent map (key-binding "S"))
6942 (let (key def gnus-pick-mode)
6943 (while sumkeys
6944 (setq key (pop sumkeys))
6945 (cond ((and (vectorp key) (= (length key) 1)
6946 (consp (setq def (aref key 0)))
6947 (numberp (car def)) (numberp (cdr def)))
6948 (when (< (max (car def) (cdr def)) 128)
6949 (setq sumkeys
6950 (append (mapcar
6951 #'vector
6952 (nreverse (gnus-uncompress-range def)))
6953 sumkeys))))
6954 ((setq def (key-binding key))
6955 (unless (eq def 'undefined)
6956 (define-key keymap key def))))))
6957 (when (boundp 'gnus-agent-summary-mode)
6958 (setq agent gnus-agent-summary-mode))
6959 (when (boundp 'gnus-draft-mode)
6960 (setq draft gnus-draft-mode)))
6961 (with-temp-buffer
6962 (use-local-map keymap)
6963 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6964 (set (make-local-variable 'gnus-draft-mode) draft)
6965 (describe-bindings prefix))
6966 (let ((item `((lambda (prefix)
6967 (with-current-buffer ,(current-buffer)
6968 (gnus-article-describe-bindings prefix)))
6969 ,prefix)))
6970 ;; Loading `help-mode' here is necessary if `describe-bindings'
6971 ;; is replaced with something, e.g. `helm-descbinds'.
6972 (require 'help-mode)
6973 (with-current-buffer (let (help-xref-following) (help-buffer))
6974 (setq help-xref-stack-item item)))))
6976 (defun gnus-article-reply-with-original (&optional wide)
6977 "Start composing a reply mail to the current message.
6978 The text in the region will be yanked. If the region isn't active,
6979 the entire article will be yanked."
6980 (interactive)
6981 (let ((article (cdr gnus-article-current))
6982 contents)
6983 (if (not (gnus-region-active-p))
6984 (with-current-buffer gnus-summary-buffer
6985 (gnus-summary-reply (list (list article)) wide))
6986 (setq contents (buffer-substring (point) (mark t)))
6987 ;; Deactivate active regions.
6988 (when (and (boundp 'transient-mark-mode)
6989 transient-mark-mode)
6990 (setq mark-active nil))
6991 (with-current-buffer gnus-summary-buffer
6992 (gnus-summary-reply
6993 (list (list article contents)) wide)))))
6995 (defun gnus-article-wide-reply-with-original ()
6996 "Start composing a wide reply mail to the current message.
6997 The text in the region will be yanked. If the region isn't active,
6998 the entire article will be yanked."
6999 (interactive)
7000 (gnus-article-reply-with-original t))
7002 (defun gnus-article-followup-with-original ()
7003 "Compose a followup to the current article.
7004 The text in the region will be yanked. If the region isn't active,
7005 the entire article will be yanked."
7006 (interactive)
7007 (let ((article (cdr gnus-article-current))
7008 contents)
7009 (if (not (gnus-region-active-p))
7010 (with-current-buffer gnus-summary-buffer
7011 (gnus-summary-followup (list (list article))))
7012 (setq contents (buffer-substring (point) (mark t)))
7013 ;; Deactivate active regions.
7014 (when (and (boundp 'transient-mark-mode)
7015 transient-mark-mode)
7016 (setq mark-active nil))
7017 (with-current-buffer gnus-summary-buffer
7018 (gnus-summary-followup
7019 (list (list article contents)))))))
7021 (defun gnus-article-hide (&optional arg force)
7022 "Hide all the gruft in the current article.
7023 This means that signatures, cited text and (some) headers will be
7024 hidden.
7025 If given a prefix, show the hidden text instead."
7026 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7027 (gnus-article-hide-headers arg)
7028 (gnus-article-hide-list-identifiers arg)
7029 (gnus-article-hide-citation-maybe arg force)
7030 (gnus-article-hide-signature arg))
7032 (defun gnus-check-group-server ()
7033 ;; Make sure the connection to the server is alive.
7034 (unless (gnus-server-opened
7035 (gnus-find-method-for-group gnus-newsgroup-name))
7036 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7037 (gnus-request-group gnus-newsgroup-name t)))
7039 (eval-when-compile
7040 (autoload 'nneething-get-file-name "nneething"))
7042 (defun gnus-request-article-this-buffer (article group)
7043 "Get an article and insert it into this buffer."
7044 (let (do-update-line sparse-header)
7045 (prog1
7046 (save-excursion
7047 (erase-buffer)
7048 (gnus-kill-all-overlays)
7049 (setq group (or group gnus-newsgroup-name))
7051 ;; Using `gnus-request-article' directly will insert the article into
7052 ;; `nntp-server-buffer' - so we'll save some time by not having to
7053 ;; copy it from the server buffer into the article buffer.
7055 ;; We only request an article by message-id when we do not have the
7056 ;; headers for it, so we'll have to get those.
7057 (when (stringp article)
7058 (gnus-read-header article))
7060 ;; If the article number is negative, that means that this article
7061 ;; doesn't belong in this newsgroup (possibly), so we find its
7062 ;; message-id and request it by id instead of number.
7063 (when (and (numberp article)
7064 gnus-summary-buffer
7065 (get-buffer gnus-summary-buffer)
7066 (gnus-buffer-exists-p gnus-summary-buffer))
7067 (with-current-buffer gnus-summary-buffer
7068 (let ((header (gnus-summary-article-header article)))
7069 (when (< article 0)
7070 (cond
7071 ((memq article gnus-newsgroup-sparse)
7072 ;; This is a sparse gap article.
7073 (setq do-update-line article)
7074 (setq article (mail-header-id header))
7075 (setq sparse-header (gnus-read-header article))
7076 (setq gnus-newsgroup-sparse
7077 (delq article gnus-newsgroup-sparse)))
7078 ((vectorp header)
7079 ;; It's a real article.
7080 (setq article (mail-header-id header)))
7082 ;; It is an extracted pseudo-article.
7083 (setq article 'pseudo)
7084 (gnus-request-pseudo-article header))))
7086 (let ((method (gnus-find-method-for-group
7087 gnus-newsgroup-name)))
7088 (when (and (eq (car method) 'nneething)
7089 (vectorp header))
7090 (let ((dir (nneething-get-file-name
7091 (mail-header-id header))))
7092 (when (and (stringp dir)
7093 (file-directory-p dir))
7094 (setq article 'nneething)
7095 (gnus-group-enter-directory dir))))))))
7097 (cond
7098 ;; Refuse to select canceled articles.
7099 ((and (numberp article)
7100 gnus-summary-buffer
7101 (get-buffer gnus-summary-buffer)
7102 (gnus-buffer-exists-p gnus-summary-buffer)
7103 (eq (cdr (with-current-buffer gnus-summary-buffer
7104 (assq article gnus-newsgroup-reads)))
7105 gnus-canceled-mark))
7106 nil)
7107 ;; We first check `gnus-original-article-buffer'.
7108 ((and (get-buffer gnus-original-article-buffer)
7109 (numberp article)
7110 (with-current-buffer gnus-original-article-buffer
7111 (and (equal (car gnus-original-article) group)
7112 (eq (cdr gnus-original-article) article))))
7113 ;; `insert-buffer-substring' would incorrectly use the
7114 ;; equivalent of string-make-multibyte which amount to decoding
7115 ;; with locale-coding-system, causing failure of
7116 ;; subsequent decoding.
7117 (insert (mm-string-to-multibyte
7118 (with-current-buffer gnus-original-article-buffer
7119 (buffer-substring (point-min) (point-max)))))
7120 'article)
7121 ;; Check the backlog.
7122 ((and gnus-keep-backlog
7123 (gnus-backlog-request-article group article (current-buffer)))
7124 'article)
7125 ;; Check asynchronous pre-fetch.
7126 ((gnus-async-request-fetched-article group article (current-buffer))
7127 (gnus-async-prefetch-next group article gnus-summary-buffer)
7128 (when (and (numberp article) gnus-keep-backlog)
7129 (gnus-backlog-enter-article group article (current-buffer)))
7130 'article)
7131 ;; Check the cache.
7132 ((and gnus-use-cache
7133 (numberp article)
7134 (gnus-cache-request-article article group))
7135 'article)
7136 ;; Check the agent cache.
7137 ((gnus-agent-request-article article group)
7138 'article)
7139 ;; Get the article and put into the article buffer.
7140 ((or (stringp article)
7141 (numberp article))
7142 (let ((gnus-override-method gnus-override-method)
7143 (methods (and (stringp article)
7144 (with-current-buffer gnus-summary-buffer
7145 (gnus-refer-article-methods))))
7146 (backend (car (gnus-find-method-for-group
7147 gnus-newsgroup-name)))
7148 result
7149 (inhibit-read-only t))
7150 (when (and (null gnus-override-method)
7151 methods)
7152 (setq gnus-override-method (pop methods)))
7153 (while (not result)
7154 (erase-buffer)
7155 (gnus-kill-all-overlays)
7156 (let ((gnus-newsgroup-name group))
7157 (gnus-check-group-server))
7158 (cond
7159 ((gnus-request-article article group (current-buffer))
7160 (when (numberp article)
7161 (gnus-async-prefetch-next group article
7162 gnus-summary-buffer)
7163 (when gnus-keep-backlog
7164 (gnus-backlog-enter-article
7165 group article (current-buffer)))
7166 (when (and gnus-agent
7167 (gnus-agent-group-covered-p group))
7168 (gnus-agent-store-article article group)))
7169 (setq result 'article))
7170 (methods
7171 (setq gnus-override-method (pop methods)))
7172 ((not (string-match "^400 "
7173 (nnheader-get-report backend)))
7174 ;; If we get 400 server disconnect, reconnect and
7175 ;; retry; otherwise, assume the article has expired.
7176 (setq result 'done))))
7177 (and (eq result 'article) 'article)))
7178 ;; It was a pseudo.
7179 (t article)))
7181 ;; Associate this article with the current summary buffer.
7182 (setq gnus-article-current-summary gnus-summary-buffer)
7184 ;; Take the article from the original article buffer
7185 ;; and place it in the buffer it's supposed to be in.
7186 (when (and (get-buffer gnus-article-buffer)
7187 (equal (buffer-name (current-buffer))
7188 (buffer-name (get-buffer gnus-article-buffer))))
7189 (save-excursion
7190 (if (get-buffer gnus-original-article-buffer)
7191 (set-buffer gnus-original-article-buffer)
7192 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7193 (buffer-disable-undo)
7194 (setq major-mode 'gnus-original-article-mode)
7195 (setq buffer-read-only t))
7196 (let ((inhibit-read-only t))
7197 (erase-buffer)
7198 (insert-buffer-substring gnus-article-buffer))
7199 (setq gnus-original-article (cons group article)))
7201 ;; Decode charsets.
7202 (run-hooks 'gnus-article-decode-hook)
7203 ;; Mark article as decoded or not.
7204 (setq gnus-article-decoded-p gnus-article-decode-hook))
7206 ;; Update sparse articles.
7207 (when (and do-update-line
7208 (or (numberp article)
7209 (stringp article)))
7210 (let ((buf (current-buffer)))
7211 (set-buffer gnus-summary-buffer)
7212 (gnus-summary-update-article do-update-line sparse-header)
7213 (gnus-summary-goto-subject do-update-line nil t)
7214 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7215 (point))
7216 (set-buffer buf))))))
7218 (defun gnus-block-private-groups (group)
7219 "Allows images in newsgroups to be shown, blocks images in all
7220 other groups."
7221 (if (or (gnus-news-group-p group)
7222 (gnus-member-of-valid 'global group))
7223 ;; Block nothing in news groups.
7225 ;; Block everything anywhere else.
7226 "."))
7228 (defun gnus-blocked-images ()
7229 (if (functionp gnus-blocked-images)
7230 (funcall gnus-blocked-images gnus-newsgroup-name)
7231 gnus-blocked-images))
7234 ;;; Article editing
7237 (defcustom gnus-article-edit-mode-hook nil
7238 "Hook run in article edit mode buffers."
7239 :group 'gnus-article-various
7240 :type 'hook)
7242 (defvar gnus-article-edit-done-function nil)
7244 (defvar gnus-article-edit-mode-map nil)
7246 ;; Should we be using derived.el for this?
7247 (unless gnus-article-edit-mode-map
7248 (setq gnus-article-edit-mode-map (make-keymap))
7249 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7251 (gnus-define-keys gnus-article-edit-mode-map
7252 "\C-c?" describe-mode
7253 "\C-c\C-c" gnus-article-edit-done
7254 "\C-c\C-k" gnus-article-edit-exit
7255 "\C-c\C-f\C-t" message-goto-to
7256 "\C-c\C-f\C-o" message-goto-from
7257 "\C-c\C-f\C-b" message-goto-bcc
7258 ;;"\C-c\C-f\C-w" message-goto-fcc
7259 "\C-c\C-f\C-c" message-goto-cc
7260 "\C-c\C-f\C-s" message-goto-subject
7261 "\C-c\C-f\C-r" message-goto-reply-to
7262 "\C-c\C-f\C-n" message-goto-newsgroups
7263 "\C-c\C-f\C-d" message-goto-distribution
7264 "\C-c\C-f\C-f" message-goto-followup-to
7265 "\C-c\C-f\C-m" message-goto-mail-followup-to
7266 "\C-c\C-f\C-k" message-goto-keywords
7267 "\C-c\C-f\C-u" message-goto-summary
7268 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7269 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7270 "\C-c\C-b" message-goto-body
7271 "\C-c\C-i" message-goto-signature
7273 "\C-c\C-t" message-insert-to
7274 "\C-c\C-n" message-insert-newsgroups
7275 "\C-c\C-o" message-sort-headers
7276 "\C-c\C-e" message-elide-region
7277 "\C-c\C-v" message-delete-not-region
7278 "\C-c\C-z" message-kill-to-signature
7279 "\M-\r" message-newline-and-reformat
7280 "\C-c\C-a" mml-attach-file
7281 "\C-a" message-beginning-of-line
7282 "\t" message-tab
7283 "\M-;" comment-region)
7285 (gnus-define-keys (gnus-article-edit-wash-map
7286 "\C-c\C-w" gnus-article-edit-mode-map)
7287 "f" gnus-article-edit-full-stops))
7289 (easy-menu-define
7290 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7291 '("Field"
7292 ["Fetch To" message-insert-to t]
7293 ["Fetch Newsgroups" message-insert-newsgroups t]
7294 "----"
7295 ["To" message-goto-to t]
7296 ["From" message-goto-from t]
7297 ["Subject" message-goto-subject t]
7298 ["Cc" message-goto-cc t]
7299 ["Reply-To" message-goto-reply-to t]
7300 ["Summary" message-goto-summary t]
7301 ["Keywords" message-goto-keywords t]
7302 ["Newsgroups" message-goto-newsgroups t]
7303 ["Followup-To" message-goto-followup-to t]
7304 ["Mail-Followup-To" message-goto-mail-followup-to t]
7305 ["Distribution" message-goto-distribution t]
7306 ["Body" message-goto-body t]
7307 ["Signature" message-goto-signature t]))
7309 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7310 "Major mode for editing articles.
7311 This is an extended text-mode.
7313 \\{gnus-article-edit-mode-map}"
7314 (make-local-variable 'gnus-article-edit-done-function)
7315 (make-local-variable 'gnus-prev-winconf)
7316 (set (make-local-variable 'font-lock-defaults)
7317 '(message-font-lock-keywords t))
7318 (set (make-local-variable 'mail-header-separator) "")
7319 (set (make-local-variable 'gnus-article-edit-mode) t)
7320 (easy-menu-add message-mode-field-menu message-mode-map)
7321 (mml-mode)
7322 (setq buffer-read-only nil)
7323 (buffer-enable-undo)
7324 (widen))
7326 (defun gnus-article-edit (&optional force)
7327 "Edit the current article.
7328 This will have permanent effect only in mail groups.
7329 If FORCE is non-nil, allow editing of articles even in read-only
7330 groups."
7331 (interactive "P")
7332 (when (and (not force)
7333 (gnus-group-read-only-p))
7334 (error "The current newsgroup does not support article editing"))
7335 (gnus-article-date-original)
7336 (gnus-article-edit-article
7337 'ignore
7338 `(lambda (no-highlight)
7339 'ignore
7340 (gnus-summary-edit-article-done
7341 ,(or (mail-header-references gnus-current-headers) "")
7342 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7344 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7345 "Start editing the contents of the current article buffer."
7346 (let ((winconf (current-window-configuration)))
7347 (set-buffer gnus-article-buffer)
7348 (let ((message-auto-save-directory
7349 ;; Don't associate the article buffer with a draft file.
7350 nil))
7351 (gnus-article-edit-mode))
7352 (funcall start-func)
7353 (set-buffer-modified-p nil)
7354 (gnus-configure-windows 'edit-article)
7355 (setq gnus-article-edit-done-function exit-func)
7356 (setq gnus-prev-winconf winconf)
7357 (unless quiet
7358 (gnus-message 6 "C-c C-c to end edits"))))
7360 (defun gnus-article-edit-done (&optional arg)
7361 "Update the article edits and exit."
7362 (interactive "P")
7363 (let ((func gnus-article-edit-done-function)
7364 (buf (current-buffer))
7365 (start (window-start))
7366 (winconf gnus-prev-winconf))
7367 (widen) ;; Widen it in case that users narrowed the buffer.
7368 (funcall func arg)
7369 (set-buffer buf)
7370 ;; The cache and backlog have to be flushed somewhat.
7371 (when gnus-keep-backlog
7372 (gnus-backlog-remove-article
7373 (car gnus-article-current) (cdr gnus-article-current)))
7374 ;; Flush original article as well.
7375 (gnus-flush-original-article-buffer)
7376 (when gnus-use-cache
7377 (gnus-cache-update-article
7378 (car gnus-article-current) (cdr gnus-article-current)))
7379 ;; We remove all text props from the article buffer.
7380 (kill-all-local-variables)
7381 (set-text-properties (point-min) (point-max) nil)
7382 (gnus-article-mode)
7383 (set-window-configuration winconf)
7384 (set-buffer buf)
7385 (set-window-start (get-buffer-window buf) start)
7386 (set-window-point (get-buffer-window buf) (point)))
7387 (gnus-summary-show-article))
7389 (defun gnus-flush-original-article-buffer ()
7390 (when (get-buffer gnus-original-article-buffer)
7391 (with-current-buffer gnus-original-article-buffer
7392 (setq gnus-original-article nil))))
7394 (defun gnus-article-edit-exit ()
7395 "Exit the article editing without updating."
7396 (interactive)
7397 (when (or (not (buffer-modified-p))
7398 (yes-or-no-p "Article modified; kill anyway? "))
7399 (let ((curbuf (current-buffer))
7400 (p (point))
7401 (window-start (window-start)))
7402 (erase-buffer)
7403 (if (gnus-buffer-live-p gnus-original-article-buffer)
7404 (insert-buffer-substring gnus-original-article-buffer))
7405 (let ((winconf gnus-prev-winconf))
7406 (kill-all-local-variables)
7407 (gnus-article-mode)
7408 (set-window-configuration winconf)
7409 ;; Tippy-toe some to make sure that point remains where it was.
7410 (save-current-buffer
7411 (set-buffer curbuf)
7412 (set-window-start (get-buffer-window (current-buffer)) window-start)
7413 (goto-char p))))
7414 (gnus-summary-show-article)))
7416 (defun gnus-article-edit-full-stops ()
7417 "Interactively repair spacing at end of sentences."
7418 (interactive)
7419 (save-excursion
7420 (goto-char (point-min))
7421 (search-forward-regexp "^$" nil t)
7422 (let ((case-fold-search nil))
7423 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7426 ;;; Article highlights
7429 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7431 ;;; Internal Variables:
7433 (defcustom gnus-button-url-regexp
7434 (concat
7435 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7436 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7437 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7438 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7439 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7440 (punct "!?:;.,"))
7441 (concat
7442 "\\(?:"
7443 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7444 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7445 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7446 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7447 "\\|"
7448 "[" chars punct "]+" "[" chars "]"
7449 "\\)"))
7450 (concat ;; XEmacs 21.4 doesn't support POSIX.
7451 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7452 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7453 "\\)")
7454 "Regular expression that matches URLs."
7455 :version "24.4"
7456 :group 'gnus-article-buttons
7457 :type 'regexp)
7459 (defcustom gnus-button-valid-fqdn-regexp
7460 message-valid-fqdn-regexp
7461 "Regular expression that matches a valid FQDN."
7462 :version "22.1"
7463 :group 'gnus-article-buttons
7464 :type 'regexp)
7466 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7467 (defcustom gnus-button-valid-localpart-regexp
7468 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7469 "Regular expression that matches a localpart of mail addresses or MIDs."
7470 :version "22.1"
7471 :group 'gnus-article-buttons
7472 :type 'regexp)
7474 (defcustom gnus-button-man-handler 'manual-entry
7475 "Function to use for displaying man pages.
7476 The function must take at least one argument with a string naming the
7477 man page."
7478 :version "22.1"
7479 :type '(choice (function-item :tag "Man" manual-entry)
7480 (function-item :tag "Woman" woman)
7481 (function :tag "Other"))
7482 :group 'gnus-article-buttons)
7484 (defcustom gnus-button-mid-or-mail-regexp
7485 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7486 gnus-button-valid-fqdn-regexp
7487 ">?\\)\\b")
7488 "Regular expression that matches a message ID or a mail address."
7489 :version "22.1"
7490 :group 'gnus-article-buttons
7491 :type 'regexp)
7493 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7494 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7495 Strings like this can be either a message ID or a mail address. If it is one
7496 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7497 message ID or a mail address, respectively. If this variable is set to the
7498 symbol `ask', always query the user what do do. If it is a function, this
7499 function will be called with the string as its only argument. The function
7500 must return `mid', `mail', `invalid' or `ask'."
7501 :version "22.1"
7502 :group 'gnus-article-buttons
7503 :type '(choice (function-item :tag "Heuristic function"
7504 gnus-button-mid-or-mail-heuristic)
7505 (const ask)
7506 (const mid)
7507 (const mail)))
7509 (defcustom gnus-button-mid-or-mail-heuristic-alist
7510 '((-10.0 . ".+\\$.+@")
7511 (-10.0 . "#")
7512 (-10.0 . "\\*")
7513 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7514 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7515 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7516 (-1.0 . "^[^a-z]+@")
7518 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7519 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7520 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7521 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7523 (-2.0 . "^[0-9]")
7524 (-1.0 . "^[0-9][0-9]")
7526 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7527 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7528 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7529 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7531 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7532 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7533 ;; "[0-9]{8,}.*\@"
7534 (-3.0
7535 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7536 ;; "[0-9]{12,}.*\@"
7537 ;; compensation for TDMA dated mail addresses:
7538 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7540 (-20.0 . "\\.fsf@") ;; Gnus
7541 (-20.0 . "^slrn")
7542 (-20.0 . "^Pine")
7543 (-20.0 . "^alpine\\.")
7544 (-20.0 . "_-_") ;; Subject change in thread
7546 (-20.0 . "\\.ln@") ;; leafnode
7547 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7548 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7550 ;; (5.0 . "") ;; $local_part_len <= 7
7551 (10.0 . "^[^0-9]+@")
7552 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7553 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7554 (3.0 . "\@stud")
7556 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7558 (0.5 . "^[A-Z][a-z]")
7559 (0.5 . "^[A-Z][a-z][a-z]")
7560 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7561 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7562 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7564 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7565 address. The REGEXP is processed with `case-fold-search' set to nil."
7566 :version "22.1"
7567 :group 'gnus-article-buttons
7568 :type '(repeat (cons (number :tag "Rate")
7569 (regexp :tag "Regexp"))))
7571 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7572 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7573 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7574 address, `ask' if unsure and `invalid' if the string is invalid."
7575 (let ((case-fold-search nil)
7576 (list gnus-button-mid-or-mail-heuristic-alist)
7577 (result 0) rate regexp lpartlen elem)
7578 (setq lpartlen
7579 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7580 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7581 ;; Certain special cases...
7582 (when (string-match
7583 (concat
7584 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7585 "^[0-9]+\\.[0-9]+@compuserve\\|"
7586 "@public\\.gmane\\.org")
7587 mid-or-mail)
7588 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7589 (setq result 'mail))
7590 (when (string-match "@.*@\\| " mid-or-mail)
7591 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7592 (setq result 'invalid))
7593 ;; Nothing more to do, if result is not a number here...
7594 (when (numberp result)
7595 (while list
7596 (setq elem (car list)
7597 rate (car elem)
7598 regexp (cdr elem)
7599 list (cdr list))
7600 (when (string-match regexp mid-or-mail)
7601 (setq result (+ result rate))
7602 (gnus-message
7603 9 "`%s' matched `%s', rate `%s', result `%s'."
7604 mid-or-mail regexp rate result)))
7605 (when (<= lpartlen 7)
7606 (setq result (+ result 5.0))
7607 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7608 mid-or-mail result))
7609 (when (>= lpartlen 12)
7610 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7611 (cond
7612 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7613 ;; Long local part should contain realname if e-mail address,
7614 ;; too many digits: message-id.
7615 ;; $score -= 5.0 + 0.1 * $local_part_len;
7616 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7617 (setq result (+ result rate))
7618 (gnus-message
7619 9 "Many digits in `%s', rate `%s', result `%s'."
7620 mid-or-mail rate result))
7621 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7622 mid-or-mail)
7623 ;; Too few vowels [^aeiouy]{4,}.*\@
7624 (setq result (+ result -5.0))
7625 (gnus-message
7626 9 "Few vowels in `%s', rate `%s', result `%s'."
7627 mid-or-mail -5.0 result))
7629 (setq result (+ result 5.0))
7630 (gnus-message
7631 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7632 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7633 ;; Maybe we should make this a customizable alist: (condition . 'result)
7634 (cond
7635 ((symbolp result) result)
7636 ;; Now convert number into proper results:
7637 ((< result -10.0) 'mid)
7638 ((> result 10.0) 'mail)
7639 (t 'ask))))
7641 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7642 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7643 (url-mid (concat "news" ":" mid-or-mail))
7644 (url-mailto (concat "mailto" ":" mid-or-mail)))
7645 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7646 (when (fboundp pref)
7647 (setq guessed
7648 ;; get rid of surrounding angles...
7649 (funcall pref
7650 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7651 (if (or (eq 'mid guessed) (eq 'mail guessed))
7652 (setq pref guessed)
7653 (setq pref 'ask)))
7654 (if (eq pref 'ask)
7655 (save-window-excursion
7656 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7657 (setq pref 'mail)
7658 (setq pref 'mid))))
7659 (cond ((eq pref 'mid)
7660 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7661 (gnus-button-handle-news url-mid))
7662 ((eq pref 'mail)
7663 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7664 (gnus-url-mailto url-mailto))
7665 (t (gnus-message 3 "Invalid string.")))))
7667 (defun gnus-button-handle-custom (fun arg)
7668 "Call function FUN on argument ARG.
7669 Both FUN and ARG are supposed to be strings. ARG will be passed
7670 as a symbol to FUN."
7671 (funcall (intern fun)
7672 (if (string-match "^customize-apropos" fun)
7674 (intern arg))))
7676 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7678 (defun gnus-button-handle-describe-function (url)
7679 "Call `describe-function' when pushing the corresponding URL button."
7680 (describe-function
7681 (intern
7682 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7684 (defun gnus-button-handle-describe-variable (url)
7685 "Call `describe-variable' when pushing the corresponding URL button."
7686 (describe-variable
7687 (intern
7688 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7690 (defun gnus-button-handle-symbol (url)
7691 "Display help on variable or function.
7692 Calls `describe-variable' or `describe-function'."
7693 (let ((sym (intern url)))
7694 (cond
7695 ((fboundp sym) (describe-function sym))
7696 ((boundp sym) (describe-variable sym))
7697 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7699 (defun gnus-button-handle-describe-key (url)
7700 "Call `describe-key' when pushing the corresponding URL button."
7701 (let* ((key-string
7702 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7703 (keys (ignore-errors (eval `(kbd ,key-string)))))
7704 (if keys
7705 (describe-key keys)
7706 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7708 (defun gnus-button-handle-apropos (url)
7709 "Call `apropos' when pushing the corresponding URL button."
7710 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7712 (defun gnus-button-handle-apropos-command (url)
7713 "Call `apropos' when pushing the corresponding URL button."
7714 (apropos-command
7715 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7717 (defun gnus-button-handle-apropos-variable (url)
7718 "Call `apropos' when pushing the corresponding URL button."
7719 (funcall
7720 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7721 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7723 (defun gnus-button-handle-apropos-documentation (url)
7724 "Call `apropos' when pushing the corresponding URL button."
7725 (funcall
7726 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7727 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7729 (defun gnus-button-handle-library (url)
7730 "Call `locate-library' when pushing the corresponding URL button."
7731 (gnus-message 9 "url=`%s'" url)
7732 (let* ((lib (locate-library url))
7733 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7734 (if (not lib)
7735 (gnus-message 1 "Cannot locale library `%s'." url)
7736 (find-file-read-only file))))
7738 (defcustom gnus-button-man-level 5
7739 "*Integer that says how many man-related buttons Gnus will show.
7740 The higher the number, the more buttons will appear and the more false
7741 positives are possible. Note that you can set this variable local to
7742 specific groups. Setting it higher in Unix groups is probably a good idea.
7743 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7744 how to set variables in specific groups."
7745 :version "22.1"
7746 :group 'gnus-article-buttons
7747 :link '(custom-manual "(gnus)Group Parameters")
7748 :type 'integer)
7750 (defcustom gnus-button-emacs-level 5
7751 "*Integer that says how many emacs-related buttons Gnus will show.
7752 The higher the number, the more buttons will appear and the more false
7753 positives are possible. Note that you can set this variable local to
7754 specific groups. Setting it higher in Emacs or Gnus related groups is
7755 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7756 `gnus-parameters' on how to set variables in specific groups."
7757 :version "22.1"
7758 :group 'gnus-article-buttons
7759 :link '(custom-manual "(gnus)Group Parameters")
7760 :type 'integer)
7762 (defcustom gnus-button-message-level 5
7763 "*Integer that says how many buttons for news or mail messages will appear.
7764 The higher the number, the more buttons will appear and the more false
7765 positives are possible."
7766 ;; mail addresses, MIDs, URLs for news, ...
7767 :version "22.1"
7768 :group 'gnus-article-buttons
7769 :type 'integer)
7771 (defcustom gnus-button-browse-level 5
7772 "*Integer that says how many buttons for browsing will appear.
7773 The higher the number, the more buttons will appear and the more false
7774 positives are possible."
7775 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7776 :version "22.1"
7777 :group 'gnus-article-buttons
7778 :type 'integer)
7780 (defcustom gnus-button-alist
7781 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7782 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7783 ((concat "\\b\\(nntp\\|news\\):\\("
7784 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7785 0 t gnus-button-handle-news 2)
7786 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7787 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7788 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7789 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7790 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7791 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7792 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7793 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7794 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7795 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7796 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7797 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7798 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7799 ;; RFC 2368 (The mailto URL scheme)
7800 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7801 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7802 ("\\bmailto:\\([^ \n\t]+\\)"
7803 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7804 ;; Info Konqueror style <info:/foo/bar baz>.
7805 ;; Must come before " Gnus home-grown style".
7806 ("\\binfo://?\\([^'\">\n\t]+\\)"
7807 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7808 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7809 ("\\binfo://\\([^'\">\n\t ]+\\)"
7810 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7811 ;; Info GNOME style <info:foo#bar_baz>
7812 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7813 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7814 ;; Info KDE style <info:(foo)bar baz>
7815 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7816 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7817 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7818 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7819 ("\\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,]*\\)\\)?"
7820 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7821 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7822 ;; This is custom
7823 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7824 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7825 ;; Emacs help commands
7826 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7827 ;; regexp doesn't match arguments containing ` '.
7828 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7829 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7830 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7831 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7832 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7833 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7834 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7835 ;; The following entries may lead to many false positives so don't enable
7836 ;; them by default (use a high button level).
7837 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7838 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7839 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7840 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7841 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7842 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7843 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7844 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7845 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7846 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7847 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7848 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7849 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7850 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7851 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7852 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7853 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7854 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7855 ;; Unlike the other regexps we really have to require quoting
7856 ;; here to determine where it ends.
7857 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7858 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7859 ("<URL: *\\([^\n<>]*\\)>"
7860 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7861 ;; RFC 2396 (2.4.3., delims) ...
7862 ("\"URL: *\\([^\n\"]*\\)\""
7863 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7864 ;; Raw URLs.
7865 (gnus-button-url-regexp
7866 0 (>= gnus-button-browse-level 0) browse-url 0)
7867 ;; man pages
7868 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7869 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7870 gnus-button-handle-man 1)
7871 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7872 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7873 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7874 gnus-button-handle-man 1)
7875 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7876 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7877 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7878 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7879 ;; Recognizing patches to .el files. This is somewhat obscure,
7880 ;; but considering the percentage of Gnus users who hack Emacs
7881 ;; Lisp files...
7882 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7883 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7884 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7885 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7886 ;; MID or mail: To avoid too many false positives we don't try to catch
7887 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7888 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7889 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7890 ;; so that non-ambiguous entries (see above) match first.
7891 (gnus-button-mid-or-mail-regexp
7892 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7893 "*Alist of regexps matching buttons in article bodies.
7895 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7896 REGEXP: is the string (case insensitive) matching text around the button (can
7897 also be Lisp expression evaluating to a string),
7898 BUTTON: is the number of the regexp grouping actually matching the button,
7899 FORM: is a Lisp expression which must eval to true for the button to
7900 be added,
7901 CALLBACK: is the function to call when the user push this button, and each
7902 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7904 CALLBACK can also be a variable, in that case the value of that
7905 variable it the real callback function."
7906 :group 'gnus-article-buttons
7907 :type '(repeat (list (choice regexp variable sexp)
7908 (integer :tag "Button")
7909 (sexp :tag "Form")
7910 (function :tag "Callback")
7911 (repeat :tag "Par"
7912 :inline t
7913 (integer :tag "Regexp group")))))
7914 (put 'gnus-button-alist 'risky-local-variable t)
7916 (defcustom gnus-header-button-alist
7917 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7918 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7919 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7920 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7921 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7922 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7923 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7924 0 (>= gnus-button-browse-level 0) browse-url 0)
7925 ("^Subject:" gnus-button-url-regexp
7926 0 (>= gnus-button-browse-level 0) browse-url 0)
7927 ("^[^:]+:" gnus-button-url-regexp
7928 0 (>= gnus-button-browse-level 0) browse-url 0)
7929 ("^OpenPGP:.*url=" gnus-button-url-regexp
7930 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7931 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7932 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7933 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7934 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7935 "*Alist of headers and regexps to match buttons in article heads.
7937 This alist is very similar to `gnus-button-alist', except that each
7938 alist has an additional HEADER element first in each entry:
7940 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7942 HEADER is a regexp to match a header. For a fuller explanation, see
7943 `gnus-button-alist'."
7944 :group 'gnus-article-buttons
7945 :group 'gnus-article-headers
7946 :type '(repeat (list (regexp :tag "Header")
7947 (choice regexp variable)
7948 (integer :tag "Button")
7949 (sexp :tag "Form")
7950 (function :tag "Callback")
7951 (repeat :tag "Par"
7952 :inline t
7953 (integer :tag "Regexp group")))))
7954 (put 'gnus-header-button-alist 'risky-local-variable t)
7956 ;;; Commands:
7958 (defun gnus-article-push-button (event)
7959 "Check text under the mouse pointer for a callback function.
7960 If the text under the mouse pointer has a `gnus-callback' property,
7961 call it with the value of the `gnus-data' text property."
7962 (interactive "e")
7963 (set-buffer (window-buffer (posn-window (event-start event))))
7964 (let* ((pos (posn-point (event-start event)))
7965 (data (get-text-property pos 'gnus-data))
7966 (fun (get-text-property pos 'gnus-callback)))
7967 (goto-char pos)
7968 (when fun
7969 (funcall fun data))))
7971 (defun gnus-article-press-button ()
7972 "Check text at point for a callback function.
7973 If the text at point has a `gnus-callback' property,
7974 call it with the value of the `gnus-data' text property."
7975 (interactive)
7976 (let ((data (get-text-property (point) 'gnus-data))
7977 (fun (get-text-property (point) 'gnus-callback)))
7978 (when fun
7979 (funcall fun data))))
7981 (defun gnus-article-highlight (&optional force)
7982 "Highlight current article.
7983 This function calls `gnus-article-highlight-headers',
7984 `gnus-article-highlight-citation',
7985 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7986 do the highlighting. See the documentation for those functions."
7987 (interactive (list 'force))
7988 (gnus-article-highlight-headers)
7989 (gnus-article-highlight-citation force)
7990 (gnus-article-highlight-signature)
7991 (gnus-article-add-buttons)
7992 (gnus-article-add-buttons-to-head))
7994 (defun gnus-article-highlight-some (&optional _force)
7995 "Highlight current article.
7996 This function calls `gnus-article-highlight-headers',
7997 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7998 do the highlighting. See the documentation for those functions."
7999 (interactive (list 'force))
8000 (gnus-article-highlight-headers)
8001 (gnus-article-highlight-signature)
8002 (gnus-article-add-buttons))
8004 (defun gnus-article-highlight-headers ()
8005 "Highlight article headers as specified by `gnus-header-face-alist'."
8006 (interactive)
8007 (gnus-with-article-headers
8008 (let (regexp header-face field-face from hpoints fpoints)
8009 (dolist (entry gnus-header-face-alist)
8010 (goto-char (point-min))
8011 (setq regexp (concat "^\\("
8012 (if (string-equal "" (nth 0 entry))
8013 "[^\t ]"
8014 (nth 0 entry))
8015 "\\)")
8016 header-face (nth 1 entry)
8017 field-face (nth 2 entry))
8018 (while (and (re-search-forward regexp nil t)
8019 (not (eobp)))
8020 (beginning-of-line)
8021 (setq from (point))
8022 (unless (search-forward ":" nil t)
8023 (forward-char 1))
8024 (when (and header-face
8025 (not (memq (point) hpoints)))
8026 (push (point) hpoints)
8027 (gnus-put-text-property from (point) 'face header-face))
8028 (when (and field-face
8029 (not (memq (setq from (point)) fpoints)))
8030 (push from fpoints)
8031 (if (re-search-forward "^[^ \t]" nil t)
8032 (forward-char -2)
8033 (goto-char (point-max)))
8034 (gnus-put-text-property from (point) 'face field-face)))))))
8036 (defun gnus-article-highlight-signature ()
8037 "Highlight the signature in an article.
8038 It does this by highlighting everything after
8039 `gnus-signature-separator' using the face `gnus-signature'."
8040 (interactive)
8041 (gnus-with-article-buffer
8042 (let ((inhibit-point-motion-hooks t))
8043 (save-restriction
8044 (when (and gnus-signature-face
8045 (gnus-article-narrow-to-signature))
8046 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8047 'face gnus-signature-face)
8048 (widen)
8049 (gnus-article-search-signature)
8050 (let ((start (match-beginning 0))
8051 (end (set-marker (make-marker) (1+ (match-end 0)))))
8052 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8053 end)))))))
8055 (defun gnus-button-in-region-p (b e prop)
8056 "Say whether PROP exists in the region."
8057 (text-property-not-all b e prop nil))
8059 (defun gnus-article-add-buttons ()
8060 "Find external references in the article and make buttons of them.
8061 \"External references\" are things like Message-IDs and URLs, as
8062 specified by `gnus-button-alist'."
8063 (interactive)
8064 (gnus-with-article-buffer
8065 (let ((inhibit-point-motion-hooks t)
8066 (case-fold-search t)
8067 (alist gnus-button-alist)
8068 beg entry regexp)
8069 ;; We skip the headers.
8070 (article-goto-body)
8071 (setq beg (point))
8072 (while (setq entry (pop alist))
8073 (setq regexp (eval (car entry)))
8074 (goto-char beg)
8075 (while (re-search-forward regexp nil t)
8076 (let ((start (match-beginning (nth 1 entry)))
8077 (end (match-end (nth 1 entry)))
8078 (from (match-beginning 0)))
8079 (when (and (eval (nth 2 entry))
8080 (not (gnus-button-in-region-p
8081 start end 'gnus-callback)))
8082 ;; That optional form returned non-nil, so we add the
8083 ;; button.
8084 (setq from (set-marker (make-marker) from))
8085 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8086 (gnus-article-extend-url-button from start end))
8087 (gnus-article-add-button start end
8088 'gnus-button-push (list from entry))
8089 (gnus-put-text-property
8090 start end
8091 'gnus-string (buffer-substring-no-properties
8092 start end))))))))))
8094 (defun gnus-article-extend-url-button (beg start end)
8095 "Extend url button if url is folded into two or more lines.
8096 Return non-nil if button is extended. BEG is a marker that points to
8097 the beginning position of a text containing url. START and END are
8098 the endpoints of a url button before it is extended. The concatenated
8099 url is put as the `gnus-button-url' overlay property on the button."
8100 (let ((opoint (point))
8101 (points (list start end))
8102 url delim regexp)
8103 (prog1
8104 (when (and (progn
8105 (goto-char end)
8106 (not (looking-at "[\t ]*[\">]")))
8107 (progn
8108 (goto-char start)
8109 (string-match
8110 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8111 (buffer-substring (point-at-bol) start)))
8112 (progn
8113 (setq url (list (buffer-substring start end))
8114 delim (if (match-beginning 1) ">" "\""))
8115 (beginning-of-line)
8116 (setq regexp (concat
8117 (when (and (looking-at
8118 message-cite-prefix-regexp)
8119 (< (match-end 0) start))
8120 (regexp-quote (match-string 0)))
8122 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8123 delim "\\)"))
8124 (while (progn
8125 (forward-line 1)
8126 (and (looking-at regexp)
8127 (prog1
8128 (match-beginning 1)
8129 (push (or (match-string 2)
8130 (match-string 1))
8131 url)
8132 (push (setq end (or (match-end 2)
8133 (match-end 1)))
8134 points)
8135 (push (or (match-beginning 2)
8136 (match-beginning 1))
8137 points)))))
8138 (match-beginning 2)))
8139 (let (gnus-article-mouse-face widget-mouse-face)
8140 (while points
8141 (gnus-article-add-button (pop points) (pop points)
8142 'gnus-button-push
8143 (list beg (assq 'gnus-button-url-regexp
8144 gnus-button-alist)))))
8145 (let ((overlay (gnus-make-overlay start end)))
8146 (gnus-overlay-put overlay 'evaporate t)
8147 (gnus-overlay-put overlay 'gnus-button-url
8148 (list (mapconcat 'identity (nreverse url) "")))
8149 (when gnus-article-mouse-face
8150 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8152 (goto-char opoint))))
8154 ;; Add buttons to the head of an article.
8155 (defun gnus-article-add-buttons-to-head ()
8156 "Add buttons to the head of the article."
8157 (interactive)
8158 (gnus-with-article-headers
8159 (let (beg end)
8160 (dolist (entry gnus-header-button-alist)
8161 ;; Each alist entry.
8162 (goto-char (point-min))
8163 (while (re-search-forward (car entry) nil t)
8164 ;; Each header matching the entry.
8165 (setq beg (match-beginning 0))
8166 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8167 (match-beginning 0))
8168 (point-max)))
8169 (goto-char beg)
8170 (while (re-search-forward (eval (nth 1 entry)) end t)
8171 ;; Each match within a header.
8172 (let* ((entry (cdr entry))
8173 (start (match-beginning (nth 1 entry)))
8174 (end (match-end (nth 1 entry)))
8175 (form (nth 2 entry)))
8176 (goto-char (match-end 0))
8177 (when (eval form)
8178 (gnus-article-add-button
8179 start end (nth 3 entry)
8180 (buffer-substring (match-beginning (nth 4 entry))
8181 (match-end (nth 4 entry)))))))
8182 (goto-char end))))))
8184 ;;; External functions:
8186 (defun gnus-article-add-button (from to fun &optional data text)
8187 "Create a button between FROM and TO with callback FUN and data DATA."
8188 (when gnus-article-button-face
8189 (gnus-overlay-put (gnus-make-overlay from to nil t)
8190 'face gnus-article-button-face))
8191 (gnus-add-text-properties
8192 from to
8193 (nconc (and gnus-article-mouse-face
8194 (list gnus-mouse-face-prop gnus-article-mouse-face))
8195 (list 'gnus-callback fun)
8196 (and data (list 'gnus-data data))))
8197 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8198 :help-echo (or text "Follow the link")
8199 :keymap gnus-url-button-map
8200 :button-keymap gnus-widget-button-keymap))
8202 (defun gnus-article-copy-string ()
8203 "Copy the string in the button to the kill ring."
8204 (interactive)
8205 (gnus-article-check-buffer)
8206 (let ((data (get-text-property (point) 'gnus-string)))
8207 (when data
8208 (with-temp-buffer
8209 (insert data)
8210 (copy-region-as-kill (point-min) (point-max))
8211 (message "Copied %s" data)))))
8213 ;;; Internal functions:
8215 (defun gnus-article-set-globals ()
8216 (with-current-buffer gnus-summary-buffer
8217 (gnus-set-global-variables)))
8219 (defun gnus-signature-toggle (end)
8220 (gnus-with-article-buffer
8221 (let ((inhibit-point-motion-hooks t))
8222 (if (text-property-any end (point-max) 'article-type 'signature)
8223 (progn
8224 (gnus-delete-wash-type 'signature)
8225 (gnus-remove-text-properties-when
8226 'article-type 'signature end (point-max)
8227 (cons 'article-type (cons 'signature
8228 gnus-hidden-properties))))
8229 (gnus-add-wash-type 'signature)
8230 (gnus-add-text-properties-when
8231 'article-type nil end (point-max)
8232 (cons 'article-type (cons 'signature
8233 gnus-hidden-properties)))))
8234 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8235 (gnus-set-mode-line 'article))))
8237 (defun gnus-button-push (marker-and-entry)
8238 ;; Push button starting at MARKER.
8239 (save-excursion
8240 (let* ((marker (car marker-and-entry))
8241 (entry (cadr marker-and-entry))
8242 (regexp (car entry))
8243 (inhibit-point-motion-hooks t))
8244 (goto-char marker)
8245 ;; This is obviously true, or something bad is happening :)
8246 ;; But we need it to have the match-data
8247 (when (looking-at (or (if (symbolp regexp)
8248 (symbol-value regexp)
8249 regexp)))
8250 (let ((fun (nth 3 entry))
8251 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8252 (get-char-property marker 'gnus-button-url))
8253 (mapcar (lambda (group)
8254 (let ((string (match-string group)))
8255 (set-text-properties
8256 0 (length string) nil string)
8257 string))
8258 (nthcdr 4 entry)))))
8260 (cond
8261 ((fboundp fun)
8262 (apply fun args))
8263 ((and (boundp fun)
8264 (fboundp (symbol-value fun)))
8265 (apply (symbol-value fun) args))
8267 (gnus-message 1 "You must define `%S' to use this button"
8268 (cons fun args)))))))))
8270 (defun gnus-parse-news-url (url)
8271 (let (scheme server port group message-id articles)
8272 (with-temp-buffer
8273 (insert url)
8274 (goto-char (point-min))
8275 (when (looking-at "\\([A-Za-z]+\\):")
8276 (setq scheme (match-string 1))
8277 (goto-char (match-end 0)))
8278 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8279 (setq server (match-string 1))
8280 (setq port (if (stringp (match-string 3))
8281 (string-to-number (match-string 3))
8282 (match-string 3)))
8283 (goto-char (match-end 0)))
8285 (cond
8286 ((looking-at "\\(.*@.*\\)")
8287 (setq message-id (match-string 1)))
8288 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8289 (setq group (match-string 1)
8290 articles (split-string (match-string 2) "-")))
8291 ((looking-at "\\([^/]+\\)/?")
8292 (setq group (match-string 1)))
8294 (error "Unknown news URL syntax"))))
8295 (list scheme server port group message-id articles)))
8297 (defvar nntp-port-number)
8299 (defun gnus-button-handle-news (url)
8300 "Fetch a news URL."
8301 (destructuring-bind (_scheme server port group message-id _articles)
8302 (gnus-parse-news-url url)
8303 (cond
8304 (message-id
8305 (with-current-buffer gnus-summary-buffer
8306 (if server
8307 (let ((gnus-refer-article-method
8308 (nconc (list (list 'nntp server))
8309 gnus-refer-article-method))
8310 (nntp-port-number (or port "nntp")))
8311 (gnus-message 7 "Fetching %s with %s"
8312 message-id gnus-refer-article-method)
8313 (gnus-summary-refer-article message-id))
8314 (gnus-summary-refer-article message-id))))
8315 (group
8316 (gnus-button-fetch-group url)))))
8318 (defun gnus-button-patch (library line)
8319 "Visit an Emacs Lisp library LIBRARY on line LINE."
8320 (interactive)
8321 (let ((file (locate-library (file-name-nondirectory library))))
8322 (unless file
8323 (error "Couldn't find library %s" library))
8324 (find-file file)
8325 (goto-char (point-min))
8326 (forward-line (1- (string-to-number line)))))
8328 (defun gnus-button-handle-man (url)
8329 "Fetch a man page."
8330 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8331 (when (eq gnus-button-man-handler 'woman)
8332 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8333 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8334 (funcall gnus-button-man-handler url))
8336 (defun gnus-button-handle-info-url (url)
8337 "Fetch an info URL."
8338 (setq url (mm-subst-char-in-string ?+ ?\ url))
8339 (cond
8340 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8341 (gnus-info-find-node
8342 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8343 "Gnus")
8344 ")" (gnus-url-unhex-string (match-string 2 url)))))
8345 ((string-match "([^)\"]+)[^\"]+" url)
8346 (setq url
8347 (gnus-replace-in-string
8348 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8349 (gnus-info-find-node url))
8350 (t (error "Can't parse %s" url))))
8352 (defun gnus-button-handle-info-url-gnome (url)
8353 "Fetch GNOME style info URL."
8354 (setq url (mm-subst-char-in-string ?_ ?\ url))
8355 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8356 (gnus-info-find-node
8357 (concat "("
8358 (gnus-url-unhex-string
8359 (match-string 1 url))
8361 (or (gnus-url-unhex-string
8362 (match-string 2 url))
8363 "Top")))
8364 (error "Can't parse %s" url)))
8366 (defun gnus-button-handle-info-url-kde (url)
8367 "Fetch KDE style info URL."
8368 (gnus-info-find-node (gnus-url-unhex-string url)))
8370 ;; (info) will autoload info.el
8371 (declare-function Info-menu "info" (menu-item &optional fork))
8372 (declare-function Info-index-next "info" (num))
8374 (defun gnus-button-handle-info-keystrokes (url)
8375 "Call `info' when pushing the corresponding URL button."
8376 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8377 (let (node indx comma)
8378 (if (string-match
8379 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8380 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8381 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8382 "\\(?:[ \t\n,]*\\)\\)?")
8383 url)
8384 (setq node (match-string 2 url)
8385 indx (match-string 3 url))
8386 (error "Can't parse %s" url))
8387 (info)
8388 (Info-directory)
8389 (Info-menu node)
8390 (when (> (length indx) 0)
8391 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8392 "\\([ \t\n,]*\\)")
8393 indx)
8394 (setq comma (match-string 2 indx))
8395 (setq indx (match-string 1 indx))
8396 (Info-index indx)
8397 (when comma
8398 (dotimes (i (with-temp-buffer
8399 (insert comma)
8400 ;; Note: the XEmacs version of `how-many' takes
8401 ;; no optional argument.
8402 (goto-char (point-min))
8403 (how-many ",")))
8404 (Info-index-next 1)))
8405 nil)))
8407 (autoload 'pgg-snarf-keys-region "pgg")
8408 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8409 (declare-function pgg-display-output-buffer "pgg" (start end status))
8411 (defun gnus-button-openpgp (url)
8412 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8413 (with-temp-buffer
8414 (mm-url-insert-file-contents-external url)
8415 (pgg-snarf-keys-region (point-min) (point-max))
8416 (pgg-display-output-buffer nil nil nil)))
8418 (defun gnus-button-message-id (message-id)
8419 "Fetch MESSAGE-ID."
8420 (with-current-buffer gnus-summary-buffer
8421 (gnus-summary-refer-article message-id)))
8423 (defun gnus-button-fetch-group (address &rest _ignore)
8424 "Fetch GROUP specified by ADDRESS."
8425 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8426 address)
8427 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8428 ;; for nntp:// and news://
8429 (setq address (match-string 3 address)))
8430 (if (not (string-match "[:/]" address))
8431 ;; This is just a simple group url.
8432 (gnus-group-read-ephemeral-group address gnus-select-method)
8433 (if (not
8434 (string-match
8435 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8436 address))
8437 (error "Can't parse %s" address)
8438 (gnus-group-read-ephemeral-group
8439 (match-string 4 address)
8440 `(nntp ,(match-string 1 address)
8441 (nntp-address ,(match-string 1 address))
8442 (nntp-port-number ,(if (match-end 3)
8443 (match-string 3 address)
8444 "nntp")))
8445 nil nil nil
8446 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8448 (defun gnus-url-parse-query-string (query &optional downcase)
8449 (let (retval pairs cur key val)
8450 (setq pairs (split-string query "&"))
8451 (while pairs
8452 (setq cur (car pairs)
8453 pairs (cdr pairs))
8454 (if (not (string-match "=" cur))
8455 nil ; Grace
8456 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8457 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8458 (if downcase
8459 (setq key (downcase key)))
8460 (setq cur (assoc key retval))
8461 (if cur
8462 (setcdr cur (cons val (cdr cur)))
8463 (setq retval (cons (list key val) retval)))))
8464 retval))
8466 (defun gnus-url-mailto (url)
8467 ;; Send mail to someone
8468 (setq url (replace-regexp-in-string "\n" " " url))
8469 (when (string-match "mailto:/*\\(.*\\)" url)
8470 (setq url (substring url (match-beginning 1) nil)))
8471 (let* ((args (gnus-url-parse-query-string
8472 (if (string-match "^\\?" url)
8473 (substring url 1)
8474 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8475 (concat "to=" (match-string 1 url) "&"
8476 (match-string 2 url))
8477 (concat "to=" url)))))
8478 (subject (cdr-safe (assoc "subject" args)))
8479 func)
8480 (gnus-msg-mail)
8481 (while args
8482 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8483 (if (fboundp func)
8484 (funcall func)
8485 (message-position-on-field (caar args)))
8486 (insert (gnus-replace-in-string
8487 (mapconcat 'identity (reverse (cdar args)) ", ")
8488 "\r\n" "\n" t))
8489 (setq args (cdr args)))
8490 (if subject
8491 (message-goto-body)
8492 (message-goto-subject))))
8494 (defun gnus-button-embedded-url (address)
8495 "Activate ADDRESS with `browse-url'."
8496 (browse-url (gnus-strip-whitespace address)))
8498 ;;; Next/prev buttons in the article buffer.
8500 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8501 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8503 (defvar gnus-prev-page-map
8504 (let ((map (make-sparse-keymap)))
8505 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8506 (define-key map "\r" 'gnus-button-prev-page)
8507 map))
8509 (defvar gnus-next-page-map
8510 (let ((map (make-sparse-keymap)))
8511 (define-key map gnus-mouse-2 'gnus-button-next-page)
8512 (define-key map "\r" 'gnus-button-next-page)
8513 map))
8515 (defun gnus-insert-prev-page-button ()
8516 (let ((b (point)) e
8517 (inhibit-read-only t))
8518 (gnus-eval-format
8519 gnus-prev-page-line-format nil
8520 `(keymap ,gnus-prev-page-map
8521 gnus-prev t
8522 gnus-callback gnus-article-button-prev-page
8523 article-type annotation))
8524 (setq e (if (bolp)
8525 ;; Exclude a newline.
8526 (1- (point))
8527 (point)))
8528 (when gnus-article-button-face
8529 (gnus-overlay-put (gnus-make-overlay b e nil t)
8530 'face gnus-article-button-face))
8531 (widget-convert-button
8532 'link b e
8533 :action 'gnus-button-prev-page
8534 :button-keymap gnus-prev-page-map)))
8536 (defun gnus-button-next-page (&optional _args _more-args)
8537 "Go to the next page."
8538 (interactive)
8539 (let ((win (selected-window)))
8540 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8541 (gnus-article-next-page)
8542 (select-window win)))
8544 (defun gnus-button-prev-page (&optional _args _more-args)
8545 "Go to the prev page."
8546 (interactive)
8547 (let ((win (selected-window)))
8548 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8549 (gnus-article-prev-page)
8550 (select-window win)))
8552 (defun gnus-insert-next-page-button ()
8553 (let ((b (point)) e
8554 (inhibit-read-only t))
8555 (gnus-eval-format gnus-next-page-line-format nil
8556 `(keymap ,gnus-next-page-map
8557 gnus-next t
8558 gnus-callback gnus-article-button-next-page
8559 article-type annotation))
8560 (setq e (if (bolp)
8561 ;; Exclude a newline.
8562 (1- (point))
8563 (point)))
8564 (when gnus-article-button-face
8565 (gnus-overlay-put (gnus-make-overlay b e nil t)
8566 'face gnus-article-button-face))
8567 (widget-convert-button
8568 'link b e
8569 :action 'gnus-button-next-page
8570 :button-keymap gnus-next-page-map)))
8572 (defun gnus-article-button-next-page (_arg)
8573 "Go to the next page."
8574 (interactive "P")
8575 (let ((win (selected-window)))
8576 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8577 (gnus-article-next-page)
8578 (select-window win)))
8580 (defun gnus-article-button-prev-page (_arg)
8581 "Go to the prev page."
8582 (interactive "P")
8583 (let ((win (selected-window)))
8584 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8585 (gnus-article-prev-page)
8586 (select-window win)))
8588 (defvar gnus-decode-header-methods
8589 '(mail-decode-encoded-word-region)
8590 "List of methods used to decode headers.
8592 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8593 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8594 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8595 whose names match REGEXP.
8597 For example:
8598 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8599 mail-decode-encoded-word-region
8600 (\"chinese\" . rfc1843-decode-region))
8603 (defvar gnus-decode-header-methods-cache nil)
8605 (defun gnus-multi-decode-header (start end)
8606 "Apply the functions from `gnus-encoded-word-methods' that match."
8607 (unless (and gnus-decode-header-methods-cache
8608 (eq gnus-newsgroup-name
8609 (car gnus-decode-header-methods-cache)))
8610 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8611 (dolist (x gnus-decode-header-methods)
8612 (if (symbolp x)
8613 (nconc gnus-decode-header-methods-cache (list x))
8614 (if (and gnus-newsgroup-name
8615 (string-match (car x) gnus-newsgroup-name))
8616 (nconc gnus-decode-header-methods-cache
8617 (list (cdr x)))))))
8618 (let ((xlist gnus-decode-header-methods-cache))
8619 (pop xlist)
8620 (save-restriction
8621 (narrow-to-region start end)
8622 (while xlist
8623 (funcall (pop xlist) (point-min) (point-max))))))
8626 ;;; Treatment top-level handling.
8629 (defvar gnus-inhibit-article-treatments nil)
8631 ;; Dynamic variables.
8632 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8633 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8634 (defvar gnus-treat-type)
8635 (defvar gnus-treat-condition)
8636 (defvar gnus-treat-length)
8638 (defun gnus-treat-article (condition
8639 &optional part-num total type)
8640 (let ((gnus-treat-condition condition)
8641 (part-number part-num)
8642 (total-parts total)
8643 (gnus-treat-type type)
8644 (gnus-treat-length (- (point-max) (point-min)))
8645 (alist gnus-treatment-function-alist)
8646 (article-goto-body-goes-to-point-min-p t)
8647 (treated-type
8648 (or (not type)
8649 (catch 'found
8650 (let ((list gnus-article-treat-types))
8651 (while list
8652 (when (string-match (pop list) type)
8653 (throw 'found t)))))))
8654 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8655 val)
8656 (gnus-run-hooks 'gnus-part-display-hook)
8657 (dolist (elem alist)
8658 (setq val
8659 (save-excursion
8660 (when (gnus-buffer-live-p gnus-summary-buffer)
8661 (set-buffer gnus-summary-buffer))
8662 (symbol-value (car elem))))
8663 (when (and (or (consp val)
8664 treated-type)
8665 (or (not gnus-inhibit-article-treatments)
8666 (eq gnus-treat-condition 'head))
8667 (gnus-treat-predicate val)
8668 (or (not (get (car elem) 'highlight))
8669 highlightp))
8670 (save-restriction
8671 (funcall (cadr elem)))))))
8673 (defun gnus-treat-predicate (val)
8674 (cond
8675 ((null val)
8676 nil)
8677 (gnus-treat-condition
8678 (eq gnus-treat-condition val))
8679 ((and (listp val)
8680 (stringp (car val)))
8681 (apply 'gnus-or (mapcar `(lambda (s)
8682 (string-match s ,(or gnus-newsgroup-name "")))
8683 val)))
8684 ((listp val)
8685 (let ((pred (pop val)))
8686 (cond
8687 ((eq pred 'or)
8688 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8689 ((eq pred 'and)
8690 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8691 ((eq pred 'not)
8692 (not (gnus-treat-predicate (car val))))
8693 ((eq pred 'typep)
8694 (equal (car val) gnus-treat-type))
8695 ((functionp pred)
8696 (funcall pred))
8698 (error "%S is not a valid predicate" pred)))))
8699 ((eq val t)
8701 ((eq val 'head)
8702 nil)
8703 ((eq val 'first)
8704 (eq part-number 1))
8705 ((eq val 'last)
8706 (eq part-number total-parts))
8707 ((numberp val)
8708 (< gnus-treat-length val))
8710 (error "%S is not a valid value" val))))
8712 (defun gnus-article-encrypt-body (protocol &optional n)
8713 "Encrypt the article body."
8714 (interactive
8715 (list
8716 (or gnus-article-encrypt-protocol
8717 (gnus-completing-read "Encrypt protocol"
8718 (mapcar 'car gnus-article-encrypt-protocol-alist)
8720 current-prefix-arg))
8721 ;; User might hit `K E' instead of `K e', so prompt once.
8722 (when (and gnus-article-encrypt-protocol
8723 gnus-novice-user)
8724 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8725 (error "Encrypt aborted")))
8726 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8727 (unless func
8728 (error "Can't find the encrypt protocol %s" protocol))
8729 (if (member gnus-newsgroup-name '("nndraft:delayed"
8730 "nndraft:drafts"
8731 "nndraft:queue"))
8732 (error "Can't encrypt the article in group %s"
8733 gnus-newsgroup-name))
8734 (gnus-summary-iterate n
8735 (with-current-buffer gnus-summary-buffer
8736 (let ((mail-parse-charset gnus-newsgroup-charset)
8737 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8738 (summary-buffer gnus-summary-buffer)
8739 references point)
8740 (gnus-set-global-variables)
8741 (when (gnus-group-read-only-p)
8742 (error "The current newsgroup does not support article encrypt"))
8743 (gnus-summary-show-article t)
8744 (setq references
8745 (or (mail-header-references gnus-current-headers) ""))
8746 (set-buffer gnus-article-buffer)
8747 (let* ((inhibit-read-only t)
8748 (headers
8749 (mapcar (lambda (field)
8750 (and (save-restriction
8751 (message-narrow-to-head)
8752 (goto-char (point-min))
8753 (search-forward field nil t))
8754 (prog2
8755 (message-narrow-to-field)
8756 (buffer-string)
8757 (delete-region (point-min) (point-max))
8758 (widen))))
8759 '("Content-Type:" "Content-Transfer-Encoding:"
8760 "Content-Disposition:"))))
8761 (message-narrow-to-head)
8762 (message-remove-header "MIME-Version")
8763 (goto-char (point-max))
8764 (setq point (point))
8765 (insert (apply 'concat headers))
8766 (widen)
8767 (narrow-to-region point (point-max))
8768 (let ((message-options message-options))
8769 (message-options-set 'message-sender user-mail-address)
8770 (message-options-set 'message-recipients user-mail-address)
8771 (message-options-set 'message-sign-encrypt 'not)
8772 (funcall func))
8773 (goto-char (point-min))
8774 (insert "MIME-Version: 1.0\n")
8775 (widen)
8776 (gnus-summary-edit-article-done
8777 references nil summary-buffer t))
8778 (when gnus-keep-backlog
8779 (gnus-backlog-remove-article
8780 (car gnus-article-current) (cdr gnus-article-current)))
8781 (gnus-flush-original-article-buffer)
8782 (when gnus-use-cache
8783 (gnus-cache-update-article
8784 (car gnus-article-current) (cdr gnus-article-current))))))))
8786 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8787 "The following specs can be used:
8788 %t The security MIME type
8789 %i Additional info
8790 %d Details
8791 %D Details if button is pressed")
8793 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8794 "The following specs can be used:
8795 %t The security MIME type
8796 %i Additional info
8797 %d Details
8798 %D Details if button is pressed")
8800 (defvar gnus-mime-security-button-line-format-alist
8801 '((?t gnus-tmp-type ?s)
8802 (?i gnus-tmp-info ?s)
8803 (?d gnus-tmp-details ?s)
8804 (?D gnus-tmp-pressed-details ?s)))
8806 (defvar gnus-mime-security-button-commands
8807 '((gnus-article-press-button "\r" "Show Detail")
8808 (undefined "v")
8809 (undefined "t")
8810 (undefined "C")
8811 (gnus-mime-security-save-part "o" "Save...")
8812 (undefined "\C-o")
8813 (undefined "r")
8814 (undefined "d")
8815 (undefined "c")
8816 (undefined "i")
8817 (undefined "E")
8818 (undefined "e")
8819 (undefined "p")
8820 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8821 (undefined ".")))
8823 (defvar gnus-mime-security-button-map
8824 (let ((map (make-sparse-keymap)))
8825 (define-key map gnus-mouse-2 'gnus-article-push-button)
8826 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8827 (dolist (c gnus-mime-security-button-commands)
8828 (define-key map (cadr c) (car c)))
8829 map))
8831 (easy-menu-define
8832 gnus-mime-security-button-menu gnus-mime-security-button-map
8833 "Security button menu."
8834 `("Security Part"
8835 ,@(delq nil
8836 (mapcar (lambda (c)
8837 (unless (eq (car c) 'undefined)
8838 (vector (caddr c) (car c) :active t)))
8839 gnus-mime-security-button-commands))))
8841 (defun gnus-mime-security-button-menu (event prefix)
8842 "Construct a context-sensitive menu of security commands."
8843 (interactive "e\nP")
8844 (save-window-excursion
8845 (let ((pos (event-start event)))
8846 (select-window (posn-window pos))
8847 (goto-char (posn-point pos))
8848 (gnus-article-check-buffer)
8849 (popup-menu gnus-mime-security-button-menu nil prefix))))
8851 (defvar gnus-mime-security-details-buffer nil)
8853 (defvar gnus-mime-security-button-pressed nil)
8855 (defvar gnus-mime-security-show-details-inline t
8856 "If non-nil, show details in the article buffer.")
8858 (defun gnus-mime-security-verify-or-decrypt (handle)
8859 (mm-remove-parts (cdr handle))
8860 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8861 point (inhibit-read-only t))
8862 (if region
8863 (goto-char (car region)))
8864 (setq point (point))
8865 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8866 (let* ((mm-verify-option 'known)
8867 (mm-decrypt-option 'known)
8868 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8869 (unless (eq nparts (cdr handle))
8870 (mm-destroy-parts (cdr handle))
8871 (setcdr handle nparts))))
8872 (gnus-mime-display-security handle)
8873 (when region
8874 (delete-region (point) (cdr region))
8875 (set-marker (car region) nil)
8876 (set-marker (cdr region) nil))
8877 (goto-char point)))
8879 (defun gnus-mime-security-show-details (handle)
8880 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8881 (if (not details)
8882 (gnus-message 5 "No details.")
8883 (if gnus-mime-security-show-details-inline
8884 (let ((gnus-mime-security-button-pressed
8885 (not (get-text-property (point) 'gnus-mime-details)))
8886 (gnus-mime-security-button-line-format
8887 (get-text-property (point) 'gnus-line-format))
8888 (inhibit-read-only t))
8889 (forward-char -1)
8890 (while (eq (get-text-property (point) 'gnus-line-format)
8891 gnus-mime-security-button-line-format)
8892 (forward-char -1))
8893 (forward-char)
8894 (save-restriction
8895 (narrow-to-region (point) (point))
8896 (gnus-insert-mime-security-button handle))
8897 (delete-region (point)
8898 (or (text-property-not-all
8899 (point) (point-max)
8900 'gnus-line-format
8901 gnus-mime-security-button-line-format)
8902 (point-max))))
8903 ;; Not inlined.
8904 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8905 (with-current-buffer gnus-mime-security-details-buffer
8906 (erase-buffer)
8908 (setq gnus-mime-security-details-buffer
8909 (gnus-get-buffer-create "*MIME Security Details*")))
8910 (with-current-buffer gnus-mime-security-details-buffer
8911 (insert details)
8912 (goto-char (point-min)))
8913 (pop-to-buffer gnus-mime-security-details-buffer)))))
8915 (defun gnus-mime-security-press-button (handle)
8916 (save-excursion
8917 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8918 (gnus-mime-security-show-details handle)
8919 (gnus-mime-security-verify-or-decrypt handle))))
8921 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8922 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8923 (gnus-tmp-type
8924 (concat
8925 (or (nth 2 (assoc protocol mm-verify-function-alist))
8926 (nth 2 (assoc protocol mm-decrypt-function-alist))
8927 "Unknown")
8928 (if (equal (car handle) "multipart/signed")
8929 " Signed" " Encrypted")
8930 " Part"))
8931 (gnus-tmp-info
8932 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8933 "Undecided"))
8934 (gnus-tmp-details
8935 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8936 gnus-tmp-pressed-details
8937 b e)
8938 (setq gnus-tmp-details
8939 (if gnus-tmp-details
8940 (concat "\n" gnus-tmp-details)
8941 ""))
8942 (setq gnus-tmp-pressed-details
8943 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8944 (unless (bolp)
8945 (insert "\n"))
8946 (setq b (point))
8947 (gnus-eval-format
8948 gnus-mime-security-button-line-format
8949 gnus-mime-security-button-line-format-alist
8950 `(keymap ,gnus-mime-security-button-map
8951 gnus-callback gnus-mime-security-press-button
8952 gnus-line-format ,gnus-mime-security-button-line-format
8953 gnus-mime-details ,gnus-mime-security-button-pressed
8954 article-type annotation
8955 gnus-data ,handle))
8956 (setq e (if (bolp)
8957 ;; Exclude a newline.
8958 (1- (point))
8959 (point)))
8960 (when gnus-article-button-face
8961 (gnus-overlay-put (gnus-make-overlay b e nil t)
8962 'face gnus-article-button-face))
8963 (widget-convert-button
8964 'link b e
8965 :mime-handle handle
8966 :action 'gnus-widget-press-button
8967 :button-keymap gnus-mime-security-button-map
8968 :help-echo
8969 (lambda (_widget)
8970 ;; Needed to properly clear the message due to a bug in
8971 ;; wid-edit (XEmacs only).
8972 (when (boundp 'help-echo-owns-message)
8973 (setq help-echo-owns-message t))
8974 (format
8975 "%S: show detail; %S: more options"
8976 (aref gnus-mouse-2 0)
8977 (aref gnus-down-mouse-3 0))))))
8979 (defun gnus-mime-display-security (handle)
8980 (save-restriction
8981 (narrow-to-region (point) (point))
8982 (unless (gnus-unbuttonized-mime-type-p (car handle))
8983 (gnus-insert-mime-security-button handle))
8984 (gnus-mime-display-part (cadr handle))
8985 (unless (bolp)
8986 (insert "\n"))
8987 (unless (gnus-unbuttonized-mime-type-p (car handle))
8988 (let ((gnus-mime-security-button-line-format
8989 gnus-mime-security-button-end-line-format))
8990 (gnus-insert-mime-security-button handle)))
8991 (mm-set-handle-multipart-parameter
8992 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8993 (goto-char (point-max))))
8995 (defun gnus-mime-security-run-function (function)
8996 "Run FUNCTION with the security part under point."
8997 (gnus-article-check-buffer)
8998 (let ((data (get-text-property (point) 'gnus-data))
8999 buffer handle)
9000 (when (and (stringp (car-safe data))
9001 (setq buffer (mm-handle-multipart-original-buffer data))
9002 (setq handle (cadr data)))
9003 (if (bufferp (mm-handle-buffer handle))
9004 (progn
9005 (setq handle (cons buffer (copy-sequence (cdr handle))))
9006 (mm-handle-set-undisplayer handle nil))
9007 (setq handle (mm-make-handle
9008 buffer
9009 (mm-handle-multipart-ctl-parameter handle 'protocol)
9010 nil nil nil nil nil nil)))
9011 (funcall function handle))))
9013 (defun gnus-mime-security-save-part ()
9014 "Save the security part under point."
9015 (interactive)
9016 (gnus-mime-security-run-function 'mm-save-part))
9018 (defun gnus-mime-security-pipe-part ()
9019 "Pipe the security part under point to a process."
9020 (interactive)
9021 (gnus-mime-security-run-function 'mm-pipe-part))
9023 (gnus-ems-redefine)
9025 (provide 'gnus-art)
9027 (run-hooks 'gnus-art-load-hook)
9029 ;;; gnus-art.el ends here