Merge from emacs-24; up to 2014-06-06T02:22:40Z!monnier@iro.umontreal.ca
[emacs.git] / lisp / gnus / gnus-art.el
blobb08e523c4405e4e37855643621e75171dafd235f
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
167 (defcustom gnus-visible-headers
168 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
169 "*All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "*This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
197 'empty Headers with no content.
198 'newsgroups Newsgroup identical to Gnus group.
199 'to-address To identical to To-address.
200 'to-list To identical to To-list.
201 'cc-list CC identical to To-list.
202 'followup-to Followup-to identical to Newsgroups.
203 'reply-to Reply-to identical to From.
204 'date Date less than four days old.
205 'long-to To and/or Cc longer than 1024 characters.
206 'many-to Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "CC identical to To-list." cc-list)
212 (const :tag "Followup-to identical to Newsgroups." followup-to)
213 (const :tag "Reply-to identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
256 (defcustom gnus-hidden-properties '(invisible t intangible t)
257 "Property list to use for hiding text."
258 :type 'sexp
259 :group 'gnus-article-hiding)
261 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
262 ;; frames in a session.
263 (defcustom gnus-article-x-face-command
264 (if (featurep 'xemacs)
265 (if (or (gnus-image-type-available-p 'xface)
266 (gnus-image-type-available-p 'pbm))
267 'gnus-display-x-face-in-from
268 "{ echo \
269 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
270 ; uncompface; } | icontopbm | ee -")
271 (if (gnus-image-type-available-p 'pbm)
272 'gnus-display-x-face-in-from
273 "{ echo \
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | display -"))
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
281 function)
282 :version "21.1"
283 :group 'gnus-picon
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
293 For example,
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295 :version "21.1"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
300 banner
301 :variable-document
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
304 :parameter-type
305 '(choice :tag "Banner"
306 :value nil
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
309 regexp
310 (const :tag "None" nil))
311 :parameter-document
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 :type '(repeat
331 (cons
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
336 regexp
337 (const :tag "None" nil))))
338 :version "22.1"
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342 `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345 ,@body))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
353 (nth 2 value))
354 value)))
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
361 "\\'"))
362 pattern)
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
365 (= (nth 2 value) 2)
366 (nth 3 value))
367 value))))
369 (defcustom gnus-emphasis-alist
370 (let ((types
371 '(("\\*" "\\*" bold nil 2)
372 ("_" "_" underline)
373 ("/" "/" italic)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
378 (nconc
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
382 (or (nth 3 spec) 2)
383 (or (nth 4 spec) 3)
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385 types))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
404 :type
405 '(repeat
406 (menu-choice
407 :format "%[Customizing Style%]\n%v"
408 :indent 2
409 (group :tag "Default"
410 :value ("" 0 0 default)
411 :value-create
412 (lambda (widget)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
415 :args))
416 :value)))
417 (if (not (eq (nth 2 value) 'default))
418 (widget-put
419 widget
420 :value
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
423 regexp
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
426 face)
427 (group :tag "Simple"
428 :value (("_" . "_") nil default)
429 (cons :format "%v"
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
434 face)))
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440 value)))
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448 :version "21.1"
449 :group 'gnus-article-emphasis
450 :type 'regexp)
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509 :group 'gnus-article-saving
510 :type 'boolean)
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
534 :type 'regexp)
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favorite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
542 Gnus provides the following functions:
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
554 The symbol of each function may have the following properties:
556 * :decode
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
584 (function)))
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
595 commands including:
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
602 and the functions to which you may set `gnus-default-article-saver':
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
614 :type `(choice
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
617 ,@(delq nil
618 (mapcar
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
630 :type 'function)
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
647 LAST-FILE."
648 :group 'gnus-article-saving
649 :type 'function)
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
664 non-nil.
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evalled in the same buffer.
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
677 (sexp :value nil))))
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
683 :type 'regexp
684 :group 'gnus-article-various)
686 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
690 The following additional specs are available:
692 %w The article washing status.
693 %m The number of MIME parts in the article."
694 :version "24.1"
695 :type 'string
696 :group 'gnus-article-various)
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
700 :type 'hook
701 :group 'gnus-article-various)
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
878 (png . nil)))
879 "Alist of image types and properties applied to Face and X-Face images.
880 Here are examples:
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
905 :type 'hook)
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
910 :type 'function)
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
918 (defvar gnus-article-dumbquotes-map
919 '((?\200 "EUR")
920 (?\202 ",")
921 (?\203 "f")
922 (?\204 ",,")
923 (?\205 "...")
924 (?\213 "<")
925 (?\214 "OE")
926 (?\221 "`")
927 (?\222 "'")
928 (?\223 "``")
929 (?\224 "\"")
930 (?\225 "*")
931 (?\226 "-")
932 (?\227 "--")
933 (?\230 "~")
934 (?\231 "(TM)")
935 (?\233 ">")
936 (?\234 "oe")
937 (?\264 "'"))
938 "Table for MS-to-Latin1 translation.")
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :version "21.1"
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :version "22.1"
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
971 :version "22.1"
972 :group 'gnus-article-mime
973 :type 'boolean)
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
979 :version "22.1"
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
982 string))
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "/usr/share/picons")
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :version "22.1"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
994 :group 'gnus-picon)
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1002 installed))
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1010 function))
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1014 :version "21.1"
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018 (defcustom gnus-article-date-headers '(combined-lapsed)
1019 "A list of Date header formats to display.
1020 Valid formats are `ut' (universal time), `local' (local time
1021 zone), `english' (readable English), `lapsed' (elapsed time),
1022 `combined-lapsed' (both the original date and the elapsed time),
1023 `original' (the original date header), `iso8601' (ISO8601
1024 format), and `user-defined' (a user-defined format defined by the
1025 `gnus-article-time-format' variable).
1027 You have as many date headers as you want in the article buffer.
1028 Some of these headers are updated automatically. See
1029 `gnus-article-update-date-headers' for details."
1030 :version "24.1"
1031 :group 'gnus-article-headers
1032 :type '(set
1033 (const :tag "Universal time (UT)" ut)
1034 (const :tag "Local time zone" local)
1035 (const :tag "Readable English" english)
1036 (const :tag "Elapsed time" lapsed)
1037 (const :tag "Original and elapsed time" combined-lapsed)
1038 (const :tag "Original date header" original)
1039 (const :tag "ISO8601 format" iso8601)
1040 (const :tag "User-defined" user-defined)))
1042 (defcustom gnus-article-update-date-headers nil
1043 "A number that says how often to update the date header (in seconds).
1044 If nil, don't update it at all."
1045 :version "24.1"
1046 :group 'gnus-article-headers
1047 :type '(choice
1048 (item :tag "Don't update" :value nil)
1049 integer))
1051 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1052 "Function called with a MIME handle as the argument.
1053 This is meant for people who want to view first matched part.
1054 For `undisplayed-alternative' (default), the first undisplayed
1055 part or alternative part is used. For `undisplayed', the first
1056 undisplayed part is used. For a function, the first part which
1057 the function return t is used. For nil, the first part is
1058 used."
1059 :version "21.1"
1060 :group 'gnus-article-mime
1061 :type '(choice
1062 (item :tag "first" :value nil)
1063 (item :tag "undisplayed" :value undisplayed)
1064 (item :tag "undisplayed or alternative"
1065 :value undisplayed-alternative)
1066 (function)))
1068 (defcustom gnus-mime-action-alist
1069 '(("save to file" . gnus-mime-save-part)
1070 ("save and strip" . gnus-mime-save-part-and-strip)
1071 ("replace with file" . gnus-mime-replace-part)
1072 ("delete part" . gnus-mime-delete-part)
1073 ("display as text" . gnus-mime-inline-part)
1074 ("view the part" . gnus-mime-view-part)
1075 ("pipe to command" . gnus-mime-pipe-part)
1076 ("toggle display" . gnus-article-press-button)
1077 ("toggle display" . gnus-article-view-part-as-charset)
1078 ("view as type" . gnus-mime-view-part-as-type)
1079 ("view internally" . gnus-mime-view-part-internally)
1080 ("view externally" . gnus-mime-view-part-externally))
1081 "An alist of actions that run on the MIME attachment."
1082 :group 'gnus-article-mime
1083 :type '(repeat (cons (string :tag "name")
1084 (function))))
1086 (defcustom gnus-auto-select-part 1
1087 "Advance to next MIME part when deleting or stripping parts.
1089 When 0, point will be placed on the same part as before. When
1090 positive (negative), move point forward (backwards) this many
1091 parts. When nil, redisplay article."
1092 :version "23.1" ;; No Gnus
1093 :group 'gnus-article-mime
1094 :type '(choice (const nil :tag "Redisplay article.")
1095 (const 1 :tag "Next part.")
1096 (const 0 :tag "Current part.")
1097 integer))
1100 ;;; The treatment variables
1103 (defvar gnus-part-display-hook nil
1104 "Hook called on parts that are to receive treatment.")
1106 (defvar gnus-article-treat-custom
1107 '(choice (const :tag "Off" nil)
1108 (const :tag "On" t)
1109 (const :tag "Header" head)
1110 (const :tag "First" first)
1111 (const :tag "Last" last)
1112 (integer :tag "Less")
1113 (repeat :tag "Groups" regexp)
1114 (sexp :tag "Predicate")))
1116 (defvar gnus-article-treat-head-custom
1117 '(choice (const :tag "Off" nil)
1118 (const :tag "Header" head)))
1120 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1121 "text/x-patch" "text/html")
1122 "Part types eligible for treatment.")
1124 (defvar gnus-inhibit-treatment nil
1125 "Whether to inhibit treatment.")
1127 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1128 "Highlight the signature.
1129 Valid values are nil, t, `head', `first', `last', an integer or a
1130 predicate. See Info node `(gnus)Customizing Articles'."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134 (put 'gnus-treat-highlight-signature 'highlight t)
1136 (defcustom gnus-treat-buttonize 100000
1137 "Add buttons.
1138 Valid values are nil, t, `head', `first', `last', an integer or a
1139 predicate. See Info node `(gnus)Customizing Articles'."
1140 :group 'gnus-article-treat
1141 :link '(custom-manual "(gnus)Customizing Articles")
1142 :type gnus-article-treat-custom)
1143 (put 'gnus-treat-buttonize 'highlight t)
1145 (defcustom gnus-treat-buttonize-head 'head
1146 "Add buttons to the head.
1147 Valid values are nil, t, `head', `first', `last', an integer or a
1148 predicate. See Info node `(gnus)Customizing Articles'."
1149 :group 'gnus-article-treat
1150 :link '(custom-manual "(gnus)Customizing Articles")
1151 :type gnus-article-treat-head-custom)
1152 (put 'gnus-treat-buttonize-head 'highlight t)
1154 (defcustom gnus-treat-date 'head
1155 "Display dates according to the `gnus-article-date-headers' variable.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate. See Info node `(gnus)Customizing Articles'."
1158 :version "24.1"
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1163 (defcustom gnus-treat-emphasize 50000
1164 "Emphasize text.
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-custom)
1170 (put 'gnus-treat-emphasize 'highlight t)
1172 (defcustom gnus-treat-strip-cr nil
1173 "Remove carriage returns.
1174 Valid values are nil, t, `head', `first', `last', an integer or a
1175 predicate. See Info node `(gnus)Customizing Articles'."
1176 :version "22.1"
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-custom)
1181 (defcustom gnus-treat-unsplit-urls nil
1182 "Remove newlines from within URLs.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1185 :version "22.1"
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-leading-whitespace nil
1191 "Remove leading whitespace in headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :version "22.1"
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-hide-headers 'head
1200 "Hide headers.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1207 (defcustom gnus-treat-hide-boring-headers nil
1208 "Hide boring headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1215 (defcustom gnus-treat-hide-signature nil
1216 "Hide the signature.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (defcustom gnus-treat-fill-article nil
1224 "Fill the article.
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-hide-citation nil
1232 "Hide cited text.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'.
1236 See `gnus-article-highlight-citation' for variables used to
1237 control what it hides."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1242 (defcustom gnus-treat-hide-citation-maybe nil
1243 "Hide cited text according to certain conditions.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'.
1247 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1248 how to control what it hides."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1253 (defcustom gnus-treat-strip-list-identifiers 'head
1254 "Strip list identifiers from `gnus-list-identifiers`.
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :version "21.1"
1258 :group 'gnus-article-treat
1259 :link '(custom-manual "(gnus)Customizing Articles")
1260 :type gnus-article-treat-custom)
1262 (gnus-define-group-parameter
1263 list-identifier
1264 :variable-document
1265 "Alist of regexps and correspondent identifiers."
1266 :variable-group gnus-article-washing
1267 :parameter-type
1268 '(choice :tag "Identifier"
1269 :value nil
1270 (symbol :tag "Item in `gnus-list-identifiers'" none)
1271 regexp
1272 (const :tag "None" nil))
1273 :parameter-document
1274 "If non-nil, specify how to remove `identifiers' from articles' subject.
1276 Any symbol is used to look up a regular expression to match the
1277 banner in `gnus-list-identifiers'. A string is used as a regular
1278 expression to match the identifier directly.")
1280 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1281 "Gnus 5.10 (Emacs 22.1)")
1283 (defcustom gnus-treat-strip-pem nil
1284 "Strip PEM signatures.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1287 :group 'gnus-article-treat
1288 :link '(custom-manual "(gnus)Customizing Articles")
1289 :type gnus-article-treat-custom)
1291 (defcustom gnus-treat-strip-banner t
1292 "Strip banners from articles.
1293 The banner to be stripped is specified in the `banner' group parameter.
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-custom)
1300 (defcustom gnus-treat-highlight-headers 'head
1301 "Highlight the headers.
1302 Valid values are nil, t, `head', `first', `last', an integer or a
1303 predicate. See Info node `(gnus)Customizing Articles'."
1304 :group 'gnus-article-treat
1305 :link '(custom-manual "(gnus)Customizing Articles")
1306 :type gnus-article-treat-head-custom)
1307 (put 'gnus-treat-highlight-headers 'highlight t)
1309 (defcustom gnus-treat-highlight-citation t
1310 "Highlight cited text.
1311 Valid values are nil, t, `head', `first', `last', an integer or a
1312 predicate. See Info node `(gnus)Customizing Articles'."
1313 :group 'gnus-article-treat
1314 :link '(custom-manual "(gnus)Customizing Articles")
1315 :type gnus-article-treat-custom)
1316 (put 'gnus-treat-highlight-citation 'highlight t)
1318 (defcustom gnus-treat-strip-headers-in-body t
1319 "Strip the X-No-Archive header line from the beginning of the body.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1322 :version "21.1"
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-custom)
1327 (defcustom gnus-treat-strip-trailing-blank-lines nil
1328 "Strip trailing blank lines.
1329 Valid values are nil, t, `head', `first', `last', an integer or a
1330 predicate. See Info node `(gnus)Customizing Articles'.
1332 When set to t, it also strips trailing blanks in all MIME parts.
1333 Consider to use `last' instead."
1334 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :type gnus-article-treat-custom)
1338 (defcustom gnus-treat-strip-leading-blank-lines nil
1339 "Strip leading blank lines.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles'.
1343 When set to t, it also strips trailing blanks in all MIME parts."
1344 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :type gnus-article-treat-custom)
1348 (defcustom gnus-treat-strip-multiple-blank-lines nil
1349 "Strip multiple blank lines.
1350 Valid values are nil, t, `head', `first', `last', an integer or a
1351 predicate. See Info node `(gnus)Customizing Articles'."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-treat-unfold-headers 'head
1357 "Unfold folded header lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'."
1360 :version "22.1"
1361 :group 'gnus-article-treat
1362 :link '(custom-manual "(gnus)Customizing Articles")
1363 :type gnus-article-treat-custom)
1365 (defcustom gnus-article-unfold-long-headers nil
1366 "If non-nil, allow unfolding headers even if the header is long.
1367 If it is a regexp, only long headers matching this regexp are unfolded.
1368 If it is t, all long headers are unfolded.
1370 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1371 :version "23.1" ;; No Gnus
1372 :group 'gnus-article-treat
1373 :type '(choice (const nil)
1374 (const :tag "all" t)
1375 (regexp)))
1377 (defcustom gnus-treat-fold-headers nil
1378 "Fold headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles'."
1381 :version "22.1"
1382 :group 'gnus-article-treat
1383 :link '(custom-manual "(gnus)Customizing Articles")
1384 :type gnus-article-treat-custom)
1386 (defcustom gnus-treat-fold-newsgroups 'head
1387 "Fold the Newsgroups and Followup-To headers.
1388 Valid values are nil, t, `head', `first', `last', an integer or a
1389 predicate. See Info node `(gnus)Customizing Articles'."
1390 :version "22.1"
1391 :group 'gnus-article-treat
1392 :link '(custom-manual "(gnus)Customizing Articles")
1393 :type gnus-article-treat-custom)
1395 (defcustom gnus-treat-overstrike t
1396 "Treat overstrike highlighting.
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1399 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :type gnus-article-treat-custom)
1402 (put 'gnus-treat-overstrike 'highlight t)
1404 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1405 "Treat ANSI SGR control sequences.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1408 :group 'gnus-article-treat
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :type gnus-article-treat-custom)
1412 (make-obsolete-variable 'gnus-treat-display-xface
1413 'gnus-treat-display-x-face "Emacs 22.1")
1415 (defcustom gnus-treat-display-x-face
1416 (and (not noninteractive)
1417 (gnus-image-type-available-p 'xbm)
1418 (if (featurep 'xemacs)
1419 (featurep 'xface)
1420 (condition-case nil
1421 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1422 (executable-find "icontopbm"))
1423 ;; shell-command-to-string may signal an error, e.g. if
1424 ;; shell-file-name is not found.
1425 (error nil)))
1426 'head)
1427 "Display X-Face headers.
1428 Valid values are nil and `head'.
1429 See Info node `(gnus)Customizing Articles' and Info node
1430 `(gnus)X-Face' for details."
1431 :group 'gnus-article-treat
1432 :version "21.1"
1433 :link '(custom-manual "(gnus)Customizing Articles")
1434 :link '(custom-manual "(gnus)X-Face")
1435 :type gnus-article-treat-head-custom
1436 :set (lambda (symbol value)
1437 (set-default
1438 symbol
1439 (cond ((or (boundp symbol) (get symbol 'saved-value))
1440 value)
1441 ((boundp 'gnus-treat-display-xface)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (default-value 'gnus-treat-display-xface))
1446 ((get 'gnus-treat-display-xface 'saved-value)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1452 value)))))
1453 (put 'gnus-treat-display-x-face 'highlight t)
1455 (defcustom gnus-treat-display-face
1456 (and (not noninteractive)
1457 (gnus-image-type-available-p 'png)
1458 'head)
1459 "Display Face headers.
1460 Valid values are nil, t, `head', `first', `last', an integer or a
1461 predicate. See Info node `(gnus)Customizing Articles' and Info
1462 node `(gnus)Face' for details."
1463 :group 'gnus-article-treat
1464 :version "22.1"
1465 :link '(custom-manual "(gnus)Customizing Articles")
1466 :link '(custom-manual "(gnus)X-Face")
1467 :type gnus-article-treat-head-custom)
1468 (put 'gnus-treat-display-face 'highlight t)
1470 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1471 "Display smileys.
1472 Valid values are nil, t, `head', `first', `last', an integer or a
1473 predicate. See Info node `(gnus)Customizing Articles' and Info
1474 node `(gnus)Smileys' for details."
1475 :group 'gnus-article-treat
1476 :version "21.1"
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Smileys")
1479 :type gnus-article-treat-custom)
1480 (put 'gnus-treat-display-smileys 'highlight t)
1482 (defcustom gnus-treat-from-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1485 'head nil)
1486 "Display picons in the From header.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1490 :version "22.1"
1491 :group 'gnus-article-treat
1492 :group 'gnus-picon
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-from-picon 'highlight t)
1498 (defcustom gnus-treat-mail-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1501 'head nil)
1502 "Display picons in To and Cc headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1506 :version "22.1"
1507 :group 'gnus-article-treat
1508 :group 'gnus-picon
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-mail-picon 'highlight t)
1514 (defcustom gnus-treat-newsgroups-picon
1515 (if (and (gnus-image-type-available-p 'xpm)
1516 (gnus-picons-installed-p))
1517 'head nil)
1518 "Display picons in the Newsgroups and Followup-To headers.
1519 Valid values are nil, t, `head', `first', `last', an integer or a
1520 predicate. See Info node `(gnus)Customizing Articles' and Info
1521 node `(gnus)Picons' for details."
1522 :version "22.1"
1523 :group 'gnus-article-treat
1524 :group 'gnus-picon
1525 :link '(custom-manual "(gnus)Customizing Articles")
1526 :link '(custom-manual "(gnus)Picons")
1527 :type gnus-article-treat-head-custom)
1528 (put 'gnus-treat-newsgroups-picon 'highlight t)
1530 (defcustom gnus-treat-from-gravatar nil
1531 "Display gravatars in the From header.
1532 Valid values are nil, t, `head', `first', `last', an integer or a
1533 predicate. See Info node `(gnus)Customizing Articles' and Info
1534 node `(gnus)Gravatars' for details."
1535 :version "24.1"
1536 :group 'gnus-article-treat
1537 :group 'gnus-gravatar
1538 :link '(custom-manual "(gnus)Customizing Articles")
1539 :link '(custom-manual "(gnus)Gravatars")
1540 :type gnus-article-treat-head-custom)
1541 (put 'gnus-treat-from-gravatar 'highlight t)
1543 (defcustom gnus-treat-mail-gravatar nil
1544 "Display gravatars in To and Cc headers.
1545 Valid values are nil, t, `head', `first', `last', an integer or a
1546 predicate. See Info node `(gnus)Customizing Articles' and Info
1547 node `(gnus)Gravatars' for details."
1548 :version "24.1"
1549 :group 'gnus-article-treat
1550 :group 'gnus-gravatar
1551 :link '(custom-manual "(gnus)Customizing Articles")
1552 :link '(custom-manual "(gnus)Gravatars")
1553 :type gnus-article-treat-head-custom)
1554 (put 'gnus-treat-mail-gravatar 'highlight t)
1556 (defcustom gnus-treat-body-boundary
1557 (if (or gnus-treat-newsgroups-picon
1558 gnus-treat-mail-picon
1559 gnus-treat-from-picon
1560 gnus-treat-from-gravatar
1561 gnus-treat-mail-gravatar)
1562 ;; If there's much decoration, the user might prefer a boundary.
1563 'head
1564 nil)
1565 "Draw a boundary at the end of the headers.
1566 Valid values are nil and `head'.
1567 See Info node `(gnus)Customizing Articles' for details."
1568 :version "22.1"
1569 :group 'gnus-article-treat
1570 :link '(custom-manual "(gnus)Customizing Articles")
1571 :type gnus-article-treat-head-custom)
1573 (defcustom gnus-treat-capitalize-sentences nil
1574 "Capitalize sentence-starting words.
1575 Valid values are nil, t, `head', `first', `last', an integer or a
1576 predicate. See Info node `(gnus)Customizing Articles'."
1577 :version "21.1"
1578 :group 'gnus-article-treat
1579 :link '(custom-manual "(gnus)Customizing Articles")
1580 :type gnus-article-treat-custom)
1582 (defcustom gnus-treat-wash-html nil
1583 "Format as HTML.
1584 Valid values are nil, t, `head', `first', `last', an integer or a
1585 predicate. See Info node `(gnus)Customizing Articles'."
1586 :version "22.1"
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-custom)
1591 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1592 "Fill long lines.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1595 :version "24.1"
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1600 (defcustom gnus-treat-x-pgp-sig nil
1601 "Verify X-PGP-Sig.
1602 To automatically treat X-PGP-Sig, set it to head.
1603 Valid values are nil, t, `head', `first', `last', an integer or a
1604 predicate. See Info node `(gnus)Customizing Articles'."
1605 :version "22.1"
1606 :group 'gnus-article-treat
1607 :group 'mime-security
1608 :link '(custom-manual "(gnus)Customizing Articles")
1609 :type gnus-article-treat-custom)
1611 (defvar gnus-article-encrypt-protocol-alist
1612 '(("PGP" . mml2015-self-encrypt)))
1614 ;; Set to nil if more than one protocol added to
1615 ;; gnus-article-encrypt-protocol-alist.
1616 (defcustom gnus-article-encrypt-protocol "PGP"
1617 "The protocol used for encrypt articles.
1618 It is a string, such as \"PGP\". If nil, ask user."
1619 :version "22.1"
1620 :type 'string
1621 :group 'mime-security)
1623 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1624 (mm-coding-system-p 'utf-8)
1625 (executable-find idna-program))
1626 "Whether IDNA decoding of headers is used when viewing messages.
1627 This requires GNU Libidn, and by default only enabled if it is found."
1628 :version "22.1"
1629 :group 'gnus-article-headers
1630 :type 'boolean)
1632 (defcustom gnus-article-over-scroll nil
1633 "If non-nil, allow scrolling the article buffer even when there no more text."
1634 :version "22.1"
1635 :group 'gnus-article
1636 :type 'boolean)
1638 (defcustom gnus-inhibit-images nil
1639 "Non-nil means inhibit displaying of images inline in the article body."
1640 :version "24.1"
1641 :group 'gnus-article
1642 :type 'boolean)
1644 (defcustom gnus-blocked-images 'gnus-block-private-groups
1645 "Images that have URLs matching this regexp will be blocked.
1646 This can also be a function to be evaluated. If so, it will be
1647 called with the group name as the parameter, and should return a
1648 regexp."
1649 :version "24.1"
1650 :group 'gnus-art
1651 :type '(choice regexp function))
1653 ;;; Internal variables
1655 (defvar gnus-english-month-names
1656 '("January" "February" "March" "April" "May" "June" "July" "August"
1657 "September" "October" "November" "December"))
1659 (defvar article-goto-body-goes-to-point-min-p nil)
1660 (defvar gnus-article-wash-types nil)
1661 (defvar gnus-article-emphasis-alist nil)
1662 (defvar gnus-article-image-alist nil)
1664 (defvar gnus-article-mime-handle-alist-1 nil)
1665 (defvar gnus-treatment-function-alist
1666 '((gnus-treat-strip-cr gnus-article-remove-cr)
1667 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1668 (gnus-treat-strip-banner gnus-article-strip-banner)
1669 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1670 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1671 (gnus-treat-buttonize gnus-article-add-buttons)
1672 (gnus-treat-fill-article gnus-article-fill-cited-article)
1673 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1674 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1675 (gnus-treat-display-x-face gnus-article-display-x-face)
1676 (gnus-treat-display-face gnus-article-display-face)
1677 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1678 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1679 (gnus-treat-hide-signature gnus-article-hide-signature)
1680 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1681 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1682 (gnus-treat-from-picon gnus-treat-from-picon)
1683 (gnus-treat-mail-picon gnus-treat-mail-picon)
1684 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1685 (gnus-treat-strip-pem gnus-article-hide-pem)
1686 (gnus-treat-date gnus-article-treat-date)
1687 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1688 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1689 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1690 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1691 (gnus-treat-strip-trailing-blank-lines
1692 gnus-article-remove-trailing-blank-lines)
1693 (gnus-treat-strip-leading-blank-lines
1694 gnus-article-strip-leading-blank-lines)
1695 (gnus-treat-strip-multiple-blank-lines
1696 gnus-article-strip-multiple-blank-lines)
1697 (gnus-treat-overstrike gnus-article-treat-overstrike)
1698 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1699 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1700 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1701 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1702 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1703 (gnus-treat-display-smileys gnus-treat-smiley)
1704 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1705 (gnus-treat-wash-html gnus-article-wash-html)
1706 (gnus-treat-emphasize gnus-article-emphasize)
1707 (gnus-treat-hide-citation gnus-article-hide-citation)
1708 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1709 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1710 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1712 (defvar gnus-article-mime-handle-alist nil)
1713 (defvar article-lapsed-timer nil)
1714 (defvar gnus-article-current-summary nil)
1716 (defvar gnus-article-mode-syntax-table
1717 (let ((table (copy-syntax-table text-mode-syntax-table)))
1718 ;; This causes the citation match run O(2^n).
1719 ;; (modify-syntax-entry ?- "w" table)
1720 (modify-syntax-entry ?> ")<" table)
1721 (modify-syntax-entry ?< "(>" table)
1722 ;; make M-. in article buffers work for `foo' strings
1723 (modify-syntax-entry ?' " " table)
1724 (modify-syntax-entry ?` " " table)
1725 table)
1726 "Syntax table used in article mode buffers.
1727 Initialized from `text-mode-syntax-table.")
1729 (defvar gnus-save-article-buffer nil)
1731 (defvar gnus-number-of-articles-to-be-saved nil)
1733 (defvar gnus-inhibit-hiding nil)
1735 (defvar gnus-article-edit-mode nil)
1737 ;;; Macros for dealing with the article buffer.
1739 (defmacro gnus-with-article-headers (&rest forms)
1740 `(with-current-buffer gnus-article-buffer
1741 (save-restriction
1742 (let ((inhibit-read-only t)
1743 (inhibit-point-motion-hooks t)
1744 (case-fold-search t))
1745 (article-narrow-to-head)
1746 ,@forms))))
1748 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1749 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1751 (defmacro gnus-with-article-buffer (&rest forms)
1752 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1753 (with-current-buffer gnus-article-buffer
1754 (let ((inhibit-read-only t))
1755 ,@forms))))
1757 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1760 (defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1764 (defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1766 (gnus-add-text-properties-when 'article-type nil b e props)
1767 (when (memq 'intangible props)
1768 (put-text-property
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
1772 (defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1779 (defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
1781 (gnus-add-wash-type type)
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1785 (defun gnus-article-unhide-text-type (b e type)
1786 "Unhide text of TYPE between B and E."
1787 (gnus-delete-wash-type type)
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1794 (defun gnus-article-delete-text-of-type (type)
1795 "Delete text of TYPE in the current buffer."
1796 (save-excursion
1797 (let ((b (point-min)))
1798 (if (eq type 'multipart)
1799 ;; Remove MIME buttons associated with multipart/alternative parts.
1800 (progn
1801 (goto-char b)
1802 (while (if (get-text-property (point) 'gnus-part)
1803 (setq b (point))
1804 (when (setq b (next-single-property-change (point)
1805 'gnus-part))
1806 (goto-char b)
1808 (end-of-line)
1809 (skip-chars-forward "\n")
1810 (when (eq (get-text-property b 'article-type) 'multipart)
1811 (delete-region b (point)))))
1812 (while (setq b (text-property-any b (point-max) 'article-type type))
1813 (delete-region
1814 b (or (text-property-not-all b (point-max) 'article-type type)
1815 (point-max))))))))
1817 (defun gnus-article-delete-invisible-text ()
1818 "Delete all invisible text in the current buffer."
1819 (save-excursion
1820 (let ((b (point-min)))
1821 (while (setq b (text-property-any b (point-max) 'invisible t))
1822 (delete-region
1823 b (or (text-property-not-all b (point-max) 'invisible t)
1824 (point-max)))))))
1826 (defsubst gnus-article-header-rank ()
1827 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1828 (let ((list gnus-sorted-header-list)
1829 (i 1))
1830 (while list
1831 (if (looking-at (car list))
1832 (setq list nil)
1833 (setq list (cdr list))
1834 (incf i)))
1837 (defun article-hide-headers (&optional arg delete)
1838 "Hide unwanted headers and possibly sort them as well."
1839 (interactive)
1840 ;; This function might be inhibited.
1841 (unless gnus-inhibit-hiding
1842 (let ((inhibit-read-only t)
1843 (case-fold-search t)
1844 (max (1+ (length gnus-sorted-header-list)))
1845 (inhibit-point-motion-hooks t)
1846 (cur (current-buffer))
1847 ignored visible beg)
1848 (save-excursion
1849 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1850 ;; group parameters, so we should go to the summary buffer.
1851 (when (prog1
1852 (condition-case nil
1853 (progn (set-buffer gnus-summary-buffer) t)
1854 (error nil))
1855 (setq ignored (when (not gnus-visible-headers)
1856 (cond ((stringp gnus-ignored-headers)
1857 gnus-ignored-headers)
1858 ((listp gnus-ignored-headers)
1859 (mapconcat 'identity
1860 gnus-ignored-headers
1861 "\\|"))))
1862 visible (cond ((stringp gnus-visible-headers)
1863 gnus-visible-headers)
1864 ((and gnus-visible-headers
1865 (listp gnus-visible-headers))
1866 (mapconcat 'identity
1867 gnus-visible-headers
1868 "\\|")))))
1869 (set-buffer cur))
1870 (save-restriction
1871 ;; First we narrow to just the headers.
1872 (article-narrow-to-head)
1873 ;; Hide any "From " lines at the beginning of (mail) articles.
1874 (while (looking-at "From ")
1875 (forward-line 1))
1876 (unless (bobp)
1877 (delete-region (point-min) (point)))
1878 ;; Then treat the rest of the header lines.
1879 ;; Then we use the two regular expressions
1880 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1881 ;; select which header lines is to remain visible in the
1882 ;; article buffer.
1883 (while (re-search-forward "^[^ \t:]*:" nil t)
1884 (beginning-of-line)
1885 ;; Mark the rank of the header.
1886 (put-text-property
1887 (point) (1+ (point)) 'message-rank
1888 (if (or (and visible (looking-at visible))
1889 (and ignored
1890 (not (looking-at ignored))))
1891 (gnus-article-header-rank)
1892 (+ 2 max)))
1893 (forward-line 1))
1894 (message-sort-headers-1)
1895 (when (setq beg (text-property-any
1896 (point-min) (point-max) 'message-rank (+ 2 max)))
1897 ;; We delete the unwanted headers.
1898 (gnus-add-wash-type 'headers)
1899 (add-text-properties (point-min) (+ 5 (point-min))
1900 '(article-type headers dummy-invisible t))
1901 (delete-region beg (point-max))))))))
1903 (defun article-hide-boring-headers (&optional arg)
1904 "Toggle hiding of headers that aren't very interesting.
1905 If given a negative prefix, always show; if given a positive prefix,
1906 always hide."
1907 (interactive (gnus-article-hidden-arg))
1908 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1909 (not gnus-show-all-headers))
1910 (save-excursion
1911 (save-restriction
1912 (let ((inhibit-read-only t)
1913 (inhibit-point-motion-hooks t))
1914 (article-narrow-to-head)
1915 (dolist (elem gnus-boring-article-headers)
1916 (goto-char (point-min))
1917 (cond
1918 ;; Hide empty headers.
1919 ((eq elem 'empty)
1920 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1921 (forward-line -1)
1922 (gnus-article-hide-text-type
1923 (point-at-bol)
1924 (progn
1925 (end-of-line)
1926 (if (re-search-forward "^[^ \t]" nil t)
1927 (match-beginning 0)
1928 (point-max)))
1929 'boring-headers)))
1930 ;; Hide boring Newsgroups header.
1931 ((eq elem 'newsgroups)
1932 (when (gnus-string-equal
1933 (gnus-fetch-field "newsgroups")
1934 (gnus-group-real-name
1935 (if (boundp 'gnus-newsgroup-name)
1936 gnus-newsgroup-name
1937 "")))
1938 (gnus-article-hide-header "newsgroups")))
1939 ((eq elem 'to-address)
1940 (let ((to (message-fetch-field "to"))
1941 (to-address
1942 (gnus-parameter-to-address
1943 (if (boundp 'gnus-newsgroup-name)
1944 gnus-newsgroup-name ""))))
1945 (when (and to to-address
1946 (ignore-errors
1947 (gnus-string-equal
1948 ;; only one address in To
1949 (nth 1 (mail-extract-address-components to))
1950 to-address)))
1951 (gnus-article-hide-header "to"))))
1952 ((eq elem 'to-list)
1953 (let ((to (message-fetch-field "to"))
1954 (to-list
1955 (gnus-parameter-to-list
1956 (if (boundp 'gnus-newsgroup-name)
1957 gnus-newsgroup-name ""))))
1958 (when (and to to-list
1959 (ignore-errors
1960 (gnus-string-equal
1961 ;; only one address in To
1962 (nth 1 (mail-extract-address-components to))
1963 to-list)))
1964 (gnus-article-hide-header "to"))))
1965 ((eq elem 'cc-list)
1966 (let ((cc (message-fetch-field "cc"))
1967 (to-list
1968 (gnus-parameter-to-list
1969 (if (boundp 'gnus-newsgroup-name)
1970 gnus-newsgroup-name ""))))
1971 (when (and cc to-list
1972 (ignore-errors
1973 (gnus-string-equal
1974 ;; only one address in CC
1975 (nth 1 (mail-extract-address-components cc))
1976 to-list)))
1977 (gnus-article-hide-header "cc"))))
1978 ((eq elem 'followup-to)
1979 (when (gnus-string-equal
1980 (message-fetch-field "followup-to")
1981 (message-fetch-field "newsgroups"))
1982 (gnus-article-hide-header "followup-to")))
1983 ((eq elem 'reply-to)
1984 (if (gnus-group-find-parameter
1985 gnus-newsgroup-name 'broken-reply-to)
1986 (gnus-article-hide-header "reply-to")
1987 (let ((from (message-fetch-field "from"))
1988 (reply-to (message-fetch-field "reply-to")))
1989 (when
1990 (and
1991 from reply-to
1992 (ignore-errors
1993 (equal
1994 (sort (mapcar
1995 (lambda (x) (downcase (cadr x)))
1996 (mail-extract-address-components from t))
1997 'string<)
1998 (sort (mapcar
1999 (lambda (x) (downcase (cadr x)))
2000 (mail-extract-address-components reply-to t))
2001 'string<))))
2002 (gnus-article-hide-header "reply-to")))))
2003 ((eq elem 'date)
2004 (let ((date (with-current-buffer gnus-original-article-buffer
2005 ;; If date in `gnus-article-buffer' is localized
2006 ;; (`gnus-treat-date-user-defined'),
2007 ;; `days-between' might fail.
2008 (message-fetch-field "date"))))
2009 (when (and date
2010 (< (days-between (current-time-string) date)
2012 (gnus-article-hide-header "date"))))
2013 ((eq elem 'long-to)
2014 (let ((to (message-fetch-field "to"))
2015 (cc (message-fetch-field "cc")))
2016 (when (> (length to) 1024)
2017 (gnus-article-hide-header "to"))
2018 (when (> (length cc) 1024)
2019 (gnus-article-hide-header "cc"))))
2020 ((eq elem 'many-to)
2021 (let ((to-count 0)
2022 (cc-count 0))
2023 (goto-char (point-min))
2024 (while (re-search-forward "^to:" nil t)
2025 (setq to-count (1+ to-count)))
2026 (when (> to-count 1)
2027 (while (> to-count 0)
2028 (goto-char (point-min))
2029 (save-restriction
2030 (re-search-forward "^to:" nil nil to-count)
2031 (forward-line -1)
2032 (narrow-to-region (point) (point-max))
2033 (gnus-article-hide-header "to"))
2034 (setq to-count (1- to-count))))
2035 (goto-char (point-min))
2036 (while (re-search-forward "^cc:" nil t)
2037 (setq cc-count (1+ cc-count)))
2038 (when (> cc-count 1)
2039 (while (> cc-count 0)
2040 (goto-char (point-min))
2041 (save-restriction
2042 (re-search-forward "^cc:" nil nil cc-count)
2043 (forward-line -1)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "cc"))
2046 (setq cc-count (1- cc-count)))))))))))))
2048 (defun gnus-article-hide-header (header)
2049 (save-excursion
2050 (goto-char (point-min))
2051 (when (re-search-forward (concat "^" header ":") nil t)
2052 (gnus-article-hide-text-type
2053 (point-at-bol)
2054 (progn
2055 (end-of-line)
2056 (if (re-search-forward "^[^ \t]" nil t)
2057 (match-beginning 0)
2058 (point-max)))
2059 'boring-headers))))
2061 (defvar gnus-article-normalized-header-length 40
2062 "Length of normalized headers.")
2064 (defun article-normalize-headers ()
2065 "Make all header lines 40 characters long."
2066 (interactive)
2067 (let ((inhibit-read-only t)
2068 column)
2069 (save-excursion
2070 (save-restriction
2071 (article-narrow-to-head)
2072 (while (not (eobp))
2073 (cond
2074 ((< (setq column (- (point-at-eol) (point)))
2075 gnus-article-normalized-header-length)
2076 (end-of-line)
2077 (insert (make-string
2078 (- gnus-article-normalized-header-length column)
2079 ? )))
2080 ((> column gnus-article-normalized-header-length)
2081 (gnus-put-text-property
2082 (progn
2083 (forward-char gnus-article-normalized-header-length)
2084 (point))
2085 (point-at-eol)
2086 'invisible t))
2088 ;; Do nothing.
2090 (forward-line 1))))))
2092 (defun article-treat-dumbquotes ()
2093 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2094 Note that this function guesses whether a character is a sm*rtq**t* or
2095 not, so it should only be used interactively.
2097 Sm*rtq**t*s are M****s***'s unilateral extension to the
2098 iso-8859-1 character map in an attempt to provide more quoting
2099 characters. If you see something like \\222 or \\264 where
2100 you're expecting some kind of apostrophe or quotation mark, then
2101 try this wash."
2102 (interactive)
2103 (article-translate-strings gnus-article-dumbquotes-map))
2105 (defvar org-entities)
2107 (defun article-treat-non-ascii ()
2108 "Translate many Unicode characters into their ASCII equivalents."
2109 (interactive)
2110 (require 'org-entities)
2111 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2112 (dolist (elem org-entities)
2113 (when (and (listp elem)
2114 (= (length (nth 6 elem)) 1))
2115 (if (featurep 'xemacs)
2116 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2117 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t)
2121 replace props)
2122 (while (not (eobp))
2123 (if (not (setq replace (if (featurep 'xemacs)
2124 (get-char-table (following-char) table)
2125 (aref table (following-char)))))
2126 (forward-char 1)
2127 (if (prog1
2128 (setq props (text-properties-at (point)))
2129 (delete-char 1))
2130 (add-text-properties (point) (progn (insert replace) (point))
2131 props)
2132 (insert replace)))))))))
2134 (defun article-translate-strings (map)
2135 "Translate all string in the body of the article according to MAP.
2136 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2137 (save-excursion
2138 (when (article-goto-body)
2139 (let ((inhibit-read-only t))
2140 (dolist (elem map)
2141 (let ((from (car elem))
2142 (to (cadr elem)))
2143 (save-excursion
2144 (if (stringp from)
2145 (while (search-forward from nil t)
2146 (replace-match to))
2147 (while (not (eobp))
2148 (if (eq (following-char) from)
2149 (progn
2150 (delete-char 1)
2151 (insert to))
2152 (forward-char 1)))))))))))
2154 (defun article-treat-overstrike ()
2155 "Translate overstrikes into bold text."
2156 (interactive)
2157 (save-excursion
2158 (when (article-goto-body)
2159 (let ((inhibit-read-only t))
2160 (while (search-forward "\b" nil t)
2161 (let ((next (char-after))
2162 (previous (char-after (- (point) 2))))
2163 ;; We do the boldification/underlining by hiding the
2164 ;; overstrikes and putting the proper text property
2165 ;; on the letters.
2166 (cond
2167 ((eq next previous)
2168 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2169 (put-text-property (point) (1+ (point)) 'face 'bold))
2170 ((eq next ?_)
2171 (gnus-article-hide-text-type
2172 (1- (point)) (1+ (point)) 'overstrike)
2173 (put-text-property
2174 (- (point) 2) (1- (point)) 'face 'underline))
2175 ((eq previous ?_)
2176 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2177 (put-text-property
2178 (point) (1+ (point)) 'face 'underline)))))))))
2180 (defun article-treat-ansi-sequences ()
2181 "Translate ANSI SGR control sequences into overlays or extents."
2182 (interactive)
2183 (save-excursion
2184 (when (article-goto-body)
2185 (let ((inhibit-read-only t))
2186 (ansi-color-apply-on-region (point) (point-max))))))
2188 (defun gnus-article-treat-unfold-headers ()
2189 "Unfold folded message headers.
2190 Only the headers that fit into the current window width will be
2191 unfolded."
2192 (interactive)
2193 (gnus-with-article-headers
2194 (let (length)
2195 (while (not (eobp))
2196 (save-restriction
2197 (mail-header-narrow-to-field)
2198 (let* ((header (buffer-string))
2199 (unfoldable
2200 (or (equal gnus-article-unfold-long-headers t)
2201 (and (stringp gnus-article-unfold-long-headers)
2202 (string-match gnus-article-unfold-long-headers
2203 header)))))
2204 (with-temp-buffer
2205 (insert header)
2206 (goto-char (point-min))
2207 (while (re-search-forward "\n[\t ]" nil t)
2208 (replace-match " " t t)))
2209 (setq length (- (point-max) (point-min) 1))
2210 (when (or unfoldable
2211 (< length (window-width)))
2212 (while (re-search-forward "\n[\t ]" nil t)
2213 (replace-match " " t t))))
2214 (goto-char (point-max)))))))
2216 (defun gnus-article-treat-fold-headers ()
2217 "Fold message headers."
2218 (interactive)
2219 (gnus-with-article-headers
2220 (while (not (eobp))
2221 (save-restriction
2222 (mail-header-narrow-to-field)
2223 (mail-header-fold-field)
2224 (goto-char (point-max))))))
2226 (defun gnus-treat-smiley ()
2227 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2228 (interactive)
2229 (gnus-with-article-buffer
2230 (if (memq 'smiley gnus-article-wash-types)
2231 (gnus-delete-images 'smiley)
2232 (article-goto-body)
2233 (let ((images (smiley-region (point) (point-max))))
2234 (when images
2235 (gnus-add-wash-type 'smiley)
2236 (dolist (image images)
2237 (gnus-add-image 'smiley image)))))))
2239 (defun gnus-article-remove-images ()
2240 "Remove all images from the article buffer."
2241 (interactive)
2242 (gnus-with-article-buffer
2243 (save-restriction
2244 (widen)
2245 (dolist (elem gnus-article-image-alist)
2246 (gnus-delete-images (car elem))))))
2248 (autoload 'w3m-toggle-inline-images "w3m")
2250 (defun gnus-article-show-images ()
2251 "Show any images that are in the HTML-rendered article buffer.
2252 This only works if the article in question is HTML."
2253 (interactive)
2254 (gnus-with-article-buffer
2255 (save-restriction
2256 (widen)
2257 (if (eq mm-text-html-renderer 'w3m)
2258 (let ((mm-inline-text-html-with-images nil))
2259 (w3m-toggle-inline-images))
2260 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2261 'image-displayer))
2262 (destructuring-bind (start end function) region
2263 (funcall function (get-text-property start 'image-url)
2264 start end)))))))
2266 (defun gnus-article-treat-fold-newsgroups ()
2267 "Unfold folded message headers.
2268 Only the headers that fit into the current window width will be
2269 unfolded."
2270 (interactive)
2271 (gnus-with-article-headers
2272 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2273 (save-restriction
2274 (mail-header-narrow-to-field)
2275 (while (re-search-forward ", *" nil t)
2276 (replace-match ", " t t))
2277 (mail-header-fold-field)
2278 (goto-char (point-max))))))
2280 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2281 "Value of `truncate-lines' in Gnus Article buffer.
2282 Valid values are nil, t, `head', `first', `last', an integer or a
2283 predicate. See Info node `(gnus)Customizing Articles'."
2284 :version "23.1" ;; No Gnus
2285 :group 'gnus-article
2286 ;; :link '(custom-manual "(gnus)Customizing Articles")
2287 :type 'boolean)
2289 (defun gnus-article-toggle-truncate-lines (&optional arg)
2290 "Toggle whether to fold or truncate long lines in article the buffer.
2291 If ARG is non-nil and not a number, toggle
2292 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2293 long lines if and only if arg is positive."
2294 (interactive "P")
2295 (cond
2296 ((and (numberp arg) (> arg 0))
2297 (setq gnus-article-truncate-lines t))
2298 ((numberp arg)
2299 (setq gnus-article-truncate-lines nil))
2300 (arg
2301 (setq gnus-article-truncate-lines
2302 (not gnus-article-truncate-lines))))
2303 (gnus-with-article-buffer
2304 (cond
2305 ((and (numberp arg) (> arg 0))
2306 (setq truncate-lines nil))
2307 ((numberp arg)
2308 (setq truncate-lines t)))
2309 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2310 ;; `toggle-truncate-lines' needs an argument.
2311 (toggle-truncate-lines)))
2313 (defun gnus-article-treat-body-boundary ()
2314 "Place a boundary line at the end of the headers."
2315 (interactive)
2316 (when (and gnus-body-boundary-delimiter
2317 (> (length gnus-body-boundary-delimiter) 0))
2318 (gnus-with-article-headers
2319 (goto-char (point-max))
2320 (let ((start (point)))
2321 (insert "X-Boundary: ")
2322 (gnus-add-text-properties start (point) '(invisible t intangible t))
2323 (insert (let (str (max (window-width)))
2324 (if (featurep 'xemacs)
2325 (setq max (1- max)))
2326 (while (>= max (length str))
2327 (setq str (concat str gnus-body-boundary-delimiter)))
2328 (substring str 0 max))
2329 "\n")
2330 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2332 (defun article-fill-long-lines ()
2333 "Fill lines that are wider than the window width."
2334 (interactive)
2335 (save-excursion
2336 (let ((inhibit-read-only t)
2337 (width (window-width (get-buffer-window (current-buffer)))))
2338 (save-restriction
2339 (article-goto-body)
2340 (let ((adaptive-fill-mode nil)) ;Why? -sm
2341 (while (not (eobp))
2342 (end-of-line)
2343 (when (>= (current-column) (min fill-column width))
2344 (narrow-to-region (min (1+ (point)) (point-max))
2345 (point-at-bol))
2346 (let ((goback (point-marker)))
2347 (fill-paragraph nil)
2348 (goto-char (marker-position goback)))
2349 (widen))
2350 (forward-line 1)))))))
2352 (defun article-capitalize-sentences ()
2353 "Capitalize the first word in each sentence."
2354 (interactive)
2355 (save-excursion
2356 (let ((inhibit-read-only t)
2357 (paragraph-start "^[\n\^L]"))
2358 (article-goto-body)
2359 (while (not (eobp))
2360 (capitalize-word 1)
2361 (forward-sentence)))))
2363 (defun article-remove-cr ()
2364 "Remove trailing CRs and then translate remaining CRs into LFs."
2365 (interactive)
2366 (save-excursion
2367 (let ((inhibit-read-only t))
2368 (goto-char (point-min))
2369 (while (re-search-forward "\r+$" nil t)
2370 (replace-match "" t t))
2371 (goto-char (point-min))
2372 (while (search-forward "\r" nil t)
2373 (replace-match "\n" t t)))))
2375 (defun article-remove-trailing-blank-lines ()
2376 "Remove all trailing blank lines from the article."
2377 (interactive)
2378 (save-excursion
2379 (let ((inhibit-read-only t))
2380 (goto-char (point-max))
2381 (delete-region
2382 (point)
2383 (progn
2384 (while (and (not (bobp))
2385 (looking-at "^[ \t]*$")
2386 (not (gnus-annotation-in-region-p
2387 (point) (point-at-eol))))
2388 (forward-line -1))
2389 (forward-line 1)
2390 (point))))))
2392 (defvar gnus-face-properties-alist)
2394 (defun article-display-face (&optional force)
2395 "Display any Face headers in the header."
2396 (interactive (list 'force))
2397 (let ((wash-face-p buffer-read-only))
2398 (gnus-with-article-headers
2399 ;; When displaying parts, this function can be called several times on
2400 ;; the same article, without any intended toggle semantic (as typing `W
2401 ;; D d' would have). So face deletion must occur only when we come from
2402 ;; an interactive command, that is when the *Article* buffer is
2403 ;; read-only.
2404 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2405 (gnus-delete-images 'face)
2406 (let ((from (message-fetch-field "from"))
2407 face faces)
2408 (save-current-buffer
2409 (when (and wash-face-p
2410 (gnus-buffer-live-p gnus-original-article-buffer)
2411 (not (re-search-forward "^Face:[\t ]*" nil t)))
2412 (set-buffer gnus-original-article-buffer))
2413 (save-restriction
2414 (mail-narrow-to-head)
2415 (when (or force
2416 ;; Check whether this face is censored.
2417 (not (and gnus-article-x-face-too-ugly
2418 (or from
2419 (setq from (message-fetch-field "from")))
2420 (string-match gnus-article-x-face-too-ugly
2421 from))))
2422 (while (gnus-article-goto-header "Face")
2423 (push (mail-header-field-value) faces)))))
2424 (when faces
2425 (goto-char (point-min))
2426 (let (png image)
2427 (unless (setq from (gnus-article-goto-header "from"))
2428 (insert "From:")
2429 (setq from (point))
2430 (insert " [no `from' set]\n"))
2431 (while faces
2432 (when (setq png (gnus-convert-face-to-png (pop faces)))
2433 (setq image
2434 (apply 'gnus-create-image png 'png t
2435 (cdr (assq 'png gnus-face-properties-alist))))
2436 (goto-char from)
2437 (when image
2438 (gnus-add-wash-type 'face)
2439 (gnus-add-image 'face image)
2440 (gnus-put-image image nil 'face)))))))))))
2442 (defun article-display-x-face (&optional force)
2443 "Look for an X-Face header and display it if present."
2444 (interactive (list 'force))
2445 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2446 (gnus-with-article-headers
2447 ;; Delete the old process, if any.
2448 (when (process-status "article-x-face")
2449 (delete-process "article-x-face"))
2450 ;; See the comment in `article-display-face'.
2451 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2452 ;; We have already displayed X-Faces, so we remove them
2453 ;; instead.
2454 (gnus-delete-images 'xface)
2455 ;; Display X-Faces.
2456 (let ((from (message-fetch-field "from"))
2457 x-faces face)
2458 (save-current-buffer
2459 (when (and wash-face-p
2460 (gnus-buffer-live-p gnus-original-article-buffer)
2461 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2462 ;; If type `W f', use gnus-original-article-buffer,
2463 ;; otherwise use the current buffer because displaying
2464 ;; RFC822 parts calls this function too.
2465 (set-buffer gnus-original-article-buffer))
2466 (save-restriction
2467 (mail-narrow-to-head)
2468 (and gnus-article-x-face-command
2469 (or force
2470 ;; Check whether this face is censored.
2471 (not (and gnus-article-x-face-too-ugly
2472 (or from
2473 (setq from (message-fetch-field "from")))
2474 (string-match gnus-article-x-face-too-ugly
2475 from))))
2476 (while (gnus-article-goto-header "X-Face")
2477 (push (mail-header-field-value) x-faces)))))
2478 (when x-faces
2479 ;; We display the face.
2480 (cond ((functionp gnus-article-x-face-command)
2481 ;; The command is a lisp function, so we call it.
2482 (mapc gnus-article-x-face-command x-faces))
2483 ((stringp gnus-article-x-face-command)
2484 ;; The command is a string, so we interpret the command
2485 ;; as a, well, command, and fork it off.
2486 (let ((process-connection-type nil))
2487 (gnus-set-process-query-on-exit-flag
2488 (start-process
2489 "article-x-face" nil shell-file-name
2490 shell-command-switch gnus-article-x-face-command)
2491 nil)
2492 ;; Sending multiple EOFs to xv doesn't work,
2493 ;; so we only do a single external face.
2494 (with-temp-buffer
2495 (insert (car x-faces))
2496 (process-send-region "article-x-face"
2497 (point-min) (point-max)))
2498 (process-send-eof "article-x-face")))
2500 (error "`%s' set to `%s' is not a function"
2501 gnus-article-x-face-command
2502 'gnus-article-x-face-command)))))))))
2504 (defun article-decode-mime-words ()
2505 "Decode all MIME-encoded words in the article."
2506 (interactive)
2507 (gnus-with-article-buffer
2508 (let ((inhibit-point-motion-hooks t)
2509 (mail-parse-charset gnus-newsgroup-charset)
2510 (mail-parse-ignored-charsets
2511 (with-current-buffer gnus-summary-buffer
2512 gnus-newsgroup-ignored-charsets)))
2513 (mail-decode-encoded-word-region (point-min) (point-max)))))
2515 (defun article-decode-charset (&optional prompt)
2516 "Decode charset-encoded text in the article.
2517 If PROMPT (the prefix), prompt for a coding system to use."
2518 (interactive "P")
2519 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2520 (inhibit-read-only t)
2521 (mail-parse-charset gnus-newsgroup-charset)
2522 (mail-parse-ignored-charsets
2523 (save-excursion (condition-case nil
2524 (set-buffer gnus-summary-buffer)
2525 (error))
2526 gnus-newsgroup-ignored-charsets))
2527 ct cte ctl charset format)
2528 (save-excursion
2529 (save-restriction
2530 (article-narrow-to-head)
2531 (setq ct (message-fetch-field "Content-Type" t)
2532 cte (message-fetch-field "Content-Transfer-Encoding" t)
2533 ctl (and ct (mail-header-parse-content-type ct))
2534 charset (cond
2535 (prompt
2536 (mm-read-coding-system "Charset to decode: "))
2537 (ctl
2538 (mail-content-type-get ctl 'charset)))
2539 format (and ctl (mail-content-type-get ctl 'format)))
2540 (when cte
2541 (setq cte (mail-header-strip cte)))
2542 (if (and ctl (not (string-match "/" (car ctl))))
2543 (setq ctl nil))
2544 (goto-char (point-max)))
2545 (forward-line 1)
2546 (save-restriction
2547 (narrow-to-region (point) (point-max))
2548 (when (and (eq mail-parse-charset 'gnus-decoded)
2549 (eq (mm-body-7-or-8) '8bit))
2550 ;; The text code could have been decoded.
2551 (setq charset mail-parse-charset))
2552 (when (and (or (not ctl)
2553 (equal (car ctl) "text/plain"))
2554 (not format)) ;; article with format will decode later.
2555 (mm-decode-body
2556 charset (and cte (intern (downcase
2557 (gnus-strip-whitespace cte))))
2558 (car ctl)))))))
2560 (defun article-decode-encoded-words ()
2561 "Remove encoded-word encoding from headers."
2562 (let ((inhibit-point-motion-hooks t)
2563 (mail-parse-charset gnus-newsgroup-charset)
2564 (mail-parse-ignored-charsets
2565 (save-excursion (condition-case nil
2566 (set-buffer gnus-summary-buffer)
2567 (error))
2568 gnus-newsgroup-ignored-charsets))
2569 (inhibit-read-only t)
2570 end start)
2571 (goto-char (point-min))
2572 (when (search-forward "\n\n" nil 'move)
2573 (forward-line -1))
2574 (setq end (point))
2575 (while (not (bobp))
2576 (while (progn
2577 (forward-line -1)
2578 (and (not (bobp))
2579 (memq (char-after) '(?\t ? )))))
2580 (setq start (point))
2581 (if (looking-at "\
2582 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2583 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2584 (funcall gnus-decode-address-function start end)
2585 (funcall gnus-decode-header-function start end))
2586 (goto-char (setq end start)))))
2588 (defun article-decode-group-name ()
2589 "Decode group names in Newsgroups, Followup-To and Xref headers."
2590 (let ((inhibit-point-motion-hooks t)
2591 (inhibit-read-only t)
2592 (method (gnus-find-method-for-group gnus-newsgroup-name))
2593 regexp)
2594 (when (and (or gnus-group-name-charset-method-alist
2595 gnus-group-name-charset-group-alist)
2596 (gnus-buffer-live-p gnus-original-article-buffer))
2597 (save-restriction
2598 (article-narrow-to-head)
2599 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2600 (with-current-buffer gnus-original-article-buffer
2601 (goto-char (point-min)))
2602 (setq regexp (concat "^" header
2603 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2604 (while (re-search-forward regexp nil t)
2605 (replace-match (save-match-data
2606 (gnus-decode-newsgroups
2607 ;; XXX how to use data in article buffer?
2608 (with-current-buffer gnus-original-article-buffer
2609 (re-search-forward regexp nil t)
2610 (match-string 1))
2611 gnus-newsgroup-name method))
2612 t t nil 1))
2613 (goto-char (point-min)))))))
2615 (autoload 'idna-to-unicode "idna")
2617 (defun article-decode-idna-rhs ()
2618 "Decode IDNA strings in RHS in various headers in current buffer.
2619 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2620 Mail-Reply-To: and Mail-Followup-To:."
2621 (when gnus-use-idna
2622 (save-restriction
2623 (let ((inhibit-point-motion-hooks t)
2624 (inhibit-read-only t))
2625 (article-narrow-to-head)
2626 (goto-char (point-min))
2627 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2628 (let (ace unicode)
2629 (when (save-match-data
2630 (and (setq ace (match-string 1))
2631 (save-excursion
2632 (and (re-search-backward "^[^ \t]" nil t)
2633 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2634 (setq unicode (idna-to-unicode ace))))
2635 (unless (string= ace unicode)
2636 (replace-match unicode nil nil nil 1)))))))))
2638 (defun article-de-quoted-unreadable (&optional force read-charset)
2639 "Translate a quoted-printable-encoded article.
2640 If FORCE, decode the article whether it is marked as quoted-printable
2641 or not.
2642 If READ-CHARSET, ask for a coding system."
2643 (interactive (list 'force current-prefix-arg))
2644 (save-excursion
2645 (let ((inhibit-read-only t) type charset)
2646 (if (gnus-buffer-live-p gnus-original-article-buffer)
2647 (with-current-buffer gnus-original-article-buffer
2648 (setq type
2649 (gnus-fetch-field "content-transfer-encoding"))
2650 (let* ((ct (gnus-fetch-field "content-type"))
2651 (ctl (and ct (mail-header-parse-content-type ct))))
2652 (setq charset (and ctl
2653 (mail-content-type-get ctl 'charset)))
2654 (if (stringp charset)
2655 (setq charset (intern (downcase charset)))))))
2656 (if read-charset
2657 (setq charset (mm-read-coding-system "Charset: " charset)))
2658 (unless charset
2659 (setq charset gnus-newsgroup-charset))
2660 (when (or force
2661 (and type (let ((case-fold-search t))
2662 (string-match "quoted-printable" type))))
2663 (article-goto-body)
2664 (quoted-printable-decode-region
2665 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2667 (defun article-de-base64-unreadable (&optional force read-charset)
2668 "Translate a base64 article.
2669 If FORCE, decode the article whether it is marked as base64 not.
2670 If READ-CHARSET, ask for a coding system."
2671 (interactive (list 'force current-prefix-arg))
2672 (save-excursion
2673 (let ((inhibit-read-only t) type charset)
2674 (if (gnus-buffer-live-p gnus-original-article-buffer)
2675 (with-current-buffer gnus-original-article-buffer
2676 (setq type
2677 (gnus-fetch-field "content-transfer-encoding"))
2678 (let* ((ct (gnus-fetch-field "content-type"))
2679 (ctl (and ct (mail-header-parse-content-type ct))))
2680 (setq charset (and ctl
2681 (mail-content-type-get ctl 'charset)))
2682 (if (stringp charset)
2683 (setq charset (intern (downcase charset)))))))
2684 (if read-charset
2685 (setq charset (mm-read-coding-system "Charset: " charset)))
2686 (unless charset
2687 (setq charset gnus-newsgroup-charset))
2688 (when (or force
2689 (and type (let ((case-fold-search t))
2690 (string-match "base64" type))))
2691 (article-goto-body)
2692 (save-restriction
2693 (narrow-to-region (point) (point-max))
2694 (base64-decode-region (point-min) (point-max))
2695 (mm-decode-coding-region
2696 (point-min) (point-max)
2697 (mm-charset-to-coding-system charset nil t)))))))
2699 (eval-when-compile
2700 (require 'rfc1843))
2702 (defun article-decode-HZ ()
2703 "Translate a HZ-encoded article."
2704 (interactive)
2705 (require 'rfc1843)
2706 (save-excursion
2707 (let ((inhibit-read-only t))
2708 (rfc1843-decode-region (point-min) (point-max)))))
2710 (defun article-unsplit-urls ()
2711 "Remove the newlines that some other mailers insert into URLs."
2712 (interactive)
2713 (save-excursion
2714 (let ((inhibit-read-only t))
2715 (goto-char (point-min))
2716 (while (re-search-forward
2717 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2718 (replace-match "\\1\\3" t)))
2719 (when (gmm-called-interactively-p 'any)
2720 (gnus-treat-article nil))))
2722 (defun article-wash-html ()
2723 "Format an HTML article."
2724 (interactive)
2725 (let ((handles nil)
2726 (buffer-read-only nil))
2727 (when (gnus-buffer-live-p gnus-original-article-buffer)
2728 (with-current-buffer gnus-original-article-buffer
2729 (setq handles (mm-dissect-buffer t t))))
2730 (article-goto-body)
2731 (delete-region (point) (point-max))
2732 (mm-enable-multibyte)
2733 (mm-inline-text-html handles)))
2735 (defvar gnus-article-browse-html-temp-list nil
2736 "List of temporary files created by `gnus-article-browse-html-parts'.
2737 Internal variable.")
2739 (defcustom gnus-article-browse-delete-temp 'ask
2740 "What to do with temporary files from `gnus-article-browse-html-parts'.
2741 If nil, don't delete temporary files. If it is t, delete them on
2742 exit from the summary buffer. If it is the symbol `file', query
2743 on each file, if it is `ask' ask once when exiting from the
2744 summary buffer."
2745 :group 'gnus-article
2746 :version "23.1" ;; No Gnus
2747 :type '(choice (const :tag "Don't delete" nil)
2748 (const :tag "Don't ask" t)
2749 (const :tag "Ask" ask)
2750 (const :tag "Ask for each file" file)))
2752 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2754 (defun gnus-article-browse-delete-temp-files (&optional how)
2755 "Delete temp-files created by `gnus-article-browse-html-parts'."
2756 (when (and gnus-article-browse-html-temp-list
2757 (progn
2758 (or how (setq how gnus-article-browse-delete-temp))
2759 (if (eq how 'ask)
2760 (let ((files (length gnus-article-browse-html-temp-list)))
2761 (or (gnus-y-or-n-p
2762 (if (= files 1)
2763 "Delete the temporary HTML file? "
2764 (format "Delete all %s temporary HTML files? "
2765 files)))
2766 (setq gnus-article-browse-html-temp-list nil)))
2767 how)))
2768 (dolist (file gnus-article-browse-html-temp-list)
2769 (cond ((file-directory-p file)
2770 (when (or (not (eq how 'file))
2771 (gnus-y-or-n-p
2772 (format
2773 "Delete temporary HTML file(s) in directory `%s'? "
2774 (file-name-as-directory file))))
2775 (gnus-delete-directory file)))
2776 ((file-exists-p file)
2777 (when (or (not (eq how 'file))
2778 (gnus-y-or-n-p
2779 (format "Delete temporary HTML file `%s'? " file)))
2780 (delete-file file)))))
2781 ;; Also remove file from the list when not deleted or if file doesn't
2782 ;; exist anymore.
2783 (setq gnus-article-browse-html-temp-list nil))
2784 gnus-article-browse-html-temp-list)
2786 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2787 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2788 Return file name."
2789 (save-match-data
2790 (let (file type)
2791 (catch 'found
2792 (dolist (handle handles)
2793 (cond
2794 ((not (listp handle)))
2795 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2796 ;; may create.
2797 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2798 ((equal (mm-handle-media-supertype handle) "multipart")
2799 (when (setq file (gnus-article-browse-html-save-cid-content
2800 cid handle directory))
2801 (throw 'found file)))
2802 ((equal (concat "<" cid ">") (mm-handle-id handle))
2803 (setq file
2804 (expand-file-name
2805 (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 directory))
2811 (mm-save-part-to-file handle file)
2812 (throw 'found file))))))))
2814 (defun gnus-article-browse-html-parts (list &optional header)
2815 "View all \"text/html\" parts from LIST.
2816 Recurse into multiparts. The optional HEADER that should be a decoded
2817 message header will be added to the bodies of the \"text/html\" parts."
2818 ;; Internal function used by `gnus-article-browse-html-article'.
2819 (let (type file charset content cid-dir tmp-file showed)
2820 ;; Find and show the html-parts.
2821 (dolist (handle list)
2822 ;; If HTML, show it:
2823 (cond ((not (listp handle)))
2824 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2825 (and (equal (car type) "message/external-body")
2826 (or header
2827 (setq file (mm-handle-filename handle)))
2828 (or (mm-handle-cache handle)
2829 (condition-case code
2830 (progn (mm-extern-cache-contents handle) t)
2831 (error
2832 (gnus-message 3 "%s" (error-message-string code))
2833 (when (>= gnus-verbose 3) (sit-for 2))
2834 nil)))
2835 (progn
2836 (setq handle (mm-handle-cache handle)
2837 type (mm-handle-type handle))
2838 (equal (car type) "text/html"))))
2839 (setq charset (mail-content-type-get type 'charset)
2840 content (mm-get-part handle))
2841 (with-temp-buffer
2842 (if (eq charset 'gnus-decoded)
2843 (mm-enable-multibyte)
2844 (mm-disable-multibyte))
2845 (insert content)
2846 ;; resolve cid contents
2847 (let ((case-fold-search t)
2848 cid-file)
2849 (goto-char (point-min))
2850 (while (re-search-forward "\
2851 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2852 nil t)
2853 (unless cid-dir
2854 (setq cid-dir (mm-make-temp-file "cid" t))
2855 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2856 (setq file nil
2857 content nil)
2858 (when (setq cid-file
2859 (gnus-article-browse-html-save-cid-content
2860 (match-string 2)
2861 (with-current-buffer gnus-article-buffer
2862 gnus-article-mime-handles)
2863 cid-dir))
2864 (when (eq system-type 'cygwin)
2865 (setq cid-file
2866 (concat "/" (substring
2867 (with-output-to-string
2868 (call-process "cygpath" nil
2869 standard-output
2870 nil "-m" cid-file))
2871 0 -1))))
2872 (replace-match (concat "file://" cid-file)
2873 nil nil nil 1))))
2874 (unless content (setq content (buffer-string))))
2875 (when (or charset header (not file))
2876 (setq tmp-file (mm-make-temp-file
2877 ;; Do we need to care for 8.3 filenames?
2878 "mm-" nil ".html")))
2879 ;; Add a meta html tag to specify charset and a header.
2880 (cond
2881 (header
2882 (let (title eheader body hcharset coding)
2883 (with-temp-buffer
2884 (mm-enable-multibyte)
2885 (setq case-fold-search t)
2886 (insert header "\n")
2887 (setq title (message-fetch-field "subject"))
2888 (goto-char (point-min))
2889 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2890 nil t)
2891 (replace-match (cond ((match-beginning 1) "&lt;")
2892 ((match-beginning 2) "&gt;")
2893 ((match-beginning 3) "&amp;")
2894 (t "<br>\n"))))
2895 (goto-char (point-min))
2896 (while (re-search-forward "^[\t ]+" nil t)
2897 (dotimes (i (prog1
2898 (current-column)
2899 (delete-region (match-beginning 0)
2900 (match-end 0))))
2901 (insert "&nbsp;")))
2902 (goto-char (point-min))
2903 (insert "<div align=\"left\">\n")
2904 (goto-char (point-max))
2905 (insert "</div>\n<hr>\n")
2906 ;; We have to examine charset one by one since
2907 ;; charset specified in parts might be different.
2908 (if (eq charset 'gnus-decoded)
2909 (setq charset 'utf-8
2910 eheader (mm-encode-coding-string (buffer-string)
2911 charset)
2912 title (when title
2913 (mm-encode-coding-string title charset))
2914 body (mm-encode-coding-string content charset))
2915 (setq hcharset (mm-find-mime-charset-region (point-min)
2916 (point-max)))
2917 (cond ((= (length hcharset) 1)
2918 (setq hcharset (car hcharset)
2919 coding (mm-charset-to-coding-system
2920 hcharset nil t)))
2921 ((> (length hcharset) 1)
2922 (setq hcharset 'utf-8
2923 coding hcharset)))
2924 (if coding
2925 (if charset
2926 (progn
2927 (setq body
2928 (mm-charset-to-coding-system charset
2929 nil t))
2930 (if (eq coding body)
2931 (setq eheader (mm-encode-coding-string
2932 (buffer-string) coding)
2933 title (when title
2934 (mm-encode-coding-string
2935 title coding))
2936 body content)
2937 (setq charset 'utf-8
2938 eheader (mm-encode-coding-string
2939 (buffer-string) charset)
2940 title (when title
2941 (mm-encode-coding-string
2942 title charset))
2943 body (mm-encode-coding-string
2944 (mm-decode-coding-string
2945 content body)
2946 charset))))
2947 (setq charset hcharset
2948 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 eheader (mm-string-as-unibyte (buffer-string))
2955 body content)))
2956 (erase-buffer)
2957 (mm-disable-multibyte)
2958 (insert body)
2959 (when charset
2960 (mm-add-meta-html-tag handle charset t))
2961 (when title
2962 (goto-char (point-min))
2963 (unless (search-forward "<title>" nil t)
2964 (re-search-forward "<head>\\s-*" nil t)
2965 (insert "<title>" title "</title>\n")))
2966 (goto-char (point-min))
2967 (or (re-search-forward
2968 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2969 (re-search-forward
2970 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2971 (insert eheader)
2972 (mm-write-region (point-min) (point-max)
2973 tmp-file nil nil nil 'binary t))))
2974 (charset
2975 (mm-with-unibyte-buffer
2976 (insert (if (eq charset 'gnus-decoded)
2977 (mm-encode-coding-string content
2978 (setq charset 'utf-8))
2979 content))
2980 (if (or (mm-add-meta-html-tag handle charset)
2981 (not file))
2982 (mm-write-region (point-min) (point-max)
2983 tmp-file nil nil nil 'binary t)
2984 (setq tmp-file nil))))
2985 (tmp-file
2986 (mm-save-part-to-file handle tmp-file)))
2987 (when tmp-file
2988 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2989 (add-hook 'gnus-summary-prepare-exit-hook
2990 'gnus-article-browse-delete-temp-files)
2991 (add-hook 'gnus-exit-gnus-hook
2992 (lambda ()
2993 (gnus-article-browse-delete-temp-files t)))
2994 ;; FIXME: Warn if there's an <img> tag?
2995 (browse-url-of-file (or tmp-file (expand-file-name file)))
2996 (setq showed t))
2997 ;; If multipart, recurse
2998 ((equal (mm-handle-media-supertype handle) "multipart")
2999 (when (gnus-article-browse-html-parts handle header)
3000 (setq showed t)))
3001 ((equal (mm-handle-media-type handle) "message/rfc822")
3002 (mm-with-multibyte-buffer
3003 (mm-insert-part handle)
3004 (setq handle (mm-dissect-buffer t t))
3005 (when (and (bufferp (car handle))
3006 (stringp (car (mm-handle-type handle))))
3007 (setq handle (list handle)))
3008 (when header
3009 (article-decode-encoded-words)
3010 (let ((gnus-visible-headers
3011 (or (get 'gnus-visible-headers 'standard-value)
3012 gnus-visible-headers)))
3013 (article-hide-headers))
3014 (goto-char (point-min))
3015 (search-forward "\n\n" nil 'move)
3016 (skip-chars-backward "\t\n ")
3017 (setq header (buffer-substring (point-min) (point)))))
3018 (when (prog1
3019 (gnus-article-browse-html-parts handle header)
3020 (mm-destroy-parts handle))
3021 (setq showed t)))))
3022 showed))
3024 (defun gnus-article-browse-html-article (&optional arg)
3025 "View \"text/html\" parts of the current article with a WWW browser.
3026 Inline images embedded in a message using the cid scheme, as they are
3027 generally considered to be safe, will be processed properly.
3028 The message header is added to the beginning of every html part unless
3029 the prefix argument ARG is given.
3031 Warning: Spammers use links to images (using the http scheme) in HTML
3032 articles to verify whether you have read the message. As
3033 `gnus-article-browse-html-article' passes the HTML content to the
3034 browser without eliminating these \"web bugs\" you should only
3035 use it for mails from trusted senders.
3037 If you always want to display HTML parts in the browser, set
3038 `mm-text-html-renderer' to nil.
3040 This command creates temporary files to pass HTML contents including
3041 images if any to the browser, and deletes them when exiting the group
3042 \(if you want)."
3043 ;; Cf. `mm-w3m-safe-url-regexp'
3044 (interactive "P")
3045 (if arg
3046 (gnus-summary-show-article)
3047 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3048 gnus-visible-headers))
3049 ;; As we insert a <hr>, there's no need for the body boundary.
3050 (gnus-treat-body-boundary nil))
3051 (gnus-summary-show-article)))
3052 (with-current-buffer gnus-article-buffer
3053 (let ((header (unless arg
3054 (save-restriction
3055 (widen)
3056 (buffer-substring-no-properties
3057 (goto-char (point-min))
3058 (if (search-forward "\n\n" nil t)
3059 (match-beginning 0)
3060 (goto-char (point-max))
3061 (skip-chars-backward "\t\n ")
3062 (point))))))
3063 parts)
3064 (set-buffer gnus-original-article-buffer)
3065 (setq parts (mm-dissect-buffer t t))
3066 ;; If singlepart, enforce a list.
3067 (when (and (bufferp (car parts))
3068 (stringp (car (mm-handle-type parts))))
3069 (setq parts (list parts)))
3070 ;; Process the list
3071 (unless (gnus-article-browse-html-parts parts header)
3072 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3073 (mm-destroy-parts parts)
3074 (unless arg
3075 (gnus-summary-show-article)))))
3077 (defun article-hide-list-identifiers ()
3078 "Remove list identifies from the Subject header.
3079 The `gnus-list-identifiers' variable specifies what to do."
3080 (interactive)
3081 (let ((inhibit-point-motion-hooks t)
3082 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3083 (inhibit-read-only t))
3084 (when regexp
3085 (save-excursion
3086 (save-restriction
3087 (article-narrow-to-head)
3088 (goto-char (point-min))
3089 (while (re-search-forward
3090 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3091 nil t)
3092 (delete-region (match-beginning 2) (match-end 0))
3093 (beginning-of-line))
3094 (when (re-search-forward
3095 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3096 (delete-region (match-beginning 1) (match-end 1))))))))
3098 (defun article-hide-pem (&optional arg)
3099 "Toggle hiding of any PEM headers and signatures in the current article.
3100 If given a negative prefix, always show; if given a positive prefix,
3101 always hide."
3102 (interactive (gnus-article-hidden-arg))
3103 (unless (gnus-article-check-hidden-text 'pem arg)
3104 (save-excursion
3105 (let ((inhibit-read-only t) end)
3106 (goto-char (point-min))
3107 ;; Hide the horrendously ugly "header".
3108 (when (and (search-forward
3109 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3110 nil t)
3111 (setq end (1+ (match-beginning 0))))
3112 (gnus-add-wash-type 'pem)
3113 (gnus-article-hide-text-type
3115 (if (search-forward "\n\n" nil t)
3116 (match-end 0)
3117 (point-max))
3118 'pem)
3119 ;; Hide the trailer as well
3120 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3121 nil t)
3122 (gnus-article-hide-text-type
3123 (match-beginning 0) (match-end 0) 'pem)))))))
3125 (defun article-strip-banner ()
3126 "Strip the banners specified by the `banner' group parameter and by
3127 `gnus-article-address-banner-alist'."
3128 (interactive)
3129 (save-excursion
3130 (save-restriction
3131 (let ((inhibit-point-motion-hooks t))
3132 (when (gnus-parameter-banner gnus-newsgroup-name)
3133 (article-really-strip-banner
3134 (gnus-parameter-banner gnus-newsgroup-name)))
3135 (when gnus-article-address-banner-alist
3136 ;; Note that the From header is decoded here, so it is
3137 ;; required that the *-extract-address-components function
3138 ;; supports non-ASCII text.
3139 (let ((from (save-restriction
3140 (widen)
3141 (article-narrow-to-head)
3142 (mail-fetch-field "from"))))
3143 (when (and from
3144 (setq from
3145 (cadr (funcall gnus-extract-address-components
3146 from))))
3147 (catch 'found
3148 (dolist (pair gnus-article-address-banner-alist)
3149 (when (string-match (car pair) from)
3150 (throw 'found
3151 (article-really-strip-banner (cdr pair)))))))))))))
3153 (defun article-really-strip-banner (banner)
3154 "Strip the banner specified by the argument."
3155 (save-excursion
3156 (save-restriction
3157 (let ((inhibit-point-motion-hooks t)
3158 (gnus-signature-limit nil)
3159 (inhibit-read-only t))
3160 (article-goto-body)
3161 (cond
3162 ((eq banner 'signature)
3163 (when (gnus-article-narrow-to-signature)
3164 (widen)
3165 (forward-line -1)
3166 (delete-region (point) (point-max))))
3167 ((symbolp banner)
3168 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3169 (while (re-search-forward banner nil t)
3170 (delete-region (match-beginning 0) (match-end 0)))))
3171 ((stringp banner)
3172 (while (re-search-forward banner nil t)
3173 (delete-region (match-beginning 0) (match-end 0)))))))))
3175 (defun article-babel ()
3176 "Translate article using an online translation service."
3177 (interactive)
3178 (require 'babel)
3179 (gnus-with-article-buffer
3180 (when (article-goto-body)
3181 (let* ((start (point))
3182 (end (point-max))
3183 (orig (buffer-substring start end))
3184 (trans (babel-as-string orig)))
3185 (save-restriction
3186 (narrow-to-region start end)
3187 (delete-region start end)
3188 (insert trans))))))
3190 (defun article-hide-signature (&optional arg)
3191 "Hide the signature in the current article.
3192 If given a negative prefix, always show; if given a positive prefix,
3193 always hide."
3194 (interactive (gnus-article-hidden-arg))
3195 (unless (gnus-article-check-hidden-text 'signature arg)
3196 (save-excursion
3197 (save-restriction
3198 (let ((inhibit-read-only t))
3199 (when (gnus-article-narrow-to-signature)
3200 (gnus-article-hide-text-type
3201 (point-min) (point-max) 'signature))))))
3202 (gnus-set-mode-line 'article))
3204 (defun article-strip-headers-in-body ()
3205 "Strip offensive headers from bodies."
3206 (interactive)
3207 (save-excursion
3208 (article-goto-body)
3209 (let ((case-fold-search t))
3210 (when (looking-at "x-no-archive:")
3211 (gnus-delete-line)))))
3213 (defun article-strip-leading-blank-lines ()
3214 "Remove all blank lines from the beginning of the article."
3215 (interactive)
3216 (save-excursion
3217 (let ((inhibit-point-motion-hooks t)
3218 (inhibit-read-only t))
3219 (when (article-goto-body)
3220 (while (and (not (eobp))
3221 (looking-at "[ \t]*$"))
3222 (gnus-delete-line))))))
3224 (defun article-narrow-to-head ()
3225 "Narrow the buffer to the head of the message.
3226 Point is left at the beginning of the narrowed-to region."
3227 (narrow-to-region
3228 (goto-char (point-min))
3229 (cond
3230 ;; Absolutely no headers displayed.
3231 ((looking-at "\n")
3232 (point))
3233 ;; Normal headers.
3234 ((search-forward "\n\n" nil 1)
3235 (1- (point)))
3236 ;; Nothing but headers.
3238 (point-max))))
3239 (goto-char (point-min)))
3241 (defun article-goto-body ()
3242 "Place point at the start of the body."
3243 (goto-char (point-min))
3244 (cond
3245 ;; This variable is only bound when dealing with separate
3246 ;; MIME body parts.
3247 (article-goto-body-goes-to-point-min-p
3249 ((search-forward "\n\n" nil t)
3252 (goto-char (point-max))
3253 nil)))
3255 (defun article-strip-multiple-blank-lines ()
3256 "Replace consecutive blank lines with one empty line."
3257 (interactive)
3258 (save-excursion
3259 (let ((inhibit-point-motion-hooks t)
3260 (inhibit-read-only t))
3261 ;; First make all blank lines empty.
3262 (article-goto-body)
3263 (while (re-search-forward "^[ \t]+$" nil t)
3264 (unless (gnus-annotation-in-region-p
3265 (match-beginning 0) (match-end 0))
3266 (replace-match "" nil t)))
3267 ;; Then replace multiple empty lines with a single empty line.
3268 (article-goto-body)
3269 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3270 (unless (gnus-annotation-in-region-p
3271 (match-beginning 0) (match-end 0))
3272 (delete-region (match-beginning 1) (match-end 1)))))))
3274 (defun article-strip-leading-space ()
3275 "Remove all white space from the beginning of the lines in the article."
3276 (interactive)
3277 (save-excursion
3278 (let ((inhibit-point-motion-hooks t)
3279 (inhibit-read-only t))
3280 (article-goto-body)
3281 (while (re-search-forward "^[ \t]+" nil t)
3282 (replace-match "" t t)))))
3284 (defun article-strip-trailing-space ()
3285 "Remove all white space from the end of the lines in the article."
3286 (interactive)
3287 (save-excursion
3288 (let ((inhibit-point-motion-hooks t)
3289 (inhibit-read-only t))
3290 (article-goto-body)
3291 (while (re-search-forward "[ \t]+$" nil t)
3292 (replace-match "" t t)))))
3294 (defun article-strip-blank-lines ()
3295 "Strip leading, trailing and multiple blank lines."
3296 (interactive)
3297 (article-strip-leading-blank-lines)
3298 (article-remove-trailing-blank-lines)
3299 (article-strip-multiple-blank-lines))
3301 (defun article-strip-all-blank-lines ()
3302 "Strip all blank lines."
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]*\n" nil t)
3309 (replace-match "" t t)))))
3311 (defun gnus-article-narrow-to-signature ()
3312 "Narrow to the signature; return t if a signature is found, else nil."
3313 (let ((inhibit-point-motion-hooks t))
3314 (when (gnus-article-search-signature)
3315 (forward-line 1)
3316 ;; Check whether we have some limits to what we consider
3317 ;; to be a signature.
3318 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3319 (list gnus-signature-limit)))
3320 limit limited)
3321 (while (setq limit (pop limits))
3322 (if (or (and (integerp limit)
3323 (< (- (point-max) (point)) limit))
3324 (and (floatp limit)
3325 (< (count-lines (point) (point-max)) limit))
3326 (and (functionp limit)
3327 (funcall limit))
3328 (and (stringp limit)
3329 (not (re-search-forward limit nil t))))
3330 () ; This limit did not succeed.
3331 (setq limited t
3332 limits nil)))
3333 (unless limited
3334 (narrow-to-region (point) (point-max))
3335 t)))))
3337 (defun gnus-article-search-signature ()
3338 "Search the current buffer for the signature separator.
3339 Put point at the beginning of the signature separator."
3340 (let ((cur (point)))
3341 (goto-char (point-max))
3342 (if (if (stringp gnus-signature-separator)
3343 (re-search-backward gnus-signature-separator nil t)
3344 (let ((seps gnus-signature-separator))
3345 (while (and seps
3346 (not (re-search-backward (car seps) nil t)))
3347 (pop seps))
3348 seps))
3350 (goto-char cur)
3351 nil)))
3353 (defun gnus-article-hidden-arg ()
3354 "Return the current prefix arg as a number, or 0 if no prefix."
3355 (list (if current-prefix-arg
3356 (prefix-numeric-value current-prefix-arg)
3357 0)))
3359 (defun gnus-article-check-hidden-text (type arg)
3360 "Return nil if hiding is necessary.
3361 Arg can be nil or a number. nil and positive means hide, negative
3362 means show, 0 means toggle."
3363 (save-excursion
3364 (save-restriction
3365 (let ((hide (gnus-article-hidden-text-p type)))
3366 (cond
3367 ((or (null arg)
3368 (> arg 0))
3369 nil)
3370 ((< arg 0)
3371 (gnus-article-show-hidden-text type)
3374 (if (eq hide 'hidden)
3375 (progn
3376 (gnus-article-show-hidden-text type)
3378 nil)))))))
3380 (defun gnus-article-hidden-text-p (type)
3381 "Say whether the current buffer contains hidden text of type TYPE."
3382 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3383 (while (and pos
3384 (not (get-text-property pos 'invisible))
3385 (not (get-text-property pos 'dummy-invisible)))
3386 (setq pos
3387 (text-property-any (1+ pos) (point-max) 'article-type type)))
3388 (if pos
3389 'hidden
3390 nil)))
3392 (defun gnus-article-show-hidden-text (type &optional dummy)
3393 "Show all hidden text of type TYPE.
3394 Originally it is hide instead of DUMMY."
3395 (let ((inhibit-read-only t)
3396 (inhibit-point-motion-hooks t))
3397 (gnus-remove-text-properties-when
3398 'article-type type
3399 (point-min) (point-max)
3400 (cons 'article-type (cons type
3401 gnus-hidden-properties)))
3402 (gnus-delete-wash-type type)))
3404 (defconst article-time-units
3405 `((year . ,(* 365.25 24 60 60))
3406 (week . ,(* 7 24 60 60))
3407 (day . ,(* 24 60 60))
3408 (hour . ,(* 60 60))
3409 (minute . 60)
3410 (second . 1))
3411 "Mapping from time units to seconds.")
3413 (defun gnus-article-forward-header ()
3414 "Move point to the start of the next header.
3415 If the current header is a continuation header, this can be several
3416 lines forward."
3417 (let ((ended nil))
3418 (while (not ended)
3419 (forward-line 1)
3420 (if (looking-at "[ \t]+[^ \t]")
3421 (forward-line 1)
3422 (setq ended t)))))
3424 (defun article-treat-date ()
3425 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3426 (with-current-buffer gnus-summary-buffer
3427 gnus-article-date-headers)
3428 gnus-article-date-headers)
3431 (defun article-date-ut (&optional type highlight date-position)
3432 "Convert DATE date to TYPE in the current article.
3433 The default type is `ut'. See `gnus-article-date-headers' for
3434 possible values."
3435 (interactive (list 'ut t))
3436 (let* ((case-fold-search t)
3437 (inhibit-read-only t)
3438 (inhibit-point-motion-hooks t)
3439 (first t)
3440 (visible-date (mail-fetch-field "Date"))
3441 pos date bface eface)
3442 (save-excursion
3443 (if date-position
3444 (progn
3445 (goto-char date-position)
3446 (setq date (get-text-property (point) 'original-date))
3447 (when (looking-at "[^:]+:[\t ]*")
3448 (setq bface (get-text-property (match-beginning 0) 'face)
3449 eface (get-text-property (match-end 0) 'face)))
3450 (delete-region (point)
3451 (progn
3452 (gnus-article-forward-header)
3453 (point)))
3454 (article-transform-date date type bface eface))
3455 (save-restriction
3456 (widen)
3457 (goto-char (point-min))
3458 (while (or (get-text-property (setq pos (point)) 'original-date)
3459 (and (setq pos (next-single-property-change
3460 (point) 'original-date))
3461 (goto-char pos)))
3462 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3463 (1+ (match-beginning 0))
3464 (point-max)))
3465 (while (setq pos (text-property-not-all pos (point-max)
3466 'gnus-date-type nil))
3467 (setq date (get-text-property pos 'original-date))
3468 (goto-char pos)
3469 (when (looking-at "[^:]+:[\t ]*")
3470 (setq bface (get-text-property (match-beginning 0) 'face)
3471 eface (get-text-property (match-end 0) 'face)))
3472 (delete-region pos (or (text-property-any pos (point-max)
3473 'gnus-date-type nil)
3474 (point-max))))
3475 (unless date ;; the 1st time
3476 (goto-char (point-min))
3477 (while (re-search-forward "^Date:[\t ]*" nil t)
3478 (setq date (get-text-property (match-beginning 0)
3479 'original-date)
3480 bface (get-text-property (match-beginning 0) 'face)
3481 eface (get-text-property (match-end 0) 'face))
3482 (delete-region (point-at-bol) (progn
3483 (gnus-article-forward-header)
3484 (point)))))
3485 (when (and (not date)
3486 visible-date)
3487 (setq date visible-date))
3488 (when date
3489 (article-transform-date date type bface eface))
3490 (goto-char (point-max))
3491 (widen)))))))
3493 (defun article-transform-date (date type bface eface)
3494 (dolist (this-type (cond
3495 ((null type)
3496 (list 'ut))
3497 ((atom type)
3498 (list type))
3500 type)))
3501 (goto-char
3502 (prog1
3503 (point)
3504 (add-text-properties
3505 (point)
3506 (progn
3507 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3508 (point))
3509 (list 'original-date date 'gnus-date-type this-type))))
3510 ;; Do highlighting.
3511 (when (looking-at
3512 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3513 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3514 (when (match-beginning 2)
3515 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3516 (while (and (zerop (forward-line 1))
3517 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3518 (when (match-beginning 1)
3519 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3521 (defun article-make-date-line (date type)
3522 "Return a DATE line of TYPE."
3523 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3524 combined-lapsed))
3525 (error "Unknown conversion type: %s" type))
3526 (condition-case ()
3527 (let ((time (ignore-errors (date-to-time date))))
3528 (cond
3529 ;; Convert to the local timezone.
3530 ((eq type 'local)
3531 (concat "Date: " (message-make-date time)))
3532 ;; Convert to Universal Time.
3533 ((eq type 'ut)
3534 (concat "Date: "
3535 (substring
3536 (message-make-date
3537 (let* ((e (parse-time-string date))
3538 (tm (apply 'encode-time e))
3539 (ms (car tm))
3540 (ls (- (cadr tm) (car (current-time-zone time)))))
3541 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3542 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3543 (t (list ms ls)))))
3544 0 -5)
3545 "UT"))
3546 ;; Get the original date from the article.
3547 ((eq type 'original)
3548 (concat "Date: " (if (string-match "\n+$" date)
3549 (substring date 0 (match-beginning 0))
3550 date)))
3551 ;; Let the user define the format.
3552 ((eq type 'user-defined)
3553 (let ((format (or (condition-case nil
3554 (with-current-buffer gnus-summary-buffer
3555 gnus-article-time-format)
3556 (error nil))
3557 gnus-article-time-format)))
3558 (if (functionp format)
3559 (funcall format time)
3560 (concat "Date: " (format-time-string format time)))))
3561 ;; ISO 8601.
3562 ((eq type 'iso8601)
3563 (let ((tz (car (current-time-zone time))))
3564 (concat
3565 "Date: "
3566 (format-time-string "%Y%m%dT%H%M%S" time)
3567 (format "%s%02d%02d"
3568 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3569 (/ (% (abs tz) 3600) 60)))))
3570 ;; Do a lapsed format.
3571 ((eq type 'lapsed)
3572 (concat "Date: " (article-lapsed-string time)))
3573 ;; A combined date/lapsed format.
3574 ((eq type 'combined-lapsed)
3575 (let ((date-string (article-make-date-line date 'original))
3576 (segments 3)
3577 lapsed-string)
3578 (while (and
3579 time
3580 (setq lapsed-string
3581 (concat " (" (article-lapsed-string time segments) ")"))
3582 (> (+ (length date-string)
3583 (length lapsed-string))
3584 (+ fill-column 6))
3585 (> segments 0))
3586 (setq segments (1- segments)))
3587 (if (> segments 0)
3588 (concat date-string lapsed-string)
3589 date-string)))
3590 ;; Display the date in proper English
3591 ((eq type 'english)
3592 (let ((dtime (decode-time time)))
3593 (concat
3594 "Date: the "
3595 (number-to-string (nth 3 dtime))
3596 (let ((digit (% (nth 3 dtime) 10)))
3597 (cond
3598 ((memq (nth 3 dtime) '(11 12 13)) "th")
3599 ((= digit 1) "st")
3600 ((= digit 2) "nd")
3601 ((= digit 3) "rd")
3602 (t "th")))
3603 " of "
3604 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3606 (number-to-string (nth 5 dtime))
3607 " at "
3608 (format "%02d" (nth 2 dtime))
3610 (format "%02d" (nth 1 dtime)))))))
3611 (foo
3612 (format "Date: %s (from Gnus)" date))))
3614 (defun article-lapsed-string (time &optional max-segments)
3615 ;; If the date is seriously mangled, the timezone functions are
3616 ;; liable to bug out, so we ignore all errors.
3617 (let* ((now (current-time))
3618 (real-time (subtract-time now time))
3619 (real-sec (and real-time
3620 (+ (* (float (car real-time)) 65536)
3621 (cadr real-time))))
3622 (sec (and real-time (abs real-sec)))
3623 (segments 0)
3624 num prev)
3625 (unless max-segments
3626 (setq max-segments (length article-time-units)))
3627 (cond
3628 ((null real-time)
3629 "Unknown")
3630 ((zerop sec)
3631 "Now")
3633 (concat
3634 ;; This is a bit convoluted, but basically we go
3635 ;; through the time units for years, weeks, etc,
3636 ;; and divide things to see whether that results
3637 ;; in positive answers.
3638 (mapconcat
3639 (lambda (unit)
3640 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3641 (>= segments max-segments))
3642 ;; The (remaining) seconds are too few to
3643 ;; be divided into this time unit.
3645 ;; It's big enough, so we output it.
3646 (setq sec (- sec (* num (cdr unit))))
3647 (prog1
3648 (concat (if prev ", " "") (int-to-string
3649 (floor num))
3650 " " (symbol-name (car unit))
3651 (if (> num 1) "s" ""))
3652 (setq prev t
3653 segments (1+ segments)))))
3654 article-time-units "")
3655 ;; If dates are odd, then it might appear like the
3656 ;; article was sent in the future.
3657 (if (> real-sec 0)
3658 " ago"
3659 " in the future"))))))
3661 (defun article-date-local (&optional highlight)
3662 "Convert the current article date to the local timezone."
3663 (interactive (list t))
3664 (article-date-ut 'local highlight))
3666 (defun article-date-english (&optional highlight)
3667 "Convert the current article date to something that is proper English."
3668 (interactive (list t))
3669 (article-date-ut 'english highlight))
3671 (defun article-date-original (&optional highlight)
3672 "Convert the current article date to what it was originally.
3673 This is only useful if you have used some other date conversion
3674 function and want to see what the date was before converting."
3675 (interactive (list t))
3676 (article-date-ut 'original highlight))
3678 (defun article-date-lapsed (&optional highlight)
3679 "Convert the current article date to time lapsed since it was sent."
3680 (interactive (list t))
3681 (article-date-ut 'lapsed highlight))
3683 (defun article-date-combined-lapsed (&optional highlight)
3684 "Convert the current article date to time lapsed since it was sent."
3685 (interactive (list t))
3686 (article-date-ut 'combined-lapsed highlight))
3688 (defun article-update-date-lapsed ()
3689 "Function to be run from a timer to update the lapsed time line."
3690 (save-match-data
3691 (let ((buffer (current-buffer)))
3692 (ignore-errors
3693 (walk-windows
3694 (lambda (w)
3695 (set-buffer (window-buffer w))
3696 (when (derived-mode-p 'gnus-article-mode)
3697 (let ((old-line (count-lines (point-min) (point)))
3698 (old-column (- (point) (line-beginning-position)))
3699 (window-start (window-start w))
3700 (pos (point-min))
3701 type next end)
3702 (while (setq pos (text-property-not-all pos (point-max)
3703 'gnus-date-type nil))
3704 (setq next (or (next-single-property-change pos
3705 'gnus-date-type)
3706 (point-max)))
3707 (setq type (get-text-property pos 'gnus-date-type))
3708 (when (memq type '(lapsed combined-lapsed user-defined))
3709 (article-date-ut type t pos)
3710 (setq end (or (next-single-property-change pos
3711 'gnus-date-type)
3712 (point-max)))
3713 (when window-start
3714 (if (/= window-start next)
3715 (setq window-start nil)
3716 (set-window-start w end)))
3717 (setq next end))
3718 (setq pos next))
3719 (goto-char (point-min))
3720 (when (> old-column 0)
3721 (setq old-line (1- old-line)))
3722 (forward-line old-line)
3723 (end-of-line)
3724 (when (> (current-column) old-column)
3725 (beginning-of-line)
3726 (forward-char old-column)))))
3727 nil 'visible))
3728 (set-buffer buffer))))
3730 (defun gnus-start-date-timer (&optional n)
3731 "Start a timer to update the Date headers in the article buffers.
3732 The numerical prefix says how frequently (in seconds) the function
3733 is to run."
3734 (interactive "p")
3735 (unless n
3736 (setq n 1))
3737 (gnus-stop-date-timer)
3738 (setq article-lapsed-timer
3739 (run-at-time 1 n 'article-update-date-lapsed)))
3741 (defun gnus-stop-date-timer ()
3742 "Stop the Date timer."
3743 (interactive)
3744 (when article-lapsed-timer
3745 (nnheader-cancel-timer article-lapsed-timer)
3746 (setq article-lapsed-timer nil)))
3748 (defun article-date-user (&optional highlight)
3749 "Convert the current article date to the user-defined format.
3750 This format is defined by the `gnus-article-time-format' variable."
3751 (interactive (list t))
3752 (article-date-ut 'user highlight))
3754 (defun article-date-iso8601 (&optional highlight)
3755 "Convert the current article date to ISO8601."
3756 (interactive (list t))
3757 (article-date-ut 'iso8601 highlight))
3759 (defmacro gnus-article-save-original-date (&rest forms)
3760 "Save the original date as a text property and evaluate FORMS."
3761 `(let* ((case-fold-search t)
3762 (start (progn
3763 (goto-char (point-min))
3764 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3765 (not (bolp)))
3766 (match-end 0))))
3767 (date (when (and start
3768 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3769 nil t))
3770 (buffer-substring-no-properties start
3771 (match-beginning 0)))))
3772 (goto-char (point-max))
3773 (skip-chars-backward "\n")
3774 (put-text-property (point-min) (point) 'original-date date)
3775 ,@forms
3776 (goto-char (point-max))
3777 (skip-chars-backward "\n")
3778 (put-text-property (point-min) (point) 'original-date date)))
3780 ;; (defun article-show-all ()
3781 ;; "Show all hidden text in the article buffer."
3782 ;; (interactive)
3783 ;; (save-excursion
3784 ;; (let ((inhibit-read-only t))
3785 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3787 (defun article-remove-leading-whitespace ()
3788 "Remove excessive whitespace from all headers."
3789 (interactive)
3790 (save-excursion
3791 (save-restriction
3792 (let ((inhibit-read-only t))
3793 (article-narrow-to-head)
3794 (goto-char (point-min))
3795 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3796 (delete-region (match-beginning 1) (match-end 1)))))))
3798 (defun article-emphasize (&optional arg)
3799 "Emphasize text according to `gnus-emphasis-alist'."
3800 (interactive (gnus-article-hidden-arg))
3801 (unless (gnus-article-check-hidden-text 'emphasis arg)
3802 (save-excursion
3803 (let ((alist (or
3804 (condition-case nil
3805 (with-current-buffer gnus-summary-buffer
3806 gnus-article-emphasis-alist)
3807 (error))
3808 gnus-emphasis-alist))
3809 (inhibit-read-only t)
3810 (props (append '(article-type emphasis)
3811 gnus-hidden-properties))
3812 regexp elem beg invisible visible face)
3813 (article-goto-body)
3814 (setq beg (point))
3815 (while (setq elem (pop alist))
3816 (goto-char beg)
3817 (setq regexp (car elem)
3818 invisible (nth 1 elem)
3819 visible (nth 2 elem)
3820 face (nth 3 elem))
3821 (while (re-search-forward regexp nil t)
3822 (when (and (match-beginning visible) (match-beginning invisible))
3823 (gnus-article-hide-text
3824 (match-beginning invisible) (match-end invisible) props)
3825 (gnus-article-unhide-text-type
3826 (match-beginning visible) (match-end visible) 'emphasis)
3827 (gnus-put-overlay-excluding-newlines
3828 (match-beginning visible) (match-end visible) 'face face)
3829 (gnus-add-wash-type 'emphasis)
3830 (goto-char (match-end invisible)))))))))
3832 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3833 "Setup newsgroup emphasis alist."
3834 (unless gnus-article-emphasis-alist
3835 (let ((name (and gnus-newsgroup-name
3836 (gnus-group-real-name gnus-newsgroup-name))))
3837 (make-local-variable 'gnus-article-emphasis-alist)
3838 (setq gnus-article-emphasis-alist
3839 (nconc
3840 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3841 (while (setq elem (pop alist))
3842 (when (and name (string-match (car elem) name))
3843 (setq alist nil
3844 highlight (copy-sequence (cdr elem)))))
3845 highlight)
3846 (copy-sequence highlight-words)
3847 (if gnus-newsgroup-name
3848 (copy-sequence (gnus-group-find-parameter
3849 gnus-newsgroup-name 'highlight-words t)))
3850 gnus-emphasis-alist)))))
3852 (defvar gnus-summary-article-menu)
3853 (defvar gnus-summary-post-menu)
3855 ;;; Saving functions.
3857 (defun gnus-article-save (save-buffer file &optional num)
3858 "Save the currently selected article."
3859 (when (or (get gnus-default-article-saver :headers)
3860 (not gnus-save-all-headers))
3861 ;; Remove headers according to `gnus-saved-headers' or the value
3862 ;; of the `:headers' property that the saver function might have.
3863 (let ((gnus-visible-headers
3864 (or (symbol-value (get gnus-default-article-saver :headers))
3865 gnus-saved-headers gnus-visible-headers))
3866 ;; Ignore group parameter. See `article-hide-headers'.
3867 (gnus-summary-buffer nil))
3868 (with-current-buffer save-buffer
3869 (article-hide-headers 1 t))))
3870 (save-window-excursion
3871 (if (not gnus-default-article-saver)
3872 (error "No default saver is defined")
3873 ;; !!! Magic! The saving functions all save
3874 ;; `gnus-save-article-buffer' (or so they think), but we
3875 ;; bind that variable to our save-buffer.
3876 (set-buffer gnus-article-buffer)
3877 (let* ((gnus-save-article-buffer save-buffer)
3878 (filename
3879 (cond
3880 ((not gnus-prompt-before-saving) 'default)
3881 ((eq gnus-prompt-before-saving 'always) nil)
3882 (t file)))
3883 (gnus-number-of-articles-to-be-saved
3884 (when (eq gnus-prompt-before-saving t)
3885 num))) ; Magic
3886 (set-buffer gnus-article-current-summary)
3887 (funcall gnus-default-article-saver filename)))))
3889 (defun gnus-read-save-file-name (prompt &optional filename
3890 function group headers variable
3891 dir-var)
3892 (let ((default-name
3893 (funcall function group headers (symbol-value variable)))
3894 result)
3895 (setq result
3896 (expand-file-name
3897 (cond
3898 ((eq filename 'default)
3899 default-name)
3900 ((eq filename t)
3901 default-name)
3902 (filename filename)
3904 (when (symbol-value dir-var)
3905 (setq default-name (expand-file-name
3906 (file-name-nondirectory default-name)
3907 (symbol-value dir-var))))
3908 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3909 (prompt
3910 (format prompt
3911 (if (and gnus-number-of-articles-to-be-saved
3912 (> gnus-number-of-articles-to-be-saved 1))
3913 (format "these %d articles"
3914 gnus-number-of-articles-to-be-saved)
3915 "this article")))
3916 (file
3917 ;; Let the split methods have their say.
3918 (cond
3919 ;; No split name was found.
3920 ((null split-name)
3921 (read-file-name
3922 (concat prompt " (default "
3923 (file-name-nondirectory default-name) "): ")
3924 (file-name-directory default-name)
3925 default-name))
3926 ;; A single group name is returned.
3927 ((stringp split-name)
3928 (setq default-name
3929 (funcall function split-name headers
3930 (symbol-value variable)))
3931 (read-file-name
3932 (concat prompt " (default "
3933 (file-name-nondirectory default-name) "): ")
3934 (file-name-directory default-name)
3935 default-name))
3936 ;; A single split name was found
3937 ((= 1 (length split-name))
3938 (let* ((name (expand-file-name
3939 (car split-name)
3940 gnus-article-save-directory))
3941 (dir (cond ((file-directory-p name)
3942 (file-name-as-directory name))
3943 ((file-exists-p name) name)
3944 (t gnus-article-save-directory))))
3945 (read-file-name
3946 (concat prompt " (default " name "): ")
3947 dir name)))
3948 ;; A list of splits was found.
3950 (setq split-name (nreverse split-name))
3951 (let (result)
3952 (let ((file-name-history
3953 (nconc split-name file-name-history)))
3954 (setq result
3955 (expand-file-name
3956 (read-file-name
3957 (concat prompt " (`M-p' for defaults): ")
3958 gnus-article-save-directory
3959 (car split-name))
3960 gnus-article-save-directory)))
3961 (car (push result file-name-history)))))))
3962 ;; Create the directory.
3963 (gnus-make-directory (file-name-directory file))
3964 ;; If we have read a directory, we append the default file name.
3965 (when (file-directory-p file)
3966 (setq file (expand-file-name (file-name-nondirectory
3967 default-name)
3968 (file-name-as-directory file))))
3969 ;; Possibly translate some characters.
3970 (nnheader-translate-file-chars file))))))
3971 (gnus-make-directory (file-name-directory result))
3972 (when variable
3973 (set variable result))
3974 (when dir-var
3975 (set dir-var (file-name-directory result)))
3976 result))
3978 (defun gnus-article-archive-name (group)
3979 "Return the first instance of an \"Archive-name\" in the current buffer."
3980 (let ((case-fold-search t))
3981 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3982 (nnheader-concat gnus-article-save-directory
3983 (match-string 1)))))
3985 (defun gnus-article-nndoc-name (group)
3986 "If GROUP is an nndoc group, return the name of the parent group."
3987 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3988 (gnus-group-get-parameter group 'save-article-group)))
3990 (defun gnus-summary-save-in-rmail (&optional filename)
3991 "Append this article to Rmail file.
3992 Optional argument FILENAME specifies file name.
3993 Directory to save to is default to `gnus-article-save-directory'."
3994 (setq filename (gnus-read-save-file-name
3995 "Save %s in rmail file" filename
3996 gnus-rmail-save-name gnus-newsgroup-name
3997 gnus-current-headers 'gnus-newsgroup-last-rmail))
3998 (with-current-buffer gnus-save-article-buffer
3999 (save-excursion
4000 (save-restriction
4001 (widen)
4002 ;; Note that unlike gnus-summary-save-in-mail, there is no
4003 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4004 ;; not use Babyl.
4005 (gnus-output-to-rmail filename))))
4006 filename)
4008 (defun gnus-summary-save-in-mail (&optional filename)
4009 "Append this article to Unix mail file.
4010 Optional argument FILENAME specifies file name.
4011 Directory to save to is default to `gnus-article-save-directory'."
4012 (setq filename (gnus-read-save-file-name
4013 "Save %s in Unix mail file" filename
4014 gnus-mail-save-name gnus-newsgroup-name
4015 gnus-current-headers 'gnus-newsgroup-last-mail))
4016 (with-current-buffer gnus-save-article-buffer
4017 (save-excursion
4018 (save-restriction
4019 (widen)
4020 (if (and (file-readable-p filename)
4021 (file-regular-p filename)
4022 (mail-file-babyl-p filename))
4023 (gnus-output-to-rmail filename)
4024 (gnus-output-to-mail filename)))))
4025 filename)
4027 (put 'gnus-summary-save-in-file :decode t)
4028 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4029 (defun gnus-summary-save-in-file (&optional filename overwrite)
4030 "Append this article to file.
4031 Optional argument FILENAME specifies file name.
4032 Directory to save to is default to `gnus-article-save-directory'."
4033 (setq filename (gnus-read-save-file-name
4034 "Save %s in file" filename
4035 gnus-file-save-name gnus-newsgroup-name
4036 gnus-current-headers 'gnus-newsgroup-last-file))
4037 (with-current-buffer gnus-save-article-buffer
4038 (save-excursion
4039 (save-restriction
4040 (widen)
4041 (when (and overwrite
4042 (file-exists-p filename))
4043 (delete-file filename))
4044 (gnus-output-to-file filename))))
4045 filename)
4047 (put 'gnus-summary-write-to-file :decode t)
4048 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4049 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4050 (defun gnus-summary-write-to-file (&optional filename)
4051 "Write this article to a file, overwriting it if the file exists.
4052 Optional argument FILENAME specifies file name.
4053 The directory to save in defaults to `gnus-article-save-directory'."
4054 (setq filename (gnus-read-save-file-name
4055 "Save %s in file" filename
4056 gnus-file-save-name gnus-newsgroup-name
4057 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4058 (gnus-summary-save-in-file filename t))
4060 (put 'gnus-summary-save-body-in-file :decode t)
4061 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4062 "Append this article body to a file.
4063 Optional argument FILENAME specifies file name.
4064 The directory to save in defaults to `gnus-article-save-directory'."
4065 (setq filename (gnus-read-save-file-name
4066 "Save %s body in file" filename
4067 gnus-file-save-name gnus-newsgroup-name
4068 gnus-current-headers 'gnus-newsgroup-last-file))
4069 (with-current-buffer gnus-save-article-buffer
4070 (save-excursion
4071 (save-restriction
4072 (widen)
4073 (when (article-goto-body)
4074 (narrow-to-region (point) (point-max)))
4075 (when (and overwrite
4076 (file-exists-p filename))
4077 (delete-file filename))
4078 (gnus-output-to-file filename))))
4079 filename)
4081 (put 'gnus-summary-write-body-to-file :decode t)
4082 (put 'gnus-summary-write-body-to-file
4083 :function 'gnus-summary-save-body-in-file)
4084 (defun gnus-summary-write-body-to-file (&optional filename)
4085 "Write this article body to a file, overwriting it if the file exists.
4086 Optional argument FILENAME specifies file name.
4087 The directory to save in defaults to `gnus-article-save-directory'."
4088 (setq filename (gnus-read-save-file-name
4089 "Save %s body in file" filename
4090 gnus-file-save-name gnus-newsgroup-name
4091 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4092 (gnus-summary-save-body-in-file filename t))
4094 (put 'gnus-summary-save-in-pipe :decode t)
4095 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4096 (defun gnus-summary-save-in-pipe (&optional command raw)
4097 "Pipe this article to subprocess COMMAND.
4098 Valid values for COMMAND include:
4099 a string
4100 The executable command name and possibly arguments.
4102 You will be prompted for the command in the minibuffer.
4103 the symbol `default'
4104 It will be replaced with the command which the variable
4105 `gnus-summary-pipe-output-default-command' holds or the command
4106 last used for saving.
4107 Non-nil value for RAW overrides `:decode' and `:headers' properties
4108 and the raw article including all headers will be piped."
4109 (let ((article (gnus-summary-article-number))
4110 (decode (unless raw
4111 (get 'gnus-summary-save-in-pipe :decode)))
4112 save-buffer default)
4113 (if article
4114 (if (vectorp (gnus-summary-article-header article))
4115 (save-current-buffer
4116 (gnus-summary-select-article decode decode nil article)
4117 (insert-buffer-substring
4118 (prog1
4119 (if decode
4120 gnus-article-buffer
4121 gnus-original-article-buffer)
4122 (setq save-buffer
4123 (nnheader-set-temp-buffer " *Gnus Save*"))))
4124 ;; Remove unwanted headers.
4125 (when (and (not raw)
4126 (or (get 'gnus-summary-save-in-pipe :headers)
4127 (not gnus-save-all-headers)))
4128 (let ((gnus-visible-headers
4129 (or (symbol-value (get 'gnus-summary-save-in-pipe
4130 :headers))
4131 gnus-saved-headers gnus-visible-headers))
4132 (gnus-summary-buffer nil))
4133 (article-hide-headers 1 t))))
4134 (error "%d is not a real article" article))
4135 (error "No article to pipe"))
4136 (setq default (or gnus-summary-pipe-output-default-command
4137 gnus-last-shell-command))
4138 (unless (stringp command)
4139 (setq command
4140 (if (and (eq command 'default) default)
4141 default
4142 (gnus-read-shell-command "Shell command on this article: "
4143 default))))
4144 (when (string-equal command "")
4145 (if default
4146 (setq command default)
4147 (error "A command is required")))
4148 (with-current-buffer save-buffer
4149 (save-restriction
4150 (widen)
4151 (shell-command-on-region (point-min) (point-max) command nil)))
4152 (gnus-kill-buffer save-buffer))
4153 (setq gnus-summary-pipe-output-default-command command))
4155 (defun gnus-summary-pipe-to-muttprint (&optional command)
4156 "Pipe this article to muttprint."
4157 (unless (stringp command)
4158 (setq command (read-string
4159 "Print using command: " gnus-summary-muttprint-program
4160 nil gnus-summary-muttprint-program)))
4161 (let ((gnus-summary-pipe-output-default-command
4162 gnus-summary-pipe-output-default-command))
4163 (gnus-summary-save-in-pipe command))
4164 (setq gnus-summary-muttprint-program command))
4166 ;;; Article file names when saving.
4168 (defun gnus-capitalize-newsgroup (newsgroup)
4169 "Capitalize NEWSGROUP name."
4170 (when (not (zerop (length newsgroup)))
4171 (concat (char-to-string (upcase (aref newsgroup 0)))
4172 (substring newsgroup 1))))
4174 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4175 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4176 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4177 Otherwise, it is like ~/News/news/group/num."
4178 (let ((default
4179 (expand-file-name
4180 (concat (if (gnus-use-long-file-name 'not-save)
4181 (gnus-capitalize-newsgroup newsgroup)
4182 (gnus-newsgroup-directory-form newsgroup))
4183 "/" (int-to-string (mail-header-number headers)))
4184 gnus-article-save-directory)))
4185 (if (and last-file
4186 (string-equal (file-name-directory default)
4187 (file-name-directory last-file))
4188 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4189 default
4190 (or last-file default))))
4192 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4193 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4194 If variable `gnus-use-long-file-name' is non-nil, it is
4195 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4196 (let ((default
4197 (expand-file-name
4198 (concat (if (gnus-use-long-file-name 'not-save)
4199 newsgroup
4200 (gnus-newsgroup-directory-form newsgroup))
4201 "/" (int-to-string (mail-header-number headers)))
4202 gnus-article-save-directory)))
4203 (if (and last-file
4204 (string-equal (file-name-directory default)
4205 (file-name-directory last-file))
4206 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4207 default
4208 (or last-file default))))
4210 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4211 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4212 If variable `gnus-use-long-file-name' is non-nil, it is
4213 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4214 (or last-file
4215 (expand-file-name
4216 (if (gnus-use-long-file-name 'not-save)
4217 newsgroup
4218 (file-relative-name
4219 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4220 default-directory))
4221 gnus-article-save-directory)))
4223 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4224 "Generate file name from sender."
4225 (let ((from (mail-header-from headers)))
4226 (expand-file-name
4227 (if (and from (string-match "\\([^ <]+\\)@" from))
4228 (match-string 1 from)
4229 "nobody")
4230 gnus-article-save-directory)))
4232 (defun article-verify-x-pgp-sig ()
4233 "Verify X-PGP-Sig."
4234 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4235 (interactive)
4236 (if (gnus-buffer-live-p gnus-original-article-buffer)
4237 (let ((sig (with-current-buffer gnus-original-article-buffer
4238 (gnus-fetch-field "X-PGP-Sig")))
4239 items info headers)
4240 (when (and sig
4241 mml2015-use
4242 (mml2015-clear-verify-function))
4243 (with-temp-buffer
4244 (insert-buffer-substring gnus-original-article-buffer)
4245 (setq items (split-string sig))
4246 (message-narrow-to-head)
4247 (let ((inhibit-point-motion-hooks t)
4248 (case-fold-search t))
4249 ;; Don't verify multiple headers.
4250 (setq headers (mapconcat (lambda (header)
4251 (concat header ": "
4252 (mail-fetch-field header)
4253 "\n"))
4254 (split-string (nth 1 items) ",") "")))
4255 (delete-region (point-min) (point-max))
4256 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4257 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4258 (insert headers)
4259 (widen)
4260 (forward-line)
4261 (while (not (eobp))
4262 (if (looking-at "^-")
4263 (insert "- "))
4264 (forward-line))
4265 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4266 (insert "Version: " (car items) "\n\n")
4267 (insert (mapconcat 'identity (cddr items) "\n"))
4268 (insert "\n-----END PGP SIGNATURE-----\n")
4269 (let ((mm-security-handle (list (format "multipart/signed"))))
4270 (mml2015-clean-buffer)
4271 (let ((coding-system-for-write (or gnus-newsgroup-charset
4272 'iso-8859-1)))
4273 (funcall (mml2015-clear-verify-function)))
4274 (setq info
4275 (or (mm-handle-multipart-ctl-parameter
4276 mm-security-handle 'gnus-details)
4277 (mm-handle-multipart-ctl-parameter
4278 mm-security-handle 'gnus-info)))))
4279 (when info
4280 (let ((inhibit-read-only t) bface eface)
4281 (save-restriction
4282 (message-narrow-to-head)
4283 (goto-char (point-max))
4284 (forward-line -1)
4285 (setq bface (get-text-property (point-at-bol) 'face)
4286 eface (get-text-property (1- (point-at-eol)) 'face))
4287 (message-remove-header "X-Gnus-PGP-Verify")
4288 (if (re-search-forward "^X-PGP-Sig:" nil t)
4289 (forward-line)
4290 (goto-char (point-max)))
4291 (narrow-to-region (point) (point))
4292 (insert "X-Gnus-PGP-Verify: " info "\n")
4293 (goto-char (point-min))
4294 (forward-line)
4295 (while (not (eobp))
4296 (if (not (looking-at "^[ \t]"))
4297 (insert " "))
4298 (forward-line))
4299 ;; Do highlighting.
4300 (goto-char (point-min))
4301 (when (looking-at "\\([^:]+\\): *")
4302 (put-text-property (match-beginning 1) (1+ (match-end 1))
4303 'face bface)
4304 (put-text-property (match-end 0) (point-max)
4305 'face eface)))))))))
4307 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4309 (defun article-verify-cancel-lock ()
4310 "Verify Cancel-Lock header."
4311 (interactive)
4312 (if (gnus-buffer-live-p gnus-original-article-buffer)
4313 (canlock-verify gnus-original-article-buffer)))
4315 (eval-and-compile
4316 (mapc
4317 (lambda (func)
4318 (let (afunc gfunc)
4319 (if (consp func)
4320 (setq afunc (car func)
4321 gfunc (cdr func))
4322 (setq afunc func
4323 gfunc (intern (format "gnus-%s" func))))
4324 (defalias gfunc
4325 (when (fboundp afunc)
4326 `(lambda (&optional interactive &rest args)
4327 ,(documentation afunc t)
4328 (interactive (list t))
4329 (with-current-buffer gnus-article-buffer
4330 (if interactive
4331 (call-interactively ',afunc)
4332 (apply ',afunc args))))))))
4333 '(article-hide-headers
4334 article-verify-x-pgp-sig
4335 article-verify-cancel-lock
4336 article-hide-boring-headers
4337 article-treat-overstrike
4338 article-treat-ansi-sequences
4339 article-fill-long-lines
4340 article-capitalize-sentences
4341 article-remove-cr
4342 article-remove-leading-whitespace
4343 article-display-x-face
4344 article-display-face
4345 article-de-quoted-unreadable
4346 article-de-base64-unreadable
4347 article-decode-HZ
4348 article-wash-html
4349 article-unsplit-urls
4350 article-hide-list-identifiers
4351 article-strip-banner
4352 article-babel
4353 article-hide-pem
4354 article-hide-signature
4355 article-strip-headers-in-body
4356 article-remove-trailing-blank-lines
4357 article-strip-leading-blank-lines
4358 article-strip-multiple-blank-lines
4359 article-strip-leading-space
4360 article-strip-trailing-space
4361 article-strip-blank-lines
4362 article-strip-all-blank-lines
4363 article-date-local
4364 article-date-english
4365 article-date-iso8601
4366 article-date-original
4367 article-treat-date
4368 article-date-ut
4369 article-decode-mime-words
4370 article-decode-charset
4371 article-decode-encoded-words
4372 article-date-user
4373 article-date-lapsed
4374 article-date-combined-lapsed
4375 article-emphasize
4376 article-treat-dumbquotes
4377 article-treat-non-ascii
4378 article-normalize-headers
4379 ;;(article-show-all . gnus-article-show-all-headers)
4383 ;;; Gnus article mode
4386 (put 'gnus-article-mode 'mode-class 'special)
4388 (set-keymap-parent gnus-article-mode-map widget-keymap)
4390 (gnus-define-keys gnus-article-mode-map
4391 " " gnus-article-goto-next-page
4392 [?\S-\ ] gnus-article-goto-prev-page
4393 "\177" gnus-article-goto-prev-page
4394 [delete] gnus-article-goto-prev-page
4395 "\C-c^" gnus-article-refer-article
4396 "h" gnus-article-show-summary
4397 "s" gnus-article-show-summary
4398 "\C-c\C-m" gnus-article-mail
4399 "?" gnus-article-describe-briefly
4400 "<" beginning-of-buffer
4401 ">" end-of-buffer
4402 "\C-c\C-i" gnus-info-find-node
4403 "\C-c\C-b" gnus-bug
4404 "R" gnus-article-reply-with-original
4405 "F" gnus-article-followup-with-original
4406 "\C-hk" gnus-article-describe-key
4407 "\C-hc" gnus-article-describe-key-briefly
4408 "\C-hb" gnus-article-describe-bindings
4410 "e" gnus-article-read-summary-keys
4411 "\C-d" gnus-article-read-summary-keys
4412 "\M-*" gnus-article-read-summary-keys
4413 "\M-#" gnus-article-read-summary-keys
4414 "\M-^" gnus-article-read-summary-keys
4415 "\M-g" gnus-article-read-summary-keys)
4417 (substitute-key-definition
4418 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4420 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4421 "W" gnus-article-wide-reply-with-original)
4422 (if (featurep 'xemacs)
4423 (set-keymap-default-binding gnus-article-send-map
4424 'gnus-article-read-summary-send-keys)
4425 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4427 (defun gnus-article-make-menu-bar ()
4428 (unless (boundp 'gnus-article-commands-menu)
4429 (gnus-summary-make-menu-bar))
4430 (unless (boundp 'gnus-article-article-menu)
4431 (easy-menu-define
4432 gnus-article-article-menu gnus-article-mode-map ""
4433 '("Article"
4434 ["Scroll forwards" gnus-article-goto-next-page t]
4435 ["Scroll backwards" gnus-article-goto-prev-page t]
4436 ["Show summary" gnus-article-show-summary t]
4437 ["Fetch Message-ID at point" gnus-article-refer-article t]
4438 ["Mail to address at point" gnus-article-mail t]
4439 ["Send a bug report" gnus-bug t]))
4441 (easy-menu-define
4442 gnus-article-treatment-menu gnus-article-mode-map ""
4443 ;; Fixme: this should use :active (and maybe :visible).
4444 '("Treatment"
4445 ["Hide headers" gnus-article-hide-headers t]
4446 ["Hide signature" gnus-article-hide-signature t]
4447 ["Hide citation" gnus-article-hide-citation t]
4448 ["Treat overstrike" gnus-article-treat-overstrike t]
4449 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4450 ["Remove carriage return" gnus-article-remove-cr t]
4451 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4452 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4453 ["Remove base64" gnus-article-de-base64-unreadable t]
4454 ["Treat html" gnus-article-wash-html t]
4455 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4456 ["Decode HZ" gnus-article-decode-HZ t]))
4458 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4460 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4462 (gnus-run-hooks 'gnus-article-menu-hook)))
4464 (defvar bookmark-make-record-function)
4465 (defvar shr-put-image-function)
4467 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4468 "Major mode for displaying an article.
4470 All normal editing commands are switched off.
4472 The following commands are available in addition to all summary mode
4473 commands:
4474 \\<gnus-article-mode-map>
4475 \\[gnus-article-next-page]\t Scroll the article one page forwards
4476 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4477 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4478 \\[gnus-article-show-summary]\t Display the summary buffer
4479 \\[gnus-article-mail]\t Send a reply to the address near point
4480 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4481 \\[gnus-info-find-node]\t Go to the Gnus info node"
4482 (gnus-simplify-mode-line)
4483 (make-local-variable 'minor-mode-alist)
4484 (when (gnus-visual-p 'article-menu 'menu)
4485 (gnus-article-make-menu-bar)
4486 (when gnus-summary-tool-bar-map
4487 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4488 (gnus-update-format-specifications nil 'article-mode)
4489 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4490 (set (make-local-variable 'gnus-page-broken) nil)
4491 (make-local-variable 'gnus-article-current-summary)
4492 (make-local-variable 'gnus-article-mime-handles)
4493 (make-local-variable 'gnus-article-decoded-p)
4494 (make-local-variable 'gnus-article-mime-handle-alist)
4495 (make-local-variable 'gnus-article-wash-types)
4496 (make-local-variable 'gnus-article-image-alist)
4497 (make-local-variable 'gnus-article-charset)
4498 (make-local-variable 'gnus-article-ignored-charsets)
4499 (set (make-local-variable 'bookmark-make-record-function)
4500 'gnus-summary-bookmark-make-record)
4501 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4502 ;; face.
4503 (set (make-local-variable 'nobreak-char-display) nil)
4504 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4505 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4506 (setq cursor-in-non-selected-windows nil)
4507 (gnus-set-default-directory)
4508 (buffer-disable-undo)
4509 (setq buffer-read-only t
4510 show-trailing-whitespace nil)
4511 (mm-enable-multibyte))
4513 (defun gnus-article-setup-buffer ()
4514 "Initialize the article buffer."
4515 (let* ((name (if gnus-single-article-buffer "*Article*"
4516 (concat "*Article "
4517 (gnus-group-decoded-name gnus-newsgroup-name)
4518 "*")))
4519 (original
4520 (progn (string-match "\\*Article" name)
4521 (concat " *Original Article"
4522 (substring name (match-end 0))))))
4523 (setq gnus-article-buffer name)
4524 (setq gnus-original-article-buffer original)
4525 (setq gnus-article-mime-handle-alist nil)
4526 (with-current-buffer gnus-summary-buffer
4527 ;; This might be a variable local to the summary buffer.
4528 (unless gnus-single-article-buffer
4529 (setq gnus-article-buffer name)
4530 (setq gnus-original-article-buffer original)
4531 (gnus-set-global-variables)))
4532 (gnus-article-setup-highlight-words)
4533 ;; Init original article buffer.
4534 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4535 (mm-enable-multibyte)
4536 (setq major-mode 'gnus-original-article-mode)
4537 (make-local-variable 'gnus-original-article))
4538 (if (and (get-buffer name)
4539 (with-current-buffer name
4540 (if gnus-article-edit-mode
4541 (if (y-or-n-p "Article mode edit in progress; discard? ")
4542 (progn
4543 (set-buffer-modified-p nil)
4544 (gnus-kill-buffer name)
4545 (message "")
4546 nil)
4547 (error "Action aborted"))
4548 t)))
4549 (let ((summary gnus-summary-buffer))
4550 (with-current-buffer name
4551 (set (make-local-variable 'gnus-article-edit-mode) nil)
4552 (gnus-article-stop-animations)
4553 (when gnus-article-mime-handles
4554 (mm-destroy-parts gnus-article-mime-handles)
4555 (setq gnus-article-mime-handles nil))
4556 ;; Set it to nil in article-buffer!
4557 (setq gnus-article-mime-handle-alist nil)
4558 (buffer-disable-undo)
4559 (setq buffer-read-only t)
4560 (unless (derived-mode-p 'gnus-article-mode)
4561 (gnus-article-mode))
4562 (set (make-local-variable 'gnus-summary-buffer) summary)
4563 (setq truncate-lines gnus-article-truncate-lines)
4564 (current-buffer)))
4565 (let ((summary gnus-summary-buffer))
4566 (with-current-buffer (gnus-get-buffer-create name)
4567 (gnus-article-mode)
4568 (setq truncate-lines gnus-article-truncate-lines)
4569 (set (make-local-variable 'gnus-summary-buffer) summary)
4570 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4571 (when article-lapsed-timer
4572 (gnus-stop-date-timer))
4573 (when gnus-article-update-date-headers
4574 (gnus-start-date-timer gnus-article-update-date-headers))
4575 (current-buffer))))))
4577 (defun gnus-article-stop-animations ()
4578 (dolist (timer (and (boundp 'timer-list)
4579 timer-list))
4580 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4581 (cancel-timer timer))))
4583 (defun gnus-stop-downloads ()
4584 (when (boundp 'url-queue)
4585 (set (intern "url-queue" obarray) nil)))
4587 ;; Set article window start at LINE, where LINE is the number of lines
4588 ;; from the head of the article.
4589 (defun gnus-article-set-window-start (&optional line)
4590 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4591 (when article-window
4592 (set-window-start
4593 article-window
4594 (with-current-buffer gnus-article-buffer
4595 (goto-char (point-min))
4596 (if (not line)
4597 (point-min)
4598 (gnus-message 6 "Moved to bookmark")
4599 (search-forward "\n\n" nil t)
4600 (forward-line line)
4601 (point)))))))
4603 (defun gnus-article-prepare (article &optional all-headers header)
4604 "Prepare ARTICLE in article mode buffer.
4605 ARTICLE should either be an article number or a Message-ID.
4606 If ARTICLE is an id, HEADER should be the article headers.
4607 If ALL-HEADERS is non-nil, no headers are hidden."
4608 (save-excursion
4609 ;; Make sure we start in a summary buffer.
4610 (unless (derived-mode-p 'gnus-summary-mode)
4611 (set-buffer gnus-summary-buffer))
4612 (setq gnus-summary-buffer (current-buffer))
4613 (let* ((gnus-article (if header (mail-header-number header) article))
4614 (summary-buffer (current-buffer))
4615 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4616 (group gnus-newsgroup-name)
4617 result)
4618 (save-excursion
4619 (gnus-article-setup-buffer)
4620 (set-buffer gnus-article-buffer)
4621 ;; Deactivate active regions.
4622 (when (and (boundp 'transient-mark-mode)
4623 transient-mark-mode)
4624 (setq mark-active nil))
4625 (if (not (setq result (let ((inhibit-read-only t))
4626 (gnus-request-article-this-buffer
4627 article group))))
4628 ;; There is no such article.
4629 (save-excursion
4630 (when (and (numberp article)
4631 (not (memq article gnus-newsgroup-sparse)))
4632 (setq gnus-article-current
4633 (cons gnus-newsgroup-name article))
4634 (set-buffer gnus-summary-buffer)
4635 (setq gnus-current-article article)
4636 (if (and (memq article gnus-newsgroup-undownloaded)
4637 (not (gnus-online (gnus-find-method-for-group
4638 gnus-newsgroup-name))))
4639 (progn
4640 (gnus-summary-set-agent-mark article)
4641 (message "Message marked for downloading"))
4642 (gnus-summary-mark-article article gnus-canceled-mark)
4643 (unless (memq article gnus-newsgroup-sparse)
4644 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4645 (if (or (eq result 'pseudo)
4646 (eq result 'nneething))
4647 (progn
4648 (with-current-buffer summary-buffer
4649 (push article gnus-newsgroup-history)
4650 (setq gnus-last-article gnus-current-article
4651 gnus-current-article 0
4652 gnus-current-headers nil
4653 gnus-article-current nil)
4654 (if (eq result 'nneething)
4655 (gnus-configure-windows 'summary)
4656 (gnus-configure-windows 'article))
4657 (gnus-set-global-variables))
4658 (let ((gnus-article-mime-handle-alist-1
4659 gnus-article-mime-handle-alist))
4660 (gnus-set-mode-line 'article)))
4661 ;; The result from the `request' was an actual article -
4662 ;; or at least some text that is now displayed in the
4663 ;; article buffer.
4664 (when (and (numberp article)
4665 (not (eq article gnus-current-article)))
4666 ;; Seems like a new article has been selected.
4667 ;; `gnus-current-article' must be an article number.
4668 (with-current-buffer summary-buffer
4669 (push article gnus-newsgroup-history)
4670 (setq gnus-last-article gnus-current-article
4671 gnus-current-article article
4672 gnus-current-headers
4673 (gnus-summary-article-header gnus-current-article)
4674 gnus-article-current
4675 (cons gnus-newsgroup-name gnus-current-article))
4676 (unless (vectorp gnus-current-headers)
4677 (setq gnus-current-headers nil))
4678 (gnus-summary-goto-subject gnus-current-article)
4679 (when (gnus-summary-show-thread)
4680 ;; If the summary buffer really was folded, the
4681 ;; previous goto may not actually have gone to
4682 ;; the right article, but the thread root instead.
4683 ;; So we go again.
4684 (gnus-summary-goto-subject gnus-current-article))
4685 (gnus-run-hooks 'gnus-mark-article-hook)
4686 (gnus-set-mode-line 'summary)
4687 (when (gnus-visual-p 'article-highlight 'highlight)
4688 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4689 ;; Set the global newsgroup variables here.
4690 (gnus-set-global-variables)
4691 (setq gnus-have-all-headers
4692 (or all-headers gnus-show-all-headers))))
4693 (save-excursion
4694 (gnus-configure-windows 'article))
4695 (when (or (numberp article)
4696 (stringp article))
4697 (gnus-article-prepare-display)
4698 ;; Do page break.
4699 (goto-char (point-min))
4700 (when gnus-break-pages
4701 (gnus-narrow-to-page)))
4702 (let ((gnus-article-mime-handle-alist-1
4703 gnus-article-mime-handle-alist))
4704 (gnus-set-mode-line 'article))
4705 (article-goto-body)
4706 (unless (bobp)
4707 (forward-line -1))
4708 (set-window-point (get-buffer-window (current-buffer)) (point))
4709 (gnus-configure-windows 'article)
4710 (gnus-run-hooks 'gnus-article-prepare-hook)
4711 t))))))
4713 ;;;###autoload
4714 (defun gnus-article-prepare-display ()
4715 "Make the current buffer look like a nice article."
4716 ;; Hooks for getting information from the article.
4717 ;; This hook must be called before being narrowed.
4718 (let ((gnus-article-buffer (current-buffer))
4719 buffer-read-only
4720 (inhibit-read-only t))
4721 (unless (derived-mode-p 'gnus-article-mode)
4722 (gnus-article-mode))
4723 (setq buffer-read-only nil
4724 gnus-article-wash-types nil
4725 gnus-article-image-alist nil)
4726 (gnus-run-hooks 'gnus-tmp-internal-hook)
4727 (when gnus-display-mime-function
4728 (funcall gnus-display-mime-function))
4729 ;; Add attachment buttons to the header.
4730 (when gnus-mime-display-attachment-buttons-in-header
4731 (gnus-mime-buttonize-attachments-in-header))))
4734 ;;; Gnus Sticky Article Mode
4737 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4738 "Mode for sticky articles."
4739 ;; Release bindings that won't work.
4740 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4741 gnus-sticky-article-mode-map)
4742 (substitute-key-definition 'gnus-article-refer-article 'undefined
4743 gnus-sticky-article-mode-map)
4744 (dolist (k '("e" "h" "s" "F" "R"))
4745 (define-key gnus-sticky-article-mode-map k nil))
4746 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4747 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4748 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4749 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4751 (defun gnus-sticky-article (arg)
4752 "Make the current article sticky.
4753 If a prefix ARG is given, ask for a name for this sticky article buffer."
4754 (interactive "P")
4755 (gnus-summary-show-thread)
4756 (gnus-summary-select-article nil nil 'pseudo)
4757 (let (new-art-buf-name)
4758 (gnus-eval-in-buffer-window gnus-article-buffer
4759 (setq new-art-buf-name
4760 (concat
4761 "*Sticky Article: "
4762 (if arg
4763 (read-from-minibuffer "Sticky article buffer name: ")
4764 (gnus-with-article-headers
4765 (gnus-article-goto-header "subject")
4766 (setq new-art-buf-name
4767 (buffer-substring-no-properties
4768 (line-beginning-position) (line-end-position)))
4769 (goto-char (point-min))
4770 (gnus-article-goto-header "from")
4771 (setq new-art-buf-name
4772 (concat
4773 new-art-buf-name ", "
4774 (buffer-substring-no-properties
4775 (line-beginning-position) (line-end-position))))
4776 (goto-char (point-min))
4777 (gnus-article-goto-header "date")
4778 (setq new-art-buf-name
4779 (concat
4780 new-art-buf-name ", "
4781 (buffer-substring-no-properties
4782 (line-beginning-position) (line-end-position))))))
4783 "*"))
4784 (if (and (gnus-buffer-live-p new-art-buf-name)
4785 (with-current-buffer new-art-buf-name
4786 (derived-mode-p 'gnus-sticky-article-mode)))
4787 (switch-to-buffer new-art-buf-name)
4788 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4789 (gnus-sticky-article-mode))
4790 (setq gnus-article-buffer new-art-buf-name))
4791 (gnus-summary-recenter)
4792 (gnus-summary-position-point))
4794 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4795 "Kill the given sticky article BUFFER.
4796 If none is given, assume the current buffer and kill it if it has
4797 `gnus-sticky-article-mode'."
4798 (interactive)
4799 (unless buffer
4800 (setq buffer (current-buffer)))
4801 (with-current-buffer buffer
4802 (when (derived-mode-p 'gnus-sticky-article-mode)
4803 (gnus-kill-buffer buffer))))
4805 (defun gnus-kill-sticky-article-buffers (arg)
4806 "Kill all sticky article buffers.
4807 If a prefix ARG is given, ask for confirmation."
4808 (interactive "P")
4809 (dolist (buf (gnus-buffers))
4810 (with-current-buffer buf
4811 (when (derived-mode-p 'gnus-sticky-article-mode)
4812 (if (not arg)
4813 (gnus-kill-buffer buf)
4814 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4815 (gnus-kill-buffer buf)))))))
4818 ;;; Gnus MIME viewing functions
4821 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4822 "Format of the MIME buttons.
4824 Valid specifiers include:
4825 %t The MIME type
4826 %T MIME type, along with additional info
4827 %n The `name' parameter
4828 %d The description, if any
4829 %l The length of the encoded part
4830 %p The part identifier number
4831 %e Dots if the part isn't displayed
4833 General format specifiers can also be used. See Info node
4834 `(gnus)Formatting Variables'.")
4836 (defvar gnus-mime-button-line-format-alist
4837 '((?t gnus-tmp-type ?s)
4838 (?T gnus-tmp-type-long ?s)
4839 (?n gnus-tmp-name ?s)
4840 (?d gnus-tmp-description ?s)
4841 (?p gnus-tmp-id ?s)
4842 (?l gnus-tmp-length ?d)
4843 (?e gnus-tmp-dots ?s)))
4845 (defvar gnus-mime-button-commands
4846 '((gnus-article-press-button "\r" "Toggle Display")
4847 (gnus-mime-view-part "v" "View Interactively...")
4848 (gnus-mime-view-part-as-type "t" "View As Type...")
4849 (gnus-mime-view-part-as-charset "C" "View As charset...")
4850 (gnus-mime-save-part "o" "Save...")
4851 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4852 (gnus-mime-replace-part "r" "Replace part")
4853 (gnus-mime-delete-part "d" "Delete part")
4854 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4855 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4856 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4857 (gnus-mime-view-part-externally "e" "View Externally")
4858 (gnus-mime-print-part "p" "Print")
4859 (gnus-mime-pipe-part "|" "Pipe To Command...")
4860 (gnus-mime-action-on-part "." "Take action on the part...")))
4862 (defun gnus-article-mime-part-status ()
4863 (if gnus-article-mime-handle-alist-1
4864 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4865 " (1 part)"
4866 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4867 ""))
4869 (defvar gnus-mime-button-map
4870 (let ((map (make-sparse-keymap)))
4871 (define-key map gnus-mouse-2 'gnus-article-push-button)
4872 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4873 (dolist (c gnus-mime-button-commands)
4874 (define-key map (cadr c) (car c)))
4875 map))
4877 (easy-menu-define
4878 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4879 `("MIME Part"
4880 ,@(mapcar (lambda (c)
4881 (vector (caddr c) (car c) :active t))
4882 gnus-mime-button-commands)))
4884 (defvar gnus-url-button-commands
4885 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4887 (defvar gnus-url-button-map
4888 (let ((map (make-sparse-keymap)))
4889 (dolist (c gnus-url-button-commands)
4890 (define-key map (cadr c) (car c)))
4891 map))
4893 (easy-menu-define
4894 gnus-url-button-menu gnus-url-button-map "URL button menu."
4895 `("Url Button"
4896 ,@(mapcar (lambda (c)
4897 (vector (caddr c) (car c) :active t))
4898 gnus-url-button-commands)))
4900 (defmacro gnus-bind-safe-url-regexp (&rest body)
4901 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4902 `(let ((mm-w3m-safe-url-regexp
4903 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4904 (gnus-buffer-live-p
4905 gnus-article-current-summary))
4906 (with-current-buffer gnus-article-current-summary
4907 gnus-newsgroup-name)
4908 gnus-newsgroup-name)))
4909 (if (cond ((not group)
4910 ;; Maybe we're in a mml-preview buffer
4911 ;; and no group is selected.
4913 ((stringp gnus-safe-html-newsgroups)
4914 (string-match gnus-safe-html-newsgroups group))
4915 ((consp gnus-safe-html-newsgroups)
4916 (member group gnus-safe-html-newsgroups)))
4918 mm-w3m-safe-url-regexp))))
4919 ,@body))
4921 (defun gnus-mime-button-menu (event prefix)
4922 "Construct a context-sensitive menu of MIME commands."
4923 (interactive "e\nP")
4924 (save-window-excursion
4925 (let ((pos (event-start event)))
4926 (select-window (posn-window pos))
4927 (goto-char (posn-point pos))
4928 (gnus-article-check-buffer)
4929 (popup-menu gnus-mime-button-menu nil prefix))))
4931 (defun gnus-mime-view-all-parts (&optional handles)
4932 "View all the MIME parts."
4933 (interactive)
4934 (with-current-buffer gnus-article-buffer
4935 (let ((handles (or handles gnus-article-mime-handles))
4936 (mail-parse-charset gnus-newsgroup-charset)
4937 (mail-parse-ignored-charsets
4938 (with-current-buffer gnus-summary-buffer
4939 gnus-newsgroup-ignored-charsets)))
4940 (when handles
4941 (mm-remove-parts handles)
4942 (goto-char (point-min))
4943 (or (search-forward "\n\n") (goto-char (point-max)))
4944 (let ((inhibit-read-only t))
4945 (delete-region (point) (point-max))
4946 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4948 (defun gnus-article-jump-to-part (n)
4949 "Jump to MIME part N."
4950 (interactive "P")
4951 (let ((parts (with-current-buffer gnus-article-buffer
4952 (length gnus-article-mime-handle-alist))))
4953 (when (zerop parts)
4954 (error "No such part"))
4955 (pop-to-buffer gnus-article-buffer)
4956 (or n
4957 (setq n (if (= parts 1)
4959 (read-number (format "Jump to part (1..%s): " parts)))))
4960 (unless (and (integerp n) (<= n parts) (>= n 1))
4961 (setq n
4962 (progn
4963 (gnus-message 7 "Invalid part `%s', using %s instead."
4964 n parts)
4965 parts)))
4966 (gnus-message 9 "Jumping to part %s." n)
4967 (cond ((>= gnus-auto-select-part 1)
4968 (while (and (<= n parts)
4969 (not (gnus-article-goto-part n)))
4970 (setq n (1+ n))))
4971 ((< gnus-auto-select-part 0)
4972 (while (and (>= n 1)
4973 (not (gnus-article-goto-part n)))
4974 (setq n (1- n))))
4976 (gnus-article-goto-part n)))))
4978 (defvar gnus-mime-buttonized-part-id nil
4979 "ID of a mime part that should be buttonized.
4980 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4982 (eval-when-compile
4983 (defsubst gnus-article-edit-part (handles &optional current-id)
4984 "Edit an article in order to delete a mime part.
4985 This function is exclusively used by `gnus-mime-save-part-and-strip'
4986 and `gnus-mime-delete-part', and not provided at run-time normally."
4987 (gnus-article-edit-article
4988 `(lambda ()
4989 (buffer-disable-undo)
4990 (let ((mail-parse-charset (or gnus-article-charset
4991 ',gnus-newsgroup-charset))
4992 (mail-parse-ignored-charsets
4993 (or gnus-article-ignored-charsets
4994 ',gnus-newsgroup-ignored-charsets))
4995 (mbl mml-buffer-list))
4996 (setq mml-buffer-list nil)
4997 ;; A new text must be inserted before deleting existing ones
4998 ;; at the end so as not to move existing markers of which
4999 ;; the insertion type is t.
5000 (delete-region
5001 (point-min)
5002 (prog1
5003 (goto-char (point-max))
5004 (insert-buffer-substring gnus-original-article-buffer)))
5005 (mime-to-mml ',handles)
5006 (setq gnus-article-mime-handles nil)
5007 (let ((mbl1 mml-buffer-list))
5008 (setq mml-buffer-list mbl)
5009 (set (make-local-variable 'mml-buffer-list) mbl1))
5010 (gnus-make-local-hook 'kill-buffer-hook)
5011 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5012 `(lambda (no-highlight)
5013 (let ((mail-parse-charset (or gnus-article-charset
5014 ',gnus-newsgroup-charset))
5015 (message-options message-options)
5016 (message-options-set-recipient)
5017 (mail-parse-ignored-charsets
5018 (or gnus-article-ignored-charsets
5019 ',gnus-newsgroup-ignored-charsets)))
5020 (mml-to-mime)
5021 (mml-destroy-buffers)
5022 (remove-hook 'kill-buffer-hook
5023 'mml-destroy-buffers t)
5024 (kill-local-variable 'mml-buffer-list))
5025 (gnus-summary-edit-article-done
5026 ,(or (mail-header-references gnus-current-headers) "")
5027 ,(gnus-group-read-only-p)
5028 ,gnus-summary-buffer no-highlight))
5030 ;; Force buttonizing this part.
5031 (let ((gnus-mime-buttonized-part-id current-id))
5032 (gnus-article-edit-done))
5033 (gnus-configure-windows 'article)
5034 (when (and current-id (integerp gnus-auto-select-part))
5035 (gnus-article-jump-to-part
5036 (min (max (+ current-id gnus-auto-select-part) 1)
5037 (with-current-buffer gnus-article-buffer
5038 (length gnus-article-mime-handle-alist)))))))
5040 (defun gnus-mime-replace-part (file)
5041 "Replace MIME part under point with an external body."
5042 ;; Useful if file has already been saved to disk
5043 (interactive
5044 (list
5045 (read-file-name "Replace MIME part with file: "
5046 (or mm-default-directory default-directory)
5047 nil nil)))
5048 (gnus-mime-save-part-and-strip file))
5050 (defun gnus-mime-save-part-and-strip (&optional file)
5051 "Save the MIME part under point then replace it with an external body.
5052 If FILE is given, use it for the external part."
5053 (interactive)
5054 (gnus-article-check-buffer)
5055 (when (gnus-group-read-only-p)
5056 (error "The current group does not support deleting of parts"))
5057 (when (mm-complicated-handles gnus-article-mime-handles)
5058 (error "\
5059 The current article has a complicated MIME structure, giving up..."))
5060 (let* ((data (get-text-property (point) 'gnus-data))
5061 (id (get-text-property (point) 'gnus-part))
5062 param
5063 (handles gnus-article-mime-handles))
5064 (unless file
5065 (setq file
5066 (and data (mm-save-part data "Delete MIME part and save to: "))))
5067 (when file
5068 (with-current-buffer (mm-handle-buffer data)
5069 (erase-buffer)
5070 (insert "Content-Type: " (mm-handle-media-type data))
5071 (mml-insert-parameter-string (cdr (mm-handle-type data))
5072 '(charset))
5073 ;; Add a filename for the sake of saving the part again.
5074 (mml-insert-parameter
5075 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5076 (insert "\n")
5077 (insert "Content-ID: " (message-make-message-id) "\n")
5078 (insert "Content-Transfer-Encoding: binary\n")
5079 (insert "\n"))
5080 (setcdr data
5081 (cdr (mm-make-handle nil
5082 `("message/external-body"
5083 (access-type . "LOCAL-FILE")
5084 (name . ,file)))))
5085 ;; (set-buffer gnus-summary-buffer)
5086 (gnus-article-edit-part handles id))))
5088 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5089 ;; parts...>') but with stripping would be nice.
5091 (defun gnus-mime-delete-part ()
5092 "Delete the MIME part under point.
5093 Replace it with some information about the removed part."
5094 (interactive)
5095 (gnus-article-check-buffer)
5096 (when (gnus-group-read-only-p)
5097 (error "The current group does not support deleting of parts"))
5098 (when (mm-complicated-handles gnus-article-mime-handles)
5099 (error "\
5100 The current article has a complicated MIME structure, giving up..."))
5101 (when (or gnus-expert-user
5102 (gnus-yes-or-no-p "\
5103 Deleting parts may malfunction or destroy the article; continue? "))
5104 (let* ((data (get-text-property (point) 'gnus-data))
5105 (id (get-text-property (point) 'gnus-part))
5106 (handles gnus-article-mime-handles)
5107 (description
5108 (let ((desc (mm-handle-description data)))
5109 (when desc
5110 (mail-decode-encoded-word-string desc))))
5111 (filename (or (mm-handle-filename data) "(none)"))
5112 (type (mm-handle-media-type data)))
5113 (unless data
5114 (error "No MIME part under point"))
5115 (with-current-buffer (mm-handle-buffer data)
5116 (let ((bsize (buffer-size)))
5117 (erase-buffer)
5118 (insert
5119 (concat
5120 ",----\n"
5121 "| The following attachment has been deleted:\n"
5122 "|\n"
5123 "| Type: " type "\n"
5124 "| Filename: " filename "\n"
5125 "| Size (encoded): " (format "%s byte%s\n"
5126 bsize (if (= bsize 1)
5128 "s"))
5129 (when description
5130 (concat "| Description: " description "\n"))
5131 "`----\n"))
5132 (setcdr data
5133 (cdr (mm-make-handle
5134 nil `("text/plain" (charset . gnus-decoded)) nil nil
5135 (list "attachment")
5136 (format "Deleted attachment (%s bytes)" bsize))))))
5137 ;; (set-buffer gnus-summary-buffer)
5138 (gnus-article-edit-part handles id))))
5140 (defun gnus-mime-save-part ()
5141 "Save the MIME part under point."
5142 (interactive)
5143 (gnus-article-check-buffer)
5144 (let ((data (get-text-property (point) 'gnus-data)))
5145 (when data
5146 (mm-save-part data))))
5148 (defun gnus-mime-pipe-part (&optional cmd)
5149 "Pipe the MIME part under point to a process.
5150 Use CMD as the process."
5151 (interactive)
5152 (gnus-article-check-buffer)
5153 (let ((data (get-text-property (point) 'gnus-data)))
5154 (when data
5155 (mm-pipe-part data cmd))))
5157 (defun gnus-mime-view-part ()
5158 "Interactively choose a viewing method for the MIME part under point."
5159 (interactive)
5160 (gnus-article-check-buffer)
5161 (let ((data (get-text-property (point) 'gnus-data)))
5162 (when data
5163 (setq gnus-article-mime-handles
5164 (mm-merge-handles
5165 gnus-article-mime-handles (setq data (copy-sequence data))))
5166 (mm-interactively-view-part data))))
5168 (defun gnus-mime-view-part-as-type-internal ()
5169 (gnus-article-check-buffer)
5170 (let* ((handle (get-text-property (point) 'gnus-data))
5171 (name (or
5172 ;; Content-Type: foo/bar; name=...
5173 (mail-content-type-get (mm-handle-type handle) 'name)
5174 ;; Content-Disposition: attachment; filename=...
5175 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5176 (def-type (and name (mm-default-file-encoding name))))
5177 (or (and def-type (cons def-type 0))
5178 (and handle
5179 (equal (mm-handle-media-supertype handle) "text")
5180 '("text/plain" . 0))
5181 '("application/octet-stream" . 0))))
5183 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5184 "Choose a MIME media type, and view the part as such.
5185 If non-nil, PRED is a predicate to use during completion to limit the
5186 available media-types."
5187 (interactive)
5188 (unless mime-type
5189 (setq mime-type
5190 (let ((default (gnus-mime-view-part-as-type-internal)))
5191 (gnus-completing-read
5192 "View as MIME type"
5193 (if pred
5194 (gnus-remove-if-not pred (mailcap-mime-types))
5195 (mailcap-mime-types))
5196 nil nil nil
5197 (car default)))))
5198 (gnus-article-check-buffer)
5199 (let ((handle (get-text-property (point) 'gnus-data)))
5200 (when handle
5201 (when (equal (mm-handle-media-type handle) "message/external-body")
5202 (unless (mm-handle-cache handle)
5203 (mm-extern-cache-contents handle))
5204 (setq handle (mm-handle-cache handle)))
5205 (setq handle
5206 (mm-make-handle (mm-handle-buffer handle)
5207 (cons mime-type (cdr (mm-handle-type handle)))
5208 (mm-handle-encoding handle)
5209 (mm-handle-undisplayer handle)
5210 (mm-handle-disposition handle)
5211 (mm-handle-description handle)
5213 (mm-handle-id handle)))
5214 (setq gnus-article-mime-handles
5215 (mm-merge-handles gnus-article-mime-handles handle))
5216 (when (mm-handle-displayed-p handle)
5217 (mm-remove-part handle))
5218 (gnus-mm-display-part handle))))
5220 (defun gnus-mime-copy-part (&optional handle arg)
5221 "Put the MIME part under point into a new buffer.
5222 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5223 are decompressed."
5224 (interactive (list nil current-prefix-arg))
5225 (gnus-article-check-buffer)
5226 (unless handle
5227 (setq handle (get-text-property (point) 'gnus-data)))
5228 (when handle
5229 (let ((filename (mm-handle-filename handle))
5230 contents dont-decode charset coding-system)
5231 (mm-with-unibyte-buffer
5232 (mm-insert-part handle)
5233 (setq contents (or (condition-case nil
5234 (mm-decompress-buffer filename nil 'sig)
5235 (error
5236 (setq dont-decode t)
5237 nil))
5238 (buffer-string))))
5239 (setq filename (cond (filename (file-name-nondirectory filename))
5240 (dont-decode "*raw data*")
5241 (t "*decoded*")))
5242 (cond
5243 (dont-decode)
5244 ((not arg)
5245 (unless (setq charset (mail-content-type-get
5246 (mm-handle-type handle) 'charset))
5247 (unless (setq coding-system (mm-with-unibyte-buffer
5248 (insert contents)
5249 (mm-find-buffer-file-coding-system)))
5250 (setq charset gnus-newsgroup-charset))))
5251 ((numberp arg)
5252 (setq charset (or (cdr (assq arg
5253 gnus-summary-show-article-charset-alist))
5254 (mm-read-coding-system "Charset: ")))))
5255 (switch-to-buffer (generate-new-buffer filename))
5256 (if (or coding-system
5257 (and charset
5258 (setq coding-system (mm-charset-to-coding-system
5259 charset nil t))
5260 (not (eq coding-system 'ascii))))
5261 (progn
5262 (mm-enable-multibyte)
5263 (insert (mm-decode-coding-string contents coding-system))
5264 (setq buffer-file-coding-system
5265 (if (boundp 'last-coding-system-used)
5266 (symbol-value 'last-coding-system-used)
5267 coding-system)))
5268 (mm-disable-multibyte)
5269 (insert contents)
5270 (setq buffer-file-coding-system mm-binary-coding-system))
5271 ;; We do it this way to make `normal-mode' set the appropriate mode.
5272 (unwind-protect
5273 (progn
5274 (setq buffer-file-name (expand-file-name filename))
5275 (normal-mode))
5276 (setq buffer-file-name nil))
5277 (goto-char (point-min)))))
5279 (defun gnus-mime-print-part (&optional handle filename)
5280 "Print the MIME part under point."
5281 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5282 (gnus-article-check-buffer)
5283 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5284 (contents (and handle (mm-get-part handle)))
5285 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5286 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5287 (when contents
5288 (if printer
5289 (unwind-protect
5290 (progn
5291 (mm-save-part-to-file handle file)
5292 (call-process shell-file-name nil
5293 (generate-new-buffer " *mm*")
5295 shell-command-switch
5296 (mm-mailcap-command
5297 printer file (mm-handle-type handle))))
5298 (delete-file file))
5299 (with-temp-buffer
5300 (insert contents)
5301 (gnus-print-buffer))
5302 (ps-despool filename)))))
5304 (defun gnus-mime-inline-part (&optional handle arg)
5305 "Insert the MIME part under point into the current buffer.
5306 Compressed files like .gz and .bz2 are decompressed."
5307 (interactive (list nil current-prefix-arg))
5308 (gnus-article-check-buffer)
5309 (let* ((inhibit-read-only t)
5310 (b (point))
5311 (btn ;; position where the MIME button exists
5312 (if handle
5313 (if (eq handle (get-text-property b 'gnus-data))
5315 (article-goto-body)
5316 (or (text-property-any (point) (point-max) 'gnus-data handle)
5317 (text-property-any (point-min) (point) 'gnus-data handle)))
5318 (setq handle (get-text-property b 'gnus-data))
5320 start contents charset coding-system)
5321 (when handle
5322 (when (= b (prog1
5324 (setq start (next-single-property-change btn 'gnus-data
5325 nil (point-max))
5326 btn (previous-single-property-change start
5327 'gnus-data))))
5328 (setq b btn))
5329 (if (and (not arg) (mm-handle-undisplayer handle))
5330 (mm-remove-part handle)
5331 (mm-with-unibyte-buffer
5332 (mm-insert-part handle)
5333 (setq contents
5334 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5335 (buffer-string))))
5336 (cond
5337 ((not arg)
5338 (unless (setq charset (mail-content-type-get
5339 (mm-handle-type handle) 'charset))
5340 (unless (setq coding-system
5341 (mm-with-unibyte-buffer
5342 (insert contents)
5343 (mm-find-buffer-file-coding-system)))
5344 (setq charset gnus-newsgroup-charset))))
5345 ((numberp arg)
5346 (if (mm-handle-undisplayer handle)
5347 (mm-remove-part handle))
5348 (setq charset
5349 (or (cdr (assq arg
5350 gnus-summary-show-article-charset-alist))
5351 (mm-read-coding-system "Charset: "))))
5352 ((mm-handle-undisplayer handle)
5353 (mm-remove-part handle)))
5354 (goto-char start)
5355 (unless (bolp)
5356 ;; This is a header button.
5357 (forward-line 1))
5358 (mm-display-inline handle))
5359 ;; Toggle the button appearance between `[button]...' and `[button]'.
5360 (goto-char btn)
5361 (let ((displayed-p (mm-handle-displayed-p handle)))
5362 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5363 (list displayed-p))
5364 (if (featurep 'emacs)
5365 (delete-region
5366 (point)
5367 (next-single-property-change (point) 'gnus-data nil (point-max)))
5368 (let* ((end (next-single-property-change (point) 'gnus-data))
5369 (annots (annotations-at (or end (point-max)))))
5370 (delete-region (point)
5371 (if end
5372 (if annots (1+ end) end)
5373 (point-max)))
5374 (dolist (annot annots)
5375 (set-extent-endpoints annot (point) (point)))))
5376 (setq start (point))
5377 (if (search-backward "\n\n" nil t)
5378 (progn
5379 (goto-char start)
5380 (unless (or displayed-p (eolp))
5381 ;; Add extra newline.
5382 (insert (propertize (buffer-substring (1- start) start)
5383 'gnus-undeletable t))))
5384 ;; We're in the article header.
5385 (delete-char -1)
5386 (dolist (ovl (gnus-overlays-in btn (point)))
5387 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5388 (gnus-overlay-put ovl 'face nil))
5389 (save-restriction
5390 (message-narrow-to-field)
5391 (let ((gnus-treatment-function-alist
5392 '((gnus-treat-highlight-headers
5393 gnus-article-highlight-headers))))
5394 (gnus-treat-article 'head)))))
5395 (goto-char b))))
5397 (defun gnus-mime-set-charset-parameters (handle charset)
5398 "Set CHARSET to parameters in HANDLE.
5399 CHARSET may either be a string or a symbol."
5400 (unless (stringp charset)
5401 (setq charset (symbol-name charset)))
5402 (if (stringp (car handle))
5403 (dolist (h (cdr handle))
5404 (gnus-mime-set-charset-parameters h charset))
5405 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5406 "message/external-body")
5407 (progn
5408 (unless (mm-handle-cache handle)
5409 (mm-extern-cache-contents handle))
5410 (mm-handle-cache handle))
5411 handle)))
5412 (param (assq 'charset (cdr type))))
5413 (if param
5414 (setcdr param charset)
5415 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5417 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5418 "Insert the MIME part under point into the current buffer using the
5419 specified charset."
5420 (interactive (list nil current-prefix-arg))
5421 (gnus-article-check-buffer)
5422 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5423 (fun (get-text-property (point) 'gnus-callback))
5424 (gnus-newsgroup-ignored-charsets 'gnus-all)
5425 charset form preferred parts)
5426 (when handle
5427 (when (prog1
5428 (and fun
5429 (setq charset
5430 (or (cdr (assq
5432 gnus-summary-show-article-charset-alist))
5433 (mm-read-coding-system "Charset: "))))
5434 (if (mm-handle-undisplayer handle)
5435 (mm-remove-part handle)))
5436 (gnus-mime-set-charset-parameters handle charset)
5437 (when (and (consp (setq form (cdr-safe fun)))
5438 (setq form (ignore-errors
5439 (assq 'gnus-mime-display-alternative form)))
5440 (setq preferred (caddr form))
5441 (progn
5442 (when (eq (car preferred) 'quote)
5443 (setq preferred (cadr preferred)))
5444 (not (equal preferred
5445 (get-text-property (point) 'gnus-data))))
5446 (setq parts (get-text-property (point) 'gnus-part))
5447 (setq parts (cdr (assq parts
5448 gnus-article-mime-handle-alist)))
5449 (equal (mm-handle-media-type parts) "multipart/alternative")
5450 (setq parts (reverse (cdr parts))))
5451 (setcar (cddr form)
5452 (list 'quote (or (cadr (member preferred parts))
5453 (car parts)))))
5454 (funcall fun handle)))))
5456 (defun gnus-mime-view-part-externally (&optional handle)
5457 "View the MIME part under point with an external viewer."
5458 (interactive)
5459 (gnus-article-check-buffer)
5460 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5461 (mm-user-display-methods nil)
5462 (mm-inlined-types nil)
5463 (mail-parse-charset gnus-newsgroup-charset)
5464 (mail-parse-ignored-charsets
5465 (with-current-buffer gnus-summary-buffer
5466 gnus-newsgroup-ignored-charsets))
5467 (type (mm-handle-media-type handle))
5468 (method (mailcap-mime-info type))
5469 (mm-enable-external t))
5470 (if (not (stringp method))
5471 (gnus-mime-view-part-as-type
5472 nil (lambda (type) (stringp (mailcap-mime-info type))))
5473 (when handle
5474 (mm-display-part handle nil t)))))
5476 (defun gnus-mime-view-part-internally (&optional handle)
5477 "View the MIME part under point with an internal viewer.
5478 If no internal viewer is available, use an external viewer."
5479 (interactive)
5480 (gnus-article-check-buffer)
5481 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5482 (mm-inlined-types '(".*"))
5483 (mm-inline-large-images t)
5484 (mail-parse-charset gnus-newsgroup-charset)
5485 (mail-parse-ignored-charsets
5486 (with-current-buffer gnus-summary-buffer
5487 gnus-newsgroup-ignored-charsets))
5488 (inhibit-read-only t))
5489 (if (not (mm-inlinable-p handle))
5490 (gnus-mime-view-part-as-type
5491 nil (lambda (type) (mm-inlinable-p handle type)))
5492 (when handle
5493 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5495 (defun gnus-mime-action-on-part (&optional action)
5496 "Do something with the MIME attachment at \(point\)."
5497 (interactive
5498 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5499 (gnus-article-check-buffer)
5500 (let ((action-pair (assoc action gnus-mime-action-alist)))
5501 (if action-pair
5502 (funcall (cdr action-pair)))))
5504 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5505 "Call FUNCTION on MIME part N.
5506 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5507 If INTERACTIVE, call FUNCTION interactively."
5508 (let (window frame)
5509 ;; Check whether the article is displayed.
5510 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5511 (setq window (get-buffer-window gnus-article-buffer t))
5512 (frame-visible-p (setq frame (window-frame window))))
5513 (error "No article is displayed"))
5514 (with-current-buffer gnus-article-buffer
5515 ;; Check whether the article displays the right contents.
5516 (unless (with-current-buffer gnus-summary-buffer
5517 (eq gnus-current-article (gnus-summary-article-number)))
5518 (error "You should select the right article first"))
5519 (if n
5520 (setq n (prefix-numeric-value n))
5521 (let ((pt (point)))
5522 (setq n (or (get-text-property pt 'gnus-part)
5523 (and (not (bobp))
5524 (get-text-property (1- pt) 'gnus-part))
5525 (get-text-property (prog2
5526 (forward-line 1)
5527 (point)
5528 (goto-char pt))
5529 'gnus-part)
5530 (get-text-property
5531 (or (and (setq pt (previous-single-property-change
5532 pt 'gnus-part))
5533 (1- pt))
5534 (next-single-property-change (point) 'gnus-part)
5535 (point))
5536 'gnus-part)
5537 1))))
5538 ;; Check whether the specified part exists.
5539 (when (> n (length gnus-article-mime-handle-alist))
5540 (error "No such part")))
5541 (unless
5542 (progn
5543 ;; To select the window is needed so that the cursor
5544 ;; might be visible on the MIME button.
5545 (select-window (prog1
5546 window
5547 (setq window (selected-window))
5548 ;; Article may be displayed in the other frame.
5549 (gnus-select-frame-set-input-focus
5550 (prog1
5551 frame
5552 (setq frame (selected-frame))))))
5553 (when (gnus-article-goto-part n)
5554 ;; We point the cursor and the arrow at the MIME button
5555 ;; when the `function' prompt the user for something.
5556 (unless (and (pos-visible-in-window-p)
5557 (> (count-lines (point) (window-end))
5558 (/ (1- (window-height)) 3)))
5559 (recenter (/ (1- (window-height)) 3)))
5560 (let ((cursor-in-non-selected-windows t)
5561 (overlay-arrow-string "=>")
5562 (overlay-arrow-position (point-marker)))
5563 (unwind-protect
5564 (cond
5565 ((and no-handle interactive)
5566 (call-interactively function))
5567 (no-handle
5568 (funcall function))
5569 (interactive
5570 (call-interactively
5571 function (get-text-property (point) 'gnus-data)))
5573 (funcall function
5574 (get-text-property (point) 'gnus-data))))
5575 (set-marker overlay-arrow-position nil)
5576 (unless gnus-auto-select-part
5577 (gnus-select-frame-set-input-focus frame)
5578 (select-window window))))
5580 (if gnus-inhibit-mime-unbuttonizing
5581 ;; This is the default though the program shouldn't reach here.
5582 (error "No such part")
5583 ;; The part which doesn't have the MIME button is selected.
5584 ;; So, we display all the buttons and redo it.
5585 (let ((gnus-inhibit-mime-unbuttonizing t))
5586 (gnus-summary-show-article)
5587 (gnus-article-part-wrapper n function no-handle))))))
5589 (defun gnus-article-pipe-part (n)
5590 "Pipe MIME part N, which is the numerical prefix."
5591 (interactive "P")
5592 (gnus-article-part-wrapper n 'mm-pipe-part))
5594 (defun gnus-article-save-part (n)
5595 "Save MIME part N, which is the numerical prefix."
5596 (interactive "P")
5597 (gnus-article-part-wrapper n 'mm-save-part))
5599 (defun gnus-article-interactively-view-part (n)
5600 "View MIME part N interactively, which is the numerical prefix."
5601 (interactive "P")
5602 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5604 (defun gnus-article-copy-part (n)
5605 "Copy MIME part N, which is the numerical prefix."
5606 (interactive "P")
5607 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5609 (defun gnus-article-view-part-as-charset (n)
5610 "View MIME part N using a specified charset.
5611 N is the numerical prefix."
5612 (interactive "P")
5613 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5615 (defun gnus-article-view-part-externally (n)
5616 "View MIME part N externally, which is the numerical prefix."
5617 (interactive "P")
5618 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5620 (defun gnus-article-inline-part (n)
5621 "Inline MIME part N, which is the numerical prefix."
5622 (interactive "P")
5623 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5625 (defun gnus-article-save-part-and-strip (n)
5626 "Save MIME part N and replace it with an external body.
5627 N is the numerical prefix."
5628 (interactive "P")
5629 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5631 (defun gnus-article-replace-part (n)
5632 "Replace MIME part N with an external body.
5633 N is the numerical prefix."
5634 (interactive "P")
5635 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5637 (defun gnus-article-delete-part (n)
5638 "Delete MIME part N and add some information about the removed part.
5639 N is the numerical prefix."
5640 (interactive "P")
5641 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5643 (defun gnus-article-view-part-as-type (n)
5644 "Choose a MIME media type, and view part N as such.
5645 N is the numerical prefix."
5646 (interactive "P")
5647 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5649 (defun gnus-article-mime-match-handle-first (condition)
5650 (if condition
5651 (let (n)
5652 (dolist (ihandle gnus-article-mime-handle-alist)
5653 (if (and (cond
5654 ((functionp condition)
5655 (funcall condition (cdr ihandle)))
5656 ((eq condition 'undisplayed)
5657 (not (or (mm-handle-undisplayer (cdr ihandle))
5658 (equal (mm-handle-media-type (cdr ihandle))
5659 "multipart/alternative"))))
5660 ((eq condition 'undisplayed-alternative)
5661 (not (mm-handle-undisplayer (cdr ihandle))))
5662 (t t))
5663 (gnus-article-goto-part (car ihandle))
5664 (or (not n) (< (car ihandle) n)))
5665 (setq n (car ihandle))))
5666 (or n 1))
5669 (defun gnus-article-view-part (&optional n)
5670 "View MIME part N, which is the numerical prefix.
5671 If the part is already shown, hide the part. If N is nil, view
5672 all parts."
5673 (interactive "P")
5674 (with-current-buffer gnus-article-buffer
5675 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5676 gnus-article-mime-match-handle-function)))
5677 (when (> n (length gnus-article-mime-handle-alist))
5678 (error "No such part"))
5679 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5680 (when (gnus-article-goto-part n)
5681 (if (equal (car handle) "multipart/alternative")
5682 (progn
5683 (beginning-of-line) ;; Make it toggle subparts
5684 (gnus-article-press-button))
5685 (when (eq (gnus-mm-display-part handle) 'internal)
5686 (gnus-set-window-start)))))))
5688 (defsubst gnus-article-mime-total-parts ()
5689 (if (bufferp (car gnus-article-mime-handles))
5690 1 ;; single part
5691 (1- (length gnus-article-mime-handles))))
5693 (defun gnus-mm-display-part (handle)
5694 "Display HANDLE and fix MIME button."
5695 (let ((id (get-text-property (point) 'gnus-part))
5696 (point (point))
5697 (inhibit-read-only t)
5698 (window (selected-window))
5699 (mail-parse-charset gnus-newsgroup-charset)
5700 (mail-parse-ignored-charsets
5701 (if (gnus-buffer-live-p gnus-summary-buffer)
5702 (with-current-buffer gnus-summary-buffer
5703 gnus-newsgroup-ignored-charsets)
5704 nil))
5705 start retval)
5706 (unwind-protect
5707 (progn
5708 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5709 (when win
5710 (select-window win)
5711 (goto-char point)))
5712 (setq start (next-single-property-change point 'gnus-data
5713 nil (point-max))
5714 point (previous-single-property-change start 'gnus-data))
5715 (if (mm-handle-displayed-p handle)
5716 ;; This will remove the part.
5717 (setq retval (mm-display-part handle))
5718 (let ((part (or (and (mm-inlinable-p handle)
5719 (mm-inlined-p handle)
5721 (with-temp-buffer
5722 (gnus-bind-safe-url-regexp
5723 (setq retval (mm-display-part handle)))
5724 (unless (zerop (buffer-size))
5725 (buffer-string))))))
5726 (goto-char start)
5727 (unless (bolp)
5728 ;; This is a header button.
5729 (forward-line 1))
5730 (cond ((stringp part)
5731 (save-restriction
5732 (narrow-to-region (point)
5733 (progn
5734 (insert part)
5735 (unless (bolp) (insert "\n"))
5736 (point)))
5737 (gnus-treat-article nil id
5738 (gnus-article-mime-total-parts)
5739 (mm-handle-media-type handle))
5740 (mm-handle-set-undisplayer
5741 handle
5742 `(lambda ()
5743 (let ((inhibit-read-only t))
5744 (delete-region ,(copy-marker (point-min) t)
5745 ,(point-max-marker)))))))
5746 (part
5747 (mm-display-inline handle))))))
5748 (goto-char point)
5749 ;; Toggle the button appearance between `[button]...' and `[button]'.
5750 (let ((displayed-p (mm-handle-displayed-p handle)))
5751 (gnus-insert-mime-button handle id (list displayed-p))
5752 (if (featurep 'emacs)
5753 (delete-region
5754 (point)
5755 (next-single-property-change (point) 'gnus-data nil (point-max)))
5756 (let* ((end (next-single-property-change (point) 'gnus-data))
5757 (annots (annotations-at (or end (point-max)))))
5758 (delete-region (point)
5759 (if end
5760 (if annots (1+ end) end)
5761 (point-max)))
5762 (dolist (annot annots)
5763 (set-extent-endpoints annot (point) (point)))))
5764 (setq start (point))
5765 (if (search-backward "\n\n" nil t)
5766 (progn
5767 (goto-char start)
5768 (unless (or displayed-p (eolp))
5769 ;; Add extra newline.
5770 (insert (propertize (buffer-substring (1- start) start)
5771 'gnus-undeletable t))))
5772 ;; We're in the article header.
5773 (delete-char -1)
5774 (dolist (ovl (gnus-overlays-in point (point)))
5775 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5776 (gnus-overlay-put ovl 'face nil))
5777 (save-restriction
5778 (message-narrow-to-field)
5779 (let ((gnus-treatment-function-alist
5780 '((gnus-treat-highlight-headers
5781 gnus-article-highlight-headers))))
5782 (gnus-treat-article 'head)))))
5783 (goto-char point)
5784 (if (window-live-p window)
5785 (select-window window)))
5786 retval))
5788 (defun gnus-article-goto-part (n)
5789 "Go to MIME part N."
5790 (when gnus-break-pages
5791 (widen))
5792 (article-goto-body)
5793 (prog1
5794 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5795 ;; There may be header buttons.
5796 (text-property-any (point-min) (point) 'gnus-part n)))
5797 part handle end next handles)
5798 (when start
5799 (goto-char start)
5800 (if (setq handle (get-text-property start 'gnus-data))
5801 start
5802 ;; Go to the displayed subpart, assuming this is
5803 ;; multipart/alternative.
5804 (setq part start
5805 end (point-at-eol))
5806 (while (and (not handle)
5807 part
5808 (< part end)
5809 (setq next (text-property-not-all part end
5810 'gnus-data nil)))
5811 (setq part next
5812 handle (get-text-property part 'gnus-data))
5813 (push (cons handle part) handles)
5814 (unless (mm-handle-displayed-p handle)
5815 (setq handle nil
5816 part (text-property-any part end 'gnus-data nil))))
5817 (unless handle
5818 ;; No subpart is displayed, so we find preferred one.
5819 (setq part
5820 (cdr (assq (mm-preferred-alternative
5821 (nreverse (mapcar 'car handles)))
5822 handles))))
5823 (if part
5824 (goto-char (1+ part))
5825 start))))
5826 (when gnus-break-pages
5827 (gnus-narrow-to-page))))
5829 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5830 (let ((gnus-tmp-name
5831 (or (mm-handle-filename handle)
5832 (mail-content-type-get (mm-handle-type handle) 'url)
5833 ""))
5834 (gnus-tmp-type (mm-handle-media-type handle))
5835 (gnus-tmp-description (or (mm-handle-description handle) ""))
5836 (gnus-tmp-dots
5837 (if (if displayed (car displayed)
5838 (mm-handle-displayed-p handle))
5839 "" "..."))
5840 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5841 (buffer-size)))
5842 gnus-tmp-type-long b e)
5843 (when (string-match ".*/" gnus-tmp-name)
5844 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5845 (setq gnus-tmp-type-long (concat gnus-tmp-type
5846 (and (not (equal gnus-tmp-name ""))
5847 (concat "; " gnus-tmp-name))))
5848 (unless (equal gnus-tmp-description "")
5849 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5850 (setq b (point))
5851 (gnus-eval-format
5852 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5853 `(keymap ,gnus-mime-button-map
5854 gnus-callback gnus-mm-display-part
5855 gnus-part ,gnus-tmp-id
5856 article-type annotation
5857 gnus-data ,handle
5858 rear-nonsticky t))
5859 (setq e (if (bolp)
5860 ;; Exclude a newline.
5861 (1- (point))
5862 (point)))
5863 (when gnus-article-button-face
5864 (gnus-overlay-put (gnus-make-overlay b e nil t)
5865 'face gnus-article-button-face))
5866 (widget-convert-button
5867 'link b e
5868 :mime-handle handle
5869 :action 'gnus-widget-press-button
5870 :button-keymap gnus-mime-button-map
5871 :help-echo
5872 (lambda (widget)
5873 ;; Needed to properly clear the message due to a bug in
5874 ;; wid-edit (XEmacs only).
5875 (if (boundp 'help-echo-owns-message)
5876 (setq help-echo-owns-message t))
5877 (format
5878 "%S: %s the MIME part; %S: more options"
5879 (aref gnus-mouse-2 0)
5880 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5881 "hide" "show")
5882 (aref gnus-down-mouse-3 0))))))
5884 (defun gnus-widget-press-button (elems el)
5885 (goto-char (widget-get elems :from))
5886 (gnus-article-press-button))
5888 (defvar gnus-displaying-mime nil)
5890 (defun gnus-display-mime (&optional ihandles)
5891 "Display the MIME parts."
5892 (save-excursion
5893 (save-selected-window
5894 (let ((window (get-buffer-window gnus-article-buffer))
5895 (point (point)))
5896 (when window
5897 (select-window window)
5898 ;; We have to do this since selecting the window
5899 ;; may change the point. So we set the window point.
5900 (set-window-point window point)))
5901 (let ((handles ihandles)
5902 (inhibit-read-only t)
5903 handle)
5904 (cond (handles)
5905 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5906 (when gnus-article-emulate-mime
5907 (mm-uu-dissect-text-parts handles)))
5908 (gnus-article-emulate-mime
5909 (setq handles (mm-uu-dissect))))
5910 (when (and (not ihandles)
5911 (not gnus-displaying-mime))
5912 ;; Top-level call; we clean up.
5913 (when gnus-article-mime-handles
5914 (mm-destroy-parts gnus-article-mime-handles)
5915 (setq gnus-article-mime-handle-alist nil));; A trick.
5916 (setq gnus-article-mime-handles handles)
5917 ;; We allow users to glean info from the handles.
5918 (when gnus-article-mime-part-function
5919 (gnus-mime-part-function handles)))
5920 (if (and handles
5921 (or (not (stringp (car handles)))
5922 (cdr handles)))
5923 (progn
5924 (when (and (not ihandles)
5925 (not gnus-displaying-mime))
5926 ;; Clean up for mime parts.
5927 (article-goto-body)
5928 (delete-region (point) (point-max)))
5929 (let ((gnus-displaying-mime t))
5930 (gnus-mime-display-part handles)))
5931 (save-restriction
5932 (article-goto-body)
5933 (narrow-to-region (point) (point-max))
5934 (gnus-treat-article nil 1 1 "text/plain")
5935 (widen)))
5936 (unless ihandles
5937 ;; Highlight the headers.
5938 (save-excursion
5939 (save-restriction
5940 (article-goto-body)
5941 (narrow-to-region (point-min) (point))
5942 (gnus-article-save-original-date
5943 (gnus-treat-article 'head)))))))
5944 ;; Cope with broken MIME messages.
5945 (goto-char (point-max))
5946 (unless (bolp)
5947 (insert "\n"))))
5949 (defcustom gnus-mime-display-multipart-as-mixed nil
5950 "Display \"multipart\" parts as \"multipart/mixed\".
5952 If t, it overrides nil values of
5953 `gnus-mime-display-multipart-alternative-as-mixed' and
5954 `gnus-mime-display-multipart-related-as-mixed'."
5955 :group 'gnus-article-mime
5956 :type 'boolean)
5958 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5959 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5960 :version "22.1"
5961 :group 'gnus-article-mime
5962 :type 'boolean)
5964 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5965 "Display \"multipart/related\" parts as \"multipart/mixed\".
5967 If displaying \"text/html\" is discouraged \(see
5968 `mm-discouraged-alternatives'\) images or other material inside a
5969 \"multipart/related\" part might be overlooked when this variable is nil."
5970 :version "22.1"
5971 :group 'gnus-article-mime
5972 :type 'boolean)
5974 (defcustom gnus-mime-display-attachment-buttons-in-header t
5975 "Add attachment buttons in the end of the header of an article.
5976 Since MIME attachments tend to be put at the end of an article, we may
5977 overlook them if there is a huge body. This option offers you a copy
5978 of all non-inlinable MIME parts as buttons shown in front of an article.
5979 If nil, don't show those extra buttons."
5980 :version "24.5"
5981 :group 'gnus-article-mime
5982 :type 'boolean)
5984 (defun gnus-mime-display-part (handle)
5985 (cond
5986 ;; Maybe a broken MIME message.
5987 ((null handle))
5988 ;; Single part.
5989 ((not (stringp (car handle)))
5990 (gnus-mime-display-single handle))
5991 ;; User-defined multipart
5992 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5993 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5994 handle))
5995 ;; multipart/alternative
5996 ((and (equal (car handle) "multipart/alternative")
5997 (not (or gnus-mime-display-multipart-as-mixed
5998 gnus-mime-display-multipart-alternative-as-mixed)))
5999 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6000 (push (cons id handle) gnus-article-mime-handle-alist)
6001 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6002 ;; multipart/related
6003 ((and (equal (car handle) "multipart/related")
6004 (not (or gnus-mime-display-multipart-as-mixed
6005 gnus-mime-display-multipart-related-as-mixed)))
6006 (gnus-mime-display-part (cadr handle)))
6007 ((equal (car handle) "multipart/signed")
6008 (gnus-add-wash-type 'signed)
6009 (gnus-mime-display-security handle))
6010 ((equal (car handle) "multipart/encrypted")
6011 (gnus-add-wash-type 'encrypted)
6012 (gnus-mime-display-security handle))
6013 ;; Other multiparts are handled like multipart/mixed.
6015 (gnus-mime-display-mixed (cdr handle)))))
6017 (defun gnus-mime-part-function (handles)
6018 (if (stringp (car handles))
6019 (mapcar 'gnus-mime-part-function (cdr handles))
6020 (funcall gnus-article-mime-part-function handles)))
6022 (defun gnus-mime-display-mixed (handles)
6023 (mapcar 'gnus-mime-display-part handles))
6025 (defun gnus-mime-display-single (handle)
6026 (let ((type (mm-handle-media-type handle))
6027 (ignored gnus-ignored-mime-types)
6028 (not-attachment t)
6029 display text)
6030 (catch 'ignored
6031 (progn
6032 (while ignored
6033 (when (string-match (pop ignored) type)
6034 (throw 'ignored nil)))
6035 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6036 (with-current-buffer gnus-summary-buffer
6037 gnus-inhibit-images)
6038 gnus-inhibit-images)
6039 (string-match "\\`image/" type)))
6040 (setq not-attachment
6041 (and (not (mm-inline-override-p handle))
6042 (or (not (mm-handle-disposition handle))
6043 (equal (car (mm-handle-disposition handle))
6044 "inline")
6045 (mm-attachment-override-p handle))))
6046 (mm-automatic-display-p handle)
6047 (or (and
6048 (mm-inlinable-p handle)
6049 (mm-inlined-p handle))
6050 (mm-automatic-external-display-p type)))
6051 (setq display t)
6052 (when (equal (mm-handle-media-supertype handle) "text")
6053 (setq text t)))
6054 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6055 beg)
6056 (unless id
6057 (setq id (1+ (length gnus-article-mime-handle-alist)))
6058 (push (cons id handle) gnus-article-mime-handle-alist))
6059 (when (and display
6060 (equal (mm-handle-media-supertype handle) "message"))
6061 (insert-char
6063 (cond ((not (bolp)) 2)
6064 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6065 (t 1))))
6066 (when (or (not display)
6067 (not (gnus-unbuttonized-mime-type-p type))
6068 (eq id gnus-mime-buttonized-part-id))
6069 (gnus-insert-mime-button
6070 handle id (list (or display (and not-attachment text)))))
6071 (setq beg (point))
6072 (cond
6073 (display
6074 (let ((mail-parse-charset gnus-newsgroup-charset)
6075 (mail-parse-ignored-charsets
6076 (save-excursion (condition-case ()
6077 (set-buffer gnus-summary-buffer)
6078 (error))
6079 gnus-newsgroup-ignored-charsets)))
6080 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6081 ((and text not-attachment)
6082 (mm-display-inline handle)))
6083 (goto-char (point-max))
6084 (if (string-match "\\`image/" type)
6085 (gnus-article-insert-newline)
6086 (if (prog1
6087 (= (skip-chars-backward "\n") -1)
6088 (forward-char 1))
6089 (gnus-article-insert-newline)
6090 (put-text-property (point) (point-max) 'gnus-undeletable t))
6091 (goto-char (point-max)))
6092 ;; Do highlighting.
6093 (save-excursion
6094 (save-restriction
6095 (narrow-to-region beg (point))
6096 (if (eq handle gnus-article-mime-handles)
6097 ;; The format=flowed case.
6098 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6099 ;; Don't count signature parts that are never displayed.
6100 ;; The part number should be re-calculated supposing this
6101 ;; might be a message/rfc822 part.
6102 (let (handles)
6103 (dolist (part gnus-article-mime-handles)
6104 (unless (or (stringp part)
6105 (equal (car (mm-handle-type part))
6106 "application/pgp-signature"))
6107 (push part handles)))
6108 (gnus-treat-article
6109 nil (length (memq handle handles)) (length handles)
6110 (mm-handle-media-type handle)))))))))))
6112 (defun gnus-unbuttonized-mime-type-p (type)
6113 "Say whether TYPE is to be unbuttonized."
6114 (unless gnus-inhibit-mime-unbuttonizing
6115 (when (catch 'found
6116 (let ((types gnus-unbuttonized-mime-types))
6117 (while types
6118 (when (string-match (pop types) type)
6119 (throw 'found t)))))
6120 (not (catch 'found
6121 (let ((types gnus-buttonized-mime-types))
6122 (while types
6123 (when (string-match (pop types) type)
6124 (throw 'found t)))))))))
6126 (defun gnus-article-insert-newline ()
6127 "Insert a newline, but mark it as undeletable."
6128 (gnus-put-text-property
6129 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6131 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6132 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6133 (ihandles handles)
6134 (point (point))
6135 handle (inhibit-read-only t) from props begend not-pref)
6136 (save-window-excursion
6137 (save-restriction
6138 (when ibegend
6139 (narrow-to-region (car ibegend)
6140 (or (cdr ibegend)
6141 (progn
6142 (goto-char (car ibegend))
6143 (forward-line 2)
6144 (point))))
6145 (delete-region (point-min) (point-max))
6146 (mm-remove-parts handles))
6147 (setq begend (list (point-marker)))
6148 ;; Do the toggle.
6149 (unless (setq not-pref (cadr (member preferred ihandles)))
6150 (setq not-pref (car ihandles)))
6151 (when (or ibegend
6152 (not preferred)
6153 (not (gnus-unbuttonized-mime-type-p
6154 "multipart/alternative")))
6155 (gnus-add-text-properties
6156 (setq from (point))
6157 (progn
6158 (insert (format "%d. " id))
6159 (point))
6160 `(gnus-callback
6161 (lambda (handles)
6162 (unless ,(not ibegend)
6163 (setq gnus-article-mime-handle-alist
6164 ',gnus-article-mime-handle-alist))
6165 (gnus-mime-display-alternative
6166 ',ihandles ',not-pref ',begend ,id))
6167 keymap ,gnus-mime-button-map
6168 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6169 face ,gnus-article-button-face
6170 gnus-part ,id
6171 article-type multipart
6172 rear-nonsticky t))
6173 (widget-convert-button 'link from (point)
6174 :action 'gnus-widget-press-button
6175 :button-keymap gnus-widget-button-keymap)
6176 ;; Do the handles
6177 (while (setq handle (pop handles))
6178 (gnus-add-text-properties
6179 (setq from (point))
6180 (progn
6181 (insert (format "(%c) %-18s"
6182 (if (equal handle preferred) ?* ? )
6183 (mm-handle-media-type handle)))
6184 (point))
6185 `(gnus-callback
6186 (lambda (handles)
6187 (unless ,(not ibegend)
6188 (setq gnus-article-mime-handle-alist
6189 ',gnus-article-mime-handle-alist))
6190 (gnus-mime-display-alternative
6191 ',ihandles ',handle ',begend ,id))
6192 keymap ,gnus-mime-button-map
6193 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6194 face ,gnus-article-button-face
6195 gnus-part ,id
6196 gnus-data ,handle
6197 rear-nonsticky t))
6198 (widget-convert-button 'link from (point)
6199 :action 'gnus-widget-press-button
6200 :button-keymap gnus-widget-button-keymap)
6201 (insert " "))
6202 (insert "\n\n"))
6203 (when preferred
6204 (if (stringp (car preferred))
6205 (gnus-display-mime preferred)
6206 (let ((mail-parse-charset gnus-newsgroup-charset)
6207 (mail-parse-ignored-charsets
6208 (with-current-buffer gnus-summary-buffer
6209 gnus-newsgroup-ignored-charsets)))
6210 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6211 ;; Do highlighting.
6212 (save-excursion
6213 (save-restriction
6214 (narrow-to-region (car begend) (point-max))
6215 (gnus-treat-article
6216 nil (length gnus-article-mime-handle-alist)
6217 (gnus-article-mime-total-parts)
6218 (mm-handle-media-type preferred))))))
6219 (goto-char (point-max))
6220 (setcdr begend (point-marker)))))
6221 (when ibegend
6222 (goto-char point)))
6223 ;; Redraw attachment buttons in the header.
6224 (when gnus-mime-display-attachment-buttons-in-header
6225 (gnus-mime-buttonize-attachments-in-header)))
6227 (defconst gnus-article-wash-status-strings
6228 (let ((alist '((cite "c" "Possible hidden citation text"
6229 " " "All citation text visible")
6230 (headers "h" "Hidden headers"
6231 " " "All headers visible.")
6232 (pgp "p" "Encrypted or signed message status hidden"
6233 " " "No hidden encryption nor digital signature status")
6234 (signature "s" "Signature has been hidden"
6235 " " "Signature is visible")
6236 (overstrike "o" "Overstrike (^H) characters applied"
6237 " " "No overstrike characters applied")
6238 (emphasis "e" "/*_Emphasis_*/ characters applied"
6239 " " "No /*_emphasis_*/ characters applied")))
6240 result)
6241 (dolist (entry alist result)
6242 (let ((key (nth 0 entry))
6243 (on (copy-sequence (nth 1 entry)))
6244 (on-help (nth 2 entry))
6245 (off (copy-sequence (nth 3 entry)))
6246 (off-help (nth 4 entry)))
6247 (put-text-property 0 1 'help-echo on-help on)
6248 (put-text-property 0 1 'help-echo off-help off)
6249 (push (list key on off) result))))
6250 "Alist of strings describing wash status in the mode line.
6251 Each entry has the form (KEY ON OF), where the KEY is a symbol
6252 representing the particular washing function, ON is the string to use
6253 in the article mode line when the washing function is active, and OFF
6254 is the string to use when it is inactive.")
6256 (defun gnus-article-wash-status-entry (key value)
6257 (let ((entry (assoc key gnus-article-wash-status-strings)))
6258 (if value (nth 1 entry) (nth 2 entry))))
6260 (defun gnus-article-wash-status ()
6261 "Return a string which display status of article washing."
6262 (with-current-buffer gnus-article-buffer
6263 (let ((cite (memq 'cite gnus-article-wash-types))
6264 (headers (memq 'headers gnus-article-wash-types))
6265 (boring (memq 'boring-headers gnus-article-wash-types))
6266 (pgp (memq 'pgp gnus-article-wash-types))
6267 (pem (memq 'pem gnus-article-wash-types))
6268 (signed (memq 'signed gnus-article-wash-types))
6269 (encrypted (memq 'encrypted gnus-article-wash-types))
6270 (signature (memq 'signature gnus-article-wash-types))
6271 (overstrike (memq 'overstrike gnus-article-wash-types))
6272 (emphasis (memq 'emphasis gnus-article-wash-types)))
6273 (concat
6274 (gnus-article-wash-status-entry 'cite cite)
6275 (gnus-article-wash-status-entry 'headers (or headers boring))
6276 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6277 (gnus-article-wash-status-entry 'signature signature)
6278 (gnus-article-wash-status-entry 'overstrike overstrike)
6279 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6281 (defun gnus-add-wash-type (type)
6282 "Add a washing of TYPE to the current status."
6283 (add-to-list 'gnus-article-wash-types type))
6285 (defun gnus-delete-wash-type (type)
6286 "Add a washing of TYPE to the current status."
6287 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6289 (defun gnus-add-image (category image)
6290 "Add IMAGE of CATEGORY to the list of displayed images."
6291 (let ((entry (assq category gnus-article-image-alist)))
6292 (unless entry
6293 (setq entry (list category))
6294 (push entry gnus-article-image-alist))
6295 (nconc entry (list image))))
6297 (defun gnus-delete-images (category)
6298 "Delete all images in CATEGORY."
6299 (let ((entry (assq category gnus-article-image-alist)))
6300 (dolist (image (cdr entry))
6301 (gnus-remove-image image category))
6302 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6303 (gnus-delete-wash-type category)))
6305 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6307 (defun gnus-article-maybe-hide-headers ()
6308 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6309 Provided for backwards compatibility."
6310 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6311 (not (with-current-buffer gnus-summary-buffer
6312 gnus-have-all-headers)))
6313 (not gnus-inhibit-hiding))
6314 (gnus-article-hide-headers)))
6316 (declare-function shr-put-image "shr" (data alt &optional flags))
6318 (defun gnus-shr-put-image (data alt &optional flags)
6319 "Put image DATA with a string ALT. Enable image to be deleted."
6320 (let ((image (if flags
6321 (shr-put-image data (propertize (or alt "*")
6322 'gnus-image-category 'shr)
6323 flags)
6324 ;; Old `shr-put-image' doesn't take the optional `flags'
6325 ;; argument.
6326 (shr-put-image data (propertize (or alt "*")
6327 'gnus-image-category 'shr)))))
6328 (when image
6329 (gnus-add-image 'shr image))))
6331 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6332 "Show attachments as buttons in the end of the header of an article.
6333 This function toggles the display when called interactively. Note that
6334 buttons to be added to the header are only the ones that aren't inlined
6335 in the body. Use `gnus-header-face-alist' to highlight buttons."
6336 (interactive (list t))
6337 (gnus-with-article-buffer
6338 (gmm-labels
6339 ;; Function that returns a flattened version of
6340 ;; `gnus-article-mime-handle-alist'.
6341 ((flattened-alist
6342 (&optional alist id all)
6343 (if alist
6344 (let ((i 1) newid flat)
6345 (dolist (handle alist flat)
6346 (setq newid (append id (list i))
6347 i (1+ i))
6348 (if (stringp (car handle))
6349 (setq flat (nconc flat (flattened-alist (cdr handle)
6350 newid all)))
6351 (delq (rassq handle all) all)
6352 (setq flat (nconc flat (list (cons newid handle)))))))
6353 (let ((flat (list nil)))
6354 ;; Assume that elements of `gnus-article-mime-handle-alist'
6355 ;; are in the decreasing order, but unnumbered subsidiaries
6356 ;; in each element are in the increasing order.
6357 (dolist (handle (reverse gnus-article-mime-handle-alist))
6358 (if (stringp (cadr handle))
6359 (setq flat (nconc flat (flattened-alist (cddr handle)
6360 (list (car handle))
6361 flat)))
6362 (delq (rassq (cdr handle) flat) flat)
6363 (setq flat (nconc flat (list (cons (list (car handle))
6364 (cdr handle)))))))
6365 (setq flat (cdr flat))
6366 (mapc (lambda (handle)
6367 (if (cdar handle)
6368 ;; This is a hidden (i.e. unnumbered) handle.
6369 (progn
6370 (setcar handle
6371 (1+ (caar gnus-article-mime-handle-alist)))
6372 (push handle gnus-article-mime-handle-alist))
6373 (setcar handle (caar handle))))
6374 flat)
6375 flat))))
6376 (let ((case-fold-search t) buttons handle type st)
6377 (save-excursion
6378 (save-restriction
6379 (widen)
6380 (article-narrow-to-head)
6381 ;; Header buttons exist?
6382 (while (and (not buttons)
6383 (re-search-forward "^attachments?:[\n ]+" nil t))
6384 (when (get-char-property (match-end 0)
6385 'gnus-button-attachment-extra)
6386 (setq buttons (match-beginning 0))))
6387 (widen)
6388 (when buttons
6389 ;; Delete header buttons.
6390 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6391 (match-beginning 0)
6392 (point-max))))
6393 (unless (and interactive buttons)
6394 ;; Find buttons.
6395 (setq buttons nil)
6396 (dolist (button (flattened-alist))
6397 (setq handle (cdr button)
6398 type (mm-handle-media-type handle))
6399 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6400 (with-current-buffer gnus-summary-buffer
6401 gnus-inhibit-images)
6402 gnus-inhibit-images)
6403 (string-match "\\`image/" type))
6404 (mm-inline-override-p handle)
6405 (and (mm-handle-disposition handle)
6406 (not (equal (car (mm-handle-disposition handle))
6407 "inline"))
6408 (not (mm-attachment-override-p handle)))
6409 (not (mm-automatic-display-p handle))
6410 (not (or (and (mm-inlinable-p handle)
6411 (mm-inlined-p handle))
6412 (mm-automatic-external-display-p type))))
6413 (push button buttons)))
6414 (when buttons
6415 ;; Add header buttons.
6416 (article-goto-body)
6417 (forward-line -1)
6418 (narrow-to-region (point) (point))
6419 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6420 (dolist (button (nreverse buttons))
6421 (setq st (point))
6422 (insert " ")
6423 (mm-handle-set-undisplayer
6424 (setq handle (copy-sequence (cdr button))) nil)
6425 (gnus-insert-mime-button handle (car button))
6426 (skip-chars-backward "\t\n ")
6427 (delete-region (point) (point-max))
6428 (when (> (current-column) (window-width))
6429 (goto-char st)
6430 (insert "\n")
6431 (end-of-line)))
6432 (insert "\n")
6433 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6434 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6435 (gnus-overlay-put ovl 'face nil))
6436 (let ((gnus-treatment-function-alist
6437 '((gnus-treat-highlight-headers
6438 gnus-article-highlight-headers))))
6439 (gnus-treat-article 'head))))))))))
6441 ;;; Article savers.
6443 (defun gnus-output-to-file (file-name)
6444 "Append the current article to a file named FILE-NAME.
6445 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6446 text and used as the value of the coding cookie which is added to the
6447 top of a file. Otherwise, this function saves a raw article without
6448 the coding cookie."
6449 (let* ((artbuf (current-buffer))
6450 (file-name-coding-system nnmail-pathname-coding-system)
6451 (coding gnus-article-save-coding-system)
6452 (coding-system-for-read (if coding
6453 nil ;; Rely on the coding cookie.
6454 mm-text-coding-system))
6455 (coding-system-for-write (or coding
6456 mm-text-coding-system-for-write
6457 mm-text-coding-system))
6458 (exists (file-exists-p file-name)))
6459 (with-temp-buffer
6460 (when exists
6461 (insert-file-contents file-name)
6462 (goto-char (point-min))
6463 ;; Remove the existing coding cookie.
6464 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6465 (delete-region (match-beginning 0) (match-end 0))))
6466 (goto-char (point-max))
6467 (insert-buffer-substring artbuf)
6468 ;; Append newline at end of the buffer as separator, and then
6469 ;; save it to file.
6470 (goto-char (point-max))
6471 (insert "\n")
6472 (when coding
6473 ;; If the coding system is not suitable to encode the text,
6474 ;; ask a user for a proper one.
6475 (when (fboundp 'select-safe-coding-system)
6476 (setq coding (coding-system-base
6477 (save-window-excursion
6478 (select-safe-coding-system (point-min) (point-max)
6479 coding))))
6480 (setq coding-system-for-write
6481 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6482 coding)))
6483 (goto-char (point-min))
6484 ;; Add the coding cookie.
6485 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6486 coding-system-for-write)))
6487 (if exists
6488 (progn
6489 (write-region (point-min) (point-max) file-name nil 'no-message)
6490 (message "Appended to %s" file-name))
6491 (write-region (point-min) (point-max) file-name))))
6494 (defun gnus-narrow-to-page (&optional arg)
6495 "Narrow the article buffer to a page.
6496 If given a numerical ARG, move forward ARG pages."
6497 (interactive "P")
6498 (setq arg (if arg (prefix-numeric-value arg) 0))
6499 (with-current-buffer gnus-article-buffer
6500 (widen)
6501 ;; Remove any old next/prev buttons.
6502 (when (gnus-visual-p 'page-marker)
6503 (let ((inhibit-read-only t))
6504 (gnus-remove-text-with-property 'gnus-prev)
6505 (gnus-remove-text-with-property 'gnus-next)))
6506 (let (st nd pt)
6507 (when (save-excursion
6508 (cond ((< arg 0)
6509 (if (re-search-backward page-delimiter nil 'move (abs arg))
6510 (prog1
6511 (setq nd (match-beginning 0)
6512 pt nd)
6513 (when (re-search-backward page-delimiter nil t)
6514 (setq st (match-end 0))))
6515 (when (re-search-forward page-delimiter nil t)
6516 (setq nd (match-beginning 0)
6517 pt (point-min)))))
6518 ((> arg 0)
6519 (if (re-search-forward page-delimiter nil 'move arg)
6520 (prog1
6521 (setq st (match-end 0)
6522 pt st)
6523 (when (re-search-forward page-delimiter nil t)
6524 (setq nd (match-beginning 0))))
6525 (when (re-search-backward page-delimiter nil t)
6526 (setq st (match-end 0)
6527 pt (point-max)))))
6529 (when (re-search-backward page-delimiter nil t)
6530 (goto-char (setq st (match-end 0))))
6531 (when (re-search-forward page-delimiter nil t)
6532 (setq nd (match-beginning 0)))
6533 (or st nd))))
6534 (setq gnus-page-broken t)
6535 (when pt (goto-char pt))
6536 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6537 (when (gnus-visual-p 'page-marker)
6538 (save-excursion
6539 (when nd
6540 (goto-char nd)
6541 (gnus-insert-next-page-button))
6542 (when st
6543 (goto-char st)
6544 (gnus-insert-prev-page-button))))))))
6546 ;; Article mode commands
6548 (defun gnus-article-goto-next-page ()
6549 "Show the next page of the article."
6550 (interactive)
6551 (when (gnus-article-next-page)
6552 (goto-char (point-min))
6553 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6556 (defun gnus-article-goto-prev-page ()
6557 "Show the previous page of the article."
6558 (interactive)
6559 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6560 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6561 (gnus-article-prev-page nil)))
6563 ;; This is cleaner but currently breaks `gnus-pick-mode':
6565 ;; (defun gnus-article-goto-next-page ()
6566 ;; "Show the next page of the article."
6567 ;; (interactive)
6568 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6569 ;; (gnus-summary-next-page)))
6571 ;; (defun gnus-article-goto-prev-page ()
6572 ;; "Show the next page of the article."
6573 ;; (interactive)
6574 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6575 ;; (gnus-summary-prev-page)))
6577 (defun gnus-article-next-page (&optional lines)
6578 "Show the next page of the current article.
6579 If end of article, return non-nil. Otherwise return nil.
6580 Argument LINES specifies lines to be scrolled up."
6581 (interactive "p")
6582 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6583 (if (and (not (and gnus-article-over-scroll
6584 (> (count-lines (window-start) (point-max))
6585 (if (featurep 'xemacs)
6586 (or lines (1- (window-height)))
6587 (+ (or lines (1- (window-height))) scroll-margin)))))
6588 (save-excursion
6589 (end-of-line)
6590 (and (pos-visible-in-window-p) ;Not continuation line.
6591 (>= (point) (point-max)))))
6592 ;; Nothing in this page.
6593 (if (or (not gnus-page-broken)
6594 (save-excursion
6595 (save-restriction
6596 (widen)
6597 (forward-line)
6598 (eobp)))) ;Real end-of-buffer?
6599 (progn
6600 (when gnus-article-over-scroll
6601 (gnus-article-next-page-1 lines))
6602 t) ;Nothing more.
6603 (gnus-narrow-to-page 1) ;Go to next page.
6604 nil)
6605 ;; More in this page.
6606 (gnus-article-next-page-1 lines)
6607 nil))
6609 (defun gnus-article-beginning-of-window ()
6610 "Move point to the beginning of the window.
6611 In Emacs, the point is placed at the line number which `scroll-margin'
6612 specifies."
6613 (if (featurep 'xemacs)
6614 (move-to-window-line 0)
6615 ;; There is an obscure bug in Emacs that makes it impossible to
6616 ;; scroll past big pictures in the article buffer. Try to fix
6617 ;; this by adding a sanity check by counting the lines visible.
6618 (when (> (count-lines (window-start) (window-end)) 30)
6619 (move-to-window-line
6620 (min (max 0 scroll-margin)
6621 (max 1 (- (window-height)
6622 (if mode-line-format 1 0)
6623 (if header-line-format 1 0)
6624 2)))))))
6626 (defun gnus-article-next-page-1 (lines)
6627 (condition-case ()
6628 (let ((scroll-in-place nil)
6629 (auto-window-vscroll nil))
6630 (scroll-up lines))
6631 (end-of-buffer
6632 ;; Long lines may cause an end-of-buffer error.
6633 (goto-char (point-max))))
6634 (gnus-article-beginning-of-window))
6636 (defun gnus-article-prev-page (&optional lines)
6637 "Show previous page of current article.
6638 Argument LINES specifies lines to be scrolled down."
6639 (interactive "p")
6640 (move-to-window-line 0)
6641 (if (and gnus-page-broken
6642 (bobp)
6643 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6644 (progn
6645 (gnus-narrow-to-page -1) ;Go to previous page.
6646 (goto-char (point-max))
6647 (recenter (if gnus-article-over-scroll
6648 (if lines
6649 (max (if (featurep 'xemacs)
6650 lines
6651 (+ lines scroll-margin))
6653 (- (window-height) 2))
6654 -1)))
6655 (prog1
6656 (condition-case ()
6657 (let ((scroll-in-place nil))
6658 (scroll-down lines))
6659 (beginning-of-buffer
6660 (goto-char (point-min))))
6661 (gnus-article-beginning-of-window))))
6663 (defun gnus-article-only-boring-p ()
6664 "Decide whether there is only boring text remaining in the article.
6665 Something \"interesting\" is a word of at least two letters that does
6666 not have a face in `gnus-article-boring-faces'."
6667 (when (and gnus-article-skip-boring
6668 (boundp 'gnus-article-boring-faces)
6669 (symbol-value 'gnus-article-boring-faces))
6670 (save-excursion
6671 (let ((inhibit-point-motion-hooks t))
6672 (catch 'only-boring
6673 (while (re-search-forward "\\b\\w\\w" nil t)
6674 (forward-char -1)
6675 (when (not (gnus-intersection
6676 (gnus-faces-at (point))
6677 (symbol-value 'gnus-article-boring-faces)))
6678 (throw 'only-boring nil)))
6679 (throw 'only-boring t))))))
6681 (defun gnus-article-refer-article ()
6682 "Read article specified by message-id around point."
6683 (interactive)
6684 (save-excursion
6685 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6686 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6687 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6688 (let ((msg-id (concat "<" (match-string 0) ">")))
6689 (set-buffer gnus-summary-buffer)
6690 (gnus-summary-refer-article msg-id))
6691 (error "No references around point"))))
6693 (defun gnus-article-show-summary ()
6694 "Reconfigure windows to show summary buffer."
6695 (interactive)
6696 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6697 (error "There is no summary buffer for this article buffer")
6698 (gnus-article-set-globals)
6699 (gnus-configure-windows 'article)
6700 (gnus-summary-goto-subject gnus-current-article)
6701 (gnus-summary-position-point)))
6703 (defun gnus-article-describe-briefly ()
6704 "Describe article mode commands briefly."
6705 (interactive)
6706 (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")))
6708 (defun gnus-article-check-buffer ()
6709 "Beep if not in an article buffer."
6710 (unless (derived-mode-p 'gnus-article-mode)
6711 (error "Command invoked outside of a Gnus article buffer")))
6713 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6714 "Read a summary buffer key sequence and execute it from the article buffer."
6715 (interactive "P")
6716 (gnus-article-check-buffer)
6717 (let ((nosaves
6718 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6719 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6720 "=" "^" "\M-^" "|"))
6721 (nosave-but-article
6722 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6723 "An" "Ap" [?A (meta return)] [?A delete]))
6724 (nosave-in-article
6725 '("AS" "\C-d"))
6726 (up-to-top
6727 '("n" "Gn" "p" "Gp"))
6728 keys new-sum-point)
6729 (with-current-buffer gnus-article-current-summary
6730 (let (gnus-pick-mode)
6731 (setq unread-command-events (nconc unread-command-events
6732 (list (or key last-command-event)))
6733 keys (if (featurep 'xemacs)
6734 (events-to-keys (read-key-sequence nil t))
6735 (read-key-sequence nil t)))))
6737 (message "")
6739 (cond
6740 ((eq (aref keys (1- (length keys))) ?\C-h)
6741 (gnus-article-describe-bindings (substring keys 0 -1)))
6742 ((or (member keys nosaves)
6743 (member keys nosave-but-article)
6744 (member keys nosave-in-article))
6745 (let (func)
6746 (save-window-excursion
6747 (pop-to-buffer gnus-article-current-summary)
6748 ;; We disable the pick minor mode commands.
6749 (let (gnus-pick-mode)
6750 (setq func (key-binding keys t))))
6751 (if (or (not func)
6752 (numberp func))
6753 (ding)
6754 (unless (member keys nosave-in-article)
6755 (set-buffer gnus-article-current-summary))
6756 (when (and (symbolp func)
6757 (get func 'disabled))
6758 (error "Function %s disabled" func))
6759 (call-interactively func)
6760 (setq new-sum-point (point)))
6761 (when (member keys nosave-but-article)
6762 (pop-to-buffer gnus-article-buffer))))
6764 ;; These commands should restore window configuration.
6765 (let ((obuf (current-buffer))
6766 (owin (current-window-configuration))
6767 win func in-buffer selected new-sum-start new-sum-hscroll err)
6768 (cond (not-restore-window
6769 (pop-to-buffer gnus-article-current-summary)
6770 (setq win (selected-window)))
6771 ((setq win (get-buffer-window gnus-article-current-summary))
6772 (select-window win))
6774 (let ((summary-buffer gnus-article-current-summary))
6775 (gnus-configure-windows 'article)
6776 (unless (setq win (get-buffer-window summary-buffer 'visible))
6777 (let ((gnus-buffer-configuration
6778 '((article ((vertical 1.0
6779 (summary 0.25 point)
6780 (article 1.0)))))))
6781 (gnus-configure-windows 'article))
6782 (setq win (get-buffer-window summary-buffer 'visible)))
6783 (gnus-select-frame-set-input-focus (window-frame win))
6784 (select-window win))))
6785 (setq in-buffer (current-buffer))
6786 ;; We disable the pick minor mode commands.
6787 (setq func (let (gnus-pick-mode)
6788 (key-binding keys t)))
6789 (when (get func 'disabled)
6790 (error "Function %s disabled" func))
6791 (if (and func
6792 (functionp func)
6793 (condition-case code
6794 (progn
6795 (call-interactively func)
6797 (error
6798 (setq err code)
6799 nil)))
6800 (progn
6801 (when (eq win (selected-window))
6802 (setq new-sum-point (point)
6803 new-sum-start (window-start win)
6804 new-sum-hscroll (window-hscroll win)))
6805 (when (or (eq in-buffer (current-buffer))
6806 (when (eq obuf (current-buffer))
6807 (set-buffer in-buffer)
6809 (setq selected (ignore-errors (gnus-summary-select-article)))
6810 (set-buffer obuf)
6811 (unless not-restore-window
6812 (set-window-configuration owin))
6813 (when (and (eq selected 'old)
6814 new-sum-point)
6815 (set-window-start (get-buffer-window (current-buffer))
6817 (set-window-point (get-buffer-window (current-buffer))
6818 (if (article-goto-body)
6819 (1- (point))
6820 (point))))
6821 (when (and (not not-restore-window)
6822 new-sum-point
6823 (window-live-p win)
6824 (with-current-buffer (window-buffer win)
6825 (derived-mode-p 'gnus-summary-mode)))
6826 (set-window-point win new-sum-point)
6827 (set-window-start win new-sum-start)
6828 (set-window-hscroll win new-sum-hscroll))))
6829 (set-window-configuration owin)
6830 (if err
6831 (signal (car err) (cdr err))
6832 (ding))))))))
6834 (defun gnus-article-read-summary-send-keys ()
6835 (interactive)
6836 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6837 (gnus-article-read-summary-keys)))
6839 (defun gnus-article-describe-key (key)
6840 "Display documentation of the function invoked by KEY.
6841 KEY is a string or a vector."
6842 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6843 (read-key-sequence "Describe key: "))))
6844 (gnus-article-check-buffer)
6845 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6846 gnus-article-read-summary-send-keys))
6847 (with-current-buffer gnus-article-current-summary
6848 (setq unread-command-events
6849 (if (featurep 'xemacs)
6850 (append key nil)
6851 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6852 (list 'meta (- x 128))
6854 key)))
6855 (let ((cursor-in-echo-area t)
6856 gnus-pick-mode)
6857 (describe-key (read-key-sequence nil t))))
6858 (describe-key key)))
6860 (defun gnus-article-describe-key-briefly (key &optional insert)
6861 "Display documentation of the function invoked by KEY.
6862 KEY is a string or a vector."
6863 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6864 (read-key-sequence "Describe key: "))
6865 current-prefix-arg))
6866 (gnus-article-check-buffer)
6867 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6868 gnus-article-read-summary-send-keys))
6869 (with-current-buffer gnus-article-current-summary
6870 (setq unread-command-events
6871 (if (featurep 'xemacs)
6872 (append key nil)
6873 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6874 (list 'meta (- x 128))
6876 key)))
6877 (let ((cursor-in-echo-area t)
6878 gnus-pick-mode)
6879 (describe-key-briefly (read-key-sequence nil t) insert)))
6880 (describe-key-briefly key insert)))
6882 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6883 (defvar gnus-agent-summary-mode)
6884 (defvar gnus-draft-mode)
6885 (defvar help-xref-stack-item)
6887 (defun gnus-article-describe-bindings (&optional prefix)
6888 "Show a list of all defined keys, and their definitions.
6889 The optional argument PREFIX, if non-nil, should be a key sequence;
6890 then we display only bindings that start with that prefix."
6891 (interactive)
6892 (gnus-article-check-buffer)
6893 (let ((keymap (copy-keymap gnus-article-mode-map))
6894 (map (copy-keymap gnus-article-send-map))
6895 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6896 parent agent draft)
6897 (define-key keymap "S" map)
6898 (define-key map [t] nil)
6899 (with-current-buffer gnus-article-current-summary
6900 (set-keymap-parent
6901 keymap
6902 (if (setq parent (keymap-parent gnus-article-mode-map))
6903 (prog1
6904 (setq parent (copy-keymap parent))
6905 (set-keymap-parent parent (current-local-map)))
6906 (current-local-map)))
6907 (set-keymap-parent map (key-binding "S"))
6908 (let (key def gnus-pick-mode)
6909 (while sumkeys
6910 (setq key (pop sumkeys))
6911 (cond ((and (vectorp key) (= (length key) 1)
6912 (consp (setq def (aref key 0)))
6913 (numberp (car def)) (numberp (cdr def)))
6914 (when (< (max (car def) (cdr def)) 128)
6915 (setq sumkeys
6916 (append (mapcar
6917 #'vector
6918 (nreverse (gnus-uncompress-range def)))
6919 sumkeys))))
6920 ((setq def (key-binding key))
6921 (unless (eq def 'undefined)
6922 (define-key keymap key def))))))
6923 (when (boundp 'gnus-agent-summary-mode)
6924 (setq agent gnus-agent-summary-mode))
6925 (when (boundp 'gnus-draft-mode)
6926 (setq draft gnus-draft-mode)))
6927 (with-temp-buffer
6928 (use-local-map keymap)
6929 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6930 (set (make-local-variable 'gnus-draft-mode) draft)
6931 (describe-bindings prefix))
6932 (let ((item `((lambda (prefix)
6933 (with-current-buffer ,(current-buffer)
6934 (gnus-article-describe-bindings prefix)))
6935 ,prefix)))
6936 ;; Loading `help-mode' here is necessary if `describe-bindings'
6937 ;; is replaced with something, e.g. `helm-descbinds'.
6938 (require 'help-mode)
6939 (with-current-buffer (let (help-xref-following) (help-buffer))
6940 (setq help-xref-stack-item item)))))
6942 (defun gnus-article-reply-with-original (&optional wide)
6943 "Start composing a reply mail to the current message.
6944 The text in the region will be yanked. If the region isn't active,
6945 the entire article will be yanked."
6946 (interactive)
6947 (let ((article (cdr gnus-article-current))
6948 contents)
6949 (if (not (gnus-region-active-p))
6950 (with-current-buffer gnus-summary-buffer
6951 (gnus-summary-reply (list (list article)) wide))
6952 (setq contents (buffer-substring (point) (mark t)))
6953 ;; Deactivate active regions.
6954 (when (and (boundp 'transient-mark-mode)
6955 transient-mark-mode)
6956 (setq mark-active nil))
6957 (with-current-buffer gnus-summary-buffer
6958 (gnus-summary-reply
6959 (list (list article contents)) wide)))))
6961 (defun gnus-article-wide-reply-with-original ()
6962 "Start composing a wide reply mail to the current message.
6963 The text in the region will be yanked. If the region isn't active,
6964 the entire article will be yanked."
6965 (interactive)
6966 (gnus-article-reply-with-original t))
6968 (defun gnus-article-followup-with-original ()
6969 "Compose a followup to the current article.
6970 The text in the region will be yanked. If the region isn't active,
6971 the entire article will be yanked."
6972 (interactive)
6973 (let ((article (cdr gnus-article-current))
6974 contents)
6975 (if (not (gnus-region-active-p))
6976 (with-current-buffer gnus-summary-buffer
6977 (gnus-summary-followup (list (list article))))
6978 (setq contents (buffer-substring (point) (mark t)))
6979 ;; Deactivate active regions.
6980 (when (and (boundp 'transient-mark-mode)
6981 transient-mark-mode)
6982 (setq mark-active nil))
6983 (with-current-buffer gnus-summary-buffer
6984 (gnus-summary-followup
6985 (list (list article contents)))))))
6987 (defun gnus-article-hide (&optional arg force)
6988 "Hide all the gruft in the current article.
6989 This means that signatures, cited text and (some) headers will be
6990 hidden.
6991 If given a prefix, show the hidden text instead."
6992 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6993 (gnus-article-hide-headers arg)
6994 (gnus-article-hide-list-identifiers arg)
6995 (gnus-article-hide-citation-maybe arg force)
6996 (gnus-article-hide-signature arg))
6998 (defun gnus-check-group-server ()
6999 ;; Make sure the connection to the server is alive.
7000 (unless (gnus-server-opened
7001 (gnus-find-method-for-group gnus-newsgroup-name))
7002 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7003 (gnus-request-group gnus-newsgroup-name t)))
7005 (eval-when-compile
7006 (autoload 'nneething-get-file-name "nneething"))
7008 (defun gnus-request-article-this-buffer (article group)
7009 "Get an article and insert it into this buffer."
7010 (let (do-update-line sparse-header)
7011 (prog1
7012 (save-excursion
7013 (erase-buffer)
7014 (gnus-kill-all-overlays)
7015 (setq group (or group gnus-newsgroup-name))
7017 ;; Using `gnus-request-article' directly will insert the article into
7018 ;; `nntp-server-buffer' - so we'll save some time by not having to
7019 ;; copy it from the server buffer into the article buffer.
7021 ;; We only request an article by message-id when we do not have the
7022 ;; headers for it, so we'll have to get those.
7023 (when (stringp article)
7024 (gnus-read-header article))
7026 ;; If the article number is negative, that means that this article
7027 ;; doesn't belong in this newsgroup (possibly), so we find its
7028 ;; message-id and request it by id instead of number.
7029 (when (and (numberp article)
7030 gnus-summary-buffer
7031 (get-buffer gnus-summary-buffer)
7032 (gnus-buffer-exists-p gnus-summary-buffer))
7033 (with-current-buffer gnus-summary-buffer
7034 (let ((header (gnus-summary-article-header article)))
7035 (when (< article 0)
7036 (cond
7037 ((memq article gnus-newsgroup-sparse)
7038 ;; This is a sparse gap article.
7039 (setq do-update-line article)
7040 (setq article (mail-header-id header))
7041 (setq sparse-header (gnus-read-header article))
7042 (setq gnus-newsgroup-sparse
7043 (delq article gnus-newsgroup-sparse)))
7044 ((vectorp header)
7045 ;; It's a real article.
7046 (setq article (mail-header-id header)))
7048 ;; It is an extracted pseudo-article.
7049 (setq article 'pseudo)
7050 (gnus-request-pseudo-article header))))
7052 (let ((method (gnus-find-method-for-group
7053 gnus-newsgroup-name)))
7054 (when (and (eq (car method) 'nneething)
7055 (vectorp header))
7056 (let ((dir (nneething-get-file-name
7057 (mail-header-id header))))
7058 (when (and (stringp dir)
7059 (file-directory-p dir))
7060 (setq article 'nneething)
7061 (gnus-group-enter-directory dir))))))))
7063 (cond
7064 ;; Refuse to select canceled articles.
7065 ((and (numberp article)
7066 gnus-summary-buffer
7067 (get-buffer gnus-summary-buffer)
7068 (gnus-buffer-exists-p gnus-summary-buffer)
7069 (eq (cdr (with-current-buffer gnus-summary-buffer
7070 (assq article gnus-newsgroup-reads)))
7071 gnus-canceled-mark))
7072 nil)
7073 ;; We first check `gnus-original-article-buffer'.
7074 ((and (get-buffer gnus-original-article-buffer)
7075 (numberp article)
7076 (with-current-buffer gnus-original-article-buffer
7077 (and (equal (car gnus-original-article) group)
7078 (eq (cdr gnus-original-article) article))))
7079 ;; `insert-buffer-substring' would incorrectly use the
7080 ;; equivalent of string-make-multibyte which amount to decoding
7081 ;; with locale-coding-system, causing failure of
7082 ;; subsequent decoding.
7083 (insert (mm-string-to-multibyte
7084 (with-current-buffer gnus-original-article-buffer
7085 (buffer-substring (point-min) (point-max)))))
7086 'article)
7087 ;; Check the backlog.
7088 ((and gnus-keep-backlog
7089 (gnus-backlog-request-article group article (current-buffer)))
7090 'article)
7091 ;; Check asynchronous pre-fetch.
7092 ((gnus-async-request-fetched-article group article (current-buffer))
7093 (gnus-async-prefetch-next group article gnus-summary-buffer)
7094 (when (and (numberp article) gnus-keep-backlog)
7095 (gnus-backlog-enter-article group article (current-buffer)))
7096 'article)
7097 ;; Check the cache.
7098 ((and gnus-use-cache
7099 (numberp article)
7100 (gnus-cache-request-article article group))
7101 'article)
7102 ;; Check the agent cache.
7103 ((gnus-agent-request-article article group)
7104 'article)
7105 ;; Get the article and put into the article buffer.
7106 ((or (stringp article)
7107 (numberp article))
7108 (let ((gnus-override-method gnus-override-method)
7109 (methods (and (stringp article)
7110 (with-current-buffer gnus-summary-buffer
7111 (gnus-refer-article-methods))))
7112 (backend (car (gnus-find-method-for-group
7113 gnus-newsgroup-name)))
7114 result
7115 (inhibit-read-only t))
7116 (when (and (null gnus-override-method)
7117 methods)
7118 (setq gnus-override-method (pop methods)))
7119 (while (not result)
7120 (erase-buffer)
7121 (gnus-kill-all-overlays)
7122 (let ((gnus-newsgroup-name group))
7123 (gnus-check-group-server))
7124 (cond
7125 ((gnus-request-article article group (current-buffer))
7126 (when (numberp article)
7127 (gnus-async-prefetch-next group article
7128 gnus-summary-buffer)
7129 (when gnus-keep-backlog
7130 (gnus-backlog-enter-article
7131 group article (current-buffer)))
7132 (when (and gnus-agent
7133 (gnus-agent-group-covered-p group))
7134 (gnus-agent-store-article article group)))
7135 (setq result 'article))
7136 (methods
7137 (setq gnus-override-method (pop methods)))
7138 ((not (string-match "^400 "
7139 (nnheader-get-report backend)))
7140 ;; If we get 400 server disconnect, reconnect and
7141 ;; retry; otherwise, assume the article has expired.
7142 (setq result 'done))))
7143 (and (eq result 'article) 'article)))
7144 ;; It was a pseudo.
7145 (t article)))
7147 ;; Associate this article with the current summary buffer.
7148 (setq gnus-article-current-summary gnus-summary-buffer)
7150 ;; Take the article from the original article buffer
7151 ;; and place it in the buffer it's supposed to be in.
7152 (when (and (get-buffer gnus-article-buffer)
7153 (equal (buffer-name (current-buffer))
7154 (buffer-name (get-buffer gnus-article-buffer))))
7155 (save-excursion
7156 (if (get-buffer gnus-original-article-buffer)
7157 (set-buffer gnus-original-article-buffer)
7158 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7159 (buffer-disable-undo)
7160 (setq major-mode 'gnus-original-article-mode)
7161 (setq buffer-read-only t))
7162 (let ((inhibit-read-only t))
7163 (erase-buffer)
7164 (insert-buffer-substring gnus-article-buffer))
7165 (setq gnus-original-article (cons group article)))
7167 ;; Decode charsets.
7168 (run-hooks 'gnus-article-decode-hook)
7169 ;; Mark article as decoded or not.
7170 (setq gnus-article-decoded-p gnus-article-decode-hook))
7172 ;; Update sparse articles.
7173 (when (and do-update-line
7174 (or (numberp article)
7175 (stringp article)))
7176 (let ((buf (current-buffer)))
7177 (set-buffer gnus-summary-buffer)
7178 (gnus-summary-update-article do-update-line sparse-header)
7179 (gnus-summary-goto-subject do-update-line nil t)
7180 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7181 (point))
7182 (set-buffer buf))))))
7184 (defun gnus-block-private-groups (group)
7185 (if (or (gnus-news-group-p group)
7186 (gnus-member-of-valid 'global group))
7187 ;; Block nothing in news groups.
7189 ;; Block everything anywhere else.
7190 "."))
7192 (defun gnus-blocked-images ()
7193 (if (functionp gnus-blocked-images)
7194 (funcall gnus-blocked-images gnus-newsgroup-name)
7195 gnus-blocked-images))
7198 ;;; Article editing
7201 (defcustom gnus-article-edit-mode-hook nil
7202 "Hook run in article edit mode buffers."
7203 :group 'gnus-article-various
7204 :type 'hook)
7206 (defvar gnus-article-edit-done-function nil)
7208 (defvar gnus-article-edit-mode-map nil)
7210 ;; Should we be using derived.el for this?
7211 (unless gnus-article-edit-mode-map
7212 (setq gnus-article-edit-mode-map (make-keymap))
7213 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7215 (gnus-define-keys gnus-article-edit-mode-map
7216 "\C-c?" describe-mode
7217 "\C-c\C-c" gnus-article-edit-done
7218 "\C-c\C-k" gnus-article-edit-exit
7219 "\C-c\C-f\C-t" message-goto-to
7220 "\C-c\C-f\C-o" message-goto-from
7221 "\C-c\C-f\C-b" message-goto-bcc
7222 ;;"\C-c\C-f\C-w" message-goto-fcc
7223 "\C-c\C-f\C-c" message-goto-cc
7224 "\C-c\C-f\C-s" message-goto-subject
7225 "\C-c\C-f\C-r" message-goto-reply-to
7226 "\C-c\C-f\C-n" message-goto-newsgroups
7227 "\C-c\C-f\C-d" message-goto-distribution
7228 "\C-c\C-f\C-f" message-goto-followup-to
7229 "\C-c\C-f\C-m" message-goto-mail-followup-to
7230 "\C-c\C-f\C-k" message-goto-keywords
7231 "\C-c\C-f\C-u" message-goto-summary
7232 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7233 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7234 "\C-c\C-b" message-goto-body
7235 "\C-c\C-i" message-goto-signature
7237 "\C-c\C-t" message-insert-to
7238 "\C-c\C-n" message-insert-newsgroups
7239 "\C-c\C-o" message-sort-headers
7240 "\C-c\C-e" message-elide-region
7241 "\C-c\C-v" message-delete-not-region
7242 "\C-c\C-z" message-kill-to-signature
7243 "\M-\r" message-newline-and-reformat
7244 "\C-c\C-a" mml-attach-file
7245 "\C-a" message-beginning-of-line
7246 "\t" message-tab
7247 "\M-;" comment-region)
7249 (gnus-define-keys (gnus-article-edit-wash-map
7250 "\C-c\C-w" gnus-article-edit-mode-map)
7251 "f" gnus-article-edit-full-stops))
7253 (easy-menu-define
7254 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7255 '("Field"
7256 ["Fetch To" message-insert-to t]
7257 ["Fetch Newsgroups" message-insert-newsgroups t]
7258 "----"
7259 ["To" message-goto-to t]
7260 ["From" message-goto-from t]
7261 ["Subject" message-goto-subject t]
7262 ["Cc" message-goto-cc t]
7263 ["Reply-To" message-goto-reply-to t]
7264 ["Summary" message-goto-summary t]
7265 ["Keywords" message-goto-keywords t]
7266 ["Newsgroups" message-goto-newsgroups t]
7267 ["Followup-To" message-goto-followup-to t]
7268 ["Mail-Followup-To" message-goto-mail-followup-to t]
7269 ["Distribution" message-goto-distribution t]
7270 ["Body" message-goto-body t]
7271 ["Signature" message-goto-signature t]))
7273 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7274 "Major mode for editing articles.
7275 This is an extended text-mode.
7277 \\{gnus-article-edit-mode-map}"
7278 (make-local-variable 'gnus-article-edit-done-function)
7279 (make-local-variable 'gnus-prev-winconf)
7280 (set (make-local-variable 'font-lock-defaults)
7281 '(message-font-lock-keywords t))
7282 (set (make-local-variable 'mail-header-separator) "")
7283 (set (make-local-variable 'gnus-article-edit-mode) t)
7284 (easy-menu-add message-mode-field-menu message-mode-map)
7285 (mml-mode)
7286 (setq buffer-read-only nil)
7287 (buffer-enable-undo)
7288 (widen))
7290 (defun gnus-article-edit (&optional force)
7291 "Edit the current article.
7292 This will have permanent effect only in mail groups.
7293 If FORCE is non-nil, allow editing of articles even in read-only
7294 groups."
7295 (interactive "P")
7296 (when (and (not force)
7297 (gnus-group-read-only-p))
7298 (error "The current newsgroup does not support article editing"))
7299 (gnus-article-date-original)
7300 (gnus-article-edit-article
7301 'ignore
7302 `(lambda (no-highlight)
7303 'ignore
7304 (gnus-summary-edit-article-done
7305 ,(or (mail-header-references gnus-current-headers) "")
7306 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7308 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7309 "Start editing the contents of the current article buffer."
7310 (let ((winconf (current-window-configuration)))
7311 (set-buffer gnus-article-buffer)
7312 (let ((message-auto-save-directory
7313 ;; Don't associate the article buffer with a draft file.
7314 nil))
7315 (gnus-article-edit-mode))
7316 (funcall start-func)
7317 (set-buffer-modified-p nil)
7318 (gnus-configure-windows 'edit-article)
7319 (setq gnus-article-edit-done-function exit-func)
7320 (setq gnus-prev-winconf winconf)
7321 (unless quiet
7322 (gnus-message 6 "C-c C-c to end edits"))))
7324 (defun gnus-article-edit-done (&optional arg)
7325 "Update the article edits and exit."
7326 (interactive "P")
7327 (let ((func gnus-article-edit-done-function)
7328 (buf (current-buffer))
7329 (start (window-start))
7330 (p (point))
7331 (winconf gnus-prev-winconf))
7332 (widen) ;; Widen it in case that users narrowed the buffer.
7333 (funcall func arg)
7334 (set-buffer buf)
7335 ;; The cache and backlog have to be flushed somewhat.
7336 (when gnus-keep-backlog
7337 (gnus-backlog-remove-article
7338 (car gnus-article-current) (cdr gnus-article-current)))
7339 ;; Flush original article as well.
7340 (gnus-flush-original-article-buffer)
7341 (when gnus-use-cache
7342 (gnus-cache-update-article
7343 (car gnus-article-current) (cdr gnus-article-current)))
7344 ;; We remove all text props from the article buffer.
7345 (kill-all-local-variables)
7346 (set-text-properties (point-min) (point-max) nil)
7347 (gnus-article-mode)
7348 (set-window-configuration winconf)
7349 (set-buffer buf)
7350 (set-window-start (get-buffer-window buf) start)
7351 (set-window-point (get-buffer-window buf) (point)))
7352 (gnus-summary-show-article))
7354 (defun gnus-flush-original-article-buffer ()
7355 (when (get-buffer gnus-original-article-buffer)
7356 (with-current-buffer gnus-original-article-buffer
7357 (setq gnus-original-article nil))))
7359 (defun gnus-article-edit-exit ()
7360 "Exit the article editing without updating."
7361 (interactive)
7362 (when (or (not (buffer-modified-p))
7363 (yes-or-no-p "Article modified; kill anyway? "))
7364 (let ((curbuf (current-buffer))
7365 (p (point))
7366 (window-start (window-start)))
7367 (erase-buffer)
7368 (if (gnus-buffer-live-p gnus-original-article-buffer)
7369 (insert-buffer-substring gnus-original-article-buffer))
7370 (let ((winconf gnus-prev-winconf))
7371 (kill-all-local-variables)
7372 (gnus-article-mode)
7373 (set-window-configuration winconf)
7374 ;; Tippy-toe some to make sure that point remains where it was.
7375 (save-current-buffer
7376 (set-buffer curbuf)
7377 (set-window-start (get-buffer-window (current-buffer)) window-start)
7378 (goto-char p))))
7379 (gnus-summary-show-article)))
7381 (defun gnus-article-edit-full-stops ()
7382 "Interactively repair spacing at end of sentences."
7383 (interactive)
7384 (save-excursion
7385 (goto-char (point-min))
7386 (search-forward-regexp "^$" nil t)
7387 (let ((case-fold-search nil))
7388 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7391 ;;; Article highlights
7394 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7396 ;;; Internal Variables:
7398 (defcustom gnus-button-url-regexp
7399 (concat
7400 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7401 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7402 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7403 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7404 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7405 (punct "!?:;.,"))
7406 (concat
7407 "\\(?:"
7408 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7409 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7410 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7411 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7412 "\\|"
7413 "[" chars punct "]+" "[" chars "]"
7414 "\\)"))
7415 (concat ;; XEmacs 21.4 doesn't support POSIX.
7416 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7417 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7418 "\\)")
7419 "Regular expression that matches URLs."
7420 :version "24.4"
7421 :group 'gnus-article-buttons
7422 :type 'regexp)
7424 (defcustom gnus-button-valid-fqdn-regexp
7425 message-valid-fqdn-regexp
7426 "Regular expression that matches a valid FQDN."
7427 :version "22.1"
7428 :group 'gnus-article-buttons
7429 :type 'regexp)
7431 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7432 (defcustom gnus-button-valid-localpart-regexp
7433 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7434 "Regular expression that matches a localpart of mail addresses or MIDs."
7435 :version "22.1"
7436 :group 'gnus-article-buttons
7437 :type 'regexp)
7439 (defcustom gnus-button-man-handler 'manual-entry
7440 "Function to use for displaying man pages.
7441 The function must take at least one argument with a string naming the
7442 man page."
7443 :version "22.1"
7444 :type '(choice (function-item :tag "Man" manual-entry)
7445 (function-item :tag "Woman" woman)
7446 (function :tag "Other"))
7447 :group 'gnus-article-buttons)
7449 (defcustom gnus-button-mid-or-mail-regexp
7450 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7451 gnus-button-valid-fqdn-regexp
7452 ">?\\)\\b")
7453 "Regular expression that matches a message ID or a mail address."
7454 :version "22.1"
7455 :group 'gnus-article-buttons
7456 :type 'regexp)
7458 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7459 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7460 Strings like this can be either a message ID or a mail address. If it is one
7461 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7462 message ID or a mail address, respectively. If this variable is set to the
7463 symbol `ask', always query the user what do do. If it is a function, this
7464 function will be called with the string as its only argument. The function
7465 must return `mid', `mail', `invalid' or `ask'."
7466 :version "22.1"
7467 :group 'gnus-article-buttons
7468 :type '(choice (function-item :tag "Heuristic function"
7469 gnus-button-mid-or-mail-heuristic)
7470 (const ask)
7471 (const mid)
7472 (const mail)))
7474 (defcustom gnus-button-mid-or-mail-heuristic-alist
7475 '((-10.0 . ".+\\$.+@")
7476 (-10.0 . "#")
7477 (-10.0 . "\\*")
7478 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7479 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7480 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7481 (-1.0 . "^[^a-z]+@")
7483 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7484 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7485 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7486 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7488 (-2.0 . "^[0-9]")
7489 (-1.0 . "^[0-9][0-9]")
7491 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7492 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7493 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7494 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7496 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7497 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7498 ;; "[0-9]{8,}.*\@"
7499 (-3.0
7500 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7501 ;; "[0-9]{12,}.*\@"
7502 ;; compensation for TDMA dated mail addresses:
7503 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7505 (-20.0 . "\\.fsf@") ;; Gnus
7506 (-20.0 . "^slrn")
7507 (-20.0 . "^Pine")
7508 (-20.0 . "^alpine\\.")
7509 (-20.0 . "_-_") ;; Subject change in thread
7511 (-20.0 . "\\.ln@") ;; leafnode
7512 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7513 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7515 ;; (5.0 . "") ;; $local_part_len <= 7
7516 (10.0 . "^[^0-9]+@")
7517 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7518 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7519 (3.0 . "\@stud")
7521 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7523 (0.5 . "^[A-Z][a-z]")
7524 (0.5 . "^[A-Z][a-z][a-z]")
7525 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7526 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7527 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7529 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7530 address. The REGEXP is processed with `case-fold-search' set to nil."
7531 :version "22.1"
7532 :group 'gnus-article-buttons
7533 :type '(repeat (cons (number :tag "Rate")
7534 (regexp :tag "Regexp"))))
7536 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7537 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7538 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7539 address, `ask' if unsure and `invalid' if the string is invalid."
7540 (let ((case-fold-search nil)
7541 (list gnus-button-mid-or-mail-heuristic-alist)
7542 (result 0) rate regexp lpartlen elem)
7543 (setq lpartlen
7544 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7545 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7546 ;; Certain special cases...
7547 (when (string-match
7548 (concat
7549 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7550 "^[0-9]+\\.[0-9]+@compuserve\\|"
7551 "@public\\.gmane\\.org")
7552 mid-or-mail)
7553 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7554 (setq result 'mail))
7555 (when (string-match "@.*@\\| " mid-or-mail)
7556 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7557 (setq result 'invalid))
7558 ;; Nothing more to do, if result is not a number here...
7559 (when (numberp result)
7560 (while list
7561 (setq elem (car list)
7562 rate (car elem)
7563 regexp (cdr elem)
7564 list (cdr list))
7565 (when (string-match regexp mid-or-mail)
7566 (setq result (+ result rate))
7567 (gnus-message
7568 9 "`%s' matched `%s', rate `%s', result `%s'."
7569 mid-or-mail regexp rate result)))
7570 (when (<= lpartlen 7)
7571 (setq result (+ result 5.0))
7572 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7573 mid-or-mail result))
7574 (when (>= lpartlen 12)
7575 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7576 (cond
7577 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7578 ;; Long local part should contain realname if e-mail address,
7579 ;; too many digits: message-id.
7580 ;; $score -= 5.0 + 0.1 * $local_part_len;
7581 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7582 (setq result (+ result rate))
7583 (gnus-message
7584 9 "Many digits in `%s', rate `%s', result `%s'."
7585 mid-or-mail rate result))
7586 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7587 mid-or-mail)
7588 ;; Too few vowels [^aeiouy]{4,}.*\@
7589 (setq result (+ result -5.0))
7590 (gnus-message
7591 9 "Few vowels in `%s', rate `%s', result `%s'."
7592 mid-or-mail -5.0 result))
7594 (setq result (+ result 5.0))
7595 (gnus-message
7596 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7597 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7598 ;; Maybe we should make this a customizable alist: (condition . 'result)
7599 (cond
7600 ((symbolp result) result)
7601 ;; Now convert number into proper results:
7602 ((< result -10.0) 'mid)
7603 ((> result 10.0) 'mail)
7604 (t 'ask))))
7606 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7607 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7608 (url-mid (concat "news" ":" mid-or-mail))
7609 (url-mailto (concat "mailto" ":" mid-or-mail)))
7610 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7611 (when (fboundp pref)
7612 (setq guessed
7613 ;; get rid of surrounding angles...
7614 (funcall pref
7615 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7616 (if (or (eq 'mid guessed) (eq 'mail guessed))
7617 (setq pref guessed)
7618 (setq pref 'ask)))
7619 (if (eq pref 'ask)
7620 (save-window-excursion
7621 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7622 (setq pref 'mail)
7623 (setq pref 'mid))))
7624 (cond ((eq pref 'mid)
7625 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7626 (gnus-button-handle-news url-mid))
7627 ((eq pref 'mail)
7628 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7629 (gnus-url-mailto url-mailto))
7630 (t (gnus-message 3 "Invalid string.")))))
7632 (defun gnus-button-handle-custom (fun arg)
7633 "Call function FUN on argument ARG.
7634 Both FUN and ARG are supposed to be strings. ARG will be passed
7635 as a symbol to FUN."
7636 (funcall (intern fun)
7637 (if (string-match "^customize-apropos" fun)
7639 (intern arg))))
7641 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7643 (defun gnus-button-handle-describe-function (url)
7644 "Call `describe-function' when pushing the corresponding URL button."
7645 (describe-function
7646 (intern
7647 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7649 (defun gnus-button-handle-describe-variable (url)
7650 "Call `describe-variable' when pushing the corresponding URL button."
7651 (describe-variable
7652 (intern
7653 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7655 (defun gnus-button-handle-symbol (url)
7656 "Display help on variable or function.
7657 Calls `describe-variable' or `describe-function'."
7658 (let ((sym (intern url)))
7659 (cond
7660 ((fboundp sym) (describe-function sym))
7661 ((boundp sym) (describe-variable sym))
7662 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7664 (defun gnus-button-handle-describe-key (url)
7665 "Call `describe-key' when pushing the corresponding URL button."
7666 (let* ((key-string
7667 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7668 (keys (ignore-errors (eval `(kbd ,key-string)))))
7669 (if keys
7670 (describe-key keys)
7671 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7673 (defun gnus-button-handle-apropos (url)
7674 "Call `apropos' when pushing the corresponding URL button."
7675 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7677 (defun gnus-button-handle-apropos-command (url)
7678 "Call `apropos' when pushing the corresponding URL button."
7679 (apropos-command
7680 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7682 (defun gnus-button-handle-apropos-variable (url)
7683 "Call `apropos' when pushing the corresponding URL button."
7684 (funcall
7685 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7686 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7688 (defun gnus-button-handle-apropos-documentation (url)
7689 "Call `apropos' when pushing the corresponding URL button."
7690 (funcall
7691 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7692 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7694 (defun gnus-button-handle-library (url)
7695 "Call `locate-library' when pushing the corresponding URL button."
7696 (gnus-message 9 "url=`%s'" url)
7697 (let* ((lib (locate-library url))
7698 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7699 (if (not lib)
7700 (gnus-message 1 "Cannot locale library `%s'." url)
7701 (find-file-read-only file))))
7703 (defcustom gnus-button-man-level 5
7704 "*Integer that says how many man-related buttons Gnus will show.
7705 The higher the number, the more buttons will appear and the more false
7706 positives are possible. Note that you can set this variable local to
7707 specific groups. Setting it higher in Unix groups is probably a good idea.
7708 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7709 how to set variables in specific groups."
7710 :version "22.1"
7711 :group 'gnus-article-buttons
7712 :link '(custom-manual "(gnus)Group Parameters")
7713 :type 'integer)
7715 (defcustom gnus-button-emacs-level 5
7716 "*Integer that says how many emacs-related buttons Gnus will show.
7717 The higher the number, the more buttons will appear and the more false
7718 positives are possible. Note that you can set this variable local to
7719 specific groups. Setting it higher in Emacs or Gnus related groups is
7720 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7721 `gnus-parameters' on how to set variables in specific groups."
7722 :version "22.1"
7723 :group 'gnus-article-buttons
7724 :link '(custom-manual "(gnus)Group Parameters")
7725 :type 'integer)
7727 (defcustom gnus-button-message-level 5
7728 "*Integer that says how many buttons for news or mail messages will appear.
7729 The higher the number, the more buttons will appear and the more false
7730 positives are possible."
7731 ;; mail addresses, MIDs, URLs for news, ...
7732 :version "22.1"
7733 :group 'gnus-article-buttons
7734 :type 'integer)
7736 (defcustom gnus-button-browse-level 5
7737 "*Integer that says how many buttons for browsing will appear.
7738 The higher the number, the more buttons will appear and the more false
7739 positives are possible."
7740 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7741 :version "22.1"
7742 :group 'gnus-article-buttons
7743 :type 'integer)
7745 (defcustom gnus-button-alist
7746 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7747 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7748 ((concat "\\b\\(nntp\\|news\\):\\("
7749 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7750 0 t gnus-button-handle-news 2)
7751 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7752 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7753 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7754 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7755 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7756 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7757 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7758 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7759 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7760 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7761 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7762 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7763 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7764 ;; RFC 2368 (The mailto URL scheme)
7765 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7766 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7767 ("\\bmailto:\\([^ \n\t]+\\)"
7768 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7769 ;; Info Konqueror style <info:/foo/bar baz>.
7770 ;; Must come before " Gnus home-grown style".
7771 ("\\binfo://?\\([^'\">\n\t]+\\)"
7772 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7773 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7774 ("\\binfo://\\([^'\">\n\t ]+\\)"
7775 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7776 ;; Info GNOME style <info:foo#bar_baz>
7777 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7778 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7779 ;; Info KDE style <info:(foo)bar baz>
7780 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7781 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7782 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7783 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7784 ("\\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,]*\\)\\)?"
7785 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7786 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7787 ;; This is custom
7788 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7789 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7790 ;; Emacs help commands
7791 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7792 ;; regexp doesn't match arguments containing ` '.
7793 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7794 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7795 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7796 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7797 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7798 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7799 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7800 ;; The following entries may lead to many false positives so don't enable
7801 ;; them by default (use a high button level).
7802 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7803 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7804 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7805 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7806 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7807 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7808 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7809 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7810 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7811 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7812 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7813 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7814 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7815 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7816 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7817 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7818 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7819 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7820 ;; Unlike the other regexps we really have to require quoting
7821 ;; here to determine where it ends.
7822 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7823 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7824 ("<URL: *\\([^\n<>]*\\)>"
7825 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7826 ;; RFC 2396 (2.4.3., delims) ...
7827 ("\"URL: *\\([^\n\"]*\\)\""
7828 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7829 ;; Raw URLs.
7830 (gnus-button-url-regexp
7831 0 (>= gnus-button-browse-level 0) browse-url 0)
7832 ;; man pages
7833 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7834 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7835 gnus-button-handle-man 1)
7836 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7837 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7838 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7839 gnus-button-handle-man 1)
7840 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7841 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7842 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7843 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7844 ;; Recognizing patches to .el files. This is somewhat obscure,
7845 ;; but considering the percentage of Gnus users who hack Emacs
7846 ;; Lisp files...
7847 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7848 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7849 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7850 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7851 ;; MID or mail: To avoid too many false positives we don't try to catch
7852 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7853 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7854 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7855 ;; so that non-ambiguous entries (see above) match first.
7856 (gnus-button-mid-or-mail-regexp
7857 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7858 "*Alist of regexps matching buttons in article bodies.
7860 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7861 REGEXP: is the string (case insensitive) matching text around the button (can
7862 also be Lisp expression evaluating to a string),
7863 BUTTON: is the number of the regexp grouping actually matching the button,
7864 FORM: is a Lisp expression which must eval to true for the button to
7865 be added,
7866 CALLBACK: is the function to call when the user push this button, and each
7867 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7869 CALLBACK can also be a variable, in that case the value of that
7870 variable it the real callback function."
7871 :group 'gnus-article-buttons
7872 :type '(repeat (list (choice regexp variable sexp)
7873 (integer :tag "Button")
7874 (sexp :tag "Form")
7875 (function :tag "Callback")
7876 (repeat :tag "Par"
7877 :inline t
7878 (integer :tag "Regexp group")))))
7879 (put 'gnus-button-alist 'risky-local-variable t)
7881 (defcustom gnus-header-button-alist
7882 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7883 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7884 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7885 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7886 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7887 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7888 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7889 0 (>= gnus-button-browse-level 0) browse-url 0)
7890 ("^Subject:" gnus-button-url-regexp
7891 0 (>= gnus-button-browse-level 0) browse-url 0)
7892 ("^[^:]+:" gnus-button-url-regexp
7893 0 (>= gnus-button-browse-level 0) browse-url 0)
7894 ("^OpenPGP:.*url=" gnus-button-url-regexp
7895 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7896 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7897 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7898 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7899 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7900 "*Alist of headers and regexps to match buttons in article heads.
7902 This alist is very similar to `gnus-button-alist', except that each
7903 alist has an additional HEADER element first in each entry:
7905 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7907 HEADER is a regexp to match a header. For a fuller explanation, see
7908 `gnus-button-alist'."
7909 :group 'gnus-article-buttons
7910 :group 'gnus-article-headers
7911 :type '(repeat (list (regexp :tag "Header")
7912 (choice regexp variable)
7913 (integer :tag "Button")
7914 (sexp :tag "Form")
7915 (function :tag "Callback")
7916 (repeat :tag "Par"
7917 :inline t
7918 (integer :tag "Regexp group")))))
7919 (put 'gnus-header-button-alist 'risky-local-variable t)
7921 ;;; Commands:
7923 (defun gnus-article-push-button (event)
7924 "Check text under the mouse pointer for a callback function.
7925 If the text under the mouse pointer has a `gnus-callback' property,
7926 call it with the value of the `gnus-data' text property."
7927 (interactive "e")
7928 (set-buffer (window-buffer (posn-window (event-start event))))
7929 (let* ((pos (posn-point (event-start event)))
7930 (data (get-text-property pos 'gnus-data))
7931 (fun (get-text-property pos 'gnus-callback)))
7932 (goto-char pos)
7933 (when fun
7934 (funcall fun data))))
7936 (defun gnus-article-press-button ()
7937 "Check text at point for a callback function.
7938 If the text at point has a `gnus-callback' property,
7939 call it with the value of the `gnus-data' text property."
7940 (interactive)
7941 (let ((data (get-text-property (point) 'gnus-data))
7942 (fun (get-text-property (point) 'gnus-callback)))
7943 (when fun
7944 (funcall fun data))))
7946 (defun gnus-article-highlight (&optional force)
7947 "Highlight current article.
7948 This function calls `gnus-article-highlight-headers',
7949 `gnus-article-highlight-citation',
7950 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7951 do the highlighting. See the documentation for those functions."
7952 (interactive (list 'force))
7953 (gnus-article-highlight-headers)
7954 (gnus-article-highlight-citation force)
7955 (gnus-article-highlight-signature)
7956 (gnus-article-add-buttons)
7957 (gnus-article-add-buttons-to-head))
7959 (defun gnus-article-highlight-some (&optional force)
7960 "Highlight current article.
7961 This function calls `gnus-article-highlight-headers',
7962 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7963 do the highlighting. See the documentation for those functions."
7964 (interactive (list 'force))
7965 (gnus-article-highlight-headers)
7966 (gnus-article-highlight-signature)
7967 (gnus-article-add-buttons))
7969 (defun gnus-article-highlight-headers ()
7970 "Highlight article headers as specified by `gnus-header-face-alist'."
7971 (interactive)
7972 (gnus-with-article-headers
7973 (let (regexp header-face field-face from hpoints fpoints)
7974 (dolist (entry gnus-header-face-alist)
7975 (goto-char (point-min))
7976 (setq regexp (concat "^\\("
7977 (if (string-equal "" (nth 0 entry))
7978 "[^\t ]"
7979 (nth 0 entry))
7980 "\\)")
7981 header-face (nth 1 entry)
7982 field-face (nth 2 entry))
7983 (while (and (re-search-forward regexp nil t)
7984 (not (eobp)))
7985 (beginning-of-line)
7986 (setq from (point))
7987 (unless (search-forward ":" nil t)
7988 (forward-char 1))
7989 (when (and header-face
7990 (not (memq (point) hpoints)))
7991 (push (point) hpoints)
7992 (gnus-put-text-property from (point) 'face header-face))
7993 (when (and field-face
7994 (not (memq (setq from (point)) fpoints)))
7995 (push from fpoints)
7996 (if (re-search-forward "^[^ \t]" nil t)
7997 (forward-char -2)
7998 (goto-char (point-max)))
7999 (gnus-put-text-property from (point) 'face field-face)))))))
8001 (defun gnus-article-highlight-signature ()
8002 "Highlight the signature in an article.
8003 It does this by highlighting everything after
8004 `gnus-signature-separator' using the face `gnus-signature'."
8005 (interactive)
8006 (gnus-with-article-buffer
8007 (let ((inhibit-point-motion-hooks t))
8008 (save-restriction
8009 (when (and gnus-signature-face
8010 (gnus-article-narrow-to-signature))
8011 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8012 'face gnus-signature-face)
8013 (widen)
8014 (gnus-article-search-signature)
8015 (let ((start (match-beginning 0))
8016 (end (set-marker (make-marker) (1+ (match-end 0)))))
8017 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8018 end)))))))
8020 (defun gnus-button-in-region-p (b e prop)
8021 "Say whether PROP exists in the region."
8022 (text-property-not-all b e prop nil))
8024 (defun gnus-article-add-buttons ()
8025 "Find external references in the article and make buttons of them.
8026 \"External references\" are things like Message-IDs and URLs, as
8027 specified by `gnus-button-alist'."
8028 (interactive)
8029 (gnus-with-article-buffer
8030 (let ((inhibit-point-motion-hooks t)
8031 (case-fold-search t)
8032 (alist gnus-button-alist)
8033 beg entry regexp)
8034 ;; We skip the headers.
8035 (article-goto-body)
8036 (setq beg (point))
8037 (while (setq entry (pop alist))
8038 (setq regexp (eval (car entry)))
8039 (goto-char beg)
8040 (while (re-search-forward regexp nil t)
8041 (let ((start (match-beginning (nth 1 entry)))
8042 (end (match-end (nth 1 entry)))
8043 (from (match-beginning 0)))
8044 (when (and (eval (nth 2 entry))
8045 (not (gnus-button-in-region-p
8046 start end 'gnus-callback)))
8047 ;; That optional form returned non-nil, so we add the
8048 ;; button.
8049 (setq from (set-marker (make-marker) from))
8050 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8051 (gnus-article-extend-url-button from start end))
8052 (gnus-article-add-button start end
8053 'gnus-button-push (list from entry))
8054 (gnus-put-text-property
8055 start end
8056 'gnus-string (buffer-substring-no-properties
8057 start end))))))))))
8059 (defun gnus-article-extend-url-button (beg start end)
8060 "Extend url button if url is folded into two or more lines.
8061 Return non-nil if button is extended. BEG is a marker that points to
8062 the beginning position of a text containing url. START and END are
8063 the endpoints of a url button before it is extended. The concatenated
8064 url is put as the `gnus-button-url' overlay property on the button."
8065 (let ((opoint (point))
8066 (points (list start end))
8067 url delim regexp)
8068 (prog1
8069 (when (and (progn
8070 (goto-char end)
8071 (not (looking-at "[\t ]*[\">]")))
8072 (progn
8073 (goto-char start)
8074 (string-match
8075 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8076 (buffer-substring (point-at-bol) start)))
8077 (progn
8078 (setq url (list (buffer-substring start end))
8079 delim (if (match-beginning 1) ">" "\""))
8080 (beginning-of-line)
8081 (setq regexp (concat
8082 (when (and (looking-at
8083 message-cite-prefix-regexp)
8084 (< (match-end 0) start))
8085 (regexp-quote (match-string 0)))
8087 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8088 delim "\\)"))
8089 (while (progn
8090 (forward-line 1)
8091 (and (looking-at regexp)
8092 (prog1
8093 (match-beginning 1)
8094 (push (or (match-string 2)
8095 (match-string 1))
8096 url)
8097 (push (setq end (or (match-end 2)
8098 (match-end 1)))
8099 points)
8100 (push (or (match-beginning 2)
8101 (match-beginning 1))
8102 points)))))
8103 (match-beginning 2)))
8104 (let (gnus-article-mouse-face widget-mouse-face)
8105 (while points
8106 (gnus-article-add-button (pop points) (pop points)
8107 'gnus-button-push
8108 (list beg (assq 'gnus-button-url-regexp
8109 gnus-button-alist)))))
8110 (let ((overlay (gnus-make-overlay start end)))
8111 (gnus-overlay-put overlay 'evaporate t)
8112 (gnus-overlay-put overlay 'gnus-button-url
8113 (list (mapconcat 'identity (nreverse url) "")))
8114 (when gnus-article-mouse-face
8115 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8117 (goto-char opoint))))
8119 ;; Add buttons to the head of an article.
8120 (defun gnus-article-add-buttons-to-head ()
8121 "Add buttons to the head of the article."
8122 (interactive)
8123 (gnus-with-article-headers
8124 (let (beg end)
8125 (dolist (entry gnus-header-button-alist)
8126 ;; Each alist entry.
8127 (goto-char (point-min))
8128 (while (re-search-forward (car entry) nil t)
8129 ;; Each header matching the entry.
8130 (setq beg (match-beginning 0))
8131 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8132 (match-beginning 0))
8133 (point-max)))
8134 (goto-char beg)
8135 (while (re-search-forward (eval (nth 1 entry)) end t)
8136 ;; Each match within a header.
8137 (let* ((entry (cdr entry))
8138 (start (match-beginning (nth 1 entry)))
8139 (end (match-end (nth 1 entry)))
8140 (form (nth 2 entry)))
8141 (goto-char (match-end 0))
8142 (when (eval form)
8143 (gnus-article-add-button
8144 start end (nth 3 entry)
8145 (buffer-substring (match-beginning (nth 4 entry))
8146 (match-end (nth 4 entry)))))))
8147 (goto-char end))))))
8149 ;;; External functions:
8151 (defun gnus-article-add-button (from to fun &optional data text)
8152 "Create a button between FROM and TO with callback FUN and data DATA."
8153 (when gnus-article-button-face
8154 (gnus-overlay-put (gnus-make-overlay from to nil t)
8155 'face gnus-article-button-face))
8156 (gnus-add-text-properties
8157 from to
8158 (nconc (and gnus-article-mouse-face
8159 (list gnus-mouse-face-prop gnus-article-mouse-face))
8160 (list 'gnus-callback fun)
8161 (and data (list 'gnus-data data))))
8162 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8163 :help-echo (or text "Follow the link")
8164 :keymap gnus-url-button-map
8165 :button-keymap gnus-widget-button-keymap))
8167 (defun gnus-article-copy-string ()
8168 "Copy the string in the button to the kill ring."
8169 (interactive)
8170 (gnus-article-check-buffer)
8171 (let ((data (get-text-property (point) 'gnus-string)))
8172 (when data
8173 (with-temp-buffer
8174 (insert data)
8175 (copy-region-as-kill (point-min) (point-max))
8176 (message "Copied %s" data)))))
8178 ;;; Internal functions:
8180 (defun gnus-article-set-globals ()
8181 (with-current-buffer gnus-summary-buffer
8182 (gnus-set-global-variables)))
8184 (defun gnus-signature-toggle (end)
8185 (gnus-with-article-buffer
8186 (let ((inhibit-point-motion-hooks t))
8187 (if (text-property-any end (point-max) 'article-type 'signature)
8188 (progn
8189 (gnus-delete-wash-type 'signature)
8190 (gnus-remove-text-properties-when
8191 'article-type 'signature end (point-max)
8192 (cons 'article-type (cons 'signature
8193 gnus-hidden-properties))))
8194 (gnus-add-wash-type 'signature)
8195 (gnus-add-text-properties-when
8196 'article-type nil end (point-max)
8197 (cons 'article-type (cons 'signature
8198 gnus-hidden-properties)))))
8199 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8200 (gnus-set-mode-line 'article))))
8202 (defun gnus-button-push (marker-and-entry)
8203 ;; Push button starting at MARKER.
8204 (save-excursion
8205 (let* ((marker (car marker-and-entry))
8206 (entry (cadr marker-and-entry))
8207 (regexp (car entry))
8208 (inhibit-point-motion-hooks t))
8209 (goto-char marker)
8210 ;; This is obviously true, or something bad is happening :)
8211 ;; But we need it to have the match-data
8212 (when (looking-at (or (if (symbolp regexp)
8213 (symbol-value regexp)
8214 regexp)))
8215 (let ((fun (nth 3 entry))
8216 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8217 (get-char-property marker 'gnus-button-url))
8218 (mapcar (lambda (group)
8219 (let ((string (match-string group)))
8220 (set-text-properties
8221 0 (length string) nil string)
8222 string))
8223 (nthcdr 4 entry)))))
8225 (cond
8226 ((fboundp fun)
8227 (apply fun args))
8228 ((and (boundp fun)
8229 (fboundp (symbol-value fun)))
8230 (apply (symbol-value fun) args))
8232 (gnus-message 1 "You must define `%S' to use this button"
8233 (cons fun args)))))))))
8235 (defun gnus-parse-news-url (url)
8236 (let (scheme server port group message-id articles)
8237 (with-temp-buffer
8238 (insert url)
8239 (goto-char (point-min))
8240 (when (looking-at "\\([A-Za-z]+\\):")
8241 (setq scheme (match-string 1))
8242 (goto-char (match-end 0)))
8243 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8244 (setq server (match-string 1))
8245 (setq port (if (stringp (match-string 3))
8246 (string-to-number (match-string 3))
8247 (match-string 3)))
8248 (goto-char (match-end 0)))
8250 (cond
8251 ((looking-at "\\(.*@.*\\)")
8252 (setq message-id (match-string 1)))
8253 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8254 (setq group (match-string 1)
8255 articles (split-string (match-string 2) "-")))
8256 ((looking-at "\\([^/]+\\)/?")
8257 (setq group (match-string 1)))
8259 (error "Unknown news URL syntax"))))
8260 (list scheme server port group message-id articles)))
8262 (defun gnus-button-handle-news (url)
8263 "Fetch a news URL."
8264 (destructuring-bind (scheme server port group message-id articles)
8265 (gnus-parse-news-url url)
8266 (cond
8267 (message-id
8268 (with-current-buffer gnus-summary-buffer
8269 (if server
8270 (let ((gnus-refer-article-method
8271 (nconc (list (list 'nntp server))
8272 gnus-refer-article-method))
8273 (nntp-port-number (or port "nntp")))
8274 (gnus-message 7 "Fetching %s with %s"
8275 message-id gnus-refer-article-method)
8276 (gnus-summary-refer-article message-id))
8277 (gnus-summary-refer-article message-id))))
8278 (group
8279 (gnus-button-fetch-group url)))))
8281 (defun gnus-button-patch (library line)
8282 "Visit an Emacs Lisp library LIBRARY on line LINE."
8283 (interactive)
8284 (let ((file (locate-library (file-name-nondirectory library))))
8285 (unless file
8286 (error "Couldn't find library %s" library))
8287 (find-file file)
8288 (goto-char (point-min))
8289 (forward-line (1- (string-to-number line)))))
8291 (defun gnus-button-handle-man (url)
8292 "Fetch a man page."
8293 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8294 (when (eq gnus-button-man-handler 'woman)
8295 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8296 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8297 (funcall gnus-button-man-handler url))
8299 (defun gnus-button-handle-info-url (url)
8300 "Fetch an info URL."
8301 (setq url (mm-subst-char-in-string ?+ ?\ url))
8302 (cond
8303 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8304 (gnus-info-find-node
8305 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8306 "Gnus")
8307 ")" (gnus-url-unhex-string (match-string 2 url)))))
8308 ((string-match "([^)\"]+)[^\"]+" url)
8309 (setq url
8310 (gnus-replace-in-string
8311 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8312 (gnus-info-find-node url))
8313 (t (error "Can't parse %s" url))))
8315 (defun gnus-button-handle-info-url-gnome (url)
8316 "Fetch GNOME style info URL."
8317 (setq url (mm-subst-char-in-string ?_ ?\ url))
8318 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8319 (gnus-info-find-node
8320 (concat "("
8321 (gnus-url-unhex-string
8322 (match-string 1 url))
8324 (or (gnus-url-unhex-string
8325 (match-string 2 url))
8326 "Top")))
8327 (error "Can't parse %s" url)))
8329 (defun gnus-button-handle-info-url-kde (url)
8330 "Fetch KDE style info URL."
8331 (gnus-info-find-node (gnus-url-unhex-string url)))
8333 ;; (info) will autoload info.el
8334 (declare-function Info-menu "info" (menu-item &optional fork))
8335 (declare-function Info-index-next "info" (num))
8337 (defun gnus-button-handle-info-keystrokes (url)
8338 "Call `info' when pushing the corresponding URL button."
8339 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8340 (let (node indx comma)
8341 (if (string-match
8342 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8343 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8344 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8345 "\\(?:[ \t\n,]*\\)\\)?")
8346 url)
8347 (setq node (match-string 2 url)
8348 indx (match-string 3 url))
8349 (error "Can't parse %s" url))
8350 (info)
8351 (Info-directory)
8352 (Info-menu node)
8353 (when (> (length indx) 0)
8354 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8355 "\\([ \t\n,]*\\)")
8356 indx)
8357 (setq comma (match-string 2 indx))
8358 (setq indx (match-string 1 indx))
8359 (Info-index indx)
8360 (when comma
8361 (dotimes (i (with-temp-buffer
8362 (insert comma)
8363 ;; Note: the XEmacs version of `how-many' takes
8364 ;; no optional argument.
8365 (goto-char (point-min))
8366 (how-many ",")))
8367 (Info-index-next 1)))
8368 nil)))
8370 (autoload 'pgg-snarf-keys-region "pgg")
8371 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8372 (declare-function pgg-display-output-buffer "pgg" (start end status))
8374 (defun gnus-button-openpgp (url)
8375 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8376 (with-temp-buffer
8377 (mm-url-insert-file-contents-external url)
8378 (pgg-snarf-keys-region (point-min) (point-max))
8379 (pgg-display-output-buffer nil nil nil)))
8381 (defun gnus-button-message-id (message-id)
8382 "Fetch MESSAGE-ID."
8383 (with-current-buffer gnus-summary-buffer
8384 (gnus-summary-refer-article message-id)))
8386 (defun gnus-button-fetch-group (address &rest ignore)
8387 "Fetch GROUP specified by ADDRESS."
8388 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8389 address)
8390 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8391 ;; for nntp:// and news://
8392 (setq address (match-string 3 address)))
8393 (if (not (string-match "[:/]" address))
8394 ;; This is just a simple group url.
8395 (gnus-group-read-ephemeral-group address gnus-select-method)
8396 (if (not
8397 (string-match
8398 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8399 address))
8400 (error "Can't parse %s" address)
8401 (gnus-group-read-ephemeral-group
8402 (match-string 4 address)
8403 `(nntp ,(match-string 1 address)
8404 (nntp-address ,(match-string 1 address))
8405 (nntp-port-number ,(if (match-end 3)
8406 (match-string 3 address)
8407 "nntp")))
8408 nil nil nil
8409 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8411 (defun gnus-url-parse-query-string (query &optional downcase)
8412 (let (retval pairs cur key val)
8413 (setq pairs (split-string query "&"))
8414 (while pairs
8415 (setq cur (car pairs)
8416 pairs (cdr pairs))
8417 (if (not (string-match "=" cur))
8418 nil ; Grace
8419 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8420 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8421 (if downcase
8422 (setq key (downcase key)))
8423 (setq cur (assoc key retval))
8424 (if cur
8425 (setcdr cur (cons val (cdr cur)))
8426 (setq retval (cons (list key val) retval)))))
8427 retval))
8429 (defun gnus-url-mailto (url)
8430 ;; Send mail to someone
8431 (setq url (replace-regexp-in-string "\n" " " url))
8432 (when (string-match "mailto:/*\\(.*\\)" url)
8433 (setq url (substring url (match-beginning 1) nil)))
8434 (let (to args subject func)
8435 (setq args (gnus-url-parse-query-string
8436 (if (string-match "^\\?" url)
8437 (substring url 1)
8438 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8439 (concat "to=" (match-string 1 url) "&"
8440 (match-string 2 url))
8441 (concat "to=" url))))
8442 subject (cdr-safe (assoc "subject" args)))
8443 (gnus-msg-mail)
8444 (while args
8445 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8446 (if (fboundp func)
8447 (funcall func)
8448 (message-position-on-field (caar args)))
8449 (insert (gnus-replace-in-string
8450 (mapconcat 'identity (reverse (cdar args)) ", ")
8451 "\r\n" "\n" t))
8452 (setq args (cdr args)))
8453 (if subject
8454 (message-goto-body)
8455 (message-goto-subject))))
8457 (defun gnus-button-embedded-url (address)
8458 "Activate ADDRESS with `browse-url'."
8459 (browse-url (gnus-strip-whitespace address)))
8461 ;;; Next/prev buttons in the article buffer.
8463 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8464 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8466 (defvar gnus-prev-page-map
8467 (let ((map (make-sparse-keymap)))
8468 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8469 (define-key map "\r" 'gnus-button-prev-page)
8470 map))
8472 (defvar gnus-next-page-map
8473 (let ((map (make-sparse-keymap)))
8474 (define-key map gnus-mouse-2 'gnus-button-next-page)
8475 (define-key map "\r" 'gnus-button-next-page)
8476 map))
8478 (defun gnus-insert-prev-page-button ()
8479 (let ((b (point)) e
8480 (inhibit-read-only t))
8481 (gnus-eval-format
8482 gnus-prev-page-line-format nil
8483 `(keymap ,gnus-prev-page-map
8484 gnus-prev t
8485 gnus-callback gnus-article-button-prev-page
8486 article-type annotation))
8487 (setq e (if (bolp)
8488 ;; Exclude a newline.
8489 (1- (point))
8490 (point)))
8491 (when gnus-article-button-face
8492 (gnus-overlay-put (gnus-make-overlay b e nil t)
8493 'face gnus-article-button-face))
8494 (widget-convert-button
8495 'link b e
8496 :action 'gnus-button-prev-page
8497 :button-keymap gnus-prev-page-map)))
8499 (defun gnus-button-next-page (&optional args more-args)
8500 "Go to the next page."
8501 (interactive)
8502 (let ((win (selected-window)))
8503 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8504 (gnus-article-next-page)
8505 (select-window win)))
8507 (defun gnus-button-prev-page (&optional args more-args)
8508 "Go to the prev page."
8509 (interactive)
8510 (let ((win (selected-window)))
8511 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8512 (gnus-article-prev-page)
8513 (select-window win)))
8515 (defun gnus-insert-next-page-button ()
8516 (let ((b (point)) e
8517 (inhibit-read-only t))
8518 (gnus-eval-format gnus-next-page-line-format nil
8519 `(keymap ,gnus-next-page-map
8520 gnus-next t
8521 gnus-callback gnus-article-button-next-page
8522 article-type annotation))
8523 (setq e (if (bolp)
8524 ;; Exclude a newline.
8525 (1- (point))
8526 (point)))
8527 (when gnus-article-button-face
8528 (gnus-overlay-put (gnus-make-overlay b e nil t)
8529 'face gnus-article-button-face))
8530 (widget-convert-button
8531 'link b e
8532 :action 'gnus-button-next-page
8533 :button-keymap gnus-next-page-map)))
8535 (defun gnus-article-button-next-page (arg)
8536 "Go to the next page."
8537 (interactive "P")
8538 (let ((win (selected-window)))
8539 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8540 (gnus-article-next-page)
8541 (select-window win)))
8543 (defun gnus-article-button-prev-page (arg)
8544 "Go to the prev page."
8545 (interactive "P")
8546 (let ((win (selected-window)))
8547 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8548 (gnus-article-prev-page)
8549 (select-window win)))
8551 (defvar gnus-decode-header-methods
8552 '(mail-decode-encoded-word-region)
8553 "List of methods used to decode headers.
8555 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8556 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8557 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8558 whose names match REGEXP.
8560 For example:
8561 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8562 mail-decode-encoded-word-region
8563 (\"chinese\" . rfc1843-decode-region))
8566 (defvar gnus-decode-header-methods-cache nil)
8568 (defun gnus-multi-decode-header (start end)
8569 "Apply the functions from `gnus-encoded-word-methods' that match."
8570 (unless (and gnus-decode-header-methods-cache
8571 (eq gnus-newsgroup-name
8572 (car gnus-decode-header-methods-cache)))
8573 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8574 (dolist (x gnus-decode-header-methods)
8575 (if (symbolp x)
8576 (nconc gnus-decode-header-methods-cache (list x))
8577 (if (and gnus-newsgroup-name
8578 (string-match (car x) gnus-newsgroup-name))
8579 (nconc gnus-decode-header-methods-cache
8580 (list (cdr x)))))))
8581 (let ((xlist gnus-decode-header-methods-cache))
8582 (pop xlist)
8583 (save-restriction
8584 (narrow-to-region start end)
8585 (while xlist
8586 (funcall (pop xlist) (point-min) (point-max))))))
8589 ;;; Treatment top-level handling.
8592 (defvar gnus-inhibit-article-treatments nil)
8594 (defun gnus-treat-article (gnus-treat-condition
8595 &optional part-number total-parts gnus-treat-type)
8596 (let ((gnus-treat-length (- (point-max) (point-min)))
8597 (alist gnus-treatment-function-alist)
8598 (article-goto-body-goes-to-point-min-p t)
8599 (treated-type
8600 (or (not gnus-treat-type)
8601 (catch 'found
8602 (let ((list gnus-article-treat-types))
8603 (while list
8604 (when (string-match (pop list) gnus-treat-type)
8605 (throw 'found t)))))))
8606 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8607 val elem)
8608 (gnus-run-hooks 'gnus-part-display-hook)
8609 (dolist (elem alist)
8610 (setq val
8611 (save-excursion
8612 (when (gnus-buffer-live-p gnus-summary-buffer)
8613 (set-buffer gnus-summary-buffer))
8614 (symbol-value (car elem))))
8615 (when (and (or (consp val)
8616 treated-type)
8617 (or (not gnus-inhibit-article-treatments)
8618 (eq gnus-treat-condition 'head))
8619 (gnus-treat-predicate val)
8620 (or (not (get (car elem) 'highlight))
8621 highlightp))
8622 (save-restriction
8623 (funcall (cadr elem)))))))
8625 ;; Dynamic variables.
8626 (defvar part-number)
8627 (defvar total-parts)
8628 (defvar gnus-treat-type)
8629 (defvar gnus-treat-condition)
8630 (defvar gnus-treat-length)
8632 (defun gnus-treat-predicate (val)
8633 (cond
8634 ((null val)
8635 nil)
8636 (gnus-treat-condition
8637 (eq gnus-treat-condition val))
8638 ((and (listp val)
8639 (stringp (car val)))
8640 (apply 'gnus-or (mapcar `(lambda (s)
8641 (string-match s ,(or gnus-newsgroup-name "")))
8642 val)))
8643 ((listp val)
8644 (let ((pred (pop val)))
8645 (cond
8646 ((eq pred 'or)
8647 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8648 ((eq pred 'and)
8649 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8650 ((eq pred 'not)
8651 (not (gnus-treat-predicate (car val))))
8652 ((eq pred 'typep)
8653 (equal (car val) gnus-treat-type))
8654 ((functionp pred)
8655 (funcall pred))
8657 (error "%S is not a valid predicate" pred)))))
8658 ((eq val t)
8660 ((eq val 'head)
8661 nil)
8662 ((eq val 'first)
8663 (eq part-number 1))
8664 ((eq val 'last)
8665 (eq part-number total-parts))
8666 ((numberp val)
8667 (< gnus-treat-length val))
8669 (error "%S is not a valid value" val))))
8671 (defun gnus-article-encrypt-body (protocol &optional n)
8672 "Encrypt the article body."
8673 (interactive
8674 (list
8675 (or gnus-article-encrypt-protocol
8676 (gnus-completing-read "Encrypt protocol"
8677 (mapcar 'car gnus-article-encrypt-protocol-alist)
8679 current-prefix-arg))
8680 ;; User might hit `K E' instead of `K e', so prompt once.
8681 (when (and gnus-article-encrypt-protocol
8682 gnus-novice-user)
8683 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8684 (error "Encrypt aborted")))
8685 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8686 (unless func
8687 (error "Can't find the encrypt protocol %s" protocol))
8688 (if (member gnus-newsgroup-name '("nndraft:delayed"
8689 "nndraft:drafts"
8690 "nndraft:queue"))
8691 (error "Can't encrypt the article in group %s"
8692 gnus-newsgroup-name))
8693 (gnus-summary-iterate n
8694 (with-current-buffer gnus-summary-buffer
8695 (let ((mail-parse-charset gnus-newsgroup-charset)
8696 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8697 (summary-buffer gnus-summary-buffer)
8698 references point)
8699 (gnus-set-global-variables)
8700 (when (gnus-group-read-only-p)
8701 (error "The current newsgroup does not support article encrypt"))
8702 (gnus-summary-show-article t)
8703 (setq references
8704 (or (mail-header-references gnus-current-headers) ""))
8705 (set-buffer gnus-article-buffer)
8706 (let* ((inhibit-read-only t)
8707 (headers
8708 (mapcar (lambda (field)
8709 (and (save-restriction
8710 (message-narrow-to-head)
8711 (goto-char (point-min))
8712 (search-forward field nil t))
8713 (prog2
8714 (message-narrow-to-field)
8715 (buffer-string)
8716 (delete-region (point-min) (point-max))
8717 (widen))))
8718 '("Content-Type:" "Content-Transfer-Encoding:"
8719 "Content-Disposition:"))))
8720 (message-narrow-to-head)
8721 (message-remove-header "MIME-Version")
8722 (goto-char (point-max))
8723 (setq point (point))
8724 (insert (apply 'concat headers))
8725 (widen)
8726 (narrow-to-region point (point-max))
8727 (let ((message-options message-options))
8728 (message-options-set 'message-sender user-mail-address)
8729 (message-options-set 'message-recipients user-mail-address)
8730 (message-options-set 'message-sign-encrypt 'not)
8731 (funcall func))
8732 (goto-char (point-min))
8733 (insert "MIME-Version: 1.0\n")
8734 (widen)
8735 (gnus-summary-edit-article-done
8736 references nil summary-buffer t))
8737 (when gnus-keep-backlog
8738 (gnus-backlog-remove-article
8739 (car gnus-article-current) (cdr gnus-article-current)))
8740 (gnus-flush-original-article-buffer)
8741 (when gnus-use-cache
8742 (gnus-cache-update-article
8743 (car gnus-article-current) (cdr gnus-article-current))))))))
8745 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8746 "The following specs can be used:
8747 %t The security MIME type
8748 %i Additional info
8749 %d Details
8750 %D Details if button is pressed")
8752 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8753 "The following specs can be used:
8754 %t The security MIME type
8755 %i Additional info
8756 %d Details
8757 %D Details if button is pressed")
8759 (defvar gnus-mime-security-button-line-format-alist
8760 '((?t gnus-tmp-type ?s)
8761 (?i gnus-tmp-info ?s)
8762 (?d gnus-tmp-details ?s)
8763 (?D gnus-tmp-pressed-details ?s)))
8765 (defvar gnus-mime-security-button-commands
8766 '((gnus-article-press-button "\r" "Show Detail")
8767 (undefined "v")
8768 (undefined "t")
8769 (undefined "C")
8770 (gnus-mime-security-save-part "o" "Save...")
8771 (undefined "\C-o")
8772 (undefined "r")
8773 (undefined "d")
8774 (undefined "c")
8775 (undefined "i")
8776 (undefined "E")
8777 (undefined "e")
8778 (undefined "p")
8779 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8780 (undefined ".")))
8782 (defvar gnus-mime-security-button-map
8783 (let ((map (make-sparse-keymap)))
8784 (define-key map gnus-mouse-2 'gnus-article-push-button)
8785 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8786 (dolist (c gnus-mime-security-button-commands)
8787 (define-key map (cadr c) (car c)))
8788 map))
8790 (easy-menu-define
8791 gnus-mime-security-button-menu gnus-mime-security-button-map
8792 "Security button menu."
8793 `("Security Part"
8794 ,@(delq nil
8795 (mapcar (lambda (c)
8796 (unless (eq (car c) 'undefined)
8797 (vector (caddr c) (car c) :active t)))
8798 gnus-mime-security-button-commands))))
8800 (defun gnus-mime-security-button-menu (event prefix)
8801 "Construct a context-sensitive menu of security commands."
8802 (interactive "e\nP")
8803 (save-window-excursion
8804 (let ((pos (event-start event)))
8805 (select-window (posn-window pos))
8806 (goto-char (posn-point pos))
8807 (gnus-article-check-buffer)
8808 (popup-menu gnus-mime-security-button-menu nil prefix))))
8810 (defvar gnus-mime-security-details-buffer nil)
8812 (defvar gnus-mime-security-button-pressed nil)
8814 (defvar gnus-mime-security-show-details-inline t
8815 "If non-nil, show details in the article buffer.")
8817 (defun gnus-mime-security-verify-or-decrypt (handle)
8818 (mm-remove-parts (cdr handle))
8819 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8820 point (inhibit-read-only t))
8821 (if region
8822 (goto-char (car region)))
8823 (setq point (point))
8824 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8825 (let* ((mm-verify-option 'known)
8826 (mm-decrypt-option 'known)
8827 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8828 (unless (eq nparts (cdr handle))
8829 (mm-destroy-parts (cdr handle))
8830 (setcdr handle nparts))))
8831 (gnus-mime-display-security handle)
8832 (when region
8833 (delete-region (point) (cdr region))
8834 (set-marker (car region) nil)
8835 (set-marker (cdr region) nil))
8836 (goto-char point)))
8838 (defun gnus-mime-security-show-details (handle)
8839 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8840 (if (not details)
8841 (gnus-message 5 "No details.")
8842 (if gnus-mime-security-show-details-inline
8843 (let ((gnus-mime-security-button-pressed
8844 (not (get-text-property (point) 'gnus-mime-details)))
8845 (gnus-mime-security-button-line-format
8846 (get-text-property (point) 'gnus-line-format))
8847 (inhibit-read-only t))
8848 (forward-char -1)
8849 (while (eq (get-text-property (point) 'gnus-line-format)
8850 gnus-mime-security-button-line-format)
8851 (forward-char -1))
8852 (forward-char)
8853 (save-restriction
8854 (narrow-to-region (point) (point))
8855 (gnus-insert-mime-security-button handle))
8856 (delete-region (point)
8857 (or (text-property-not-all
8858 (point) (point-max)
8859 'gnus-line-format
8860 gnus-mime-security-button-line-format)
8861 (point-max))))
8862 ;; Not inlined.
8863 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8864 (with-current-buffer gnus-mime-security-details-buffer
8865 (erase-buffer)
8867 (setq gnus-mime-security-details-buffer
8868 (gnus-get-buffer-create "*MIME Security Details*")))
8869 (with-current-buffer gnus-mime-security-details-buffer
8870 (insert details)
8871 (goto-char (point-min)))
8872 (pop-to-buffer gnus-mime-security-details-buffer)))))
8874 (defun gnus-mime-security-press-button (handle)
8875 (save-excursion
8876 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8877 (gnus-mime-security-show-details handle)
8878 (gnus-mime-security-verify-or-decrypt handle))))
8880 (defun gnus-insert-mime-security-button (handle &optional displayed)
8881 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8882 (gnus-tmp-type
8883 (concat
8884 (or (nth 2 (assoc protocol mm-verify-function-alist))
8885 (nth 2 (assoc protocol mm-decrypt-function-alist))
8886 "Unknown")
8887 (if (equal (car handle) "multipart/signed")
8888 " Signed" " Encrypted")
8889 " Part"))
8890 (gnus-tmp-info
8891 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8892 "Undecided"))
8893 (gnus-tmp-details
8894 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8895 gnus-tmp-pressed-details
8896 b e)
8897 (setq gnus-tmp-details
8898 (if gnus-tmp-details
8899 (concat "\n" gnus-tmp-details)
8900 ""))
8901 (setq gnus-tmp-pressed-details
8902 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8903 (unless (bolp)
8904 (insert "\n"))
8905 (setq b (point))
8906 (gnus-eval-format
8907 gnus-mime-security-button-line-format
8908 gnus-mime-security-button-line-format-alist
8909 `(keymap ,gnus-mime-security-button-map
8910 gnus-callback gnus-mime-security-press-button
8911 gnus-line-format ,gnus-mime-security-button-line-format
8912 gnus-mime-details ,gnus-mime-security-button-pressed
8913 article-type annotation
8914 gnus-data ,handle))
8915 (setq e (if (bolp)
8916 ;; Exclude a newline.
8917 (1- (point))
8918 (point)))
8919 (when gnus-article-button-face
8920 (gnus-overlay-put (gnus-make-overlay b e nil t)
8921 'face gnus-article-button-face))
8922 (widget-convert-button
8923 'link b e
8924 :mime-handle handle
8925 :action 'gnus-widget-press-button
8926 :button-keymap gnus-mime-security-button-map
8927 :help-echo
8928 (lambda (widget)
8929 ;; Needed to properly clear the message due to a bug in
8930 ;; wid-edit (XEmacs only).
8931 (when (boundp 'help-echo-owns-message)
8932 (setq help-echo-owns-message t))
8933 (format
8934 "%S: show detail; %S: more options"
8935 (aref gnus-mouse-2 0)
8936 (aref gnus-down-mouse-3 0))))))
8938 (defun gnus-mime-display-security (handle)
8939 (save-restriction
8940 (narrow-to-region (point) (point))
8941 (unless (gnus-unbuttonized-mime-type-p (car handle))
8942 (gnus-insert-mime-security-button handle))
8943 (gnus-mime-display-part (cadr handle))
8944 (unless (bolp)
8945 (insert "\n"))
8946 (unless (gnus-unbuttonized-mime-type-p (car handle))
8947 (let ((gnus-mime-security-button-line-format
8948 gnus-mime-security-button-end-line-format))
8949 (gnus-insert-mime-security-button handle)))
8950 (mm-set-handle-multipart-parameter
8951 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8952 (goto-char (point-max))))
8954 (defun gnus-mime-security-run-function (function)
8955 "Run FUNCTION with the security part under point."
8956 (gnus-article-check-buffer)
8957 (let ((data (get-text-property (point) 'gnus-data))
8958 buffer handle)
8959 (when (and (stringp (car-safe data))
8960 (setq buffer (mm-handle-multipart-original-buffer data))
8961 (setq handle (cadr data)))
8962 (if (bufferp (mm-handle-buffer handle))
8963 (progn
8964 (setq handle (cons buffer (copy-sequence (cdr handle))))
8965 (mm-handle-set-undisplayer handle nil))
8966 (setq handle (mm-make-handle
8967 buffer
8968 (mm-handle-multipart-ctl-parameter handle 'protocol)
8969 nil nil nil nil nil nil)))
8970 (funcall function handle))))
8972 (defun gnus-mime-security-save-part ()
8973 "Save the security part under point."
8974 (interactive)
8975 (gnus-mime-security-run-function 'mm-save-part))
8977 (defun gnus-mime-security-pipe-part ()
8978 "Pipe the security part under point to a process."
8979 (interactive)
8980 (gnus-mime-security-run-function 'mm-pipe-part))
8982 (gnus-ems-redefine)
8984 (provide 'gnus-art)
8986 (run-hooks 'gnus-art-load-hook)
8988 ;;; gnus-art.el ends here