Prefer directed to neutral quotes
[gnus.git] / lisp / gnus-art.el
blob1367440f77751636076ff8e68c1ebb631465939e
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-util)
34 (require 'gnus-sum)
35 (require 'gnus-spec)
36 (require 'gnus-int)
37 (require 'gnus-win)
38 (require 'mm-bodies)
39 (require 'mail-parse)
40 (require 'mm-decode)
41 (require 'mm-view)
42 (require 'wid-edit)
43 (require 'mm-uu)
44 (require 'message)
45 (require 'mouse)
47 (autoload 'gnus-msg-mail "gnus-msg" nil t)
48 (autoload 'gnus-button-mailto "gnus-msg")
49 (autoload 'gnus-button-reply "gnus-msg" nil t)
50 (autoload 'parse-time-string "parse-time" nil nil)
51 (autoload 'ansi-color-apply-on-region "ansi-color")
52 (autoload 'mm-url-insert-file-contents-external "mm-url")
53 (autoload 'mm-extern-cache-contents "mm-extern")
54 (autoload 'url-expand-file-name "url-expand")
56 (defgroup gnus-article nil
57 "Article display."
58 :link '(custom-manual "(gnus)Article Buffer")
59 :group 'gnus)
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
64 :group 'gnus-article)
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
69 :group 'gnus-article)
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
74 :group 'gnus-article
75 :group 'gnus-visual)
77 (defgroup gnus-article-signature nil
78 "Article signatures."
79 :link '(custom-manual "(gnus)Article Signature")
80 :group 'gnus-article)
82 (defgroup gnus-article-headers nil
83 "Article headers."
84 :link '(custom-manual "(gnus)Hiding Headers")
85 :group 'gnus-article)
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
90 :group 'gnus-article)
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
95 :group 'gnus-article)
97 (defgroup gnus-article-saving nil
98 "Saving articles."
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
118 (mapcar
119 (lambda (header)
120 (concat "^" header ":"))
121 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127 "X-Attribution" "X-Originating-IP" "Delivered-To"
128 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144 "List-[A-Za-z]+" "X-Listprocessor-Version"
145 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147 "X-Received" "Content-length" "X-precedence"
148 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153 "X-Content-length" "X-Posting-Agent" "Original-Received"
154 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
158 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161 "Envelope-Sender" "Envelope-Recipients"))
162 "*All headers that start with this regexp will be hidden.
163 This variable can also be a list of regexps of headers to be ignored.
164 If `gnus-visible-headers' is non-nil, this variable will be ignored."
165 :type '(choice regexp
166 (repeat regexp))
167 :group 'gnus-article-hiding)
169 (defcustom gnus-visible-headers
170 "^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:"
171 "*All headers that do not match this regexp will be hidden.
172 This variable can also be a list of regexp of headers to remain visible.
173 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174 :type '(choice
175 (repeat :value-to-internal (lambda (widget value)
176 (custom-split-regexp-maybe value))
177 :match (lambda (widget value)
178 (or (stringp value)
179 (widget-editable-list-match widget value)))
180 regexp)
181 (const :tag "Use gnus-ignored-headers" nil)
182 regexp)
183 :group 'gnus-article-hiding)
185 (defcustom gnus-sorted-header-list
186 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
187 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
188 "*This variable is a list of regular expressions.
189 If it is non-nil, headers that match the regular expressions will
190 be placed first in the article buffer in the sequence specified by
191 this list."
192 :type '(repeat regexp)
193 :group 'gnus-article-hiding)
195 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
196 "Headers that are only to be displayed if they have interesting data.
197 Possible values in this list are:
199 'empty Headers with no content.
200 'newsgroups Newsgroup identical to Gnus group.
201 'to-address To identical to To-address.
202 'to-list To identical to To-list.
203 'cc-list CC identical to To-list.
204 'followup-to Followup-to identical to Newsgroups.
205 'reply-to Reply-to identical to From.
206 'date Date less than four days old.
207 'long-to To and/or Cc longer than 1024 characters.
208 'many-to Multiple To and/or Cc."
209 :type '(set (const :tag "Headers with no content." empty)
210 (const :tag "Newsgroups identical to Gnus group." newsgroups)
211 (const :tag "To identical to To-address." to-address)
212 (const :tag "To identical to To-list." to-list)
213 (const :tag "CC identical to To-list." cc-list)
214 (const :tag "Followup-to identical to Newsgroups." followup-to)
215 (const :tag "Reply-to identical to From." reply-to)
216 (const :tag "Date less than four days old." date)
217 (const :tag "To and/or Cc longer than 1024 characters." long-to)
218 (const :tag "Multiple To and/or Cc headers." many-to))
219 :group 'gnus-article-hiding)
221 (defcustom gnus-article-skip-boring nil
222 "Skip over text that is not worth reading.
223 By default, if you set this t, then Gnus will display citations and
224 signatures, but will never scroll down to show you a page consisting
225 only of boring text. Boring text is controlled by
226 `gnus-article-boring-faces'."
227 :version "22.1"
228 :type 'boolean
229 :group 'gnus-article-hiding)
231 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
232 "Regexp matching signature separator.
233 This can also be a list of regexps. In that case, it will be checked
234 from head to tail looking for a separator. Searches will be done from
235 the end of the buffer."
236 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
237 (regexp)
238 (repeat :tag "List of regexp" regexp))
239 :group 'gnus-article-signature)
241 (defcustom gnus-signature-limit nil
242 "Provide a limit to what is considered a signature.
243 If it is a number, no signature may not be longer (in characters) than
244 that number. If it is a floating point number, no signature may be
245 longer (in lines) than that number. If it is a function, the function
246 will be called without any parameters, and if it returns nil, there is
247 no signature in the buffer. If it is a string, it will be used as a
248 regexp. If it matches, the text in question is not a signature.
250 This can also be a list of the above values."
251 :type '(choice (const nil)
252 (integer :value 200)
253 (number :value 4.0)
254 function
255 (regexp :value ".*"))
256 :group 'gnus-article-signature)
258 (defcustom gnus-hidden-properties
259 ;; We use to have `intangible' here as well, but Emacs's command loop moves
260 ;; point out of invisible text anyway, so `intangible' is clearly not
261 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
262 '(invisible t)
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo \
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | ee -")
277 (if (gnus-image-type-available-p 'pbm)
278 'gnus-display-x-face-in-from
279 "{ echo \
280 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
281 ; uncompface; } | icontopbm | display -"))
282 "*String or function to be executed to display an X-Face header.
283 If it is a string, the command will be executed in a sub-shell
284 asynchronously. The compressed face will be piped to this command."
285 :type `(choice string
286 (function-item gnus-display-x-face-in-from)
287 function)
288 :version "21.1"
289 :group 'gnus-picon
290 :group 'gnus-article-washing)
292 (defcustom gnus-article-x-face-too-ugly nil
293 "Regexp matching posters whose face shouldn't be shown automatically."
294 :type '(choice regexp (const nil))
295 :group 'gnus-article-washing)
297 (defcustom gnus-article-banner-alist nil
298 "Banner alist for stripping.
299 For example,
300 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301 :version "21.1"
302 :type '(repeat (cons symbol regexp))
303 :group 'gnus-article-washing)
305 (gnus-define-group-parameter
306 banner
307 :variable-document
308 "Alist of regexps (to match group names) and banner."
309 :variable-group gnus-article-washing
310 :parameter-type
311 '(choice :tag "Banner"
312 :value nil
313 (const :tag "Remove signature" signature)
314 (symbol :tag "Item in `gnus-article-banner-alist'" none)
315 regexp
316 (const :tag "None" nil))
317 :parameter-document
318 "If non-nil, specify how to remove `banners' from articles.
320 Symbol `signature' means to remove signatures delimited by
321 `gnus-signature-separator'. Any other symbol is used to look up a
322 regular expression to match the banner in `gnus-article-banner-alist'.
323 A string is used as a regular expression to match the banner
324 directly.")
326 (defcustom gnus-article-address-banner-alist nil
327 "Alist of mail addresses and banners.
328 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
329 to match a mail address in the From: header, BANNER is one of a symbol
330 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
331 If ADDRESS matches author's mail address, it will remove things like
332 advertisements. For example:
334 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
336 :type '(repeat
337 (cons
338 (regexp :tag "Address")
339 (choice :tag "Banner" :value nil
340 (const :tag "Remove signature" signature)
341 (symbol :tag "Item in `gnus-article-banner-alist'" none)
342 regexp
343 (const :tag "None" nil))))
344 :version "22.1"
345 :group 'gnus-article-washing)
347 (defmacro gnus-emphasis-custom-with-format (&rest body)
348 `(let ((format "\
349 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
350 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351 ,@body))
353 (defun gnus-emphasis-custom-value-to-external (value)
354 (gnus-emphasis-custom-with-format
355 (if (consp (car value))
356 (list (format format (car (car value)) (cdr (car value)))
358 (if (nth 1 value) 2 3)
359 (nth 2 value))
360 value)))
362 (defun gnus-emphasis-custom-value-to-internal (value)
363 (gnus-emphasis-custom-with-format
364 (let ((regexp (concat "\\`"
365 (format (regexp-quote format)
366 "\\([^()]+\\)" "\\([^()]+\\)")
367 "\\'"))
368 pattern)
369 (if (string-match regexp (setq pattern (car value)))
370 (list (cons (match-string 1 pattern) (match-string 2 pattern))
371 (= (nth 2 value) 2)
372 (nth 3 value))
373 value))))
375 (defcustom gnus-emphasis-alist
376 (let ((types
377 '(("\\*" "\\*" bold nil 2)
378 ("_" "_" underline)
379 ("/" "/" italic)
380 ("_/" "/_" underline-italic)
381 ("_\\*" "\\*_" underline-bold)
382 ("\\*/" "/\\*" bold-italic)
383 ("_\\*/" "/\\*_" underline-bold-italic))))
384 (nconc
385 (gnus-emphasis-custom-with-format
386 (mapcar (lambda (spec)
387 (list (format format (car spec) (cadr spec))
388 (or (nth 3 spec) 2)
389 (or (nth 4 spec) 3)
390 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391 types))
392 '(;; I've never seen anyone use this strikethru convention whereas I've
393 ;; several times seen it triggered by normal text. --Stef
394 ;; Miles suggests that this form is sometimes used but for italics,
395 ;; so maybe we should map it to `italic'.
396 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
397 ;; 2 3 gnus-emphasis-strikethru)
398 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
399 2 3 gnus-emphasis-underline))))
400 "*Alist that says how to fontify certain phrases.
401 Each item looks like this:
403 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
405 The first element is a regular expression to be matched. The second
406 is a number that says what regular expression grouping used to find
407 the entire emphasized word. The third is a number that says what
408 regexp grouping should be displayed and highlighted. The fourth
409 is the face used for highlighting."
410 :type
411 '(repeat
412 (menu-choice
413 :format "%[Customizing Style%]\n%v"
414 :indent 2
415 (group :tag "Default"
416 :value ("" 0 0 default)
417 :value-create
418 (lambda (widget)
419 (let ((value (widget-get
420 (cadr (widget-get (widget-get widget :parent)
421 :args))
422 :value)))
423 (if (not (eq (nth 2 value) 'default))
424 (widget-put
425 widget
426 :value
427 (gnus-emphasis-custom-value-to-external value))))
428 (widget-group-value-create widget))
429 regexp
430 (integer :format "Match group: %v")
431 (integer :format "Emphasize group: %v")
432 face)
433 (group :tag "Simple"
434 :value (("_" . "_") nil default)
435 (cons :format "%v"
436 (regexp :format "Start regexp: %v")
437 (regexp :format "End regexp: %v"))
438 (boolean :format "Show start and end patterns: %[%v%]\n"
439 :on " On " :off " Off ")
440 face)))
441 :get (lambda (symbol)
442 (mapcar 'gnus-emphasis-custom-value-to-internal
443 (default-value symbol)))
444 :set (lambda (symbol value)
445 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446 value)))
447 :group 'gnus-article-emphasis)
449 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
450 "A regexp to describe whitespace which should not be emphasized.
451 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
452 The former avoids underlining of leading and trailing whitespace,
453 and the latter avoids underlining any whitespace at all."
454 :version "21.1"
455 :group 'gnus-article-emphasis
456 :type 'regexp)
458 (defface gnus-emphasis-bold '((t (:bold t)))
459 "Face used for displaying strong emphasized text (*word*)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-italic '((t (:italic t)))
463 "Face used for displaying italic emphasized text (/word/)."
464 :group 'gnus-article-emphasis)
466 (defface gnus-emphasis-underline '((t (:underline t)))
467 "Face used for displaying underlined emphasized text (_word_)."
468 :group 'gnus-article-emphasis)
470 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
471 "Face used for displaying underlined bold emphasized text (_*word*_)."
472 :group 'gnus-article-emphasis)
474 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
475 "Face used for displaying underlined italic emphasized text (_/word/_)."
476 :group 'gnus-article-emphasis)
478 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
479 "Face used for displaying bold italic emphasized text (/*word*/)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-underline-bold-italic
483 '((t (:bold t :italic t :underline t)))
484 "Face used for displaying underlined bold italic emphasized text.
485 Example: (_/*word*/_)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
489 '((t (:strikethru t)))
490 '((t (:strike-through t))))
491 "Face used for displaying strike-through text (-word-)."
492 :group 'gnus-article-emphasis)
494 (defface gnus-emphasis-highlight-words
495 '((t (:background "black" :foreground "yellow")))
496 "Face used for displaying highlighted words."
497 :group 'gnus-article-emphasis)
499 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
500 "Format for display of Date headers in article bodies.
501 See `format-time-string' for the possible values.
503 The variable can also be function, which should return a complete Date
504 header. The function is called with one argument, the time, which can
505 be fed to `format-time-string'."
506 :type '(choice string function)
507 :link '(custom-manual "(gnus)Article Date")
508 :group 'gnus-article-washing)
510 (defcustom gnus-save-all-headers t
511 "*If non-nil, don't remove any headers before saving.
512 This will be overridden by the `:headers' property that the symbol of
513 the saver function, which is specified by `gnus-default-article-saver',
514 might have."
515 :group 'gnus-article-saving
516 :type 'boolean)
518 (defcustom gnus-prompt-before-saving 'always
519 "*This variable says how much prompting is to be done when saving articles.
520 If it is nil, no prompting will be done, and the articles will be
521 saved to the default files. If this variable is `always', each and
522 every article that is saved will be preceded by a prompt, even when
523 saving large batches of articles. If this variable is neither nil not
524 `always', there the user will be prompted once for a file name for
525 each invocation of the saving commands."
526 :group 'gnus-article-saving
527 :type '(choice (item always)
528 (item :tag "never" nil)
529 (sexp :tag "once" :format "%t\n" :value t)))
531 (defcustom gnus-saved-headers gnus-visible-headers
532 "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving. This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539 :group 'gnus-article-saving
540 :type 'regexp)
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544 "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
548 Gnus provides the following functions:
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
560 The symbol of each function may have the following properties:
562 * :decode
563 The value non-nil means save decoded articles. This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file. This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file. This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved. If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580 :group 'gnus-article-saving
581 :type '(radio (function-item gnus-summary-save-in-rmail)
582 (function-item gnus-summary-save-in-mail)
583 (function-item gnus-summary-save-in-folder)
584 (function-item gnus-summary-save-in-file)
585 (function-item gnus-summary-save-body-in-file)
586 (function-item gnus-summary-save-in-vm)
587 (function-item gnus-summary-write-to-file)
588 (function-item gnus-summary-write-body-to-file)
589 (function-item gnus-summary-save-in-pipe)
590 (function)))
592 (defcustom gnus-article-save-coding-system
593 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597 "Coding system used to save decoded articles to a file.
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text. This is used by the
601 commands including:
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
608 and the functions to which you may set `gnus-default-article-saver':
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil. Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619 :group 'gnus-article-saving
620 :type `(choice
621 :format "%{%t%}:\n %[Value Menu%] %v"
622 (const :tag "Save raw articles" nil)
623 ,@(delq nil
624 (mapcar
625 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626 '((const :tag "UTF-8" utf-8)
627 (const :tag "iso-2022-7bit" iso-2022-7bit)
628 (const :tag "Emacs internal" emacs-mule)
629 (const :tag "escape-quoted" escape-quoted))))
630 (symbol :tag "Coding system")))
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639 "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645 "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647 :group 'gnus-article-saving
648 :type 'function)
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651 "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654 :group 'gnus-article-saving
655 :type 'function)
657 (defcustom gnus-split-methods
658 '((gnus-article-archive-name)
659 (gnus-article-nndoc-name))
660 "*Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
665 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
672 If the match is a string, it is used as a regexp match on the
673 article. If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter. If it is a list, it will be evalled in the same buffer.
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680 :group 'gnus-article-saving
681 :type '(repeat (choice (list :value (fun) function)
682 (cons :value ("" "") regexp (repeat string))
683 (sexp :value nil))))
685 (defcustom gnus-page-delimiter "^\^L"
686 "*Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689 :type 'regexp
690 :group 'gnus-article-various)
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693 "*The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
696 The following additional specs are available:
698 %w The article washing status.
699 %m The number of MIME parts in the article."
700 :version "24.1"
701 :type 'string
702 :group 'gnus-article-various)
704 (defcustom gnus-article-mode-hook nil
705 "*A hook for Gnus article mode."
706 :type 'hook
707 :group 'gnus-article-various)
709 (when (featurep 'xemacs)
710 ;; Extracted from gnus-xmas-define in order to preserve user settings
711 (when (fboundp 'turn-off-scroll-in-place)
712 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
713 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
714 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
716 (defcustom gnus-article-menu-hook nil
717 "*Hook run after the creation of the article mode menu."
718 :type 'hook
719 :group 'gnus-article-various)
721 (defcustom gnus-article-prepare-hook nil
722 "*A hook called after an article has been prepared in the article buffer."
723 :type 'hook
724 :group 'gnus-article-various)
726 (defcustom gnus-copy-article-ignored-headers nil
727 "List of headers to be removed when copying an article.
728 Each element is a regular expression."
729 :version "23.1" ;; No Gnus
730 :type '(repeat regexp)
731 :group 'gnus-article-various)
733 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
734 "Gnus 5.10 (Emacs 22.1)")
736 (defface gnus-button
737 '((t (:weight bold)))
738 "Face used for highlighting a button in the article buffer."
739 :group 'gnus-article-buttons)
741 (defcustom gnus-article-button-face 'gnus-button
742 "Face used for highlighting buttons in the article buffer.
744 An article button is a piece of text that you can activate by pressing
745 `RET' or `mouse-2' above it."
746 :type 'face
747 :group 'gnus-article-buttons)
749 (defcustom gnus-article-mouse-face 'highlight
750 "Face used for mouse highlighting in the article buffer.
752 Article buttons will be displayed in this face when the cursor is
753 above them."
754 :type 'face
755 :group 'gnus-article-buttons)
757 (defcustom gnus-signature-face 'gnus-signature
758 "Face used for highlighting a signature in the article buffer.
759 Obsolete; use the face `gnus-signature' for customizations instead."
760 :type 'face
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
764 (defface gnus-signature
765 '((t
766 (:italic t)))
767 "Face used for highlighting a signature in the article buffer."
768 :group 'gnus-article-highlight
769 :group 'gnus-article-signature)
770 ;; backward-compatibility alias
771 (put 'gnus-signature-face 'face-alias 'gnus-signature)
772 (put 'gnus-signature-face 'obsolete-face "22.1")
774 (defface gnus-header-from
775 '((((class color)
776 (background dark))
777 (:foreground "PaleGreen1"))
778 (((class color)
779 (background light))
780 (:foreground "red3"))
782 (:italic t)))
783 "Face used for displaying from headers."
784 :group 'gnus-article-headers
785 :group 'gnus-article-highlight)
786 ;; backward-compatibility alias
787 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
788 (put 'gnus-header-from-face 'obsolete-face "22.1")
790 (defface gnus-header-subject
791 '((((class color)
792 (background dark))
793 (:foreground "SeaGreen1"))
794 (((class color)
795 (background light))
796 (:foreground "red4"))
798 (:bold t :italic t)))
799 "Face used for displaying subject headers."
800 :group 'gnus-article-headers
801 :group 'gnus-article-highlight)
802 ;; backward-compatibility alias
803 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
804 (put 'gnus-header-subject-face 'obsolete-face "22.1")
806 (defface gnus-header-newsgroups
807 '((((class color)
808 (background dark))
809 (:foreground "yellow" :italic t))
810 (((class color)
811 (background light))
812 (:foreground "MidnightBlue" :italic t))
814 (:italic t)))
815 "Face used for displaying newsgroups headers.
816 In the default setup this face is only used for crossposted
817 articles."
818 :group 'gnus-article-headers
819 :group 'gnus-article-highlight)
820 ;; backward-compatibility alias
821 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
822 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
824 (defface gnus-header-name
825 '((((class color)
826 (background dark))
827 (:foreground "SpringGreen2"))
828 (((class color)
829 (background light))
830 (:foreground "maroon"))
832 (:bold t)))
833 "Face used for displaying header names."
834 :group 'gnus-article-headers
835 :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
838 (put 'gnus-header-name-face 'obsolete-face "22.1")
840 (defface gnus-header-content
841 '((((class color)
842 (background dark))
843 (:foreground "SpringGreen1" :italic t))
844 (((class color)
845 (background light))
846 (:foreground "indianred4" :italic t))
848 (:italic t))) "Face used for displaying header content."
849 :group 'gnus-article-headers
850 :group 'gnus-article-highlight)
851 ;; backward-compatibility alias
852 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
853 (put 'gnus-header-content-face 'obsolete-face "22.1")
855 (defcustom gnus-header-face-alist
856 '(("From" nil gnus-header-from)
857 ("Subject" nil gnus-header-subject)
858 ("Newsgroups:.*," nil gnus-header-newsgroups)
859 ("" gnus-header-name gnus-header-content))
860 "*Controls highlighting of article headers.
862 An alist of the form (HEADER NAME CONTENT).
864 HEADER is a regular expression which should match the name of a
865 header and NAME and CONTENT are either face names or nil.
867 The name of each header field will be displayed using the face
868 specified by the first element in the list where HEADER matches
869 the header name and NAME is non-nil. Similarly, the content will
870 be displayed by the first non-nil matching CONTENT face."
871 :group 'gnus-article-headers
872 :group 'gnus-article-highlight
873 :type '(repeat (list (regexp :tag "Header")
874 (choice :tag "Name"
875 (item :tag "skip" nil)
876 (face :value default))
877 (choice :tag "Content"
878 (item :tag "skip" nil)
879 (face :value default)))))
881 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
882 '((xface . (:face gnus-x-face)))
883 '((pbm . (:face gnus-x-face))
884 (png . nil)))
885 "Alist of image types and properties applied to Face and X-Face images.
886 Here are examples:
888 ;; Specify the altitude of Face images in the From header.
889 \(setq gnus-face-properties-alist
890 '((pbm . (:face gnus-x-face :ascent 80))
891 (png . (:ascent 80))))
893 ;; Show Face images as pressed buttons.
894 \(setq gnus-face-properties-alist
895 '((pbm . (:face gnus-x-face :relief -2))
896 (png . (:relief -2))))
898 See the manual for the valid properties for various image types.
899 Currently, `pbm' is used for X-Face images and `png' is used for Face
900 images in Emacs. Only the `:face' property is effective on the `xface'
901 image type in XEmacs if it is built with the libcompface library."
902 :version "23.1" ;; No Gnus
903 :group 'gnus-article-headers
904 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
906 (defcustom gnus-article-decode-hook
907 '(article-decode-charset article-decode-encoded-words
908 article-decode-group-name article-decode-idna-rhs)
909 "*Hook run to decode charsets in articles."
910 :group 'gnus-article-headers
911 :type 'hook)
913 (defcustom gnus-display-mime-function 'gnus-display-mime
914 "Function to display MIME articles."
915 :group 'gnus-article-mime
916 :type 'function)
918 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
919 "Function used to decode headers.")
921 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
922 "Function used to decode addresses.")
924 (defvar gnus-article-dumbquotes-map
925 '((?\200 "EUR")
926 (?\202 ",")
927 (?\203 "f")
928 (?\204 ",,")
929 (?\205 "...")
930 (?\213 "<")
931 (?\214 "OE")
932 (?\221 "`")
933 (?\222 "'")
934 (?\223 "``")
935 (?\224 "\"")
936 (?\225 "*")
937 (?\226 "-")
938 (?\227 "--")
939 (?\230 "~")
940 (?\231 "(TM)")
941 (?\233 ">")
942 (?\234 "oe")
943 (?\264 "'"))
944 "Table for MS-to-Latin1 translation.")
946 (defcustom gnus-ignored-mime-types nil
947 "List of MIME types that should be ignored by Gnus."
948 :version "21.1"
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
952 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
953 "List of MIME types that should not be given buttons when rendered inline.
954 See also `gnus-buttonized-mime-types' which may override this variable.
955 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956 :version "21.1"
957 :group 'gnus-article-mime
958 :type '(repeat regexp))
960 (defcustom gnus-buttonized-mime-types nil
961 "List of MIME types that should be given buttons when rendered inline.
962 If set, this variable overrides `gnus-unbuttonized-mime-types'.
963 To see e.g. security buttons you could set this to
964 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
965 this list to display radio buttons that allow you to choose one of two
966 media types those mails include. See also `mm-discouraged-alternatives'.
967 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type '(repeat regexp))
972 (defcustom gnus-inhibit-mime-unbuttonizing nil
973 "If non-nil, all MIME parts get buttons.
974 When nil (the default value), then some MIME parts do not get buttons,
975 as described by the variables `gnus-buttonized-mime-types' and
976 `gnus-unbuttonized-mime-types'."
977 :version "22.1"
978 :group 'gnus-article-mime
979 :type 'boolean)
981 (defcustom gnus-body-boundary-delimiter "_"
982 "String used to delimit header and body.
983 This variable is used by `gnus-article-treat-body-boundary' which can
984 be controlled by `gnus-treat-body-boundary'."
985 :version "22.1"
986 :group 'gnus-article-various
987 :type '(choice (item :tag "None" :value nil)
988 string))
990 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991 "/usr/share/picons")
992 "Defines the location of the faces database.
993 For information on obtaining this database of pretty pictures, please
994 see http://www.cs.indiana.edu/picons/ftp/index.html"
995 :version "22.1"
996 :type '(repeat directory)
997 :link '(url-link :tag "download"
998 "http://www.cs.indiana.edu/picons/ftp/index.html")
999 :link '(custom-manual "(gnus)Picons")
1000 :group 'gnus-picon)
1002 (defun gnus-picons-installed-p ()
1003 "Say whether picons are installed on your machine."
1004 (let ((installed nil))
1005 (dolist (database gnus-picon-databases)
1006 (when (file-exists-p database)
1007 (setq installed t)))
1008 installed))
1010 (defcustom gnus-article-mime-part-function nil
1011 "Function called with a MIME handle as the argument.
1012 This is meant for people who want to do something automatic based
1013 on parts -- for instance, adding Vcard info to a database."
1014 :group 'gnus-article-mime
1015 :type '(choice (const nil)
1016 function))
1018 (defcustom gnus-mime-multipart-functions nil
1019 "An alist of MIME types to functions to display them."
1020 :version "21.1"
1021 :group 'gnus-article-mime
1022 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1024 (defcustom gnus-article-date-headers '(combined-lapsed)
1025 "A list of Date header formats to display.
1026 Valid formats are `ut' (universal time), `local' (local time
1027 zone), `english' (readable English), `lapsed' (elapsed time),
1028 `combined-lapsed' (both the original date and the elapsed time),
1029 `original' (the original date header), `iso8601' (ISO8601
1030 format), and `user-defined' (a user-defined format defined by the
1031 `gnus-article-time-format' variable).
1033 You have as many date headers as you want in the article buffer.
1034 Some of these headers are updated automatically. See
1035 `gnus-article-update-date-headers' for details."
1036 :version "24.1"
1037 :group 'gnus-article-headers
1038 :type '(set
1039 (const :tag "Universal time (UT)" ut)
1040 (const :tag "Local time zone" local)
1041 (const :tag "Readable English" english)
1042 (const :tag "Elapsed time" lapsed)
1043 (const :tag "Original and elapsed time" combined-lapsed)
1044 (const :tag "Original date header" original)
1045 (const :tag "ISO8601 format" iso8601)
1046 (const :tag "User-defined" user-defined)))
1048 (defcustom gnus-article-update-date-headers nil
1049 "A number that says how often to update the date header (in seconds).
1050 If nil, don't update it at all."
1051 :version "24.1"
1052 :group 'gnus-article-headers
1053 :type '(choice
1054 (item :tag "Don't update" :value nil)
1055 integer))
1057 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1058 "Function called with a MIME handle as the argument.
1059 This is meant for people who want to view first matched part.
1060 For `undisplayed-alternative' (default), the first undisplayed
1061 part or alternative part is used. For `undisplayed', the first
1062 undisplayed part is used. For a function, the first part which
1063 the function return t is used. For nil, the first part is
1064 used."
1065 :version "21.1"
1066 :group 'gnus-article-mime
1067 :type '(choice
1068 (item :tag "first" :value nil)
1069 (item :tag "undisplayed" :value undisplayed)
1070 (item :tag "undisplayed or alternative"
1071 :value undisplayed-alternative)
1072 (function)))
1074 (defcustom gnus-mime-action-alist
1075 '(("save to file" . gnus-mime-save-part)
1076 ("save and strip" . gnus-mime-save-part-and-strip)
1077 ("replace with file" . gnus-mime-replace-part)
1078 ("delete part" . gnus-mime-delete-part)
1079 ("display as text" . gnus-mime-inline-part)
1080 ("view the part" . gnus-mime-view-part)
1081 ("pipe to command" . gnus-mime-pipe-part)
1082 ("toggle display" . gnus-article-press-button)
1083 ("toggle display" . gnus-article-view-part-as-charset)
1084 ("view as type" . gnus-mime-view-part-as-type)
1085 ("view internally" . gnus-mime-view-part-internally)
1086 ("view externally" . gnus-mime-view-part-externally))
1087 "An alist of actions that run on the MIME attachment."
1088 :group 'gnus-article-mime
1089 :type '(repeat (cons (string :tag "name")
1090 (function))))
1092 (defcustom gnus-auto-select-part 1
1093 "Advance to next MIME part when deleting or stripping parts.
1095 When 0, point will be placed on the same part as before. When
1096 positive (negative), move point forward (backwards) this many
1097 parts. When nil, redisplay article."
1098 :version "23.1" ;; No Gnus
1099 :group 'gnus-article-mime
1100 :type '(choice (const nil :tag "Redisplay article.")
1101 (const 1 :tag "Next part.")
1102 (const 0 :tag "Current part.")
1103 integer))
1106 ;;; The treatment variables
1109 (defvar gnus-part-display-hook nil
1110 "Hook called on parts that are to receive treatment.")
1112 (defvar gnus-article-treat-custom
1113 '(choice (const :tag "Off" nil)
1114 (const :tag "On" t)
1115 (const :tag "Header" head)
1116 (const :tag "First" first)
1117 (const :tag "Last" last)
1118 (integer :tag "Less")
1119 (repeat :tag "Groups" regexp)
1120 (sexp :tag "Predicate")))
1122 (defvar gnus-article-treat-head-custom
1123 '(choice (const :tag "Off" nil)
1124 (const :tag "Header" head)))
1126 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 "text/x-patch" "text/html")
1128 "Part types eligible for treatment.")
1130 (defvar gnus-inhibit-treatment nil
1131 "Whether to inhibit treatment.")
1133 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1134 "Highlight the signature.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-signature 'highlight t)
1142 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1143 "Add buttons.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-custom)
1149 (put 'gnus-treat-buttonize 'highlight t)
1151 (defcustom gnus-treat-buttonize-head 'head
1152 "Add buttons to the head.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-head-custom)
1158 (put 'gnus-treat-buttonize-head 'highlight t)
1160 (defcustom gnus-treat-date 'head
1161 "Display dates according to the `gnus-article-date-headers' variable.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :version "24.1"
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
1167 :type gnus-article-treat-head-custom)
1169 (defcustom gnus-treat-emphasize 50000
1170 "Emphasize text.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :group 'gnus-article-treat
1174 :link '(custom-manual "(gnus)Customizing Articles")
1175 :type gnus-article-treat-custom)
1176 (put 'gnus-treat-emphasize 'highlight t)
1178 (defcustom gnus-treat-strip-cr nil
1179 "Remove carriage returns.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate. See Info node `(gnus)Customizing Articles'."
1182 :version "22.1"
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1187 (defcustom gnus-treat-unsplit-urls nil
1188 "Remove newlines from within URLs.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :version "22.1"
1192 :group 'gnus-article-treat
1193 :link '(custom-manual "(gnus)Customizing Articles")
1194 :type gnus-article-treat-custom)
1196 (defcustom gnus-treat-leading-whitespace nil
1197 "Remove leading whitespace in headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :version "22.1"
1201 :group 'gnus-article-treat
1202 :link '(custom-manual "(gnus)Customizing Articles")
1203 :type gnus-article-treat-custom)
1205 (defcustom gnus-treat-hide-headers 'head
1206 "Hide headers.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate. See Info node `(gnus)Customizing Articles'."
1209 :group 'gnus-article-treat
1210 :link '(custom-manual "(gnus)Customizing Articles")
1211 :type gnus-article-treat-head-custom)
1213 (defcustom gnus-treat-hide-boring-headers nil
1214 "Hide boring headers.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate. See Info node `(gnus)Customizing Articles'."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-head-custom)
1221 (defcustom gnus-treat-hide-signature nil
1222 "Hide the signature.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate. See Info node `(gnus)Customizing Articles'."
1225 :group 'gnus-article-treat
1226 :link '(custom-manual "(gnus)Customizing Articles")
1227 :type gnus-article-treat-custom)
1229 (defcustom gnus-treat-fill-article nil
1230 "Fill the article.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate. See Info node `(gnus)Customizing Articles'."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1237 (defcustom gnus-treat-hide-citation nil
1238 "Hide cited text.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate. See Info node `(gnus)Customizing Articles'.
1242 See `gnus-article-highlight-citation' for variables used to
1243 control what it hides."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1248 (defcustom gnus-treat-hide-citation-maybe nil
1249 "Hide cited text according to certain conditions.
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate. See Info node `(gnus)Customizing Articles'.
1253 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1254 how to control what it hides."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (defcustom gnus-treat-strip-list-identifiers 'head
1260 "Strip list identifiers from `gnus-list-identifiers'.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate. See Info node `(gnus)Customizing Articles'."
1263 :version "21.1"
1264 :group 'gnus-article-treat
1265 :link '(custom-manual "(gnus)Customizing Articles")
1266 :type gnus-article-treat-custom)
1268 (gnus-define-group-parameter
1269 list-identifier
1270 :variable-document
1271 "Alist of regexps and correspondent identifiers."
1272 :variable-group gnus-article-washing
1273 :parameter-type
1274 '(choice :tag "Identifier"
1275 :value nil
1276 (symbol :tag "Item in `gnus-list-identifiers'" none)
1277 regexp
1278 (const :tag "None" nil))
1279 :parameter-document
1280 "If non-nil, specify how to remove `identifiers' from articles' subject.
1282 Any symbol is used to look up a regular expression to match the
1283 banner in `gnus-list-identifiers'. A string is used as a regular
1284 expression to match the identifier directly.")
1286 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1287 "Gnus 5.10 (Emacs 22.1)")
1289 (defcustom gnus-treat-strip-pem nil
1290 "Strip PEM signatures.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate. See Info node `(gnus)Customizing Articles'."
1293 :group 'gnus-article-treat
1294 :link '(custom-manual "(gnus)Customizing Articles")
1295 :type gnus-article-treat-custom)
1297 (defcustom gnus-treat-strip-banner t
1298 "Strip banners from articles.
1299 The banner to be stripped is specified in the `banner' group parameter.
1300 Valid values are nil, t, `head', `first', `last', an integer or a
1301 predicate. See Info node `(gnus)Customizing Articles'."
1302 :group 'gnus-article-treat
1303 :link '(custom-manual "(gnus)Customizing Articles")
1304 :type gnus-article-treat-custom)
1306 (defcustom gnus-treat-highlight-headers 'head
1307 "Highlight the headers.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate. See Info node `(gnus)Customizing Articles'."
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-head-custom)
1313 (put 'gnus-treat-highlight-headers 'highlight t)
1315 (defcustom gnus-treat-highlight-citation t
1316 "Highlight cited text.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-custom)
1322 (put 'gnus-treat-highlight-citation 'highlight t)
1324 (defcustom gnus-treat-strip-headers-in-body t
1325 "Strip the X-No-Archive header line from the beginning of the body.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'."
1328 :version "21.1"
1329 :group 'gnus-article-treat
1330 :link '(custom-manual "(gnus)Customizing Articles")
1331 :type gnus-article-treat-custom)
1333 (defcustom gnus-treat-strip-trailing-blank-lines nil
1334 "Strip trailing blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate. See Info node `(gnus)Customizing Articles'.
1338 When set to t, it also strips trailing blanks in all MIME parts.
1339 Consider to use `last' instead."
1340 :group 'gnus-article-treat
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :type gnus-article-treat-custom)
1344 (defcustom gnus-treat-strip-leading-blank-lines nil
1345 "Strip leading blank lines.
1346 Valid values are nil, t, `head', `first', `last', an integer or a
1347 predicate. See Info node `(gnus)Customizing Articles'.
1349 When set to t, it also strips trailing blanks in all MIME parts."
1350 :group 'gnus-article-treat
1351 :link '(custom-manual "(gnus)Customizing Articles")
1352 :type gnus-article-treat-custom)
1354 (defcustom gnus-treat-strip-multiple-blank-lines nil
1355 "Strip multiple blank lines.
1356 Valid values are nil, t, `head', `first', `last', an integer or a
1357 predicate. See Info node `(gnus)Customizing Articles'."
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1362 (defcustom gnus-treat-unfold-headers 'head
1363 "Unfold folded header lines.
1364 Valid values are nil, t, `head', `first', `last', an integer or a
1365 predicate. See Info node `(gnus)Customizing Articles'."
1366 :version "22.1"
1367 :group 'gnus-article-treat
1368 :link '(custom-manual "(gnus)Customizing Articles")
1369 :type gnus-article-treat-custom)
1371 (defcustom gnus-article-unfold-long-headers nil
1372 "If non-nil, allow unfolding headers even if the header is long.
1373 If it is a regexp, only long headers matching this regexp are unfolded.
1374 If it is t, all long headers are unfolded.
1376 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1377 :version "23.1" ;; No Gnus
1378 :group 'gnus-article-treat
1379 :type '(choice (const nil)
1380 (const :tag "all" t)
1381 (regexp)))
1383 (defcustom gnus-treat-fold-headers nil
1384 "Fold headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles'."
1387 :version "22.1"
1388 :group 'gnus-article-treat
1389 :link '(custom-manual "(gnus)Customizing Articles")
1390 :type gnus-article-treat-custom)
1392 (defcustom gnus-treat-fold-newsgroups 'head
1393 "Fold the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :version "22.1"
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1401 (defcustom gnus-treat-overstrike t
1402 "Treat overstrike highlighting.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate. See Info node `(gnus)Customizing Articles'."
1405 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :type gnus-article-treat-custom)
1408 (put 'gnus-treat-overstrike 'highlight t)
1410 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1411 "Treat ANSI SGR control sequences.
1412 Valid values are nil, t, `head', `first', `last', an integer or a
1413 predicate. See Info node `(gnus)Customizing Articles'."
1414 :group 'gnus-article-treat
1415 :link '(custom-manual "(gnus)Customizing Articles")
1416 :type gnus-article-treat-custom)
1418 (make-obsolete-variable 'gnus-treat-display-xface
1419 'gnus-treat-display-x-face "Emacs 22.1")
1421 (defcustom gnus-treat-display-x-face
1422 (and (not noninteractive)
1423 (gnus-image-type-available-p 'xbm)
1424 (if (featurep 'xemacs)
1425 (featurep 'xface)
1426 (condition-case nil
1427 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1428 (executable-find "icontopbm"))
1429 ;; shell-command-to-string may signal an error, e.g. if
1430 ;; shell-file-name is not found.
1431 (error nil)))
1432 'head)
1433 "Display X-Face headers.
1434 Valid values are nil and `head'.
1435 See Info node `(gnus)Customizing Articles' and Info node
1436 `(gnus)X-Face' for details."
1437 :group 'gnus-article-treat
1438 :version "21.1"
1439 :link '(custom-manual "(gnus)Customizing Articles")
1440 :link '(custom-manual "(gnus)X-Face")
1441 :type gnus-article-treat-head-custom
1442 :set (lambda (symbol value)
1443 (set-default
1444 symbol
1445 (cond ((or (boundp symbol) (get symbol 'saved-value))
1446 value)
1447 ((boundp 'gnus-treat-display-xface)
1448 (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450 use gnus-treat-display-x-face instead")
1451 (default-value 'gnus-treat-display-xface))
1452 ((get 'gnus-treat-display-xface 'saved-value)
1453 (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455 use gnus-treat-display-x-face instead")
1456 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1458 value)))))
1459 (put 'gnus-treat-display-x-face 'highlight t)
1461 (defcustom gnus-treat-display-face
1462 (and (not noninteractive)
1463 (gnus-image-type-available-p 'png)
1464 'head)
1465 "Display Face headers.
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate. See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Face' for details."
1469 :group 'gnus-article-treat
1470 :version "22.1"
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :link '(custom-manual "(gnus)X-Face")
1473 :type gnus-article-treat-head-custom)
1474 (put 'gnus-treat-display-face 'highlight t)
1476 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477 "Display smileys.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Smileys' for details."
1481 :group 'gnus-article-treat
1482 :version "21.1"
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Smileys")
1485 :type gnus-article-treat-custom)
1486 (put 'gnus-treat-display-smileys 'highlight t)
1488 (defcustom gnus-treat-from-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in the From header.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-from-picon 'highlight t)
1504 (defcustom gnus-treat-mail-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in To and Cc headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-mail-picon 'highlight t)
1520 (defcustom gnus-treat-newsgroups-picon
1521 (if (and (gnus-image-type-available-p 'xpm)
1522 (gnus-picons-installed-p))
1523 'head nil)
1524 "Display picons in the Newsgroups and Followup-To headers.
1525 Valid values are nil, t, `head', `first', `last', an integer or a
1526 predicate. See Info node `(gnus)Customizing Articles' and Info
1527 node `(gnus)Picons' for details."
1528 :version "22.1"
1529 :group 'gnus-article-treat
1530 :group 'gnus-picon
1531 :link '(custom-manual "(gnus)Customizing Articles")
1532 :link '(custom-manual "(gnus)Picons")
1533 :type gnus-article-treat-head-custom)
1534 (put 'gnus-treat-newsgroups-picon 'highlight t)
1536 (defcustom gnus-treat-from-gravatar nil
1537 "Display gravatars in the From header.
1538 Valid values are nil, t, `head', `first', `last', an integer or a
1539 predicate. See Info node `(gnus)Customizing Articles' and Info
1540 node `(gnus)Gravatars' for details."
1541 :version "24.1"
1542 :group 'gnus-article-treat
1543 :group 'gnus-gravatar
1544 :link '(custom-manual "(gnus)Customizing Articles")
1545 :link '(custom-manual "(gnus)Gravatars")
1546 :type gnus-article-treat-head-custom)
1547 (put 'gnus-treat-from-gravatar 'highlight t)
1549 (defcustom gnus-treat-mail-gravatar nil
1550 "Display gravatars in To and Cc headers.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate. See Info node `(gnus)Customizing Articles' and Info
1553 node `(gnus)Gravatars' for details."
1554 :version "24.1"
1555 :group 'gnus-article-treat
1556 :group 'gnus-gravatar
1557 :link '(custom-manual "(gnus)Customizing Articles")
1558 :link '(custom-manual "(gnus)Gravatars")
1559 :type gnus-article-treat-head-custom)
1560 (put 'gnus-treat-mail-gravatar 'highlight t)
1562 (defcustom gnus-treat-body-boundary
1563 (if (or gnus-treat-newsgroups-picon
1564 gnus-treat-mail-picon
1565 gnus-treat-from-picon
1566 gnus-treat-from-gravatar
1567 gnus-treat-mail-gravatar)
1568 ;; If there's much decoration, the user might prefer a boundary.
1569 'head
1570 nil)
1571 "Draw a boundary at the end of the headers.
1572 Valid values are nil and `head'.
1573 See Info node `(gnus)Customizing Articles' for details."
1574 :version "22.1"
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-head-custom)
1579 (defcustom gnus-treat-capitalize-sentences nil
1580 "Capitalize sentence-starting words.
1581 Valid values are nil, t, `head', `first', `last', an integer or a
1582 predicate. See Info node `(gnus)Customizing Articles'."
1583 :version "21.1"
1584 :group 'gnus-article-treat
1585 :link '(custom-manual "(gnus)Customizing Articles")
1586 :type gnus-article-treat-custom)
1588 (defcustom gnus-treat-wash-html nil
1589 "Format as HTML.
1590 Valid values are nil, t, `head', `first', `last', an integer or a
1591 predicate. See Info node `(gnus)Customizing Articles'."
1592 :version "22.1"
1593 :group 'gnus-article-treat
1594 :link '(custom-manual "(gnus)Customizing Articles")
1595 :type gnus-article-treat-custom)
1597 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598 "Fill long lines.
1599 Valid values are nil, t, `head', `first', `last', an integer or a
1600 predicate. See Info node `(gnus)Customizing Articles'."
1601 :version "24.1"
1602 :group 'gnus-article-treat
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1606 (defcustom gnus-treat-x-pgp-sig nil
1607 "Verify X-PGP-Sig.
1608 To automatically treat X-PGP-Sig, set it to head.
1609 Valid values are nil, t, `head', `first', `last', an integer or a
1610 predicate. See Info node `(gnus)Customizing Articles'."
1611 :version "22.1"
1612 :group 'gnus-article-treat
1613 :group 'mime-security
1614 :link '(custom-manual "(gnus)Customizing Articles")
1615 :type gnus-article-treat-custom)
1617 (defvar gnus-article-encrypt-protocol-alist
1618 '(("PGP" . mml2015-self-encrypt)))
1620 ;; Set to nil if more than one protocol added to
1621 ;; gnus-article-encrypt-protocol-alist.
1622 (defcustom gnus-article-encrypt-protocol "PGP"
1623 "The protocol used for encrypt articles.
1624 It is a string, such as \"PGP\". If nil, ask user."
1625 :version "22.1"
1626 :type 'string
1627 :group 'mime-security)
1629 (defvar idna-program)
1631 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1632 (condition-case nil
1633 (require 'idna)
1634 (file-error)
1635 (invalid-operation))
1636 idna-program
1637 (executable-find idna-program))
1638 "Whether IDNA decoding of headers is used when viewing messages.
1639 This requires GNU Libidn, and by default only enabled if it is found."
1640 :version "22.1"
1641 :group 'gnus-article-headers
1642 :type 'boolean)
1644 (defcustom gnus-article-over-scroll nil
1645 "If non-nil, allow scrolling the article buffer even when there no more text."
1646 :version "22.1"
1647 :group 'gnus-article
1648 :type 'boolean)
1650 (defcustom gnus-inhibit-images nil
1651 "Non-nil means inhibit displaying of images inline in the article body."
1652 :version "24.1"
1653 :group 'gnus-article
1654 :type 'boolean)
1656 (defcustom gnus-blocked-images 'gnus-block-private-groups
1657 "Images that have URLs matching this regexp will be blocked.
1658 This can also be a function to be evaluated. If so, it will be
1659 called with the group name as the parameter, and should return a
1660 regexp."
1661 :version "24.1"
1662 :group 'gnus-art
1663 :type '(choice regexp function))
1665 ;;; Internal variables
1667 (defvar gnus-english-month-names
1668 '("January" "February" "March" "April" "May" "June" "July" "August"
1669 "September" "October" "November" "December"))
1671 (defvar article-goto-body-goes-to-point-min-p nil)
1672 (defvar gnus-article-wash-types nil)
1673 (defvar gnus-article-emphasis-alist nil)
1674 (defvar gnus-article-image-alist nil)
1676 (defvar gnus-article-mime-handle-alist-1 nil)
1677 (defvar gnus-treatment-function-alist
1678 '((gnus-treat-strip-cr gnus-article-remove-cr)
1679 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1680 (gnus-treat-strip-banner gnus-article-strip-banner)
1681 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1682 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1683 (gnus-treat-buttonize gnus-article-add-buttons)
1684 (gnus-treat-fill-article gnus-article-fill-cited-article)
1685 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1686 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1687 (gnus-treat-display-x-face gnus-article-display-x-face)
1688 (gnus-treat-display-face gnus-article-display-face)
1689 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1690 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1691 (gnus-treat-hide-signature gnus-article-hide-signature)
1692 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1693 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1694 (gnus-treat-from-picon gnus-treat-from-picon)
1695 (gnus-treat-mail-picon gnus-treat-mail-picon)
1696 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1697 (gnus-treat-strip-pem gnus-article-hide-pem)
1698 (gnus-treat-date gnus-article-treat-date)
1699 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1700 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1701 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1702 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1703 (gnus-treat-strip-trailing-blank-lines
1704 gnus-article-remove-trailing-blank-lines)
1705 (gnus-treat-strip-leading-blank-lines
1706 gnus-article-strip-leading-blank-lines)
1707 (gnus-treat-strip-multiple-blank-lines
1708 gnus-article-strip-multiple-blank-lines)
1709 (gnus-treat-overstrike gnus-article-treat-overstrike)
1710 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1711 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1712 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1713 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1714 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1715 (gnus-treat-display-smileys gnus-treat-smiley)
1716 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1717 (gnus-treat-wash-html gnus-article-wash-html)
1718 (gnus-treat-emphasize gnus-article-emphasize)
1719 (gnus-treat-hide-citation gnus-article-hide-citation)
1720 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1721 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1722 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1724 (defvar gnus-article-mime-handle-alist nil)
1725 (defvar article-lapsed-timer nil)
1726 (defvar gnus-article-current-summary nil)
1728 (defvar gnus-article-mode-syntax-table
1729 (let ((table (copy-syntax-table text-mode-syntax-table)))
1730 ;; This causes the citation match run O(2^n).
1731 ;; (modify-syntax-entry ?- "w" table)
1732 (modify-syntax-entry ?> ")<" table)
1733 (modify-syntax-entry ?< "(>" table)
1734 ;; make M-. in article buffers work for `foo' strings
1735 (modify-syntax-entry ?' " " table)
1736 (modify-syntax-entry ?` " " table)
1737 table)
1738 "Syntax table used in article mode buffers.
1739 Initialized from `text-mode-syntax-table'.")
1741 (defvar gnus-save-article-buffer nil)
1743 (defvar gnus-number-of-articles-to-be-saved nil)
1745 (defvar gnus-inhibit-hiding nil)
1747 (defvar gnus-article-edit-mode nil)
1749 ;;; Macros for dealing with the article buffer.
1751 (defmacro gnus-with-article-headers (&rest forms)
1752 `(with-current-buffer gnus-article-buffer
1753 (save-restriction
1754 (let ((inhibit-read-only t)
1755 (inhibit-point-motion-hooks t)
1756 (case-fold-search t))
1757 (article-narrow-to-head)
1758 ,@forms))))
1760 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1761 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1763 (defmacro gnus-with-article-buffer (&rest forms)
1764 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1765 (with-current-buffer gnus-article-buffer
1766 (let ((inhibit-read-only t))
1767 ,@forms))))
1769 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1770 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1772 (defun gnus-article-goto-header (header)
1773 "Go to HEADER, which is a regular expression."
1774 (re-search-forward (concat "^\\(" header "\\):") nil t))
1776 (defsubst gnus-article-hide-text (b e props)
1777 "Set text PROPS on the B to E region."
1778 (gnus-add-text-properties-when 'article-type nil b e props))
1780 (defsubst gnus-article-unhide-text (b e)
1781 "Remove hidden text properties from region between B and E."
1782 (remove-text-properties b e gnus-hidden-properties))
1784 (defun gnus-article-hide-text-type (b e type)
1785 "Hide text of TYPE between B and E."
1786 (gnus-add-wash-type type)
1787 (gnus-article-hide-text
1788 b e (cons 'article-type (cons type gnus-hidden-properties))))
1790 (defun gnus-article-unhide-text-type (b e type)
1791 "Unhide text of TYPE between B and E."
1792 (gnus-delete-wash-type type)
1793 (remove-text-properties
1794 b e (cons 'article-type (cons type gnus-hidden-properties))))
1796 (defun gnus-article-delete-text-of-type (type)
1797 "Delete text of TYPE in the current buffer."
1798 (save-excursion
1799 (let ((b (point-min)))
1800 (if (eq type 'multipart)
1801 ;; Remove MIME buttons associated with multipart/alternative parts.
1802 (progn
1803 (goto-char b)
1804 (while (if (get-text-property (point) 'gnus-part)
1805 (setq b (point))
1806 (when (setq b (next-single-property-change (point)
1807 'gnus-part))
1808 (goto-char b)
1810 (end-of-line)
1811 (skip-chars-forward "\n")
1812 (when (eq (get-text-property b 'article-type) 'multipart)
1813 (delete-region b (point)))))
1814 (while (setq b (text-property-any b (point-max) 'article-type type))
1815 (delete-region
1816 b (or (text-property-not-all b (point-max) 'article-type type)
1817 (point-max))))))))
1819 (defun gnus-article-delete-invisible-text ()
1820 "Delete all invisible text in the current buffer."
1821 (save-excursion
1822 (let ((b (point-min)))
1823 (while (setq b (text-property-any b (point-max) 'invisible t))
1824 (delete-region
1825 b (or (text-property-not-all b (point-max) 'invisible t)
1826 (point-max)))))))
1828 (defsubst gnus-article-header-rank ()
1829 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1830 (let ((list gnus-sorted-header-list)
1831 (i 1))
1832 (while list
1833 (if (looking-at (car list))
1834 (setq list nil)
1835 (setq list (cdr list))
1836 (incf i)))
1839 (defun article-hide-headers (&optional _arg _delete)
1840 "Hide unwanted headers and possibly sort them as well."
1841 (interactive)
1842 ;; This function might be inhibited.
1843 (unless gnus-inhibit-hiding
1844 (let ((inhibit-read-only t)
1845 (case-fold-search t)
1846 (max (1+ (length gnus-sorted-header-list)))
1847 (inhibit-point-motion-hooks t)
1848 (cur (current-buffer))
1849 ignored visible beg)
1850 (save-excursion
1851 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1852 ;; group parameters, so we should go to the summary buffer.
1853 (when (prog1
1854 (condition-case nil
1855 (progn (set-buffer gnus-summary-buffer) t)
1856 (error nil))
1857 (setq ignored (when (not gnus-visible-headers)
1858 (cond ((stringp gnus-ignored-headers)
1859 gnus-ignored-headers)
1860 ((listp gnus-ignored-headers)
1861 (mapconcat 'identity
1862 gnus-ignored-headers
1863 "\\|"))))
1864 visible (cond ((stringp gnus-visible-headers)
1865 gnus-visible-headers)
1866 ((and gnus-visible-headers
1867 (listp gnus-visible-headers))
1868 (mapconcat 'identity
1869 gnus-visible-headers
1870 "\\|")))))
1871 (set-buffer cur))
1872 (save-restriction
1873 ;; First we narrow to just the headers.
1874 (article-narrow-to-head)
1875 ;; Hide any "From " lines at the beginning of (mail) articles.
1876 (while (looking-at "From ")
1877 (forward-line 1))
1878 (unless (bobp)
1879 (delete-region (point-min) (point)))
1880 ;; Then treat the rest of the header lines.
1881 ;; Then we use the two regular expressions
1882 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1883 ;; select which header lines is to remain visible in the
1884 ;; article buffer.
1885 (while (re-search-forward "^[^ \t:]*:" nil t)
1886 (beginning-of-line)
1887 ;; Mark the rank of the header.
1888 (put-text-property
1889 (point) (1+ (point)) 'message-rank
1890 (if (or (and visible (looking-at visible))
1891 (and ignored
1892 (not (looking-at ignored))))
1893 (gnus-article-header-rank)
1894 (+ 2 max)))
1895 (forward-line 1))
1896 (message-sort-headers-1)
1897 (when (setq beg (text-property-any
1898 (point-min) (point-max) 'message-rank (+ 2 max)))
1899 ;; We delete the unwanted headers.
1900 (gnus-add-wash-type 'headers)
1901 (add-text-properties (point-min) (+ 5 (point-min))
1902 '(article-type headers dummy-invisible t))
1903 (delete-region beg (point-max))))))))
1905 (defun article-hide-boring-headers (&optional arg)
1906 "Toggle hiding of headers that aren't very interesting.
1907 If given a negative prefix, always show; if given a positive prefix,
1908 always hide."
1909 (interactive (gnus-article-hidden-arg))
1910 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1911 (not gnus-show-all-headers))
1912 (save-excursion
1913 (save-restriction
1914 (let ((inhibit-read-only t)
1915 (inhibit-point-motion-hooks t))
1916 (article-narrow-to-head)
1917 (dolist (elem gnus-boring-article-headers)
1918 (goto-char (point-min))
1919 (cond
1920 ;; Hide empty headers.
1921 ((eq elem 'empty)
1922 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1923 (forward-line -1)
1924 (gnus-article-hide-text-type
1925 (point-at-bol)
1926 (progn
1927 (end-of-line)
1928 (if (re-search-forward "^[^ \t]" nil t)
1929 (match-beginning 0)
1930 (point-max)))
1931 'boring-headers)))
1932 ;; Hide boring Newsgroups header.
1933 ((eq elem 'newsgroups)
1934 (when (gnus-string-equal
1935 (gnus-fetch-field "newsgroups")
1936 (gnus-group-real-name
1937 (if (boundp 'gnus-newsgroup-name)
1938 gnus-newsgroup-name
1939 "")))
1940 (gnus-article-hide-header "newsgroups")))
1941 ((eq elem 'to-address)
1942 (let ((to (message-fetch-field "to"))
1943 (to-address
1944 (gnus-parameter-to-address
1945 (if (boundp 'gnus-newsgroup-name)
1946 gnus-newsgroup-name ""))))
1947 (when (and to to-address
1948 (ignore-errors
1949 (gnus-string-equal
1950 ;; only one address in To
1951 (nth 1 (mail-extract-address-components to))
1952 to-address)))
1953 (gnus-article-hide-header "to"))))
1954 ((eq elem 'to-list)
1955 (let ((to (message-fetch-field "to"))
1956 (to-list
1957 (gnus-parameter-to-list
1958 (if (boundp 'gnus-newsgroup-name)
1959 gnus-newsgroup-name ""))))
1960 (when (and to to-list
1961 (ignore-errors
1962 (gnus-string-equal
1963 ;; only one address in To
1964 (nth 1 (mail-extract-address-components to))
1965 to-list)))
1966 (gnus-article-hide-header "to"))))
1967 ((eq elem 'cc-list)
1968 (let ((cc (message-fetch-field "cc"))
1969 (to-list
1970 (gnus-parameter-to-list
1971 (if (boundp 'gnus-newsgroup-name)
1972 gnus-newsgroup-name ""))))
1973 (when (and cc to-list
1974 (ignore-errors
1975 (gnus-string-equal
1976 ;; only one address in CC
1977 (nth 1 (mail-extract-address-components cc))
1978 to-list)))
1979 (gnus-article-hide-header "cc"))))
1980 ((eq elem 'followup-to)
1981 (when (gnus-string-equal
1982 (message-fetch-field "followup-to")
1983 (message-fetch-field "newsgroups"))
1984 (gnus-article-hide-header "followup-to")))
1985 ((eq elem 'reply-to)
1986 (if (gnus-group-find-parameter
1987 gnus-newsgroup-name 'broken-reply-to)
1988 (gnus-article-hide-header "reply-to")
1989 (let ((from (message-fetch-field "from"))
1990 (reply-to (message-fetch-field "reply-to")))
1991 (when
1992 (and
1993 from reply-to
1994 (ignore-errors
1995 (equal
1996 (sort (mapcar
1997 (lambda (x) (downcase (cadr x)))
1998 (mail-extract-address-components from t))
1999 'string<)
2000 (sort (mapcar
2001 (lambda (x) (downcase (cadr x)))
2002 (mail-extract-address-components reply-to t))
2003 'string<))))
2004 (gnus-article-hide-header "reply-to")))))
2005 ((eq elem 'date)
2006 (let ((date (with-current-buffer gnus-original-article-buffer
2007 ;; If date in `gnus-article-buffer' is localized
2008 ;; (`gnus-treat-date-user-defined'),
2009 ;; `days-between' might fail.
2010 (message-fetch-field "date"))))
2011 (when (and date
2012 (< (days-between (current-time-string) date)
2014 (gnus-article-hide-header "date"))))
2015 ((eq elem 'long-to)
2016 (let ((to (message-fetch-field "to"))
2017 (cc (message-fetch-field "cc")))
2018 (when (> (length to) 1024)
2019 (gnus-article-hide-header "to"))
2020 (when (> (length cc) 1024)
2021 (gnus-article-hide-header "cc"))))
2022 ((eq elem 'many-to)
2023 (let ((to-count 0)
2024 (cc-count 0))
2025 (goto-char (point-min))
2026 (while (re-search-forward "^to:" nil t)
2027 (setq to-count (1+ to-count)))
2028 (when (> to-count 1)
2029 (while (> to-count 0)
2030 (goto-char (point-min))
2031 (save-restriction
2032 (re-search-forward "^to:" nil nil to-count)
2033 (forward-line -1)
2034 (narrow-to-region (point) (point-max))
2035 (gnus-article-hide-header "to"))
2036 (setq to-count (1- to-count))))
2037 (goto-char (point-min))
2038 (while (re-search-forward "^cc:" nil t)
2039 (setq cc-count (1+ cc-count)))
2040 (when (> cc-count 1)
2041 (while (> cc-count 0)
2042 (goto-char (point-min))
2043 (save-restriction
2044 (re-search-forward "^cc:" nil nil cc-count)
2045 (forward-line -1)
2046 (narrow-to-region (point) (point-max))
2047 (gnus-article-hide-header "cc"))
2048 (setq cc-count (1- cc-count)))))))))))))
2050 (defun gnus-article-hide-header (header)
2051 (save-excursion
2052 (goto-char (point-min))
2053 (when (re-search-forward (concat "^" header ":") nil t)
2054 (gnus-article-hide-text-type
2055 (point-at-bol)
2056 (progn
2057 (end-of-line)
2058 (if (re-search-forward "^[^ \t]" nil t)
2059 (match-beginning 0)
2060 (point-max)))
2061 'boring-headers))))
2063 (defvar gnus-article-normalized-header-length 40
2064 "Length of normalized headers.")
2066 (defun article-normalize-headers ()
2067 "Make all header lines 40 characters long."
2068 (interactive)
2069 (let ((inhibit-read-only t)
2070 column)
2071 (save-excursion
2072 (save-restriction
2073 (article-narrow-to-head)
2074 (while (not (eobp))
2075 (cond
2076 ((< (setq column (- (point-at-eol) (point)))
2077 gnus-article-normalized-header-length)
2078 (end-of-line)
2079 (insert (make-string
2080 (- gnus-article-normalized-header-length column)
2081 ? )))
2082 ((> column gnus-article-normalized-header-length)
2083 (gnus-put-text-property
2084 (progn
2085 (forward-char gnus-article-normalized-header-length)
2086 (point))
2087 (point-at-eol)
2088 'invisible t))
2090 ;; Do nothing.
2092 (forward-line 1))))))
2094 (defun article-treat-dumbquotes ()
2095 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2096 Note that this function guesses whether a character is a sm*rtq**t* or
2097 not, so it should only be used interactively.
2099 Sm*rtq**t*s are M****s***'s unilateral extension to the
2100 iso-8859-1 character map in an attempt to provide more quoting
2101 characters. If you see something like \\222 or \\264 where
2102 you're expecting some kind of apostrophe or quotation mark, then
2103 try this wash."
2104 (interactive)
2105 (article-translate-strings gnus-article-dumbquotes-map))
2107 (defvar org-entities)
2109 (defun article-treat-non-ascii ()
2110 "Translate many Unicode characters into their ASCII equivalents."
2111 (interactive)
2112 (require 'org-entities)
2113 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2114 (dolist (elem org-entities)
2115 (when (and (listp elem)
2116 (= (length (nth 6 elem)) 1))
2117 (if (featurep 'xemacs)
2118 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2119 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2120 (save-excursion
2121 (when (article-goto-body)
2122 (let ((inhibit-read-only t)
2123 replace props)
2124 (while (not (eobp))
2125 (if (not (setq replace (if (featurep 'xemacs)
2126 (get-char-table (following-char) table)
2127 (aref table (following-char)))))
2128 (forward-char 1)
2129 (if (prog1
2130 (setq props (text-properties-at (point)))
2131 (delete-char 1))
2132 (add-text-properties (point) (progn (insert replace) (point))
2133 props)
2134 (insert replace)))))))))
2136 (defun article-translate-strings (map)
2137 "Translate all string in the body of the article according to MAP.
2138 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2139 (save-excursion
2140 (when (article-goto-body)
2141 (let ((inhibit-read-only t))
2142 (dolist (elem map)
2143 (let ((from (car elem))
2144 (to (cadr elem)))
2145 (save-excursion
2146 (if (stringp from)
2147 (while (search-forward from nil t)
2148 (replace-match to))
2149 (while (not (eobp))
2150 (if (eq (following-char) from)
2151 (progn
2152 (delete-char 1)
2153 (insert to))
2154 (forward-char 1)))))))))))
2156 (defun article-treat-overstrike ()
2157 "Translate overstrikes into bold text."
2158 (interactive)
2159 (save-excursion
2160 (when (article-goto-body)
2161 (let ((inhibit-read-only t))
2162 (while (search-forward "\b" nil t)
2163 (let ((next (char-after))
2164 (previous (char-after (- (point) 2))))
2165 ;; We do the boldification/underlining by hiding the
2166 ;; overstrikes and putting the proper text property
2167 ;; on the letters.
2168 (cond
2169 ((eq next previous)
2170 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2171 (put-text-property (point) (1+ (point)) 'face 'bold))
2172 ((eq next ?_)
2173 (gnus-article-hide-text-type
2174 (1- (point)) (1+ (point)) 'overstrike)
2175 (put-text-property
2176 (- (point) 2) (1- (point)) 'face 'underline))
2177 ((eq previous ?_)
2178 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2179 (put-text-property
2180 (point) (1+ (point)) 'face 'underline)))))))))
2182 (defun article-treat-ansi-sequences ()
2183 "Translate ANSI SGR control sequences into overlays or extents."
2184 (interactive)
2185 (save-excursion
2186 (when (article-goto-body)
2187 (let ((inhibit-read-only t))
2188 (ansi-color-apply-on-region (point) (point-max))))))
2190 (defun gnus-article-treat-unfold-headers ()
2191 "Unfold folded message headers.
2192 Only the headers that fit into the current window width will be
2193 unfolded."
2194 (interactive)
2195 (gnus-with-article-headers
2196 (let (length)
2197 (while (not (eobp))
2198 (save-restriction
2199 (mail-header-narrow-to-field)
2200 (let* ((header (buffer-string))
2201 (unfoldable
2202 (or (equal gnus-article-unfold-long-headers t)
2203 (and (stringp gnus-article-unfold-long-headers)
2204 (string-match gnus-article-unfold-long-headers
2205 header)))))
2206 (with-temp-buffer
2207 (insert header)
2208 (goto-char (point-min))
2209 (while (re-search-forward "\n[\t ]" nil t)
2210 (replace-match " " t t)))
2211 (setq length (- (point-max) (point-min) 1))
2212 (when (or unfoldable
2213 (< length (window-width)))
2214 (while (re-search-forward "\n[\t ]" nil t)
2215 (replace-match " " t t))))
2216 (goto-char (point-max)))))))
2218 (defun gnus-article-treat-fold-headers ()
2219 "Fold message headers."
2220 (interactive)
2221 (gnus-with-article-headers
2222 (while (not (eobp))
2223 (save-restriction
2224 (mail-header-narrow-to-field)
2225 (mail-header-fold-field)
2226 (goto-char (point-max))))))
2228 (defun gnus-treat-smiley ()
2229 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2230 (interactive)
2231 (gnus-with-article-buffer
2232 (if (memq 'smiley gnus-article-wash-types)
2233 (gnus-delete-images 'smiley)
2234 (article-goto-body)
2235 (let ((images (smiley-region (point) (point-max))))
2236 (when images
2237 (gnus-add-wash-type 'smiley)
2238 (dolist (image images)
2239 (gnus-add-image 'smiley image)))))))
2241 (defun gnus-article-remove-images ()
2242 "Remove all images from the article buffer."
2243 (interactive)
2244 (gnus-with-article-buffer
2245 (save-restriction
2246 (widen)
2247 (dolist (elem gnus-article-image-alist)
2248 (gnus-delete-images (car elem))))))
2250 (autoload 'w3m-toggle-inline-images "w3m")
2252 (defun gnus-article-show-images ()
2253 "Show any images that are in the HTML-rendered article buffer.
2254 This only works if the article in question is HTML."
2255 (interactive)
2256 (gnus-with-article-buffer
2257 (save-restriction
2258 (widen)
2259 (if (eq mm-text-html-renderer 'w3m)
2260 (let ((mm-inline-text-html-with-images nil))
2261 (w3m-toggle-inline-images))
2262 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2263 'image-displayer))
2264 (destructuring-bind (start end function) region
2265 (funcall function (get-text-property start 'image-url)
2266 start end)))))))
2268 (defun gnus-article-treat-fold-newsgroups ()
2269 "Unfold folded message headers.
2270 Only the headers that fit into the current window width will be
2271 unfolded."
2272 (interactive)
2273 (gnus-with-article-headers
2274 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2275 (save-restriction
2276 (mail-header-narrow-to-field)
2277 (while (re-search-forward ", *" nil t)
2278 (replace-match ", " t t))
2279 (mail-header-fold-field)
2280 (goto-char (point-max))))))
2282 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2283 "Value of `truncate-lines' in Gnus Article buffer.
2284 Valid values are nil, t, `head', `first', `last', an integer or a
2285 predicate. See Info node `(gnus)Customizing Articles'."
2286 :version "23.1" ;; No Gnus
2287 :group 'gnus-article
2288 ;; :link '(custom-manual "(gnus)Customizing Articles")
2289 :type 'boolean)
2291 (defun gnus-article-toggle-truncate-lines (&optional arg)
2292 "Toggle whether to fold or truncate long lines in article the buffer.
2293 If ARG is non-nil and not a number, toggle
2294 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2295 long lines if and only if arg is positive."
2296 (interactive "P")
2297 (cond
2298 ((and (numberp arg) (> arg 0))
2299 (setq gnus-article-truncate-lines t))
2300 ((numberp arg)
2301 (setq gnus-article-truncate-lines nil))
2302 (arg
2303 (setq gnus-article-truncate-lines
2304 (not gnus-article-truncate-lines))))
2305 (gnus-with-article-buffer
2306 (cond
2307 ((and (numberp arg) (> arg 0))
2308 (setq truncate-lines nil))
2309 ((numberp arg)
2310 (setq truncate-lines t)))
2311 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2312 ;; `toggle-truncate-lines' needs an argument.
2313 (toggle-truncate-lines)))
2315 (defun gnus-article-treat-body-boundary ()
2316 "Place a boundary line at the end of the headers."
2317 (interactive)
2318 (when (and gnus-body-boundary-delimiter
2319 (> (length gnus-body-boundary-delimiter) 0))
2320 (gnus-with-article-headers
2321 (goto-char (point-max))
2322 (let ((start (point)))
2323 (insert "X-Boundary: ")
2324 (gnus-add-text-properties start (point) gnus-hidden-properties)
2325 (insert (let (str (max (window-width)))
2326 (if (featurep 'xemacs)
2327 (setq max (1- max)))
2328 (while (>= max (length str))
2329 (setq str (concat str gnus-body-boundary-delimiter)))
2330 (substring str 0 max))
2331 "\n")
2332 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2334 (defun article-fill-long-lines ()
2335 "Fill lines that are wider than the window width."
2336 (interactive)
2337 (save-excursion
2338 (let ((inhibit-read-only t)
2339 (width (window-width (get-buffer-window (current-buffer)))))
2340 (save-restriction
2341 (article-goto-body)
2342 (let ((adaptive-fill-mode nil)) ;Why? -sm
2343 (while (not (eobp))
2344 (end-of-line)
2345 (when (>= (current-column) (min fill-column width))
2346 (narrow-to-region (min (1+ (point)) (point-max))
2347 (point-at-bol))
2348 (let ((goback (point-marker)))
2349 (fill-paragraph nil)
2350 (goto-char (marker-position goback)))
2351 (widen))
2352 (forward-line 1)))))))
2354 (defun article-capitalize-sentences ()
2355 "Capitalize the first word in each sentence."
2356 (interactive)
2357 (save-excursion
2358 (let ((inhibit-read-only t)
2359 (paragraph-start "^[\n\^L]"))
2360 (article-goto-body)
2361 (while (not (eobp))
2362 (capitalize-word 1)
2363 (forward-sentence)))))
2365 (defun article-remove-cr ()
2366 "Remove trailing CRs and then translate remaining CRs into LFs."
2367 (interactive)
2368 (save-excursion
2369 (let ((inhibit-read-only t))
2370 (goto-char (point-min))
2371 (while (re-search-forward "\r+$" nil t)
2372 (replace-match "" t t))
2373 (goto-char (point-min))
2374 (while (search-forward "\r" nil t)
2375 (replace-match "\n" t t)))))
2377 (defun article-remove-trailing-blank-lines ()
2378 "Remove all trailing blank lines from the article."
2379 (interactive)
2380 (save-excursion
2381 (let ((inhibit-read-only t))
2382 (goto-char (point-max))
2383 (delete-region
2384 (point)
2385 (progn
2386 (while (and (not (bobp))
2387 (looking-at "^[ \t]*$")
2388 (not (gnus-annotation-in-region-p
2389 (point) (point-at-eol))))
2390 (forward-line -1))
2391 (forward-line 1)
2392 (point))))))
2394 (defvar gnus-face-properties-alist)
2396 (defun article-display-face (&optional force)
2397 "Display any Face headers in the header."
2398 (interactive (list 'force))
2399 (let ((wash-face-p buffer-read-only))
2400 (gnus-with-article-headers
2401 ;; When displaying parts, this function can be called several times on
2402 ;; the same article, without any intended toggle semantic (as typing `W
2403 ;; D d' would have). So face deletion must occur only when we come from
2404 ;; an interactive command, that is when the *Article* buffer is
2405 ;; read-only.
2406 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2407 (gnus-delete-images 'face)
2408 (let ((from (message-fetch-field "from"))
2409 faces)
2410 (save-current-buffer
2411 (when (and wash-face-p
2412 (gnus-buffer-live-p gnus-original-article-buffer)
2413 (not (re-search-forward "^Face:[\t ]*" nil t)))
2414 (set-buffer gnus-original-article-buffer))
2415 (save-restriction
2416 (mail-narrow-to-head)
2417 (when (or force
2418 ;; Check whether this face is censored.
2419 (not (and gnus-article-x-face-too-ugly
2420 (or from
2421 (setq from (message-fetch-field "from")))
2422 (string-match gnus-article-x-face-too-ugly
2423 from))))
2424 (while (gnus-article-goto-header "Face")
2425 (push (mail-header-field-value) faces)))))
2426 (when faces
2427 (goto-char (point-min))
2428 (let (png image)
2429 (unless (setq from (gnus-article-goto-header "from"))
2430 (insert "From:")
2431 (setq from (point))
2432 (insert " [no `from' set]\n"))
2433 (while faces
2434 (when (setq png (gnus-convert-face-to-png (pop faces)))
2435 (setq image
2436 (apply 'gnus-create-image png 'png t
2437 (cdr (assq 'png gnus-face-properties-alist))))
2438 (goto-char from)
2439 (when image
2440 (gnus-add-wash-type 'face)
2441 (gnus-add-image 'face image)
2442 (gnus-put-image image nil 'face)))))))))))
2444 (defun article-display-x-face (&optional force)
2445 "Look for an X-Face header and display it if present."
2446 (interactive (list 'force))
2447 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2448 (gnus-with-article-headers
2449 ;; Delete the old process, if any.
2450 (when (process-status "article-x-face")
2451 (delete-process "article-x-face"))
2452 ;; See the comment in `article-display-face'.
2453 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2454 ;; We have already displayed X-Faces, so we remove them
2455 ;; instead.
2456 (gnus-delete-images 'xface)
2457 ;; Display X-Faces.
2458 (let ((from (message-fetch-field "from"))
2459 x-faces)
2460 (save-current-buffer
2461 (when (and wash-face-p
2462 (gnus-buffer-live-p gnus-original-article-buffer)
2463 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2464 ;; If type `W f', use gnus-original-article-buffer,
2465 ;; otherwise use the current buffer because displaying
2466 ;; RFC822 parts calls this function too.
2467 (set-buffer gnus-original-article-buffer))
2468 (save-restriction
2469 (mail-narrow-to-head)
2470 (and gnus-article-x-face-command
2471 (or force
2472 ;; Check whether this face is censored.
2473 (not (and gnus-article-x-face-too-ugly
2474 (or from
2475 (setq from (message-fetch-field "from")))
2476 (string-match gnus-article-x-face-too-ugly
2477 from))))
2478 (while (gnus-article-goto-header "X-Face")
2479 (push (mail-header-field-value) x-faces)))))
2480 (when x-faces
2481 ;; We display the face.
2482 (cond ((functionp gnus-article-x-face-command)
2483 ;; The command is a lisp function, so we call it.
2484 (mapc gnus-article-x-face-command x-faces))
2485 ((stringp gnus-article-x-face-command)
2486 ;; The command is a string, so we interpret the command
2487 ;; as a, well, command, and fork it off.
2488 (let ((process-connection-type nil))
2489 (gnus-set-process-query-on-exit-flag
2490 (start-process
2491 "article-x-face" nil shell-file-name
2492 shell-command-switch gnus-article-x-face-command)
2493 nil)
2494 ;; Sending multiple EOFs to xv doesn't work,
2495 ;; so we only do a single external face.
2496 (with-temp-buffer
2497 (insert (car x-faces))
2498 (process-send-region "article-x-face"
2499 (point-min) (point-max)))
2500 (process-send-eof "article-x-face")))
2502 (error "`%s' set to `%s' is not a function"
2503 gnus-article-x-face-command
2504 'gnus-article-x-face-command)))))))))
2506 (defun article-decode-mime-words ()
2507 "Decode all MIME-encoded words in the article."
2508 (interactive)
2509 (gnus-with-article-buffer
2510 (let ((inhibit-point-motion-hooks t)
2511 (mail-parse-charset gnus-newsgroup-charset)
2512 (mail-parse-ignored-charsets
2513 (with-current-buffer gnus-summary-buffer
2514 gnus-newsgroup-ignored-charsets)))
2515 (mail-decode-encoded-word-region (point-min) (point-max)))))
2517 (defun article-decode-charset (&optional prompt)
2518 "Decode charset-encoded text in the article.
2519 If PROMPT (the prefix), prompt for a coding system to use."
2520 (interactive "P")
2521 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2522 (inhibit-read-only t)
2523 (mail-parse-charset gnus-newsgroup-charset)
2524 (mail-parse-ignored-charsets
2525 (save-excursion (condition-case nil
2526 (set-buffer gnus-summary-buffer)
2527 (error))
2528 gnus-newsgroup-ignored-charsets))
2529 ct cte ctl charset format)
2530 (save-excursion
2531 (save-restriction
2532 (article-narrow-to-head)
2533 (setq ct (message-fetch-field "Content-Type" t)
2534 cte (message-fetch-field "Content-Transfer-Encoding" t)
2535 ctl (and ct (mail-header-parse-content-type ct))
2536 charset (cond
2537 (prompt
2538 (mm-read-coding-system "Charset to decode: "))
2539 (ctl
2540 (mail-content-type-get ctl 'charset)))
2541 format (and ctl (mail-content-type-get ctl 'format)))
2542 (when cte
2543 (setq cte (mail-header-strip cte)))
2544 (if (and ctl (not (string-match "/" (car ctl))))
2545 (setq ctl nil))
2546 (goto-char (point-max)))
2547 (forward-line 1)
2548 (save-restriction
2549 (narrow-to-region (point) (point-max))
2550 (when (and (eq mail-parse-charset 'gnus-decoded)
2551 (eq (mm-body-7-or-8) '8bit))
2552 ;; The text code could have been decoded.
2553 (setq charset mail-parse-charset))
2554 (when (and (or (not ctl)
2555 (equal (car ctl) "text/plain"))
2556 (not format)) ;; article with format will decode later.
2557 (mm-decode-body
2558 charset (and cte (intern (downcase
2559 (gnus-strip-whitespace cte))))
2560 (car ctl)))))))
2562 (defun article-decode-encoded-words ()
2563 "Remove encoded-word encoding from headers."
2564 (let ((inhibit-point-motion-hooks t)
2565 (mail-parse-charset gnus-newsgroup-charset)
2566 (mail-parse-ignored-charsets
2567 (save-excursion (condition-case nil
2568 (set-buffer gnus-summary-buffer)
2569 (error))
2570 gnus-newsgroup-ignored-charsets))
2571 (inhibit-read-only t)
2572 end start)
2573 (goto-char (point-min))
2574 (when (search-forward "\n\n" nil 'move)
2575 (forward-line -1))
2576 (setq end (point))
2577 (while (not (bobp))
2578 (while (progn
2579 (forward-line -1)
2580 (and (not (bobp))
2581 (memq (char-after) '(?\t ? )))))
2582 (setq start (point))
2583 (if (looking-at "\
2584 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2585 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2586 (funcall gnus-decode-address-function start end)
2587 (funcall gnus-decode-header-function start end))
2588 (goto-char (setq end start)))))
2590 (defun article-decode-group-name ()
2591 "Decode group names in Newsgroups, Followup-To and Xref headers."
2592 (let ((inhibit-point-motion-hooks t)
2593 (inhibit-read-only t)
2594 (method (gnus-find-method-for-group gnus-newsgroup-name))
2595 regexp)
2596 (when (and (or gnus-group-name-charset-method-alist
2597 gnus-group-name-charset-group-alist)
2598 (gnus-buffer-live-p gnus-original-article-buffer))
2599 (save-restriction
2600 (article-narrow-to-head)
2601 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2602 (with-current-buffer gnus-original-article-buffer
2603 (goto-char (point-min)))
2604 (setq regexp (concat "^" header
2605 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2606 (while (re-search-forward regexp nil t)
2607 (replace-match (save-match-data
2608 (gnus-decode-newsgroups
2609 ;; XXX how to use data in article buffer?
2610 (with-current-buffer gnus-original-article-buffer
2611 (re-search-forward regexp nil t)
2612 (match-string 1))
2613 gnus-newsgroup-name method))
2614 t t nil 1))
2615 (goto-char (point-min)))))))
2617 (autoload 'idna-to-unicode "idna")
2619 (defun article-decode-idna-rhs ()
2620 "Decode IDNA strings in RHS in various headers in current buffer.
2621 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2622 Mail-Reply-To: and Mail-Followup-To:."
2623 (when gnus-use-idna
2624 (save-restriction
2625 (let ((inhibit-point-motion-hooks t)
2626 (inhibit-read-only t))
2627 (article-narrow-to-head)
2628 (goto-char (point-min))
2629 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2630 (let (ace unicode)
2631 (when (save-match-data
2632 (and (setq ace (match-string 1))
2633 (save-excursion
2634 (and (re-search-backward "^[^ \t]" nil t)
2635 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2636 (setq unicode (idna-to-unicode ace))))
2637 (unless (string= ace unicode)
2638 (replace-match unicode nil nil nil 1)))))))))
2640 (defun article-de-quoted-unreadable (&optional force read-charset)
2641 "Translate a quoted-printable-encoded article.
2642 If FORCE, decode the article whether it is marked as quoted-printable
2643 or not.
2644 If READ-CHARSET, ask for a coding system."
2645 (interactive (list 'force current-prefix-arg))
2646 (save-excursion
2647 (let ((inhibit-read-only t) type charset)
2648 (if (gnus-buffer-live-p gnus-original-article-buffer)
2649 (with-current-buffer gnus-original-article-buffer
2650 (setq type
2651 (gnus-fetch-field "content-transfer-encoding"))
2652 (let* ((ct (gnus-fetch-field "content-type"))
2653 (ctl (and ct (mail-header-parse-content-type ct))))
2654 (setq charset (and ctl
2655 (mail-content-type-get ctl 'charset)))
2656 (if (stringp charset)
2657 (setq charset (intern (downcase charset)))))))
2658 (if read-charset
2659 (setq charset (mm-read-coding-system "Charset: " charset)))
2660 (unless charset
2661 (setq charset gnus-newsgroup-charset))
2662 (when (or force
2663 (and type (let ((case-fold-search t))
2664 (string-match "quoted-printable" type))))
2665 (article-goto-body)
2666 (quoted-printable-decode-region
2667 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2669 (defun article-de-base64-unreadable (&optional force read-charset)
2670 "Translate a base64 article.
2671 If FORCE, decode the article whether it is marked as base64 not.
2672 If READ-CHARSET, ask for a coding system."
2673 (interactive (list 'force current-prefix-arg))
2674 (save-excursion
2675 (let ((inhibit-read-only t) type charset)
2676 (if (gnus-buffer-live-p gnus-original-article-buffer)
2677 (with-current-buffer gnus-original-article-buffer
2678 (setq type
2679 (gnus-fetch-field "content-transfer-encoding"))
2680 (let* ((ct (gnus-fetch-field "content-type"))
2681 (ctl (and ct (mail-header-parse-content-type ct))))
2682 (setq charset (and ctl
2683 (mail-content-type-get ctl 'charset)))
2684 (if (stringp charset)
2685 (setq charset (intern (downcase charset)))))))
2686 (if read-charset
2687 (setq charset (mm-read-coding-system "Charset: " charset)))
2688 (unless charset
2689 (setq charset gnus-newsgroup-charset))
2690 (when (or force
2691 (and type (let ((case-fold-search t))
2692 (string-match "base64" type))))
2693 (article-goto-body)
2694 (save-restriction
2695 (narrow-to-region (point) (point-max))
2696 (base64-decode-region (point-min) (point-max))
2697 (mm-decode-coding-region
2698 (point-min) (point-max)
2699 (mm-charset-to-coding-system charset nil t)))))))
2701 (eval-when-compile
2702 (require 'rfc1843))
2704 (defun article-decode-HZ ()
2705 "Translate a HZ-encoded article."
2706 (interactive)
2707 (require 'rfc1843)
2708 (save-excursion
2709 (let ((inhibit-read-only t))
2710 (rfc1843-decode-region (point-min) (point-max)))))
2712 (defun article-unsplit-urls ()
2713 "Remove the newlines that some other mailers insert into URLs."
2714 (interactive)
2715 (save-excursion
2716 (let ((inhibit-read-only t))
2717 (goto-char (point-min))
2718 (while (re-search-forward
2719 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2720 (replace-match "\\1\\3" t)))
2721 (when (gmm-called-interactively-p 'any)
2722 (gnus-treat-article nil))))
2724 (defun article-wash-html ()
2725 "Format an HTML article."
2726 (interactive)
2727 (let ((handles nil)
2728 (buffer-read-only nil))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (setq handles (mm-dissect-buffer t t))))
2732 (article-goto-body)
2733 (delete-region (point) (point-max))
2734 (mm-enable-multibyte)
2735 (mm-inline-text-html handles)))
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2746 summary buffer."
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2759 (progn
2760 (or how (setq how gnus-article-browse-delete-temp))
2761 (if (eq how 'ask)
2762 (let ((files (length gnus-article-browse-html-temp-list)))
2763 (or (gnus-y-or-n-p
2764 (if (= files 1)
2765 "Delete the temporary HTML file? "
2766 (format "Delete all %s temporary HTML files? "
2767 files)))
2768 (setq gnus-article-browse-html-temp-list nil)))
2769 how)))
2770 (dolist (file gnus-article-browse-html-temp-list)
2771 (cond ((file-directory-p file)
2772 (when (or (not (eq how 'file))
2773 (gnus-y-or-n-p
2774 (format
2775 "Delete temporary HTML file(s) in directory `%s'? "
2776 (file-name-as-directory file))))
2777 (gnus-delete-directory file)))
2778 ((file-exists-p file)
2779 (when (or (not (eq how 'file))
2780 (gnus-y-or-n-p
2781 (format "Delete temporary HTML file `%s'? " file)))
2782 (delete-file file)))))
2783 ;; Also remove file from the list when not deleted or if file doesn't
2784 ;; exist anymore.
2785 (setq gnus-article-browse-html-temp-list nil))
2786 gnus-article-browse-html-temp-list)
2788 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2789 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2790 Return file name relative to the parent of DIRECTORY."
2791 (save-match-data
2792 (let (file afile)
2793 (catch 'found
2794 (dolist (handle handles)
2795 (cond
2796 ((not (listp handle)))
2797 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2798 ;; may create.
2799 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2800 ((equal (mm-handle-media-supertype handle) "multipart")
2801 (when (setq file (gnus-article-browse-html-save-cid-content
2802 cid handle directory))
2803 (throw 'found file)))
2804 ((equal (concat "<" cid ">") (mm-handle-id handle))
2805 (setq file (or (mm-handle-filename handle)
2806 (concat
2807 (make-temp-name "cid")
2808 (car (rassoc (car (mm-handle-type handle))
2809 mailcap-mime-extensions))))
2810 afile (expand-file-name file directory))
2811 (mm-save-part-to-file handle afile)
2812 (throw 'found (concat (file-name-nondirectory
2813 (directory-file-name directory))
2814 "/" file)))))))))
2816 (defun gnus-article-browse-html-parts (list &optional header)
2817 "View all \"text/html\" parts from LIST.
2818 Recurse into multiparts. The optional HEADER that should be a decoded
2819 message header will be added to the bodies of the \"text/html\" parts."
2820 ;; Internal function used by `gnus-article-browse-html-article'.
2821 (let (type file charset content cid-dir tmp-file showed)
2822 ;; Find and show the html-parts.
2823 (dolist (handle list)
2824 ;; If HTML, show it:
2825 (cond ((not (listp handle)))
2826 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2827 (and (equal (car type) "message/external-body")
2828 (or header
2829 (setq file (mm-handle-filename handle)))
2830 (or (mm-handle-cache handle)
2831 (condition-case code
2832 (progn (mm-extern-cache-contents handle) t)
2833 (error
2834 (gnus-message 3 "%s" (error-message-string code))
2835 (when (>= gnus-verbose 3) (sit-for 2))
2836 nil)))
2837 (progn
2838 (setq handle (mm-handle-cache handle)
2839 type (mm-handle-type handle))
2840 (equal (car type) "text/html"))))
2841 (setq charset (mail-content-type-get type 'charset)
2842 content (mm-get-part handle))
2843 (with-temp-buffer
2844 (if (eq charset 'gnus-decoded)
2845 (mm-enable-multibyte)
2846 (mm-disable-multibyte))
2847 (insert content)
2848 ;; resolve cid contents
2849 (let ((case-fold-search t)
2850 st base regexp cid-file)
2851 (goto-char (point-min))
2852 (when (and (re-search-forward "<head[\t\n >]" nil t)
2853 (progn
2854 (setq st (match-end 0))
2855 (re-search-forward "</head[\t\n >]" nil t))
2856 (re-search-backward "<base\
2857 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2858 (setq base (match-string 1))
2859 (replace-match "<!--\\&-->")
2860 (setq st (point))
2861 (dolist (tag '(("a" . "href") ("form" . "action")
2862 ("img" . "src")))
2863 (setq regexp (concat "<" (car tag)
2864 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2865 (cdr tag) "=\"\\([^\"]+\\)"))
2866 (while (re-search-forward regexp nil t)
2867 (insert (prog1
2868 (condition-case nil
2869 (save-match-data
2870 (url-expand-file-name (match-string 1)
2871 base))
2872 (error (match-string 1)))
2873 (delete-region (match-beginning 1)
2874 (match-end 1)))))
2875 (goto-char st)))
2876 (while (re-search-forward "\
2877 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2878 nil t)
2879 (unless cid-dir
2880 (setq cid-dir (mm-make-temp-file "cid" t))
2881 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2882 (setq file nil
2883 content nil)
2884 (when (setq cid-file
2885 (gnus-article-browse-html-save-cid-content
2886 (match-string 2)
2887 (with-current-buffer gnus-article-buffer
2888 gnus-article-mime-handles)
2889 cid-dir))
2890 (replace-match cid-file nil nil nil 1))))
2891 (unless content (setq content (buffer-string))))
2892 (when (or charset header (not file))
2893 (setq tmp-file (mm-make-temp-file
2894 ;; Do we need to care for 8.3 filenames?
2895 "mm-" nil ".html")))
2896 ;; Add a meta html tag to specify charset and a header.
2897 (cond
2898 (header
2899 (let (title eheader body hcharset coding)
2900 (with-temp-buffer
2901 (mm-enable-multibyte)
2902 (setq case-fold-search t)
2903 (insert header "\n")
2904 (setq title (message-fetch-field "subject"))
2905 (goto-char (point-min))
2906 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2907 nil t)
2908 (replace-match (cond ((match-beginning 1) "&lt;")
2909 ((match-beginning 2) "&gt;")
2910 ((match-beginning 3) "&amp;")
2911 (t "<br>\n"))))
2912 (goto-char (point-min))
2913 (while (re-search-forward "^[\t ]+" nil t)
2914 (dotimes (i (prog1
2915 (current-column)
2916 (delete-region (match-beginning 0)
2917 (match-end 0))))
2918 (insert "&nbsp;")))
2919 (goto-char (point-min))
2920 (insert "<div align=\"left\">\n")
2921 (goto-char (point-max))
2922 (insert "</div>\n<hr>\n")
2923 ;; We have to examine charset one by one since
2924 ;; charset specified in parts might be different.
2925 (if (eq charset 'gnus-decoded)
2926 (setq charset 'utf-8
2927 eheader (mm-encode-coding-string (buffer-string)
2928 charset)
2929 title (when title
2930 (mm-encode-coding-string title charset))
2931 body (mm-encode-coding-string content charset))
2932 (setq hcharset (mm-find-mime-charset-region (point-min)
2933 (point-max)))
2934 (cond ((= (length hcharset) 1)
2935 (setq hcharset (car hcharset)
2936 coding (mm-charset-to-coding-system
2937 hcharset nil t)))
2938 ((> (length hcharset) 1)
2939 (setq hcharset 'utf-8
2940 coding hcharset)))
2941 (if coding
2942 (if charset
2943 (progn
2944 (setq body
2945 (mm-charset-to-coding-system charset
2946 nil t))
2947 (if (eq coding body)
2948 (setq eheader (mm-encode-coding-string
2949 (buffer-string) coding)
2950 title (when title
2951 (mm-encode-coding-string
2952 title coding))
2953 body content)
2954 (setq charset 'utf-8
2955 eheader (mm-encode-coding-string
2956 (buffer-string) charset)
2957 title (when title
2958 (mm-encode-coding-string
2959 title charset))
2960 body (mm-encode-coding-string
2961 (mm-decode-coding-string
2962 content body)
2963 charset))))
2964 (setq charset hcharset
2965 eheader (mm-encode-coding-string
2966 (buffer-string) coding)
2967 title (when title
2968 (mm-encode-coding-string
2969 title coding))
2970 body content))
2971 (setq eheader (mm-string-as-unibyte (buffer-string))
2972 body content)))
2973 (erase-buffer)
2974 (mm-disable-multibyte)
2975 (insert body)
2976 (when charset
2977 (mm-add-meta-html-tag handle charset t))
2978 (when title
2979 (goto-char (point-min))
2980 (unless (search-forward "<title>" nil t)
2981 (re-search-forward "<head>\\s-*" nil t)
2982 (insert "<title>" title "</title>\n")))
2983 (goto-char (point-min))
2984 (or (re-search-forward
2985 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2986 (re-search-forward
2987 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2988 (insert eheader)
2989 (mm-write-region (point-min) (point-max)
2990 tmp-file nil nil nil 'binary t))))
2991 (charset
2992 (mm-with-unibyte-buffer
2993 (insert (if (eq charset 'gnus-decoded)
2994 (mm-encode-coding-string content
2995 (setq charset 'utf-8))
2996 content))
2997 (if (or (mm-add-meta-html-tag handle charset)
2998 (not file))
2999 (mm-write-region (point-min) (point-max)
3000 tmp-file nil nil nil 'binary t)
3001 (setq tmp-file nil))))
3002 (tmp-file
3003 (mm-save-part-to-file handle tmp-file)))
3004 (when tmp-file
3005 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3006 (add-hook 'gnus-summary-prepare-exit-hook
3007 'gnus-article-browse-delete-temp-files)
3008 (add-hook 'gnus-exit-gnus-hook
3009 (lambda ()
3010 (gnus-article-browse-delete-temp-files t)))
3011 ;; FIXME: Warn if there's an <img> tag?
3012 (browse-url-of-file (or tmp-file (expand-file-name file)))
3013 (setq showed t))
3014 ;; If multipart, recurse
3015 ((equal (mm-handle-media-supertype handle) "multipart")
3016 (when (gnus-article-browse-html-parts handle header)
3017 (setq showed t)))
3018 ((equal (mm-handle-media-type handle) "message/rfc822")
3019 (mm-with-multibyte-buffer
3020 (mm-insert-part handle)
3021 (setq handle (mm-dissect-buffer t t))
3022 (when (and (bufferp (car handle))
3023 (stringp (car (mm-handle-type handle))))
3024 (setq handle (list handle)))
3025 (when header
3026 (article-decode-encoded-words)
3027 (let ((gnus-visible-headers
3028 (or (get 'gnus-visible-headers 'standard-value)
3029 gnus-visible-headers)))
3030 (article-hide-headers))
3031 (goto-char (point-min))
3032 (search-forward "\n\n" nil 'move)
3033 (skip-chars-backward "\t\n ")
3034 (setq header (buffer-substring (point-min) (point)))))
3035 (when (prog1
3036 (gnus-article-browse-html-parts handle header)
3037 (mm-destroy-parts handle))
3038 (setq showed t)))))
3039 showed))
3041 (defun gnus-article-browse-html-article (&optional arg)
3042 "View \"text/html\" parts of the current article with a WWW browser.
3043 Inline images embedded in a message using the cid scheme, as they are
3044 generally considered to be safe, will be processed properly.
3045 The message header is added to the beginning of every html part unless
3046 the prefix argument ARG is given.
3048 Warning: Spammers use links to images (using the http scheme) in HTML
3049 articles to verify whether you have read the message. As
3050 `gnus-article-browse-html-article' passes the HTML content to the
3051 browser without eliminating these \"web bugs\" you should only
3052 use it for mails from trusted senders.
3054 If you always want to display HTML parts in the browser, set
3055 `mm-text-html-renderer' to nil.
3057 This command creates temporary files to pass HTML contents including
3058 images if any to the browser, and deletes them when exiting the group
3059 \(if you want)."
3060 ;; Cf. `mm-w3m-safe-url-regexp'
3061 (interactive "P")
3062 (if arg
3063 (gnus-summary-show-article)
3064 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3065 gnus-visible-headers))
3066 ;; As we insert a <hr>, there's no need for the body boundary.
3067 (gnus-treat-body-boundary nil))
3068 (gnus-summary-show-article)))
3069 (with-current-buffer gnus-article-buffer
3070 (let ((header (unless arg
3071 (save-restriction
3072 (widen)
3073 (buffer-substring-no-properties
3074 (goto-char (point-min))
3075 (if (search-forward "\n\n" nil t)
3076 (match-beginning 0)
3077 (goto-char (point-max))
3078 (skip-chars-backward "\t\n ")
3079 (point))))))
3080 parts)
3081 (set-buffer gnus-original-article-buffer)
3082 (setq parts (mm-dissect-buffer t t))
3083 ;; If singlepart, enforce a list.
3084 (when (and (bufferp (car parts))
3085 (stringp (car (mm-handle-type parts))))
3086 (setq parts (list parts)))
3087 ;; Process the list
3088 (unless (gnus-article-browse-html-parts parts header)
3089 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3090 (mm-destroy-parts parts)
3091 (unless arg
3092 (gnus-summary-show-article)))))
3094 (defun article-hide-list-identifiers ()
3095 "Remove list identifiers from the Subject header.
3096 The `gnus-list-identifiers' variable specifies what to do."
3097 (interactive)
3098 (let ((inhibit-point-motion-hooks t)
3099 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3100 (inhibit-read-only t))
3101 (when regexp
3102 (save-excursion
3103 (save-restriction
3104 (article-narrow-to-head)
3105 (goto-char (point-min))
3106 (while (re-search-forward
3107 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3108 nil t)
3109 (delete-region (match-beginning 2) (match-end 0))
3110 (beginning-of-line))
3111 (when (re-search-forward
3112 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3113 (delete-region (match-beginning 1) (match-end 1))))))))
3115 (defun article-hide-pem (&optional arg)
3116 "Toggle hiding of any PEM headers and signatures in the current article.
3117 If given a negative prefix, always show; if given a positive prefix,
3118 always hide."
3119 (interactive (gnus-article-hidden-arg))
3120 (unless (gnus-article-check-hidden-text 'pem arg)
3121 (save-excursion
3122 (let ((inhibit-read-only t) end)
3123 (goto-char (point-min))
3124 ;; Hide the horrendously ugly "header".
3125 (when (and (search-forward
3126 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3127 nil t)
3128 (setq end (1+ (match-beginning 0))))
3129 (gnus-add-wash-type 'pem)
3130 (gnus-article-hide-text-type
3132 (if (search-forward "\n\n" nil t)
3133 (match-end 0)
3134 (point-max))
3135 'pem)
3136 ;; Hide the trailer as well
3137 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3138 nil t)
3139 (gnus-article-hide-text-type
3140 (match-beginning 0) (match-end 0) 'pem)))))))
3142 (defun article-strip-banner ()
3143 "Strip the banners specified by the `banner' group parameter and by
3144 `gnus-article-address-banner-alist'."
3145 (interactive)
3146 (save-excursion
3147 (save-restriction
3148 (let ((inhibit-point-motion-hooks t))
3149 (when (gnus-parameter-banner gnus-newsgroup-name)
3150 (article-really-strip-banner
3151 (gnus-parameter-banner gnus-newsgroup-name)))
3152 (when gnus-article-address-banner-alist
3153 ;; Note that the From header is decoded here, so it is
3154 ;; required that the *-extract-address-components function
3155 ;; supports non-ASCII text.
3156 (let ((from (save-restriction
3157 (widen)
3158 (article-narrow-to-head)
3159 (mail-fetch-field "from"))))
3160 (when (and from
3161 (setq from
3162 (cadr (funcall gnus-extract-address-components
3163 from))))
3164 (catch 'found
3165 (dolist (pair gnus-article-address-banner-alist)
3166 (when (string-match (car pair) from)
3167 (throw 'found
3168 (article-really-strip-banner (cdr pair)))))))))))))
3170 (defun article-really-strip-banner (banner)
3171 "Strip the banner specified by the argument."
3172 (save-excursion
3173 (save-restriction
3174 (let ((inhibit-point-motion-hooks t)
3175 (gnus-signature-limit nil)
3176 (inhibit-read-only t))
3177 (article-goto-body)
3178 (cond
3179 ((eq banner 'signature)
3180 (when (gnus-article-narrow-to-signature)
3181 (widen)
3182 (forward-line -1)
3183 (delete-region (point) (point-max))))
3184 ((symbolp banner)
3185 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3186 (while (re-search-forward banner nil t)
3187 (delete-region (match-beginning 0) (match-end 0)))))
3188 ((stringp banner)
3189 (while (re-search-forward banner nil t)
3190 (delete-region (match-beginning 0) (match-end 0)))))))))
3192 (defun article-babel ()
3193 "Translate article using an online translation service."
3194 (interactive)
3195 (require 'babel)
3196 (gnus-with-article-buffer
3197 (when (article-goto-body)
3198 (let* ((start (point))
3199 (end (point-max))
3200 (orig (buffer-substring start end))
3201 (trans (babel-as-string orig)))
3202 (save-restriction
3203 (narrow-to-region start end)
3204 (delete-region start end)
3205 (insert trans))))))
3207 (defun article-hide-signature (&optional arg)
3208 "Hide the signature in the current article.
3209 If given a negative prefix, always show; if given a positive prefix,
3210 always hide."
3211 (interactive (gnus-article-hidden-arg))
3212 (unless (gnus-article-check-hidden-text 'signature arg)
3213 (save-excursion
3214 (save-restriction
3215 (let ((inhibit-read-only t))
3216 (when (gnus-article-narrow-to-signature)
3217 (gnus-article-hide-text-type
3218 (point-min) (point-max) 'signature))))))
3219 (gnus-set-mode-line 'article))
3221 (defun article-strip-headers-in-body ()
3222 "Strip offensive headers from bodies."
3223 (interactive)
3224 (save-excursion
3225 (article-goto-body)
3226 (let ((case-fold-search t))
3227 (when (looking-at "x-no-archive:")
3228 (gnus-delete-line)))))
3230 (defun article-strip-leading-blank-lines ()
3231 "Remove all blank lines from the beginning of the article."
3232 (interactive)
3233 (save-excursion
3234 (let ((inhibit-point-motion-hooks t)
3235 (inhibit-read-only t))
3236 (when (article-goto-body)
3237 (while (and (not (eobp))
3238 (looking-at "[ \t]*$"))
3239 (gnus-delete-line))))))
3241 (defun article-narrow-to-head ()
3242 "Narrow the buffer to the head of the message.
3243 Point is left at the beginning of the narrowed-to region."
3244 (narrow-to-region
3245 (goto-char (point-min))
3246 (cond
3247 ;; Absolutely no headers displayed.
3248 ((looking-at "\n")
3249 (point))
3250 ;; Normal headers.
3251 ((search-forward "\n\n" nil 1)
3252 (1- (point)))
3253 ;; Nothing but headers.
3255 (point-max))))
3256 (goto-char (point-min)))
3258 (defun article-goto-body ()
3259 "Place point at the start of the body."
3260 (goto-char (point-min))
3261 (cond
3262 ;; This variable is only bound when dealing with separate
3263 ;; MIME body parts.
3264 (article-goto-body-goes-to-point-min-p
3266 ((search-forward "\n\n" nil t)
3269 (goto-char (point-max))
3270 nil)))
3272 (defun article-strip-multiple-blank-lines ()
3273 "Replace consecutive blank lines with one empty line."
3274 (interactive)
3275 (save-excursion
3276 (let ((inhibit-point-motion-hooks t)
3277 (inhibit-read-only t))
3278 ;; First make all blank lines empty.
3279 (article-goto-body)
3280 (while (re-search-forward "^[ \t]+$" nil t)
3281 (unless (gnus-annotation-in-region-p
3282 (match-beginning 0) (match-end 0))
3283 (replace-match "" nil t)))
3284 ;; Then replace multiple empty lines with a single empty line.
3285 (article-goto-body)
3286 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3287 (unless (gnus-annotation-in-region-p
3288 (match-beginning 0) (match-end 0))
3289 (delete-region (match-beginning 1) (match-end 1)))))))
3291 (defun article-strip-leading-space ()
3292 "Remove all white space from the beginning of the lines in the article."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "^[ \t]+" nil t)
3299 (replace-match "" t t)))))
3301 (defun article-strip-trailing-space ()
3302 "Remove all white space from the end of the lines in the article."
3303 (interactive)
3304 (save-excursion
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3307 (article-goto-body)
3308 (while (re-search-forward "[ \t]+$" nil t)
3309 (replace-match "" t t)))))
3311 (defun article-strip-blank-lines ()
3312 "Strip leading, trailing and multiple blank lines."
3313 (interactive)
3314 (article-strip-leading-blank-lines)
3315 (article-remove-trailing-blank-lines)
3316 (article-strip-multiple-blank-lines))
3318 (defun article-strip-all-blank-lines ()
3319 "Strip all blank lines."
3320 (interactive)
3321 (save-excursion
3322 (let ((inhibit-point-motion-hooks t)
3323 (inhibit-read-only t))
3324 (article-goto-body)
3325 (while (re-search-forward "^[ \t]*\n" nil t)
3326 (replace-match "" t t)))))
3328 (defun gnus-article-narrow-to-signature ()
3329 "Narrow to the signature; return t if a signature is found, else nil."
3330 (let ((inhibit-point-motion-hooks t))
3331 (when (gnus-article-search-signature)
3332 (forward-line 1)
3333 ;; Check whether we have some limits to what we consider
3334 ;; to be a signature.
3335 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3336 (list gnus-signature-limit)))
3337 limit limited)
3338 (while (setq limit (pop limits))
3339 (if (or (and (integerp limit)
3340 (< (- (point-max) (point)) limit))
3341 (and (floatp limit)
3342 (< (count-lines (point) (point-max)) limit))
3343 (and (functionp limit)
3344 (funcall limit))
3345 (and (stringp limit)
3346 (not (re-search-forward limit nil t))))
3347 () ; This limit did not succeed.
3348 (setq limited t
3349 limits nil)))
3350 (unless limited
3351 (narrow-to-region (point) (point-max))
3352 t)))))
3354 (defun gnus-article-search-signature ()
3355 "Search the current buffer for the signature separator.
3356 Put point at the beginning of the signature separator."
3357 (let ((cur (point)))
3358 (goto-char (point-max))
3359 (if (if (stringp gnus-signature-separator)
3360 (re-search-backward gnus-signature-separator nil t)
3361 (let ((seps gnus-signature-separator))
3362 (while (and seps
3363 (not (re-search-backward (car seps) nil t)))
3364 (pop seps))
3365 seps))
3367 (goto-char cur)
3368 nil)))
3370 (defun gnus-article-hidden-arg ()
3371 "Return the current prefix arg as a number, or 0 if no prefix."
3372 (list (if current-prefix-arg
3373 (prefix-numeric-value current-prefix-arg)
3374 0)))
3376 (defun gnus-article-check-hidden-text (type arg)
3377 "Return nil if hiding is necessary.
3378 Arg can be nil or a number. nil and positive means hide, negative
3379 means show, 0 means toggle."
3380 (save-excursion
3381 (save-restriction
3382 (let ((hide (gnus-article-hidden-text-p type)))
3383 (cond
3384 ((or (null arg)
3385 (> arg 0))
3386 nil)
3387 ((< arg 0)
3388 (gnus-article-show-hidden-text type)
3391 (if (eq hide 'hidden)
3392 (progn
3393 (gnus-article-show-hidden-text type)
3395 nil)))))))
3397 (defun gnus-article-hidden-text-p (type)
3398 "Say whether the current buffer contains hidden text of type TYPE."
3399 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3400 (while (and pos
3401 (not (get-text-property pos 'invisible))
3402 (not (get-text-property pos 'dummy-invisible)))
3403 (setq pos
3404 (text-property-any (1+ pos) (point-max) 'article-type type)))
3405 (if pos
3406 'hidden
3407 nil)))
3409 (defun gnus-article-show-hidden-text (type &optional _dummy)
3410 "Show all hidden text of type TYPE.
3411 Originally it is hide instead of DUMMY."
3412 (let ((inhibit-read-only t)
3413 (inhibit-point-motion-hooks t))
3414 (gnus-remove-text-properties-when
3415 'article-type type
3416 (point-min) (point-max)
3417 (cons 'article-type (cons type
3418 gnus-hidden-properties)))
3419 (gnus-delete-wash-type type)))
3421 (defconst article-time-units
3422 `((year . ,(* 365.25 24 60 60))
3423 (week . ,(* 7 24 60 60))
3424 (day . ,(* 24 60 60))
3425 (hour . ,(* 60 60))
3426 (minute . 60)
3427 (second . 1))
3428 "Mapping from time units to seconds.")
3430 (defun gnus-article-forward-header ()
3431 "Move point to the start of the next header.
3432 If the current header is a continuation header, this can be several
3433 lines forward."
3434 (let ((ended nil))
3435 (while (not ended)
3436 (forward-line 1)
3437 (if (looking-at "[ \t]+[^ \t]")
3438 (forward-line 1)
3439 (setq ended t)))))
3441 (defun article-treat-date ()
3442 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3443 (with-current-buffer gnus-summary-buffer
3444 gnus-article-date-headers)
3445 gnus-article-date-headers)
3448 (defun article-date-ut (&optional type _highlight date-position)
3449 "Convert DATE date to TYPE in the current article.
3450 The default type is `ut'. See `gnus-article-date-headers' for
3451 possible values."
3452 (interactive (list 'ut t))
3453 (let* ((case-fold-search t)
3454 (inhibit-read-only t)
3455 (inhibit-point-motion-hooks t)
3456 (visible-date (mail-fetch-field "Date"))
3457 pos date bface eface)
3458 (save-excursion
3459 (if date-position
3460 (progn
3461 (goto-char date-position)
3462 (setq date (get-text-property (point) 'original-date))
3463 (when (looking-at "[^:]+:[\t ]*")
3464 (setq bface (get-text-property (match-beginning 0) 'face)
3465 eface (get-text-property (match-end 0) 'face)))
3466 (delete-region (point)
3467 (progn
3468 (gnus-article-forward-header)
3469 (point)))
3470 (article-transform-date date type bface eface))
3471 (save-restriction
3472 (widen)
3473 (goto-char (point-min))
3474 (while (or (get-text-property (setq pos (point)) 'original-date)
3475 (and (setq pos (next-single-property-change
3476 (point) 'original-date))
3477 (goto-char pos)))
3478 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3479 (1+ (match-beginning 0))
3480 (point-max)))
3481 (while (setq pos (text-property-not-all pos (point-max)
3482 'gnus-date-type nil))
3483 (setq date (get-text-property pos 'original-date))
3484 (goto-char pos)
3485 (when (looking-at "[^:]+:[\t ]*")
3486 (setq bface (get-text-property (match-beginning 0) 'face)
3487 eface (get-text-property (match-end 0) 'face)))
3488 (delete-region pos (or (text-property-any pos (point-max)
3489 'gnus-date-type nil)
3490 (point-max))))
3491 (unless date ;; the 1st time
3492 (goto-char (point-min))
3493 (while (re-search-forward "^Date:[\t ]*" nil t)
3494 (setq date (get-text-property (match-beginning 0)
3495 'original-date)
3496 bface (get-text-property (match-beginning 0) 'face)
3497 eface (get-text-property (match-end 0) 'face))
3498 (delete-region (point-at-bol) (progn
3499 (gnus-article-forward-header)
3500 (point)))))
3501 (when (and (not date)
3502 visible-date)
3503 (setq date visible-date))
3504 (when date
3505 (article-transform-date date type bface eface))
3506 (goto-char (point-max))
3507 (widen)))))))
3509 (defun article-transform-date (date type bface eface)
3510 (dolist (this-type (cond
3511 ((null type)
3512 (list 'ut))
3513 ((atom type)
3514 (list type))
3516 type)))
3517 (goto-char
3518 (prog1
3519 (point)
3520 (add-text-properties
3521 (point)
3522 (progn
3523 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3524 (point))
3525 (list 'original-date date 'gnus-date-type this-type))))
3526 ;; Do highlighting.
3527 (when (looking-at
3528 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3529 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3530 (when (match-beginning 2)
3531 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3532 (while (and (zerop (forward-line 1))
3533 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3534 (when (match-beginning 1)
3535 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3537 (defun article-make-date-line (date type)
3538 "Return a DATE line of TYPE."
3539 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3540 combined-lapsed))
3541 (error "Unknown conversion type: %s" type))
3542 (condition-case ()
3543 (let ((time (ignore-errors (date-to-time date))))
3544 (cond
3545 ;; Convert to the local timezone.
3546 ((eq type 'local)
3547 (concat "Date: " (message-make-date time)))
3548 ;; Convert to Universal Time.
3549 ((eq type 'ut)
3550 (concat "Date: "
3551 (substring
3552 (message-make-date
3553 (let* ((e (parse-time-string date))
3554 (tm (apply 'encode-time e))
3555 (ms (car tm))
3556 (ls (- (cadr tm) (car (current-time-zone time)))))
3557 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3558 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3559 (t (list ms ls)))))
3560 0 -5)
3561 "UT"))
3562 ;; Get the original date from the article.
3563 ((eq type 'original)
3564 (concat "Date: " (if (string-match "\n+$" date)
3565 (substring date 0 (match-beginning 0))
3566 date)))
3567 ;; Let the user define the format.
3568 ((eq type 'user-defined)
3569 (let ((format (or (condition-case nil
3570 (with-current-buffer gnus-summary-buffer
3571 gnus-article-time-format)
3572 (error nil))
3573 gnus-article-time-format)))
3574 (if (functionp format)
3575 (funcall format time)
3576 (concat "Date: " (format-time-string format time)))))
3577 ;; ISO 8601.
3578 ((eq type 'iso8601)
3579 (let ((tz (car (current-time-zone time))))
3580 (concat
3581 "Date: "
3582 (format-time-string "%Y%m%dT%H%M%S" time)
3583 (format "%s%02d%02d"
3584 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3585 (/ (% (abs tz) 3600) 60)))))
3586 ;; Do a lapsed format.
3587 ((eq type 'lapsed)
3588 (concat "Date: " (article-lapsed-string time)))
3589 ;; A combined date/lapsed format.
3590 ((eq type 'combined-lapsed)
3591 (let ((date-string (article-make-date-line date 'original))
3592 (segments 3)
3593 lapsed-string)
3594 (while (and
3595 time
3596 (setq lapsed-string
3597 (concat " (" (article-lapsed-string time segments) ")"))
3598 (> (+ (length date-string)
3599 (length lapsed-string))
3600 (+ fill-column 6))
3601 (> segments 0))
3602 (setq segments (1- segments)))
3603 (if (> segments 0)
3604 (concat date-string lapsed-string)
3605 date-string)))
3606 ;; Display the date in proper English
3607 ((eq type 'english)
3608 (let ((dtime (decode-time time)))
3609 (concat
3610 "Date: the "
3611 (number-to-string (nth 3 dtime))
3612 (let ((digit (% (nth 3 dtime) 10)))
3613 (cond
3614 ((memq (nth 3 dtime) '(11 12 13)) "th")
3615 ((= digit 1) "st")
3616 ((= digit 2) "nd")
3617 ((= digit 3) "rd")
3618 (t "th")))
3619 " of "
3620 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3622 (number-to-string (nth 5 dtime))
3623 " at "
3624 (format "%02d" (nth 2 dtime))
3626 (format "%02d" (nth 1 dtime)))))))
3627 (foo
3628 (format "Date: %s (from Gnus)" date))))
3630 (defun article-lapsed-string (time &optional max-segments)
3631 ;; If the date is seriously mangled, the timezone functions are
3632 ;; liable to bug out, so we ignore all errors.
3633 (let* ((now (current-time))
3634 (real-time (subtract-time now time))
3635 (real-sec (and real-time
3636 (+ (* (float (car real-time)) 65536)
3637 (cadr real-time))))
3638 (sec (and real-time (abs real-sec)))
3639 (segments 0)
3640 num prev)
3641 (unless max-segments
3642 (setq max-segments (length article-time-units)))
3643 (cond
3644 ((null real-time)
3645 "Unknown")
3646 ((zerop sec)
3647 "Now")
3649 (concat
3650 ;; This is a bit convoluted, but basically we go
3651 ;; through the time units for years, weeks, etc,
3652 ;; and divide things to see whether that results
3653 ;; in positive answers.
3654 (mapconcat
3655 (lambda (unit)
3656 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3657 (>= segments max-segments))
3658 ;; The (remaining) seconds are too few to
3659 ;; be divided into this time unit.
3661 ;; It's big enough, so we output it.
3662 (setq sec (- sec (* num (cdr unit))))
3663 (prog1
3664 (concat (if prev ", " "") (int-to-string
3665 (floor num))
3666 " " (symbol-name (car unit))
3667 (if (> num 1) "s" ""))
3668 (setq prev t
3669 segments (1+ segments)))))
3670 article-time-units "")
3671 ;; If dates are odd, then it might appear like the
3672 ;; article was sent in the future.
3673 (if (> real-sec 0)
3674 " ago"
3675 " in the future"))))))
3677 (defun article-date-local (&optional highlight)
3678 "Convert the current article date to the local timezone."
3679 (interactive (list t))
3680 (article-date-ut 'local highlight))
3682 (defun article-date-english (&optional highlight)
3683 "Convert the current article date to something that is proper English."
3684 (interactive (list t))
3685 (article-date-ut 'english highlight))
3687 (defun article-date-original (&optional highlight)
3688 "Convert the current article date to what it was originally.
3689 This is only useful if you have used some other date conversion
3690 function and want to see what the date was before converting."
3691 (interactive (list t))
3692 (article-date-ut 'original highlight))
3694 (defun article-date-lapsed (&optional highlight)
3695 "Convert the current article date to time lapsed since it was sent."
3696 (interactive (list t))
3697 (article-date-ut 'lapsed highlight))
3699 (defun article-date-combined-lapsed (&optional highlight)
3700 "Convert the current article date to time lapsed since it was sent."
3701 (interactive (list t))
3702 (article-date-ut 'combined-lapsed highlight))
3704 (defun article-update-date-lapsed ()
3705 "Function to be run from a timer to update the lapsed time line."
3706 (save-match-data
3707 (let ((buffer (current-buffer)))
3708 (ignore-errors
3709 (walk-windows
3710 (lambda (w)
3711 (set-buffer (window-buffer w))
3712 (when (derived-mode-p 'gnus-article-mode)
3713 (let ((old-line (count-lines (point-min) (point)))
3714 (old-column (- (point) (line-beginning-position)))
3715 (window-start (window-start w))
3716 (pos (point-min))
3717 type next end)
3718 (while (setq pos (text-property-not-all pos (point-max)
3719 'gnus-date-type nil))
3720 (setq next (or (next-single-property-change pos
3721 'gnus-date-type)
3722 (point-max)))
3723 (setq type (get-text-property pos 'gnus-date-type))
3724 (when (memq type '(lapsed combined-lapsed user-defined))
3725 (article-date-ut type t pos)
3726 (setq end (or (next-single-property-change pos
3727 'gnus-date-type)
3728 (point-max)))
3729 (when window-start
3730 (if (/= window-start next)
3731 (setq window-start nil)
3732 (set-window-start w end)))
3733 (setq next end))
3734 (setq pos next))
3735 (goto-char (point-min))
3736 (when (> old-column 0)
3737 (setq old-line (1- old-line)))
3738 (forward-line old-line)
3739 (end-of-line)
3740 (when (> (current-column) old-column)
3741 (beginning-of-line)
3742 (forward-char old-column)))))
3743 nil 'visible))
3744 (set-buffer buffer))))
3746 (defun gnus-start-date-timer (&optional n)
3747 "Start a timer to update the Date headers in the article buffers.
3748 The numerical prefix says how frequently (in seconds) the function
3749 is to run."
3750 (interactive "p")
3751 (unless n
3752 (setq n 1))
3753 (gnus-stop-date-timer)
3754 (setq article-lapsed-timer
3755 (run-at-time 1 n 'article-update-date-lapsed)))
3757 (defun gnus-stop-date-timer ()
3758 "Stop the Date timer."
3759 (interactive)
3760 (when article-lapsed-timer
3761 (nnheader-cancel-timer article-lapsed-timer)
3762 (setq article-lapsed-timer nil)))
3764 (defun article-date-user (&optional highlight)
3765 "Convert the current article date to the user-defined format.
3766 This format is defined by the `gnus-article-time-format' variable."
3767 (interactive (list t))
3768 (article-date-ut 'user highlight))
3770 (defun article-date-iso8601 (&optional highlight)
3771 "Convert the current article date to ISO8601."
3772 (interactive (list t))
3773 (article-date-ut 'iso8601 highlight))
3775 (defmacro gnus-article-save-original-date (&rest forms)
3776 "Save the original date as a text property and evaluate FORMS."
3777 `(let* ((case-fold-search t)
3778 (start (progn
3779 (goto-char (point-min))
3780 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3781 (not (bolp)))
3782 (match-end 0))))
3783 (date (when (and start
3784 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3785 nil t))
3786 (buffer-substring-no-properties start
3787 (match-beginning 0)))))
3788 (goto-char (point-max))
3789 (skip-chars-backward "\n")
3790 (put-text-property (point-min) (point) 'original-date date)
3791 ,@forms
3792 (goto-char (point-max))
3793 (skip-chars-backward "\n")
3794 (put-text-property (point-min) (point) 'original-date date)))
3796 ;; (defun article-show-all ()
3797 ;; "Show all hidden text in the article buffer."
3798 ;; (interactive)
3799 ;; (save-excursion
3800 ;; (let ((inhibit-read-only t))
3801 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3803 (defun article-remove-leading-whitespace ()
3804 "Remove excessive whitespace from all headers."
3805 (interactive)
3806 (save-excursion
3807 (save-restriction
3808 (let ((inhibit-read-only t))
3809 (article-narrow-to-head)
3810 (goto-char (point-min))
3811 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3812 (delete-region (match-beginning 1) (match-end 1)))))))
3814 (defun article-emphasize (&optional arg)
3815 "Emphasize text according to `gnus-emphasis-alist'."
3816 (interactive (gnus-article-hidden-arg))
3817 (unless (gnus-article-check-hidden-text 'emphasis arg)
3818 (save-excursion
3819 (let ((alist (or
3820 (condition-case nil
3821 (with-current-buffer gnus-summary-buffer
3822 gnus-article-emphasis-alist)
3823 (error))
3824 gnus-emphasis-alist))
3825 (inhibit-read-only t)
3826 (props (append '(article-type emphasis)
3827 gnus-hidden-properties))
3828 regexp elem beg invisible visible face)
3829 (article-goto-body)
3830 (setq beg (point))
3831 (while (setq elem (pop alist))
3832 (goto-char beg)
3833 (setq regexp (car elem)
3834 invisible (nth 1 elem)
3835 visible (nth 2 elem)
3836 face (nth 3 elem))
3837 (while (re-search-forward regexp nil t)
3838 (when (and (match-beginning visible) (match-beginning invisible))
3839 (gnus-article-hide-text
3840 (match-beginning invisible) (match-end invisible) props)
3841 (gnus-article-unhide-text-type
3842 (match-beginning visible) (match-end visible) 'emphasis)
3843 (gnus-put-overlay-excluding-newlines
3844 (match-beginning visible) (match-end visible) 'face face)
3845 (gnus-add-wash-type 'emphasis)
3846 (goto-char (match-end invisible)))))))))
3848 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3849 "Setup newsgroup emphasis alist."
3850 (unless gnus-article-emphasis-alist
3851 (let ((name (and gnus-newsgroup-name
3852 (gnus-group-real-name gnus-newsgroup-name))))
3853 (make-local-variable 'gnus-article-emphasis-alist)
3854 (setq gnus-article-emphasis-alist
3855 (nconc
3856 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3857 (while (setq elem (pop alist))
3858 (when (and name (string-match (car elem) name))
3859 (setq alist nil
3860 highlight (copy-sequence (cdr elem)))))
3861 highlight)
3862 (copy-sequence highlight-words)
3863 (if gnus-newsgroup-name
3864 (copy-sequence (gnus-group-find-parameter
3865 gnus-newsgroup-name 'highlight-words t)))
3866 gnus-emphasis-alist)))))
3868 (defvar gnus-summary-article-menu)
3869 (defvar gnus-summary-post-menu)
3871 ;;; Saving functions.
3873 (defun gnus-article-save (save-buffer file &optional num)
3874 "Save the currently selected article."
3875 (when (or (get gnus-default-article-saver :headers)
3876 (not gnus-save-all-headers))
3877 ;; Remove headers according to `gnus-saved-headers' or the value
3878 ;; of the `:headers' property that the saver function might have.
3879 (let ((gnus-visible-headers
3880 (or (symbol-value (get gnus-default-article-saver :headers))
3881 gnus-saved-headers gnus-visible-headers))
3882 ;; Ignore group parameter. See `article-hide-headers'.
3883 (gnus-summary-buffer nil))
3884 (with-current-buffer save-buffer
3885 (article-hide-headers 1 t))))
3886 (save-window-excursion
3887 (if (not gnus-default-article-saver)
3888 (error "No default saver is defined")
3889 ;; !!! Magic! The saving functions all save
3890 ;; `gnus-save-article-buffer' (or so they think), but we
3891 ;; bind that variable to our save-buffer.
3892 (set-buffer gnus-article-buffer)
3893 (let* ((gnus-save-article-buffer save-buffer)
3894 (filename
3895 (cond
3896 ((not gnus-prompt-before-saving) 'default)
3897 ((eq gnus-prompt-before-saving 'always) nil)
3898 (t file)))
3899 (gnus-number-of-articles-to-be-saved
3900 (when (eq gnus-prompt-before-saving t)
3901 num))) ; Magic
3902 (set-buffer gnus-article-current-summary)
3903 (funcall gnus-default-article-saver filename)))))
3905 (defun gnus-read-save-file-name (prompt &optional filename
3906 function group headers variable
3907 dir-var)
3908 (let ((default-name
3909 (funcall function group headers (symbol-value variable)))
3910 result)
3911 (setq result
3912 (expand-file-name
3913 (cond
3914 ((eq filename 'default)
3915 default-name)
3916 ((eq filename t)
3917 default-name)
3918 (filename filename)
3920 (when (symbol-value dir-var)
3921 (setq default-name (expand-file-name
3922 (file-name-nondirectory default-name)
3923 (symbol-value dir-var))))
3924 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3925 (prompt
3926 (format prompt
3927 (if (and gnus-number-of-articles-to-be-saved
3928 (> gnus-number-of-articles-to-be-saved 1))
3929 (format "these %d articles"
3930 gnus-number-of-articles-to-be-saved)
3931 "this article")))
3932 (file
3933 ;; Let the split methods have their say.
3934 (cond
3935 ;; No split name was found.
3936 ((null split-name)
3937 (read-file-name
3938 (concat prompt " (default "
3939 (file-name-nondirectory default-name) "): ")
3940 (file-name-directory default-name)
3941 default-name))
3942 ;; A single group name is returned.
3943 ((stringp split-name)
3944 (setq default-name
3945 (funcall function split-name headers
3946 (symbol-value variable)))
3947 (read-file-name
3948 (concat prompt " (default "
3949 (file-name-nondirectory default-name) "): ")
3950 (file-name-directory default-name)
3951 default-name))
3952 ;; A single split name was found
3953 ((= 1 (length split-name))
3954 (let* ((name (expand-file-name
3955 (car split-name)
3956 gnus-article-save-directory))
3957 (dir (cond ((file-directory-p name)
3958 (file-name-as-directory name))
3959 ((file-exists-p name) name)
3960 (t gnus-article-save-directory))))
3961 (read-file-name
3962 (concat prompt " (default " name "): ")
3963 dir name)))
3964 ;; A list of splits was found.
3966 (setq split-name (nreverse split-name))
3967 (let (result)
3968 (let ((file-name-history
3969 (nconc split-name file-name-history)))
3970 (setq result
3971 (expand-file-name
3972 (read-file-name
3973 (concat prompt " (`M-p' for defaults): ")
3974 gnus-article-save-directory
3975 (car split-name))
3976 gnus-article-save-directory)))
3977 (car (push result file-name-history)))))))
3978 ;; Create the directory.
3979 (gnus-make-directory (file-name-directory file))
3980 ;; If we have read a directory, we append the default file name.
3981 (when (file-directory-p file)
3982 (setq file (expand-file-name (file-name-nondirectory
3983 default-name)
3984 (file-name-as-directory file))))
3985 ;; Possibly translate some characters.
3986 (nnheader-translate-file-chars file))))))
3987 (gnus-make-directory (file-name-directory result))
3988 (when variable
3989 (set variable result))
3990 (when dir-var
3991 (set dir-var (file-name-directory result)))
3992 result))
3994 (defun gnus-article-archive-name (_group)
3995 "Return the first instance of an \"Archive-name\" in the current buffer."
3996 (let ((case-fold-search t))
3997 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3998 (nnheader-concat gnus-article-save-directory
3999 (match-string 1)))))
4001 (defun gnus-article-nndoc-name (group)
4002 "If GROUP is an nndoc group, return the name of the parent group."
4003 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4004 (gnus-group-get-parameter group 'save-article-group)))
4006 (defun gnus-summary-save-in-rmail (&optional filename)
4007 "Append this article to Rmail file.
4008 Optional argument FILENAME specifies file name.
4009 Directory to save to is default to `gnus-article-save-directory'."
4010 (setq filename (gnus-read-save-file-name
4011 "Save %s in rmail file" filename
4012 gnus-rmail-save-name gnus-newsgroup-name
4013 gnus-current-headers 'gnus-newsgroup-last-rmail))
4014 (with-current-buffer gnus-save-article-buffer
4015 (save-excursion
4016 (save-restriction
4017 (widen)
4018 ;; Note that unlike gnus-summary-save-in-mail, there is no
4019 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4020 ;; not use Babyl.
4021 (gnus-output-to-rmail filename))))
4022 filename)
4024 (defun gnus-summary-save-in-mail (&optional filename)
4025 "Append this article to Unix mail file.
4026 Optional argument FILENAME specifies file name.
4027 Directory to save to is default to `gnus-article-save-directory'."
4028 (setq filename (gnus-read-save-file-name
4029 "Save %s in Unix mail file" filename
4030 gnus-mail-save-name gnus-newsgroup-name
4031 gnus-current-headers 'gnus-newsgroup-last-mail))
4032 (with-current-buffer gnus-save-article-buffer
4033 (save-excursion
4034 (save-restriction
4035 (widen)
4036 (if (and (file-readable-p filename)
4037 (file-regular-p filename)
4038 (mail-file-babyl-p filename))
4039 (gnus-output-to-rmail filename)
4040 (gnus-output-to-mail filename)))))
4041 filename)
4043 (put 'gnus-summary-save-in-file :decode t)
4044 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4045 (defun gnus-summary-save-in-file (&optional filename overwrite)
4046 "Append this article to file.
4047 Optional argument FILENAME specifies file name.
4048 Directory to save to is default to `gnus-article-save-directory'."
4049 (setq filename (gnus-read-save-file-name
4050 "Save %s in file" filename
4051 gnus-file-save-name gnus-newsgroup-name
4052 gnus-current-headers 'gnus-newsgroup-last-file))
4053 (with-current-buffer gnus-save-article-buffer
4054 (save-excursion
4055 (save-restriction
4056 (widen)
4057 (when (and overwrite
4058 (file-exists-p filename))
4059 (delete-file filename))
4060 (gnus-output-to-file filename))))
4061 filename)
4063 (put 'gnus-summary-write-to-file :decode t)
4064 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4065 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4066 (defun gnus-summary-write-to-file (&optional filename)
4067 "Write this article to a file, overwriting it if the file exists.
4068 Optional argument FILENAME specifies file name.
4069 The directory to save in defaults to `gnus-article-save-directory'."
4070 (setq filename (gnus-read-save-file-name
4071 "Save %s in file" filename
4072 gnus-file-save-name gnus-newsgroup-name
4073 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4074 (gnus-summary-save-in-file filename t))
4076 (put 'gnus-summary-save-body-in-file :decode t)
4077 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4078 "Append this article body to a file.
4079 Optional argument FILENAME specifies file name.
4080 The directory to save in defaults to `gnus-article-save-directory'."
4081 (setq filename (gnus-read-save-file-name
4082 "Save %s body in file" filename
4083 gnus-file-save-name gnus-newsgroup-name
4084 gnus-current-headers 'gnus-newsgroup-last-file))
4085 (with-current-buffer gnus-save-article-buffer
4086 (save-excursion
4087 (save-restriction
4088 (widen)
4089 (when (article-goto-body)
4090 (narrow-to-region (point) (point-max)))
4091 (when (and overwrite
4092 (file-exists-p filename))
4093 (delete-file filename))
4094 (gnus-output-to-file filename))))
4095 filename)
4097 (put 'gnus-summary-write-body-to-file :decode t)
4098 (put 'gnus-summary-write-body-to-file
4099 :function 'gnus-summary-save-body-in-file)
4100 (defun gnus-summary-write-body-to-file (&optional filename)
4101 "Write this article body to a file, overwriting it if the file exists.
4102 Optional argument FILENAME specifies file name.
4103 The directory to save in defaults to `gnus-article-save-directory'."
4104 (setq filename (gnus-read-save-file-name
4105 "Save %s body in file" filename
4106 gnus-file-save-name gnus-newsgroup-name
4107 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4108 (gnus-summary-save-body-in-file filename t))
4110 (put 'gnus-summary-save-in-pipe :decode t)
4111 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4112 (defun gnus-summary-save-in-pipe (&optional command raw)
4113 "Pipe this article to subprocess COMMAND.
4114 Valid values for COMMAND include:
4115 a string
4116 The executable command name and possibly arguments.
4118 You will be prompted for the command in the minibuffer.
4119 the symbol `default'
4120 It will be replaced with the command which the variable
4121 `gnus-summary-pipe-output-default-command' holds or the command
4122 last used for saving.
4123 Non-nil value for RAW overrides `:decode' and `:headers' properties
4124 and the raw article including all headers will be piped."
4125 (let ((article (gnus-summary-article-number))
4126 (decode (unless raw
4127 (get 'gnus-summary-save-in-pipe :decode)))
4128 save-buffer default)
4129 (if article
4130 (if (vectorp (gnus-summary-article-header article))
4131 (save-current-buffer
4132 (gnus-summary-select-article decode decode nil article)
4133 (insert-buffer-substring
4134 (prog1
4135 (if decode
4136 gnus-article-buffer
4137 gnus-original-article-buffer)
4138 (setq save-buffer
4139 (nnheader-set-temp-buffer " *Gnus Save*"))))
4140 ;; Remove unwanted headers.
4141 (when (and (not raw)
4142 (or (get 'gnus-summary-save-in-pipe :headers)
4143 (not gnus-save-all-headers)))
4144 (let ((gnus-visible-headers
4145 (or (symbol-value (get 'gnus-summary-save-in-pipe
4146 :headers))
4147 gnus-saved-headers gnus-visible-headers))
4148 (gnus-summary-buffer nil))
4149 (article-hide-headers 1 t))))
4150 (error "%d is not a real article" article))
4151 (error "No article to pipe"))
4152 (setq default (or gnus-summary-pipe-output-default-command
4153 gnus-last-shell-command))
4154 (unless (stringp command)
4155 (setq command
4156 (if (and (eq command 'default) default)
4157 default
4158 (gnus-read-shell-command "Shell command on this article: "
4159 default))))
4160 (when (string-equal command "")
4161 (if default
4162 (setq command default)
4163 (error "A command is required")))
4164 (with-current-buffer save-buffer
4165 (save-restriction
4166 (widen)
4167 (shell-command-on-region (point-min) (point-max) command nil)))
4168 (gnus-kill-buffer save-buffer))
4169 (setq gnus-summary-pipe-output-default-command command))
4171 (defun gnus-summary-pipe-to-muttprint (&optional command)
4172 "Pipe this article to muttprint."
4173 (unless (stringp command)
4174 (setq command (read-string
4175 "Print using command: " gnus-summary-muttprint-program
4176 nil gnus-summary-muttprint-program)))
4177 (let ((gnus-summary-pipe-output-default-command
4178 gnus-summary-pipe-output-default-command))
4179 (gnus-summary-save-in-pipe command))
4180 (setq gnus-summary-muttprint-program command))
4182 ;;; Article file names when saving.
4184 (defun gnus-capitalize-newsgroup (newsgroup)
4185 "Capitalize NEWSGROUP name."
4186 (when (not (zerop (length newsgroup)))
4187 (concat (char-to-string (upcase (aref newsgroup 0)))
4188 (substring newsgroup 1))))
4190 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4191 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4192 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4193 Otherwise, it is like ~/News/news/group/num."
4194 (let ((default
4195 (expand-file-name
4196 (concat (if (gnus-use-long-file-name 'not-save)
4197 (gnus-capitalize-newsgroup newsgroup)
4198 (gnus-newsgroup-directory-form newsgroup))
4199 "/" (int-to-string (mail-header-number headers)))
4200 gnus-article-save-directory)))
4201 (if (and last-file
4202 (string-equal (file-name-directory default)
4203 (file-name-directory last-file))
4204 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4205 default
4206 (or last-file default))))
4208 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4209 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4210 If variable `gnus-use-long-file-name' is non-nil, it is
4211 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4212 (let ((default
4213 (expand-file-name
4214 (concat (if (gnus-use-long-file-name 'not-save)
4215 newsgroup
4216 (gnus-newsgroup-directory-form newsgroup))
4217 "/" (int-to-string (mail-header-number headers)))
4218 gnus-article-save-directory)))
4219 (if (and last-file
4220 (string-equal (file-name-directory default)
4221 (file-name-directory last-file))
4222 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4223 default
4224 (or last-file default))))
4226 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4227 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4228 If variable `gnus-use-long-file-name' is non-nil, it is
4229 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4230 (or last-file
4231 (expand-file-name
4232 (if (gnus-use-long-file-name 'not-save)
4233 newsgroup
4234 (file-relative-name
4235 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4236 default-directory))
4237 gnus-article-save-directory)))
4239 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4240 "Generate file name from sender."
4241 (let ((from (mail-header-from headers)))
4242 (expand-file-name
4243 (if (and from (string-match "\\([^ <]+\\)@" from))
4244 (match-string 1 from)
4245 "nobody")
4246 gnus-article-save-directory)))
4248 (defun article-verify-x-pgp-sig ()
4249 "Verify X-PGP-Sig."
4250 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4251 (interactive)
4252 (if (gnus-buffer-live-p gnus-original-article-buffer)
4253 (let ((sig (with-current-buffer gnus-original-article-buffer
4254 (gnus-fetch-field "X-PGP-Sig")))
4255 items info headers)
4256 (when (and sig
4257 mml2015-use
4258 (mml2015-clear-verify-function))
4259 (with-temp-buffer
4260 (insert-buffer-substring gnus-original-article-buffer)
4261 (setq items (split-string sig))
4262 (message-narrow-to-head)
4263 (let ((inhibit-point-motion-hooks t)
4264 (case-fold-search t))
4265 ;; Don't verify multiple headers.
4266 (setq headers (mapconcat (lambda (header)
4267 (concat header ": "
4268 (mail-fetch-field header)
4269 "\n"))
4270 (split-string (nth 1 items) ",") "")))
4271 (delete-region (point-min) (point-max))
4272 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4273 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4274 (insert headers)
4275 (widen)
4276 (forward-line)
4277 (while (not (eobp))
4278 (if (looking-at "^-")
4279 (insert "- "))
4280 (forward-line))
4281 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4282 (insert "Version: " (car items) "\n\n")
4283 (insert (mapconcat 'identity (cddr items) "\n"))
4284 (insert "\n-----END PGP SIGNATURE-----\n")
4285 (let ((mm-security-handle (list (format "multipart/signed"))))
4286 (mml2015-clean-buffer)
4287 (let ((coding-system-for-write (or gnus-newsgroup-charset
4288 'iso-8859-1)))
4289 (funcall (mml2015-clear-verify-function)))
4290 (setq info
4291 (or (mm-handle-multipart-ctl-parameter
4292 mm-security-handle 'gnus-details)
4293 (mm-handle-multipart-ctl-parameter
4294 mm-security-handle 'gnus-info)))))
4295 (when info
4296 (let ((inhibit-read-only t) bface eface)
4297 (save-restriction
4298 (message-narrow-to-head)
4299 (goto-char (point-max))
4300 (forward-line -1)
4301 (setq bface (get-text-property (point-at-bol) 'face)
4302 eface (get-text-property (1- (point-at-eol)) 'face))
4303 (message-remove-header "X-Gnus-PGP-Verify")
4304 (if (re-search-forward "^X-PGP-Sig:" nil t)
4305 (forward-line)
4306 (goto-char (point-max)))
4307 (narrow-to-region (point) (point))
4308 (insert "X-Gnus-PGP-Verify: " info "\n")
4309 (goto-char (point-min))
4310 (forward-line)
4311 (while (not (eobp))
4312 (if (not (looking-at "^[ \t]"))
4313 (insert " "))
4314 (forward-line))
4315 ;; Do highlighting.
4316 (goto-char (point-min))
4317 (when (looking-at "\\([^:]+\\): *")
4318 (put-text-property (match-beginning 1) (1+ (match-end 1))
4319 'face bface)
4320 (put-text-property (match-end 0) (point-max)
4321 'face eface)))))))))
4323 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4325 (defun article-verify-cancel-lock ()
4326 "Verify Cancel-Lock header."
4327 (interactive)
4328 (if (gnus-buffer-live-p gnus-original-article-buffer)
4329 (canlock-verify gnus-original-article-buffer)))
4331 (eval-and-compile
4332 (mapc
4333 (lambda (func)
4334 (let (afunc gfunc)
4335 (if (consp func)
4336 (setq afunc (car func)
4337 gfunc (cdr func))
4338 (setq afunc func
4339 gfunc (intern (format "gnus-%s" func))))
4340 (defalias gfunc
4341 (when (fboundp afunc)
4342 `(lambda (&optional interactive &rest args)
4343 ,(documentation afunc t)
4344 (interactive (list t))
4345 (with-current-buffer gnus-article-buffer
4346 (if interactive
4347 (call-interactively ',afunc)
4348 (apply ',afunc args))))))))
4349 '(article-hide-headers
4350 article-verify-x-pgp-sig
4351 article-verify-cancel-lock
4352 article-hide-boring-headers
4353 article-treat-overstrike
4354 article-treat-ansi-sequences
4355 article-fill-long-lines
4356 article-capitalize-sentences
4357 article-remove-cr
4358 article-remove-leading-whitespace
4359 article-display-x-face
4360 article-display-face
4361 article-de-quoted-unreadable
4362 article-de-base64-unreadable
4363 article-decode-HZ
4364 article-wash-html
4365 article-unsplit-urls
4366 article-hide-list-identifiers
4367 article-strip-banner
4368 article-babel
4369 article-hide-pem
4370 article-hide-signature
4371 article-strip-headers-in-body
4372 article-remove-trailing-blank-lines
4373 article-strip-leading-blank-lines
4374 article-strip-multiple-blank-lines
4375 article-strip-leading-space
4376 article-strip-trailing-space
4377 article-strip-blank-lines
4378 article-strip-all-blank-lines
4379 article-date-local
4380 article-date-english
4381 article-date-iso8601
4382 article-date-original
4383 article-treat-date
4384 article-date-ut
4385 article-decode-mime-words
4386 article-decode-charset
4387 article-decode-encoded-words
4388 article-date-user
4389 article-date-lapsed
4390 article-date-combined-lapsed
4391 article-emphasize
4392 article-treat-dumbquotes
4393 article-treat-non-ascii
4394 article-normalize-headers
4395 ;;(article-show-all . gnus-article-show-all-headers)
4399 ;;; Gnus article mode
4402 (put 'gnus-article-mode 'mode-class 'special)
4404 (set-keymap-parent gnus-article-mode-map widget-keymap)
4406 (gnus-define-keys gnus-article-mode-map
4407 " " gnus-article-goto-next-page
4408 [?\S-\ ] gnus-article-goto-prev-page
4409 "\177" gnus-article-goto-prev-page
4410 [delete] gnus-article-goto-prev-page
4411 "\C-c^" gnus-article-refer-article
4412 "h" gnus-article-show-summary
4413 "s" gnus-article-show-summary
4414 "\C-c\C-m" gnus-article-mail
4415 "?" gnus-article-describe-briefly
4416 "<" beginning-of-buffer
4417 ">" end-of-buffer
4418 "\C-c\C-i" gnus-info-find-node
4419 "\C-c\C-b" gnus-bug
4420 "R" gnus-article-reply-with-original
4421 "F" gnus-article-followup-with-original
4422 "\C-hk" gnus-article-describe-key
4423 "\C-hc" gnus-article-describe-key-briefly
4424 "\C-hb" gnus-article-describe-bindings
4426 "e" gnus-article-read-summary-keys
4427 "\C-d" gnus-article-read-summary-keys
4428 "\M-*" gnus-article-read-summary-keys
4429 "\M-#" gnus-article-read-summary-keys
4430 "\M-^" gnus-article-read-summary-keys
4431 "\M-g" gnus-article-read-summary-keys)
4433 (substitute-key-definition
4434 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4436 (defvar gnus-article-send-map)
4438 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4439 "W" gnus-article-wide-reply-with-original)
4440 (if (featurep 'xemacs)
4441 (set-keymap-default-binding gnus-article-send-map
4442 'gnus-article-read-summary-send-keys)
4443 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4445 (defun gnus-article-make-menu-bar ()
4446 (unless (boundp 'gnus-article-commands-menu)
4447 (gnus-summary-make-menu-bar))
4448 (unless (boundp 'gnus-article-article-menu)
4449 (easy-menu-define
4450 gnus-article-article-menu gnus-article-mode-map ""
4451 '("Article"
4452 ["Scroll forwards" gnus-article-goto-next-page t]
4453 ["Scroll backwards" gnus-article-goto-prev-page t]
4454 ["Show summary" gnus-article-show-summary t]
4455 ["Fetch Message-ID at point" gnus-article-refer-article t]
4456 ["Mail to address at point" gnus-article-mail t]
4457 ["Send a bug report" gnus-bug t]))
4459 (easy-menu-define
4460 gnus-article-treatment-menu gnus-article-mode-map ""
4461 ;; Fixme: this should use :active (and maybe :visible).
4462 '("Treatment"
4463 ["Hide headers" gnus-article-hide-headers t]
4464 ["Hide signature" gnus-article-hide-signature t]
4465 ["Hide citation" gnus-article-hide-citation t]
4466 ["Treat overstrike" gnus-article-treat-overstrike t]
4467 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4468 ["Remove carriage return" gnus-article-remove-cr t]
4469 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4470 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4471 ["Remove base64" gnus-article-de-base64-unreadable t]
4472 ["Treat html" gnus-article-wash-html t]
4473 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4474 ["Decode HZ" gnus-article-decode-HZ t]))
4476 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4478 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4480 (gnus-run-hooks 'gnus-article-menu-hook)))
4482 (defvar bookmark-make-record-function)
4483 (defvar shr-put-image-function)
4485 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4486 "Major mode for displaying an article.
4488 All normal editing commands are switched off.
4490 The following commands are available in addition to all summary mode
4491 commands:
4492 \\<gnus-article-mode-map>
4493 \\[gnus-article-next-page]\t Scroll the article one page forwards
4494 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4495 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4496 \\[gnus-article-show-summary]\t Display the summary buffer
4497 \\[gnus-article-mail]\t Send a reply to the address near point
4498 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4499 \\[gnus-info-find-node]\t Go to the Gnus info node"
4500 (gnus-simplify-mode-line)
4501 (make-local-variable 'minor-mode-alist)
4502 (when (gnus-visual-p 'article-menu 'menu)
4503 (gnus-article-make-menu-bar)
4504 (when gnus-summary-tool-bar-map
4505 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4506 (gnus-update-format-specifications nil 'article-mode)
4507 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4508 (set (make-local-variable 'gnus-page-broken) nil)
4509 (make-local-variable 'gnus-article-current-summary)
4510 (make-local-variable 'gnus-article-mime-handles)
4511 (make-local-variable 'gnus-article-decoded-p)
4512 (make-local-variable 'gnus-article-mime-handle-alist)
4513 (make-local-variable 'gnus-article-wash-types)
4514 (make-local-variable 'gnus-article-image-alist)
4515 (make-local-variable 'gnus-article-charset)
4516 (make-local-variable 'gnus-article-ignored-charsets)
4517 (set (make-local-variable 'bookmark-make-record-function)
4518 'gnus-summary-bookmark-make-record)
4519 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4520 ;; face.
4521 (set (make-local-variable 'nobreak-char-display) nil)
4522 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4523 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4524 (setq cursor-in-non-selected-windows nil)
4525 (gnus-set-default-directory)
4526 (buffer-disable-undo)
4527 (setq buffer-read-only t
4528 show-trailing-whitespace nil)
4529 (mm-enable-multibyte))
4531 (defun gnus-article-setup-buffer ()
4532 "Initialize the article buffer."
4533 (let* ((name (if gnus-single-article-buffer "*Article*"
4534 (concat "*Article "
4535 (gnus-group-decoded-name gnus-newsgroup-name)
4536 "*")))
4537 (original
4538 (progn (string-match "\\*Article" name)
4539 (concat " *Original Article"
4540 (substring name (match-end 0))))))
4541 (setq gnus-article-buffer name)
4542 (setq gnus-original-article-buffer original)
4543 (setq gnus-article-mime-handle-alist nil)
4544 (with-current-buffer gnus-summary-buffer
4545 ;; This might be a variable local to the summary buffer.
4546 (unless gnus-single-article-buffer
4547 (setq gnus-article-buffer name)
4548 (setq gnus-original-article-buffer original)
4549 (gnus-set-global-variables)))
4550 (gnus-article-setup-highlight-words)
4551 ;; Init original article buffer.
4552 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4553 (mm-enable-multibyte)
4554 (setq major-mode 'gnus-original-article-mode)
4555 (make-local-variable 'gnus-original-article))
4556 (if (and (get-buffer name)
4557 (with-current-buffer name
4558 (if gnus-article-edit-mode
4559 (if (y-or-n-p "Article mode edit in progress; discard? ")
4560 (progn
4561 (set-buffer-modified-p nil)
4562 (gnus-kill-buffer name)
4563 (message "")
4564 nil)
4565 (error "Action aborted"))
4566 t)))
4567 (let ((summary gnus-summary-buffer))
4568 (with-current-buffer name
4569 (set (make-local-variable 'gnus-article-edit-mode) nil)
4570 (gnus-article-stop-animations)
4571 (when gnus-article-mime-handles
4572 (mm-destroy-parts gnus-article-mime-handles)
4573 (setq gnus-article-mime-handles nil))
4574 ;; Set it to nil in article-buffer!
4575 (setq gnus-article-mime-handle-alist nil)
4576 (buffer-disable-undo)
4577 (setq buffer-read-only t)
4578 (unless (derived-mode-p 'gnus-article-mode)
4579 (gnus-article-mode))
4580 (set (make-local-variable 'gnus-summary-buffer) summary)
4581 (setq truncate-lines gnus-article-truncate-lines)
4582 (current-buffer)))
4583 (let ((summary gnus-summary-buffer))
4584 (with-current-buffer (gnus-get-buffer-create name)
4585 (gnus-article-mode)
4586 (setq truncate-lines gnus-article-truncate-lines)
4587 (set (make-local-variable 'gnus-summary-buffer) summary)
4588 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4589 (when article-lapsed-timer
4590 (gnus-stop-date-timer))
4591 (when gnus-article-update-date-headers
4592 (gnus-start-date-timer gnus-article-update-date-headers))
4593 (current-buffer))))))
4595 (defun gnus-article-stop-animations ()
4596 (dolist (timer (and (boundp 'timer-list)
4597 timer-list))
4598 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4599 (cancel-timer timer))))
4601 (defun gnus-stop-downloads ()
4602 (when (boundp 'url-queue)
4603 (set (intern "url-queue" obarray) nil)))
4605 ;; Set article window start at LINE, where LINE is the number of lines
4606 ;; from the head of the article.
4607 (defun gnus-article-set-window-start (&optional line)
4608 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4609 (when article-window
4610 (set-window-start
4611 article-window
4612 (with-current-buffer gnus-article-buffer
4613 (goto-char (point-min))
4614 (if (not line)
4615 (point-min)
4616 (gnus-message 6 "Moved to bookmark")
4617 (search-forward "\n\n" nil t)
4618 (forward-line line)
4619 (point)))))))
4621 (defvar gnus-tmp-internal-hook)
4623 (defun gnus-article-prepare (article &optional all-headers _header)
4624 "Prepare ARTICLE in article mode buffer.
4625 ARTICLE should either be an article number or a Message-ID.
4626 If ARTICLE is an id, HEADER should be the article headers.
4627 If ALL-HEADERS is non-nil, no headers are hidden."
4628 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4629 ;; Make sure we start in a summary buffer.
4630 (unless (derived-mode-p 'gnus-summary-mode)
4631 (set-buffer gnus-summary-buffer))
4632 (setq gnus-summary-buffer (current-buffer))
4633 (let* ((summary-buffer (current-buffer))
4634 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4635 (group gnus-newsgroup-name)
4636 result)
4637 (save-excursion
4638 (gnus-article-setup-buffer)
4639 (set-buffer gnus-article-buffer)
4640 ;; Deactivate active regions.
4641 (when (and (boundp 'transient-mark-mode)
4642 transient-mark-mode)
4643 (setq mark-active nil))
4644 (if (not (setq result (let ((inhibit-read-only t))
4645 (gnus-request-article-this-buffer
4646 article group))))
4647 ;; There is no such article.
4648 (save-excursion
4649 (when (and (numberp article)
4650 (not (memq article gnus-newsgroup-sparse)))
4651 (setq gnus-article-current
4652 (cons gnus-newsgroup-name article))
4653 (set-buffer gnus-summary-buffer)
4654 (setq gnus-current-article article)
4655 (if (and (memq article gnus-newsgroup-undownloaded)
4656 (not (gnus-online (gnus-find-method-for-group
4657 gnus-newsgroup-name))))
4658 (progn
4659 (gnus-summary-set-agent-mark article)
4660 (message "Message marked for downloading"))
4661 (gnus-summary-mark-article article gnus-canceled-mark)
4662 (unless (memq article gnus-newsgroup-sparse)
4663 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4664 (if (or (eq result 'pseudo)
4665 (eq result 'nneething))
4666 (progn
4667 (with-current-buffer summary-buffer
4668 (push article gnus-newsgroup-history)
4669 (setq gnus-last-article gnus-current-article
4670 gnus-current-article 0
4671 gnus-current-headers nil
4672 gnus-article-current nil)
4673 (if (eq result 'nneething)
4674 (gnus-configure-windows 'summary)
4675 (gnus-configure-windows 'article))
4676 (gnus-set-global-variables))
4677 (let ((gnus-article-mime-handle-alist-1
4678 gnus-article-mime-handle-alist))
4679 (gnus-set-mode-line 'article)))
4680 ;; The result from the `request' was an actual article -
4681 ;; or at least some text that is now displayed in the
4682 ;; article buffer.
4683 (when (and (numberp article)
4684 (not (eq article gnus-current-article)))
4685 ;; Seems like a new article has been selected.
4686 ;; `gnus-current-article' must be an article number.
4687 (with-current-buffer summary-buffer
4688 (push article gnus-newsgroup-history)
4689 (setq gnus-last-article gnus-current-article
4690 gnus-current-article article
4691 gnus-current-headers
4692 (gnus-summary-article-header gnus-current-article)
4693 gnus-article-current
4694 (cons gnus-newsgroup-name gnus-current-article))
4695 (unless (vectorp gnus-current-headers)
4696 (setq gnus-current-headers nil))
4697 (gnus-summary-goto-subject gnus-current-article)
4698 (when (gnus-summary-show-thread)
4699 ;; If the summary buffer really was folded, the
4700 ;; previous goto may not actually have gone to
4701 ;; the right article, but the thread root instead.
4702 ;; So we go again.
4703 (gnus-summary-goto-subject gnus-current-article))
4704 (gnus-run-hooks 'gnus-mark-article-hook)
4705 (gnus-set-mode-line 'summary)
4706 (when (gnus-visual-p 'article-highlight 'highlight)
4707 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4708 ;; Set the global newsgroup variables here.
4709 (gnus-set-global-variables)
4710 (setq gnus-have-all-headers
4711 (or all-headers gnus-show-all-headers))))
4712 (save-excursion
4713 (gnus-configure-windows 'article))
4714 (when (or (numberp article)
4715 (stringp article))
4716 (gnus-article-prepare-display)
4717 ;; Do page break.
4718 (goto-char (point-min))
4719 (when gnus-break-pages
4720 (gnus-narrow-to-page)))
4721 (let ((gnus-article-mime-handle-alist-1
4722 gnus-article-mime-handle-alist))
4723 (gnus-set-mode-line 'article))
4724 (article-goto-body)
4725 (unless (bobp)
4726 (forward-line -1))
4727 (set-window-point (get-buffer-window (current-buffer)) (point))
4728 (gnus-configure-windows 'article)
4729 (gnus-run-hooks 'gnus-article-prepare-hook)
4730 t))))))
4732 (defvar gnus-mime-display-attachment-buttons-in-header)
4734 ;;;###autoload
4735 (defun gnus-article-prepare-display ()
4736 "Make the current buffer look like a nice article."
4737 ;; Hooks for getting information from the article.
4738 ;; This hook must be called before being narrowed.
4739 (let ((gnus-article-buffer (current-buffer))
4740 buffer-read-only
4741 (inhibit-read-only t))
4742 (unless (derived-mode-p 'gnus-article-mode)
4743 (gnus-article-mode))
4744 (setq buffer-read-only nil
4745 gnus-article-wash-types nil
4746 gnus-article-image-alist nil)
4747 (gnus-run-hooks 'gnus-tmp-internal-hook)
4748 (when gnus-display-mime-function
4749 (funcall gnus-display-mime-function))
4750 ;; Add attachment buttons to the header.
4751 (when gnus-mime-display-attachment-buttons-in-header
4752 (gnus-mime-buttonize-attachments-in-header))))
4755 ;;; Gnus Sticky Article Mode
4758 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4759 "Mode for sticky articles."
4760 ;; Release bindings that won't work.
4761 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4762 gnus-sticky-article-mode-map)
4763 (substitute-key-definition 'gnus-article-refer-article 'undefined
4764 gnus-sticky-article-mode-map)
4765 (dolist (k '("e" "h" "s" "F" "R"))
4766 (define-key gnus-sticky-article-mode-map k nil))
4767 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4768 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4769 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4770 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4772 (defun gnus-sticky-article (arg)
4773 "Make the current article sticky.
4774 If a prefix ARG is given, ask for a name for this sticky article buffer."
4775 (interactive "P")
4776 (gnus-summary-show-thread)
4777 (gnus-summary-select-article nil nil 'pseudo)
4778 (let (new-art-buf-name)
4779 (gnus-eval-in-buffer-window gnus-article-buffer
4780 (setq new-art-buf-name
4781 (concat
4782 "*Sticky Article: "
4783 (if arg
4784 (read-from-minibuffer "Sticky article buffer name: ")
4785 (gnus-with-article-headers
4786 (gnus-article-goto-header "subject")
4787 (setq new-art-buf-name
4788 (buffer-substring-no-properties
4789 (line-beginning-position) (line-end-position)))
4790 (goto-char (point-min))
4791 (gnus-article-goto-header "from")
4792 (setq new-art-buf-name
4793 (concat
4794 new-art-buf-name ", "
4795 (buffer-substring-no-properties
4796 (line-beginning-position) (line-end-position))))
4797 (goto-char (point-min))
4798 (gnus-article-goto-header "date")
4799 (setq new-art-buf-name
4800 (concat
4801 new-art-buf-name ", "
4802 (buffer-substring-no-properties
4803 (line-beginning-position) (line-end-position))))))
4804 "*"))
4805 (if (and (gnus-buffer-live-p new-art-buf-name)
4806 (with-current-buffer new-art-buf-name
4807 (derived-mode-p 'gnus-sticky-article-mode)))
4808 (switch-to-buffer new-art-buf-name)
4809 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4810 (gnus-sticky-article-mode))
4811 (setq gnus-article-buffer new-art-buf-name))
4812 (gnus-summary-recenter)
4813 (gnus-summary-position-point))
4815 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4816 "Kill the given sticky article BUFFER.
4817 If none is given, assume the current buffer and kill it if it has
4818 `gnus-sticky-article-mode'."
4819 (interactive)
4820 (unless buffer
4821 (setq buffer (current-buffer)))
4822 (with-current-buffer buffer
4823 (when (derived-mode-p 'gnus-sticky-article-mode)
4824 (gnus-kill-buffer buffer))))
4826 (defun gnus-kill-sticky-article-buffers (arg)
4827 "Kill all sticky article buffers.
4828 If a prefix ARG is given, ask for confirmation."
4829 (interactive "P")
4830 (dolist (buf (gnus-buffers))
4831 (with-current-buffer buf
4832 (when (derived-mode-p 'gnus-sticky-article-mode)
4833 (if (not arg)
4834 (gnus-kill-buffer buf)
4835 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4836 (gnus-kill-buffer buf)))))))
4839 ;;; Gnus MIME viewing functions
4842 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4843 "Format of the MIME buttons.
4845 Valid specifiers include:
4846 %t The MIME type
4847 %T MIME type, along with additional info
4848 %n The `name' parameter
4849 %d The description, if any
4850 %l The length of the encoded part
4851 %p The part identifier number
4852 %e Dots if the part isn't displayed
4854 General format specifiers can also be used. See Info node
4855 `(gnus)Formatting Variables'.")
4857 (defvar gnus-tmp-type)
4858 (defvar gnus-tmp-type-long)
4859 (defvar gnus-tmp-name)
4860 (defvar gnus-tmp-description)
4861 (defvar gnus-tmp-id)
4862 (defvar gnus-tmp-length)
4863 (defvar gnus-tmp-dots)
4864 (defvar gnus-tmp-info)
4865 (defvar gnus-tmp-pressed-details)
4867 (defvar gnus-mime-button-line-format-alist
4868 '((?t gnus-tmp-type ?s)
4869 (?T gnus-tmp-type-long ?s)
4870 (?n gnus-tmp-name ?s)
4871 (?d gnus-tmp-description ?s)
4872 (?p gnus-tmp-id ?s)
4873 (?l gnus-tmp-length ?d)
4874 (?e gnus-tmp-dots ?s)))
4876 (defvar gnus-mime-button-commands
4877 '((gnus-article-press-button "\r" "Toggle Display")
4878 (gnus-mime-view-part "v" "View Interactively...")
4879 (gnus-mime-view-part-as-type "t" "View As Type...")
4880 (gnus-mime-view-part-as-charset "C" "View As charset...")
4881 (gnus-mime-save-part "o" "Save...")
4882 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4883 (gnus-mime-replace-part "r" "Replace part")
4884 (gnus-mime-delete-part "d" "Delete part")
4885 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4886 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4887 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4888 (gnus-mime-view-part-externally "e" "View Externally")
4889 (gnus-mime-print-part "p" "Print")
4890 (gnus-mime-pipe-part "|" "Pipe To Command...")
4891 (gnus-mime-action-on-part "." "Take action on the part...")))
4893 (defun gnus-article-mime-part-status ()
4894 (if gnus-article-mime-handle-alist-1
4895 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4896 " (1 part)"
4897 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4898 ""))
4900 (defvar gnus-mime-button-map
4901 (let ((map (make-sparse-keymap)))
4902 (define-key map gnus-mouse-2 'gnus-article-push-button)
4903 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4904 (dolist (c gnus-mime-button-commands)
4905 (define-key map (cadr c) (car c)))
4906 map))
4908 (easy-menu-define
4909 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4910 `("MIME Part"
4911 ,@(mapcar (lambda (c)
4912 (vector (caddr c) (car c) :active t))
4913 gnus-mime-button-commands)))
4915 (defvar gnus-url-button-commands
4916 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4918 (defvar gnus-url-button-map
4919 (let ((map (make-sparse-keymap)))
4920 (dolist (c gnus-url-button-commands)
4921 (define-key map (cadr c) (car c)))
4922 map))
4924 (easy-menu-define
4925 gnus-url-button-menu gnus-url-button-map "URL button menu."
4926 `("Url Button"
4927 ,@(mapcar (lambda (c)
4928 (vector (caddr c) (car c) :active t))
4929 gnus-url-button-commands)))
4931 (defmacro gnus-bind-safe-url-regexp (&rest body)
4932 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4933 `(let ((mm-w3m-safe-url-regexp
4934 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4935 (gnus-buffer-live-p
4936 gnus-article-current-summary))
4937 (with-current-buffer gnus-article-current-summary
4938 gnus-newsgroup-name)
4939 gnus-newsgroup-name)))
4940 (if (cond ((not group)
4941 ;; Maybe we're in a mml-preview buffer
4942 ;; and no group is selected.
4944 ((stringp gnus-safe-html-newsgroups)
4945 (string-match gnus-safe-html-newsgroups group))
4946 ((consp gnus-safe-html-newsgroups)
4947 (member group gnus-safe-html-newsgroups)))
4949 mm-w3m-safe-url-regexp))))
4950 ,@body))
4952 (defun gnus-mime-button-menu (event prefix)
4953 "Construct a context-sensitive menu of MIME commands."
4954 (interactive "e\nP")
4955 (save-window-excursion
4956 (let ((pos (event-start event)))
4957 (select-window (posn-window pos))
4958 (goto-char (posn-point pos))
4959 (gnus-article-check-buffer)
4960 (popup-menu gnus-mime-button-menu nil prefix))))
4962 (defun gnus-mime-view-all-parts (&optional handles)
4963 "View all the MIME parts."
4964 (interactive)
4965 (with-current-buffer gnus-article-buffer
4966 (let ((handles (or handles gnus-article-mime-handles))
4967 (mail-parse-charset gnus-newsgroup-charset)
4968 (mail-parse-ignored-charsets
4969 (with-current-buffer gnus-summary-buffer
4970 gnus-newsgroup-ignored-charsets)))
4971 (when handles
4972 (mm-remove-parts handles)
4973 (goto-char (point-min))
4974 (or (search-forward "\n\n") (goto-char (point-max)))
4975 (let ((inhibit-read-only t))
4976 (delete-region (point) (point-max))
4977 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4979 (defun gnus-article-jump-to-part (n)
4980 "Jump to MIME part N."
4981 (interactive "P")
4982 (let ((parts (with-current-buffer gnus-article-buffer
4983 (length gnus-article-mime-handle-alist))))
4984 (when (zerop parts)
4985 (error "No such part"))
4986 (pop-to-buffer gnus-article-buffer)
4987 (or n
4988 (setq n (if (= parts 1)
4990 (read-number (format "Jump to part (1..%s): " parts)))))
4991 (unless (and (integerp n) (<= n parts) (>= n 1))
4992 (setq n
4993 (progn
4994 (gnus-message 7 "Invalid part `%s', using %s instead."
4995 n parts)
4996 parts)))
4997 (gnus-message 9 "Jumping to part %s." n)
4998 (cond ((>= gnus-auto-select-part 1)
4999 (while (and (<= n parts)
5000 (not (gnus-article-goto-part n)))
5001 (setq n (1+ n))))
5002 ((< gnus-auto-select-part 0)
5003 (while (and (>= n 1)
5004 (not (gnus-article-goto-part n)))
5005 (setq n (1- n))))
5007 (gnus-article-goto-part n)))))
5009 (defvar gnus-mime-buttonized-part-id nil
5010 "ID of a mime part that should be buttonized.
5011 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5013 (eval-when-compile
5014 (defsubst gnus-article-edit-part (handles &optional current-id)
5015 "Edit an article in order to delete a mime part.
5016 This function is exclusively used by `gnus-mime-save-part-and-strip'
5017 and `gnus-mime-delete-part', and not provided at run-time normally."
5018 (gnus-article-edit-article
5019 `(lambda ()
5020 (buffer-disable-undo)
5021 (let ((mail-parse-charset (or gnus-article-charset
5022 ',gnus-newsgroup-charset))
5023 (mail-parse-ignored-charsets
5024 (or gnus-article-ignored-charsets
5025 ',gnus-newsgroup-ignored-charsets))
5026 (mbl mml-buffer-list))
5027 (setq mml-buffer-list nil)
5028 ;; A new text must be inserted before deleting existing ones
5029 ;; at the end so as not to move existing markers of which
5030 ;; the insertion type is t.
5031 (delete-region
5032 (point-min)
5033 (prog1
5034 (goto-char (point-max))
5035 (insert-buffer-substring gnus-original-article-buffer)))
5036 (mime-to-mml ',handles)
5037 (setq gnus-article-mime-handles nil)
5038 (let ((mbl1 mml-buffer-list))
5039 (setq mml-buffer-list mbl)
5040 (set (make-local-variable 'mml-buffer-list) mbl1))
5041 (gnus-make-local-hook 'kill-buffer-hook)
5042 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5043 `(lambda (no-highlight)
5044 (let ((mail-parse-charset (or gnus-article-charset
5045 ',gnus-newsgroup-charset))
5046 (message-options message-options)
5047 (message-options-set-recipient)
5048 (mail-parse-ignored-charsets
5049 (or gnus-article-ignored-charsets
5050 ',gnus-newsgroup-ignored-charsets)))
5051 (mml-to-mime)
5052 (mml-destroy-buffers)
5053 (remove-hook 'kill-buffer-hook
5054 'mml-destroy-buffers t)
5055 (kill-local-variable 'mml-buffer-list))
5056 (gnus-summary-edit-article-done
5057 ,(or (mail-header-references gnus-current-headers) "")
5058 ,(gnus-group-read-only-p)
5059 ,gnus-summary-buffer no-highlight))
5061 ;; Force buttonizing this part.
5062 (let ((gnus-mime-buttonized-part-id current-id))
5063 (gnus-article-edit-done))
5064 (gnus-configure-windows 'article)
5065 (sit-for 0)
5066 (when (and current-id (integerp gnus-auto-select-part))
5067 (gnus-article-jump-to-part
5068 (min (max (+ current-id gnus-auto-select-part) 1)
5069 (with-current-buffer gnus-article-buffer
5070 (length gnus-article-mime-handle-alist)))))))
5072 (defun gnus-mime-replace-part (file)
5073 "Replace MIME part under point with an external body."
5074 ;; Useful if file has already been saved to disk
5075 (interactive
5076 (list
5077 (read-file-name "Replace MIME part with file: "
5078 (or mm-default-directory default-directory)
5079 nil nil)))
5080 (gnus-mime-save-part-and-strip file))
5082 (defun gnus-mime-save-part-and-strip (&optional file)
5083 "Save the MIME part under point then replace it with an external body.
5084 If FILE is given, use it for the external part."
5085 (interactive)
5086 (gnus-article-check-buffer)
5087 (when (gnus-group-read-only-p)
5088 (error "The current group does not support deleting of parts"))
5089 (when (mm-complicated-handles gnus-article-mime-handles)
5090 (error "\
5091 The current article has a complicated MIME structure, giving up..."))
5092 (let* ((data (get-text-property (point) 'gnus-data))
5093 (id (get-text-property (point) 'gnus-part))
5094 (handles gnus-article-mime-handles))
5095 (unless file
5096 (setq file
5097 (and data (mm-save-part data "Delete MIME part and save to: "))))
5098 (when file
5099 (with-current-buffer (mm-handle-buffer data)
5100 (erase-buffer)
5101 (insert "Content-Type: " (mm-handle-media-type data))
5102 (mml-insert-parameter-string (cdr (mm-handle-type data))
5103 '(charset))
5104 ;; Add a filename for the sake of saving the part again.
5105 (mml-insert-parameter
5106 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5107 (insert "\n")
5108 (insert "Content-ID: " (message-make-message-id) "\n")
5109 (insert "Content-Transfer-Encoding: binary\n")
5110 (insert "\n"))
5111 (setcdr data
5112 (cdr (mm-make-handle nil
5113 `("message/external-body"
5114 (access-type . "LOCAL-FILE")
5115 (name . ,file)))))
5116 ;; (set-buffer gnus-summary-buffer)
5117 (gnus-article-edit-part handles id))))
5119 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5120 ;; parts...>') but with stripping would be nice.
5122 (defun gnus-mime-delete-part ()
5123 "Delete the MIME part under point.
5124 Replace it with some information about the removed part."
5125 (interactive)
5126 (gnus-article-check-buffer)
5127 (when (gnus-group-read-only-p)
5128 (error "The current group does not support deleting of parts"))
5129 (when (mm-complicated-handles gnus-article-mime-handles)
5130 (error "\
5131 The current article has a complicated MIME structure, giving up..."))
5132 (when (or gnus-expert-user
5133 (gnus-yes-or-no-p "\
5134 Deleting parts may malfunction or destroy the article; continue? "))
5135 (let* ((data (get-text-property (point) 'gnus-data))
5136 (id (get-text-property (point) 'gnus-part))
5137 (handles gnus-article-mime-handles)
5138 (description
5139 (let ((desc (mm-handle-description data)))
5140 (when desc
5141 (mail-decode-encoded-word-string desc))))
5142 (filename (or (mm-handle-filename data) "(none)"))
5143 (type (mm-handle-media-type data)))
5144 (unless data
5145 (error "No MIME part under point"))
5146 (with-current-buffer (mm-handle-buffer data)
5147 (let ((bsize (buffer-size)))
5148 (erase-buffer)
5149 (insert
5150 (concat
5151 ",----\n"
5152 "| The following attachment has been deleted:\n"
5153 "|\n"
5154 "| Type: " type "\n"
5155 "| Filename: " filename "\n"
5156 "| Size (encoded): " (format "%s byte%s\n"
5157 bsize (if (= bsize 1)
5159 "s"))
5160 (when description
5161 (concat "| Description: " description "\n"))
5162 "`----\n"))
5163 (setcdr data
5164 (cdr (mm-make-handle
5165 nil `("text/plain" (charset . gnus-decoded)) nil nil
5166 (list "attachment")
5167 (format "Deleted attachment (%s bytes)" bsize))))))
5168 ;; (set-buffer gnus-summary-buffer)
5169 (gnus-article-edit-part handles id))))
5171 (defun gnus-mime-save-part ()
5172 "Save the MIME part under point."
5173 (interactive)
5174 (gnus-article-check-buffer)
5175 (let ((data (get-text-property (point) 'gnus-data)))
5176 (when data
5177 (mm-save-part data))))
5179 (defun gnus-mime-pipe-part (&optional cmd)
5180 "Pipe the MIME part under point to a process.
5181 Use CMD as the process."
5182 (interactive)
5183 (gnus-article-check-buffer)
5184 (let ((data (get-text-property (point) 'gnus-data)))
5185 (when data
5186 (mm-pipe-part data cmd))))
5188 (defun gnus-mime-view-part ()
5189 "Interactively choose a viewing method for the MIME part under point."
5190 (interactive)
5191 (gnus-article-check-buffer)
5192 (let ((data (get-text-property (point) 'gnus-data)))
5193 (when data
5194 (setq gnus-article-mime-handles
5195 (mm-merge-handles
5196 gnus-article-mime-handles (setq data (copy-sequence data))))
5197 (mm-interactively-view-part data))))
5199 (defun gnus-mime-view-part-as-type-internal ()
5200 (gnus-article-check-buffer)
5201 (let* ((handle (get-text-property (point) 'gnus-data))
5202 (name (or
5203 ;; Content-Type: foo/bar; name=...
5204 (mail-content-type-get (mm-handle-type handle) 'name)
5205 ;; Content-Disposition: attachment; filename=...
5206 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5207 (def-type (and name (mm-default-file-encoding name))))
5208 (or (and def-type (cons def-type 0))
5209 (and handle
5210 (equal (mm-handle-media-supertype handle) "text")
5211 '("text/plain" . 0))
5212 '("application/octet-stream" . 0))))
5214 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5215 "Choose a MIME media type, and view the part as such.
5216 If non-nil, PRED is a predicate to use during completion to limit the
5217 available media-types."
5218 (interactive)
5219 (unless mime-type
5220 (setq mime-type
5221 (let ((default (gnus-mime-view-part-as-type-internal)))
5222 (gnus-completing-read
5223 "View as MIME type"
5224 (if pred
5225 (gnus-remove-if-not pred (mailcap-mime-types))
5226 (mailcap-mime-types))
5227 nil nil nil
5228 (car default)))))
5229 (gnus-article-check-buffer)
5230 (let ((handle (get-text-property (point) 'gnus-data)))
5231 (when handle
5232 (when (equal (mm-handle-media-type handle) "message/external-body")
5233 (unless (mm-handle-cache handle)
5234 (mm-extern-cache-contents handle))
5235 (setq handle (mm-handle-cache handle)))
5236 (setq handle
5237 (mm-make-handle (mm-handle-buffer handle)
5238 (cons mime-type (cdr (mm-handle-type handle)))
5239 (mm-handle-encoding handle)
5240 (mm-handle-undisplayer handle)
5241 (mm-handle-disposition handle)
5242 (mm-handle-description handle)
5244 (mm-handle-id handle)))
5245 (setq gnus-article-mime-handles
5246 (mm-merge-handles gnus-article-mime-handles handle))
5247 (when (mm-handle-displayed-p handle)
5248 (mm-remove-part handle))
5249 (gnus-mm-display-part handle))))
5251 (defun gnus-mime-copy-part (&optional handle arg)
5252 "Put the MIME part under point into a new buffer.
5253 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5254 are decompressed."
5255 (interactive (list nil current-prefix-arg))
5256 (gnus-article-check-buffer)
5257 (unless handle
5258 (setq handle (get-text-property (point) 'gnus-data)))
5259 (when handle
5260 (let ((filename (mm-handle-filename handle))
5261 contents dont-decode charset coding-system)
5262 (mm-with-unibyte-buffer
5263 (mm-insert-part handle)
5264 (setq contents (or (condition-case nil
5265 (mm-decompress-buffer filename nil 'sig)
5266 (error
5267 (setq dont-decode t)
5268 nil))
5269 (buffer-string))))
5270 (setq filename (cond (filename (file-name-nondirectory filename))
5271 (dont-decode "*raw data*")
5272 (t "*decoded*")))
5273 (cond
5274 (dont-decode)
5275 ((not arg)
5276 (unless (setq charset (mail-content-type-get
5277 (mm-handle-type handle) 'charset))
5278 (unless (setq coding-system (mm-with-unibyte-buffer
5279 (insert contents)
5280 (mm-find-buffer-file-coding-system)))
5281 (setq charset gnus-newsgroup-charset))))
5282 ((numberp arg)
5283 (setq charset (or (cdr (assq arg
5284 gnus-summary-show-article-charset-alist))
5285 (mm-read-coding-system "Charset: ")))))
5286 (switch-to-buffer (generate-new-buffer filename))
5287 (if (or coding-system
5288 (and charset
5289 (setq coding-system (mm-charset-to-coding-system
5290 charset nil t))
5291 (not (eq coding-system 'ascii))))
5292 (progn
5293 (mm-enable-multibyte)
5294 (insert (mm-decode-coding-string contents coding-system))
5295 (setq buffer-file-coding-system
5296 (if (boundp 'last-coding-system-used)
5297 (symbol-value 'last-coding-system-used)
5298 coding-system)))
5299 (mm-disable-multibyte)
5300 (insert contents)
5301 (setq buffer-file-coding-system mm-binary-coding-system))
5302 ;; We do it this way to make `normal-mode' set the appropriate mode.
5303 (unwind-protect
5304 (progn
5305 (setq buffer-file-name (expand-file-name filename))
5306 (normal-mode))
5307 (setq buffer-file-name nil))
5308 (goto-char (point-min)))))
5310 (defun gnus-mime-print-part (&optional handle filename)
5311 "Print the MIME part under point."
5312 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5313 (gnus-article-check-buffer)
5314 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5315 (contents (and handle (mm-get-part handle)))
5316 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5317 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5318 (when contents
5319 (if printer
5320 (unwind-protect
5321 (progn
5322 (mm-save-part-to-file handle file)
5323 (call-process shell-file-name nil
5324 (generate-new-buffer " *mm*")
5326 shell-command-switch
5327 (mm-mailcap-command
5328 printer file (mm-handle-type handle))))
5329 (delete-file file))
5330 (with-temp-buffer
5331 (insert contents)
5332 (gnus-print-buffer))
5333 (ps-despool filename)))))
5335 (defun gnus-mime-inline-part (&optional handle arg)
5336 "Insert the MIME part under point into the current buffer.
5337 Compressed files like .gz and .bz2 are decompressed."
5338 (interactive (list nil current-prefix-arg))
5339 (gnus-article-check-buffer)
5340 (let* ((inhibit-read-only t)
5341 (b (point))
5342 (btn ;; position where the MIME button exists
5343 (if handle
5344 (if (eq handle (get-text-property b 'gnus-data))
5346 (article-goto-body)
5347 (or (text-property-any (point) (point-max) 'gnus-data handle)
5348 (text-property-any (point-min) (point) 'gnus-data handle)))
5349 (setq handle (get-text-property b 'gnus-data))
5351 start)
5352 (when handle
5353 (when (= b (prog1
5355 (setq start (next-single-property-change btn 'gnus-data
5356 nil (point-max))
5357 btn (previous-single-property-change start
5358 'gnus-data))))
5359 (setq b btn))
5360 (if (and (not arg) (mm-handle-undisplayer handle))
5361 (progn
5362 (setq b (copy-marker b)
5363 btn (copy-marker btn))
5364 (mm-remove-part handle))
5365 (cond
5366 ((not arg) nil)
5367 ((numberp arg)
5368 (if (mm-handle-undisplayer handle)
5369 (mm-remove-part handle)))
5370 ((mm-handle-undisplayer handle)
5371 (mm-remove-part handle)))
5372 (goto-char start)
5373 (unless (bolp)
5374 ;; This is a header button.
5375 (forward-line 1))
5376 (mm-display-inline handle))
5377 ;; Toggle the button appearance between `[button]...' and `[button]'.
5378 (when (markerp btn)
5379 (setq btn (prog1 (marker-position btn)
5380 (set-marker btn nil))))
5381 (goto-char btn)
5382 (let ((displayed-p (mm-handle-displayed-p handle)))
5383 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5384 (list displayed-p))
5385 (if (featurep 'emacs)
5386 (delete-region
5387 (point)
5388 (next-single-property-change (point) 'gnus-data nil (point-max)))
5389 (let* ((end (next-single-property-change (point) 'gnus-data))
5390 (annots (annotations-at (or end (point-max)))))
5391 (delete-region (point)
5392 (if end
5393 (if annots (1+ end) end)
5394 (point-max)))
5395 (dolist (annot annots)
5396 (set-extent-endpoints annot (point) (point)))))
5397 (setq start (point))
5398 (if (search-backward "\n\n" nil t)
5399 (progn
5400 (goto-char start)
5401 (unless (or displayed-p (eolp))
5402 ;; Add extra newline.
5403 (insert (propertize (buffer-substring (1- start) start)
5404 'gnus-undeletable t))))
5405 ;; We're in the article header.
5406 (delete-char -1)
5407 (dolist (ovl (overlays-in btn (point)))
5408 (overlay-put ovl 'gnus-button-attachment-extra t)
5409 (overlay-put ovl 'face nil))
5410 (save-restriction
5411 (message-narrow-to-field)
5412 (let ((gnus-treatment-function-alist
5413 '((gnus-treat-highlight-headers
5414 gnus-article-highlight-headers))))
5415 (gnus-treat-article 'head)))))
5416 (when (markerp b)
5417 (setq b (prog1 (marker-position b)
5418 (set-marker b nil))))
5419 (goto-char b))))
5421 (defun gnus-mime-set-charset-parameters (handle charset)
5422 "Set CHARSET to parameters in HANDLE.
5423 CHARSET may either be a string or a symbol."
5424 (unless (stringp charset)
5425 (setq charset (symbol-name charset)))
5426 (if (stringp (car handle))
5427 (dolist (h (cdr handle))
5428 (gnus-mime-set-charset-parameters h charset))
5429 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5430 "message/external-body")
5431 (progn
5432 (unless (mm-handle-cache handle)
5433 (mm-extern-cache-contents handle))
5434 (mm-handle-cache handle))
5435 handle)))
5436 (param (assq 'charset (cdr type))))
5437 (if param
5438 (setcdr param charset)
5439 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5441 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5442 "Insert the MIME part under point into the current buffer using the
5443 specified charset."
5444 (interactive (list nil current-prefix-arg))
5445 (gnus-article-check-buffer)
5446 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5447 (fun (get-text-property (point) 'gnus-callback))
5448 (gnus-newsgroup-ignored-charsets 'gnus-all)
5449 charset form preferred parts)
5450 (when handle
5451 (when (prog1
5452 (and fun
5453 (setq charset
5454 (or (cdr (assq
5456 gnus-summary-show-article-charset-alist))
5457 (mm-read-coding-system "Charset: "))))
5458 (if (mm-handle-undisplayer handle)
5459 (mm-remove-part handle)))
5460 (gnus-mime-set-charset-parameters handle charset)
5461 (when (and (consp (setq form (cdr-safe fun)))
5462 (setq form (ignore-errors
5463 (assq 'gnus-mime-display-alternative form)))
5464 (setq preferred (caddr form))
5465 (progn
5466 (when (eq (car preferred) 'quote)
5467 (setq preferred (cadr preferred)))
5468 (not (equal preferred
5469 (get-text-property (point) 'gnus-data))))
5470 (setq parts (get-text-property (point) 'gnus-part))
5471 (setq parts (cdr (assq parts
5472 gnus-article-mime-handle-alist)))
5473 (equal (mm-handle-media-type parts) "multipart/alternative")
5474 (setq parts (reverse (cdr parts))))
5475 (setcar (cddr form)
5476 (list 'quote (or (cadr (member preferred parts))
5477 (car parts)))))
5478 (funcall fun handle)))))
5480 (defun gnus-mime-view-part-externally (&optional handle)
5481 "View the MIME part under point with an external viewer."
5482 (interactive)
5483 (gnus-article-check-buffer)
5484 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5485 (mm-inlined-types nil)
5486 (mail-parse-charset gnus-newsgroup-charset)
5487 (mail-parse-ignored-charsets
5488 (with-current-buffer gnus-summary-buffer
5489 gnus-newsgroup-ignored-charsets))
5490 (type (mm-handle-media-type handle))
5491 (method (mailcap-mime-info type))
5492 (mm-enable-external t))
5493 (if (not (stringp method))
5494 (gnus-mime-view-part-as-type
5495 nil (lambda (type) (stringp (mailcap-mime-info type))))
5496 (when handle
5497 (mm-display-part handle nil t)))))
5499 (defun gnus-mime-view-part-internally (&optional handle)
5500 "View the MIME part under point with an internal viewer.
5501 If no internal viewer is available, use an external viewer."
5502 (interactive)
5503 (gnus-article-check-buffer)
5504 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5505 (mm-inlined-types '(".*"))
5506 (mm-inline-large-images t)
5507 (mail-parse-charset gnus-newsgroup-charset)
5508 (mail-parse-ignored-charsets
5509 (with-current-buffer gnus-summary-buffer
5510 gnus-newsgroup-ignored-charsets))
5511 (inhibit-read-only t))
5512 (if (not (mm-inlinable-p handle))
5513 (gnus-mime-view-part-as-type
5514 nil (lambda (type) (mm-inlinable-p handle type)))
5515 (when handle
5516 (gnus-bind-safe-url-regexp
5517 (mm-display-part handle nil t))))))
5519 (defun gnus-mime-action-on-part (&optional action)
5520 "Do something with the MIME attachment at \(point\)."
5521 (interactive
5522 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5523 (gnus-article-check-buffer)
5524 (let ((action-pair (assoc action gnus-mime-action-alist)))
5525 (if action-pair
5526 (funcall (cdr action-pair)))))
5528 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5529 "Call FUNCTION on MIME part N.
5530 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5531 If INTERACTIVE, call FUNCTION interactively."
5532 (let (window frame)
5533 ;; Check whether the article is displayed.
5534 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5535 (setq window (get-buffer-window gnus-article-buffer t))
5536 (frame-visible-p (setq frame (window-frame window))))
5537 (error "No article is displayed"))
5538 (with-current-buffer gnus-article-buffer
5539 ;; Check whether the article displays the right contents.
5540 (unless (with-current-buffer gnus-summary-buffer
5541 (eq gnus-current-article (gnus-summary-article-number)))
5542 (error "You should select the right article first"))
5543 (if n
5544 (setq n (prefix-numeric-value n))
5545 (let ((pt (point)))
5546 (setq n (or (get-text-property pt 'gnus-part)
5547 (and (not (bobp))
5548 (get-text-property (1- pt) 'gnus-part))
5549 (get-text-property (prog2
5550 (forward-line 1)
5551 (point)
5552 (goto-char pt))
5553 'gnus-part)
5554 (get-text-property
5555 (or (and (setq pt (previous-single-property-change
5556 pt 'gnus-part))
5557 (1- pt))
5558 (next-single-property-change (point) 'gnus-part)
5559 (point))
5560 'gnus-part)
5561 1))))
5562 ;; Check whether the specified part exists.
5563 (when (> n (length gnus-article-mime-handle-alist))
5564 (error "No such part")))
5565 (unless
5566 (progn
5567 ;; To select the window is needed so that the cursor
5568 ;; might be visible on the MIME button.
5569 (select-window (prog1
5570 window
5571 (setq window (selected-window))
5572 ;; Article may be displayed in the other frame.
5573 (gnus-select-frame-set-input-focus
5574 (prog1
5575 frame
5576 (setq frame (selected-frame))))))
5577 (when (gnus-article-goto-part n)
5578 ;; We point the cursor and the arrow at the MIME button
5579 ;; when the `function' prompt the user for something.
5580 (unless (and (pos-visible-in-window-p)
5581 (> (count-lines (point) (window-end))
5582 (/ (1- (window-height)) 3)))
5583 (recenter (/ (1- (window-height)) 3)))
5584 (let ((cursor-in-non-selected-windows t)
5585 (overlay-arrow-string "=>")
5586 (overlay-arrow-position (point-marker)))
5587 (unwind-protect
5588 (cond
5589 ((and no-handle interactive)
5590 (call-interactively function))
5591 (no-handle
5592 (funcall function))
5593 (interactive
5594 (call-interactively
5595 function (get-text-property (point) 'gnus-data)))
5597 (funcall function
5598 (get-text-property (point) 'gnus-data))))
5599 (set-marker overlay-arrow-position nil)
5600 (unless gnus-auto-select-part
5601 (gnus-select-frame-set-input-focus frame)
5602 (select-window window))))
5604 (if gnus-inhibit-mime-unbuttonizing
5605 ;; This is the default though the program shouldn't reach here.
5606 (error "No such part")
5607 ;; The part which doesn't have the MIME button is selected.
5608 ;; So, we display all the buttons and redo it.
5609 (let ((gnus-inhibit-mime-unbuttonizing t))
5610 (gnus-summary-show-article)
5611 (gnus-article-part-wrapper n function no-handle))))))
5613 (defun gnus-article-pipe-part (n)
5614 "Pipe MIME part N, which is the numerical prefix."
5615 (interactive "P")
5616 (gnus-article-part-wrapper n 'mm-pipe-part))
5618 (defun gnus-article-save-part (n)
5619 "Save MIME part N, which is the numerical prefix."
5620 (interactive "P")
5621 (gnus-article-part-wrapper n 'mm-save-part))
5623 (defun gnus-article-interactively-view-part (n)
5624 "View MIME part N interactively, which is the numerical prefix."
5625 (interactive "P")
5626 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5628 (defun gnus-article-copy-part (n)
5629 "Copy MIME part N, which is the numerical prefix."
5630 (interactive "P")
5631 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5633 (defun gnus-article-view-part-as-charset (n)
5634 "View MIME part N using a specified charset.
5635 N is the numerical prefix."
5636 (interactive "P")
5637 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5639 (defun gnus-article-view-part-externally (n)
5640 "View MIME part N externally, which is the numerical prefix."
5641 (interactive "P")
5642 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5644 (defun gnus-article-inline-part (n)
5645 "Inline MIME part N, which is the numerical prefix."
5646 (interactive "P")
5647 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5649 (defun gnus-article-save-part-and-strip (n)
5650 "Save MIME part N and replace it with an external body.
5651 N is the numerical prefix."
5652 (interactive "P")
5653 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5655 (defun gnus-article-replace-part (n)
5656 "Replace MIME part N with an external body.
5657 N is the numerical prefix."
5658 (interactive "P")
5659 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5661 (defun gnus-article-delete-part (n)
5662 "Delete MIME part N and add some information about the removed part.
5663 N is the numerical prefix."
5664 (interactive "P")
5665 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5667 (defun gnus-article-view-part-as-type (n)
5668 "Choose a MIME media type, and view part N as such.
5669 N is the numerical prefix."
5670 (interactive "P")
5671 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5673 (defun gnus-article-mime-match-handle-first (condition)
5674 (if condition
5675 (let (n)
5676 (dolist (ihandle gnus-article-mime-handle-alist)
5677 (if (and (cond
5678 ((functionp condition)
5679 (funcall condition (cdr ihandle)))
5680 ((eq condition 'undisplayed)
5681 (not (or (mm-handle-undisplayer (cdr ihandle))
5682 (equal (mm-handle-media-type (cdr ihandle))
5683 "multipart/alternative"))))
5684 ((eq condition 'undisplayed-alternative)
5685 (not (mm-handle-undisplayer (cdr ihandle))))
5686 (t t))
5687 (gnus-article-goto-part (car ihandle))
5688 (or (not n) (< (car ihandle) n)))
5689 (setq n (car ihandle))))
5690 (or n 1))
5693 (defun gnus-article-view-part (&optional n)
5694 "View MIME part N, which is the numerical prefix.
5695 If the part is already shown, hide the part. If N is nil, view
5696 all parts."
5697 (interactive "P")
5698 (with-current-buffer gnus-article-buffer
5699 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5700 gnus-article-mime-match-handle-function)))
5701 (when (> n (length gnus-article-mime-handle-alist))
5702 (error "No such part"))
5703 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5704 (when (gnus-article-goto-part n)
5705 (if (equal (car handle) "multipart/alternative")
5706 (progn
5707 (beginning-of-line) ;; Make it toggle subparts
5708 (gnus-article-press-button))
5709 (when (eq (gnus-mm-display-part handle) 'internal)
5710 (gnus-set-window-start)))))))
5712 (defsubst gnus-article-mime-total-parts ()
5713 (if (bufferp (car gnus-article-mime-handles))
5714 1 ;; single part
5715 (1- (length gnus-article-mime-handles))))
5717 (defun gnus-mm-display-part (handle)
5718 "Display HANDLE and fix MIME button."
5719 (let ((id (get-text-property (point) 'gnus-part))
5720 (point (point))
5721 (inhibit-read-only t)
5722 (window (selected-window))
5723 (mail-parse-charset gnus-newsgroup-charset)
5724 (mail-parse-ignored-charsets
5725 (if (gnus-buffer-live-p gnus-summary-buffer)
5726 (with-current-buffer gnus-summary-buffer
5727 gnus-newsgroup-ignored-charsets)
5728 nil))
5729 start retval)
5730 (unwind-protect
5731 (progn
5732 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5733 (when win
5734 (select-window win)
5735 (goto-char point)))
5736 (setq start (next-single-property-change point 'gnus-data
5737 nil (point-max))
5738 point (previous-single-property-change start 'gnus-data))
5739 (if (mm-handle-displayed-p handle)
5740 ;; This will remove the part.
5741 (setq point (copy-marker point)
5742 retval (mm-display-part handle))
5743 (let ((part (or (and (mm-inlinable-p handle)
5744 (mm-inlined-p handle)
5746 (with-temp-buffer
5747 (gnus-bind-safe-url-regexp
5748 (setq retval (mm-display-part handle)))
5749 (unless (zerop (buffer-size))
5750 (buffer-string))))))
5751 (goto-char start)
5752 (unless (bolp)
5753 ;; This is a header button.
5754 (forward-line 1))
5755 (cond ((stringp part)
5756 (save-restriction
5757 (narrow-to-region (point)
5758 (progn
5759 (insert part)
5760 (unless (bolp) (insert "\n"))
5761 (point)))
5762 (gnus-treat-article nil id
5763 (gnus-article-mime-total-parts)
5764 (mm-handle-media-type handle))
5765 (mm-handle-set-undisplayer
5766 handle
5767 `(lambda ()
5768 (let ((inhibit-read-only t))
5769 (delete-region ,(copy-marker (point-min) t)
5770 ,(point-max-marker)))))))
5771 (part
5772 (mm-display-inline handle))))))
5773 (when (markerp point)
5774 (setq point (prog1 (marker-position point)
5775 (set-marker point nil))))
5776 (goto-char point)
5777 ;; Toggle the button appearance between `[button]...' and `[button]'.
5778 (let ((displayed-p (mm-handle-displayed-p handle)))
5779 (gnus-insert-mime-button handle id (list displayed-p))
5780 (if (featurep 'emacs)
5781 (delete-region
5782 (point)
5783 (next-single-property-change (point) 'gnus-data nil (point-max)))
5784 (let* ((end (next-single-property-change (point) 'gnus-data))
5785 (annots (annotations-at (or end (point-max)))))
5786 (delete-region (point)
5787 (if end
5788 (if annots (1+ end) end)
5789 (point-max)))
5790 (dolist (annot annots)
5791 (set-extent-endpoints annot (point) (point)))))
5792 (setq start (point))
5793 (if (search-backward "\n\n" nil t)
5794 (progn
5795 (goto-char start)
5796 (unless (or displayed-p (eolp))
5797 ;; Add extra newline.
5798 (insert (propertize (buffer-substring (1- start) start)
5799 'gnus-undeletable t))))
5800 ;; We're in the article header.
5801 (delete-char -1)
5802 (dolist (ovl (overlays-in point (point)))
5803 (overlay-put ovl 'gnus-button-attachment-extra t)
5804 (overlay-put ovl 'face nil))
5805 (save-restriction
5806 (message-narrow-to-field)
5807 (let ((gnus-treatment-function-alist
5808 '((gnus-treat-highlight-headers
5809 gnus-article-highlight-headers))))
5810 (gnus-treat-article 'head)))))
5811 (goto-char point)
5812 (if (window-live-p window)
5813 (select-window window)))
5814 retval))
5816 (defun gnus-article-goto-part (n)
5817 "Go to MIME part N."
5818 (when gnus-break-pages
5819 (widen))
5820 (article-goto-body)
5821 (prog1
5822 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5823 ;; There may be header buttons.
5824 (text-property-any (point-min) (point) 'gnus-part n)))
5825 part handle end next handles)
5826 (when start
5827 (goto-char start)
5828 (if (setq handle (get-text-property start 'gnus-data))
5829 start
5830 ;; Go to the displayed subpart, assuming this is
5831 ;; multipart/alternative.
5832 (setq part start
5833 end (point-at-eol))
5834 (while (and (not handle)
5835 part
5836 (< part end)
5837 (setq next (text-property-not-all part end
5838 'gnus-data nil)))
5839 (setq part next
5840 handle (get-text-property part 'gnus-data))
5841 (push (cons handle part) handles)
5842 (unless (mm-handle-displayed-p handle)
5843 (setq handle nil
5844 part (text-property-any part end 'gnus-data nil))))
5845 (unless handle
5846 ;; No subpart is displayed, so we find preferred one.
5847 (setq part
5848 (cdr (assq (mm-preferred-alternative
5849 (nreverse (mapcar 'car handles)))
5850 handles))))
5851 (if part
5852 (goto-char (1+ part))
5853 start))))
5854 (when gnus-break-pages
5855 (gnus-narrow-to-page))))
5857 (defun gnus-insert-mime-button (handle id &optional displayed)
5858 (let ((gnus-tmp-name
5859 (or (mm-handle-filename handle)
5860 (mail-content-type-get (mm-handle-type handle) 'url)
5861 ""))
5862 (gnus-tmp-id id)
5863 (gnus-tmp-type (mm-handle-media-type handle))
5864 (gnus-tmp-description (or (mm-handle-description handle) ""))
5865 (gnus-tmp-dots
5866 (if (if displayed (car displayed)
5867 (mm-handle-displayed-p handle))
5868 "" "..."))
5869 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5870 (buffer-size)))
5871 gnus-tmp-type-long b e)
5872 (when (string-match ".*/" gnus-tmp-name)
5873 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5874 (setq gnus-tmp-type-long (concat gnus-tmp-type
5875 (and (not (equal gnus-tmp-name ""))
5876 (concat "; " gnus-tmp-name))))
5877 (unless (equal gnus-tmp-description "")
5878 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5879 (setq b (point))
5880 (gnus-eval-format
5881 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5882 `(keymap ,gnus-mime-button-map
5883 gnus-callback gnus-mm-display-part
5884 gnus-part ,gnus-tmp-id
5885 article-type annotation
5886 gnus-data ,handle
5887 rear-nonsticky t))
5888 (setq e (if (bolp)
5889 ;; Exclude a newline.
5890 (1- (point))
5891 (point)))
5892 (when gnus-article-button-face
5893 (overlay-put (make-overlay b e nil t)
5894 'face gnus-article-button-face))
5895 (widget-convert-button
5896 'link b e
5897 :mime-handle handle
5898 :action 'gnus-widget-press-button
5899 :button-keymap gnus-mime-button-map
5900 :help-echo
5901 (lambda (widget)
5902 ;; Needed to properly clear the message due to a bug in
5903 ;; wid-edit (XEmacs only).
5904 (if (boundp 'help-echo-owns-message)
5905 (setq help-echo-owns-message t))
5906 (format
5907 "%S: %s the MIME part; %S: more options"
5908 (aref gnus-mouse-2 0)
5909 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5910 "hide" "show")
5911 (aref gnus-down-mouse-3 0))))))
5913 (defun gnus-widget-press-button (elems _el)
5914 (goto-char (widget-get elems :from))
5915 (gnus-article-press-button))
5917 (defvar gnus-displaying-mime nil)
5919 (defun gnus-display-mime (&optional ihandles)
5920 "Display the MIME parts."
5921 (save-excursion
5922 (save-selected-window
5923 (let ((window (get-buffer-window gnus-article-buffer))
5924 (point (point)))
5925 (when window
5926 (select-window window)
5927 ;; We have to do this since selecting the window
5928 ;; may change the point. So we set the window point.
5929 (set-window-point window point)))
5930 (let ((handles ihandles)
5931 (inhibit-read-only t))
5932 (cond (handles)
5933 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5934 (when gnus-article-emulate-mime
5935 (mm-uu-dissect-text-parts handles)))
5936 (gnus-article-emulate-mime
5937 (setq handles (mm-uu-dissect))))
5938 (when (and (not ihandles)
5939 (not gnus-displaying-mime))
5940 ;; Top-level call; we clean up.
5941 (when gnus-article-mime-handles
5942 (mm-destroy-parts gnus-article-mime-handles)
5943 (setq gnus-article-mime-handle-alist nil));; A trick.
5944 (setq gnus-article-mime-handles handles)
5945 ;; We allow users to glean info from the handles.
5946 (when gnus-article-mime-part-function
5947 (gnus-mime-part-function handles)))
5948 (if (and handles
5949 (or (not (stringp (car handles)))
5950 (cdr handles)))
5951 (progn
5952 (when (and (not ihandles)
5953 (not gnus-displaying-mime))
5954 ;; Clean up for mime parts.
5955 (article-goto-body)
5956 (delete-region (point) (point-max)))
5957 (let ((gnus-displaying-mime t))
5958 (gnus-mime-display-part handles)))
5959 (save-restriction
5960 (article-goto-body)
5961 (narrow-to-region (point) (point-max))
5962 (gnus-treat-article nil 1 1 "text/plain")
5963 (widen)))
5964 (unless ihandles
5965 ;; Highlight the headers.
5966 (save-excursion
5967 (save-restriction
5968 (article-goto-body)
5969 (narrow-to-region (point-min) (point))
5970 (gnus-article-save-original-date
5971 (gnus-treat-article 'head)))))))
5972 ;; Cope with broken MIME messages.
5973 (goto-char (point-max))
5974 (unless (bolp)
5975 (insert "\n"))))
5977 (defcustom gnus-mime-display-multipart-as-mixed nil
5978 "Display \"multipart\" parts as \"multipart/mixed\".
5980 If t, it overrides nil values of
5981 `gnus-mime-display-multipart-alternative-as-mixed' and
5982 `gnus-mime-display-multipart-related-as-mixed'."
5983 :group 'gnus-article-mime
5984 :type 'boolean)
5986 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5987 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5988 :version "22.1"
5989 :group 'gnus-article-mime
5990 :type 'boolean)
5992 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5993 "Display \"multipart/related\" parts as \"multipart/mixed\".
5995 If displaying \"text/html\" is discouraged \(see
5996 `mm-discouraged-alternatives'\) images or other material inside a
5997 \"multipart/related\" part might be overlooked when this variable is nil."
5998 :version "22.1"
5999 :group 'gnus-article-mime
6000 :type 'boolean)
6002 (defcustom gnus-mime-display-attachment-buttons-in-header t
6003 "Add attachment buttons in the end of the header of an article.
6004 Since MIME attachments tend to be put at the end of an article, we may
6005 overlook them if there is a huge body. This option offers you a copy
6006 of all non-inlinable MIME parts as buttons shown in front of an article.
6007 If nil, don't show those extra buttons."
6008 :version "25.1"
6009 :group 'gnus-article-mime
6010 :type 'boolean)
6012 (defun gnus-mime-display-part (handle)
6013 (cond
6014 ;; Maybe a broken MIME message.
6015 ((null handle))
6016 ;; Single part.
6017 ((not (stringp (car handle)))
6018 (gnus-mime-display-single handle))
6019 ;; User-defined multipart
6020 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6021 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6022 handle))
6023 ;; multipart/alternative
6024 ((and (equal (car handle) "multipart/alternative")
6025 (not (or gnus-mime-display-multipart-as-mixed
6026 gnus-mime-display-multipart-alternative-as-mixed)))
6027 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6028 (push (cons id handle) gnus-article-mime-handle-alist)
6029 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6030 ;; multipart/related
6031 ((and (equal (car handle) "multipart/related")
6032 (not (or gnus-mime-display-multipart-as-mixed
6033 gnus-mime-display-multipart-related-as-mixed)))
6034 (gnus-mime-display-part (cadr handle)))
6035 ((equal (car handle) "multipart/signed")
6036 (gnus-add-wash-type 'signed)
6037 (gnus-mime-display-security handle))
6038 ((equal (car handle) "multipart/encrypted")
6039 (gnus-add-wash-type 'encrypted)
6040 (gnus-mime-display-security handle))
6041 ;; Other multiparts are handled like multipart/mixed.
6043 (gnus-mime-display-mixed (cdr handle)))))
6045 (defun gnus-mime-part-function (handles)
6046 (if (stringp (car handles))
6047 (mapcar 'gnus-mime-part-function (cdr handles))
6048 (funcall gnus-article-mime-part-function handles)))
6050 (defun gnus-mime-display-mixed (handles)
6051 (mapcar 'gnus-mime-display-part handles))
6053 (defun gnus-mime-display-single (handle)
6054 (let ((type (mm-handle-media-type handle))
6055 (ignored gnus-ignored-mime-types)
6056 (not-attachment t)
6057 display text)
6058 (catch 'ignored
6059 (progn
6060 (while ignored
6061 (when (string-match (pop ignored) type)
6062 (throw 'ignored nil)))
6063 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6064 (with-current-buffer gnus-summary-buffer
6065 gnus-inhibit-images)
6066 gnus-inhibit-images)
6067 (string-match "\\`image/" type)))
6068 (setq not-attachment
6069 (and (not (mm-inline-override-p handle))
6070 (or (not (mm-handle-disposition handle))
6071 (equal (car (mm-handle-disposition handle))
6072 "inline")
6073 (mm-attachment-override-p handle))))
6074 (mm-automatic-display-p handle)
6075 (or (and
6076 (mm-inlinable-p handle)
6077 (mm-inlined-p handle))
6078 (mm-automatic-external-display-p type)))
6079 (setq display t)
6080 (when (equal (mm-handle-media-supertype handle) "text")
6081 (setq text t)))
6082 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6083 beg)
6084 (unless id
6085 (setq id (1+ (length gnus-article-mime-handle-alist)))
6086 (push (cons id handle) gnus-article-mime-handle-alist))
6087 (when (and display
6088 (equal (mm-handle-media-supertype handle) "message"))
6089 (insert-char
6091 (cond ((not (bolp)) 2)
6092 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6093 (t 1))))
6094 (when (or (not display)
6095 (not (gnus-unbuttonized-mime-type-p type))
6096 (eq id gnus-mime-buttonized-part-id))
6097 (gnus-insert-mime-button
6098 handle id (list (or display (and not-attachment text)))))
6099 (setq beg (point))
6100 (cond
6101 (display
6102 (let ((mail-parse-charset gnus-newsgroup-charset)
6103 (mail-parse-ignored-charsets
6104 (save-excursion (condition-case ()
6105 (set-buffer gnus-summary-buffer)
6106 (error))
6107 gnus-newsgroup-ignored-charsets)))
6108 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6109 ((and text not-attachment)
6110 (mm-display-inline handle)))
6111 (goto-char (point-max))
6112 (if (string-match "\\`image/" type)
6113 (gnus-article-insert-newline)
6114 (if (prog1
6115 (= (skip-chars-backward "\n") -1)
6116 (unless (eobp) (forward-char 1)))
6117 (gnus-article-insert-newline)
6118 (put-text-property (point) (point-max) 'gnus-undeletable t))
6119 (goto-char (point-max)))
6120 ;; Do highlighting.
6121 (save-excursion
6122 (save-restriction
6123 (narrow-to-region beg (point))
6124 (if (eq handle gnus-article-mime-handles)
6125 ;; The format=flowed case.
6126 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6127 ;; Don't count signature parts that are never displayed.
6128 ;; The part number should be re-calculated supposing this
6129 ;; might be a message/rfc822 part.
6130 (let (handles)
6131 (dolist (part gnus-article-mime-handles)
6132 (unless (or (stringp part)
6133 (equal (car (mm-handle-type part))
6134 "application/pgp-signature"))
6135 (push part handles)))
6136 (gnus-treat-article
6137 nil (length (memq handle handles)) (length handles)
6138 (mm-handle-media-type handle)))))))))))
6140 (defun gnus-unbuttonized-mime-type-p (type)
6141 "Say whether TYPE is to be unbuttonized."
6142 (unless gnus-inhibit-mime-unbuttonizing
6143 (when (catch 'found
6144 (let ((types gnus-unbuttonized-mime-types))
6145 (while types
6146 (when (string-match (pop types) type)
6147 (throw 'found t)))))
6148 (not (catch 'found
6149 (let ((types gnus-buttonized-mime-types))
6150 (while types
6151 (when (string-match (pop types) type)
6152 (throw 'found t)))))))))
6154 (defun gnus-article-insert-newline ()
6155 "Insert a newline, but mark it as undeletable."
6156 (gnus-put-text-property
6157 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6159 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6160 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6161 (ihandles handles)
6162 (point (point))
6163 handle (inhibit-read-only t) from begend not-pref)
6164 (save-window-excursion
6165 (save-restriction
6166 (when ibegend
6167 (narrow-to-region (car ibegend)
6168 (or (cdr ibegend)
6169 (progn
6170 (goto-char (car ibegend))
6171 (forward-line 2)
6172 (point))))
6173 (delete-region (point-min) (point-max))
6174 (mm-remove-parts handles))
6175 (setq begend (list (point-marker)))
6176 ;; Do the toggle.
6177 (unless (setq not-pref (cadr (member preferred ihandles)))
6178 (setq not-pref (car ihandles)))
6179 (when (or ibegend
6180 (not preferred)
6181 (not (gnus-unbuttonized-mime-type-p
6182 "multipart/alternative")))
6183 (gnus-add-text-properties
6184 (setq from (point))
6185 (progn
6186 (insert (format "%d. " id))
6187 (point))
6188 `(gnus-callback
6189 (lambda (handles)
6190 (unless ,(not ibegend)
6191 (setq gnus-article-mime-handle-alist
6192 ',gnus-article-mime-handle-alist))
6193 (gnus-mime-display-alternative
6194 ',ihandles ',not-pref ',begend ,id))
6195 keymap ,gnus-mime-button-map
6196 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6197 face ,gnus-article-button-face
6198 gnus-part ,id
6199 article-type multipart
6200 rear-nonsticky t))
6201 (widget-convert-button 'link from (point)
6202 :action 'gnus-widget-press-button
6203 :button-keymap gnus-widget-button-keymap)
6204 ;; Do the handles
6205 (while (setq handle (pop handles))
6206 (gnus-add-text-properties
6207 (setq from (point))
6208 (progn
6209 (insert (format "(%c) %-18s"
6210 (if (equal handle preferred) ?* ? )
6211 (mm-handle-media-type handle)))
6212 (point))
6213 `(gnus-callback
6214 (lambda (handles)
6215 (unless ,(not ibegend)
6216 (setq gnus-article-mime-handle-alist
6217 ',gnus-article-mime-handle-alist))
6218 (gnus-mime-display-alternative
6219 ',ihandles ',handle ',begend ,id))
6220 keymap ,gnus-mime-button-map
6221 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6222 face ,gnus-article-button-face
6223 gnus-part ,id
6224 gnus-data ,handle
6225 rear-nonsticky t))
6226 (widget-convert-button 'link from (point)
6227 :action 'gnus-widget-press-button
6228 :button-keymap gnus-widget-button-keymap)
6229 (insert " "))
6230 (insert "\n\n"))
6231 (when preferred
6232 (if (stringp (car preferred))
6233 (gnus-display-mime preferred)
6234 (let ((mail-parse-charset gnus-newsgroup-charset)
6235 (mail-parse-ignored-charsets
6236 (with-current-buffer gnus-summary-buffer
6237 gnus-newsgroup-ignored-charsets)))
6238 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6239 ;; Do highlighting.
6240 (save-excursion
6241 (save-restriction
6242 (narrow-to-region (car begend) (point-max))
6243 (gnus-treat-article
6244 nil (length gnus-article-mime-handle-alist)
6245 (gnus-article-mime-total-parts)
6246 (mm-handle-media-type preferred))))))
6247 (goto-char (point-max))
6248 (setcdr begend (point-marker)))))
6249 (when ibegend
6250 (goto-char point)))
6251 ;; Redraw attachment buttons in the header.
6252 (when gnus-mime-display-attachment-buttons-in-header
6253 (gnus-mime-buttonize-attachments-in-header)))
6255 (defconst gnus-article-wash-status-strings
6256 (let ((alist '((cite "c" "Possible hidden citation text"
6257 " " "All citation text visible")
6258 (headers "h" "Hidden headers"
6259 " " "All headers visible.")
6260 (pgp "p" "Encrypted or signed message status hidden"
6261 " " "No hidden encryption nor digital signature status")
6262 (signature "s" "Signature has been hidden"
6263 " " "Signature is visible")
6264 (overstrike "o" "Overstrike (^H) characters applied"
6265 " " "No overstrike characters applied")
6266 (emphasis "e" "/*_Emphasis_*/ characters applied"
6267 " " "No /*_emphasis_*/ characters applied")))
6268 result)
6269 (dolist (entry alist result)
6270 (let ((key (nth 0 entry))
6271 (on (copy-sequence (nth 1 entry)))
6272 (on-help (nth 2 entry))
6273 (off (copy-sequence (nth 3 entry)))
6274 (off-help (nth 4 entry)))
6275 (put-text-property 0 1 'help-echo on-help on)
6276 (put-text-property 0 1 'help-echo off-help off)
6277 (push (list key on off) result))))
6278 "Alist of strings describing wash status in the mode line.
6279 Each entry has the form (KEY ON OF), where the KEY is a symbol
6280 representing the particular washing function, ON is the string to use
6281 in the article mode line when the washing function is active, and OFF
6282 is the string to use when it is inactive.")
6284 (defun gnus-article-wash-status-entry (key value)
6285 (let ((entry (assoc key gnus-article-wash-status-strings)))
6286 (if value (nth 1 entry) (nth 2 entry))))
6288 (defun gnus-article-wash-status ()
6289 "Return a string which display status of article washing."
6290 (with-current-buffer gnus-article-buffer
6291 (let ((cite (memq 'cite gnus-article-wash-types))
6292 (headers (memq 'headers gnus-article-wash-types))
6293 (boring (memq 'boring-headers gnus-article-wash-types))
6294 (pgp (memq 'pgp gnus-article-wash-types))
6295 (pem (memq 'pem gnus-article-wash-types))
6296 (signed (memq 'signed gnus-article-wash-types))
6297 (encrypted (memq 'encrypted gnus-article-wash-types))
6298 (signature (memq 'signature gnus-article-wash-types))
6299 (overstrike (memq 'overstrike gnus-article-wash-types))
6300 (emphasis (memq 'emphasis gnus-article-wash-types)))
6301 (concat
6302 (gnus-article-wash-status-entry 'cite cite)
6303 (gnus-article-wash-status-entry 'headers (or headers boring))
6304 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6305 (gnus-article-wash-status-entry 'signature signature)
6306 (gnus-article-wash-status-entry 'overstrike overstrike)
6307 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6309 (defun gnus-add-wash-type (type)
6310 "Add a washing of TYPE to the current status."
6311 (add-to-list 'gnus-article-wash-types type))
6313 (defun gnus-delete-wash-type (type)
6314 "Add a washing of TYPE to the current status."
6315 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6317 (defun gnus-add-image (category image)
6318 "Add IMAGE of CATEGORY to the list of displayed images."
6319 (let ((entry (assq category gnus-article-image-alist)))
6320 (unless entry
6321 (setq entry (list category))
6322 (push entry gnus-article-image-alist))
6323 (nconc entry (list image))))
6325 (defun gnus-delete-images (category)
6326 "Delete all images in CATEGORY."
6327 (let ((entry (assq category gnus-article-image-alist)))
6328 (dolist (image (cdr entry))
6329 (gnus-remove-image image category))
6330 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6331 (gnus-delete-wash-type category)))
6333 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6335 (defun gnus-article-maybe-hide-headers ()
6336 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6337 Provided for backwards compatibility."
6338 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6339 (not (with-current-buffer gnus-summary-buffer
6340 gnus-have-all-headers)))
6341 (not gnus-inhibit-hiding))
6342 (gnus-article-hide-headers)))
6344 (declare-function shr-put-image "shr" (data alt &optional flags))
6346 (defun gnus-shr-put-image (data alt &optional flags)
6347 "Put image DATA with a string ALT. Enable image to be deleted."
6348 (let ((image (if flags
6349 (shr-put-image data (propertize (or alt "*")
6350 'gnus-image-category 'shr)
6351 flags)
6352 ;; Old `shr-put-image' doesn't take the optional `flags'
6353 ;; argument.
6354 (shr-put-image data (propertize (or alt "*")
6355 'gnus-image-category 'shr)))))
6356 (when image
6357 (gnus-add-image 'shr image))))
6359 (defun gnus-article-mime-handles (&optional alist id all)
6360 (if alist
6361 (let ((i 1) newid flat)
6362 (dolist (handle alist flat)
6363 (setq newid (append id (list i))
6364 i (1+ i))
6365 (if (stringp (car handle))
6366 (setq flat (nconc flat (gnus-article-mime-handles
6367 (cdr handle) newid all)))
6368 (delq (rassq handle all) all)
6369 (setq flat (nconc flat (list (cons newid handle)))))))
6370 (let ((flat (list nil)))
6371 ;; Assume that elements of `gnus-article-mime-handle-alist'
6372 ;; are in the decreasing order, but unnumbered subsidiaries
6373 ;; in each element are in the increasing order.
6374 (dolist (handle (reverse gnus-article-mime-handle-alist))
6375 (if (stringp (cadr handle))
6376 (setq flat (nconc flat (gnus-article-mime-handles
6377 (cddr handle) (list (car handle)) flat)))
6378 (delq (rassq (cdr handle) flat) flat)
6379 (setq flat (nconc flat (list (cons (list (car handle))
6380 (cdr handle)))))))
6381 (setq flat (cdr flat))
6382 (mapc (lambda (handle)
6383 (if (cdar handle)
6384 ;; This is a hidden (i.e. unnumbered) handle.
6385 (progn
6386 (setcar handle
6387 (1+ (caar gnus-article-mime-handle-alist)))
6388 (push handle gnus-article-mime-handle-alist))
6389 (setcar handle (caar handle))))
6390 flat)
6391 flat)))
6393 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6394 "Show attachments as buttons in the end of the header of an article.
6395 This function toggles the display when called interactively. Note that
6396 buttons to be added to the header are only the ones that aren't inlined
6397 in the body. Use `gnus-header-face-alist' to highlight buttons."
6398 (interactive (list t))
6399 (gnus-with-article-buffer
6400 (let ((case-fold-search t) buttons handle type st)
6401 (save-excursion
6402 (save-restriction
6403 (widen)
6404 (article-narrow-to-head)
6405 ;; Header buttons exist?
6406 (while (and (not buttons)
6407 (re-search-forward "^attachments?:[\n ]+" nil t))
6408 (when (get-char-property (match-end 0)
6409 'gnus-button-attachment-extra)
6410 (setq buttons (match-beginning 0))))
6411 (widen)
6412 (when buttons
6413 ;; Delete header buttons.
6414 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6415 (match-beginning 0)
6416 (point-max))))
6417 (unless (and interactive buttons)
6418 ;; Find buttons.
6419 (setq buttons nil)
6420 (dolist (button (gnus-article-mime-handles))
6421 (setq handle (cdr button)
6422 type (mm-handle-media-type handle))
6423 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6424 (with-current-buffer gnus-summary-buffer
6425 gnus-inhibit-images)
6426 gnus-inhibit-images)
6427 (string-match "\\`image/" type))
6428 (mm-inline-override-p handle)
6429 (and (mm-handle-disposition handle)
6430 (not (equal (car (mm-handle-disposition handle))
6431 "inline"))
6432 (not (mm-attachment-override-p handle)))
6433 (not (mm-automatic-display-p handle))
6434 (not (or (and (mm-inlinable-p handle)
6435 (mm-inlined-p handle))
6436 (mm-automatic-external-display-p type))))
6437 (push button buttons)))
6438 (when buttons
6439 ;; Add header buttons.
6440 (article-goto-body)
6441 (forward-line -1)
6442 (narrow-to-region (point) (point))
6443 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6444 (dolist (button (nreverse buttons))
6445 (setq st (point))
6446 (insert " ")
6447 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6448 (gnus-insert-mime-button handle (car button))
6449 (skip-chars-backward "\t\n ")
6450 (delete-region (point) (point-max))
6451 (when (> (current-column) (window-width))
6452 (goto-char st)
6453 (insert "\n")
6454 (end-of-line)))
6455 (insert "\n")
6456 (dolist (ovl (overlays-in (point-min) (point)))
6457 (overlay-put ovl 'gnus-button-attachment-extra t)
6458 (overlay-put ovl 'face nil))
6459 (let ((gnus-treatment-function-alist
6460 '((gnus-treat-highlight-headers
6461 gnus-article-highlight-headers))))
6462 (gnus-treat-article 'head)))))))))
6464 ;;; Article savers.
6466 (defun gnus-output-to-file (file-name)
6467 "Append the current article to a file named FILE-NAME.
6468 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6469 text and used as the value of the coding cookie which is added to the
6470 top of a file. Otherwise, this function saves a raw article without
6471 the coding cookie."
6472 (let* ((artbuf (current-buffer))
6473 (file-name-coding-system nnmail-pathname-coding-system)
6474 (coding gnus-article-save-coding-system)
6475 (coding-system-for-read (if coding
6476 nil ;; Rely on the coding cookie.
6477 mm-text-coding-system))
6478 (coding-system-for-write (or coding
6479 mm-text-coding-system-for-write
6480 mm-text-coding-system))
6481 (exists (file-exists-p file-name)))
6482 (with-temp-buffer
6483 (when exists
6484 (insert-file-contents file-name)
6485 (goto-char (point-min))
6486 ;; Remove the existing coding cookie.
6487 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6488 (delete-region (match-beginning 0) (match-end 0))))
6489 (goto-char (point-max))
6490 (insert-buffer-substring artbuf)
6491 ;; Append newline at end of the buffer as separator, and then
6492 ;; save it to file.
6493 (goto-char (point-max))
6494 (insert "\n")
6495 (when coding
6496 ;; If the coding system is not suitable to encode the text,
6497 ;; ask a user for a proper one.
6498 (when (fboundp 'select-safe-coding-system)
6499 (setq coding (coding-system-base
6500 (save-window-excursion
6501 (select-safe-coding-system (point-min) (point-max)
6502 coding))))
6503 (setq coding-system-for-write
6504 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6505 coding)))
6506 (goto-char (point-min))
6507 ;; Add the coding cookie.
6508 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6509 coding-system-for-write)))
6510 (if exists
6511 (progn
6512 (write-region (point-min) (point-max) file-name nil 'no-message)
6513 (message "Appended to %s" file-name))
6514 (write-region (point-min) (point-max) file-name))))
6517 (defun gnus-narrow-to-page (&optional arg)
6518 "Narrow the article buffer to a page.
6519 If given a numerical ARG, move forward ARG pages."
6520 (interactive "P")
6521 (setq arg (if arg (prefix-numeric-value arg) 0))
6522 (with-current-buffer gnus-article-buffer
6523 (widen)
6524 ;; Remove any old next/prev buttons.
6525 (when (gnus-visual-p 'page-marker)
6526 (let ((inhibit-read-only t))
6527 (gnus-remove-text-with-property 'gnus-prev)
6528 (gnus-remove-text-with-property 'gnus-next)))
6529 (let (st nd pt)
6530 (when (save-excursion
6531 (cond ((< arg 0)
6532 (if (re-search-backward page-delimiter nil 'move (abs arg))
6533 (prog1
6534 (setq nd (match-beginning 0)
6535 pt nd)
6536 (when (re-search-backward page-delimiter nil t)
6537 (setq st (match-end 0))))
6538 (when (re-search-forward page-delimiter nil t)
6539 (setq nd (match-beginning 0)
6540 pt (point-min)))))
6541 ((> arg 0)
6542 (if (re-search-forward page-delimiter nil 'move arg)
6543 (prog1
6544 (setq st (match-end 0)
6545 pt st)
6546 (when (re-search-forward page-delimiter nil t)
6547 (setq nd (match-beginning 0))))
6548 (when (re-search-backward page-delimiter nil t)
6549 (setq st (match-end 0)
6550 pt (point-max)))))
6552 (when (re-search-backward page-delimiter nil t)
6553 (goto-char (setq st (match-end 0))))
6554 (when (re-search-forward page-delimiter nil t)
6555 (setq nd (match-beginning 0)))
6556 (or st nd))))
6557 (setq gnus-page-broken t)
6558 (when pt (goto-char pt))
6559 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6560 (when (gnus-visual-p 'page-marker)
6561 (save-excursion
6562 (when nd
6563 (goto-char nd)
6564 (gnus-insert-next-page-button))
6565 (when st
6566 (goto-char st)
6567 (gnus-insert-prev-page-button))))))))
6569 ;; Article mode commands
6571 (defun gnus-article-goto-next-page ()
6572 "Show the next page of the article."
6573 (interactive)
6574 (when (gnus-article-next-page)
6575 (goto-char (point-min))
6576 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6579 (defun gnus-article-goto-prev-page ()
6580 "Show the previous page of the article."
6581 (interactive)
6582 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6583 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6584 (gnus-article-prev-page nil)))
6586 ;; This is cleaner but currently breaks `gnus-pick-mode':
6588 ;; (defun gnus-article-goto-next-page ()
6589 ;; "Show the next page of the article."
6590 ;; (interactive)
6591 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6592 ;; (gnus-summary-next-page)))
6594 ;; (defun gnus-article-goto-prev-page ()
6595 ;; "Show the next page of the article."
6596 ;; (interactive)
6597 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6598 ;; (gnus-summary-prev-page)))
6600 (defun gnus-article-next-page (&optional lines)
6601 "Show the next page of the current article.
6602 If end of article, return non-nil. Otherwise return nil.
6603 Argument LINES specifies lines to be scrolled up."
6604 (interactive "p")
6605 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6606 (if (and (not (and gnus-article-over-scroll
6607 (> (count-lines (window-start) (point-max))
6608 (if (featurep 'xemacs)
6609 (or lines (1- (window-height)))
6610 (+ (or lines (1- (window-height))) scroll-margin)))))
6611 (save-excursion
6612 (end-of-line)
6613 (and (pos-visible-in-window-p) ;Not continuation line.
6614 (>= (point) (point-max)))))
6615 ;; Nothing in this page.
6616 (if (or (not gnus-page-broken)
6617 (save-excursion
6618 (save-restriction
6619 (widen)
6620 (forward-line)
6621 (eobp)))) ;Real end-of-buffer?
6622 (progn
6623 (when gnus-article-over-scroll
6624 (gnus-article-next-page-1 lines))
6625 t) ;Nothing more.
6626 (gnus-narrow-to-page 1) ;Go to next page.
6627 nil)
6628 ;; More in this page.
6629 (gnus-article-next-page-1 lines)
6630 nil))
6632 (defun gnus-article-beginning-of-window ()
6633 "Move point to the beginning of the window.
6634 In Emacs, the point is placed at the line number which `scroll-margin'
6635 specifies."
6636 (if (featurep 'xemacs)
6637 (move-to-window-line 0)
6638 ;; There is an obscure bug in Emacs that makes it impossible to
6639 ;; scroll past big pictures in the article buffer. Try to fix
6640 ;; this by adding a sanity check by counting the lines visible.
6641 (when (> (count-lines (window-start) (window-end)) 30)
6642 (move-to-window-line
6643 (min (max 0 scroll-margin)
6644 (max 1 (- (window-height)
6645 (if mode-line-format 1 0)
6646 (if header-line-format 1 0)
6647 2)))))))
6649 (defvar scroll-in-place)
6651 (defun gnus-article-next-page-1 (lines)
6652 (condition-case ()
6653 (let ((scroll-in-place nil)
6654 (auto-window-vscroll nil))
6655 (scroll-up lines))
6656 (end-of-buffer
6657 ;; Long lines may cause an end-of-buffer error.
6658 (goto-char (point-max))))
6659 (gnus-article-beginning-of-window))
6661 (defun gnus-article-prev-page (&optional lines)
6662 "Show previous page of current article.
6663 Argument LINES specifies lines to be scrolled down."
6664 (interactive "p")
6665 (move-to-window-line 0)
6666 (if (and gnus-page-broken
6667 (bobp)
6668 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6669 (progn
6670 (gnus-narrow-to-page -1) ;Go to previous page.
6671 (goto-char (point-max))
6672 (recenter (if gnus-article-over-scroll
6673 (if lines
6674 (max (if (featurep 'xemacs)
6675 lines
6676 (+ lines scroll-margin))
6678 (- (window-height) 2))
6679 -1)))
6680 (prog1
6681 (condition-case ()
6682 (let ((scroll-in-place nil))
6683 (scroll-down lines))
6684 (beginning-of-buffer
6685 (goto-char (point-min))))
6686 (gnus-article-beginning-of-window))))
6688 (defun gnus-article-only-boring-p ()
6689 "Decide whether there is only boring text remaining in the article.
6690 Something \"interesting\" is a word of at least two letters that does
6691 not have a face in `gnus-article-boring-faces'."
6692 (when (and gnus-article-skip-boring
6693 (boundp 'gnus-article-boring-faces)
6694 (symbol-value 'gnus-article-boring-faces))
6695 (save-excursion
6696 (let ((inhibit-point-motion-hooks t))
6697 (catch 'only-boring
6698 (while (re-search-forward "\\b\\w\\w" nil t)
6699 (forward-char -1)
6700 (when (not (gnus-intersection
6701 (gnus-faces-at (point))
6702 (symbol-value 'gnus-article-boring-faces)))
6703 (throw 'only-boring nil)))
6704 (throw 'only-boring t))))))
6706 (defun gnus-article-refer-article ()
6707 "Read article specified by message-id around point."
6708 (interactive)
6709 (save-excursion
6710 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6711 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6712 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6713 (let ((msg-id (concat "<" (match-string 0) ">")))
6714 (set-buffer gnus-summary-buffer)
6715 (gnus-summary-refer-article msg-id))
6716 (error "No references around point"))))
6718 (defun gnus-article-show-summary ()
6719 "Reconfigure windows to show summary buffer."
6720 (interactive)
6721 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6722 (error "There is no summary buffer for this article buffer")
6723 (gnus-article-set-globals)
6724 (gnus-configure-windows 'article)
6725 (gnus-summary-goto-subject gnus-current-article)
6726 (gnus-summary-position-point)))
6728 (defun gnus-article-describe-briefly ()
6729 "Describe article mode commands briefly."
6730 (interactive)
6731 (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")))
6733 (defun gnus-article-check-buffer ()
6734 "Beep if not in an article buffer."
6735 (unless (derived-mode-p 'gnus-article-mode)
6736 (error "Command invoked outside of a Gnus article buffer")))
6738 (defvar gnus-pick-mode)
6740 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6741 "Read a summary buffer key sequence and execute it from the article buffer."
6742 (interactive "P")
6743 (gnus-article-check-buffer)
6744 (let ((nosaves
6745 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6746 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6747 "=" "^" "\M-^" "|"))
6748 (nosave-but-article
6749 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6750 "An" "Ap" [?A (meta return)] [?A delete]))
6751 (nosave-in-article
6752 '("AS" "\C-d"))
6753 keys new-sum-point)
6754 (with-current-buffer gnus-article-current-summary
6755 (let (gnus-pick-mode)
6756 (setq unread-command-events (nconc unread-command-events
6757 (list (or key last-command-event)))
6758 keys (if (featurep 'xemacs)
6759 (events-to-keys (read-key-sequence nil t))
6760 (read-key-sequence nil t)))))
6762 (message "")
6764 (cond
6765 ((eq (aref keys (1- (length keys))) ?\C-h)
6766 (gnus-article-describe-bindings (substring keys 0 -1)))
6767 ((or (member keys nosaves)
6768 (member keys nosave-but-article)
6769 (member keys nosave-in-article))
6770 (let (func)
6771 (save-window-excursion
6772 (pop-to-buffer gnus-article-current-summary)
6773 ;; We disable the pick minor mode commands.
6774 (let (gnus-pick-mode)
6775 (setq func (key-binding keys t))))
6776 (if (or (not func)
6777 (numberp func))
6778 (ding)
6779 (unless (member keys nosave-in-article)
6780 (set-buffer gnus-article-current-summary))
6781 (when (and (symbolp func)
6782 (get func 'disabled))
6783 (error "Function %s disabled" func))
6784 (call-interactively func)
6785 (setq new-sum-point (point)))
6786 (when (member keys nosave-but-article)
6787 (pop-to-buffer gnus-article-buffer))))
6789 ;; These commands should restore window configuration.
6790 (let ((obuf (current-buffer))
6791 (owin (current-window-configuration))
6792 win func in-buffer selected new-sum-start new-sum-hscroll err)
6793 (cond (not-restore-window
6794 (pop-to-buffer gnus-article-current-summary)
6795 (setq win (selected-window)))
6796 ((setq win (get-buffer-window gnus-article-current-summary))
6797 (select-window win))
6799 (let ((summary-buffer gnus-article-current-summary))
6800 (gnus-configure-windows 'article)
6801 (unless (setq win (get-buffer-window summary-buffer 'visible))
6802 (let ((gnus-buffer-configuration
6803 '((article ((vertical 1.0
6804 (summary 0.25 point)
6805 (article 1.0)))))))
6806 (gnus-configure-windows 'article))
6807 (setq win (get-buffer-window summary-buffer 'visible)))
6808 (gnus-select-frame-set-input-focus (window-frame win))
6809 (select-window win))))
6810 (setq in-buffer (current-buffer))
6811 ;; We disable the pick minor mode commands.
6812 (setq func (let (gnus-pick-mode)
6813 (key-binding keys t)))
6814 (when (get func 'disabled)
6815 (error "Function %s disabled" func))
6816 (if (and func
6817 (functionp func)
6818 (condition-case code
6819 (progn
6820 (call-interactively func)
6822 (error
6823 (setq err code)
6824 nil)))
6825 (progn
6826 (when (eq win (selected-window))
6827 (setq new-sum-point (point)
6828 new-sum-start (window-start win)
6829 new-sum-hscroll (window-hscroll win)))
6830 (when (or (eq in-buffer (current-buffer))
6831 (when (eq obuf (current-buffer))
6832 (set-buffer in-buffer)
6834 (setq selected (ignore-errors (gnus-summary-select-article)))
6835 (set-buffer obuf)
6836 (unless not-restore-window
6837 (set-window-configuration owin))
6838 (when (and (eq selected 'old)
6839 new-sum-point)
6840 (set-window-start (get-buffer-window (current-buffer))
6842 (set-window-point (get-buffer-window (current-buffer))
6843 (if (article-goto-body)
6844 (1- (point))
6845 (point))))
6846 (when (and (not not-restore-window)
6847 new-sum-point
6848 (window-live-p win)
6849 (with-current-buffer (window-buffer win)
6850 (derived-mode-p 'gnus-summary-mode)))
6851 (set-window-point win new-sum-point)
6852 (set-window-start win new-sum-start)
6853 (set-window-hscroll win new-sum-hscroll))))
6854 (set-window-configuration owin)
6855 (if err
6856 (signal (car err) (cdr err))
6857 (ding))))))))
6859 (defun gnus-article-read-summary-send-keys ()
6860 (interactive)
6861 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6862 (gnus-article-read-summary-keys)))
6864 (defun gnus-article-describe-key (key)
6865 "Display documentation of the function invoked by KEY.
6866 KEY is a string or a vector."
6867 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6868 (read-key-sequence "Describe key: "))))
6869 (gnus-article-check-buffer)
6870 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6871 gnus-article-read-summary-send-keys))
6872 (with-current-buffer gnus-article-current-summary
6873 (setq unread-command-events
6874 (if (featurep 'xemacs)
6875 (append key unread-command-events)
6876 (nconc
6877 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6878 (list 'meta (- x 128))
6880 key)
6881 unread-command-events)))
6882 (let ((cursor-in-echo-area t)
6883 gnus-pick-mode)
6884 (describe-key (read-key-sequence nil t))))
6885 (describe-key key)))
6887 (defun gnus-article-describe-key-briefly (key &optional insert)
6888 "Display documentation of the function invoked by KEY.
6889 KEY is a string or a vector."
6890 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6891 (read-key-sequence "Describe key: "))
6892 current-prefix-arg))
6893 (gnus-article-check-buffer)
6894 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6895 gnus-article-read-summary-send-keys))
6896 (with-current-buffer gnus-article-current-summary
6897 (setq unread-command-events
6898 (if (featurep 'xemacs)
6899 (append key unread-command-events)
6900 (nconc
6901 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6902 (list 'meta (- x 128))
6904 key)
6905 unread-command-events)))
6906 (let ((cursor-in-echo-area t)
6907 gnus-pick-mode)
6908 (describe-key-briefly (read-key-sequence nil t) insert)))
6909 (describe-key-briefly key insert)))
6911 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6912 (defvar gnus-agent-summary-mode)
6913 (defvar gnus-draft-mode)
6914 (defvar help-xref-stack-item)
6915 (defvar help-xref-following)
6917 (defun gnus-article-describe-bindings (&optional prefix)
6918 "Show a list of all defined keys, and their definitions.
6919 The optional argument PREFIX, if non-nil, should be a key sequence;
6920 then we display only bindings that start with that prefix."
6921 (interactive)
6922 (gnus-article-check-buffer)
6923 (let ((keymap (copy-keymap gnus-article-mode-map))
6924 (map (copy-keymap gnus-article-send-map))
6925 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6926 parent agent draft)
6927 (define-key keymap "S" map)
6928 (define-key map [t] nil)
6929 (with-current-buffer gnus-article-current-summary
6930 (set-keymap-parent
6931 keymap
6932 (if (setq parent (keymap-parent gnus-article-mode-map))
6933 (prog1
6934 (setq parent (copy-keymap parent))
6935 (set-keymap-parent parent (current-local-map)))
6936 (current-local-map)))
6937 (set-keymap-parent map (key-binding "S"))
6938 (let (key def gnus-pick-mode)
6939 (while sumkeys
6940 (setq key (pop sumkeys))
6941 (cond ((and (vectorp key) (= (length key) 1)
6942 (consp (setq def (aref key 0)))
6943 (numberp (car def)) (numberp (cdr def)))
6944 (when (< (max (car def) (cdr def)) 128)
6945 (setq sumkeys
6946 (append (mapcar
6947 #'vector
6948 (nreverse (gnus-uncompress-range def)))
6949 sumkeys))))
6950 ((setq def (key-binding key))
6951 (unless (eq def 'undefined)
6952 (define-key keymap key def))))))
6953 (when (boundp 'gnus-agent-summary-mode)
6954 (setq agent gnus-agent-summary-mode))
6955 (when (boundp 'gnus-draft-mode)
6956 (setq draft gnus-draft-mode)))
6957 (with-temp-buffer
6958 (use-local-map keymap)
6959 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6960 (set (make-local-variable 'gnus-draft-mode) draft)
6961 (describe-bindings prefix))
6962 (let ((item `((lambda (prefix)
6963 (with-current-buffer ,(current-buffer)
6964 (gnus-article-describe-bindings prefix)))
6965 ,prefix)))
6966 ;; Loading `help-mode' here is necessary if `describe-bindings'
6967 ;; is replaced with something, e.g. `helm-descbinds'.
6968 (require 'help-mode)
6969 (with-current-buffer (let (help-xref-following) (help-buffer))
6970 (setq help-xref-stack-item item)))))
6972 (defun gnus-article-reply-with-original (&optional wide)
6973 "Start composing a reply mail to the current message.
6974 The text in the region will be yanked. If the region isn't active,
6975 the entire article will be yanked."
6976 (interactive)
6977 (let ((article (cdr gnus-article-current))
6978 contents)
6979 (if (not (gnus-region-active-p))
6980 (with-current-buffer gnus-summary-buffer
6981 (gnus-summary-reply (list (list article)) wide))
6982 (setq contents (buffer-substring (point) (mark t)))
6983 ;; Deactivate active regions.
6984 (when (and (boundp 'transient-mark-mode)
6985 transient-mark-mode)
6986 (setq mark-active nil))
6987 (with-current-buffer gnus-summary-buffer
6988 (gnus-summary-reply
6989 (list (list article contents)) wide)))))
6991 (defun gnus-article-wide-reply-with-original ()
6992 "Start composing a wide reply mail to the current message.
6993 The text in the region will be yanked. If the region isn't active,
6994 the entire article will be yanked."
6995 (interactive)
6996 (gnus-article-reply-with-original t))
6998 (defun gnus-article-followup-with-original ()
6999 "Compose a followup to the current article.
7000 The text in the region will be yanked. If the region isn't active,
7001 the entire article will be yanked."
7002 (interactive)
7003 (let ((article (cdr gnus-article-current))
7004 contents)
7005 (if (not (gnus-region-active-p))
7006 (with-current-buffer gnus-summary-buffer
7007 (gnus-summary-followup (list (list article))))
7008 (setq contents (buffer-substring (point) (mark t)))
7009 ;; Deactivate active regions.
7010 (when (and (boundp 'transient-mark-mode)
7011 transient-mark-mode)
7012 (setq mark-active nil))
7013 (with-current-buffer gnus-summary-buffer
7014 (gnus-summary-followup
7015 (list (list article contents)))))))
7017 (defun gnus-article-hide (&optional arg force)
7018 "Hide all the gruft in the current article.
7019 This means that signatures, cited text and (some) headers will be
7020 hidden.
7021 If given a prefix, show the hidden text instead."
7022 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7023 (gnus-article-hide-headers arg)
7024 (gnus-article-hide-list-identifiers arg)
7025 (gnus-article-hide-citation-maybe arg force)
7026 (gnus-article-hide-signature arg))
7028 (defun gnus-check-group-server ()
7029 ;; Make sure the connection to the server is alive.
7030 (unless (gnus-server-opened
7031 (gnus-find-method-for-group gnus-newsgroup-name))
7032 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7033 (gnus-request-group gnus-newsgroup-name t)))
7035 (declare-function nneething-get-file-name "nneething" (id))
7037 (defun gnus-request-article-this-buffer (article group)
7038 "Get an article and insert it into this buffer."
7039 (let (do-update-line sparse-header)
7040 (prog1
7041 (save-excursion
7042 (erase-buffer)
7043 (gnus-kill-all-overlays)
7044 (setq group (or group gnus-newsgroup-name))
7046 ;; Using `gnus-request-article' directly will insert the article into
7047 ;; `nntp-server-buffer' - so we'll save some time by not having to
7048 ;; copy it from the server buffer into the article buffer.
7050 ;; We only request an article by message-id when we do not have the
7051 ;; headers for it, so we'll have to get those.
7052 (when (stringp article)
7053 (gnus-read-header article))
7055 ;; If the article number is negative, that means that this article
7056 ;; doesn't belong in this newsgroup (possibly), so we find its
7057 ;; message-id and request it by id instead of number.
7058 (when (and (numberp article)
7059 gnus-summary-buffer
7060 (get-buffer gnus-summary-buffer)
7061 (gnus-buffer-exists-p gnus-summary-buffer))
7062 (with-current-buffer gnus-summary-buffer
7063 (let ((header (gnus-summary-article-header article)))
7064 (when (< article 0)
7065 (cond
7066 ((memq article gnus-newsgroup-sparse)
7067 ;; This is a sparse gap article.
7068 (setq do-update-line article)
7069 (setq article (mail-header-id header))
7070 (setq sparse-header (gnus-read-header article))
7071 (setq gnus-newsgroup-sparse
7072 (delq article gnus-newsgroup-sparse)))
7073 ((vectorp header)
7074 ;; It's a real article.
7075 (setq article (mail-header-id header)))
7077 ;; It is an extracted pseudo-article.
7078 (setq article 'pseudo)
7079 (gnus-request-pseudo-article header))))
7081 (let ((method (gnus-find-method-for-group
7082 gnus-newsgroup-name)))
7083 (when (and (eq (car method) 'nneething)
7084 (vectorp header))
7085 (let ((dir (nneething-get-file-name
7086 (mail-header-id header))))
7087 (when (and (stringp dir)
7088 (file-directory-p dir))
7089 (setq article 'nneething)
7090 (gnus-group-enter-directory dir))))))))
7092 (cond
7093 ;; Refuse to select canceled articles.
7094 ((and (numberp article)
7095 gnus-summary-buffer
7096 (get-buffer gnus-summary-buffer)
7097 (gnus-buffer-exists-p gnus-summary-buffer)
7098 (eq (cdr (with-current-buffer gnus-summary-buffer
7099 (assq article gnus-newsgroup-reads)))
7100 gnus-canceled-mark))
7101 nil)
7102 ;; We first check `gnus-original-article-buffer'.
7103 ((and (get-buffer gnus-original-article-buffer)
7104 (numberp article)
7105 (with-current-buffer gnus-original-article-buffer
7106 (and (equal (car gnus-original-article) group)
7107 (eq (cdr gnus-original-article) article))))
7108 ;; `insert-buffer-substring' would incorrectly use the
7109 ;; equivalent of string-make-multibyte which amount to decoding
7110 ;; with locale-coding-system, causing failure of
7111 ;; subsequent decoding.
7112 (insert (mm-string-to-multibyte
7113 (with-current-buffer gnus-original-article-buffer
7114 (buffer-substring (point-min) (point-max)))))
7115 'article)
7116 ;; Check the backlog.
7117 ((and gnus-keep-backlog
7118 (gnus-backlog-request-article group article (current-buffer)))
7119 'article)
7120 ;; Check asynchronous pre-fetch.
7121 ((gnus-async-request-fetched-article group article (current-buffer))
7122 (gnus-async-prefetch-next group article gnus-summary-buffer)
7123 (when (and (numberp article) gnus-keep-backlog)
7124 (gnus-backlog-enter-article group article (current-buffer)))
7125 'article)
7126 ;; Check the cache.
7127 ((and gnus-use-cache
7128 (numberp article)
7129 (gnus-cache-request-article article group))
7130 'article)
7131 ;; Check the agent cache.
7132 ((gnus-agent-request-article article group)
7133 'article)
7134 ;; Get the article and put into the article buffer.
7135 ((or (stringp article)
7136 (numberp article))
7137 (let ((gnus-override-method gnus-override-method)
7138 (methods (and (stringp article)
7139 (with-current-buffer gnus-summary-buffer
7140 (gnus-refer-article-methods))))
7141 (backend (car (gnus-find-method-for-group
7142 gnus-newsgroup-name)))
7143 result
7144 (inhibit-read-only t))
7145 (when (and (null gnus-override-method)
7146 methods)
7147 (setq gnus-override-method (pop methods)))
7148 (while (not result)
7149 (erase-buffer)
7150 (gnus-kill-all-overlays)
7151 (let ((gnus-newsgroup-name group))
7152 (gnus-check-group-server))
7153 (cond
7154 ((gnus-request-article article group (current-buffer))
7155 (when (numberp article)
7156 (gnus-async-prefetch-next group article
7157 gnus-summary-buffer)
7158 (when gnus-keep-backlog
7159 (gnus-backlog-enter-article
7160 group article (current-buffer)))
7161 (when (and gnus-agent
7162 (gnus-agent-group-covered-p group))
7163 (gnus-agent-store-article article group)))
7164 (setq result 'article))
7165 (methods
7166 (setq gnus-override-method (pop methods)))
7167 ((not (string-match "^400 "
7168 (nnheader-get-report backend)))
7169 ;; If we get 400 server disconnect, reconnect and
7170 ;; retry; otherwise, assume the article has expired.
7171 (setq result 'done))))
7172 (and (eq result 'article) 'article)))
7173 ;; It was a pseudo.
7174 (t article)))
7176 ;; Associate this article with the current summary buffer.
7177 (setq gnus-article-current-summary gnus-summary-buffer)
7179 ;; Take the article from the original article buffer
7180 ;; and place it in the buffer it's supposed to be in.
7181 (when (and (get-buffer gnus-article-buffer)
7182 (equal (buffer-name (current-buffer))
7183 (buffer-name (get-buffer gnus-article-buffer))))
7184 (save-excursion
7185 (if (get-buffer gnus-original-article-buffer)
7186 (set-buffer gnus-original-article-buffer)
7187 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7188 (buffer-disable-undo)
7189 (setq major-mode 'gnus-original-article-mode)
7190 (setq buffer-read-only t))
7191 (let ((inhibit-read-only t))
7192 (erase-buffer)
7193 (insert-buffer-substring gnus-article-buffer))
7194 (setq gnus-original-article (cons group article)))
7196 ;; Decode charsets.
7197 (run-hooks 'gnus-article-decode-hook)
7198 ;; Mark article as decoded or not.
7199 (setq gnus-article-decoded-p gnus-article-decode-hook))
7201 ;; Update sparse articles.
7202 (when (and do-update-line
7203 (or (numberp article)
7204 (stringp article)))
7205 (let ((buf (current-buffer)))
7206 (set-buffer gnus-summary-buffer)
7207 (gnus-summary-update-article do-update-line sparse-header)
7208 (gnus-summary-goto-subject do-update-line nil t)
7209 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7210 (point))
7211 (set-buffer buf))))))
7213 (defun gnus-block-private-groups (group)
7214 "Allows images in newsgroups to be shown, blocks images in all
7215 other groups."
7216 (if (or (gnus-news-group-p group)
7217 (gnus-member-of-valid 'global group))
7218 ;; Block nothing in news groups.
7220 ;; Block everything anywhere else.
7221 "."))
7223 (defun gnus-blocked-images ()
7224 (if (functionp gnus-blocked-images)
7225 (funcall gnus-blocked-images gnus-newsgroup-name)
7226 gnus-blocked-images))
7229 ;;; Article editing
7232 (defcustom gnus-article-edit-mode-hook nil
7233 "Hook run in article edit mode buffers."
7234 :group 'gnus-article-various
7235 :type 'hook)
7237 (defvar gnus-article-edit-done-function nil)
7239 (defvar gnus-article-edit-mode-map nil)
7241 ;; Should we be using derived.el for this?
7242 (unless gnus-article-edit-mode-map
7243 (setq gnus-article-edit-mode-map (make-keymap))
7244 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7246 (gnus-define-keys gnus-article-edit-mode-map
7247 "\C-c?" describe-mode
7248 "\C-c\C-c" gnus-article-edit-done
7249 "\C-c\C-k" gnus-article-edit-exit
7250 "\C-c\C-f\C-t" message-goto-to
7251 "\C-c\C-f\C-o" message-goto-from
7252 "\C-c\C-f\C-b" message-goto-bcc
7253 ;;"\C-c\C-f\C-w" message-goto-fcc
7254 "\C-c\C-f\C-c" message-goto-cc
7255 "\C-c\C-f\C-s" message-goto-subject
7256 "\C-c\C-f\C-r" message-goto-reply-to
7257 "\C-c\C-f\C-n" message-goto-newsgroups
7258 "\C-c\C-f\C-d" message-goto-distribution
7259 "\C-c\C-f\C-f" message-goto-followup-to
7260 "\C-c\C-f\C-m" message-goto-mail-followup-to
7261 "\C-c\C-f\C-k" message-goto-keywords
7262 "\C-c\C-f\C-u" message-goto-summary
7263 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7264 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7265 "\C-c\C-b" message-goto-body
7266 "\C-c\C-i" message-goto-signature
7268 "\C-c\C-t" message-insert-to
7269 "\C-c\C-n" message-insert-newsgroups
7270 "\C-c\C-o" message-sort-headers
7271 "\C-c\C-e" message-elide-region
7272 "\C-c\C-v" message-delete-not-region
7273 "\C-c\C-z" message-kill-to-signature
7274 "\M-\r" message-newline-and-reformat
7275 "\C-c\C-a" mml-attach-file
7276 "\C-a" message-beginning-of-line
7277 "\t" message-tab
7278 "\M-;" comment-region)
7280 (gnus-define-keys (gnus-article-edit-wash-map
7281 "\C-c\C-w" gnus-article-edit-mode-map)
7282 "f" gnus-article-edit-full-stops))
7284 (easy-menu-define
7285 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7286 '("Field"
7287 ["Fetch To" message-insert-to t]
7288 ["Fetch Newsgroups" message-insert-newsgroups t]
7289 "----"
7290 ["To" message-goto-to t]
7291 ["From" message-goto-from t]
7292 ["Subject" message-goto-subject t]
7293 ["Cc" message-goto-cc t]
7294 ["Reply-To" message-goto-reply-to t]
7295 ["Summary" message-goto-summary t]
7296 ["Keywords" message-goto-keywords t]
7297 ["Newsgroups" message-goto-newsgroups t]
7298 ["Followup-To" message-goto-followup-to t]
7299 ["Mail-Followup-To" message-goto-mail-followup-to t]
7300 ["Distribution" message-goto-distribution t]
7301 ["Body" message-goto-body t]
7302 ["Signature" message-goto-signature t]))
7304 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7305 "Major mode for editing articles.
7306 This is an extended text-mode.
7308 \\{gnus-article-edit-mode-map}"
7309 (make-local-variable 'gnus-article-edit-done-function)
7310 (make-local-variable 'gnus-prev-winconf)
7311 (set (make-local-variable 'font-lock-defaults)
7312 '(message-font-lock-keywords t))
7313 (set (make-local-variable 'mail-header-separator) "")
7314 (set (make-local-variable 'gnus-article-edit-mode) t)
7315 (easy-menu-add message-mode-field-menu message-mode-map)
7316 (mml-mode)
7317 (setq buffer-read-only nil)
7318 (buffer-enable-undo)
7319 (widen))
7321 (defun gnus-article-edit (&optional force)
7322 "Edit the current article.
7323 This will have permanent effect only in mail groups.
7324 If FORCE is non-nil, allow editing of articles even in read-only
7325 groups."
7326 (interactive "P")
7327 (when (and (not force)
7328 (gnus-group-read-only-p))
7329 (error "The current newsgroup does not support article editing"))
7330 (gnus-article-date-original)
7331 (gnus-article-edit-article
7332 'ignore
7333 `(lambda (no-highlight)
7334 'ignore
7335 (gnus-summary-edit-article-done
7336 ,(or (mail-header-references gnus-current-headers) "")
7337 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7339 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7340 "Start editing the contents of the current article buffer."
7341 (let ((winconf (current-window-configuration)))
7342 (set-buffer gnus-article-buffer)
7343 (let ((message-auto-save-directory
7344 ;; Don't associate the article buffer with a draft file.
7345 nil))
7346 (gnus-article-edit-mode))
7347 (funcall start-func)
7348 (set-buffer-modified-p nil)
7349 (gnus-configure-windows 'edit-article)
7350 (setq gnus-article-edit-done-function exit-func)
7351 (setq gnus-prev-winconf winconf)
7352 (unless quiet
7353 (gnus-message 6 "C-c C-c to end edits"))))
7355 (defun gnus-article-edit-done (&optional arg)
7356 "Update the article edits and exit."
7357 (interactive "P")
7358 (let ((func gnus-article-edit-done-function)
7359 (buf (current-buffer))
7360 (start (window-start))
7361 (winconf gnus-prev-winconf))
7362 (widen) ;; Widen it in case that users narrowed the buffer.
7363 (funcall func arg)
7364 (set-buffer buf)
7365 ;; The cache and backlog have to be flushed somewhat.
7366 (when gnus-keep-backlog
7367 (gnus-backlog-remove-article
7368 (car gnus-article-current) (cdr gnus-article-current)))
7369 ;; Flush original article as well.
7370 (gnus-flush-original-article-buffer)
7371 (when gnus-use-cache
7372 (gnus-cache-update-article
7373 (car gnus-article-current) (cdr gnus-article-current)))
7374 ;; We remove all text props from the article buffer.
7375 (kill-all-local-variables)
7376 (set-text-properties (point-min) (point-max) nil)
7377 (gnus-article-mode)
7378 (set-window-configuration winconf)
7379 (set-buffer buf)
7380 (set-window-start (get-buffer-window buf) start)
7381 (set-window-point (get-buffer-window buf) (point)))
7382 (gnus-summary-show-article))
7384 (defun gnus-flush-original-article-buffer ()
7385 (when (get-buffer gnus-original-article-buffer)
7386 (with-current-buffer gnus-original-article-buffer
7387 (setq gnus-original-article nil))))
7389 (defun gnus-article-edit-exit ()
7390 "Exit the article editing without updating."
7391 (interactive)
7392 (when (or (not (buffer-modified-p))
7393 (yes-or-no-p "Article modified; kill anyway? "))
7394 (let ((curbuf (current-buffer))
7395 (p (point))
7396 (window-start (window-start)))
7397 (erase-buffer)
7398 (if (gnus-buffer-live-p gnus-original-article-buffer)
7399 (insert-buffer-substring gnus-original-article-buffer))
7400 (let ((winconf gnus-prev-winconf))
7401 (kill-all-local-variables)
7402 (gnus-article-mode)
7403 (set-window-configuration winconf)
7404 ;; Tippy-toe some to make sure that point remains where it was.
7405 (save-current-buffer
7406 (set-buffer curbuf)
7407 (set-window-start (get-buffer-window (current-buffer)) window-start)
7408 (goto-char p))))
7409 (gnus-summary-show-article)))
7411 (defun gnus-article-edit-full-stops ()
7412 "Interactively repair spacing at end of sentences."
7413 (interactive)
7414 (save-excursion
7415 (goto-char (point-min))
7416 (search-forward-regexp "^$" nil t)
7417 (let ((case-fold-search nil))
7418 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7421 ;;; Article highlights
7424 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7426 ;;; Internal Variables:
7428 (defcustom gnus-button-url-regexp
7429 (concat
7430 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7431 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7432 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7433 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7434 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7435 (punct "!?:;.,"))
7436 (concat
7437 "\\(?:"
7438 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7439 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7440 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7441 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7442 "\\|"
7443 "[" chars punct "]+" "[" chars "]"
7444 "\\)"))
7445 (concat ;; XEmacs 21.4 doesn't support POSIX.
7446 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7447 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7448 "\\)")
7449 "Regular expression that matches URLs."
7450 :version "24.4"
7451 :group 'gnus-article-buttons
7452 :type 'regexp)
7454 (defcustom gnus-button-valid-fqdn-regexp
7455 message-valid-fqdn-regexp
7456 "Regular expression that matches a valid FQDN."
7457 :version "22.1"
7458 :group 'gnus-article-buttons
7459 :type 'regexp)
7461 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7462 (defcustom gnus-button-valid-localpart-regexp
7463 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7464 "Regular expression that matches a localpart of mail addresses or MIDs."
7465 :version "22.1"
7466 :group 'gnus-article-buttons
7467 :type 'regexp)
7469 (defcustom gnus-button-man-handler 'manual-entry
7470 "Function to use for displaying man pages.
7471 The function must take at least one argument with a string naming the
7472 man page."
7473 :version "22.1"
7474 :type '(choice (function-item :tag "Man" manual-entry)
7475 (function-item :tag "Woman" woman)
7476 (function :tag "Other"))
7477 :group 'gnus-article-buttons)
7479 (defcustom gnus-button-mid-or-mail-regexp
7480 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7481 gnus-button-valid-fqdn-regexp
7482 ">?\\)\\b")
7483 "Regular expression that matches a message ID or a mail address."
7484 :version "22.1"
7485 :group 'gnus-article-buttons
7486 :type 'regexp)
7488 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7489 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7490 Strings like this can be either a message ID or a mail address. If it is one
7491 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7492 message ID or a mail address, respectively. If this variable is set to the
7493 symbol `ask', always query the user what do do. If it is a function, this
7494 function will be called with the string as its only argument. The function
7495 must return `mid', `mail', `invalid' or `ask'."
7496 :version "22.1"
7497 :group 'gnus-article-buttons
7498 :type '(choice (function-item :tag "Heuristic function"
7499 gnus-button-mid-or-mail-heuristic)
7500 (const ask)
7501 (const mid)
7502 (const mail)))
7504 (defcustom gnus-button-mid-or-mail-heuristic-alist
7505 '((-10.0 . ".+\\$.+@")
7506 (-10.0 . "#")
7507 (-10.0 . "\\*")
7508 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7509 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7510 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7511 (-1.0 . "^[^a-z]+@")
7513 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7514 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7515 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7516 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7518 (-2.0 . "^[0-9]")
7519 (-1.0 . "^[0-9][0-9]")
7521 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7522 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7523 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7524 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7526 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7527 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7528 ;; "[0-9]{8,}.*\@"
7529 (-3.0
7530 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7531 ;; "[0-9]{12,}.*\@"
7532 ;; compensation for TDMA dated mail addresses:
7533 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7535 (-20.0 . "\\.fsf@") ;; Gnus
7536 (-20.0 . "^slrn")
7537 (-20.0 . "^Pine")
7538 (-20.0 . "^alpine\\.")
7539 (-20.0 . "_-_") ;; Subject change in thread
7541 (-20.0 . "\\.ln@") ;; leafnode
7542 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7543 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7545 ;; (5.0 . "") ;; $local_part_len <= 7
7546 (10.0 . "^[^0-9]+@")
7547 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7548 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7549 (3.0 . "\@stud")
7551 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7553 (0.5 . "^[A-Z][a-z]")
7554 (0.5 . "^[A-Z][a-z][a-z]")
7555 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7556 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7557 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7559 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7560 address. The REGEXP is processed with `case-fold-search' set to nil."
7561 :version "22.1"
7562 :group 'gnus-article-buttons
7563 :type '(repeat (cons (number :tag "Rate")
7564 (regexp :tag "Regexp"))))
7566 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7567 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7568 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7569 address, `ask' if unsure and `invalid' if the string is invalid."
7570 (let ((case-fold-search nil)
7571 (list gnus-button-mid-or-mail-heuristic-alist)
7572 (result 0) rate regexp lpartlen elem)
7573 (setq lpartlen
7574 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7575 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7576 ;; Certain special cases...
7577 (when (string-match
7578 (concat
7579 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7580 "^[0-9]+\\.[0-9]+@compuserve\\|"
7581 "@public\\.gmane\\.org")
7582 mid-or-mail)
7583 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7584 (setq result 'mail))
7585 (when (string-match "@.*@\\| " mid-or-mail)
7586 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7587 (setq result 'invalid))
7588 ;; Nothing more to do, if result is not a number here...
7589 (when (numberp result)
7590 (while list
7591 (setq elem (car list)
7592 rate (car elem)
7593 regexp (cdr elem)
7594 list (cdr list))
7595 (when (string-match regexp mid-or-mail)
7596 (setq result (+ result rate))
7597 (gnus-message
7598 9 "`%s' matched `%s', rate `%s', result `%s'."
7599 mid-or-mail regexp rate result)))
7600 (when (<= lpartlen 7)
7601 (setq result (+ result 5.0))
7602 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7603 mid-or-mail result))
7604 (when (>= lpartlen 12)
7605 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7606 (cond
7607 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7608 ;; Long local part should contain realname if e-mail address,
7609 ;; too many digits: message-id.
7610 ;; $score -= 5.0 + 0.1 * $local_part_len;
7611 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7612 (setq result (+ result rate))
7613 (gnus-message
7614 9 "Many digits in `%s', rate `%s', result `%s'."
7615 mid-or-mail rate result))
7616 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7617 mid-or-mail)
7618 ;; Too few vowels [^aeiouy]{4,}.*\@
7619 (setq result (+ result -5.0))
7620 (gnus-message
7621 9 "Few vowels in `%s', rate `%s', result `%s'."
7622 mid-or-mail -5.0 result))
7624 (setq result (+ result 5.0))
7625 (gnus-message
7626 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7627 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7628 ;; Maybe we should make this a customizable alist: (condition . 'result)
7629 (cond
7630 ((symbolp result) result)
7631 ;; Now convert number into proper results:
7632 ((< result -10.0) 'mid)
7633 ((> result 10.0) 'mail)
7634 (t 'ask))))
7636 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7637 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7638 (url-mid (concat "news" ":" mid-or-mail))
7639 (url-mailto (concat "mailto" ":" mid-or-mail)))
7640 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7641 (when (fboundp pref)
7642 (setq guessed
7643 ;; get rid of surrounding angles...
7644 (funcall pref
7645 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7646 (if (or (eq 'mid guessed) (eq 'mail guessed))
7647 (setq pref guessed)
7648 (setq pref 'ask)))
7649 (if (eq pref 'ask)
7650 (save-window-excursion
7651 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7652 (setq pref 'mail)
7653 (setq pref 'mid))))
7654 (cond ((eq pref 'mid)
7655 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7656 (gnus-button-handle-news url-mid))
7657 ((eq pref 'mail)
7658 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7659 (gnus-url-mailto url-mailto))
7660 (t (gnus-message 3 "Invalid string.")))))
7662 (defun gnus-button-handle-custom (fun arg)
7663 "Call function FUN on argument ARG.
7664 Both FUN and ARG are supposed to be strings. ARG will be passed
7665 as a symbol to FUN."
7666 (funcall (intern fun)
7667 (if (string-match "^customize-apropos" fun)
7669 (intern arg))))
7671 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7673 (defun gnus-button-handle-describe-function (url)
7674 "Call `describe-function' when pushing the corresponding URL button."
7675 (describe-function
7676 (intern
7677 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7679 (defun gnus-button-handle-describe-variable (url)
7680 "Call `describe-variable' when pushing the corresponding URL button."
7681 (describe-variable
7682 (intern
7683 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7685 (defun gnus-button-handle-symbol (url)
7686 "Display help on variable or function.
7687 Calls `describe-variable' or `describe-function'."
7688 (let ((sym (intern url)))
7689 (cond
7690 ((fboundp sym) (describe-function sym))
7691 ((boundp sym) (describe-variable sym))
7692 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7694 (defun gnus-button-handle-describe-key (url)
7695 "Call `describe-key' when pushing the corresponding URL button."
7696 (let* ((key-string
7697 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7698 (keys (ignore-errors (eval `(kbd ,key-string)))))
7699 (if keys
7700 (describe-key keys)
7701 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7703 (defun gnus-button-handle-apropos (url)
7704 "Call `apropos' when pushing the corresponding URL button."
7705 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7707 (defun gnus-button-handle-apropos-command (url)
7708 "Call `apropos' when pushing the corresponding URL button."
7709 (apropos-command
7710 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7712 (defun gnus-button-handle-apropos-variable (url)
7713 "Call `apropos' when pushing the corresponding URL button."
7714 (funcall
7715 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7716 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7718 (defun gnus-button-handle-apropos-documentation (url)
7719 "Call `apropos' when pushing the corresponding URL button."
7720 (funcall
7721 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7722 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7724 (defun gnus-button-handle-library (url)
7725 "Call `locate-library' when pushing the corresponding URL button."
7726 (gnus-message 9 "url=`%s'" url)
7727 (let* ((lib (locate-library url))
7728 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7729 (if (not lib)
7730 (gnus-message 1 "Cannot locale library `%s'." url)
7731 (find-file-read-only file))))
7733 (defcustom gnus-button-man-level 5
7734 "*Integer that says how many man-related buttons Gnus will show.
7735 The higher the number, the more buttons will appear and the more false
7736 positives are possible. Note that you can set this variable local to
7737 specific groups. Setting it higher in Unix groups is probably a good idea.
7738 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7739 how to set variables in specific groups."
7740 :version "22.1"
7741 :group 'gnus-article-buttons
7742 :link '(custom-manual "(gnus)Group Parameters")
7743 :type 'integer)
7745 (defcustom gnus-button-emacs-level 5
7746 "*Integer that says how many emacs-related buttons Gnus will show.
7747 The higher the number, the more buttons will appear and the more false
7748 positives are possible. Note that you can set this variable local to
7749 specific groups. Setting it higher in Emacs or Gnus related groups is
7750 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7751 `gnus-parameters' on how to set variables in specific groups."
7752 :version "22.1"
7753 :group 'gnus-article-buttons
7754 :link '(custom-manual "(gnus)Group Parameters")
7755 :type 'integer)
7757 (defcustom gnus-button-message-level 5
7758 "*Integer that says how many buttons for news or mail messages will appear.
7759 The higher the number, the more buttons will appear and the more false
7760 positives are possible."
7761 ;; mail addresses, MIDs, URLs for news, ...
7762 :version "22.1"
7763 :group 'gnus-article-buttons
7764 :type 'integer)
7766 (defcustom gnus-button-browse-level 5
7767 "*Integer that says how many buttons for browsing will appear.
7768 The higher the number, the more buttons will appear and the more false
7769 positives are possible."
7770 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7771 :version "22.1"
7772 :group 'gnus-article-buttons
7773 :type 'integer)
7775 (defcustom gnus-button-alist
7776 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7777 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7778 ((concat "\\b\\(nntp\\|news\\):\\("
7779 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7780 0 t gnus-button-handle-news 2)
7781 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7782 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7783 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7784 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7785 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7786 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7787 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7788 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7789 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7790 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7791 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7792 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7793 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7794 ;; RFC 2368 (The mailto URL scheme)
7795 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7796 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7797 ("\\bmailto:\\([^ \n\t]+\\)"
7798 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7799 ;; Info Konqueror style <info:/foo/bar baz>.
7800 ;; Must come before " Gnus home-grown style".
7801 ("\\binfo://?\\([^'\">\n\t]+\\)"
7802 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7803 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7804 ("\\binfo://\\([^'\">\n\t ]+\\)"
7805 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7806 ;; Info GNOME style <info:foo#bar_baz>
7807 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7808 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7809 ;; Info KDE style <info:(foo)bar baz>
7810 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7811 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7812 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7813 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7814 ("\\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,]*\\)\\)?"
7815 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7816 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7817 ;; This is custom
7818 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7819 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7820 ;; Emacs help commands
7821 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7822 ;; regexp doesn't match arguments containing ` '.
7823 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7824 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7825 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7826 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7828 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7829 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7830 ;; The following entries may lead to many false positives so don't enable
7831 ;; them by default (use a high button level).
7832 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7833 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7834 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7835 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7836 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7837 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7838 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7839 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7840 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7841 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7842 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7843 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7844 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7845 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7846 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7847 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7848 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7849 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7850 ;; Unlike the other regexps we really have to require quoting
7851 ;; here to determine where it ends.
7852 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7853 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7854 ("<URL: *\\([^\n<>]*\\)>"
7855 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7856 ;; RFC 2396 (2.4.3., delims) ...
7857 ("\"URL: *\\([^\n\"]*\\)\""
7858 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7859 ;; Raw URLs.
7860 (gnus-button-url-regexp
7861 0 (>= gnus-button-browse-level 0) browse-url 0)
7862 ;; man pages
7863 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7864 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7865 gnus-button-handle-man 1)
7866 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7867 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7868 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7869 gnus-button-handle-man 1)
7870 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7871 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7872 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7873 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7874 ;; Recognizing patches to .el files. This is somewhat obscure,
7875 ;; but considering the percentage of Gnus users who hack Emacs
7876 ;; Lisp files...
7877 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7878 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7879 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7880 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7881 ;; MID or mail: To avoid too many false positives we don't try to catch
7882 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7883 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7884 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7885 ;; so that non-ambiguous entries (see above) match first.
7886 (gnus-button-mid-or-mail-regexp
7887 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7888 "*Alist of regexps matching buttons in article bodies.
7890 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7891 REGEXP: is the string (case insensitive) matching text around the button (can
7892 also be Lisp expression evaluating to a string),
7893 BUTTON: is the number of the regexp grouping actually matching the button,
7894 FORM: is a Lisp expression which must eval to true for the button to
7895 be added,
7896 CALLBACK: is the function to call when the user push this button, and each
7897 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7899 CALLBACK can also be a variable, in that case the value of that
7900 variable it the real callback function."
7901 :group 'gnus-article-buttons
7902 :type '(repeat (list (choice regexp variable sexp)
7903 (integer :tag "Button")
7904 (sexp :tag "Form")
7905 (function :tag "Callback")
7906 (repeat :tag "Par"
7907 :inline t
7908 (integer :tag "Regexp group")))))
7909 (put 'gnus-button-alist 'risky-local-variable t)
7911 (defcustom gnus-header-button-alist
7912 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7913 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7914 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7915 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7916 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7917 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7918 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7919 0 (>= gnus-button-browse-level 0) browse-url 0)
7920 ("^Subject:" gnus-button-url-regexp
7921 0 (>= gnus-button-browse-level 0) browse-url 0)
7922 ("^[^:]+:" gnus-button-url-regexp
7923 0 (>= gnus-button-browse-level 0) browse-url 0)
7924 ("^OpenPGP:.*url=" gnus-button-url-regexp
7925 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7926 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7927 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7928 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7929 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7930 "*Alist of headers and regexps to match buttons in article heads.
7932 This alist is very similar to `gnus-button-alist', except that each
7933 alist has an additional HEADER element first in each entry:
7935 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7937 HEADER is a regexp to match a header. For a fuller explanation, see
7938 `gnus-button-alist'."
7939 :group 'gnus-article-buttons
7940 :group 'gnus-article-headers
7941 :type '(repeat (list (regexp :tag "Header")
7942 (choice regexp variable)
7943 (integer :tag "Button")
7944 (sexp :tag "Form")
7945 (function :tag "Callback")
7946 (repeat :tag "Par"
7947 :inline t
7948 (integer :tag "Regexp group")))))
7949 (put 'gnus-header-button-alist 'risky-local-variable t)
7951 ;;; Commands:
7953 (defun gnus-article-push-button (event)
7954 "Check text under the mouse pointer for a callback function.
7955 If the text under the mouse pointer has a `gnus-callback' property,
7956 call it with the value of the `gnus-data' text property."
7957 (interactive "e")
7958 (set-buffer (window-buffer (posn-window (event-start event))))
7959 (let* ((pos (posn-point (event-start event)))
7960 (data (get-text-property pos 'gnus-data))
7961 (fun (get-text-property pos 'gnus-callback)))
7962 (goto-char pos)
7963 (when fun
7964 (funcall fun data))))
7966 (defun gnus-article-press-button ()
7967 "Check text at point for a callback function.
7968 If the text at point has a `gnus-callback' property,
7969 call it with the value of the `gnus-data' text property."
7970 (interactive)
7971 (let ((data (get-text-property (point) 'gnus-data))
7972 (fun (get-text-property (point) 'gnus-callback)))
7973 (when fun
7974 (funcall fun data))))
7976 (defun gnus-article-highlight (&optional force)
7977 "Highlight current article.
7978 This function calls `gnus-article-highlight-headers',
7979 `gnus-article-highlight-citation',
7980 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7981 do the highlighting. See the documentation for those functions."
7982 (interactive (list 'force))
7983 (gnus-article-highlight-headers)
7984 (gnus-article-highlight-citation force)
7985 (gnus-article-highlight-signature)
7986 (gnus-article-add-buttons)
7987 (gnus-article-add-buttons-to-head))
7989 (defun gnus-article-highlight-some (&optional _force)
7990 "Highlight current article.
7991 This function calls `gnus-article-highlight-headers',
7992 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7993 do the highlighting. See the documentation for those functions."
7994 (interactive (list 'force))
7995 (gnus-article-highlight-headers)
7996 (gnus-article-highlight-signature)
7997 (gnus-article-add-buttons))
7999 (defun gnus-article-highlight-headers ()
8000 "Highlight article headers as specified by `gnus-header-face-alist'."
8001 (interactive)
8002 (gnus-with-article-headers
8003 (let (regexp header-face field-face from hpoints fpoints)
8004 (dolist (entry gnus-header-face-alist)
8005 (goto-char (point-min))
8006 (setq regexp (concat "^\\("
8007 (if (string-equal "" (nth 0 entry))
8008 "[^\t ]"
8009 (nth 0 entry))
8010 "\\)")
8011 header-face (nth 1 entry)
8012 field-face (nth 2 entry))
8013 (while (and (re-search-forward regexp nil t)
8014 (not (eobp)))
8015 (beginning-of-line)
8016 (setq from (point))
8017 (unless (search-forward ":" nil t)
8018 (forward-char 1))
8019 (when (and header-face
8020 (not (memq (point) hpoints)))
8021 (push (point) hpoints)
8022 (gnus-put-text-property from (point) 'face header-face))
8023 (when (and field-face
8024 (not (memq (setq from (point)) fpoints)))
8025 (push from fpoints)
8026 (if (re-search-forward "^[^ \t]" nil t)
8027 (forward-char -2)
8028 (goto-char (point-max)))
8029 (gnus-put-text-property from (point) 'face field-face)))))))
8031 (defun gnus-article-highlight-signature ()
8032 "Highlight the signature in an article.
8033 It does this by highlighting everything after
8034 `gnus-signature-separator' using the face `gnus-signature'."
8035 (interactive)
8036 (gnus-with-article-buffer
8037 (let ((inhibit-point-motion-hooks t))
8038 (save-restriction
8039 (when (and gnus-signature-face
8040 (gnus-article-narrow-to-signature))
8041 (overlay-put (make-overlay (point-min) (point-max) nil t)
8042 'face gnus-signature-face)
8043 (widen)
8044 (gnus-article-search-signature)
8045 (let ((start (match-beginning 0))
8046 (end (set-marker (make-marker) (1+ (match-end 0)))))
8047 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8048 end)))))))
8050 (defun gnus-button-in-region-p (b e prop)
8051 "Say whether PROP exists in the region."
8052 (text-property-not-all b e prop nil))
8054 (defun gnus-article-add-buttons ()
8055 "Find external references in the article and make buttons of them.
8056 \"External references\" are things like Message-IDs and URLs, as
8057 specified by `gnus-button-alist'."
8058 (interactive)
8059 (gnus-with-article-buffer
8060 (let ((inhibit-point-motion-hooks t)
8061 (case-fold-search t)
8062 (alist gnus-button-alist)
8063 beg entry regexp)
8064 ;; We skip the headers.
8065 (article-goto-body)
8066 (setq beg (point))
8067 (while (setq entry (pop alist))
8068 (setq regexp (eval (car entry)))
8069 (goto-char beg)
8070 (while (re-search-forward regexp nil t)
8071 (let ((start (match-beginning (nth 1 entry)))
8072 (end (match-end (nth 1 entry)))
8073 (from (match-beginning 0)))
8074 (when (and (eval (nth 2 entry))
8075 (not (gnus-button-in-region-p
8076 start end 'gnus-callback)))
8077 ;; That optional form returned non-nil, so we add the
8078 ;; button.
8079 (setq from (set-marker (make-marker) from))
8080 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8081 (gnus-article-extend-url-button from start end))
8082 (gnus-article-add-button start end
8083 'gnus-button-push (list from entry))
8084 (gnus-put-text-property
8085 start end
8086 'gnus-string (buffer-substring-no-properties
8087 start end))))))))))
8089 (defun gnus-article-extend-url-button (beg start end)
8090 "Extend url button if url is folded into two or more lines.
8091 Return non-nil if button is extended. BEG is a marker that points to
8092 the beginning position of a text containing url. START and END are
8093 the endpoints of a url button before it is extended. The concatenated
8094 url is put as the `gnus-button-url' overlay property on the button."
8095 (let ((opoint (point))
8096 (points (list start end))
8097 url delim regexp)
8098 (prog1
8099 (when (and (progn
8100 (goto-char end)
8101 (not (looking-at "[\t ]*[\">]")))
8102 (progn
8103 (goto-char start)
8104 (string-match
8105 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8106 (buffer-substring (point-at-bol) start)))
8107 (progn
8108 (setq url (list (buffer-substring start end))
8109 delim (if (match-beginning 1) ">" "\""))
8110 (beginning-of-line)
8111 (setq regexp (concat
8112 (when (and (looking-at
8113 message-cite-prefix-regexp)
8114 (< (match-end 0) start))
8115 (regexp-quote (match-string 0)))
8117 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8118 delim "\\)"))
8119 (while (progn
8120 (forward-line 1)
8121 (and (looking-at regexp)
8122 (prog1
8123 (match-beginning 1)
8124 (push (or (match-string 2)
8125 (match-string 1))
8126 url)
8127 (push (setq end (or (match-end 2)
8128 (match-end 1)))
8129 points)
8130 (push (or (match-beginning 2)
8131 (match-beginning 1))
8132 points)))))
8133 (match-beginning 2)))
8134 (let (gnus-article-mouse-face widget-mouse-face)
8135 (while points
8136 (gnus-article-add-button (pop points) (pop points)
8137 'gnus-button-push
8138 (list beg (assq 'gnus-button-url-regexp
8139 gnus-button-alist)))))
8140 (let ((overlay (make-overlay start end)))
8141 (overlay-put overlay 'evaporate t)
8142 (overlay-put overlay 'gnus-button-url
8143 (list (mapconcat 'identity (nreverse url) "")))
8144 (when gnus-article-mouse-face
8145 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8147 (goto-char opoint))))
8149 ;; Add buttons to the head of an article.
8150 (defun gnus-article-add-buttons-to-head ()
8151 "Add buttons to the head of the article."
8152 (interactive)
8153 (gnus-with-article-headers
8154 (let (beg end)
8155 (dolist (entry gnus-header-button-alist)
8156 ;; Each alist entry.
8157 (goto-char (point-min))
8158 (while (re-search-forward (car entry) nil t)
8159 ;; Each header matching the entry.
8160 (setq beg (match-beginning 0))
8161 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8162 (match-beginning 0))
8163 (point-max)))
8164 (goto-char beg)
8165 (while (re-search-forward (eval (nth 1 entry)) end t)
8166 ;; Each match within a header.
8167 (let* ((entry (cdr entry))
8168 (start (match-beginning (nth 1 entry)))
8169 (end (match-end (nth 1 entry)))
8170 (form (nth 2 entry)))
8171 (goto-char (match-end 0))
8172 (when (eval form)
8173 (gnus-article-add-button
8174 start end (nth 3 entry)
8175 (buffer-substring (match-beginning (nth 4 entry))
8176 (match-end (nth 4 entry)))))))
8177 (goto-char end))))))
8179 ;;; External functions:
8181 (defun gnus-article-add-button (from to fun &optional data text)
8182 "Create a button between FROM and TO with callback FUN and data DATA."
8183 (when gnus-article-button-face
8184 (overlay-put (make-overlay from to nil t)
8185 'face gnus-article-button-face))
8186 (gnus-add-text-properties
8187 from to
8188 (nconc (and gnus-article-mouse-face
8189 (list gnus-mouse-face-prop gnus-article-mouse-face))
8190 (list 'gnus-callback fun)
8191 (and data (list 'gnus-data data))))
8192 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8193 :help-echo (or text "Follow the link")
8194 :keymap gnus-url-button-map
8195 :button-keymap gnus-widget-button-keymap))
8197 (defun gnus-article-copy-string ()
8198 "Copy the string in the button to the kill ring."
8199 (interactive)
8200 (gnus-article-check-buffer)
8201 (let ((data (get-text-property (point) 'gnus-string)))
8202 (when data
8203 (with-temp-buffer
8204 (insert data)
8205 (copy-region-as-kill (point-min) (point-max))
8206 (message "Copied %s" data)))))
8208 ;;; Internal functions:
8210 (defun gnus-article-set-globals ()
8211 (with-current-buffer gnus-summary-buffer
8212 (gnus-set-global-variables)))
8214 (defun gnus-signature-toggle (end)
8215 (gnus-with-article-buffer
8216 (let ((inhibit-point-motion-hooks t))
8217 (if (text-property-any end (point-max) 'article-type 'signature)
8218 (progn
8219 (gnus-delete-wash-type 'signature)
8220 (gnus-remove-text-properties-when
8221 'article-type 'signature end (point-max)
8222 (cons 'article-type (cons 'signature
8223 gnus-hidden-properties))))
8224 (gnus-add-wash-type 'signature)
8225 (gnus-add-text-properties-when
8226 'article-type nil end (point-max)
8227 (cons 'article-type (cons 'signature
8228 gnus-hidden-properties)))))
8229 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8230 (gnus-set-mode-line 'article))))
8232 (defun gnus-button-push (marker-and-entry)
8233 ;; Push button starting at MARKER.
8234 (save-excursion
8235 (let* ((marker (car marker-and-entry))
8236 (entry (cadr marker-and-entry))
8237 (regexp (car entry))
8238 (inhibit-point-motion-hooks t))
8239 (goto-char marker)
8240 ;; This is obviously true, or something bad is happening :)
8241 ;; But we need it to have the match-data
8242 (when (looking-at (or (if (symbolp regexp)
8243 (symbol-value regexp)
8244 regexp)))
8245 (let ((fun (nth 3 entry))
8246 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8247 (get-char-property marker 'gnus-button-url))
8248 (mapcar (lambda (group)
8249 (let ((string (match-string group)))
8250 (set-text-properties
8251 0 (length string) nil string)
8252 string))
8253 (nthcdr 4 entry)))))
8255 (cond
8256 ((fboundp fun)
8257 (apply fun args))
8258 ((and (boundp fun)
8259 (fboundp (symbol-value fun)))
8260 (apply (symbol-value fun) args))
8262 (gnus-message 1 "You must define `%S' to use this button"
8263 (cons fun args)))))))))
8265 (defun gnus-parse-news-url (url)
8266 (let (scheme server port group message-id articles)
8267 (with-temp-buffer
8268 (insert url)
8269 (goto-char (point-min))
8270 (when (looking-at "\\([A-Za-z]+\\):")
8271 (setq scheme (match-string 1))
8272 (goto-char (match-end 0)))
8273 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8274 (setq server (match-string 1))
8275 (setq port (if (stringp (match-string 3))
8276 (string-to-number (match-string 3))
8277 (match-string 3)))
8278 (goto-char (match-end 0)))
8280 (cond
8281 ((looking-at "\\(.*@.*\\)")
8282 (setq message-id (match-string 1)))
8283 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8284 (setq group (match-string 1)
8285 articles (split-string (match-string 2) "-")))
8286 ((looking-at "\\([^/]+\\)/?")
8287 (setq group (match-string 1)))
8289 (error "Unknown news URL syntax"))))
8290 (list scheme server port group message-id articles)))
8292 (defvar nntp-port-number)
8294 (defun gnus-button-handle-news (url)
8295 "Fetch a news URL."
8296 (destructuring-bind (_scheme server port group message-id _articles)
8297 (gnus-parse-news-url url)
8298 (cond
8299 (message-id
8300 (with-current-buffer gnus-summary-buffer
8301 (if server
8302 (let ((gnus-refer-article-method
8303 (nconc (list (list 'nntp server))
8304 gnus-refer-article-method))
8305 (nntp-port-number (or port "nntp")))
8306 (gnus-message 7 "Fetching %s with %s"
8307 message-id gnus-refer-article-method)
8308 (gnus-summary-refer-article message-id))
8309 (gnus-summary-refer-article message-id))))
8310 (group
8311 (gnus-button-fetch-group url)))))
8313 (defun gnus-button-patch (library line)
8314 "Visit an Emacs Lisp library LIBRARY on line LINE."
8315 (interactive)
8316 (let ((file (locate-library (file-name-nondirectory library))))
8317 (unless file
8318 (error "Couldn't find library %s" library))
8319 (find-file file)
8320 (goto-char (point-min))
8321 (forward-line (1- (string-to-number line)))))
8323 (defun gnus-button-handle-man (url)
8324 "Fetch a man page."
8325 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8326 (when (eq gnus-button-man-handler 'woman)
8327 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8328 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8329 (funcall gnus-button-man-handler url))
8331 (defun gnus-button-handle-info-url (url)
8332 "Fetch an info URL."
8333 (setq url (mm-subst-char-in-string ?+ ?\ url))
8334 (cond
8335 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8336 (gnus-info-find-node
8337 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8338 "Gnus")
8339 ")" (gnus-url-unhex-string (match-string 2 url)))))
8340 ((string-match "([^)\"]+)[^\"]+" url)
8341 (setq url
8342 (gnus-replace-in-string
8343 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8344 (gnus-info-find-node url))
8345 (t (error "Can't parse %s" url))))
8347 (defun gnus-button-handle-info-url-gnome (url)
8348 "Fetch GNOME style info URL."
8349 (setq url (mm-subst-char-in-string ?_ ?\ url))
8350 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8351 (gnus-info-find-node
8352 (concat "("
8353 (gnus-url-unhex-string
8354 (match-string 1 url))
8356 (or (gnus-url-unhex-string
8357 (match-string 2 url))
8358 "Top")))
8359 (error "Can't parse %s" url)))
8361 (defun gnus-button-handle-info-url-kde (url)
8362 "Fetch KDE style info URL."
8363 (gnus-info-find-node (gnus-url-unhex-string url)))
8365 ;; (info) will autoload info.el
8366 (declare-function Info-menu "info" (menu-item &optional fork))
8367 (declare-function Info-index-next "info" (num))
8369 (defun gnus-button-handle-info-keystrokes (url)
8370 "Call `info' when pushing the corresponding URL button."
8371 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8372 (let (node indx comma)
8373 (if (string-match
8374 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8375 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8376 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8377 "\\(?:[ \t\n,]*\\)\\)?")
8378 url)
8379 (setq node (match-string 2 url)
8380 indx (match-string 3 url))
8381 (error "Can't parse %s" url))
8382 (info)
8383 (Info-directory)
8384 (Info-menu node)
8385 (when (> (length indx) 0)
8386 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8387 "\\([ \t\n,]*\\)")
8388 indx)
8389 (setq comma (match-string 2 indx))
8390 (setq indx (match-string 1 indx))
8391 (Info-index indx)
8392 (when comma
8393 (dotimes (i (with-temp-buffer
8394 (insert comma)
8395 ;; Note: the XEmacs version of `how-many' takes
8396 ;; no optional argument.
8397 (goto-char (point-min))
8398 (how-many ",")))
8399 (Info-index-next 1)))
8400 nil)))
8402 (autoload 'pgg-snarf-keys-region "pgg")
8403 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8404 (declare-function pgg-display-output-buffer "pgg" (start end status))
8406 (defun gnus-button-openpgp (url)
8407 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8408 (with-temp-buffer
8409 (mm-url-insert-file-contents-external url)
8410 (pgg-snarf-keys-region (point-min) (point-max))
8411 (pgg-display-output-buffer nil nil nil)))
8413 (defun gnus-button-message-id (message-id)
8414 "Fetch MESSAGE-ID."
8415 (with-current-buffer gnus-summary-buffer
8416 (gnus-summary-refer-article message-id)))
8418 (defun gnus-button-fetch-group (address &rest _ignore)
8419 "Fetch GROUP specified by ADDRESS."
8420 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8421 address)
8422 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8423 ;; for nntp:// and news://
8424 (setq address (match-string 3 address)))
8425 (if (not (string-match "[:/]" address))
8426 ;; This is just a simple group url.
8427 (gnus-group-read-ephemeral-group address gnus-select-method)
8428 (if (not
8429 (string-match
8430 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8431 address))
8432 (error "Can't parse %s" address)
8433 (gnus-group-read-ephemeral-group
8434 (match-string 4 address)
8435 `(nntp ,(match-string 1 address)
8436 (nntp-address ,(match-string 1 address))
8437 (nntp-port-number ,(if (match-end 3)
8438 (match-string 3 address)
8439 "nntp")))
8440 nil nil nil
8441 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8443 (defun gnus-url-parse-query-string (query &optional downcase)
8444 (let (retval pairs cur key val)
8445 (setq pairs (split-string query "&"))
8446 (while pairs
8447 (setq cur (car pairs)
8448 pairs (cdr pairs))
8449 (if (not (string-match "=" cur))
8450 nil ; Grace
8451 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8452 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8453 (if downcase
8454 (setq key (downcase key)))
8455 (setq cur (assoc key retval))
8456 (if cur
8457 (setcdr cur (cons val (cdr cur)))
8458 (setq retval (cons (list key val) retval)))))
8459 retval))
8461 (defun gnus-url-mailto (url)
8462 ;; Send mail to someone
8463 (setq url (replace-regexp-in-string "\n" " " url))
8464 (when (string-match "mailto:/*\\(.*\\)" url)
8465 (setq url (substring url (match-beginning 1) nil)))
8466 (let* ((args (gnus-url-parse-query-string
8467 (if (string-match "^\\?" url)
8468 (substring url 1)
8469 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8470 (concat "to=" (match-string 1 url) "&"
8471 (match-string 2 url))
8472 (concat "to=" url)))))
8473 (subject (cdr-safe (assoc "subject" args)))
8474 func)
8475 (gnus-msg-mail)
8476 (while args
8477 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8478 (if (fboundp func)
8479 (funcall func)
8480 (message-position-on-field (caar args)))
8481 (insert (gnus-replace-in-string
8482 (mapconcat 'identity (reverse (cdar args)) ", ")
8483 "\r\n" "\n" t))
8484 (setq args (cdr args)))
8485 (if subject
8486 (message-goto-body)
8487 (message-goto-subject))))
8489 (defun gnus-button-embedded-url (address)
8490 "Activate ADDRESS with `browse-url'."
8491 (browse-url (gnus-strip-whitespace address)))
8493 ;;; Next/prev buttons in the article buffer.
8495 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8496 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8498 (defvar gnus-prev-page-map
8499 (let ((map (make-sparse-keymap)))
8500 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8501 (define-key map "\r" 'gnus-button-prev-page)
8502 map))
8504 (defvar gnus-next-page-map
8505 (let ((map (make-sparse-keymap)))
8506 (define-key map gnus-mouse-2 'gnus-button-next-page)
8507 (define-key map "\r" 'gnus-button-next-page)
8508 map))
8510 (defun gnus-insert-prev-page-button ()
8511 (let ((b (point)) e
8512 (inhibit-read-only t))
8513 (gnus-eval-format
8514 gnus-prev-page-line-format nil
8515 `(keymap ,gnus-prev-page-map
8516 gnus-prev t
8517 gnus-callback gnus-article-button-prev-page
8518 article-type annotation))
8519 (setq e (if (bolp)
8520 ;; Exclude a newline.
8521 (1- (point))
8522 (point)))
8523 (when gnus-article-button-face
8524 (overlay-put (make-overlay b e nil t)
8525 'face gnus-article-button-face))
8526 (widget-convert-button
8527 'link b e
8528 :action 'gnus-button-prev-page
8529 :button-keymap gnus-prev-page-map)))
8531 (defun gnus-button-next-page (&optional _args _more-args)
8532 "Go to the next page."
8533 (interactive)
8534 (let ((win (selected-window)))
8535 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8536 (gnus-article-next-page)
8537 (select-window win)))
8539 (defun gnus-button-prev-page (&optional _args _more-args)
8540 "Go to the prev page."
8541 (interactive)
8542 (let ((win (selected-window)))
8543 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8544 (gnus-article-prev-page)
8545 (select-window win)))
8547 (defun gnus-insert-next-page-button ()
8548 (let ((b (point)) e
8549 (inhibit-read-only t))
8550 (gnus-eval-format gnus-next-page-line-format nil
8551 `(keymap ,gnus-next-page-map
8552 gnus-next t
8553 gnus-callback gnus-article-button-next-page
8554 article-type annotation))
8555 (setq e (if (bolp)
8556 ;; Exclude a newline.
8557 (1- (point))
8558 (point)))
8559 (when gnus-article-button-face
8560 (overlay-put (make-overlay b e nil t)
8561 'face gnus-article-button-face))
8562 (widget-convert-button
8563 'link b e
8564 :action 'gnus-button-next-page
8565 :button-keymap gnus-next-page-map)))
8567 (defun gnus-article-button-next-page (_arg)
8568 "Go to the next page."
8569 (interactive "P")
8570 (let ((win (selected-window)))
8571 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8572 (gnus-article-next-page)
8573 (select-window win)))
8575 (defun gnus-article-button-prev-page (_arg)
8576 "Go to the prev page."
8577 (interactive "P")
8578 (let ((win (selected-window)))
8579 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8580 (gnus-article-prev-page)
8581 (select-window win)))
8583 (defvar gnus-decode-header-methods
8584 '(mail-decode-encoded-word-region)
8585 "List of methods used to decode headers.
8587 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8588 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8589 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8590 whose names match REGEXP.
8592 For example:
8593 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8594 mail-decode-encoded-word-region
8595 (\"chinese\" . rfc1843-decode-region))
8598 (defvar gnus-decode-header-methods-cache nil)
8600 (defun gnus-multi-decode-header (start end)
8601 "Apply the functions from `gnus-encoded-word-methods' that match."
8602 (unless (and gnus-decode-header-methods-cache
8603 (eq gnus-newsgroup-name
8604 (car gnus-decode-header-methods-cache)))
8605 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8606 (dolist (x gnus-decode-header-methods)
8607 (if (symbolp x)
8608 (nconc gnus-decode-header-methods-cache (list x))
8609 (if (and gnus-newsgroup-name
8610 (string-match (car x) gnus-newsgroup-name))
8611 (nconc gnus-decode-header-methods-cache
8612 (list (cdr x)))))))
8613 (let ((xlist gnus-decode-header-methods-cache))
8614 (pop xlist)
8615 (save-restriction
8616 (narrow-to-region start end)
8617 (while xlist
8618 (funcall (pop xlist) (point-min) (point-max))))))
8621 ;;; Treatment top-level handling.
8624 (defvar gnus-inhibit-article-treatments nil)
8626 ;; Dynamic variables.
8627 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8628 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8629 (defvar gnus-treat-type)
8630 (defvar gnus-treat-condition)
8631 (defvar gnus-treat-length)
8633 (defun gnus-treat-article (condition
8634 &optional part-num total type)
8635 (let ((gnus-treat-condition condition)
8636 (part-number part-num)
8637 (total-parts total)
8638 (gnus-treat-type type)
8639 (gnus-treat-length (- (point-max) (point-min)))
8640 (alist gnus-treatment-function-alist)
8641 (article-goto-body-goes-to-point-min-p t)
8642 (treated-type
8643 (or (not type)
8644 (catch 'found
8645 (let ((list gnus-article-treat-types))
8646 (while list
8647 (when (string-match (pop list) type)
8648 (throw 'found t)))))))
8649 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8650 val)
8651 (gnus-run-hooks 'gnus-part-display-hook)
8652 (dolist (elem alist)
8653 (setq val
8654 (save-excursion
8655 (when (gnus-buffer-live-p gnus-summary-buffer)
8656 (set-buffer gnus-summary-buffer))
8657 (symbol-value (car elem))))
8658 (when (and (or (consp val)
8659 treated-type)
8660 (or (not gnus-inhibit-article-treatments)
8661 (eq gnus-treat-condition 'head))
8662 (gnus-treat-predicate val)
8663 (or (not (get (car elem) 'highlight))
8664 highlightp))
8665 (save-restriction
8666 (funcall (cadr elem)))))))
8668 (defun gnus-treat-predicate (val)
8669 (cond
8670 ((null val)
8671 nil)
8672 (gnus-treat-condition
8673 (eq gnus-treat-condition val))
8674 ((and (listp val)
8675 (stringp (car val)))
8676 (apply 'gnus-or (mapcar `(lambda (s)
8677 (string-match s ,(or gnus-newsgroup-name "")))
8678 val)))
8679 ((listp val)
8680 (let ((pred (pop val)))
8681 (cond
8682 ((eq pred 'or)
8683 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8684 ((eq pred 'and)
8685 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8686 ((eq pred 'not)
8687 (not (gnus-treat-predicate (car val))))
8688 ((eq pred 'typep)
8689 (equal (car val) gnus-treat-type))
8690 ((functionp pred)
8691 (funcall pred))
8693 (error "%S is not a valid predicate" pred)))))
8694 ((eq val t)
8696 ((eq val 'head)
8697 nil)
8698 ((eq val 'first)
8699 (eq part-number 1))
8700 ((eq val 'last)
8701 (eq part-number total-parts))
8702 ((numberp val)
8703 (< gnus-treat-length val))
8705 (error "%S is not a valid value" val))))
8707 (defun gnus-article-encrypt-body (protocol &optional n)
8708 "Encrypt the article body."
8709 (interactive
8710 (list
8711 (or gnus-article-encrypt-protocol
8712 (gnus-completing-read "Encrypt protocol"
8713 (mapcar 'car gnus-article-encrypt-protocol-alist)
8715 current-prefix-arg))
8716 ;; User might hit `K E' instead of `K e', so prompt once.
8717 (when (and gnus-article-encrypt-protocol
8718 gnus-novice-user)
8719 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8720 (error "Encrypt aborted")))
8721 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8722 (unless func
8723 (error "Can't find the encrypt protocol %s" protocol))
8724 (if (member gnus-newsgroup-name '("nndraft:delayed"
8725 "nndraft:drafts"
8726 "nndraft:queue"))
8727 (error "Can't encrypt the article in group %s"
8728 gnus-newsgroup-name))
8729 (gnus-summary-iterate n
8730 (with-current-buffer gnus-summary-buffer
8731 (let ((mail-parse-charset gnus-newsgroup-charset)
8732 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8733 (summary-buffer gnus-summary-buffer)
8734 references point)
8735 (gnus-set-global-variables)
8736 (when (gnus-group-read-only-p)
8737 (error "The current newsgroup does not support article encrypt"))
8738 (gnus-summary-show-article t)
8739 (setq references
8740 (or (mail-header-references gnus-current-headers) ""))
8741 (set-buffer gnus-article-buffer)
8742 (let* ((inhibit-read-only t)
8743 (headers
8744 (mapcar (lambda (field)
8745 (and (save-restriction
8746 (message-narrow-to-head)
8747 (goto-char (point-min))
8748 (search-forward field nil t))
8749 (prog2
8750 (message-narrow-to-field)
8751 (buffer-string)
8752 (delete-region (point-min) (point-max))
8753 (widen))))
8754 '("Content-Type:" "Content-Transfer-Encoding:"
8755 "Content-Disposition:"))))
8756 (message-narrow-to-head)
8757 (message-remove-header "MIME-Version")
8758 (goto-char (point-max))
8759 (setq point (point))
8760 (insert (apply 'concat headers))
8761 (widen)
8762 (narrow-to-region point (point-max))
8763 (let ((message-options message-options))
8764 (message-options-set 'message-sender user-mail-address)
8765 (message-options-set 'message-recipients user-mail-address)
8766 (message-options-set 'message-sign-encrypt 'not)
8767 (funcall func))
8768 (goto-char (point-min))
8769 (insert "MIME-Version: 1.0\n")
8770 (widen)
8771 (gnus-summary-edit-article-done
8772 references nil summary-buffer t))
8773 (when gnus-keep-backlog
8774 (gnus-backlog-remove-article
8775 (car gnus-article-current) (cdr gnus-article-current)))
8776 (gnus-flush-original-article-buffer)
8777 (when gnus-use-cache
8778 (gnus-cache-update-article
8779 (car gnus-article-current) (cdr gnus-article-current))))))))
8781 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8782 "The following specs can be used:
8783 %t The security MIME type
8784 %i Additional info
8785 %d Details
8786 %D Details if button is pressed")
8788 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8789 "The following specs can be used:
8790 %t The security MIME type
8791 %i Additional info
8792 %d Details
8793 %D Details if button is pressed")
8795 (defvar gnus-mime-security-button-line-format-alist
8796 '((?t gnus-tmp-type ?s)
8797 (?i gnus-tmp-info ?s)
8798 (?d gnus-tmp-details ?s)
8799 (?D gnus-tmp-pressed-details ?s)))
8801 (defvar gnus-mime-security-button-commands
8802 '((gnus-article-press-button "\r" "Show Detail")
8803 (undefined "v")
8804 (undefined "t")
8805 (undefined "C")
8806 (gnus-mime-security-save-part "o" "Save...")
8807 (undefined "\C-o")
8808 (undefined "r")
8809 (undefined "d")
8810 (undefined "c")
8811 (undefined "i")
8812 (undefined "E")
8813 (undefined "e")
8814 (undefined "p")
8815 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8816 (undefined ".")))
8818 (defvar gnus-mime-security-button-map
8819 (let ((map (make-sparse-keymap)))
8820 (define-key map gnus-mouse-2 'gnus-article-push-button)
8821 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8822 (dolist (c gnus-mime-security-button-commands)
8823 (define-key map (cadr c) (car c)))
8824 map))
8826 (easy-menu-define
8827 gnus-mime-security-button-menu gnus-mime-security-button-map
8828 "Security button menu."
8829 `("Security Part"
8830 ,@(delq nil
8831 (mapcar (lambda (c)
8832 (unless (eq (car c) 'undefined)
8833 (vector (caddr c) (car c) :active t)))
8834 gnus-mime-security-button-commands))))
8836 (defun gnus-mime-security-button-menu (event prefix)
8837 "Construct a context-sensitive menu of security commands."
8838 (interactive "e\nP")
8839 (save-window-excursion
8840 (let ((pos (event-start event)))
8841 (select-window (posn-window pos))
8842 (goto-char (posn-point pos))
8843 (gnus-article-check-buffer)
8844 (popup-menu gnus-mime-security-button-menu nil prefix))))
8846 (defvar gnus-mime-security-details-buffer nil)
8848 (defvar gnus-mime-security-button-pressed nil)
8850 (defvar gnus-mime-security-show-details-inline t
8851 "If non-nil, show details in the article buffer.")
8853 (defun gnus-mime-security-verify-or-decrypt (handle)
8854 (mm-remove-parts (cdr handle))
8855 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8856 point (inhibit-read-only t))
8857 (if region
8858 (goto-char (car region)))
8859 (setq point (point))
8860 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8861 (let* ((mm-verify-option 'known)
8862 (mm-decrypt-option 'known)
8863 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8864 (unless (eq nparts (cdr handle))
8865 (mm-destroy-parts (cdr handle))
8866 (setcdr handle nparts))))
8867 (gnus-mime-display-security handle)
8868 (when region
8869 (delete-region (point) (cdr region))
8870 (set-marker (car region) nil)
8871 (set-marker (cdr region) nil))
8872 (goto-char point)))
8874 (defun gnus-mime-security-show-details (handle)
8875 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8876 (if (not details)
8877 (gnus-message 5 "No details.")
8878 (if gnus-mime-security-show-details-inline
8879 (let ((gnus-mime-security-button-pressed
8880 (not (get-text-property (point) 'gnus-mime-details)))
8881 (gnus-mime-security-button-line-format
8882 (get-text-property (point) 'gnus-line-format))
8883 (inhibit-read-only t))
8884 (forward-char -1)
8885 (while (eq (get-text-property (point) 'gnus-line-format)
8886 gnus-mime-security-button-line-format)
8887 (forward-char -1))
8888 (forward-char)
8889 (save-restriction
8890 (narrow-to-region (point) (point))
8891 (gnus-insert-mime-security-button handle))
8892 (delete-region (point)
8893 (or (text-property-not-all
8894 (point) (point-max)
8895 'gnus-line-format
8896 gnus-mime-security-button-line-format)
8897 (point-max))))
8898 ;; Not inlined.
8899 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8900 (with-current-buffer gnus-mime-security-details-buffer
8901 (erase-buffer)
8903 (setq gnus-mime-security-details-buffer
8904 (gnus-get-buffer-create "*MIME Security Details*")))
8905 (with-current-buffer gnus-mime-security-details-buffer
8906 (insert details)
8907 (goto-char (point-min)))
8908 (pop-to-buffer gnus-mime-security-details-buffer)))))
8910 (defun gnus-mime-security-press-button (handle)
8911 (save-excursion
8912 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8913 (gnus-mime-security-show-details handle)
8914 (gnus-mime-security-verify-or-decrypt handle))))
8916 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8917 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8918 (gnus-tmp-type
8919 (concat
8920 (or (nth 2 (assoc protocol mm-verify-function-alist))
8921 (nth 2 (assoc protocol mm-decrypt-function-alist))
8922 "Unknown")
8923 (if (equal (car handle) "multipart/signed")
8924 " Signed" " Encrypted")
8925 " Part"))
8926 (gnus-tmp-info
8927 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8928 "Undecided"))
8929 (gnus-tmp-details
8930 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8931 gnus-tmp-pressed-details
8932 b e)
8933 (setq gnus-tmp-details
8934 (if gnus-tmp-details
8935 (concat "\n" gnus-tmp-details)
8936 ""))
8937 (setq gnus-tmp-pressed-details
8938 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8939 (unless (bolp)
8940 (insert "\n"))
8941 (setq b (point))
8942 (gnus-eval-format
8943 gnus-mime-security-button-line-format
8944 gnus-mime-security-button-line-format-alist
8945 `(keymap ,gnus-mime-security-button-map
8946 gnus-callback gnus-mime-security-press-button
8947 gnus-line-format ,gnus-mime-security-button-line-format
8948 gnus-mime-details ,gnus-mime-security-button-pressed
8949 article-type annotation
8950 gnus-data ,handle))
8951 (setq e (if (bolp)
8952 ;; Exclude a newline.
8953 (1- (point))
8954 (point)))
8955 (when gnus-article-button-face
8956 (overlay-put (make-overlay b e nil t)
8957 'face gnus-article-button-face))
8958 (widget-convert-button
8959 'link b e
8960 :mime-handle handle
8961 :action 'gnus-widget-press-button
8962 :button-keymap gnus-mime-security-button-map
8963 :help-echo
8964 (lambda (_widget)
8965 ;; Needed to properly clear the message due to a bug in
8966 ;; wid-edit (XEmacs only).
8967 (when (boundp 'help-echo-owns-message)
8968 (setq help-echo-owns-message t))
8969 (format
8970 "%S: show detail; %S: more options"
8971 (aref gnus-mouse-2 0)
8972 (aref gnus-down-mouse-3 0))))))
8974 (defun gnus-mime-display-security (handle)
8975 (save-restriction
8976 (narrow-to-region (point) (point))
8977 (unless (gnus-unbuttonized-mime-type-p (car handle))
8978 (gnus-insert-mime-security-button handle))
8979 (gnus-mime-display-part (cadr handle))
8980 (unless (bolp)
8981 (insert "\n"))
8982 (unless (gnus-unbuttonized-mime-type-p (car handle))
8983 (let ((gnus-mime-security-button-line-format
8984 gnus-mime-security-button-end-line-format))
8985 (gnus-insert-mime-security-button handle)))
8986 (mm-set-handle-multipart-parameter
8987 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8988 (goto-char (point-max))))
8990 (defun gnus-mime-security-run-function (function)
8991 "Run FUNCTION with the security part under point."
8992 (gnus-article-check-buffer)
8993 (let ((data (get-text-property (point) 'gnus-data))
8994 buffer handle)
8995 (when (and (stringp (car-safe data))
8996 (setq buffer (mm-handle-multipart-original-buffer data))
8997 (setq handle (cadr data)))
8998 (if (bufferp (mm-handle-buffer handle))
8999 (progn
9000 (setq handle (cons buffer (copy-sequence (cdr handle))))
9001 (mm-handle-set-undisplayer handle nil))
9002 (setq handle (mm-make-handle
9003 buffer
9004 (mm-handle-multipart-ctl-parameter handle 'protocol)
9005 nil nil nil nil nil nil)))
9006 (funcall function handle))))
9008 (defun gnus-mime-security-save-part ()
9009 "Save the security part under point."
9010 (interactive)
9011 (gnus-mime-security-run-function 'mm-save-part))
9013 (defun gnus-mime-security-pipe-part ()
9014 "Pipe the security part under point to a process."
9015 (interactive)
9016 (gnus-mime-security-run-function 'mm-pipe-part))
9018 (gnus-ems-redefine)
9020 (provide 'gnus-art)
9022 (run-hooks 'gnus-art-load-hook)
9024 ;;; gnus-art.el ends here