gnus-art.el (article-transform-date): Fix infinite recursion.
[bpt/emacs.git] / lisp / gnus / gnus-art.el
CommitLineData
eec82323 1;;; gnus-art.el --- article mode commands for Gnus
e84b4b86 2
73b0cd50 3;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
eec82323
LMI
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2ff9f5b4 17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
22
23;;; Commentary:
24
25;;; Code:
26
f0b7f5a8 27;; For Emacs <22.2 and XEmacs.
9640c3bc
GM
28(eval-and-compile
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
23f87bed 30(eval-when-compile
9efa445f
DN
31 (require 'cl))
32(defvar tool-bar-map)
33(defvar w3m-minor-mode-map)
5ab7173c 34
eec82323 35(require 'gnus)
5843126b 36(require 'gnus-sum)
eec82323
LMI
37(require 'gnus-spec)
38(require 'gnus-int)
23f87bed 39(require 'gnus-win)
16409b0b
GM
40(require 'mm-bodies)
41(require 'mail-parse)
42(require 'mm-decode)
43(require 'mm-view)
44(require 'wid-edit)
45(require 'mm-uu)
23f87bed
MB
46(require 'message)
47
48(autoload 'gnus-msg-mail "gnus-msg" nil t)
49(autoload 'gnus-button-mailto "gnus-msg")
50(autoload 'gnus-button-reply "gnus-msg" nil t)
498063ec 51(autoload 'parse-time-string "parse-time" nil nil)
01c52d31
MB
52(autoload 'ansi-color-apply-on-region "ansi-color")
53(autoload 'mm-url-insert-file-contents-external "mm-url")
531bedc3 54(autoload 'mm-extern-cache-contents "mm-extern")
eec82323
LMI
55
56(defgroup gnus-article nil
57 "Article display."
23f87bed 58 :link '(custom-manual "(gnus)Article Buffer")
eec82323
LMI
59 :group 'gnus)
60
16409b0b
GM
61(defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
64 :group 'gnus-article)
65
eec82323
LMI
66(defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
69 :group 'gnus-article)
70
71(defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
74 :group 'gnus-article
75 :group 'gnus-visual)
76
77(defgroup gnus-article-signature nil
78 "Article signatures."
79 :link '(custom-manual "(gnus)Article Signature")
80 :group 'gnus-article)
81
82(defgroup gnus-article-headers nil
83 "Article headers."
84 :link '(custom-manual "(gnus)Hiding Headers")
85 :group 'gnus-article)
86
87(defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
90 :group 'gnus-article)
91
92(defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
95 :group 'gnus-article)
96
97(defgroup gnus-article-saving nil
98 "Saving articles."
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
101
102(defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
106
107(defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
111
112(defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
116
117(defcustom gnus-ignored-headers
23f87bed
MB
118 (mapcar
119 (lambda (header)
120 (concat "^" header ":"))
121 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127 "X-Attribution" "X-Originating-IP" "Delivered-To"
128 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144 "List-[A-Za-z]+" "X-Listprocessor-Version"
145 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147 "X-Received" "Content-length" "X-precedence"
148 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153 "X-Content-length" "X-Posting-Agent" "Original-Received"
154 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
01c52d31
MB
158 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161 "Envelope-Sender" "Envelope-Recipients"))
6748645f 162 "*All headers that start with this regexp will be hidden.
eec82323
LMI
163This variable can also be a list of regexps of headers to be ignored.
164If `gnus-visible-headers' is non-nil, this variable will be ignored."
165 :type '(choice :custom-show nil
166 regexp
167 (repeat regexp))
168 :group 'gnus-article-hiding)
169
170(defcustom gnus-visible-headers
12e3ca0a 171 "^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:"
6748645f 172 "*All headers that do not match this regexp will be hidden.
eec82323
LMI
173This variable can also be a list of regexp of headers to remain visible.
174If this variable is non-nil, `gnus-ignored-headers' will be ignored."
9b3ebcb6
MB
175 :type '(choice
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
179 (or (stringp value)
180 (widget-editable-list-match widget value)))
181 regexp)
182 (const :tag "Use gnus-ignored-headers" nil)
183 regexp)
eec82323
LMI
184 :group 'gnus-article-hiding)
185
186(defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
6748645f 189 "*This variable is a list of regular expressions.
eec82323
LMI
190If it is non-nil, headers that match the regular expressions will
191be placed first in the article buffer in the sequence specified by
192this list."
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
195
196(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
23f87bed
MB
198Possible values in this list are:
199
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
eec82323 210 :type '(set (const :tag "Headers with no content." empty)
23f87bed
MB
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
6748645f 217 (const :tag "Date less than four days old." date)
23f87bed 218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
16409b0b 219 (const :tag "Multiple To and/or Cc headers." many-to))
eec82323
LMI
220 :group 'gnus-article-hiding)
221
23f87bed
MB
222(defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224By default, if you set this t, then Gnus will display citations and
225signatures, but will never scroll down to show you a page consisting
226only of boring text. Boring text is controlled by
227`gnus-article-boring-faces'."
bf247b6e 228 :version "22.1"
23f87bed
MB
229 :type 'boolean
230 :group 'gnus-article-hiding)
231
eec82323
LMI
232(defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234This can also be a list of regexps. In that case, it will be checked
235from head to tail looking for a separator. Searches will be done from
236the end of the buffer."
3031d8b0
MB
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238 (regexp)
239 (repeat :tag "List of regexp" regexp))
eec82323
LMI
240 :group 'gnus-article-signature)
241
242(defcustom gnus-signature-limit nil
16409b0b 243 "Provide a limit to what is considered a signature.
eec82323
LMI
244If it is a number, no signature may not be longer (in characters) than
245that number. If it is a floating point number, no signature may be
246longer (in lines) than that number. If it is a function, the function
247will be called without any parameters, and if it returns nil, there is
248no signature in the buffer. If it is a string, it will be used as a
01c52d31
MB
249regexp. If it matches, the text in question is not a signature.
250
251This can also be a list of the above values."
4a2358e9
MB
252 :type '(choice (const nil)
253 (integer :value 200)
6748645f 254 (number :value 4.0)
b28080e3 255 function
6748645f 256 (regexp :value ".*"))
eec82323
LMI
257 :group 'gnus-article-signature)
258
259(defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
261 :type 'sexp
262 :group 'gnus-article-hiding)
263
23f87bed
MB
264;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265;; frames in a session.
eec82323 266(defcustom gnus-article-x-face-command
23f87bed
MB
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
e0bad764
DL
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
275display -"))
6748645f 276 "*String or function to be executed to display an X-Face header.
eec82323 277If it is a string, the command will be executed in a sub-shell
2ff9f5b4 278asynchronously. The compressed face will be piped to this command."
23f87bed
MB
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
16409b0b 281 function)
b5a206e7 282 :version "21.1"
23f87bed 283 :group 'gnus-picon
eec82323
LMI
284 :group 'gnus-article-washing)
285
286(defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
4bb6a3a6 288 :type '(choice regexp (const nil))
eec82323
LMI
289 :group 'gnus-article-washing)
290
e0bad764
DL
291(defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
a1506d29 293For example,
23f87bed 294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
fc2c2db8 295 :version "21.1"
e0bad764
DL
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
298
23f87bed
MB
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.
313
314Symbol `signature' means to remove signatures delimited by
315`gnus-signature-separator'. Any other symbol is used to look up a
316regular expression to match the banner in `gnus-article-banner-alist'.
317A string is used as a regular expression to match the banner
318directly.")
319
320(defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323to 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.
325If ADDRESS matches author's mail address, it will remove things like
326advertisements. For example:
327
328\((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
329"
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))))
bf247b6e 338 :version "22.1"
23f87bed
MB
339 :group 'gnus-article-washing)
340
ae465fa7
MB
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))
346
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)))
351 2
352 (if (nth 1 value) 2 3)
353 (nth 2 value))
354 value)))
355
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))))
368
eec82323 369(defcustom gnus-emphasis-alist
ae465fa7
MB
370 (let ((types
371 '(("\\*" "\\*" bold nil 2)
23f87bed 372 ("_" "_" underline)
eec82323 373 ("/" "/" italic)
eec82323
LMI
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
ae465fa7
MB
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))
95f75c75
SM
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)
ae465fa7
MB
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
6748645f 394 "*Alist that says how to fontify certain phrases.
eec82323
LMI
395Each item looks like this:
396
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
398
399The first element is a regular expression to be matched. The second
400is a number that says what regular expression grouping used to find
401the entire emphasized word. The third is a number that says what
402regexp grouping should be displayed and highlighted. The fourth
403is the face used for highlighting."
ae465fa7
MB
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))
ad136a7c
MB
423 regexp
424 (integer :format "Match group: %v")
01c52d31 425 (integer :format "Emphasize group: %v")
ae465fa7
MB
426 face)
427 (group :tag "Simple"
428 :value (("_" . "_") nil default)
429 (cons :format "%v"
ad136a7c
MB
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
ae465fa7
MB
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)))
eec82323
LMI
441 :group 'gnus-article-emphasis)
442
16409b0b
GM
443(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446The former avoids underlining of leading and trailing whitespace,
447and the latter avoids underlining any whitespace at all."
fc2c2db8 448 :version "21.1"
16409b0b
GM
449 :group 'gnus-article-emphasis
450 :type 'regexp)
451
23f87bed 452(defface gnus-emphasis-bold '((t (:bold t)))
eec82323
LMI
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
455
23f87bed 456(defface gnus-emphasis-italic '((t (:italic t)))
eec82323
LMI
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
459
460(defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
463
23f87bed 464(defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
eec82323
LMI
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
467
23f87bed 468(defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
8de38c21 469 "Face used for displaying underlined italic emphasized text (_/word/_)."
eec82323
LMI
470 :group 'gnus-article-emphasis)
471
23f87bed 472(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
eec82323
LMI
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
475
476(defface gnus-emphasis-underline-bold-italic
23f87bed 477 '((t (:bold t :italic t :underline t)))
eec82323 478 "Face used for displaying underlined bold italic emphasized text.
8f688cb0 479Example: (_/*word*/_)."
eec82323
LMI
480 :group 'gnus-article-emphasis)
481
23f87bed
MB
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)
487
16409b0b
GM
488(defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
492
01c52d31 493(defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
eec82323 494 "Format for display of Date headers in article bodies.
6748645f
LMI
495See `format-time-string' for the possible values.
496
497The variable can also be function, which should return a complete Date
498header. The function is called with one argument, the time, which can
499be fed to `format-time-string'."
01c52d31 500 :type '(choice string function)
eec82323
LMI
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
503
eec82323 504(defcustom gnus-save-all-headers t
26c9afc3
MB
505 "*If non-nil, don't remove any headers before saving.
506This will be overridden by the `:headers' property that the symbol of
507the saver function, which is specified by `gnus-default-article-saver',
508might have."
eec82323
LMI
509 :group 'gnus-article-saving
510 :type 'boolean)
511
512(defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514If it is nil, no prompting will be done, and the articles will be
515saved to the default files. If this variable is `always', each and
516every article that is saved will be preceded by a prompt, even when
517saving 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
519each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
6748645f 523 (sexp :tag "once" :format "%t\n" :value t)))
eec82323
LMI
524
525(defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528If that variable is nil, however, all headers that match this regexp
26c9afc3
MB
529will be kept while the rest will be deleted before saving. This and
530`gnus-save-all-headers' will be overridden by the `:headers' property
531that the symbol of the saver function, which is specified by
532`gnus-default-article-saver', might have."
eec82323 533 :group 'gnus-article-saving
4bb6a3a6 534 :type 'regexp)
eec82323 535
fef8d38e 536;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
eec82323
LMI
537(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favourite format.
26c9afc3
MB
539The function will be called by way of the `gnus-summary-save-article'
540command, and friends such as `gnus-summary-save-article-rmail'.
eec82323
LMI
541
542Gnus provides the following functions:
543
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)
23f87bed 548* gnus-summary-save-body-in-file (article body)
eec82323 549* gnus-summary-save-in-vm (use VM's folder format)
26c9afc3
MB
550* gnus-summary-write-to-file (article format -- overwrite)
551* gnus-summary-write-body-to-file (article body -- overwrite)
89167438 552* gnus-summary-save-in-pipe (article format)
26c9afc3
MB
553
554The symbol of each function may have the following properties:
555
556* :decode
557The value non-nil means save decoded articles. This is meaningful
558only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
89167438
MB
559`gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560`gnus-summary-save-in-pipe'.
26c9afc3
MB
561
562* :function
563The value specifies an alternative function which appends, not
564overwrites, articles to a file. This implies that when saving many
565articles at a time, `gnus-prompt-before-saving' is bound to t and all
566articles are saved in a single file. This is meaningful only with
567`gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569* :headers
570The value specifies the symbol of a variable of which the value
571specifies headers to be saved. If it is omitted,
572`gnus-save-all-headers' and `gnus-saved-headers' control what
573headers should be saved."
eec82323
LMI
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)
23f87bed 579 (function-item gnus-summary-save-body-in-file)
eec82323 580 (function-item gnus-summary-save-in-vm)
58090a8d 581 (function-item gnus-summary-write-to-file)
26c9afc3 582 (function-item gnus-summary-write-body-to-file)
89167438 583 (function-item gnus-summary-save-in-pipe)
58090a8d 584 (function)))
eec82323 585
26c9afc3
MB
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.
592
593The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594which can safely encode any characters in text. This is used by the
595commands including:
596
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
601
602and the functions to which you may set `gnus-default-article-saver':
603
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
608
609Those commands and functions save just text displayed in the article
610buffer to a file if the value of this variable is non-nil. Note that
611buttonized MIME parts will be lost in a saved file in that case.
612Otherwise, 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")))
625
eec82323
LMI
626(defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
630 :type 'function)
631
632(defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
637
638(defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
642 :type 'function)
643
644(defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646The function is called with NEWSGROUP, HEADERS, and optional
647LAST-FILE."
648 :group 'gnus-article-saving
649 :type 'function)
650
651(defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
6748645f 654 "*Variable used to suggest where articles are to be saved.
eec82323
LMI
655For instance, if you would like to save articles related to Gnus in
656the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657you could set this variable to something like:
658
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
661
01c52d31
MB
662This variable is an alist where the key is the match and the
663value is a list of possible files to save in if the match is
664non-nil.
eec82323
LMI
665
666If the match is a string, it is used as a regexp match on the
667article. If the match is a symbol, that symbol will be funcalled
668from the buffer of the article to be saved with the newsgroup as the
01c52d31 669parameter. If it is a list, it will be evaled in the same buffer.
eec82323 670
01c52d31
MB
671If this form or function returns a string, this string will be used as a
672possible file name; and if it returns a non-nil list, that list will be
673used as possible file names."
eec82323 674 :group 'gnus-article-saving
6748645f
LMI
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
677 (sexp :value nil))))
eec82323 678
eec82323
LMI
679(defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681The default value is \"^\^L\", which is a form linefeed at the
682beginning of a line."
683 :type 'regexp
684 :group 'gnus-article-various)
685
16409b0b 686(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
eec82323 687 "*The format specification for the article mode line.
16409b0b
GM
688See `gnus-summary-mode-line-format' for a closer description.
689
690The following additional specs are available:
691
692%w The article washing status.
693%m The number of MIME parts in the article."
eec82323
LMI
694 :type 'string
695 :group 'gnus-article-various)
696
697(defcustom gnus-article-mode-hook nil
698 "*A hook for Gnus article mode."
699 :type 'hook
700 :group 'gnus-article-various)
701
23f87bed
MB
702(when (featurep 'xemacs)
703 ;; Extracted from gnus-xmas-define in order to preserve user settings
704 (when (fboundp 'turn-off-scroll-in-place)
705 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
706 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
707 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
708
eec82323
LMI
709(defcustom gnus-article-menu-hook nil
710 "*Hook run after the creation of the article mode menu."
711 :type 'hook
712 :group 'gnus-article-various)
713
714(defcustom gnus-article-prepare-hook nil
16409b0b 715 "*A hook called after an article has been prepared in the article buffer."
eec82323
LMI
716 :type 'hook
717 :group 'gnus-article-various)
718
01c52d31
MB
719(defcustom gnus-copy-article-ignored-headers nil
720 "List of headers to be removed when copying an article.
721Each element is a regular expression."
330f707b 722 :version "23.1" ;; No Gnus
01c52d31
MB
723 :type '(repeat regexp)
724 :group 'gnus-article-various)
725
265ac10b 726(make-obsolete-variable 'gnus-article-hide-pgp-hook nil
6b958814 727 "Gnus 5.10 (Emacs 22.1)")
a8151ef7 728
01c52d31
MB
729(defface gnus-button
730 '((t (:weight bold)))
731 "Face used for highlighting a button in the article buffer."
732 :group 'gnus-article-buttons)
733
734(defcustom gnus-article-button-face 'gnus-button
eec82323
LMI
735 "Face used for highlighting buttons in the article buffer.
736
737An article button is a piece of text that you can activate by pressing
738`RET' or `mouse-2' above it."
739 :type 'face
740 :group 'gnus-article-buttons)
741
742(defcustom gnus-article-mouse-face 'highlight
743 "Face used for mouse highlighting in the article buffer.
744
745Article buttons will be displayed in this face when the cursor is
746above them."
747 :type 'face
748 :group 'gnus-article-buttons)
749
0f49874b 750(defcustom gnus-signature-face 'gnus-signature
a8151ef7 751 "Face used for highlighting a signature in the article buffer.
0f49874b 752Obsolete; use the face `gnus-signature' for customizations instead."
eec82323
LMI
753 :type 'face
754 :group 'gnus-article-highlight
755 :group 'gnus-article-signature)
756
0f49874b 757(defface gnus-signature
f59a3415 758 '((t
23f87bed 759 (:italic t)))
a8151ef7
LMI
760 "Face used for highlighting a signature in the article buffer."
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
0f49874b
MB
763;; backward-compatibility alias
764(put 'gnus-signature-face 'face-alias 'gnus-signature)
3d493bef 765(put 'gnus-signature-face 'obsolete-face "22.1")
a8151ef7 766
0f49874b 767(defface gnus-header-from
eec82323
LMI
768 '((((class color)
769 (background dark))
01c52d31 770 (:foreground "PaleGreen1"))
eec82323
LMI
771 (((class color)
772 (background light))
6748645f 773 (:foreground "red3"))
eec82323 774 (t
23f87bed 775 (:italic t)))
eec82323
LMI
776 "Face used for displaying from headers."
777 :group 'gnus-article-headers
778 :group 'gnus-article-highlight)
0f49874b
MB
779;; backward-compatibility alias
780(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
3d493bef 781(put 'gnus-header-from-face 'obsolete-face "22.1")
eec82323 782
0f49874b 783(defface gnus-header-subject
eec82323
LMI
784 '((((class color)
785 (background dark))
01c52d31 786 (:foreground "SeaGreen1"))
eec82323
LMI
787 (((class color)
788 (background light))
6748645f 789 (:foreground "red4"))
eec82323 790 (t
23f87bed 791 (:bold t :italic t)))
eec82323
LMI
792 "Face used for displaying subject headers."
793 :group 'gnus-article-headers
794 :group 'gnus-article-highlight)
0f49874b
MB
795;; backward-compatibility alias
796(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
3d493bef 797(put 'gnus-header-subject-face 'obsolete-face "22.1")
eec82323 798
0f49874b 799(defface gnus-header-newsgroups
eec82323
LMI
800 '((((class color)
801 (background dark))
23f87bed 802 (:foreground "yellow" :italic t))
eec82323
LMI
803 (((class color)
804 (background light))
23f87bed 805 (:foreground "MidnightBlue" :italic t))
eec82323 806 (t
23f87bed
MB
807 (:italic t)))
808 "Face used for displaying newsgroups headers.
809In the default setup this face is only used for crossposted
810articles."
eec82323
LMI
811 :group 'gnus-article-headers
812 :group 'gnus-article-highlight)
0f49874b
MB
813;; backward-compatibility alias
814(put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
3d493bef 815(put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
eec82323 816
0f49874b 817(defface gnus-header-name
eec82323
LMI
818 '((((class color)
819 (background dark))
01c52d31 820 (:foreground "SpringGreen2"))
eec82323
LMI
821 (((class color)
822 (background light))
823 (:foreground "maroon"))
824 (t
23f87bed 825 (:bold t)))
eec82323
LMI
826 "Face used for displaying header names."
827 :group 'gnus-article-headers
828 :group 'gnus-article-highlight)
0f49874b
MB
829;; backward-compatibility alias
830(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
3d493bef 831(put 'gnus-header-name-face 'obsolete-face "22.1")
eec82323 832
0f49874b 833(defface gnus-header-content
eec82323
LMI
834 '((((class color)
835 (background dark))
01c52d31 836 (:foreground "SpringGreen1" :italic t))
eec82323
LMI
837 (((class color)
838 (background light))
23f87bed 839 (:foreground "indianred4" :italic t))
eec82323 840 (t
23f87bed 841 (:italic t))) "Face used for displaying header content."
eec82323
LMI
842 :group 'gnus-article-headers
843 :group 'gnus-article-highlight)
0f49874b
MB
844;; backward-compatibility alias
845(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
3d493bef 846(put 'gnus-header-content-face 'obsolete-face "22.1")
eec82323
LMI
847
848(defcustom gnus-header-face-alist
0f49874b
MB
849 '(("From" nil gnus-header-from)
850 ("Subject" nil gnus-header-subject)
851 ("Newsgroups:.*," nil gnus-header-newsgroups)
852 ("" gnus-header-name gnus-header-content))
23f87bed 853 "*Controls highlighting of article headers.
eec82323
LMI
854
855An alist of the form (HEADER NAME CONTENT).
856
23f87bed
MB
857HEADER is a regular expression which should match the name of a
858header and NAME and CONTENT are either face names or nil.
eec82323
LMI
859
860The name of each header field will be displayed using the face
23f87bed
MB
861specified by the first element in the list where HEADER matches
862the header name and NAME is non-nil. Similarly, the content will
863be displayed by the first non-nil matching CONTENT face."
eec82323
LMI
864 :group 'gnus-article-headers
865 :group 'gnus-article-highlight
866 :type '(repeat (list (regexp :tag "Header")
867 (choice :tag "Name"
868 (item :tag "skip" nil)
869 (face :value default))
870 (choice :tag "Content"
871 (item :tag "skip" nil)
872 (face :value default)))))
873
01c52d31
MB
874(defcustom gnus-face-properties-alist (if (featurep 'xemacs)
875 '((xface . (:face gnus-x-face)))
876 '((pbm . (:face gnus-x-face))
877 (png . nil)))
878 "Alist of image types and properties applied to Face and X-Face images.
879Here are examples:
880
881;; Specify the altitude of Face images in the From header.
882\(setq gnus-face-properties-alist
883 '((pbm . (:face gnus-x-face :ascent 80))
884 (png . (:ascent 80))))
885
886;; Show Face images as pressed buttons.
887\(setq gnus-face-properties-alist
888 '((pbm . (:face gnus-x-face :relief -2))
889 (png . (:relief -2))))
890
891See the manual for the valid properties for various image types.
892Currently, `pbm' is used for X-Face images and `png' is used for Face
893images in Emacs. Only the `:face' property is effective on the `xface'
894image type in XEmacs if it is built with the libcompface library."
330f707b 895 :version "23.1" ;; No Gnus
01c52d31
MB
896 :group 'gnus-article-headers
897 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
898
16409b0b 899(defcustom gnus-article-decode-hook
23f87bed
MB
900 '(article-decode-charset article-decode-encoded-words
901 article-decode-group-name article-decode-idna-rhs)
16409b0b
GM
902 "*Hook run to decode charsets in articles."
903 :group 'gnus-article-headers
904 :type 'hook)
905
906(defcustom gnus-display-mime-function 'gnus-display-mime
907 "Function to display MIME articles."
908 :group 'gnus-article-mime
909 :type 'function)
910
911(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
912 "Function used to decode headers.")
913
343d6628
MB
914(defvar gnus-decode-address-function 'mail-decode-encoded-address-region
915 "Function used to decode addresses.")
916
16409b0b 917(defvar gnus-article-dumbquotes-map
7cad71ad
G
918 '((?\200 "EUR")
919 (?\202 ",")
920 (?\203 "f")
921 (?\204 ",,")
922 (?\205 "...")
923 (?\213 "<")
924 (?\214 "OE")
925 (?\221 "`")
926 (?\222 "'")
927 (?\223 "``")
928 (?\224 "\"")
929 (?\225 "*")
930 (?\226 "-")
931 (?\227 "--")
932 (?\230 "~")
933 (?\231 "(TM)")
934 (?\233 ">")
935 (?\234 "oe")
936 (?\264 "'"))
16409b0b
GM
937 "Table for MS-to-Latin1 translation.")
938
939(defcustom gnus-ignored-mime-types nil
940 "List of MIME types that should be ignored by Gnus."
fc2c2db8 941 :version "21.1"
16409b0b
GM
942 :group 'gnus-article-mime
943 :type '(repeat regexp))
944
945(defcustom gnus-unbuttonized-mime-types '(".*/.*")
23f87bed
MB
946 "List of MIME types that should not be given buttons when rendered inline.
947See also `gnus-buttonized-mime-types' which may override this variable.
948This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
949 :version "21.1"
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
952
953(defcustom gnus-buttonized-mime-types nil
954 "List of MIME types that should be given buttons when rendered inline.
955If set, this variable overrides `gnus-unbuttonized-mime-types'.
956To see e.g. security buttons you could set this to
3031d8b0
MB
957`(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
958this list to display radio buttons that allow you to choose one of two
959media types those mails include. See also `mm-discouraged-alternatives'.
23f87bed 960This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
bf247b6e 961 :version "22.1"
16409b0b
GM
962 :group 'gnus-article-mime
963 :type '(repeat regexp))
964
23f87bed
MB
965(defcustom gnus-inhibit-mime-unbuttonizing nil
966 "If non-nil, all MIME parts get buttons.
967When nil (the default value), then some MIME parts do not get buttons,
968as described by the variables `gnus-buttonized-mime-types' and
969`gnus-unbuttonized-mime-types'."
bf247b6e 970 :version "22.1"
d0859c9a 971 :group 'gnus-article-mime
23f87bed
MB
972 :type 'boolean)
973
974(defcustom gnus-body-boundary-delimiter "_"
975 "String used to delimit header and body.
976This variable is used by `gnus-article-treat-body-boundary' which can
977be controlled by `gnus-treat-body-boundary'."
bf247b6e 978 :version "22.1"
23f87bed
MB
979 :group 'gnus-article-various
980 :type '(choice (item :tag "None" :value nil)
981 string))
982
97f78c9b
MB
983(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
984 "/usr/share/picons")
23f87bed
MB
985 "Defines the location of the faces database.
986For information on obtaining this database of pretty pictures, please
987see http://www.cs.indiana.edu/picons/ftp/index.html"
bf247b6e 988 :version "22.1"
23f87bed
MB
989 :type '(repeat directory)
990 :link '(url-link :tag "download"
991 "http://www.cs.indiana.edu/picons/ftp/index.html")
992 :link '(custom-manual "(gnus)Picons")
993 :group 'gnus-picon)
994
995(defun gnus-picons-installed-p ()
996 "Say whether picons are installed on your machine."
997 (let ((installed nil))
998 (dolist (database gnus-picon-databases)
999 (when (file-exists-p database)
1000 (setq installed t)))
1001 installed))
1002
16409b0b
GM
1003(defcustom gnus-article-mime-part-function nil
1004 "Function called with a MIME handle as the argument.
1005This is meant for people who want to do something automatic based
1006on parts -- for instance, adding Vcard info to a database."
1007 :group 'gnus-article-mime
4a2358e9
MB
1008 :type '(choice (const nil)
1009 function))
16409b0b
GM
1010
1011(defcustom gnus-mime-multipart-functions nil
fc2c2db8
DL
1012 "An alist of MIME types to functions to display them."
1013 :version "21.1"
1014 :group 'gnus-article-mime
01c52d31 1015 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
16409b0b 1016
12e3ca0a
LI
1017(defcustom gnus-article-date-headers
1018 (let ((types '(ut local english lapsed combined-lapsed
1019 iso8601 original user-defined))
1020 default)
1021 (dolist (type types)
1022 (let ((variable (intern (format "gnus-treat-date-%s" type))))
1023 (when (and (boundp variable)
1024 (symbol-value variable))
1025 (push type default))))
1026 (when (and (or (not (boundp (intern "gnus-article-date-lapsed-new-header")))
1027 (not (symbol-value (intern "gnus-article-date-lapsed-new-header"))))
1028 (memq 'lapsed default))
1029 (setq default (delq 'lapsed default)))
1030 (or default
1031 '(combined-lapsed)))
1032 "A list of Date header formats to display.
1033Valid formats are `ut' (universal time), `local' (local time
1034zone), `english' (readable English), `lapsed' (elapsed time),
1035`combined-lapsed' (both the original date and the elapsed time),
1036`original' (the original date header), `iso8601' (ISO8601
1037format), and `user-defined' (a user-defined format defined by the
1038`gnus-article-time-format' variable).
1039
1040You have as many date headers as you want in the article buffer.
1041Some of these headers are updated automatically. See
1042`gnus-article-update-date-headers' for details."
1043 :version "24.1"
16409b0b 1044 :group 'gnus-article-headers
12e3ca0a
LI
1045 :type '(repeat
1046 (item :tag "Universal time (UT)" :value 'ut)
1047 (item :tag "Local time zone" :value 'local)
1048 (item :tag "Readable English" :value 'english)
1049 (item :tag "Elapsed time" :value 'lapsed)
1050 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1051 (item :tag "Original date header" :value 'original)
1052 (item :tag "ISO8601 format" :value 'iso8601)
1053 (item :tag "User-defined" :value 'user-defined)))
1054
1055(defcustom gnus-article-update-date-headers 1
1056 "How often to update the date header.
647559c2
LI
1057If nil, don't update it at all."
1058 :version "24.1"
1059 :group 'gnus-article-headers
1060 :type '(choice
1061 (item :tag "Don't update" :value nil)
1062 integer))
1063
16409b0b
GM
1064(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1065 "Function called with a MIME handle as the argument.
1066This is meant for people who want to view first matched part.
a1506d29
JB
1067For `undisplayed-alternative' (default), the first undisplayed
1068part or alternative part is used. For `undisplayed', the first
1069undisplayed part is used. For a function, the first part which
f20b2f5c 1070the function return t is used. For nil, the first part is
16409b0b 1071used."
fc2c2db8 1072 :version "21.1"
16409b0b 1073 :group 'gnus-article-mime
a1506d29 1074 :type '(choice
16409b0b
GM
1075 (item :tag "first" :value nil)
1076 (item :tag "undisplayed" :value undisplayed)
a1506d29 1077 (item :tag "undisplayed or alternative"
16409b0b
GM
1078 :value undisplayed-alternative)
1079 (function)))
1080
e0bad764
DL
1081(defcustom gnus-mime-action-alist
1082 '(("save to file" . gnus-mime-save-part)
23f87bed 1083 ("save and strip" . gnus-mime-save-part-and-strip)
01c52d31 1084 ("replace with file" . gnus-mime-replace-part)
23f87bed 1085 ("delete part" . gnus-mime-delete-part)
e0bad764
DL
1086 ("display as text" . gnus-mime-inline-part)
1087 ("view the part" . gnus-mime-view-part)
1088 ("pipe to command" . gnus-mime-pipe-part)
1089 ("toggle display" . gnus-article-press-button)
23f87bed 1090 ("toggle display" . gnus-article-view-part-as-charset)
e0bad764 1091 ("view as type" . gnus-mime-view-part-as-type)
23f87bed
MB
1092 ("view internally" . gnus-mime-view-part-internally)
1093 ("view externally" . gnus-mime-view-part-externally))
e0bad764
DL
1094 "An alist of actions that run on the MIME attachment."
1095 :group 'gnus-article-mime
1096 :type '(repeat (cons (string :tag "name")
1097 (function))))
1098
01c52d31
MB
1099(defcustom gnus-auto-select-part 1
1100 "Advance to next MIME part when deleting or stripping parts.
1101
1102When 0, point will be placed on the same part as before. When
1103positive (negative), move point forward (backwards) this many
1104parts. When nil, redisplay article."
330f707b 1105 :version "23.1" ;; No Gnus
01c52d31
MB
1106 :group 'gnus-article-mime
1107 :type '(choice (const nil :tag "Redisplay article.")
1108 (const 1 :tag "Next part.")
1109 (const 0 :tag "Current part.")
1110 integer))
1111
16409b0b
GM
1112;;;
1113;;; The treatment variables
1114;;;
1115
1116(defvar gnus-part-display-hook nil
1117 "Hook called on parts that are to receive treatment.")
1118
1119(defvar gnus-article-treat-custom
1120 '(choice (const :tag "Off" nil)
1121 (const :tag "On" t)
1122 (const :tag "Header" head)
01c52d31 1123 (const :tag "First" first)
16409b0b
GM
1124 (const :tag "Last" last)
1125 (integer :tag "Less")
1126 (repeat :tag "Groups" regexp)
1127 (sexp :tag "Predicate")))
1128
1129(defvar gnus-article-treat-head-custom
1130 '(choice (const :tag "Off" nil)
1131 (const :tag "Header" head)))
1132
01c52d31
MB
1133(defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1134 "text/x-patch")
16409b0b
GM
1135 "Parts to treat.")
1136
1137(defvar gnus-inhibit-treatment nil
1138 "Whether to inhibit treatment.")
1139
23f87bed 1140(defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
16409b0b 1141 "Highlight the signature.
01c52d31
MB
1142Valid values are nil, t, `head', `first', `last', an integer or a
1143predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1144 :group 'gnus-article-treat
23f87bed 1145 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1146 :type gnus-article-treat-custom)
1147(put 'gnus-treat-highlight-signature 'highlight t)
1148
1149(defcustom gnus-treat-buttonize 100000
1150 "Add buttons.
01c52d31
MB
1151Valid values are nil, t, `head', `first', `last', an integer or a
1152predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1153 :group 'gnus-article-treat
23f87bed 1154 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1155 :type gnus-article-treat-custom)
1156(put 'gnus-treat-buttonize 'highlight t)
1157
1158(defcustom gnus-treat-buttonize-head 'head
1159 "Add buttons to the head.
01c52d31
MB
1160Valid values are nil, t, `head', `first', `last', an integer or a
1161predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1162 :group 'gnus-article-treat
23f87bed 1163 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1164 :type gnus-article-treat-head-custom)
1165(put 'gnus-treat-buttonize-head 'highlight t)
1166
12e3ca0a
LI
1167(defcustom gnus-treat-date 'head
1168 "Display dates according to the `gnus-article-date-headers' variable.
1169Valid values are nil, t, `head', `first', `last', an integer or a
1170predicate. See Info node `(gnus)Customizing Articles'."
1171 :version "24.1"
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-head-custom)
1175
437ce4be 1176(defcustom gnus-treat-emphasize 50000
16409b0b 1177 "Emphasize text.
01c52d31
MB
1178Valid values are nil, t, `head', `first', `last', an integer or a
1179predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1180 :group 'gnus-article-treat
23f87bed 1181 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1182 :type gnus-article-treat-custom)
1183(put 'gnus-treat-emphasize 'highlight t)
1184
1185(defcustom gnus-treat-strip-cr nil
1186 "Remove carriage returns.
01c52d31
MB
1187Valid values are nil, t, `head', `first', `last', an integer or a
1188predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1189 :version "22.1"
16409b0b 1190 :group 'gnus-article-treat
23f87bed
MB
1191 :link '(custom-manual "(gnus)Customizing Articles")
1192 :type gnus-article-treat-custom)
1193
1194(defcustom gnus-treat-unsplit-urls nil
1195 "Remove newlines from within URLs.
01c52d31
MB
1196Valid values are nil, t, `head', `first', `last', an integer or a
1197predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1198 :version "22.1"
23f87bed
MB
1199 :group 'gnus-article-treat
1200 :link '(custom-manual "(gnus)Customizing Articles")
1201 :type gnus-article-treat-custom)
1202
1203(defcustom gnus-treat-leading-whitespace nil
1204 "Remove leading whitespace in headers.
01c52d31
MB
1205Valid values are nil, t, `head', `first', `last', an integer or a
1206predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1207 :version "22.1"
23f87bed
MB
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1210 :type gnus-article-treat-custom)
1211
1212(defcustom gnus-treat-hide-headers 'head
1213 "Hide headers.
01c52d31
MB
1214Valid values are nil, t, `head', `first', `last', an integer or a
1215predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1216 :group 'gnus-article-treat
23f87bed 1217 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1218 :type gnus-article-treat-head-custom)
1219
1220(defcustom gnus-treat-hide-boring-headers nil
1221 "Hide boring headers.
01c52d31
MB
1222Valid values are nil, t, `head', `first', `last', an integer or a
1223predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1224 :group 'gnus-article-treat
23f87bed 1225 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1226 :type gnus-article-treat-head-custom)
1227
1228(defcustom gnus-treat-hide-signature nil
1229 "Hide the signature.
01c52d31
MB
1230Valid values are nil, t, `head', `first', `last', an integer or a
1231predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1232 :group 'gnus-article-treat
23f87bed 1233 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1234 :type gnus-article-treat-custom)
1235
1236(defcustom gnus-treat-fill-article nil
1237 "Fill the article.
01c52d31
MB
1238Valid values are nil, t, `head', `first', `last', an integer or a
1239predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1240 :group 'gnus-article-treat
23f87bed 1241 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1242 :type gnus-article-treat-custom)
1243
1244(defcustom gnus-treat-hide-citation nil
1245 "Hide cited text.
01c52d31
MB
1246Valid values are nil, t, `head', `first', `last', an integer or a
1247predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1248 :group 'gnus-article-treat
23f87bed 1249 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1250 :type gnus-article-treat-custom)
1251
e0bad764
DL
1252(defcustom gnus-treat-hide-citation-maybe nil
1253 "Hide cited text.
01c52d31
MB
1254Valid values are nil, t, `head', `first', `last', an integer or a
1255predicate. See Info node `(gnus)Customizing Articles'."
e0bad764 1256 :group 'gnus-article-treat
23f87bed 1257 :link '(custom-manual "(gnus)Customizing Articles")
e0bad764
DL
1258 :type gnus-article-treat-custom)
1259
16409b0b
GM
1260(defcustom gnus-treat-strip-list-identifiers 'head
1261 "Strip list identifiers from `gnus-list-identifiers`.
01c52d31
MB
1262Valid values are nil, t, `head', `first', `last', an integer or a
1263predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1264 :version "21.1"
16409b0b 1265 :group 'gnus-article-treat
23f87bed 1266 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1267 :type gnus-article-treat-custom)
1268
265ac10b
SM
1269(make-obsolete-variable 'gnus-treat-strip-pgp nil
1270 "Gnus 5.10 (Emacs 22.1)")
16409b0b
GM
1271
1272(defcustom gnus-treat-strip-pem nil
1273 "Strip PEM signatures.
01c52d31
MB
1274Valid values are nil, t, `head', `first', `last', an integer or a
1275predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1276 :group 'gnus-article-treat
23f87bed 1277 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1278 :type gnus-article-treat-custom)
1279
1280(defcustom gnus-treat-strip-banner t
1281 "Strip banners from articles.
1282The banner to be stripped is specified in the `banner' group parameter.
01c52d31
MB
1283Valid values are nil, t, `head', `first', `last', an integer or a
1284predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1285 :group 'gnus-article-treat
23f87bed 1286 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1287 :type gnus-article-treat-custom)
1288
1289(defcustom gnus-treat-highlight-headers 'head
1290 "Highlight the headers.
01c52d31
MB
1291Valid values are nil, t, `head', `first', `last', an integer or a
1292predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1293 :group 'gnus-article-treat
23f87bed 1294 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1295 :type gnus-article-treat-head-custom)
1296(put 'gnus-treat-highlight-headers 'highlight t)
1297
1298(defcustom gnus-treat-highlight-citation t
1299 "Highlight cited text.
01c52d31
MB
1300Valid values are nil, t, `head', `first', `last', an integer or a
1301predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1302 :group 'gnus-article-treat
23f87bed 1303 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1304 :type gnus-article-treat-custom)
1305(put 'gnus-treat-highlight-citation 'highlight t)
1306
16409b0b
GM
1307(defcustom gnus-treat-strip-headers-in-body t
1308 "Strip the X-No-Archive header line from the beginning of the body.
01c52d31
MB
1309Valid values are nil, t, `head', `first', `last', an integer or a
1310predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1311 :version "21.1"
16409b0b 1312 :group 'gnus-article-treat
23f87bed 1313 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1314 :type gnus-article-treat-custom)
1315
1316(defcustom gnus-treat-strip-trailing-blank-lines nil
1317 "Strip trailing blank lines.
01c52d31
MB
1318Valid values are nil, t, `head', `first', `last', an integer or a
1319predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1320
1321When set to t, it also strips trailing blanks in all MIME parts.
1322Consider to use `last' instead."
16409b0b 1323 :group 'gnus-article-treat
23f87bed 1324 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1325 :type gnus-article-treat-custom)
1326
1327(defcustom gnus-treat-strip-leading-blank-lines nil
1328 "Strip leading blank lines.
01c52d31
MB
1329Valid values are nil, t, `head', `first', `last', an integer or a
1330predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1331
1332When set to t, it also strips trailing blanks in all MIME parts."
16409b0b 1333 :group 'gnus-article-treat
23f87bed 1334 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1335 :type gnus-article-treat-custom)
1336
1337(defcustom gnus-treat-strip-multiple-blank-lines nil
1338 "Strip multiple blank lines.
01c52d31
MB
1339Valid values are nil, t, `head', `first', `last', an integer or a
1340predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1341 :group 'gnus-article-treat
23f87bed
MB
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1344
1345(defcustom gnus-treat-unfold-headers 'head
1346 "Unfold folded header lines.
01c52d31
MB
1347Valid values are nil, t, `head', `first', `last', an integer or a
1348predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1349 :version "22.1"
23f87bed
MB
1350 :group 'gnus-article-treat
1351 :link '(custom-manual "(gnus)Customizing Articles")
1352 :type gnus-article-treat-custom)
1353
01c52d31
MB
1354(defcustom gnus-article-unfold-long-headers nil
1355 "If non-nil, allow unfolding headers even if the header is long.
1356If it is a regexp, only long headers matching this regexp are unfolded.
1357If it is t, all long headers are unfolded.
1358
1359This variable has no effect if `gnus-treat-unfold-headers' is nil."
330f707b 1360 :version "23.1" ;; No Gnus
01c52d31
MB
1361 :group 'gnus-article-treat
1362 :type '(choice (const nil)
1363 (const :tag "all" t)
1364 (regexp)))
1365
23f87bed
MB
1366(defcustom gnus-treat-fold-headers nil
1367 "Fold headers.
01c52d31
MB
1368Valid values are nil, t, `head', `first', `last', an integer or a
1369predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1370 :version "22.1"
23f87bed
MB
1371 :group 'gnus-article-treat
1372 :link '(custom-manual "(gnus)Customizing Articles")
1373 :type gnus-article-treat-custom)
1374
1375(defcustom gnus-treat-fold-newsgroups 'head
1376 "Fold the Newsgroups and Followup-To headers.
01c52d31
MB
1377Valid values are nil, t, `head', `first', `last', an integer or a
1378predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1379 :version "22.1"
23f87bed
MB
1380 :group 'gnus-article-treat
1381 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1382 :type gnus-article-treat-custom)
1383
1384(defcustom gnus-treat-overstrike t
1385 "Treat overstrike highlighting.
01c52d31
MB
1386Valid values are nil, t, `head', `first', `last', an integer or a
1387predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1388 :group 'gnus-article-treat
23f87bed 1389 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1390 :type gnus-article-treat-custom)
1391(put 'gnus-treat-overstrike 'highlight t)
1392
01c52d31
MB
1393(defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1394 "Treat ANSI SGR control sequences.
1395Valid values are nil, t, `head', `first', `last', an integer or a
1396predicate. See Info node `(gnus)Customizing Articles'."
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1400
23f87bed 1401(make-obsolete-variable 'gnus-treat-display-xface
6b958814 1402 'gnus-treat-display-x-face "Emacs 22.1")
23f87bed
MB
1403
1404(defcustom gnus-treat-display-x-face
1405 (and (not noninteractive)
11e95b02
MB
1406 (gnus-image-type-available-p 'xbm)
1407 (if (featurep 'xemacs)
1408 (featurep 'xface)
86f5c034
SM
1409 (condition-case nil
1410 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1411 (executable-find "icontopbm"))
1412 ;; shell-command-to-string may signal an error, e.g. if
1413 ;; shell-file-name is not found.
1414 (error nil)))
8b93df01 1415 'head)
16409b0b 1416 "Display X-Face headers.
87ba2830 1417Valid values are nil and `head'.
23f87bed
MB
1418See Info node `(gnus)Customizing Articles' and Info node
1419`(gnus)X-Face' for details."
1420 :group 'gnus-article-treat
1421 :version "21.1"
1422 :link '(custom-manual "(gnus)Customizing Articles")
1423 :link '(custom-manual "(gnus)X-Face")
1424 :type gnus-article-treat-head-custom
1425 :set (lambda (symbol value)
1426 (set-default
1427 symbol
1428 (cond ((or (boundp symbol) (get symbol 'saved-value))
1429 value)
1430 ((boundp 'gnus-treat-display-xface)
1431 (message "\
1432** gnus-treat-display-xface is an obsolete variable;\
1433 use gnus-treat-display-x-face instead")
1434 (default-value 'gnus-treat-display-xface))
1435 ((get 'gnus-treat-display-xface 'saved-value)
1436 (message "\
1437** gnus-treat-display-xface is an obsolete variable;\
1438 use gnus-treat-display-x-face instead")
1439 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1440 (t
1441 value)))))
1442(put 'gnus-treat-display-x-face 'highlight t)
1443
1444(defcustom gnus-treat-display-face
1445 (and (not noninteractive)
11e95b02 1446 (gnus-image-type-available-p 'png)
23f87bed
MB
1447 'head)
1448 "Display Face headers.
01c52d31
MB
1449Valid values are nil, t, `head', `first', `last', an integer or a
1450predicate. See Info node `(gnus)Customizing Articles' and Info
41ec3f54 1451node `(gnus)Face' for details."
16409b0b 1452 :group 'gnus-article-treat
bf247b6e 1453 :version "22.1"
23f87bed
MB
1454 :link '(custom-manual "(gnus)Customizing Articles")
1455 :link '(custom-manual "(gnus)X-Face")
16409b0b 1456 :type gnus-article-treat-head-custom)
23f87bed 1457(put 'gnus-treat-display-face 'highlight t)
16409b0b 1458
11e95b02 1459(defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
16409b0b 1460 "Display smileys.
01c52d31
MB
1461Valid values are nil, t, `head', `first', `last', an integer or a
1462predicate. See Info node `(gnus)Customizing Articles' and Info
1463node `(gnus)Smileys' for details."
16409b0b 1464 :group 'gnus-article-treat
b5a206e7 1465 :version "21.1"
23f87bed
MB
1466 :link '(custom-manual "(gnus)Customizing Articles")
1467 :link '(custom-manual "(gnus)Smileys")
16409b0b
GM
1468 :type gnus-article-treat-custom)
1469(put 'gnus-treat-display-smileys 'highlight t)
1470
23f87bed
MB
1471(defcustom gnus-treat-from-picon
1472 (if (and (gnus-image-type-available-p 'xpm)
1473 (gnus-picons-installed-p))
1474 'head nil)
1475 "Display picons in the From header.
01c52d31
MB
1476Valid values are nil, t, `head', `first', `last', an integer or a
1477predicate. See Info node `(gnus)Customizing Articles' and Info
1478node `(gnus)Picons' for details."
bf247b6e 1479 :version "22.1"
16409b0b 1480 :group 'gnus-article-treat
23f87bed
MB
1481 :group 'gnus-picon
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Picons")
1484 :type gnus-article-treat-head-custom)
1485(put 'gnus-treat-from-picon 'highlight t)
1486
1487(defcustom gnus-treat-mail-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1490 'head nil)
1491 "Display picons in To and Cc headers.
01c52d31
MB
1492Valid values are nil, t, `head', `first', `last', an integer or a
1493predicate. See Info node `(gnus)Customizing Articles' and Info
1494node `(gnus)Picons' for details."
bf247b6e 1495 :version "22.1"
23f87bed
MB
1496 :group 'gnus-article-treat
1497 :group 'gnus-picon
1498 :link '(custom-manual "(gnus)Customizing Articles")
1499 :link '(custom-manual "(gnus)Picons")
1500 :type gnus-article-treat-head-custom)
1501(put 'gnus-treat-mail-picon 'highlight t)
1502
1503(defcustom gnus-treat-newsgroups-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1506 'head nil)
1507 "Display picons in the Newsgroups and Followup-To headers.
01c52d31
MB
1508Valid values are nil, t, `head', `first', `last', an integer or a
1509predicate. See Info node `(gnus)Customizing Articles' and Info
1510node `(gnus)Picons' for details."
bf247b6e 1511 :version "22.1"
23f87bed
MB
1512 :group 'gnus-article-treat
1513 :group 'gnus-picon
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Picons")
1516 :type gnus-article-treat-head-custom)
1517(put 'gnus-treat-newsgroups-picon 'highlight t)
1518
6688abe0 1519(defcustom gnus-treat-from-gravatar nil
61b1af82
G
1520 "Display gravatars in the From header.
1521Valid values are nil, t, `head', `first', `last', an integer or a
1522predicate. See Info node `(gnus)Customizing Articles' and Info
1523node `(gnus)Gravatars' for details."
1524 :version "24.1"
1525 :group 'gnus-article-treat
1526 :group 'gnus-gravatar
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :link '(custom-manual "(gnus)Gravatars")
1529 :type gnus-article-treat-head-custom)
1530(put 'gnus-treat-from-gravatar 'highlight t)
1531
6688abe0 1532(defcustom gnus-treat-mail-gravatar nil
61b1af82
G
1533 "Display gravatars in To and Cc headers.
1534Valid values are nil, t, `head', `first', `last', an integer or a
1535predicate. See Info node `(gnus)Customizing Articles' and Info
1536node `(gnus)Gravatars' for details."
1537 :version "24.1"
1538 :group 'gnus-article-treat
1539 :group 'gnus-gravatar
1540 :link '(custom-manual "(gnus)Customizing Articles")
1541 :link '(custom-manual "(gnus)Gravatars")
1542 :type gnus-article-treat-head-custom)
1543(put 'gnus-treat-mail-gravatar 'highlight t)
1544
23f87bed 1545(defcustom gnus-treat-body-boundary
437ce4be
MB
1546 (if (or gnus-treat-newsgroups-picon
1547 gnus-treat-mail-picon
61b1af82
G
1548 gnus-treat-from-picon
1549 gnus-treat-from-gravatar
1550 gnus-treat-mail-gravatar)
437ce4be
MB
1551 ;; If there's much decoration, the user might prefer a boundery.
1552 'head
1553 nil)
23f87bed
MB
1554 "Draw a boundary at the end of the headers.
1555Valid values are nil and `head'.
1556See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1557 :version "22.1"
23f87bed
MB
1558 :group 'gnus-article-treat
1559 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b 1560 :type gnus-article-treat-head-custom)
16409b0b
GM
1561
1562(defcustom gnus-treat-capitalize-sentences nil
1563 "Capitalize sentence-starting words.
01c52d31
MB
1564Valid values are nil, t, `head', `first', `last', an integer or a
1565predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1566 :version "21.1"
16409b0b 1567 :group 'gnus-article-treat
23f87bed
MB
1568 :link '(custom-manual "(gnus)Customizing Articles")
1569 :type gnus-article-treat-custom)
1570
1571(defcustom gnus-treat-wash-html nil
1572 "Format as HTML.
01c52d31
MB
1573Valid values are nil, t, `head', `first', `last', an integer or a
1574predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1575 :version "22.1"
23f87bed
MB
1576 :group 'gnus-article-treat
1577 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1578 :type gnus-article-treat-custom)
1579
389b76fa 1580(defcustom gnus-treat-fill-long-lines '(typep "text/plain")
16409b0b 1581 "Fill long lines.
01c52d31
MB
1582Valid values are nil, t, `head', `first', `last', an integer or a
1583predicate. See Info node `(gnus)Customizing Articles'."
37657cbd 1584 :version "24.1"
16409b0b 1585 :group 'gnus-article-treat
23f87bed 1586 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1587 :type gnus-article-treat-custom)
1588
23f87bed
MB
1589(defcustom gnus-treat-x-pgp-sig nil
1590 "Verify X-PGP-Sig.
1591To automatically treat X-PGP-Sig, set it to head.
01c52d31
MB
1592Valid values are nil, t, `head', `first', `last', an integer or a
1593predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1594 :version "22.1"
23f87bed
MB
1595 :group 'gnus-article-treat
1596 :group 'mime-security
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1599
1600(defvar gnus-article-encrypt-protocol-alist
1601 '(("PGP" . mml2015-self-encrypt)))
1602
1603;; Set to nil if more than one protocol added to
1604;; gnus-article-encrypt-protocol-alist.
1605(defcustom gnus-article-encrypt-protocol "PGP"
1606 "The protocol used for encrypt articles.
1607It is a string, such as \"PGP\". If nil, ask user."
bf247b6e 1608 :version "22.1"
23f87bed
MB
1609 :type 'string
1610 :group 'mime-security)
1611
23f87bed
MB
1612(defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1613 (mm-coding-system-p 'utf-8)
1614 (executable-find idna-program))
1615 "Whether IDNA decoding of headers is used when viewing messages.
1616This requires GNU Libidn, and by default only enabled if it is found."
bf247b6e 1617 :version "22.1"
23f87bed
MB
1618 :group 'gnus-article-headers
1619 :type 'boolean)
1620
1621(defcustom gnus-article-over-scroll nil
1622 "If non-nil, allow scrolling the article buffer even when there no more text."
bf247b6e 1623 :version "22.1"
23f87bed
MB
1624 :group 'gnus-article
1625 :type 'boolean)
1626
40de2c6d
KY
1627(defcustom gnus-inhibit-images nil
1628 "Non-nil means inhibit displaying of images inline in the article body."
1629 :version "24.1"
1630 :group 'gnus-article
1631 :type 'boolean)
1632
2526f423
G
1633(defcustom gnus-blocked-images 'gnus-block-private-groups
1634 "Images that have URLs matching this regexp will be blocked.
1635This can also be a function to be evaluated. If so, it will be
1636called with the group name as the parameter, and should return a
1637regexp."
130e977f
LMI
1638 :version "24.1"
1639 :group 'gnus-art
1640 :type 'regexp)
1641
eec82323
LMI
1642;;; Internal variables
1643
23f87bed
MB
1644(defvar gnus-english-month-names
1645 '("January" "February" "March" "April" "May" "June" "July" "August"
1646 "September" "October" "November" "December"))
1647
16409b0b
GM
1648(defvar article-goto-body-goes-to-point-min-p nil)
1649(defvar gnus-article-wash-types nil)
1650(defvar gnus-article-emphasis-alist nil)
23f87bed 1651(defvar gnus-article-image-alist nil)
16409b0b
GM
1652
1653(defvar gnus-article-mime-handle-alist-1 nil)
1654(defvar gnus-treatment-function-alist
23f87bed
MB
1655 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1656 (gnus-treat-strip-banner gnus-article-strip-banner)
16409b0b
GM
1657 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1658 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1659 (gnus-treat-buttonize gnus-article-add-buttons)
1660 (gnus-treat-fill-article gnus-article-fill-cited-article)
389b76fa 1661 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
16409b0b 1662 (gnus-treat-strip-cr gnus-article-remove-cr)
23f87bed 1663 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
23f87bed
MB
1664 (gnus-treat-display-x-face gnus-article-display-x-face)
1665 (gnus-treat-display-face gnus-article-display-face)
16409b0b
GM
1666 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1667 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1668 (gnus-treat-hide-signature gnus-article-hide-signature)
16409b0b 1669 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
23f87bed 1670 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
2696d88f
G
1671 (gnus-treat-from-picon gnus-treat-from-picon)
1672 (gnus-treat-mail-picon gnus-treat-mail-picon)
1673 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
16409b0b 1674 (gnus-treat-strip-pem gnus-article-hide-pem)
12e3ca0a 1675 (gnus-treat-date gnus-article-treat-date)
61b1af82
G
1676 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1677 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
16409b0b 1678 (gnus-treat-highlight-headers gnus-article-highlight-headers)
16409b0b 1679 (gnus-treat-highlight-signature gnus-article-highlight-signature)
16409b0b
GM
1680 (gnus-treat-strip-trailing-blank-lines
1681 gnus-article-remove-trailing-blank-lines)
1682 (gnus-treat-strip-leading-blank-lines
1683 gnus-article-strip-leading-blank-lines)
1684 (gnus-treat-strip-multiple-blank-lines
1685 gnus-article-strip-multiple-blank-lines)
1686 (gnus-treat-overstrike gnus-article-treat-overstrike)
01c52d31 1687 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
23f87bed 1688 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
23f87bed 1689 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
01c52d31 1690 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
16409b0b 1691 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
23f87bed 1692 (gnus-treat-display-smileys gnus-treat-smiley)
16409b0b 1693 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
23f87bed
MB
1694 (gnus-treat-wash-html gnus-article-wash-html)
1695 (gnus-treat-emphasize gnus-article-emphasize)
1696 (gnus-treat-hide-citation gnus-article-hide-citation)
1697 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1698 (gnus-treat-highlight-citation gnus-article-highlight-citation)
8ccbef23 1699 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
16409b0b
GM
1700
1701(defvar gnus-article-mime-handle-alist nil)
6748645f
LMI
1702(defvar article-lapsed-timer nil)
1703(defvar gnus-article-current-summary nil)
1704
eec82323
LMI
1705(defvar gnus-article-mode-syntax-table
1706 (let ((table (copy-syntax-table text-mode-syntax-table)))
23f87bed
MB
1707 ;; This causes the citation match run O(2^n).
1708 ;; (modify-syntax-entry ?- "w" table)
1709 (modify-syntax-entry ?> ")<" table)
1710 (modify-syntax-entry ?< "(>" table)
1711 ;; make M-. in article buffers work for `foo' strings
1712 (modify-syntax-entry ?' " " table)
1713 (modify-syntax-entry ?` " " table)
eec82323
LMI
1714 table)
1715 "Syntax table used in article mode buffers.
1716Initialized from `text-mode-syntax-table.")
1717
1718(defvar gnus-save-article-buffer nil)
1719
eec82323
LMI
1720(defvar gnus-number-of-articles-to-be-saved nil)
1721
1722(defvar gnus-inhibit-hiding nil)
1723
c1d7d285
MB
1724(defvar gnus-article-edit-mode nil)
1725
23f87bed
MB
1726;;; Macros for dealing with the article buffer.
1727
1728(defmacro gnus-with-article-headers (&rest forms)
80de1778 1729 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1730 (save-restriction
1731 (let ((inhibit-read-only t)
1732 (inhibit-point-motion-hooks t)
1733 (case-fold-search t))
1734 (article-narrow-to-head)
1735 ,@forms))))
1736
1737(put 'gnus-with-article-headers 'lisp-indent-function 0)
1738(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1739
1740(defmacro gnus-with-article-buffer (&rest forms)
80de1778 1741 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1742 (let ((inhibit-read-only t))
1743 ,@forms)))
1744
1745(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1746(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1747
1748(defun gnus-article-goto-header (header)
1749 "Go to HEADER, which is a regular expression."
1750 (re-search-forward (concat "^\\(" header "\\):") nil t))
1751
eec82323
LMI
1752(defsubst gnus-article-hide-text (b e props)
1753 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1754 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1755 (when (memq 'intangible props)
1756 (put-text-property
1757 (max (1- b) (point-min))
1758 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1759
eec82323
LMI
1760(defsubst gnus-article-unhide-text (b e)
1761 "Remove hidden text properties from region between B and E."
1762 (remove-text-properties b e gnus-hidden-properties)
1763 (when (memq 'intangible gnus-hidden-properties)
1764 (put-text-property (max (1- b) (point-min))
1765 b 'intangible nil)))
1766
1767(defun gnus-article-hide-text-type (b e type)
1768 "Hide text of TYPE between B and E."
23f87bed 1769 (gnus-add-wash-type type)
eec82323
LMI
1770 (gnus-article-hide-text
1771 b e (cons 'article-type (cons type gnus-hidden-properties))))
1772
1773(defun gnus-article-unhide-text-type (b e type)
6748645f 1774 "Unhide text of TYPE between B and E."
23f87bed 1775 (gnus-delete-wash-type type)
eec82323
LMI
1776 (remove-text-properties
1777 b e (cons 'article-type (cons type gnus-hidden-properties)))
1778 (when (memq 'intangible gnus-hidden-properties)
1779 (put-text-property (max (1- b) (point-min))
1780 b 'intangible nil)))
1781
1782(defun gnus-article-hide-text-of-type (type)
1783 "Hide text of TYPE in the current buffer."
1784 (save-excursion
1785 (let ((b (point-min))
1786 (e (point-max)))
1787 (while (setq b (text-property-any b e 'article-type type))
1788 (add-text-properties b (incf b) gnus-hidden-properties)))))
1789
1790(defun gnus-article-delete-text-of-type (type)
1791 "Delete text of TYPE in the current buffer."
1792 (save-excursion
a8151ef7 1793 (let ((b (point-min)))
7dafe00b
MB
1794 (if (eq type 'multipart)
1795 ;; Remove MIME buttons associated with multipart/alternative parts.
1796 (progn
1797 (goto-char b)
1798 (while (if (get-text-property (point) 'gnus-part)
1799 (setq b (point))
1800 (when (setq b (next-single-property-change (point)
1801 'gnus-part))
1802 (goto-char b)
1803 t))
1804 (end-of-line)
1805 (skip-chars-forward "\n")
1806 (when (eq (get-text-property b 'article-type) 'multipart)
1807 (delete-region b (point)))))
1808 (while (setq b (text-property-any b (point-max) 'article-type type))
1809 (delete-region
1810 b (or (text-property-not-all b (point-max) 'article-type type)
1811 (point-max))))))))
eec82323
LMI
1812
1813(defun gnus-article-delete-invisible-text ()
1814 "Delete all invisible text in the current buffer."
1815 (save-excursion
a8151ef7
LMI
1816 (let ((b (point-min)))
1817 (while (setq b (text-property-any b (point-max) 'invisible t))
1818 (delete-region
1819 b (or (text-property-not-all b (point-max) 'invisible t)
1820 (point-max)))))))
eec82323
LMI
1821
1822(defun gnus-article-text-type-exists-p (type)
1823 "Say whether any text of type TYPE exists in the buffer."
1824 (text-property-any (point-min) (point-max) 'article-type type))
1825
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)
23f87bed 1829 (i 1))
eec82323 1830 (while list
23f87bed
MB
1831 (if (looking-at (car list))
1832 (setq list nil)
1833 (setq list (cdr list))
1834 (incf i)))
1835 i))
eec82323
LMI
1836
1837(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1838 "Hide unwanted headers and possibly sort them as well."
1839 (interactive)
1840 ;; This function might be inhibited.
1841 (unless gnus-inhibit-hiding
37cc095b 1842 (let ((inhibit-read-only t)
23f87bed
MB
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
16409b0b
GM
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.
23f87bed 1883 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
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.
23f87bed 1898 (gnus-add-wash-type 'headers)
16409b0b
GM
1899 (add-text-properties (point-min) (+ 5 (point-min))
1900 '(article-type headers dummy-invisible t))
1901 (delete-region beg (point-max))))))))
eec82323
LMI
1902
1903(defun article-hide-boring-headers (&optional arg)
1904 "Toggle hiding of headers that aren't very interesting.
1905If given a negative prefix, always show; if given a positive prefix,
1906always 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
4e7d0221 1912 (let ((inhibit-read-only t)
01c52d31 1913 (inhibit-point-motion-hooks t))
16409b0b 1914 (article-narrow-to-head)
01c52d31 1915 (dolist (elem gnus-boring-article-headers)
eec82323
LMI
1916 (goto-char (point-min))
1917 (cond
1918 ;; Hide empty headers.
1919 ((eq elem 'empty)
16409b0b 1920 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1921 (forward-line -1)
1922 (gnus-article-hide-text-type
01c52d31 1923 (point-at-bol)
eec82323
LMI
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)
23f87bed
MB
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 "")))
eec82323 1938 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
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"))))
eec82323 1978 ((eq elem 'followup-to)
23f87bed
MB
1979 (when (gnus-string-equal
1980 (message-fetch-field "followup-to")
1981 (message-fetch-field "newsgroups"))
eec82323
LMI
1982 (gnus-article-hide-header "followup-to")))
1983 ((eq elem 'reply-to)
23f87bed
MB
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
eec82323
LMI
1991 from reply-to
1992 (ignore-errors
1993 (equal
23f87bed
MB
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")))))
eec82323 2003 ((eq elem 'date)
b193caa3
MB
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"))))
eec82323 2009 (when (and date
16409b0b 2010 (< (days-between (current-time-string) date)
eec82323 2011 4))
6748645f
LMI
2012 (gnus-article-hide-header "date"))))
2013 ((eq elem 'long-to)
16409b0b
GM
2014 (let ((to (message-fetch-field "to"))
2015 (cc (message-fetch-field "cc")))
6748645f 2016 (when (> (length to) 1024)
16409b0b
GM
2017 (gnus-article-hide-header "to"))
2018 (when (> (length cc) 1024)
2019 (gnus-article-hide-header "cc"))))
6748645f 2020 ((eq elem 'many-to)
16409b0b
GM
2021 (let ((to-count 0)
2022 (cc-count 0))
6748645f
LMI
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"))
16409b0b
GM
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)))))))))))))
eec82323
LMI
2047
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
01c52d31 2053 (point-at-bol)
eec82323
LMI
2054 (progn
2055 (end-of-line)
2056 (if (re-search-forward "^[^ \t]" nil t)
2057 (match-beginning 0)
2058 (point-max)))
2059 'boring-headers))))
2060
16409b0b
GM
2061(defvar gnus-article-normalized-header-length 40
2062 "Length of normalized headers.")
2063
2064(defun article-normalize-headers ()
2065 "Make all header lines 40 characters long."
2066 (interactive)
4e7d0221 2067 (let ((inhibit-read-only t)
16409b0b
GM
2068 column)
2069 (save-excursion
2070 (save-restriction
2071 (article-narrow-to-head)
2072 (while (not (eobp))
2073 (cond
01c52d31 2074 ((< (setq column (- (point-at-eol) (point)))
16409b0b
GM
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))
01c52d31 2085 (point-at-eol)
16409b0b
GM
2086 'invisible t))
2087 (t
2088 ;; Do nothing.
2089 ))
2090 (forward-line 1))))))
2091
6748645f 2092(defun article-treat-dumbquotes ()
23f87bed 2093 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 2094Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
2095not, so it should only be used interactively.
2096
23f87bed
MB
2097Sm*rtq**t*s are M****s***'s unilateral extension to the
2098iso-8859-1 character map in an attempt to provide more quoting
2099characters. If you see something like \\222 or \\264 where
2100you're expecting some kind of apostrophe or quotation mark, then
2101try this wash."
6748645f 2102 (interactive)
16409b0b 2103 (article-translate-strings gnus-article-dumbquotes-map))
6748645f 2104
16c1b3bc
KY
2105(defvar org-entities)
2106
be3c11b3
LMI
2107(defun article-treat-non-ascii ()
2108 "Translate many Unicode characters into their ASCII equivalents."
2109 (interactive)
2110 (require 'org-entities)
9c1d3f98 2111 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
be3c11b3
LMI
2112 (dolist (elem org-entities)
2113 (when (and (listp elem)
2114 (= (length (nth 6 elem)) 1))
fdf14191
KY
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)))))
be3c11b3
LMI
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t)
2f0e0dc8 2121 replace props)
be3c11b3 2122 (while (not (eobp))
9c1d3f98
KY
2123 (if (not (setq replace (if (featurep 'xemacs)
2124 (get-char-table (following-char) table)
2125 (aref table (following-char)))))
be3c11b3 2126 (forward-char 1)
2f0e0dc8
KY
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)))))))))
be3c11b3 2133
6748645f
LMI
2134(defun article-translate-characters (from to)
2135 "Translate all characters in the body of the article according to FROM and TO.
2136FROM is a string of characters to translate from; to is a string of
2137characters to translate to."
2138 (save-excursion
16409b0b 2139 (when (article-goto-body)
4e7d0221 2140 (let ((inhibit-read-only t)
6748645f
LMI
2141 (x (make-string 225 ?x))
2142 (i -1))
2143 (while (< (incf i) (length x))
2144 (aset x i i))
2145 (setq i 0)
2146 (while (< i (length from))
2147 (aset x (aref from i) (aref to i))
2148 (incf i))
2149 (translate-region (point) (point-max) x)))))
2150
16409b0b
GM
2151(defun article-translate-strings (map)
2152 "Translate all string in the body of the article according to MAP.
2153MAP is an alist where the elements are on the form (\"from\" \"to\")."
2154 (save-excursion
2155 (when (article-goto-body)
01c52d31
MB
2156 (let ((inhibit-read-only t))
2157 (dolist (elem map)
7cad71ad
G
2158 (let ((from (car elem))
2159 (to (cadr elem)))
2160 (save-excursion
2161 (if (stringp from)
2162 (while (search-forward from nil t)
2163 (replace-match to))
2164 (while (not (eobp))
2165 (if (eq (following-char) from)
2166 (progn
2167 (delete-char 1)
2168 (insert to))
2169 (forward-char 1)))))))))))
16409b0b 2170
eec82323
LMI
2171(defun article-treat-overstrike ()
2172 "Translate overstrikes into bold text."
2173 (interactive)
2174 (save-excursion
16409b0b 2175 (when (article-goto-body)
4e7d0221 2176 (let ((inhibit-read-only t))
eec82323 2177 (while (search-forward "\b" nil t)
16409b0b 2178 (let ((next (char-after))
eec82323
LMI
2179 (previous (char-after (- (point) 2))))
2180 ;; We do the boldification/underlining by hiding the
2181 ;; overstrikes and putting the proper text property
2182 ;; on the letters.
2183 (cond
2184 ((eq next previous)
2185 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2186 (put-text-property (point) (1+ (point)) 'face 'bold))
2187 ((eq next ?_)
2188 (gnus-article-hide-text-type
2189 (1- (point)) (1+ (point)) 'overstrike)
2190 (put-text-property
2191 (- (point) 2) (1- (point)) 'face 'underline))
2192 ((eq previous ?_)
2193 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2194 (put-text-property
2195 (point) (1+ (point)) 'face 'underline)))))))))
2196
01c52d31
MB
2197(defun article-treat-ansi-sequences ()
2198 "Translate ANSI SGR control sequences into overlays or extents."
2199 (interactive)
2200 (save-excursion
2201 (when (article-goto-body)
2202 (let ((inhibit-read-only t))
2203 (ansi-color-apply-on-region (point) (point-max))))))
2204
23f87bed
MB
2205(defun gnus-article-treat-unfold-headers ()
2206 "Unfold folded message headers.
2207Only the headers that fit into the current window width will be
2208unfolded."
2209 (interactive)
2210 (gnus-with-article-headers
2211 (let (length)
2212 (while (not (eobp))
2213 (save-restriction
2214 (mail-header-narrow-to-field)
01c52d31
MB
2215 (let* ((header (buffer-string))
2216 (unfoldable
2217 (or (equal gnus-article-unfold-long-headers t)
2218 (and (stringp gnus-article-unfold-long-headers)
2219 (string-match gnus-article-unfold-long-headers header)))))
23f87bed
MB
2220 (with-temp-buffer
2221 (insert header)
2222 (goto-char (point-min))
2223 (while (re-search-forward "\n[\t ]" nil t)
2224 (replace-match " " t t)))
01c52d31
MB
2225 (setq length (- (point-max) (point-min) 1))
2226 (when (or unfoldable
2227 (< length (window-width)))
2228 (while (re-search-forward "\n[\t ]" nil t)
2229 (replace-match " " t t))))
23f87bed
MB
2230 (goto-char (point-max)))))))
2231
2232(defun gnus-article-treat-fold-headers ()
2233 "Fold message headers."
2234 (interactive)
2235 (gnus-with-article-headers
2236 (while (not (eobp))
2237 (save-restriction
2238 (mail-header-narrow-to-field)
2239 (mail-header-fold-field)
2240 (goto-char (point-max))))))
2241
2242(defun gnus-treat-smiley ()
2243 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2244 (interactive)
2245 (gnus-with-article-buffer
2246 (if (memq 'smiley gnus-article-wash-types)
2247 (gnus-delete-images 'smiley)
2248 (article-goto-body)
2249 (let ((images (smiley-region (point) (point-max))))
2250 (when images
2251 (gnus-add-wash-type 'smiley)
2252 (dolist (image images)
2253 (gnus-add-image 'smiley image)))))))
2254
2255(defun gnus-article-remove-images ()
2256 "Remove all images from the article buffer."
2257 (interactive)
2258 (gnus-with-article-buffer
9695908d
KY
2259 (save-restriction
2260 (widen)
2261 (dolist (elem gnus-article-image-alist)
2262 (gnus-delete-images (car elem))))))
23f87bed 2263
8b6f6573
LMI
2264(defun gnus-article-show-images ()
2265 "Show any images that are in the HTML-rendered article buffer.
2266This only works if the article in question is HTML."
2267 (interactive)
2268 (gnus-with-article-buffer
9695908d
KY
2269 (save-restriction
2270 (widen)
2271 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2272 'image-displayer))
2273 (destructuring-bind (start end function) region
2274 (funcall function (get-text-property start 'image-url)
2275 start end))))))
8b6f6573 2276
23f87bed
MB
2277(defun gnus-article-treat-fold-newsgroups ()
2278 "Unfold folded message headers.
2279Only the headers that fit into the current window width will be
2280unfolded."
2281 (interactive)
2282 (gnus-with-article-headers
2283 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2284 (save-restriction
2285 (mail-header-narrow-to-field)
2286 (while (re-search-forward ", *" nil t)
2287 (replace-match ", " t t))
2288 (mail-header-fold-field)
2289 (goto-char (point-max))))))
2290
b7b80032 2291(defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
01c52d31
MB
2292 "Value of `truncate-lines' in Gnus Article buffer.
2293Valid values are nil, t, `head', `first', `last', an integer or a
2294predicate. See Info node `(gnus)Customizing Articles'."
330f707b 2295 :version "23.1" ;; No Gnus
01c52d31
MB
2296 :group 'gnus-article
2297 ;; :link '(custom-manual "(gnus)Customizing Articles")
2298 :type 'boolean)
2299
2300(defun gnus-article-toggle-truncate-lines (&optional arg)
2301 "Toggle whether to fold or truncate long lines in article the buffer.
2302If ARG is non-nil and not a number, toggle
2303`gnus-article-truncate-lines' too. If ARG is a number, truncate
5229211e 2304long lines if and only if arg is positive."
01c52d31
MB
2305 (interactive "P")
2306 (cond
2307 ((and (numberp arg) (> arg 0))
2308 (setq gnus-article-truncate-lines t))
2309 ((numberp arg)
2310 (setq gnus-article-truncate-lines nil))
2311 (arg
2312 (setq gnus-article-truncate-lines
2313 (not gnus-article-truncate-lines))))
2314 (gnus-with-article-buffer
2315 (cond
2316 ((and (numberp arg) (> arg 0))
2317 (setq truncate-lines nil))
2318 ((numberp arg)
2319 (setq truncate-lines t)))
2320 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2321 ;; `toggle-truncate-lines' needs an argument.
2322 (toggle-truncate-lines)))
2323
23f87bed
MB
2324(defun gnus-article-treat-body-boundary ()
2325 "Place a boundary line at the end of the headers."
2326 (interactive)
2327 (when (and gnus-body-boundary-delimiter
2328 (> (length gnus-body-boundary-delimiter) 0))
2329 (gnus-with-article-headers
2330 (goto-char (point-max))
2331 (let ((start (point)))
2332 (insert "X-Boundary: ")
2333 (gnus-add-text-properties start (point) '(invisible t intangible t))
2334 (insert (let (str)
4478e074 2335 (while (>= (window-width) (length str))
23f87bed 2336 (setq str (concat str gnus-body-boundary-delimiter)))
4478e074 2337 (substring str 0 (window-width)))
23f87bed
MB
2338 "\n")
2339 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2340
16409b0b
GM
2341(defun article-fill-long-lines ()
2342 "Fill lines that are wider than the window width."
eec82323
LMI
2343 (interactive)
2344 (save-excursion
4e7d0221 2345 (let ((inhibit-read-only t)
16409b0b
GM
2346 (width (window-width (get-buffer-window (current-buffer)))))
2347 (save-restriction
2348 (article-goto-body)
80b47379 2349 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2350 (while (not (eobp))
2351 (end-of-line)
2352 (when (>= (current-column) (min fill-column width))
23f87bed 2353 (narrow-to-region (min (1+ (point)) (point-max))
01c52d31 2354 (point-at-bol))
23f87bed
MB
2355 (let ((goback (point-marker)))
2356 (fill-paragraph nil)
2357 (goto-char (marker-position goback)))
16409b0b
GM
2358 (widen))
2359 (forward-line 1)))))))
2360
2361(defun article-capitalize-sentences ()
2362 "Capitalize the first word in each sentence."
2363 (interactive)
2364 (save-excursion
4e7d0221 2365 (let ((inhibit-read-only t)
16409b0b
GM
2366 (paragraph-start "^[\n\^L]"))
2367 (article-goto-body)
2368 (while (not (eobp))
2369 (capitalize-word 1)
2370 (forward-sentence)))))
eec82323
LMI
2371
2372(defun article-remove-cr ()
16409b0b 2373 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2374 (interactive)
2375 (save-excursion
4e7d0221 2376 (let ((inhibit-read-only t))
eec82323 2377 (goto-char (point-min))
16409b0b
GM
2378 (while (re-search-forward "\r+$" nil t)
2379 (replace-match "" t t))
2380 (goto-char (point-min))
eec82323 2381 (while (search-forward "\r" nil t)
16409b0b 2382 (replace-match "\n" t t)))))
eec82323
LMI
2383
2384(defun article-remove-trailing-blank-lines ()
2385 "Remove all trailing blank lines from the article."
2386 (interactive)
2387 (save-excursion
4e7d0221 2388 (let ((inhibit-read-only t))
eec82323
LMI
2389 (goto-char (point-max))
2390 (delete-region
2391 (point)
2392 (progn
2393 (while (and (not (bobp))
16409b0b
GM
2394 (looking-at "^[ \t]*$")
2395 (not (gnus-annotation-in-region-p
01c52d31 2396 (point) (point-at-eol))))
eec82323
LMI
2397 (forward-line -1))
2398 (forward-line 1)
2399 (point))))))
2400
9efa445f 2401(defvar gnus-face-properties-alist)
01c52d31 2402
b890d447 2403(defun article-display-face (&optional force)
23f87bed 2404 "Display any Face headers in the header."
b890d447 2405 (interactive (list 'force))
23f87bed
MB
2406 (let ((wash-face-p buffer-read-only))
2407 (gnus-with-article-headers
2408 ;; When displaying parts, this function can be called several times on
2409 ;; the same article, without any intended toggle semantic (as typing `W
2410 ;; D d' would have). So face deletion must occur only when we come from
2411 ;; an interactive command, that is when the *Article* buffer is
2412 ;; read-only.
2413 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2414 (gnus-delete-images 'face)
b890d447
MB
2415 (let ((from (message-fetch-field "from"))
2416 face faces)
7d0c69be 2417 (save-current-buffer
23f87bed 2418 (when (and wash-face-p
7d0c69be
MB
2419 (gnus-buffer-live-p gnus-original-article-buffer)
2420 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2421 (set-buffer gnus-original-article-buffer))
2422 (save-restriction
2423 (mail-narrow-to-head)
b890d447
MB
2424 (when (or force
2425 ;; Check whether this face is censored.
2426 (not (and gnus-article-x-face-too-ugly
2427 (or from
2428 (setq from (message-fetch-field "from")))
2429 (string-match gnus-article-x-face-too-ugly
2430 from))))
2431 (while (gnus-article-goto-header "Face")
2432 (push (mail-header-field-value) faces)))))
d6697c02 2433 (when faces
7d0c69be 2434 (goto-char (point-min))
b890d447
MB
2435 (let (png image)
2436 (unless (setq from (gnus-article-goto-header "from"))
7d0c69be
MB
2437 (insert "From:")
2438 (setq from (point))
b890d447 2439 (insert " [no `from' set]\n"))
7d0c69be
MB
2440 (while faces
2441 (when (setq png (gnus-convert-face-to-png (pop faces)))
01c52d31
MB
2442 (setq image
2443 (apply 'gnus-create-image png 'png t
2444 (cdr (assq 'png gnus-face-properties-alist))))
d6697c02
MB
2445 (goto-char from)
2446 (gnus-add-wash-type 'face)
2447 (gnus-add-image 'face image)
2448 (gnus-put-image image nil 'face))))))))))
23f87bed 2449
eec82323
LMI
2450(defun article-display-x-face (&optional force)
2451 "Look for an X-Face header and display it if present."
2452 (interactive (list 'force))
23f87bed
MB
2453 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2454 (gnus-with-article-headers
2455 ;; Delete the old process, if any.
2456 (when (process-status "article-x-face")
2457 (delete-process "article-x-face"))
2458 ;; See the comment in `article-display-face'.
2459 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2460 ;; We have already displayed X-Faces, so we remove them
2461 ;; instead.
2462 (gnus-delete-images 'xface)
2463 ;; Display X-Faces.
b890d447
MB
2464 (let ((from (message-fetch-field "from"))
2465 x-faces face)
7d0c69be 2466 (save-current-buffer
23f87bed 2467 (when (and wash-face-p
7d0c69be
MB
2468 (gnus-buffer-live-p gnus-original-article-buffer)
2469 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2470 ;; If type `W f', use gnus-original-article-buffer,
2471 ;; otherwise use the current buffer because displaying
2472 ;; RFC822 parts calls this function too.
2473 (set-buffer gnus-original-article-buffer))
2474 (save-restriction
2475 (mail-narrow-to-head)
b890d447
MB
2476 (and gnus-article-x-face-command
2477 (or force
2478 ;; Check whether this face is censored.
2479 (not (and gnus-article-x-face-too-ugly
2480 (or from
2481 (setq from (message-fetch-field "from")))
2482 (string-match gnus-article-x-face-too-ugly
2483 from))))
2484 (while (gnus-article-goto-header "X-Face")
2485 (push (mail-header-field-value) x-faces)))))
2486 (when x-faces
2487 ;; We display the face.
2488 (cond ((functionp gnus-article-x-face-command)
2489 ;; The command is a lisp function, so we call it.
2490 (mapc gnus-article-x-face-command x-faces))
2491 ((stringp gnus-article-x-face-command)
2492 ;; The command is a string, so we interpret the command
2493 ;; as a, well, command, and fork it off.
2494 (let ((process-connection-type nil))
2495 (gnus-set-process-query-on-exit-flag
2496 (start-process
2497 "article-x-face" nil shell-file-name
2498 shell-command-switch gnus-article-x-face-command)
2499 nil)
2500 ;; Sending multiple EOFs to xv doesn't work,
2501 ;; so we only do a single external face.
2502 (with-temp-buffer
2503 (insert (car x-faces))
2504 (process-send-region "article-x-face"
2505 (point-min) (point-max)))
2506 (process-send-eof "article-x-face")))
2507 (t
2508 (error "`%s' set to `%s' is not a function"
2509 gnus-article-x-face-command
2510 'gnus-article-x-face-command)))))))))
a8151ef7 2511
16409b0b
GM
2512(defun article-decode-mime-words ()
2513 "Decode all MIME-encoded words in the article."
2514 (interactive)
01c52d31 2515 (gnus-with-article-buffer
16409b0b 2516 (let ((inhibit-point-motion-hooks t)
16409b0b 2517 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2518 (mail-parse-ignored-charsets
01c52d31
MB
2519 (with-current-buffer gnus-summary-buffer
2520 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
2521 (mail-decode-encoded-word-region (point-min) (point-max)))))
2522
2523(defun article-decode-charset (&optional prompt)
2524 "Decode charset-encoded text in the article.
2525If PROMPT (the prefix), prompt for a coding system to use."
2526 (interactive "P")
2527 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2528 (inhibit-read-only t)
16409b0b 2529 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2530 (mail-parse-ignored-charsets
16409b0b
GM
2531 (save-excursion (condition-case nil
2532 (set-buffer gnus-summary-buffer)
2533 (error))
2534 gnus-newsgroup-ignored-charsets))
2535 ct cte ctl charset format)
c96ec15a
MB
2536 (save-excursion
2537 (save-restriction
2538 (article-narrow-to-head)
2539 (setq ct (message-fetch-field "Content-Type" t)
2540 cte (message-fetch-field "Content-Transfer-Encoding" t)
2541 ctl (and ct (mail-header-parse-content-type ct))
2542 charset (cond
2543 (prompt
2544 (mm-read-coding-system "Charset to decode: "))
2545 (ctl
2546 (mail-content-type-get ctl 'charset)))
2547 format (and ctl (mail-content-type-get ctl 'format)))
2548 (when cte
2549 (setq cte (mail-header-strip cte)))
2550 (if (and ctl (not (string-match "/" (car ctl))))
2551 (setq ctl nil))
2552 (goto-char (point-max)))
2553 (forward-line 1)
2554 (save-restriction
2555 (narrow-to-region (point) (point-max))
2556 (when (and (eq mail-parse-charset 'gnus-decoded)
2557 (eq (mm-body-7-or-8) '8bit))
2558 ;; The text code could have been decoded.
2559 (setq charset mail-parse-charset))
2560 (when (and (or (not ctl)
2561 (equal (car ctl) "text/plain"))
2562 (not format)) ;; article with format will decode later.
2563 (mm-decode-body
2564 charset (and cte (intern (downcase
2565 (gnus-strip-whitespace cte))))
2566 (car ctl)))))))
16409b0b
GM
2567
2568(defun article-decode-encoded-words ()
2569 "Remove encoded-word encoding from headers."
2570 (let ((inhibit-point-motion-hooks t)
2571 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2572 (mail-parse-ignored-charsets
16409b0b
GM
2573 (save-excursion (condition-case nil
2574 (set-buffer gnus-summary-buffer)
2575 (error))
2576 gnus-newsgroup-ignored-charsets))
343d6628 2577 (inhibit-read-only t)
8fbdffe5
MB
2578 end start)
2579 (goto-char (point-min))
2580 (when (search-forward "\n\n" nil 'move)
2581 (forward-line -1))
2582 (setq end (point))
2583 (while (not (bobp))
2584 (while (progn
2585 (forward-line -1)
2586 (and (not (bobp))
2587 (memq (char-after) '(?\t ? )))))
2588 (setq start (point))
2589 (if (looking-at "\
343d6628
MB
2590\\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2591\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
8fbdffe5
MB
2592 (funcall gnus-decode-address-function start end)
2593 (funcall gnus-decode-header-function start end))
2594 (goto-char (setq end start)))))
eec82323 2595
23f87bed 2596(defun article-decode-group-name ()
01c52d31 2597 "Decode group names in Newsgroups, Followup-To and Xref headers."
23f87bed
MB
2598 (let ((inhibit-point-motion-hooks t)
2599 (inhibit-read-only t)
01c52d31
MB
2600 (method (gnus-find-method-for-group gnus-newsgroup-name))
2601 regexp)
23f87bed
MB
2602 (when (and (or gnus-group-name-charset-method-alist
2603 gnus-group-name-charset-group-alist)
2604 (gnus-buffer-live-p gnus-original-article-buffer))
2605 (save-restriction
2606 (article-narrow-to-head)
01c52d31
MB
2607 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2608 (with-current-buffer gnus-original-article-buffer
2609 (goto-char (point-min)))
2610 (setq regexp (concat "^" header
2611 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2612 (while (re-search-forward regexp nil t)
2613 (replace-match (save-match-data
2614 (gnus-decode-newsgroups
2615 ;; XXX how to use data in article buffer?
2616 (with-current-buffer gnus-original-article-buffer
2617 (re-search-forward regexp nil t)
2618 (match-string 1))
2619 gnus-newsgroup-name method))
2620 t t nil 1))
2621 (goto-char (point-min)))))))
23f87bed
MB
2622
2623(autoload 'idna-to-unicode "idna")
2624
2625(defun article-decode-idna-rhs ()
53cfefc8
MB
2626 "Decode IDNA strings in RHS in various headers in current buffer.
2627The following headers are decoded: From:, To:, Cc:, Reply-To:,
2628Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2629 (when gnus-use-idna
2630 (save-restriction
2631 (let ((inhibit-point-motion-hooks t)
2632 (inhibit-read-only t))
2633 (article-narrow-to-head)
2634 (goto-char (point-min))
53cfefc8 2635 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2636 (let (ace unicode)
2637 (when (save-match-data
2638 (and (setq ace (match-string 1))
2639 (save-excursion
2640 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2641 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2642 (setq unicode (idna-to-unicode ace))))
2643 (unless (string= ace unicode)
2644 (replace-match unicode nil nil nil 1)))))))))
2645
2646(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2647 "Translate a quoted-printable-encoded article.
eec82323 2648If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2649or not.
2650If READ-CHARSET, ask for a coding system."
2651 (interactive (list 'force current-prefix-arg))
eec82323 2652 (save-excursion
4e7d0221 2653 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2654 (if (gnus-buffer-live-p gnus-original-article-buffer)
2655 (with-current-buffer gnus-original-article-buffer
2656 (setq type
2657 (gnus-fetch-field "content-transfer-encoding"))
2658 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2659 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2660 (setq charset (and ctl
2661 (mail-content-type-get ctl 'charset)))
2662 (if (stringp charset)
2663 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2664 (if read-charset
2665 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2666 (unless charset
8b93df01 2667 (setq charset gnus-newsgroup-charset))
eec82323 2668 (when (or force
eb806ef3
DL
2669 (and type (let ((case-fold-search t))
2670 (string-match "quoted-printable" type))))
16409b0b 2671 (article-goto-body)
eb806ef3
DL
2672 (quoted-printable-decode-region
2673 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2674
23f87bed 2675(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2676 "Translate a base64 article.
23f87bed
MB
2677If FORCE, decode the article whether it is marked as base64 not.
2678If READ-CHARSET, ask for a coding system."
2679 (interactive (list 'force current-prefix-arg))
16409b0b 2680 (save-excursion
4e7d0221 2681 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2682 (if (gnus-buffer-live-p gnus-original-article-buffer)
2683 (with-current-buffer gnus-original-article-buffer
2684 (setq type
2685 (gnus-fetch-field "content-transfer-encoding"))
2686 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2687 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2688 (setq charset (and ctl
2689 (mail-content-type-get ctl 'charset)))
2690 (if (stringp charset)
2691 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2692 (if read-charset
2693 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2694 (unless charset
8b93df01 2695 (setq charset gnus-newsgroup-charset))
16409b0b 2696 (when (or force
eb806ef3
DL
2697 (and type (let ((case-fold-search t))
2698 (string-match "base64" type))))
16409b0b
GM
2699 (article-goto-body)
2700 (save-restriction
2701 (narrow-to-region (point) (point-max))
2702 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2703 (mm-decode-coding-region
2704 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2705
2706(eval-when-compile
2707 (require 'rfc1843))
2708
2709(defun article-decode-HZ ()
2710 "Translate a HZ-encoded article."
2711 (interactive)
2712 (require 'rfc1843)
2713 (save-excursion
4e7d0221 2714 (let ((inhibit-read-only t))
16409b0b
GM
2715 (rfc1843-decode-region (point-min) (point-max)))))
2716
23f87bed
MB
2717(defun article-unsplit-urls ()
2718 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2719 (interactive)
23f87bed
MB
2720 (save-excursion
2721 (let ((inhibit-read-only t))
2722 (goto-char (point-min))
2723 (while (re-search-forward
97f78c9b 2724 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2725 (replace-match "\\1\\3" t)))
2726 (when (interactive-p)
2727 (gnus-treat-article nil))))
2728
2526f423
G
2729(defun article-wash-html ()
2730 "Format an HTML article."
2731 (interactive)
2732 (let ((handles nil)
2733 (buffer-read-only nil))
2734 (when (gnus-buffer-live-p gnus-original-article-buffer)
2735 (setq handles (mm-dissect-buffer t t)))
2736 (article-goto-body)
2737 (delete-region (point) (point-max))
2738 (mm-inline-text-html handles)))
73043f7d 2739
01c52d31
MB
2740(defvar gnus-article-browse-html-temp-list nil
2741 "List of temporary files created by `gnus-article-browse-html-parts'.
2742Internal variable.")
2743
2744(defcustom gnus-article-browse-delete-temp 'ask
2745 "What to do with temporary files from `gnus-article-browse-html-parts'.
2746If nil, don't delete temporary files. If it is t, delete them on
2747exit from the summary buffer. If it is the symbol `file', query
2748on each file, if it is `ask' ask once when exiting from the
2749summary buffer."
2750 :group 'gnus-article
330f707b 2751 :version "23.1" ;; No Gnus
01c52d31
MB
2752 :type '(choice (const :tag "Don't delete" nil)
2753 (const :tag "Don't ask" t)
2754 (const :tag "Ask" ask)
2755 (const :tag "Ask for each file" file)))
2756
2757;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2758
2759(defun gnus-article-browse-delete-temp-files (&optional how)
2760 "Delete temp-files created by `gnus-article-browse-html-parts'."
2761 (when (and gnus-article-browse-html-temp-list
3aeb9402
KY
2762 (progn
2763 (or how (setq how gnus-article-browse-delete-temp))
2764 (if (eq how 'ask)
2765 (let ((files (length gnus-article-browse-html-temp-list)))
2766 (gnus-y-or-n-p (format
2767 "Delete all %s temporary HTML file%s? "
2768 files
2769 (if (> files 1) "s" ""))))
2770 how)))
01c52d31 2771 (dolist (file gnus-article-browse-html-temp-list)
3aeb9402
KY
2772 (cond ((file-directory-p file)
2773 (when (or (not (eq how 'file))
2774 (gnus-y-or-n-p
2775 (format
2776 "Delete temporary HTML file(s) in directory `%s'? "
2777 (file-name-as-directory file))))
2778 (gnus-delete-directory file)))
2779 ((file-exists-p file)
2780 (when (or (not (eq how 'file))
2781 (gnus-y-or-n-p
2782 (format "Delete temporary HTML file `%s'? " file)))
2783 (delete-file file)))))
01c52d31
MB
2784 ;; Also remove file from the list when not deleted or if file doesn't
2785 ;; exist anymore.
2786 (setq gnus-article-browse-html-temp-list nil))
2787 gnus-article-browse-html-temp-list)
2788
d40d713a
KY
2789(defun gnus-article-browse-html-save-cid-content (cid handles directory)
2790 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2791Return file name."
20c0b2ce 2792 (save-match-data
d40d713a
KY
2793 (let (file type)
2794 (catch 'found
2795 (dolist (handle handles)
2796 (cond
2797 ((not (listp 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 (mail-content-type-get
2806 (mm-handle-disposition handle) 'filename)
2807 (mail-content-type-get
2808 (setq type (mm-handle-type handle)) 'name)
2809 (concat
2810 (make-temp-name "cid")
2811 (car (rassoc (car type) mailcap-mime-extensions))))
2812 directory))
2813 (mm-save-part-to-file handle file)
2814 (throw 'found file))))))))
20c0b2ce 2815
87035689 2816(defun gnus-article-browse-html-parts (list &optional header)
01c52d31 2817 "View all \"text/html\" parts from LIST.
87035689
MB
2818Recurse into multiparts. The optional HEADER that should be a decoded
2819message header will be added to the bodies of the \"text/html\" parts."
01c52d31 2820 ;; Internal function used by `gnus-article-browse-html-article'.
d40d713a 2821 (let (type file charset content cid-dir tmp-file showed)
01c52d31
MB
2822 ;; Find and show the html-parts.
2823 (dolist (handle list)
2824 ;; If HTML, show it:
bbbe940b
MB
2825 (cond ((not (listp handle)))
2826 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2827 (and (equal (car type) "message/external-body")
87035689
MB
2828 (or header
2829 (setq file (or (mail-content-type-get type 'name)
2830 (mail-content-type-get
2831 (mm-handle-disposition handle)
2832 'filename))))
bbbe940b
MB
2833 (or (mm-handle-cache handle)
2834 (condition-case code
2835 (progn (mm-extern-cache-contents handle) t)
2836 (error
2837 (gnus-message 3 "%s" (error-message-string code))
2838 (when (>= gnus-verbose 3) (sit-for 2))
2839 nil)))
2840 (progn
2841 (setq handle (mm-handle-cache handle)
2842 type (mm-handle-type handle))
2843 (equal (car type) "text/html"))))
d40d713a
KY
2844 (setq charset (mail-content-type-get type 'charset)
2845 content (mm-get-part handle))
2846 (with-temp-buffer
2847 (if (eq charset 'gnus-decoded)
2848 (mm-enable-multibyte)
2849 (mm-disable-multibyte))
2850 (insert content)
2851 ;; resolve cid contents
2852 (let ((case-fold-search t)
2853 cid-file)
2854 (goto-char (point-min))
2855 (while (re-search-forward "\
2856<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2857 nil t)
2858 (unless cid-dir
765d4319 2859 (setq cid-dir (mm-make-temp-file "cid" t))
d40d713a
KY
2860 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2861 (setq file nil
2862 content nil)
2863 (when (setq cid-file
2864 (gnus-article-browse-html-save-cid-content
2865 (match-string 2)
2866 (with-current-buffer gnus-article-buffer
2867 gnus-article-mime-handles)
2868 cid-dir))
2869 (replace-match (concat "file://" cid-file)
2870 nil nil nil 1))))
2871 (unless content (setq content (buffer-string))))
2872 (when (or charset header (not file))
bbbe940b
MB
2873 (setq tmp-file (mm-make-temp-file
2874 ;; Do we need to care for 8.3 filenames?
2875 "mm-" nil ".html")))
87035689
MB
2876 ;; Add a meta html tag to specify charset and a header.
2877 (cond
2878 (header
d40d713a 2879 (let (title eheader body hcharset coding force-charset)
87035689
MB
2880 (with-temp-buffer
2881 (mm-enable-multibyte)
2882 (setq case-fold-search t)
2883 (insert header "\n")
2884 (setq title (message-fetch-field "subject"))
2885 (goto-char (point-min))
2886 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2887 (replace-match (cond ((match-beginning 1) "&lt;")
2888 ((match-beginning 2) "&gt;")
2889 (t "&amp;"))))
2890 (goto-char (point-min))
2891 (insert "<pre>\n")
2892 (goto-char (point-max))
2893 (insert "</pre>\n<hr>\n")
2894 ;; We have to examine charset one by one since
2895 ;; charset specified in parts might be different.
2896 (if (eq charset 'gnus-decoded)
2897 (setq charset 'utf-8
2898 eheader (mm-encode-coding-string (buffer-string)
2899 charset)
2900 title (when title
2901 (mm-encode-coding-string title charset))
d40d713a 2902 body (mm-encode-coding-string content charset)
82fc7980 2903 force-charset t)
87035689
MB
2904 (setq hcharset (mm-find-mime-charset-region (point-min)
2905 (point-max)))
2906 (cond ((= (length hcharset) 1)
2907 (setq hcharset (car hcharset)
2908 coding (mm-charset-to-coding-system
2909 hcharset)))
2910 ((> (length hcharset) 1)
2911 (setq hcharset 'utf-8
2912 coding hcharset)))
2913 (if coding
2914 (if charset
2915 (progn
2916 (setq body
2917 (mm-charset-to-coding-system charset))
2918 (if (eq coding body)
2919 (setq eheader (mm-encode-coding-string
2920 (buffer-string) coding)
2921 title (when title
2922 (mm-encode-coding-string
2923 title coding))
d40d713a 2924 body content)
87035689
MB
2925 (setq charset 'utf-8
2926 eheader (mm-encode-coding-string
2927 (buffer-string) charset)
2928 title (when title
2929 (mm-encode-coding-string
2930 title charset))
2931 body (mm-encode-coding-string
2932 (mm-decode-coding-string
d40d713a 2933 content body)
82fc7980
KY
2934 charset)
2935 force-charset t)))
87035689
MB
2936 (setq charset hcharset
2937 eheader (mm-encode-coding-string
2938 (buffer-string) coding)
2939 title (when title
2940 (mm-encode-coding-string
2941 title coding))
d40d713a 2942 body content))
87035689 2943 (setq eheader (mm-string-as-unibyte (buffer-string))
d40d713a 2944 body content)))
87035689
MB
2945 (erase-buffer)
2946 (mm-disable-multibyte)
2947 (insert body)
2948 (when charset
82fc7980 2949 (mm-add-meta-html-tag handle charset force-charset))
87035689
MB
2950 (when title
2951 (goto-char (point-min))
2952 (unless (search-forward "<title>" nil t)
2953 (re-search-forward "<head>\\s-*" nil t)
2954 (insert "<title>" title "</title>\n")))
2955 (goto-char (point-min))
2956 (or (re-search-forward
2957 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2958 (re-search-forward
2959 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2960 (insert eheader)
2961 (mm-write-region (point-min) (point-max)
2962 tmp-file nil nil nil 'binary t))))
2963 (charset
2964 (mm-with-unibyte-buffer
2965 (insert (if (eq charset 'gnus-decoded)
d40d713a
KY
2966 (mm-encode-coding-string content
2967 (setq charset 'utf-8))
2968 content))
87035689
MB
2969 (if (or (mm-add-meta-html-tag handle charset)
2970 (not file))
2971 (mm-write-region (point-min) (point-max)
2972 tmp-file nil nil nil 'binary t)
2973 (setq tmp-file nil))))
2974 (tmp-file
2975 (mm-save-part-to-file handle tmp-file)))
bbbe940b
MB
2976 (when tmp-file
2977 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2978 (add-hook 'gnus-summary-prepare-exit-hook
2979 'gnus-article-browse-delete-temp-files)
2980 (add-hook 'gnus-exit-gnus-hook
2981 (lambda ()
2982 (gnus-article-browse-delete-temp-files t)))
2983 ;; FIXME: Warn if there's an <img> tag?
2984 (browse-url-of-file (or tmp-file (expand-file-name file)))
2985 (setq showed t))
2986 ;; If multipart, recurse
87035689
MB
2987 ((equal (mm-handle-media-supertype handle) "multipart")
2988 (when (gnus-article-browse-html-parts handle header)
2989 (setq showed t)))
2990 ((equal (mm-handle-media-type handle) "message/rfc822")
2991 (mm-with-multibyte-buffer
2992 (mm-insert-part handle)
2993 (setq handle (mm-dissect-buffer t t))
2994 (when (and (bufferp (car handle))
2995 (stringp (car (mm-handle-type handle))))
2996 (setq handle (list handle)))
2997 (when header
2998 (article-decode-encoded-words)
2999 (let ((gnus-visible-headers
3000 (or (get 'gnus-visible-headers 'standard-value)
3001 gnus-visible-headers)))
3002 (article-hide-headers))
3003 (goto-char (point-min))
3004 (search-forward "\n\n" nil 'move)
3005 (skip-chars-backward "\t\n ")
3006 (setq header (buffer-substring (point-min) (point)))))
3007 (when (prog1
3008 (gnus-article-browse-html-parts handle header)
3009 (mm-destroy-parts handle))
3010 (setq showed t)))))
01c52d31
MB
3011 showed))
3012
87035689 3013(defun gnus-article-browse-html-article (&optional arg)
01c52d31 3014 "View \"text/html\" parts of the current article with a WWW browser.
d40d713a
KY
3015Inline images embedded in a message using the cid scheme, as they are
3016generally considered to be safe, will be processed properly.
87035689
MB
3017The message header is added to the beginning of every html part unless
3018the prefix argument ARG is given.
01c52d31 3019
d40d713a
KY
3020Warning: Spammers use links to images (using the http scheme) in HTML
3021articles to verify whether you have read the message. As
9b3ebcb6
MB
3022`gnus-article-browse-html-article' passes the HTML content to the
3023browser without eliminating these \"web bugs\" you should only
3024use it for mails from trusted senders.
b890d447 3025
9b3ebcb6 3026If you always want to display HTML parts in the browser, set
d40d713a
KY
3027`mm-text-html-renderer' to nil.
3028
3029This command creates temporary files to pass HTML contents including
3030images if any to the browser, and deletes them when exiting the group
3031\(if you want)."
01c52d31 3032 ;; Cf. `mm-w3m-safe-url-regexp'
87035689
MB
3033 (interactive "P")
3034 (if arg
3035 (gnus-summary-show-article)
3036 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
9b3ebcb6
MB
3037 gnus-visible-headers))
3038 ;; As we insert a <hr>, there's no need for the body boundary.
3039 (gnus-treat-body-boundary nil))
87035689
MB
3040 (gnus-summary-show-article)))
3041 (with-current-buffer gnus-article-buffer
3042 (let ((header (unless arg
3043 (save-restriction
3044 (widen)
3045 (buffer-substring-no-properties
3046 (goto-char (point-min))
3047 (if (search-forward "\n\n" nil t)
3048 (match-beginning 0)
3049 (goto-char (point-max))
3050 (skip-chars-backward "\t\n ")
3051 (point))))))
3052 parts)
3053 (set-buffer gnus-original-article-buffer)
3054 (setq parts (mm-dissect-buffer t t))
01c52d31
MB
3055 ;; If singlepart, enforce a list.
3056 (when (and (bufferp (car parts))
3057 (stringp (car (mm-handle-type parts))))
3058 (setq parts (list parts)))
3059 ;; Process the list
87035689 3060 (unless (gnus-article-browse-html-parts parts header)
01c52d31 3061 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
87035689
MB
3062 (mm-destroy-parts parts)
3063 (unless arg
3064 (gnus-summary-show-article)))))
01c52d31 3065
16409b0b
GM
3066(defun article-hide-list-identifiers ()
3067 "Remove list identifies from the Subject header.
3068The `gnus-list-identifiers' variable specifies what to do."
3069 (interactive)
23f87bed
MB
3070 (let ((inhibit-point-motion-hooks t)
3071 (regexp (if (consp gnus-list-identifiers)
3072 (mapconcat 'identity gnus-list-identifiers " *\\|")
3073 gnus-list-identifiers))
3074 (inhibit-read-only t))
3075 (when regexp
3076 (save-excursion
3077 (save-restriction
3078 (article-narrow-to-head)
3079 (goto-char (point-min))
3080 (while (re-search-forward
3081 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3082 nil t)
3083 (delete-region (match-beginning 2) (match-end 0))
3084 (beginning-of-line))
3085 (when (re-search-forward
3086 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3087 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
3088
3089(defun article-hide-pem (&optional arg)
3090 "Toggle hiding of any PEM headers and signatures in the current article.
3091If given a negative prefix, always show; if given a positive prefix,
3092always hide."
3093 (interactive (gnus-article-hidden-arg))
3094 (unless (gnus-article-check-hidden-text 'pem arg)
3095 (save-excursion
23f87bed 3096 (let ((inhibit-read-only t) end)
eec82323 3097 (goto-char (point-min))
16409b0b
GM
3098 ;; Hide the horrendously ugly "header".
3099 (when (and (search-forward
3100 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3101 nil t)
3102 (setq end (1+ (match-beginning 0))))
23f87bed 3103 (gnus-add-wash-type 'pem)
16409b0b
GM
3104 (gnus-article-hide-text-type
3105 end
3106 (if (search-forward "\n\n" nil t)
3107 (match-end 0)
3108 (point-max))
3109 'pem)
3110 ;; Hide the trailer as well
3111 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3112 nil t)
3113 (gnus-article-hide-text-type
3114 (match-beginning 0) (match-end 0) 'pem)))))))
3115
3116(defun article-strip-banner ()
23f87bed
MB
3117 "Strip the banners specified by the `banner' group parameter and by
3118`gnus-article-address-banner-alist'."
16409b0b 3119 (interactive)
23f87bed
MB
3120 (save-excursion
3121 (save-restriction
3122 (let ((inhibit-point-motion-hooks t))
3123 (when (gnus-parameter-banner gnus-newsgroup-name)
3124 (article-really-strip-banner
3125 (gnus-parameter-banner gnus-newsgroup-name)))
3126 (when gnus-article-address-banner-alist
cf5a5c38
MB
3127 ;; Note that the From header is decoded here, so it is
3128 ;; required that the *-extract-address-components function
3129 ;; supports non-ASCII text.
d71c0855
MB
3130 (let ((from (save-restriction
3131 (widen)
3132 (article-narrow-to-head)
3133 (mail-fetch-field "from"))))
3134 (when (and from
3135 (setq from
3136 (cadr (funcall gnus-extract-address-components
3137 from))))
3138 (catch 'found
3139 (dolist (pair gnus-article-address-banner-alist)
3140 (when (string-match (car pair) from)
3141 (throw 'found
3142 (article-really-strip-banner (cdr pair)))))))))))))
23f87bed
MB
3143
3144(defun article-really-strip-banner (banner)
3145 "Strip the banner specified by the argument."
16409b0b
GM
3146 (save-excursion
3147 (save-restriction
3148 (let ((inhibit-point-motion-hooks t)
16409b0b 3149 (gnus-signature-limit nil)
23f87bed
MB
3150 (inhibit-read-only t))
3151 (article-goto-body)
3152 (cond
3153 ((eq banner 'signature)
3154 (when (gnus-article-narrow-to-signature)
3155 (widen)
3156 (forward-line -1)
3157 (delete-region (point) (point-max))))
3158 ((symbolp banner)
3159 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3160 (while (re-search-forward banner nil t)
3161 (delete-region (match-beginning 0) (match-end 0)))))
3162 ((stringp banner)
3163 (while (re-search-forward banner nil t)
3164 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
3165
3166(defun article-babel ()
3167 "Translate article using an online translation service."
3168 (interactive)
3169 (require 'babel)
01c52d31 3170 (gnus-with-article-buffer
16409b0b 3171 (when (article-goto-body)
01c52d31 3172 (let* ((start (point))
16409b0b
GM
3173 (end (point-max))
3174 (orig (buffer-substring start end))
23f87bed 3175 (trans (babel-as-string orig)))
16409b0b
GM
3176 (save-restriction
3177 (narrow-to-region start end)
3178 (delete-region start end)
23f87bed 3179 (insert trans))))))
eec82323
LMI
3180
3181(defun article-hide-signature (&optional arg)
3182 "Hide the signature in the current article.
3183If given a negative prefix, always show; if given a positive prefix,
3184always hide."
3185 (interactive (gnus-article-hidden-arg))
3186 (unless (gnus-article-check-hidden-text 'signature arg)
3187 (save-excursion
3188 (save-restriction
4e7d0221 3189 (let ((inhibit-read-only t))
eec82323
LMI
3190 (when (gnus-article-narrow-to-signature)
3191 (gnus-article-hide-text-type
23f87bed
MB
3192 (point-min) (point-max) 'signature))))))
3193 (gnus-set-mode-line 'article))
eec82323 3194
16409b0b
GM
3195(defun article-strip-headers-in-body ()
3196 "Strip offensive headers from bodies."
3197 (interactive)
3198 (save-excursion
3199 (article-goto-body)
3200 (let ((case-fold-search t))
3201 (when (looking-at "x-no-archive:")
3202 (gnus-delete-line)))))
3203
eec82323
LMI
3204(defun article-strip-leading-blank-lines ()
3205 "Remove all blank lines from the beginning of the article."
3206 (interactive)
3207 (save-excursion
3208 (let ((inhibit-point-motion-hooks t)
23f87bed 3209 (inhibit-read-only t))
16409b0b 3210 (when (article-goto-body)
eec82323
LMI
3211 (while (and (not (eobp))
3212 (looking-at "[ \t]*$"))
3213 (gnus-delete-line))))))
3214
16409b0b
GM
3215(defun article-narrow-to-head ()
3216 "Narrow the buffer to the head of the message.
3217Point is left at the beginning of the narrowed-to region."
3218 (narrow-to-region
3219 (goto-char (point-min))
3220 (if (search-forward "\n\n" nil 1)
3221 (1- (point))
3222 (point-max)))
3223 (goto-char (point-min)))
3224
3225(defun article-goto-body ()
3226 "Place point at the start of the body."
3227 (goto-char (point-min))
3228 (cond
3229 ;; This variable is only bound when dealing with separate
3230 ;; MIME body parts.
3231 (article-goto-body-goes-to-point-min-p
3232 t)
3233 ((search-forward "\n\n" nil t)
3234 t)
3235 (t
3236 (goto-char (point-max))
3237 nil)))
3238
eec82323
LMI
3239(defun article-strip-multiple-blank-lines ()
3240 "Replace consecutive blank lines with one empty line."
3241 (interactive)
3242 (save-excursion
3243 (let ((inhibit-point-motion-hooks t)
23f87bed 3244 (inhibit-read-only t))
eec82323 3245 ;; First make all blank lines empty.
16409b0b 3246 (article-goto-body)
eec82323 3247 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
3248 (unless (gnus-annotation-in-region-p
3249 (match-beginning 0) (match-end 0))
3250 (replace-match "" nil t)))
eec82323 3251 ;; Then replace multiple empty lines with a single empty line.
16409b0b 3252 (article-goto-body)
23f87bed 3253 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
3254 (unless (gnus-annotation-in-region-p
3255 (match-beginning 0) (match-end 0))
23f87bed 3256 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3257
3258(defun article-strip-leading-space ()
3259 "Remove all white space from the beginning of the lines in the article."
3260 (interactive)
3261 (save-excursion
3262 (let ((inhibit-point-motion-hooks t)
23f87bed 3263 (inhibit-read-only t))
16409b0b 3264 (article-goto-body)
eec82323
LMI
3265 (while (re-search-forward "^[ \t]+" nil t)
3266 (replace-match "" t t)))))
3267
16409b0b
GM
3268(defun article-strip-trailing-space ()
3269 "Remove all white space from the end of the lines in the article."
3270 (interactive)
3271 (save-excursion
3272 (let ((inhibit-point-motion-hooks t)
23f87bed 3273 (inhibit-read-only t))
16409b0b
GM
3274 (article-goto-body)
3275 (while (re-search-forward "[ \t]+$" nil t)
3276 (replace-match "" t t)))))
3277
eec82323
LMI
3278(defun article-strip-blank-lines ()
3279 "Strip leading, trailing and multiple blank lines."
3280 (interactive)
3281 (article-strip-leading-blank-lines)
3282 (article-remove-trailing-blank-lines)
3283 (article-strip-multiple-blank-lines))
3284
6748645f
LMI
3285(defun article-strip-all-blank-lines ()
3286 "Strip all blank lines."
3287 (interactive)
3288 (save-excursion
3289 (let ((inhibit-point-motion-hooks t)
23f87bed 3290 (inhibit-read-only t))
16409b0b 3291 (article-goto-body)
6748645f
LMI
3292 (while (re-search-forward "^[ \t]*\n" nil t)
3293 (replace-match "" t t)))))
3294
eec82323
LMI
3295(defun gnus-article-narrow-to-signature ()
3296 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 3297 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
3298 (when (gnus-article-search-signature)
3299 (forward-line 1)
3300 ;; Check whether we have some limits to what we consider
3301 ;; to be a signature.
3302 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3303 (list gnus-signature-limit)))
3304 limit limited)
3305 (while (setq limit (pop limits))
3306 (if (or (and (integerp limit)
3307 (< (- (point-max) (point)) limit))
3308 (and (floatp limit)
3309 (< (count-lines (point) (point-max)) limit))
23f87bed 3310 (and (functionp limit)
6748645f
LMI
3311 (funcall limit))
3312 (and (stringp limit)
3313 (not (re-search-forward limit nil t))))
3314 () ; This limit did not succeed.
3315 (setq limited t
3316 limits nil)))
3317 (unless limited
3318 (narrow-to-region (point) (point-max))
3319 t)))))
eec82323
LMI
3320
3321(defun gnus-article-search-signature ()
3322 "Search the current buffer for the signature separator.
3323Put point at the beginning of the signature separator."
3324 (let ((cur (point)))
3325 (goto-char (point-max))
3326 (if (if (stringp gnus-signature-separator)
3327 (re-search-backward gnus-signature-separator nil t)
3328 (let ((seps gnus-signature-separator))
3329 (while (and seps
3330 (not (re-search-backward (car seps) nil t)))
3331 (pop seps))
3332 seps))
3333 t
3334 (goto-char cur)
3335 nil)))
3336
eec82323
LMI
3337(defun gnus-article-hidden-arg ()
3338 "Return the current prefix arg as a number, or 0 if no prefix."
3339 (list (if current-prefix-arg
3340 (prefix-numeric-value current-prefix-arg)
3341 0)))
3342
3343(defun gnus-article-check-hidden-text (type arg)
3344 "Return nil if hiding is necessary.
f0529b5b 3345Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
3346means show, 0 means toggle."
3347 (save-excursion
3348 (save-restriction
eec82323
LMI
3349 (let ((hide (gnus-article-hidden-text-p type)))
3350 (cond
3351 ((or (null arg)
3352 (> arg 0))
3353 nil)
3354 ((< arg 0)
4481aa98
SZ
3355 (gnus-article-show-hidden-text type)
3356 t)
eec82323
LMI
3357 (t
3358 (if (eq hide 'hidden)
4481aa98
SZ
3359 (progn
3360 (gnus-article-show-hidden-text type)
3361 t)
eec82323
LMI
3362 nil)))))))
3363
3364(defun gnus-article-hidden-text-p (type)
3365 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 3366 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 3367 (while (and pos
16409b0b
GM
3368 (not (get-text-property pos 'invisible))
3369 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
3370 (setq pos
3371 (text-property-any (1+ pos) (point-max) 'article-type type)))
3372 (if pos
3373 'hidden
16409b0b 3374 nil)))
eec82323 3375
520aa572 3376(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 3377 "Show all hidden text of type TYPE.
520aa572 3378Originally it is hide instead of DUMMY."
4e7d0221 3379 (let ((inhibit-read-only t)
520aa572 3380 (inhibit-point-motion-hooks t))
a1506d29 3381 (gnus-remove-text-properties-when
520aa572 3382 'article-type type
a1506d29 3383 (point-min) (point-max)
520aa572 3384 (cons 'article-type (cons type
23f87bed
MB
3385 gnus-hidden-properties)))
3386 (gnus-delete-wash-type type)))
eec82323
LMI
3387
3388(defconst article-time-units
3389 `((year . ,(* 365.25 24 60 60))
3390 (week . ,(* 7 24 60 60))
3391 (day . ,(* 24 60 60))
3392 (hour . ,(* 60 60))
3393 (minute . 60)
3394 (second . 1))
3395 "Mapping from time units to seconds.")
3396
23f87bed
MB
3397(defun gnus-article-forward-header ()
3398 "Move point to the start of the next header.
3399If the current header is a continuation header, this can be several
3400lines forward."
3401 (let ((ended nil))
3402 (while (not ended)
3403 (forward-line 1)
3404 (if (looking-at "[ \t]+[^ \t]")
3405 (forward-line 1)
3406 (setq ended t)))))
3407
12e3ca0a
LI
3408(defun article-treat-date ()
3409 (article-date-ut gnus-article-date-headers t))
3410
3411(defun article-date-ut (&optional type highlight date-position)
3412 "Convert DATE date to TYPE in the current article.
3413The default type is `ut'. See `gnus-article-date-headers' for
3414possible values."
eec82323 3415 (interactive (list 'ut t))
12e3ca0a 3416 (let* ((case-fold-search t)
31640842 3417 (inhibit-read-only t)
eec82323 3418 (inhibit-point-motion-hooks t)
12e3ca0a 3419 (first t)
31640842 3420 pos date bface eface)
16409b0b
GM
3421 (save-excursion
3422 (save-restriction
31640842 3423 (goto-char (point-min))
32a400d4
LI
3424 (when (re-search-forward "^Date:" nil t)
3425 (setq bface (get-text-property (point-at-bol) 'face)
3426 eface (get-text-property (1- (point-at-eol)) 'face)))
3427 (goto-char (point-min))
3428 ;; Delete any old Date headers.
3429 (if date-position
3430 (progn
3431 (goto-char date-position)
3432 (setq date (get-text-property (point) 'original-date))
3433 (delete-region (point)
3434 (progn
3435 (gnus-article-forward-header)
3436 (point)))
3437 (article-transform-date date type bface eface))
3438 (while (re-search-forward "^Date:" nil t)
3439 (setq date (get-text-property (match-beginning 0) 'original-date))
3440 (delete-region (point-at-bol) (progn
3441 (gnus-article-forward-header)
3442 (point)))
5b9b62f1 3443 (article-transform-date date type bface eface)))))))
32a400d4
LI
3444
3445(defun article-transform-date (date type bface eface)
3446 (dolist (this-type (cond
3447 ((null type)
3448 (list 'ut))
3449 ((atom type)
3450 (list type))
3451 (t
3452 type)))
3453 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3454 (forward-line -1)
3455 (beginning-of-line)
3456 (put-text-property (point) (1+ (point))
3457 'original-date date)
3458 (put-text-property (point) (1+ (point))
3459 'gnus-date-type this-type)
3460 ;; Do highlighting.
3461 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3462 (put-text-property (match-beginning 1) (1+ (match-end 1))
3463 'face bface)
3464 (put-text-property (match-beginning 2) (match-end 2)
5b9b62f1
LI
3465 'face eface))
3466 (forward-line 1)))
eec82323
LMI
3467
3468(defun article-make-date-line (date type)
3469 "Return a DATE line of TYPE."
5fe18311
KY
3470 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3471 combined-lapsed))
23f87bed
MB
3472 (error "Unknown conversion type: %s" type))
3473 (condition-case ()
3474 (let ((time (date-to-time date)))
16409b0b 3475 (cond
23f87bed
MB
3476 ;; Convert to the local timezone.
3477 ((eq type 'local)
01c52d31 3478 (concat "Date: " (message-make-date time)))
23f87bed
MB
3479 ;; Convert to Universal Time.
3480 ((eq type 'ut)
3481 (concat "Date: "
01c52d31
MB
3482 (substring
3483 (message-make-date
3484 (let* ((e (parse-time-string date))
3485 (tm (apply 'encode-time e))
3486 (ms (car tm))
3487 (ls (- (cadr tm) (car (current-time-zone time)))))
3488 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3489 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3490 (t (list ms ls)))))
3491 0 -5)
3492 "UT"))
23f87bed
MB
3493 ;; Get the original date from the article.
3494 ((eq type 'original)
3495 (concat "Date: " (if (string-match "\n+$" date)
3496 (substring date 0 (match-beginning 0))
3497 date)))
3498 ;; Let the user define the format.
c4753373 3499 ((eq type 'user-defined)
23f87bed
MB
3500 (let ((format (or (condition-case nil
3501 (with-current-buffer gnus-summary-buffer
3502 gnus-article-time-format)
3503 (error nil))
3504 gnus-article-time-format)))
3505 (if (functionp format)
3506 (funcall format time)
3507 (concat "Date: " (format-time-string format time)))))
3508 ;; ISO 8601.
3509 ((eq type 'iso8601)
3510 (let ((tz (car (current-time-zone time))))
3511 (concat
3512 "Date: "
3513 (format-time-string "%Y%m%dT%H%M%S" time)
3514 (format "%s%02d%02d"
3515 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3516 (/ (% (abs tz) 3600) 60)))))
12e3ca0a 3517 ;; Do a lapsed format.
23f87bed 3518 ((eq type 'lapsed)
12e3ca0a 3519 (concat "Date: " (article-lapsed-string time)))
647559c2
LI
3520 ;; A combined date/lapsed format.
3521 ((eq type 'combined-lapsed)
19cc6697
G
3522 (let ((date-string (article-make-date-line date 'original))
3523 (segments 3)
3524 lapsed-string)
3525 (while (and
3526 (setq lapsed-string
3527 (concat " (" (article-lapsed-string time segments) ")"))
3528 (> (+ (length date-string)
3529 (length lapsed-string))
d6f13ac8 3530 (+ fill-column 6))
19cc6697
G
3531 (> segments 0))
3532 (setq segments (1- segments)))
3533 (if (> segments 0)
3534 (concat date-string lapsed-string)
3535 date-string)))
23f87bed
MB
3536 ;; Display the date in proper English
3537 ((eq type 'english)
3538 (let ((dtime (decode-time time)))
3539 (concat
3540 "Date: the "
3541 (number-to-string (nth 3 dtime))
3542 (let ((digit (% (nth 3 dtime) 10)))
3543 (cond
3544 ((memq (nth 3 dtime) '(11 12 13)) "th")
3545 ((= digit 1) "st")
3546 ((= digit 2) "nd")
3547 ((= digit 3) "rd")
3548 (t "th")))
3549 " of "
3550 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3551 " "
3552 (number-to-string (nth 5 dtime))
3553 " at "
3554 (format "%02d" (nth 2 dtime))
3555 ":"
3556 (format "%02d" (nth 1 dtime)))))))
647559c2 3557 (foo
a601fb74 3558 (format "Date: %s (from Gnus)" date))))
eec82323 3559
647559c2
LI
3560(defun article-lapsed-string (time &optional max-segments)
3561 ;; If the date is seriously mangled, the timezone functions are
3562 ;; liable to bug out, so we ignore all errors.
3563 (let* ((now (current-time))
3564 (real-time (subtract-time now time))
3565 (real-sec (and real-time
3566 (+ (* (float (car real-time)) 65536)
3567 (cadr real-time))))
3568 (sec (and real-time (abs real-sec)))
3569 (segments 0)
3570 num prev)
3571 (unless max-segments
3572 (setq max-segments (length article-time-units)))
3573 (cond
3574 ((null real-time)
3575 "Unknown")
3576 ((zerop sec)
3577 "Now")
3578 (t
3579 (concat
3580 ;; This is a bit convoluted, but basically we go
3581 ;; through the time units for years, weeks, etc,
3582 ;; and divide things to see whether that results
3583 ;; in positive answers.
3584 (mapconcat
3585 (lambda (unit)
3586 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3587 (>= segments max-segments))
3588 ;; The (remaining) seconds are too few to
3589 ;; be divided into this time unit.
3590 ""
3591 ;; It's big enough, so we output it.
3592 (setq sec (- sec (* num (cdr unit))))
3593 (prog1
3594 (concat (if prev ", " "") (int-to-string
3595 (floor num))
3596 " " (symbol-name (car unit))
3597 (if (> num 1) "s" ""))
3598 (setq prev t
3599 segments (1+ segments)))))
3600 article-time-units "")
3601 ;; If dates are odd, then it might appear like the
3602 ;; article was sent in the future.
3603 (if (> real-sec 0)
3604 " ago"
3605 " in the future"))))))
3606
eec82323
LMI
3607(defun article-date-local (&optional highlight)
3608 "Convert the current article date to the local timezone."
3609 (interactive (list t))
3610 (article-date-ut 'local highlight))
3611
23f87bed
MB
3612(defun article-date-english (&optional highlight)
3613 "Convert the current article date to something that is proper English."
3614 (interactive (list t))
3615 (article-date-ut 'english highlight))
3616
eec82323
LMI
3617(defun article-date-original (&optional highlight)
3618 "Convert the current article date to what it was originally.
3619This is only useful if you have used some other date conversion
3620function and want to see what the date was before converting."
3621 (interactive (list t))
3622 (article-date-ut 'original highlight))
3623
3624(defun article-date-lapsed (&optional highlight)
3625 "Convert the current article date to time lapsed since it was sent."
3626 (interactive (list t))
3627 (article-date-ut 'lapsed highlight))
3628
647559c2
LI
3629(defun article-date-combined-lapsed (&optional highlight)
3630 "Convert the current article date to time lapsed since it was sent."
3631 (interactive (list t))
3632 (article-date-ut 'combined-lapsed highlight))
3633
6748645f
LMI
3634(defun article-update-date-lapsed ()
3635 "Function to be run from a timer to update the lapsed time line."
e0a8aa09 3636 (save-match-data
0832490d
LI
3637 (let ((buffer (current-buffer)))
3638 (ignore-errors
3639 (walk-windows
3640 (lambda (w)
3641 (set-buffer (window-buffer w))
3642 (when (eq major-mode 'gnus-article-mode)
3643 (let ((old-line (count-lines (point-min) (point)))
3644 (old-column (current-column)))
3645 (goto-char (point-min))
3646 (while (re-search-forward "^Date:" nil t)
3647 (let ((type (get-text-property (match-beginning 0) 'gnus-date-type)))
3648 (when (memq type '(lapsed combined-lapsed user-format))
3649 (save-excursion
3650 (article-date-ut type t (match-beginning 0)))
3651 (forward-line 1))))
3652 (goto-char (point-min))
3653 (when (> old-column 0)
3654 (setq old-line (1- old-line)))
3655 (forward-line old-line)
3656 (end-of-line)
3657 (when (> (current-column) old-column)
3658 (beginning-of-line)
3659 (forward-char old-column)))))
3660 nil 'visible))
3661 (set-buffer buffer))))
6748645f
LMI
3662
3663(defun gnus-start-date-timer (&optional n)
12e3ca0a 3664 "Start a timer to update the Date headers in the article buffers.
6748645f
LMI
3665The numerical prefix says how frequently (in seconds) the function
3666is to run."
3667 (interactive "p")
3668 (unless n
3669 (setq n 1))
3670 (gnus-stop-date-timer)
3671 (setq article-lapsed-timer
01c52d31 3672 (run-at-time 1 n 'article-update-date-lapsed)))
6748645f
LMI
3673
3674(defun gnus-stop-date-timer ()
12e3ca0a 3675 "Stop the Date timer."
6748645f
LMI
3676 (interactive)
3677 (when article-lapsed-timer
3678 (nnheader-cancel-timer article-lapsed-timer)
3679 (setq article-lapsed-timer nil)))
3680
eec82323
LMI
3681(defun article-date-user (&optional highlight)
3682 "Convert the current article date to the user-defined format.
3683This format is defined by the `gnus-article-time-format' variable."
3684 (interactive (list t))
3685 (article-date-ut 'user highlight))
3686
6748645f
LMI
3687(defun article-date-iso8601 (&optional highlight)
3688 "Convert the current article date to ISO8601."
3689 (interactive (list t))
3690 (article-date-ut 'iso8601 highlight))
3691
31640842
MB
3692(defmacro gnus-article-save-original-date (&rest forms)
3693 "Save the original date as a text property and evaluate FORMS."
3694 `(let* ((case-fold-search t)
3695 (start (progn
3696 (goto-char (point-min))
3697 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3698 (not (bolp)))
3699 (match-end 0))))
3700 (date (when (and start
01c52d31 3701 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
31640842
MB
3702 nil t))
3703 (buffer-substring-no-properties start
3704 (match-beginning 0)))))
3705 (goto-char (point-max))
3706 (skip-chars-backward "\n")
3707 (put-text-property (point-min) (point) 'original-date date)
3708 ,@forms
3709 (goto-char (point-max))
3710 (skip-chars-backward "\n")
3711 (put-text-property (point-min) (point) 'original-date date)))
3712
23f87bed
MB
3713;; (defun article-show-all ()
3714;; "Show all hidden text in the article buffer."
3715;; (interactive)
3716;; (save-excursion
3717;; (let ((inhibit-read-only t))
3718;; (gnus-article-unhide-text (point-min) (point-max)))))
3719
3720(defun article-remove-leading-whitespace ()
3721 "Remove excessive whitespace from all headers."
eec82323
LMI
3722 (interactive)
3723 (save-excursion
23f87bed
MB
3724 (save-restriction
3725 (let ((inhibit-read-only t))
3726 (article-narrow-to-head)
3727 (goto-char (point-min))
3728 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3729 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3730
3731(defun article-emphasize (&optional arg)
3732 "Emphasize text according to `gnus-emphasis-alist'."
3733 (interactive (gnus-article-hidden-arg))
3734 (unless (gnus-article-check-hidden-text 'emphasis arg)
3735 (save-excursion
a1506d29 3736 (let ((alist (or
16409b0b 3737 (condition-case nil
a1506d29
JB
3738 (with-current-buffer gnus-summary-buffer
3739 gnus-article-emphasis-alist)
16409b0b
GM
3740 (error))
3741 gnus-emphasis-alist))
4e7d0221 3742 (inhibit-read-only t)
eec82323
LMI
3743 (props (append '(article-type emphasis)
3744 gnus-hidden-properties))
3745 regexp elem beg invisible visible face)
16409b0b 3746 (article-goto-body)
eec82323
LMI
3747 (setq beg (point))
3748 (while (setq elem (pop alist))
3749 (goto-char beg)
3750 (setq regexp (car elem)
3751 invisible (nth 1 elem)
3752 visible (nth 2 elem)
3753 face (nth 3 elem))
3754 (while (re-search-forward regexp nil t)
23f87bed
MB
3755 (when (and (match-beginning visible) (match-beginning invisible))
3756 (gnus-article-hide-text
3757 (match-beginning invisible) (match-end invisible) props)
3758 (gnus-article-unhide-text-type
3759 (match-beginning visible) (match-end visible) 'emphasis)
3760 (gnus-put-overlay-excluding-newlines
3761 (match-beginning visible) (match-end visible) 'face face)
3762 (gnus-add-wash-type 'emphasis)
3763 (goto-char (match-end invisible)))))))))
eec82323 3764
16409b0b
GM
3765(defun gnus-article-setup-highlight-words (&optional highlight-words)
3766 "Setup newsgroup emphasis alist."
3767 (unless gnus-article-emphasis-alist
3768 (let ((name (and gnus-newsgroup-name
3769 (gnus-group-real-name gnus-newsgroup-name))))
3770 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3771 (setq gnus-article-emphasis-alist
3772 (nconc
16409b0b
GM
3773 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3774 (while (setq elem (pop alist))
3775 (when (and name (string-match (car elem) name))
3776 (setq alist nil
3777 highlight (copy-sequence (cdr elem)))))
3778 highlight)
3779 (copy-sequence highlight-words)
3780 (if gnus-newsgroup-name
a1506d29 3781 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3782 gnus-newsgroup-name 'highlight-words t)))
3783 gnus-emphasis-alist)))))
3784
9efa445f
DN
3785(defvar gnus-summary-article-menu)
3786(defvar gnus-summary-post-menu)
eec82323
LMI
3787
3788;;; Saving functions.
3789
3790(defun gnus-article-save (save-buffer file &optional num)
3791 "Save the currently selected article."
26c9afc3
MB
3792 (when (or (get gnus-default-article-saver :headers)
3793 (not gnus-save-all-headers))
3794 ;; Remove headers according to `gnus-saved-headers' or the value
3795 ;; of the `:headers' property that the saver function might have.
eec82323 3796 (let ((gnus-visible-headers
26c9afc3
MB
3797 (or (symbol-value (get gnus-default-article-saver :headers))
3798 gnus-saved-headers gnus-visible-headers))
16c85f26
MB
3799 ;; Ignore group parameter. See `article-hide-headers'.
3800 (gnus-summary-buffer nil))
80de1778 3801 (with-current-buffer save-buffer
6748645f 3802 (article-hide-headers 1 t))))
eec82323
LMI
3803 (save-window-excursion
3804 (if (not gnus-default-article-saver)
a8151ef7 3805 (error "No default saver is defined")
eec82323 3806 ;; !!! Magic! The saving functions all save
16409b0b 3807 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3808 ;; bind that variable to our save-buffer.
3809 (set-buffer gnus-article-buffer)
3810 (let* ((gnus-save-article-buffer save-buffer)
3811 (filename
3812 (cond
3813 ((not gnus-prompt-before-saving) 'default)
3814 ((eq gnus-prompt-before-saving 'always) nil)
3815 (t file)))
3816 (gnus-number-of-articles-to-be-saved
3817 (when (eq gnus-prompt-before-saving t)
3818 num))) ; Magic
6748645f 3819 (set-buffer gnus-article-current-summary)
eec82323
LMI
3820 (funcall gnus-default-article-saver filename)))))
3821
3822(defun gnus-read-save-file-name (prompt &optional filename
26c9afc3
MB
3823 function group headers variable
3824 dir-var)
eec82323
LMI
3825 (let ((default-name
3826 (funcall function group headers (symbol-value variable)))
3827 result)
4325195c 3828 (setq result
a1506d29 3829 (expand-file-name
4325195c
DL
3830 (cond
3831 ((eq filename 'default)
3832 default-name)
3833 ((eq filename t)
3834 default-name)
3835 (filename filename)
3836 (t
26c9afc3
MB
3837 (when (symbol-value dir-var)
3838 (setq default-name (expand-file-name
3839 (file-name-nondirectory default-name)
3840 (symbol-value dir-var))))
4325195c
DL
3841 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3842 (prompt
3843 (format prompt
3844 (if (and gnus-number-of-articles-to-be-saved
3845 (> gnus-number-of-articles-to-be-saved 1))
3846 (format "these %d articles"
3847 gnus-number-of-articles-to-be-saved)
3848 "this article")))
3849 (file
3850 ;; Let the split methods have their say.
3851 (cond
3852 ;; No split name was found.
3853 ((null split-name)
3854 (read-file-name
3855 (concat prompt " (default "
81df110a 3856 (file-name-nondirectory default-name) "): ")
4325195c
DL
3857 (file-name-directory default-name)
3858 default-name))
3859 ;; A single group name is returned.
3860 ((stringp split-name)
3861 (setq default-name
3862 (funcall function split-name headers
3863 (symbol-value variable)))
3864 (read-file-name
3865 (concat prompt " (default "
81df110a 3866 (file-name-nondirectory default-name) "): ")
4325195c
DL
3867 (file-name-directory default-name)
3868 default-name))
3869 ;; A single split name was found
3870 ((= 1 (length split-name))
3871 (let* ((name (expand-file-name
23f87bed
MB
3872 (car split-name)
3873 gnus-article-save-directory))
4325195c
DL
3874 (dir (cond ((file-directory-p name)
3875 (file-name-as-directory name))
3876 ((file-exists-p name) name)
3877 (t gnus-article-save-directory))))
3878 (read-file-name
81df110a 3879 (concat prompt " (default " name "): ")
4325195c
DL
3880 dir name)))
3881 ;; A list of splits was found.
3882 (t
3883 (setq split-name (nreverse split-name))
3884 (let (result)
3885 (let ((file-name-history
3886 (nconc split-name file-name-history)))
3887 (setq result
3888 (expand-file-name
3889 (read-file-name
81df110a 3890 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3891 gnus-article-save-directory
3892 (car split-name))
3893 gnus-article-save-directory)))
3894 (car (push result file-name-history)))))))
3895 ;; Create the directory.
3896 (gnus-make-directory (file-name-directory file))
23f87bed 3897 ;; If we have read a directory, we append the default file name.
4325195c 3898 (when (file-directory-p file)
23f87bed
MB
3899 (setq file (expand-file-name (file-name-nondirectory
3900 default-name)
4325195c
DL
3901 (file-name-as-directory file))))
3902 ;; Possibly translate some characters.
3903 (nnheader-translate-file-chars file))))))
eec82323 3904 (gnus-make-directory (file-name-directory result))
26c9afc3
MB
3905 (when variable
3906 (set variable result))
3907 (when dir-var
3908 (set dir-var (file-name-directory result)))
3909 result))
eec82323
LMI
3910
3911(defun gnus-article-archive-name (group)
3912 "Return the first instance of an \"Archive-name\" in the current buffer."
3913 (let ((case-fold-search t))
3914 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3915 (nnheader-concat gnus-article-save-directory
3916 (match-string 1)))))
3917
3918(defun gnus-article-nndoc-name (group)
3919 "If GROUP is an nndoc group, return the name of the parent group."
3920 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3921 (gnus-group-get-parameter group 'save-article-group)))
3922
3923(defun gnus-summary-save-in-rmail (&optional filename)
3924 "Append this article to Rmail file.
3925Optional argument FILENAME specifies file name.
3926Directory to save to is default to `gnus-article-save-directory'."
eec82323 3927 (setq filename (gnus-read-save-file-name
81df110a 3928 "Save %s in rmail file" filename
eec82323
LMI
3929 gnus-rmail-save-name gnus-newsgroup-name
3930 gnus-current-headers 'gnus-newsgroup-last-rmail))
a3f57c41 3931 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
3932 (save-excursion
3933 (save-restriction
3934 (widen)
fef8d38e
GM
3935 ;; Note that unlike gnus-summary-save-in-mail, there is no
3936 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3937 ;; not use Babyl.
6748645f
LMI
3938 (gnus-output-to-rmail filename))))
3939 filename)
eec82323
LMI
3940
3941(defun gnus-summary-save-in-mail (&optional filename)
3942 "Append this article to Unix mail file.
3943Optional argument FILENAME specifies file name.
3944Directory to save to is default to `gnus-article-save-directory'."
eec82323 3945 (setq filename (gnus-read-save-file-name
81df110a 3946 "Save %s in Unix mail file" filename
eec82323
LMI
3947 gnus-mail-save-name gnus-newsgroup-name
3948 gnus-current-headers 'gnus-newsgroup-last-mail))
a3f57c41 3949 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
3950 (save-excursion
3951 (save-restriction
3952 (widen)
3953 (if (and (file-readable-p filename)
23f87bed 3954 (file-regular-p filename)
eec82323 3955 (mail-file-babyl-p filename))
fef8d38e 3956 (gnus-output-to-rmail filename)
6748645f
LMI
3957 (gnus-output-to-mail filename)))))
3958 filename)
eec82323 3959
26c9afc3
MB
3960(put 'gnus-summary-save-in-file :decode t)
3961(put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
eec82323
LMI
3962(defun gnus-summary-save-in-file (&optional filename overwrite)
3963 "Append this article to file.
3964Optional argument FILENAME specifies file name.
3965Directory to save to is default to `gnus-article-save-directory'."
eec82323 3966 (setq filename (gnus-read-save-file-name
81df110a 3967 "Save %s in file" filename
eec82323
LMI
3968 gnus-file-save-name gnus-newsgroup-name
3969 gnus-current-headers 'gnus-newsgroup-last-file))
a3f57c41 3970 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
3971 (save-excursion
3972 (save-restriction
3973 (widen)
3974 (when (and overwrite
3975 (file-exists-p filename))
3976 (delete-file filename))
6748645f
LMI
3977 (gnus-output-to-file filename))))
3978 filename)
eec82323 3979
26c9afc3
MB
3980(put 'gnus-summary-write-to-file :decode t)
3981(put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3982(put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
eec82323 3983(defun gnus-summary-write-to-file (&optional filename)
23f87bed 3984 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
3985Optional argument FILENAME specifies file name.
3986The directory to save in defaults to `gnus-article-save-directory'."
26c9afc3
MB
3987 (setq filename (gnus-read-save-file-name
3988 "Save %s in file" filename
3989 gnus-file-save-name gnus-newsgroup-name
3990 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3991 (gnus-summary-save-in-file filename t))
eec82323 3992
26c9afc3
MB
3993(put 'gnus-summary-save-body-in-file :decode t)
3994(defun gnus-summary-save-body-in-file (&optional filename overwrite)
eec82323
LMI
3995 "Append this article body to a file.
3996Optional argument FILENAME specifies file name.
3997The directory to save in defaults to `gnus-article-save-directory'."
eec82323 3998 (setq filename (gnus-read-save-file-name
81df110a 3999 "Save %s body in file" filename
eec82323
LMI
4000 gnus-file-save-name gnus-newsgroup-name
4001 gnus-current-headers 'gnus-newsgroup-last-file))
a3f57c41 4002 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
4003 (save-excursion
4004 (save-restriction
4005 (widen)
16409b0b 4006 (when (article-goto-body)
eec82323 4007 (narrow-to-region (point) (point-max)))
26c9afc3
MB
4008 (when (and overwrite
4009 (file-exists-p filename))
4010 (delete-file filename))
6748645f
LMI
4011 (gnus-output-to-file filename))))
4012 filename)
eec82323 4013
26c9afc3
MB
4014(put 'gnus-summary-write-body-to-file :decode t)
4015(put 'gnus-summary-write-body-to-file
4016 :function 'gnus-summary-save-body-in-file)
4017(defun gnus-summary-write-body-to-file (&optional filename)
4018 "Write this article body to a file, overwriting it if the file exists.
4019Optional argument FILENAME specifies file name.
4020The directory to save in defaults to `gnus-article-save-directory'."
4021 (setq filename (gnus-read-save-file-name
4022 "Save %s body in file" filename
4023 gnus-file-save-name gnus-newsgroup-name
4024 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4025 (gnus-summary-save-body-in-file filename t))
4026
89167438
MB
4027(put 'gnus-summary-save-in-pipe :decode t)
4028(put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
d62672f3
MB
4029(defun gnus-summary-save-in-pipe (&optional command raw)
4030 "Pipe this article to subprocess COMMAND.
4031Valid values for COMMAND include:
4032 a string
4033 The executable command name and possibly arguments.
4034 nil
4035 You will be prompted for the command in the minibuffer.
4036 the symbol `default'
4037 It will be replaced with the command which the variable
4038 `gnus-summary-pipe-output-default-command' holds or the command
4039 last used for saving.
4040Non-nil value for RAW overrides `:decode' and `:headers' properties
4041and the raw article including all headers will be piped."
6ecfe5c2
MB
4042 (let ((article (gnus-summary-article-number))
4043 (decode (unless raw
4044 (get 'gnus-summary-save-in-pipe :decode)))
4045 save-buffer default)
4046 (if article
4047 (if (vectorp (gnus-summary-article-header article))
4048 (save-current-buffer
4049 (gnus-summary-select-article decode decode nil article)
4050 (insert-buffer-substring
4051 (prog1
4052 (if decode
4053 gnus-article-buffer
4054 gnus-original-article-buffer)
4055 (setq save-buffer
4056 (nnheader-set-temp-buffer " *Gnus Save*"))))
4057 ;; Remove unwanted headers.
4058 (when (and (not raw)
4059 (or (get 'gnus-summary-save-in-pipe :headers)
4060 (not gnus-save-all-headers)))
4061 (let ((gnus-visible-headers
4062 (or (symbol-value (get 'gnus-summary-save-in-pipe
4063 :headers))
4064 gnus-saved-headers gnus-visible-headers))
4065 (gnus-summary-buffer nil))
4066 (article-hide-headers 1 t))))
4067 (error "%d is not a real article" article))
4068 (error "No article to pipe"))
4069 (setq default (or gnus-summary-pipe-output-default-command
4070 gnus-last-shell-command))
89167438
MB
4071 (unless (stringp command)
4072 (setq command
4073 (if (and (eq command 'default) default)
4074 default
6ecfe5c2
MB
4075 (gnus-read-shell-command "Shell command on this article: "
4076 default))))
89167438
MB
4077 (when (string-equal command "")
4078 (if default
4079 (setq command default)
16c85f26 4080 (error "A command is required")))
a3f57c41 4081 (with-current-buffer save-buffer
16c85f26
MB
4082 (save-restriction
4083 (widen)
4084 (shell-command-on-region (point-min) (point-max) command nil)))
4085 (gnus-kill-buffer save-buffer))
89167438 4086 (setq gnus-summary-pipe-output-default-command command))
eec82323 4087
23f87bed
MB
4088(defun gnus-summary-pipe-to-muttprint (&optional command)
4089 "Pipe this article to muttprint."
16c85f26
MB
4090 (unless (stringp command)
4091 (setq command (read-string
4092 "Print using command: " gnus-summary-muttprint-program
4093 nil gnus-summary-muttprint-program)))
4094 (let ((gnus-summary-pipe-output-default-command
4095 gnus-summary-pipe-output-default-command))
4096 (gnus-summary-save-in-pipe command))
4097 (setq gnus-summary-muttprint-program command))
23f87bed 4098
eec82323
LMI
4099;;; Article file names when saving.
4100
4101(defun gnus-capitalize-newsgroup (newsgroup)
4102 "Capitalize NEWSGROUP name."
4103 (when (not (zerop (length newsgroup)))
4104 (concat (char-to-string (upcase (aref newsgroup 0)))
4105 (substring newsgroup 1))))
4106
4107(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4108 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4109If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4110Otherwise, it is like ~/News/news/group/num."
4111 (let ((default
4112 (expand-file-name
4113 (concat (if (gnus-use-long-file-name 'not-save)
4114 (gnus-capitalize-newsgroup newsgroup)
4115 (gnus-newsgroup-directory-form newsgroup))
4116 "/" (int-to-string (mail-header-number headers)))
4117 gnus-article-save-directory)))
4118 (if (and last-file
4119 (string-equal (file-name-directory default)
4120 (file-name-directory last-file))
4121 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4122 default
4123 (or last-file default))))
4124
4125(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4126 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4127If variable `gnus-use-long-file-name' is non-nil, it is
2ff9f5b4 4128~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
eec82323
LMI
4129 (let ((default
4130 (expand-file-name
4131 (concat (if (gnus-use-long-file-name 'not-save)
4132 newsgroup
4133 (gnus-newsgroup-directory-form newsgroup))
4134 "/" (int-to-string (mail-header-number headers)))
4135 gnus-article-save-directory)))
4136 (if (and last-file
4137 (string-equal (file-name-directory default)
4138 (file-name-directory last-file))
4139 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4140 default
4141 (or last-file default))))
4142
eec82323
LMI
4143(defun gnus-plain-save-name (newsgroup headers &optional last-file)
4144 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4145If variable `gnus-use-long-file-name' is non-nil, it is
4146~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4147 (or last-file
4148 (expand-file-name
4149 (if (gnus-use-long-file-name 'not-save)
4150 newsgroup
23f87bed
MB
4151 (file-relative-name
4152 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4153 default-directory))
eec82323
LMI
4154 gnus-article-save-directory)))
4155
23f87bed
MB
4156(defun gnus-sender-save-name (newsgroup headers &optional last-file)
4157 "Generate file name from sender."
4158 (let ((from (mail-header-from headers)))
4159 (expand-file-name
4160 (if (and from (string-match "\\([^ <]+\\)@" from))
4161 (match-string 1 from)
4162 "nobody")
4163 gnus-article-save-directory)))
4164
4165(defun article-verify-x-pgp-sig ()
4166 "Verify X-PGP-Sig."
bbbe940b 4167 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
23f87bed
MB
4168 (interactive)
4169 (if (gnus-buffer-live-p gnus-original-article-buffer)
4170 (let ((sig (with-current-buffer gnus-original-article-buffer
4171 (gnus-fetch-field "X-PGP-Sig")))
4172 items info headers)
4173 (when (and sig
4174 mml2015-use
4175 (mml2015-clear-verify-function))
4176 (with-temp-buffer
4177 (insert-buffer-substring gnus-original-article-buffer)
4178 (setq items (split-string sig))
4179 (message-narrow-to-head)
4180 (let ((inhibit-point-motion-hooks t)
4181 (case-fold-search t))
4182 ;; Don't verify multiple headers.
4183 (setq headers (mapconcat (lambda (header)
4184 (concat header ": "
4185 (mail-fetch-field header)
4186 "\n"))
4187 (split-string (nth 1 items) ",") "")))
4188 (delete-region (point-min) (point-max))
4189 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4190 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4191 (insert headers)
4192 (widen)
4193 (forward-line)
4194 (while (not (eobp))
4195 (if (looking-at "^-")
4196 (insert "- "))
4197 (forward-line))
4198 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4199 (insert "Version: " (car items) "\n\n")
4200 (insert (mapconcat 'identity (cddr items) "\n"))
4201 (insert "\n-----END PGP SIGNATURE-----\n")
4202 (let ((mm-security-handle (list (format "multipart/signed"))))
4203 (mml2015-clean-buffer)
4204 (let ((coding-system-for-write (or gnus-newsgroup-charset
4205 'iso-8859-1)))
4206 (funcall (mml2015-clear-verify-function)))
4207 (setq info
4208 (or (mm-handle-multipart-ctl-parameter
4209 mm-security-handle 'gnus-details)
4210 (mm-handle-multipart-ctl-parameter
4211 mm-security-handle 'gnus-info)))))
4212 (when info
4213 (let ((inhibit-read-only t) bface eface)
4214 (save-restriction
4215 (message-narrow-to-head)
4216 (goto-char (point-max))
4217 (forward-line -1)
01c52d31
MB
4218 (setq bface (get-text-property (point-at-bol) 'face)
4219 eface (get-text-property (1- (point-at-eol)) 'face))
23f87bed
MB
4220 (message-remove-header "X-Gnus-PGP-Verify")
4221 (if (re-search-forward "^X-PGP-Sig:" nil t)
4222 (forward-line)
4223 (goto-char (point-max)))
4224 (narrow-to-region (point) (point))
4225 (insert "X-Gnus-PGP-Verify: " info "\n")
4226 (goto-char (point-min))
4227 (forward-line)
4228 (while (not (eobp))
4229 (if (not (looking-at "^[ \t]"))
4230 (insert " "))
4231 (forward-line))
4232 ;; Do highlighting.
4233 (goto-char (point-min))
4234 (when (looking-at "\\([^:]+\\): *")
4235 (put-text-property (match-beginning 1) (1+ (match-end 1))
4236 'face bface)
4237 (put-text-property (match-end 0) (point-max)
4238 'face eface)))))))))
4239
5843126b 4240(autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
ec7995fa 4241
23f87bed
MB
4242(defun article-verify-cancel-lock ()
4243 "Verify Cancel-Lock header."
4244 (interactive)
4245 (if (gnus-buffer-live-p gnus-original-article-buffer)
4246 (canlock-verify gnus-original-article-buffer)))
4247
eec82323 4248(eval-and-compile
01c52d31 4249 (mapc
eec82323
LMI
4250 (lambda (func)
4251 (let (afunc gfunc)
4252 (if (consp func)
4253 (setq afunc (car func)
4254 gfunc (cdr func))
4255 (setq afunc func
4256 gfunc (intern (format "gnus-%s" func))))
16409b0b 4257 (defalias gfunc
23f87bed 4258 (when (fboundp afunc)
16409b0b
GM
4259 `(lambda (&optional interactive &rest args)
4260 ,(documentation afunc t)
4261 (interactive (list t))
80de1778 4262 (with-current-buffer gnus-article-buffer
16409b0b
GM
4263 (if interactive
4264 (call-interactively ',afunc)
4265 (apply ',afunc args))))))))
eec82323 4266 '(article-hide-headers
23f87bed
MB
4267 article-verify-x-pgp-sig
4268 article-verify-cancel-lock
eec82323
LMI
4269 article-hide-boring-headers
4270 article-treat-overstrike
01c52d31 4271 article-treat-ansi-sequences
16409b0b
GM
4272 article-fill-long-lines
4273 article-capitalize-sentences
eec82323 4274 article-remove-cr
23f87bed 4275 article-remove-leading-whitespace
eec82323 4276 article-display-x-face
23f87bed 4277 article-display-face
eec82323 4278 article-de-quoted-unreadable
16409b0b
GM
4279 article-de-base64-unreadable
4280 article-decode-HZ
4281 article-wash-html
23f87bed 4282 article-unsplit-urls
16409b0b 4283 article-hide-list-identifiers
16409b0b
GM
4284 article-strip-banner
4285 article-babel
eec82323
LMI
4286 article-hide-pem
4287 article-hide-signature
16409b0b 4288 article-strip-headers-in-body
eec82323
LMI
4289 article-remove-trailing-blank-lines
4290 article-strip-leading-blank-lines
4291 article-strip-multiple-blank-lines
4292 article-strip-leading-space
16409b0b 4293 article-strip-trailing-space
eec82323 4294 article-strip-blank-lines
6748645f 4295 article-strip-all-blank-lines
eec82323 4296 article-date-local
23f87bed 4297 article-date-english
6748645f 4298 article-date-iso8601
eec82323 4299 article-date-original
12e3ca0a 4300 article-treat-date
eec82323 4301 article-date-ut
16409b0b
GM
4302 article-decode-mime-words
4303 article-decode-charset
4304 article-decode-encoded-words
eec82323
LMI
4305 article-date-user
4306 article-date-lapsed
647559c2 4307 article-date-combined-lapsed
eec82323 4308 article-emphasize
6748645f 4309 article-treat-dumbquotes
be3c11b3 4310 article-treat-non-ascii
16409b0b 4311 article-normalize-headers
01c52d31 4312 ;;(article-show-all . gnus-article-show-all-headers)
23f87bed 4313 )))
eec82323
LMI
4314\f
4315;;;
4316;;; Gnus article mode
4317;;;
4318
4319(put 'gnus-article-mode 'mode-class 'special)
4320
16409b0b
GM
4321(set-keymap-parent gnus-article-mode-map widget-keymap)
4322
a8151ef7
LMI
4323(gnus-define-keys gnus-article-mode-map
4324 " " gnus-article-goto-next-page
4325 "\177" gnus-article-goto-prev-page
4326 [delete] gnus-article-goto-prev-page
16409b0b 4327 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
4328 "\C-c^" gnus-article-refer-article
4329 "h" gnus-article-show-summary
4330 "s" gnus-article-show-summary
4331 "\C-c\C-m" gnus-article-mail
4332 "?" gnus-article-describe-briefly
a8151ef7
LMI
4333 "<" beginning-of-buffer
4334 ">" end-of-buffer
4335 "\C-c\C-i" gnus-info-find-node
4336 "\C-c\C-b" gnus-bug
23f87bed
MB
4337 "R" gnus-article-reply-with-original
4338 "F" gnus-article-followup-with-original
520aa572
SZ
4339 "\C-hk" gnus-article-describe-key
4340 "\C-hc" gnus-article-describe-key-briefly
0b6799c3 4341 "\C-hb" gnus-article-describe-bindings
a8151ef7 4342
6ab2c7a8 4343 "e" gnus-article-read-summary-keys
a8151ef7
LMI
4344 "\C-d" gnus-article-read-summary-keys
4345 "\M-*" gnus-article-read-summary-keys
4346 "\M-#" gnus-article-read-summary-keys
4347 "\M-^" gnus-article-read-summary-keys
4348 "\M-g" gnus-article-read-summary-keys)
4349
4350(substitute-key-definition
4351 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323 4352
95838435
MB
4353(gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4354 "W" gnus-article-wide-reply-with-original)
4355(if (featurep 'xemacs)
4356 (set-keymap-default-binding gnus-article-send-map
4357 'gnus-article-read-summary-send-keys)
4358 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4359
eec82323 4360(defun gnus-article-make-menu-bar ()
23f87bed
MB
4361 (unless (boundp 'gnus-article-commands-menu)
4362 (gnus-summary-make-menu-bar))
eec82323
LMI
4363 (unless (boundp 'gnus-article-article-menu)
4364 (easy-menu-define
4365 gnus-article-article-menu gnus-article-mode-map ""
4366 '("Article"
4367 ["Scroll forwards" gnus-article-goto-next-page t]
4368 ["Scroll backwards" gnus-article-goto-prev-page t]
4369 ["Show summary" gnus-article-show-summary t]
4370 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
4371 ["Mail to address at point" gnus-article-mail t]
4372 ["Send a bug report" gnus-bug t]))
eec82323
LMI
4373
4374 (easy-menu-define
4375 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 4376 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
4377 '("Treatment"
4378 ["Hide headers" gnus-article-hide-headers t]
4379 ["Hide signature" gnus-article-hide-signature t]
4380 ["Hide citation" gnus-article-hide-citation t]
4381 ["Treat overstrike" gnus-article-treat-overstrike t]
01c52d31 4382 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
eec82323 4383 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 4384 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
4385 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4386 ["Remove base64" gnus-article-de-base64-unreadable t]
4387 ["Treat html" gnus-article-wash-html t]
23f87bed 4388 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 4389 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 4390
6748645f 4391 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 4392
23f87bed 4393 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 4394
6748645f 4395 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323 4396
8e7d4ca1
GM
4397(defvar bookmark-make-record-function)
4398
eec82323
LMI
4399(defun gnus-article-mode ()
4400 "Major mode for displaying an article.
4401
4402All normal editing commands are switched off.
4403
4404The following commands are available in addition to all summary mode
4405commands:
4406\\<gnus-article-mode-map>
4407\\[gnus-article-next-page]\t Scroll the article one page forwards
4408\\[gnus-article-prev-page]\t Scroll the article one page backwards
4409\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4410\\[gnus-article-show-summary]\t Display the summary buffer
4411\\[gnus-article-mail]\t Send a reply to the address near point
4412\\[gnus-article-describe-briefly]\t Describe the current mode briefly
4413\\[gnus-info-find-node]\t Go to the Gnus info node"
4414 (interactive)
0eb586fc 4415 (kill-all-local-variables)
eec82323
LMI
4416 (gnus-simplify-mode-line)
4417 (setq mode-name "Article")
4418 (setq major-mode 'gnus-article-mode)
4419 (make-local-variable 'minor-mode-alist)
eec82323 4420 (use-local-map gnus-article-mode-map)
1653df0f 4421 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
4422 (gnus-article-make-menu-bar)
4423 (when gnus-summary-tool-bar-map
4424 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
4425 (gnus-update-format-specifications nil 'article-mode)
4426 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 4427 (set (make-local-variable 'gnus-page-broken) nil)
6748645f 4428 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
4429 (make-local-variable 'gnus-article-mime-handles)
4430 (make-local-variable 'gnus-article-decoded-p)
4431 (make-local-variable 'gnus-article-mime-handle-alist)
4432 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
4433 (make-local-variable 'gnus-article-image-alist)
4434 (make-local-variable 'gnus-article-charset)
4435 (make-local-variable 'gnus-article-ignored-charsets)
33b48483
KF
4436 (set (make-local-variable 'bookmark-make-record-function)
4437 'gnus-summary-bookmark-make-record)
524705ae
MB
4438 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4439 ;; face.
fc1c32c1 4440 (set (make-local-variable 'nobreak-char-display) nil)
e4a89ccf 4441 (setq cursor-in-non-selected-windows nil)
eec82323 4442 (gnus-set-default-directory)
16409b0b 4443 (buffer-disable-undo)
01c52d31
MB
4444 (setq buffer-read-only t
4445 show-trailing-whitespace nil)
eec82323 4446 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 4447 (mm-enable-multibyte)
cfcd5c91 4448 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323
LMI
4449
4450(defun gnus-article-setup-buffer ()
4451 "Initialize the article buffer."
4452 (let* ((name (if gnus-single-article-buffer "*Article*"
4453 (concat "*Article " gnus-newsgroup-name "*")))
4454 (original
4455 (progn (string-match "\\*Article" name)
4456 (concat " *Original Article"
4457 (substring name (match-end 0))))))
4458 (setq gnus-article-buffer name)
4459 (setq gnus-original-article-buffer original)
16409b0b 4460 (setq gnus-article-mime-handle-alist nil)
01c52d31
MB
4461 (with-current-buffer gnus-summary-buffer
4462 ;; This might be a variable local to the summary buffer.
4463 (unless gnus-single-article-buffer
eec82323
LMI
4464 (setq gnus-article-buffer name)
4465 (setq gnus-original-article-buffer original)
4466 (gnus-set-global-variables)))
16409b0b 4467 (gnus-article-setup-highlight-words)
eec82323 4468 ;; Init original article buffer.
80de1778 4469 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
16409b0b 4470 (mm-enable-multibyte)
eec82323 4471 (setq major-mode 'gnus-original-article-mode)
eec82323 4472 (make-local-variable 'gnus-original-article))
aba1948a
MB
4473 (if (and (get-buffer name)
4474 (with-current-buffer name
4475 (if gnus-article-edit-mode
4476 (if (y-or-n-p "Article mode edit in progress; discard? ")
4477 (progn
4478 (set-buffer-modified-p nil)
4479 (gnus-kill-buffer name)
4480 (message "")
4481 nil)
4482 (error "Action aborted"))
4483 t)))
80de1778 4484 (with-current-buffer name
23f87bed 4485 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
4486 (when gnus-article-mime-handles
4487 (mm-destroy-parts gnus-article-mime-handles)
4488 (setq gnus-article-mime-handles nil))
4489 ;; Set it to nil in article-buffer!
a1506d29 4490 (setq gnus-article-mime-handle-alist nil)
16409b0b 4491 (buffer-disable-undo)
eec82323 4492 (setq buffer-read-only t)
eec82323
LMI
4493 (unless (eq major-mode 'gnus-article-mode)
4494 (gnus-article-mode))
030158f3 4495 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4496 (current-buffer))
80de1778 4497 (with-current-buffer (gnus-get-buffer-create name)
eec82323 4498 (gnus-article-mode)
030158f3 4499 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4500 (make-local-variable 'gnus-summary-buffer)
01c52d31
MB
4501 (setq gnus-summary-buffer
4502 (gnus-summary-buffer-name gnus-newsgroup-name))
16409b0b 4503 (gnus-summary-set-local-parameters gnus-newsgroup-name)
12e3ca0a 4504 (when (and gnus-article-update-date-headers
647559c2 4505 (not article-lapsed-timer))
12e3ca0a 4506 (gnus-start-date-timer gnus-article-update-date-headers))
eec82323
LMI
4507 (current-buffer)))))
4508
4509;; Set article window start at LINE, where LINE is the number of lines
4510;; from the head of the article.
4511(defun gnus-article-set-window-start (&optional line)
01c52d31
MB
4512 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4513 (when article-window
4514 (set-window-start
4515 article-window
80de1778 4516 (with-current-buffer gnus-article-buffer
01c52d31
MB
4517 (goto-char (point-min))
4518 (if (not line)
4519 (point-min)
4520 (gnus-message 6 "Moved to bookmark")
4521 (search-forward "\n\n" nil t)
4522 (forward-line line)
4523 (point)))))))
eec82323
LMI
4524
4525(defun gnus-article-prepare (article &optional all-headers header)
4526 "Prepare ARTICLE in article mode buffer.
4527ARTICLE should either be an article number or a Message-ID.
4528If ARTICLE is an id, HEADER should be the article headers.
4529If ALL-HEADERS is non-nil, no headers are hidden."
4530 (save-excursion
4531 ;; Make sure we start in a summary buffer.
4532 (unless (eq major-mode 'gnus-summary-mode)
4533 (set-buffer gnus-summary-buffer))
4534 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
4535 (let* ((gnus-article (if header (mail-header-number header) article))
4536 (summary-buffer (current-buffer))
6748645f 4537 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
4538 (group gnus-newsgroup-name)
4539 result)
4540 (save-excursion
4541 (gnus-article-setup-buffer)
4542 (set-buffer gnus-article-buffer)
4543 ;; Deactivate active regions.
4544 (when (and (boundp 'transient-mark-mode)
4545 transient-mark-mode)
4546 (setq mark-active nil))
4e7d0221 4547 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
4548 (gnus-request-article-this-buffer
4549 article group))))
4550 ;; There is no such article.
4551 (save-excursion
4552 (when (and (numberp article)
4553 (not (memq article gnus-newsgroup-sparse)))
4554 (setq gnus-article-current
4555 (cons gnus-newsgroup-name article))
4556 (set-buffer gnus-summary-buffer)
4557 (setq gnus-current-article article)
23f87bed
MB
4558 (if (and (memq article gnus-newsgroup-undownloaded)
4559 (not (gnus-online (gnus-find-method-for-group
4560 gnus-newsgroup-name))))
6748645f
LMI
4561 (progn
4562 (gnus-summary-set-agent-mark article)
4563 (message "Message marked for downloading"))
4564 (gnus-summary-mark-article article gnus-canceled-mark)
4565 (unless (memq article gnus-newsgroup-sparse)
16409b0b 4566 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
4567 (if (or (eq result 'pseudo)
4568 (eq result 'nneething))
eec82323 4569 (progn
80de1778 4570 (with-current-buffer summary-buffer
6748645f 4571 (push article gnus-newsgroup-history)
eec82323 4572 (setq gnus-last-article gnus-current-article
eec82323
LMI
4573 gnus-current-article 0
4574 gnus-current-headers nil
4575 gnus-article-current nil)
4576 (if (eq result 'nneething)
4577 (gnus-configure-windows 'summary)
4578 (gnus-configure-windows 'article))
4579 (gnus-set-global-variables))
16409b0b
GM
4580 (let ((gnus-article-mime-handle-alist-1
4581 gnus-article-mime-handle-alist))
4582 (gnus-set-mode-line 'article)))
eec82323
LMI
4583 ;; The result from the `request' was an actual article -
4584 ;; or at least some text that is now displayed in the
4585 ;; article buffer.
4586 (when (and (numberp article)
4587 (not (eq article gnus-current-article)))
4588 ;; Seems like a new article has been selected.
4589 ;; `gnus-current-article' must be an article number.
80de1778 4590 (with-current-buffer summary-buffer
6748645f 4591 (push article gnus-newsgroup-history)
eec82323 4592 (setq gnus-last-article gnus-current-article
eec82323
LMI
4593 gnus-current-article article
4594 gnus-current-headers
4595 (gnus-summary-article-header gnus-current-article)
4596 gnus-article-current
4597 (cons gnus-newsgroup-name gnus-current-article))
4598 (unless (vectorp gnus-current-headers)
4599 (setq gnus-current-headers nil))
6748645f
LMI
4600 (gnus-summary-goto-subject gnus-current-article)
4601 (when (gnus-summary-show-thread)
4602 ;; If the summary buffer really was folded, the
4603 ;; previous goto may not actually have gone to
4604 ;; the right article, but the thread root instead.
4605 ;; So we go again.
4606 (gnus-summary-goto-subject gnus-current-article))
4607 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
4608 (gnus-set-mode-line 'summary)
4609 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 4610 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 4611 ;; Set the global newsgroup variables here.
eec82323
LMI
4612 (gnus-set-global-variables)
4613 (setq gnus-have-all-headers
6748645f 4614 (or all-headers gnus-show-all-headers))))
e0bad764
DL
4615 (save-excursion
4616 (gnus-configure-windows 'article))
eec82323
LMI
4617 (when (or (numberp article)
4618 (stringp article))
16409b0b 4619 (gnus-article-prepare-display)
eec82323
LMI
4620 ;; Do page break.
4621 (goto-char (point-min))
23f87bed
MB
4622 (when gnus-break-pages
4623 (gnus-narrow-to-page)))
16409b0b
GM
4624 (let ((gnus-article-mime-handle-alist-1
4625 gnus-article-mime-handle-alist))
4626 (gnus-set-mode-line 'article))
4627 (article-goto-body)
23f87bed
MB
4628 (unless (bobp)
4629 (forward-line -1))
6748645f 4630 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 4631 (gnus-configure-windows 'article)
eec82323
LMI
4632 t))))))
4633
16409b0b
GM
4634;;;###autoload
4635(defun gnus-article-prepare-display ()
4636 "Make the current buffer look like a nice article."
4637 ;; Hooks for getting information from the article.
4638 ;; This hook must be called before being narrowed.
4639 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
4640 buffer-read-only
4641 (inhibit-read-only t))
16409b0b
GM
4642 (unless (eq major-mode 'gnus-article-mode)
4643 (gnus-article-mode))
4644 (setq buffer-read-only nil
23f87bed
MB
4645 gnus-article-wash-types nil
4646 gnus-article-image-alist nil)
16409b0b
GM
4647 (gnus-run-hooks 'gnus-tmp-internal-hook)
4648 (when gnus-display-mime-function
4649 (funcall gnus-display-mime-function))
4650 (gnus-run-hooks 'gnus-article-prepare-hook)))
4651
01c52d31
MB
4652;;;
4653;;; Gnus Sticky Article Mode
4654;;;
4655
4656(define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4657 "Mode for sticky articles."
4658 ;; Release bindings that won't work.
4659 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4660 gnus-sticky-article-mode-map)
4661 (substitute-key-definition 'gnus-article-refer-article 'undefined
4662 gnus-sticky-article-mode-map)
4663 (dolist (k '("e" "h" "s" "F" "R"))
4664 (define-key gnus-sticky-article-mode-map k nil))
4665 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4666 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4667 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4668 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4669
4670(defun gnus-sticky-article (arg)
4671 "Make the current article sticky.
4672If a prefix ARG is given, ask for a name for this sticky article buffer."
4673 (interactive "P")
4674 (gnus-summary-show-thread)
4675 (gnus-summary-select-article nil nil 'pseudo)
4676 (let (new-art-buf-name)
4677 (gnus-eval-in-buffer-window gnus-article-buffer
4678 (setq new-art-buf-name
4679 (concat
4680 "*Sticky Article: "
4681 (if arg
4682 (read-from-minibuffer "Sticky article buffer name: ")
4683 (gnus-with-article-headers
4684 (gnus-article-goto-header "subject")
4685 (setq new-art-buf-name
4686 (buffer-substring-no-properties
4687 (line-beginning-position) (line-end-position)))
4688 (goto-char (point-min))
4689 (gnus-article-goto-header "from")
4690 (setq new-art-buf-name
4691 (concat
4692 new-art-buf-name ", "
4693 (buffer-substring-no-properties
4694 (line-beginning-position) (line-end-position))))
4695 (goto-char (point-min))
4696 (gnus-article-goto-header "date")
4697 (setq new-art-buf-name
4698 (concat
4699 new-art-buf-name ", "
4700 (buffer-substring-no-properties
4701 (line-beginning-position) (line-end-position))))))
4702 "*"))
4703 (if (and (gnus-buffer-live-p new-art-buf-name)
4704 (with-current-buffer new-art-buf-name
4705 (eq major-mode 'gnus-sticky-article-mode)))
4706 (switch-to-buffer new-art-buf-name)
4707 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4708 (gnus-sticky-article-mode))
4709 (setq gnus-article-buffer new-art-buf-name))
4710 (gnus-summary-recenter)
4711 (gnus-summary-position-point))
4712
4713(defun gnus-kill-sticky-article-buffer (&optional buffer)
4714 "Kill the given sticky article BUFFER.
4715If none is given, assume the current buffer and kill it if it has
4716`gnus-sticky-article-mode'."
4717 (interactive)
4718 (unless buffer
4719 (setq buffer (current-buffer)))
4720 (with-current-buffer buffer
4721 (when (eq major-mode 'gnus-sticky-article-mode)
4722 (gnus-kill-buffer buffer))))
4723
4724(defun gnus-kill-sticky-article-buffers (arg)
4725 "Kill all sticky article buffers.
4726If a prefix ARG is given, ask for confirmation."
4727 (interactive "P")
4728 (dolist (buf (gnus-buffers))
4729 (with-current-buffer buf
4730 (when (eq major-mode 'gnus-sticky-article-mode)
4731 (if (not arg)
4732 (gnus-kill-buffer buf)
4733 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4734 (gnus-kill-buffer buf)))))))
4735
16409b0b
GM
4736;;;
4737;;; Gnus MIME viewing functions
4738;;;
4739
4740(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
4741 "Format of the MIME buttons.
4742
4743Valid specifiers include:
16409b0b
GM
4744%t The MIME type
4745%T MIME type, along with additional info
4746%n The `name' parameter
4747%d The description, if any
4748%l The length of the encoded part
4749%p The part identifier number
23f87bed
MB
4750%e Dots if the part isn't displayed
4751
4752General format specifiers can also be used. See Info node
4753`(gnus)Formatting Variables'.")
16409b0b
GM
4754
4755(defvar gnus-mime-button-line-format-alist
4756 '((?t gnus-tmp-type ?s)
4757 (?T gnus-tmp-type-long ?s)
4758 (?n gnus-tmp-name ?s)
4759 (?d gnus-tmp-description ?s)
4760 (?p gnus-tmp-id ?s)
4761 (?l gnus-tmp-length ?d)
4762 (?e gnus-tmp-dots ?s)))
4763
4764(defvar gnus-mime-button-commands
4765 '((gnus-article-press-button "\r" "Toggle Display")
4766 (gnus-mime-view-part "v" "View Interactively...")
4767 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4768 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4769 (gnus-mime-save-part "o" "Save...")
23f87bed 4770 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
01c52d31 4771 (gnus-mime-replace-part "r" "Replace part")
23f87bed 4772 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4773 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4774 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
01c52d31 4775 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
23f87bed
MB
4776 (gnus-mime-view-part-externally "e" "View Externally")
4777 (gnus-mime-print-part "p" "Print")
e0bad764 4778 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4779 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4780
4781(defun gnus-article-mime-part-status ()
4782 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4783 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4784 " (1 part)"
4785 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4786 ""))
4787
4788(defvar gnus-mime-button-map
4789 (let ((map (make-sparse-keymap)))
16409b0b
GM
4790 (define-key map gnus-mouse-2 'gnus-article-push-button)
4791 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4792 (dolist (c gnus-mime-button-commands)
4793 (define-key map (cadr c) (car c)))
4794 map))
4795
23f87bed
MB
4796(easy-menu-define
4797 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4798 `("MIME Part"
4799 ,@(mapcar (lambda (c)
01c52d31 4800 (vector (caddr c) (car c) :active t))
23f87bed
MB
4801 gnus-mime-button-commands)))
4802
7426b4f7
LMI
4803(defvar gnus-url-button-commands
4804 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4805
4806(defvar gnus-url-button-map
4807 (let ((map (make-sparse-keymap)))
4808 (dolist (c gnus-url-button-commands)
4809 (define-key map (cadr c) (car c)))
4810 map))
4811
4812(easy-menu-define
4813 gnus-url-button-menu gnus-url-button-map "URL button menu."
4814 `("Url Button"
4815 ,@(mapcar (lambda (c)
4816 (vector (caddr c) (car c) :active t))
4817 gnus-url-button-commands)))
4818
b0b63450
MB
4819(defmacro gnus-bind-safe-url-regexp (&rest body)
4820 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4821 `(let ((mm-w3m-safe-url-regexp
4822 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4823 (gnus-buffer-live-p
4824 gnus-article-current-summary))
4825 (with-current-buffer gnus-article-current-summary
4826 gnus-newsgroup-name)
4827 gnus-newsgroup-name)))
7cab80f9
KY
4828 (if (cond ((not group)
4829 ;; Maybe we're in a mml-preview buffer
4830 ;; and no group is selected.
4831 t)
4832 ((stringp gnus-safe-html-newsgroups)
b0b63450
MB
4833 (string-match gnus-safe-html-newsgroups group))
4834 ((consp gnus-safe-html-newsgroups)
4835 (member group gnus-safe-html-newsgroups)))
4836 nil
4837 mm-w3m-safe-url-regexp))))
4838 ,@body))
4839
23f87bed
MB
4840(defun gnus-mime-button-menu (event prefix)
4841 "Construct a context-sensitive menu of MIME commands."
4842 (interactive "e\nP")
4843 (save-window-excursion
4844 (let ((pos (event-start event)))
4845 (select-window (posn-window pos))
4846 (goto-char (posn-point pos))
4847 (gnus-article-check-buffer)
4848 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4849
4850(defun gnus-mime-view-all-parts (&optional handles)
4851 "View all the MIME parts."
4852 (interactive)
01c52d31 4853 (with-current-buffer gnus-article-buffer
16409b0b
GM
4854 (let ((handles (or handles gnus-article-mime-handles))
4855 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4856 (mail-parse-ignored-charsets
23f87bed
MB
4857 (with-current-buffer gnus-summary-buffer
4858 gnus-newsgroup-ignored-charsets)))
4859 (when handles
4860 (mm-remove-parts handles)
4861 (goto-char (point-min))
4862 (or (search-forward "\n\n") (goto-char (point-max)))
4863 (let ((inhibit-read-only t))
4864 (delete-region (point) (point-max))
b0b63450 4865 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
23f87bed 4866
01c52d31
MB
4867(defun gnus-article-jump-to-part (n)
4868 "Jump to MIME part N."
4869 (interactive "P")
a87ee50b
KY
4870 (let ((parts (with-current-buffer gnus-article-buffer
4871 (length gnus-article-mime-handle-alist))))
4872 (when (zerop parts)
4873 (error "No such part"))
4874 (pop-to-buffer gnus-article-buffer)
4875 ;; FIXME: why is it necessary?
4876 (sit-for 0)
4877 (or n
4878 (setq n (if (= parts 1)
4879 1
4880 (read-number (format "Jump to part (1..%s): " parts)))))
01c52d31
MB
4881 (unless (and (integerp n) (<= n parts) (>= n 1))
4882 (setq n
4883 (progn
4884 (gnus-message 7 "Invalid part `%s', using %s instead."
4885 n parts)
4886 parts)))
4887 (gnus-message 9 "Jumping to part %s." n)
4888 (cond ((>= gnus-auto-select-part 1)
4889 (while (and (<= n parts)
4890 (not (gnus-article-goto-part n)))
4891 (setq n (1+ n))))
4892 ((< gnus-auto-select-part 0)
4893 (while (and (>= n 1)
4894 (not (gnus-article-goto-part n)))
4895 (setq n (1- n))))
4896 (t
4897 (gnus-article-goto-part n)))))
4898
3e3ab3ab
KY
4899(defvar gnus-mime-buttonized-part-id nil
4900 "ID of a mime part that should be buttonized.
4901`gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4902
01c52d31
MB
4903(eval-when-compile
4904 (defsubst gnus-article-edit-part (handles &optional current-id)
4905 "Edit an article in order to delete a mime part.
4906This function is exclusively used by `gnus-mime-save-part-and-strip'
4907and `gnus-mime-delete-part', and not provided at run-time normally."
4908 (gnus-article-edit-article
4909 `(lambda ()
4910 (buffer-disable-undo)
4911 (erase-buffer)
4912 (let ((mail-parse-charset (or gnus-article-charset
4913 ',gnus-newsgroup-charset))
4914 (mail-parse-ignored-charsets
4915 (or gnus-article-ignored-charsets
4916 ',gnus-newsgroup-ignored-charsets))
4917 (mbl mml-buffer-list))
4918 (setq mml-buffer-list nil)
4919 (insert-buffer-substring gnus-original-article-buffer)
4920 (mime-to-mml ',handles)
4921 (setq gnus-article-mime-handles nil)
4922 (let ((mbl1 mml-buffer-list))
4923 (setq mml-buffer-list mbl)
4924 (set (make-local-variable 'mml-buffer-list) mbl1))
4925 (gnus-make-local-hook 'kill-buffer-hook)
4926 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4927 `(lambda (no-highlight)
4928 (let ((mail-parse-charset (or gnus-article-charset
4929 ',gnus-newsgroup-charset))
4930 (message-options message-options)
4931 (message-options-set-recipient)
4932 (mail-parse-ignored-charsets
4933 (or gnus-article-ignored-charsets
4934 ',gnus-newsgroup-ignored-charsets)))
4935 (mml-to-mime)
4936 (mml-destroy-buffers)
4937 (remove-hook 'kill-buffer-hook
4938 'mml-destroy-buffers t)
4939 (kill-local-variable 'mml-buffer-list))
4940 (gnus-summary-edit-article-done
4941 ,(or (mail-header-references gnus-current-headers) "")
4942 ,(gnus-group-read-only-p)
4943 ,gnus-summary-buffer no-highlight))
4944 t)
3e3ab3ab
KY
4945 ;; Force buttonizing this part.
4946 (let ((gnus-mime-buttonized-part-id current-id))
4947 (gnus-article-edit-done))
54c72c31 4948 (gnus-configure-windows 'article)
01c52d31 4949 (when (and current-id (integerp gnus-auto-select-part))
3e3ab3ab
KY
4950 (gnus-article-jump-to-part
4951 (min (max (+ current-id gnus-auto-select-part) 1)
4952 (with-current-buffer gnus-article-buffer
4953 (length gnus-article-mime-handle-alist)))))))
01c52d31
MB
4954
4955(defun gnus-mime-replace-part (file)
4956 "Replace MIME part under point with an external body."
4957 ;; Useful if file has already been saved to disk
4958 (interactive
4959 (list
75eda25b
SM
4960 (read-file-name "Replace MIME part with file: "
4961 (or mm-default-directory default-directory)
4962 nil nil)))
01c52d31
MB
4963 (gnus-mime-save-part-and-strip file))
4964
4965(defun gnus-mime-save-part-and-strip (&optional file)
4966 "Save the MIME part under point then replace it with an external body.
4967If FILE is given, use it for the external part."
23f87bed
MB
4968 (interactive)
4969 (gnus-article-check-buffer)
4970 (when (gnus-group-read-only-p)
4971 (error "The current group does not support deleting of parts"))
4972 (when (mm-complicated-handles gnus-article-mime-handles)
4973 (error "\
4974The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4975 (let* ((data (get-text-property (point) 'gnus-data))
4976 (id (get-text-property (point) 'gnus-part))
4977 param
4978 (handles gnus-article-mime-handles))
4979 (unless file
4980 (setq file
4981 (and data (mm-save-part data "Delete MIME part and save to: "))))
4982 (when file
4983 (with-current-buffer (mm-handle-buffer data)
4984 (erase-buffer)
4985 (insert "Content-Type: " (mm-handle-media-type data))
4986 (mml-insert-parameter-string (cdr (mm-handle-type data))
4987 '(charset))
4988 ;; Add a filename for the sake of saving the part again.
4989 (mml-insert-parameter
4990 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4991 (insert "\n")
4992 (insert "Content-ID: " (message-make-message-id) "\n")
4993 (insert "Content-Transfer-Encoding: binary\n")
4994 (insert "\n"))
4995 (setcdr data
4996 (cdr (mm-make-handle nil
4997 `("message/external-body"
4998 (access-type . "LOCAL-FILE")
4999 (name . ,file)))))
5000 ;; (set-buffer gnus-summary-buffer)
5001 (gnus-article-edit-part handles id))))
5002
5003;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5004;; parts...>') but with stripping would be nice.
23f87bed
MB
5005
5006(defun gnus-mime-delete-part ()
5007 "Delete the MIME part under point.
5008Replace it with some information about the removed part."
5009 (interactive)
5010 (gnus-article-check-buffer)
5011 (when (gnus-group-read-only-p)
5012 (error "The current group does not support deleting of parts"))
5013 (when (mm-complicated-handles gnus-article-mime-handles)
5014 (error "\
5015The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
5016 (when (or gnus-expert-user
5017 (gnus-yes-or-no-p "\
5018Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 5019 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 5020 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
5021 (handles gnus-article-mime-handles)
5022 (none "(none)")
5023 (description
bbbe940b
MB
5024 (let ((desc (mm-handle-description data)))
5025 (when desc
5026 (mail-decode-encoded-word-string desc))))
23f87bed
MB
5027 (filename
5028 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5029 none))
5030 (type (mm-handle-media-type data)))
5031 (unless data
5032 (error "No MIME part under point"))
5033 (with-current-buffer (mm-handle-buffer data)
e5fa3899 5034 (let ((bsize (buffer-size)))
23f87bed
MB
5035 (erase-buffer)
5036 (insert
5037 (concat
5038 ",----\n"
5039 "| The following attachment has been deleted:\n"
5040 "|\n"
5041 "| Type: " type "\n"
5042 "| Filename: " filename "\n"
e5fa3899
KY
5043 "| Size (encoded): " (format "%s byte%s\n"
5044 bsize (if (= bsize 1)
8ccbef23
G
5045 ""
5046 "s"))
bbbe940b
MB
5047 (when description
5048 (concat "| Description: " description "\n"))
23f87bed
MB
5049 "`----\n"))
5050 (setcdr data
5051 (cdr (mm-make-handle
0cf681b6 5052 nil `("text/plain" (charset . gnus-decoded)) nil nil
23f87bed
MB
5053 (list "attachment")
5054 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
5055 ;; (set-buffer gnus-summary-buffer)
5056 (gnus-article-edit-part handles id))))
16409b0b
GM
5057
5058(defun gnus-mime-save-part ()
5059 "Save the MIME part under point."
5060 (interactive)
5061 (gnus-article-check-buffer)
5062 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5063 (when data
5064 (mm-save-part data))))
16409b0b 5065
9581ba4d
KY
5066(defun gnus-mime-pipe-part (&optional cmd)
5067 "Pipe the MIME part under point to a process.
5068Use CMD as the process."
16409b0b
GM
5069 (interactive)
5070 (gnus-article-check-buffer)
5071 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed 5072 (when data
9581ba4d 5073 (mm-pipe-part data cmd))))
16409b0b
GM
5074
5075(defun gnus-mime-view-part ()
5076 "Interactively choose a viewing method for the MIME part under point."
5077 (interactive)
5078 (gnus-article-check-buffer)
5079 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5080 (when data
5081 (setq gnus-article-mime-handles
5082 (mm-merge-handles
5083 gnus-article-mime-handles (setq data (copy-sequence data))))
5084 (mm-interactively-view-part data))))
16409b0b
GM
5085
5086(defun gnus-mime-view-part-as-type-internal ()
5087 (gnus-article-check-buffer)
54e573e6
MB
5088 (let* ((handle (get-text-property (point) 'gnus-data))
5089 (name (or
5090 ;; Content-Type: foo/bar; name=...
5091 (mail-content-type-get (mm-handle-type handle) 'name)
5092 ;; Content-Disposition: attachment; filename=...
5093 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 5094 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
5095 (or (and def-type (cons def-type 0))
5096 (and handle
5097 (equal (mm-handle-media-supertype handle) "text")
5098 '("text/plain" . 0))
5099 '("application/octet-stream" . 0))))
16409b0b 5100
54e573e6
MB
5101(defun gnus-mime-view-part-as-type (&optional mime-type pred)
5102 "Choose a MIME media type, and view the part as such.
5103If non-nil, PRED is a predicate to use during completion to limit the
5104available media-types."
23f87bed
MB
5105 (interactive)
5106 (unless mime-type
54e573e6
MB
5107 (setq mime-type
5108 (let ((default (gnus-mime-view-part-as-type-internal)))
229b59da
G
5109 (gnus-completing-read
5110 "View as MIME type"
568f71a8
KY
5111 (if pred
5112 (gnus-remove-if-not pred (mailcap-mime-types))
5113 (mailcap-mime-types))
229b59da 5114 nil nil nil
54e573e6 5115 (car default)))))
16409b0b
GM
5116 (gnus-article-check-buffer)
5117 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 5118 (when handle
531bedc3
MB
5119 (when (equal (mm-handle-media-type handle) "message/external-body")
5120 (unless (mm-handle-cache handle)
5121 (mm-extern-cache-contents handle))
5122 (setq handle (mm-handle-cache handle)))
23f87bed
MB
5123 (setq handle
5124 (mm-make-handle (mm-handle-buffer handle)
5125 (cons mime-type (cdr (mm-handle-type handle)))
5126 (mm-handle-encoding handle)
5127 (mm-handle-undisplayer handle)
5128 (mm-handle-disposition handle)
5129 (mm-handle-description handle)
5130 nil
5131 (mm-handle-id handle)))
5132 (setq gnus-article-mime-handles
5133 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
5134 (when (mm-handle-displayed-p handle)
5135 (mm-remove-part handle))
23f87bed
MB
5136 (gnus-mm-display-part handle))))
5137
01c52d31 5138(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
5139 "Put the MIME part under point into a new buffer.
5140If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5141are decompressed."
01c52d31 5142 (interactive (list nil current-prefix-arg))
16409b0b 5143 (gnus-article-check-buffer)
01c52d31
MB
5144 (unless handle
5145 (setq handle (get-text-property (point) 'gnus-data)))
5146 (when handle
5147 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5148 'name)
5149 (mail-content-type-get (mm-handle-disposition handle)
5150 'filename)))
5151 contents dont-decode charset coding-system)
5152 (mm-with-unibyte-buffer
5153 (mm-insert-part handle)
5154 (setq contents (or (condition-case nil
5155 (mm-decompress-buffer filename nil 'sig)
5156 (error
5157 (setq dont-decode t)
5158 nil))
5159 (buffer-string))))
5160 (setq filename (cond (filename (file-name-nondirectory filename))
5161 (dont-decode "*raw data*")
5162 (t "*decoded*")))
5163 (cond
5164 (dont-decode)
5165 ((not arg)
5166 (unless (setq charset (mail-content-type-get
5167 (mm-handle-type handle) 'charset))
5168 (unless (setq coding-system (mm-with-unibyte-buffer
5169 (insert contents)
5170 (mm-find-buffer-file-coding-system)))
5171 (setq charset gnus-newsgroup-charset))))
5172 ((numberp arg)
5173 (setq charset (or (cdr (assq arg
5174 gnus-summary-show-article-charset-alist))
5175 (mm-read-coding-system "Charset: ")))))
5176 (switch-to-buffer (generate-new-buffer filename))
5177 (if (or coding-system
5178 (and charset
5179 (setq coding-system (mm-charset-to-coding-system charset))
a87ee50b 5180 (not (eq coding-system 'ascii))))
01c52d31
MB
5181 (progn
5182 (mm-enable-multibyte)
5183 (insert (mm-decode-coding-string contents coding-system))
5184 (setq buffer-file-coding-system
5185 (if (boundp 'last-coding-system-used)
5186 (symbol-value 'last-coding-system-used)
5187 coding-system)))
5188 (mm-disable-multibyte)
5189 (insert contents)
5190 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5191 ;; We do it this way to make `normal-mode' set the appropriate mode.
5192 (unwind-protect
5193 (progn
01c52d31 5194 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5195 (normal-mode))
5196 (setq buffer-file-name nil))
5197 (goto-char (point-min)))))
5198
5199(defun gnus-mime-print-part (&optional handle filename)
5200 "Print the MIME part under point."
5201 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5202 (gnus-article-check-buffer)
5203 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5204 (contents (and handle (mm-get-part handle)))
5205 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5206 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5207 (when contents
5208 (if printer
5209 (unwind-protect
5210 (progn
5211 (mm-save-part-to-file handle file)
5212 (call-process shell-file-name nil
5213 (generate-new-buffer " *mm*")
5214 nil
5215 shell-command-switch
5216 (mm-mailcap-command
5217 printer file (mm-handle-type handle))))
5218 (delete-file file))
5219 (with-temp-buffer
5220 (insert contents)
5221 (gnus-print-buffer))
5222 (ps-despool filename)))))
16409b0b 5223
e0bad764 5224(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5225 "Insert the MIME part under point into the current buffer.
5226Compressed files like .gz and .bz2 are decompressed."
e0bad764 5227 (interactive (list nil current-prefix-arg))
16409b0b 5228 (gnus-article-check-buffer)
01c52d31
MB
5229 (unless handle
5230 (setq handle (get-text-property (point) 'gnus-data)))
5231 (when handle
5232 (let ((b (point))
5233 (inhibit-read-only t)
5234 contents charset coding-system)
23f87bed
MB
5235 (if (and (not arg) (mm-handle-undisplayer handle))
5236 (mm-remove-part handle)
01c52d31
MB
5237 (mm-with-unibyte-buffer
5238 (mm-insert-part handle)
5239 (setq contents
5240 (or (mm-decompress-buffer
5241 (or (mail-content-type-get (mm-handle-type handle)
5242 'name)
5243 (mail-content-type-get (mm-handle-disposition handle)
5244 'filename))
5245 nil t)
5246 (buffer-string))))
23f87bed
MB
5247 (cond
5248 ((not arg)
01c52d31
MB
5249 (unless (setq charset (mail-content-type-get
5250 (mm-handle-type handle) 'charset))
5251 (unless (setq coding-system
5252 (mm-with-unibyte-buffer
5253 (insert contents)
5254 (mm-find-buffer-file-coding-system)))
5255 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5256 ((numberp arg)
5257 (if (mm-handle-undisplayer handle)
5258 (mm-remove-part handle))
5259 (setq charset
5260 (or (cdr (assq arg
5261 gnus-summary-show-article-charset-alist))
56c30d72
MB
5262 (mm-read-coding-system "Charset: "))))
5263 (t
5264 (if (mm-handle-undisplayer handle)
850c333d 5265 (mm-remove-part handle))))
23f87bed 5266 (forward-line 2)
6e3165fb 5267 (mm-display-inline handle)
23f87bed
MB
5268 (goto-char b)))))
5269
c0ccb0d6
KY
5270(defun gnus-mime-set-charset-parameters (handle charset)
5271 "Set CHARSET to parameters in HANDLE.
5272CHARSET may either be a string or a symbol."
5273 (unless (stringp charset)
5274 (setq charset (symbol-name charset)))
6b554e88 5275 (if (stringp (car handle))
c0ccb0d6
KY
5276 (dolist (h (cdr handle))
5277 (gnus-mime-set-charset-parameters h charset))
6b554e88
MB
5278 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5279 "message/external-body")
5280 (progn
5281 (unless (mm-handle-cache handle)
5282 (mm-extern-cache-contents handle))
5283 (mm-handle-cache handle))
5284 handle)))
c0ccb0d6
KY
5285 (param (assq 'charset (cdr type))))
5286 (if param
5287 (setcdr param charset)
5288 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
6b554e88 5289
23f87bed
MB
5290(defun gnus-mime-view-part-as-charset (&optional handle arg)
5291 "Insert the MIME part under point into the current buffer using the
5292specified charset."
5293 (interactive (list nil current-prefix-arg))
5294 (gnus-article-check-buffer)
163cb72d
MB
5295 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5296 (fun (get-text-property (point) 'gnus-callback))
5297 (gnus-newsgroup-ignored-charsets 'gnus-all)
c0ccb0d6 5298 charset form preferred parts)
23f87bed 5299 (when handle
01c52d31
MB
5300 (when (prog1
5301 (and fun
c0ccb0d6 5302 (setq charset
01c52d31
MB
5303 (or (cdr (assq
5304 arg
5305 gnus-summary-show-article-charset-alist))
5306 (mm-read-coding-system "Charset: "))))
5307 (if (mm-handle-undisplayer handle)
5308 (mm-remove-part handle)))
c0ccb0d6 5309 (gnus-mime-set-charset-parameters handle charset)
6b554e88
MB
5310 (when (and (consp (setq form (cdr-safe fun)))
5311 (setq form (ignore-errors
5312 (assq 'gnus-mime-display-alternative form)))
5313 (setq preferred (caddr form))
5314 (progn
5315 (when (eq (car preferred) 'quote)
5316 (setq preferred (cadr preferred)))
5317 (not (equal preferred
5318 (get-text-property (point) 'gnus-data))))
5319 (setq parts (get-text-property (point) 'gnus-part))
5320 (setq parts (cdr (assq parts
5321 gnus-article-mime-handle-alist)))
5322 (equal (mm-handle-media-type parts) "multipart/alternative")
5323 (setq parts (reverse (cdr parts))))
5324 (setcar (cddr form)
5325 (list 'quote (or (cadr (member preferred parts))
5326 (car parts)))))
163cb72d 5327 (funcall fun handle)))))
23f87bed
MB
5328
5329(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5330 "View the MIME part under point with an external viewer."
5331 (interactive)
5332 (gnus-article-check-buffer)
5333 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5334 (mm-user-display-methods nil)
5335 (mm-inlined-types nil)
5336 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5337 (mail-parse-ignored-charsets
54e573e6
MB
5338 (with-current-buffer gnus-summary-buffer
5339 gnus-newsgroup-ignored-charsets))
5340 (type (mm-handle-media-type handle))
5341 (method (mailcap-mime-info type))
5342 (mm-enable-external t))
5343 (if (not (stringp method))
5344 (gnus-mime-view-part-as-type
f7aa0b8f 5345 nil (lambda (type) (stringp (mailcap-mime-info type))))
54e573e6 5346 (when handle
a87ee50b 5347 (mm-display-part handle nil t)))))
16409b0b 5348
23f87bed 5349(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5350 "View the MIME part under point with an internal viewer.
23f87bed 5351If no internal viewer is available, use an external viewer."
16409b0b
GM
5352 (interactive)
5353 (gnus-article-check-buffer)
5354 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5355 (mm-inlined-types '(".*"))
5356 (mm-inline-large-images t)
5357 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5358 (mail-parse-ignored-charsets
54e573e6
MB
5359 (with-current-buffer gnus-summary-buffer
5360 gnus-newsgroup-ignored-charsets))
23f87bed 5361 (inhibit-read-only t))
54e573e6
MB
5362 (if (not (mm-inlinable-p handle))
5363 (gnus-mime-view-part-as-type
f7aa0b8f 5364 nil (lambda (type) (mm-inlinable-p handle type)))
54e573e6 5365 (when handle
a87ee50b 5366 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
16409b0b 5367
e0bad764
DL
5368(defun gnus-mime-action-on-part (&optional action)
5369 "Do something with the MIME attachment at \(point\)."
5370 (interactive
229b59da 5371 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
e0bad764
DL
5372 (gnus-article-check-buffer)
5373 (let ((action-pair (assoc action gnus-mime-action-alist)))
5374 (if action-pair
5375 (funcall (cdr action-pair)))))
5376
01c52d31
MB
5377(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5378 "Call FUNCTION on MIME part N.
5379Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5380If INTERACTIVE, call FUNCTION interactivly."
5381 (let (window frame)
5382 ;; Check whether the article is displayed.
5383 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5384 (setq window (get-buffer-window gnus-article-buffer t))
5385 (frame-visible-p (setq frame (window-frame window))))
5386 (error "No article is displayed"))
5387 (with-current-buffer gnus-article-buffer
5388 ;; Check whether the article displays the right contents.
5389 (unless (with-current-buffer gnus-summary-buffer
5390 (eq gnus-current-article (gnus-summary-article-number)))
5391 (error "You should select the right article first"))
5392 (if n
5393 (setq n (prefix-numeric-value n))
5394 (let ((pt (point)))
5395 (setq n (or (get-text-property pt 'gnus-part)
5396 (and (not (bobp))
5397 (get-text-property (1- pt) 'gnus-part))
5398 (get-text-property (prog2
5399 (forward-line 1)
5400 (point)
5401 (goto-char pt))
5402 'gnus-part)
5403 (get-text-property
5404 (or (and (setq pt (previous-single-property-change
5405 pt 'gnus-part))
5406 (1- pt))
5407 (next-single-property-change (point) 'gnus-part)
5408 (point))
5409 'gnus-part)
5410 1))))
5411 ;; Check whether the specified part exists.
5412 (when (> n (length gnus-article-mime-handle-alist))
5413 (error "No such part")))
5414 (unless
5415 (progn
5416 ;; To select the window is needed so that the cursor
5417 ;; might be visible on the MIME button.
5418 (select-window (prog1
5419 window
5420 (setq window (selected-window))
5421 ;; Article may be displayed in the other frame.
5422 (gnus-select-frame-set-input-focus
5423 (prog1
5424 frame
5425 (setq frame (selected-frame))))))
5426 (when (gnus-article-goto-part n)
5427 ;; We point the cursor and the arrow at the MIME button
5428 ;; when the `function' prompt the user for something.
a87ee50b
KY
5429 (unless (and (pos-visible-in-window-p)
5430 (> (count-lines (point) (window-end))
5431 (/ (1- (window-height)) 3)))
5432 (recenter (/ (1- (window-height)) 3)))
01c52d31
MB
5433 (let ((cursor-in-non-selected-windows t)
5434 (overlay-arrow-string "=>")
5435 (overlay-arrow-position (point-marker)))
5436 (unwind-protect
5437 (cond
5438 ((and no-handle interactive)
5439 (call-interactively function))
5440 (no-handle
5441 (funcall function))
5442 (interactive
5443 (call-interactively
a87ee50b 5444 function (get-text-property (point) 'gnus-data)))
01c52d31
MB
5445 (t
5446 (funcall function
a87ee50b 5447 (get-text-property (point) 'gnus-data))))
01c52d31
MB
5448 (set-marker overlay-arrow-position nil)
5449 (unless gnus-auto-select-part
5450 (gnus-select-frame-set-input-focus frame)
5451 (select-window window))))
5452 t))
5453 (if gnus-inhibit-mime-unbuttonizing
5454 ;; This is the default though the program shouldn't reach here.
5455 (error "No such part")
5456 ;; The part which doesn't have the MIME button is selected.
5457 ;; So, we display all the buttons and redo it.
5458 (let ((gnus-inhibit-mime-unbuttonizing t))
5459 (gnus-summary-show-article)
5460 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5461
5462(defun gnus-article-pipe-part (n)
5463 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5464 (interactive "P")
16409b0b
GM
5465 (gnus-article-part-wrapper n 'mm-pipe-part))
5466
5467(defun gnus-article-save-part (n)
5468 "Save MIME part N, which is the numerical prefix."
01c52d31 5469 (interactive "P")
16409b0b
GM
5470 (gnus-article-part-wrapper n 'mm-save-part))
5471
5472(defun gnus-article-interactively-view-part (n)
5473 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5474 (interactive "P")
16409b0b
GM
5475 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5476
5477(defun gnus-article-copy-part (n)
5478 "Copy MIME part N, which is the numerical prefix."
01c52d31 5479 (interactive "P")
16409b0b
GM
5480 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5481
23f87bed
MB
5482(defun gnus-article-view-part-as-charset (n)
5483 "View MIME part N using a specified charset.
5484N is the numerical prefix."
01c52d31 5485 (interactive "P")
23f87bed
MB
5486 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5487
5488(defun gnus-article-view-part-externally (n)
16409b0b 5489 "View MIME part N externally, which is the numerical prefix."
01c52d31 5490 (interactive "P")
23f87bed 5491 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5492
5493(defun gnus-article-inline-part (n)
5494 "Inline MIME part N, which is the numerical prefix."
01c52d31 5495 (interactive "P")
16409b0b
GM
5496 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5497
01c52d31
MB
5498(defun gnus-article-save-part-and-strip (n)
5499 "Save MIME part N and replace it with an external body.
5500N is the numerical prefix."
5501 (interactive "P")
5502 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5503
5504(defun gnus-article-replace-part (n)
5505 "Replace MIME part N with an external body.
5506N is the numerical prefix."
5507 (interactive "P")
5508 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5509
5510(defun gnus-article-delete-part (n)
5511 "Delete MIME part N and add some information about the removed part.
5512N is the numerical prefix."
5513 (interactive "P")
5514 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5515
5516(defun gnus-article-view-part-as-type (n)
5517 "Choose a MIME media type, and view part N as such.
5518N is the numerical prefix."
5519 (interactive "P")
5520 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5521
16409b0b
GM
5522(defun gnus-article-mime-match-handle-first (condition)
5523 (if condition
01c52d31
MB
5524 (let (n)
5525 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5526 (if (and (cond
16409b0b
GM
5527 ((functionp condition)
5528 (funcall condition (cdr ihandle)))
a1506d29 5529 ((eq condition 'undisplayed)
16409b0b
GM
5530 (not (or (mm-handle-undisplayer (cdr ihandle))
5531 (equal (mm-handle-media-type (cdr ihandle))
5532 "multipart/alternative"))))
5533 ((eq condition 'undisplayed-alternative)
5534 (not (mm-handle-undisplayer (cdr ihandle))))
5535 (t t))
5536 (gnus-article-goto-part (car ihandle))
5537 (or (not n) (< (car ihandle) n)))
5538 (setq n (car ihandle))))
5539 (or n 1))
5540 1))
5541
5542(defun gnus-article-view-part (&optional n)
47fe149b
KY
5543 "View MIME part N, which is the numerical prefix.
5544If the part is already shown, hide the part. If N is nil, view
5545all parts."
16409b0b 5546 (interactive "P")
01c52d31 5547 (with-current-buffer gnus-article-buffer
a1506d29 5548 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5549 gnus-article-mime-match-handle-function)))
5550 (when (> n (length gnus-article-mime-handle-alist))
5551 (error "No such part"))
5552 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5553 (when (gnus-article-goto-part n)
5554 (if (equal (car handle) "multipart/alternative")
5555 (gnus-article-press-button)
5556 (when (eq (gnus-mm-display-part handle) 'internal)
5557 (gnus-set-window-start)))))))
5558
e0bad764
DL
5559(defsubst gnus-article-mime-total-parts ()
5560 (if (bufferp (car gnus-article-mime-handles))
5561 1 ;; single part
5562 (1- (length gnus-article-mime-handles))))
5563
16409b0b
GM
5564(defun gnus-mm-display-part (handle)
5565 "Display HANDLE and fix MIME button."
5566 (let ((id (get-text-property (point) 'gnus-part))
5567 (point (point))
23f87bed 5568 (inhibit-read-only t))
16409b0b
GM
5569 (forward-line 1)
5570 (prog1
5571 (let ((window (selected-window))
5572 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5573 (mail-parse-ignored-charsets
23f87bed 5574 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5575 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5576 gnus-newsgroup-ignored-charsets)
5577 nil)))
16409b0b
GM
5578 (save-excursion
5579 (unwind-protect
23f87bed 5580 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5581 (beg (point)))
5582 (when win
5583 (select-window win))
5584 (goto-char point)
5585 (forward-line)
5586 (if (mm-handle-displayed-p handle)
5587 ;; This will remove the part.
5588 (mm-display-part handle)
5589 (save-restriction
23f87bed
MB
5590 (narrow-to-region (point)
5591 (if (eobp) (point) (1+ (point))))
b0b63450 5592 (gnus-bind-safe-url-regexp (mm-display-part handle))
16409b0b
GM
5593 ;; We narrow to the part itself and
5594 ;; then call the treatment functions.
5595 (goto-char (point-min))
5596 (forward-line 1)
5597 (narrow-to-region (point) (point-max))
5598 (gnus-treat-article
5599 nil id
e0bad764 5600 (gnus-article-mime-total-parts)
16409b0b 5601 (mm-handle-media-type handle)))))
23f87bed
MB
5602 (if (window-live-p window)
5603 (select-window window)))))
16409b0b 5604 (goto-char point)
23f87bed 5605 (gnus-delete-line)
16409b0b
GM
5606 (gnus-insert-mime-button
5607 handle id (list (mm-handle-displayed-p handle)))
5608 (goto-char point))))
5609
5610(defun gnus-article-goto-part (n)
5611 "Go to MIME part N."
9efcd224
KY
5612 (when gnus-break-pages
5613 (widen))
95de0327
KY
5614 (prog1
5615 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5616 part handle end next handles)
5617 (when start
5618 (goto-char start)
5619 (if (setq handle (get-text-property start 'gnus-data))
5620 start
5621 ;; Go to the displayed subpart, assuming this is
5622 ;; multipart/alternative.
5623 (setq part start
5624 end (point-at-eol))
5625 (while (and (not handle)
5626 part
5627 (< part end)
5628 (setq next (text-property-not-all part end
5629 'gnus-data nil)))
5630 (setq part next
5631 handle (get-text-property part 'gnus-data))
5632 (push (cons handle part) handles)
5633 (unless (mm-handle-displayed-p handle)
5634 (setq handle nil
5635 part (text-property-any part end 'gnus-data nil))))
5636 (unless handle
5637 ;; No subpart is displayed, so we find preferred one.
5638 (setq part
5639 (cdr (assq (mm-preferred-alternative
5640 (nreverse (mapcar 'car handles)))
5641 handles))))
5642 (if part
5643 (goto-char (1+ part))
5644 start))))
5645 (when gnus-break-pages
5646 (gnus-narrow-to-page))))
16409b0b
GM
5647
5648(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5649 (let ((gnus-tmp-name
23f87bed
MB
5650 (or (mail-content-type-get (mm-handle-type handle) 'name)
5651 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5652 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5653 ""))
5654 (gnus-tmp-type (mm-handle-media-type handle))
4599d0ec 5655 (gnus-tmp-description (or (mm-handle-description handle) ""))
16409b0b
GM
5656 (gnus-tmp-dots
5657 (if (if displayed (car displayed)
5658 (mm-handle-displayed-p handle))
5659 "" "..."))
5660 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5661 (buffer-size)))
5662 gnus-tmp-type-long b e)
5663 (when (string-match ".*/" gnus-tmp-name)
5664 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5665 (setq gnus-tmp-type-long (concat gnus-tmp-type
5666 (and (not (equal gnus-tmp-name ""))
5667 (concat "; " gnus-tmp-name))))
23f87bed
MB
5668 (unless (equal gnus-tmp-description "")
5669 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5670 (unless (bolp)
5671 (insert "\n"))
5672 (setq b (point))
5673 (gnus-eval-format
5674 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5675 `(keymap ,gnus-mime-button-map
5676 gnus-callback gnus-mm-display-part
5677 gnus-part ,gnus-tmp-id
5678 article-type annotation
5679 gnus-data ,handle))
23f87bed
MB
5680 (setq e (if (bolp)
5681 ;; Exclude a newline.
5682 (1- (point))
5683 (point)))
01c52d31
MB
5684 (when gnus-article-button-face
5685 (gnus-overlay-put (gnus-make-overlay b e nil t)
5686 'face gnus-article-button-face))
16409b0b
GM
5687 (widget-convert-button
5688 'link b e
5689 :mime-handle handle
5690 :action 'gnus-widget-press-button
5691 :button-keymap gnus-mime-button-map
5692 :help-echo
5843126b 5693 (lambda (widget)
16409b0b
GM
5694 ;; Needed to properly clear the message due to a bug in
5695 ;; wid-edit (XEmacs only).
5696 (if (boundp 'help-echo-owns-message)
5697 (setq help-echo-owns-message t))
5698 (format
5699 "%S: %s the MIME part; %S: more options"
5700 (aref gnus-mouse-2 0)
5843126b 5701 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
16409b0b
GM
5702 "hide" "show")
5703 (aref gnus-down-mouse-3 0))))))
5704
5705(defun gnus-widget-press-button (elems el)
5706 (goto-char (widget-get elems :from))
5707 (gnus-article-press-button))
5708
5709(defvar gnus-displaying-mime nil)
5710
5711(defun gnus-display-mime (&optional ihandles)
5712 "Display the MIME parts."
5713 (save-excursion
5714 (save-selected-window
5715 (let ((window (get-buffer-window gnus-article-buffer))
5716 (point (point)))
5717 (when window
5718 (select-window window)
5719 ;; We have to do this since selecting the window
5720 ;; may change the point. So we set the window point.
5721 (set-window-point window point)))
73043f7d
MB
5722 (let ((handles ihandles)
5723 (inhibit-read-only t)
5724 handle)
5725 (cond (handles)
5726 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5727 (when gnus-article-emulate-mime
5728 (mm-uu-dissect-text-parts handles)))
5729 (gnus-article-emulate-mime
5730 (setq handles (mm-uu-dissect))))
16409b0b
GM
5731 (when (and (not ihandles)
5732 (not gnus-displaying-mime))
5733 ;; Top-level call; we clean up.
5734 (when gnus-article-mime-handles
5735 (mm-destroy-parts gnus-article-mime-handles)
5736 (setq gnus-article-mime-handle-alist nil));; A trick.
5737 (setq gnus-article-mime-handles handles)
5738 ;; We allow users to glean info from the handles.
5739 (when gnus-article-mime-part-function
5740 (gnus-mime-part-function handles)))
5741 (if (and handles
5742 (or (not (stringp (car handles)))
5743 (cdr handles)))
5744 (progn
5745 (when (and (not ihandles)
5746 (not gnus-displaying-mime))
5747 ;; Clean up for mime parts.
5748 (article-goto-body)
5749 (delete-region (point) (point-max)))
5750 (let ((gnus-displaying-mime t))
5751 (gnus-mime-display-part handles)))
5752 (save-restriction
5753 (article-goto-body)
5754 (narrow-to-region (point) (point-max))
389b76fa 5755 (gnus-treat-article nil 1 1 "text/plain")
16409b0b
GM
5756 (widen)))
5757 (unless ihandles
5758 ;; Highlight the headers.
5759 (save-excursion
5760 (save-restriction
5761 (article-goto-body)
5762 (narrow-to-region (point-min) (point))
31640842 5763 (gnus-article-save-original-date
f362b760
MB
5764 (gnus-treat-article 'head)))))))
5765 ;; Cope with broken MIME messages.
5766 (goto-char (point-max))
5767 (unless (bolp)
5768 (insert "\n"))))
16409b0b 5769
23f87bed
MB
5770(defcustom gnus-mime-display-multipart-as-mixed nil
5771 "Display \"multipart\" parts as \"multipart/mixed\".
5772
5773If t, it overrides nil values of
5774`gnus-mime-display-multipart-alternative-as-mixed' and
5775`gnus-mime-display-multipart-related-as-mixed'."
5776 :group 'gnus-article-mime
5777 :type 'boolean)
5778
5779(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5780 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5781 :version "22.1"
23f87bed
MB
5782 :group 'gnus-article-mime
5783 :type 'boolean)
5784
5785(defcustom gnus-mime-display-multipart-related-as-mixed nil
5786 "Display \"multipart/related\" parts as \"multipart/mixed\".
5787
5788If displaying \"text/html\" is discouraged \(see
5789`mm-discouraged-alternatives'\) images or other material inside a
5790\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5791 :version "22.1"
23f87bed
MB
5792 :group 'gnus-article-mime
5793 :type 'boolean)
16409b0b
GM
5794
5795(defun gnus-mime-display-part (handle)
5796 (cond
430d3ed7
MB
5797 ;; Maybe a broken MIME message.
5798 ((null handle))
16409b0b
GM
5799 ;; Single part.
5800 ((not (stringp (car handle)))
5801 (gnus-mime-display-single handle))
5802 ;; User-defined multipart
5803 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5804 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5805 handle))
5806 ;; multipart/alternative
5807 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5808 (not (or gnus-mime-display-multipart-as-mixed
5809 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5810 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5811 (push (cons id handle) gnus-article-mime-handle-alist)
5812 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5813 ;; multipart/related
5814 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5815 (not (or gnus-mime-display-multipart-as-mixed
5816 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5817 ;;;!!!We should find the start part, but we just default
5818 ;;;!!!to the first part.
23f87bed
MB
5819 ;;(gnus-mime-display-part (cadr handle))
5820 ;;;!!! Most multipart/related is an HTML message plus images.
5821 ;;;!!! Unfortunately we are unable to let W3 display those
5822 ;;;!!! included images, so we just display it as a mixed multipart.
5823 ;;(gnus-mime-display-mixed (cdr handle))
5824 ;;;!!! No, w3 can display everything just fine.
16409b0b 5825 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5826 ((equal (car handle) "multipart/signed")
5827 (gnus-add-wash-type 'signed)
5828 (gnus-mime-display-security handle))
5829 ((equal (car handle) "multipart/encrypted")
5830 (gnus-add-wash-type 'encrypted)
5831 (gnus-mime-display-security handle))
16409b0b
GM
5832 ;; Other multiparts are handled like multipart/mixed.
5833 (t
5834 (gnus-mime-display-mixed (cdr handle)))))
5835
5836(defun gnus-mime-part-function (handles)
5837 (if (stringp (car handles))
5838 (mapcar 'gnus-mime-part-function (cdr handles))
5839 (funcall gnus-article-mime-part-function handles)))
5840
5841(defun gnus-mime-display-mixed (handles)
5842 (mapcar 'gnus-mime-display-part handles))
5843
5844(defun gnus-mime-display-single (handle)
5845 (let ((type (mm-handle-media-type handle))
5846 (ignored gnus-ignored-mime-types)
5847 (not-attachment t)
5848 (move nil)
5849 display text)
5850 (catch 'ignored
5851 (progn
5852 (while ignored
5853 (when (string-match (pop ignored) type)
5854 (throw 'ignored nil)))
b59a9eef
KY
5855 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5856 (with-current-buffer gnus-summary-buffer
5857 gnus-inhibit-images)
5858 gnus-inhibit-images)
40de2c6d
KY
5859 (string-match "\\`image/" type)))
5860 (setq not-attachment
16409b0b
GM
5861 (and (not (mm-inline-override-p handle))
5862 (or (not (mm-handle-disposition handle))
5863 (equal (car (mm-handle-disposition handle))
5864 "inline")
5865 (mm-attachment-override-p handle))))
5866 (mm-automatic-display-p handle)
23f87bed
MB
5867 (or (and
5868 (mm-inlinable-p handle)
5869 (mm-inlined-p handle))
16409b0b
GM
5870 (mm-automatic-external-display-p type)))
5871 (setq display t)
5872 (when (equal (mm-handle-media-supertype handle) "text")
5873 (setq text t)))
e0bad764
DL
5874 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5875 beg)
16409b0b 5876 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5877 (when (and display
5878 (equal (mm-handle-media-supertype handle) "message"))
5879 (insert-char
5880 ?\n
5881 (cond ((not (bolp)) 2)
5882 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5883 (t 1))))
16409b0b 5884 (when (or (not display)
3e3ab3ab
KY
5885 (not (gnus-unbuttonized-mime-type-p type))
5886 (eq id gnus-mime-buttonized-part-id))
16409b0b
GM
5887 (gnus-insert-mime-button
5888 handle id (list (or display (and not-attachment text))))
5889 (gnus-article-insert-newline)
23f87bed 5890 ;; Remember modify the number of forward lines.
e0bad764
DL
5891 (setq move t))
5892 (setq beg (point))
16409b0b
GM
5893 (cond
5894 (display
5895 (when move
23f87bed 5896 (forward-line -1)
16409b0b
GM
5897 (setq beg (point)))
5898 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5899 (mail-parse-ignored-charsets
16409b0b
GM
5900 (save-excursion (condition-case ()
5901 (set-buffer gnus-summary-buffer)
5902 (error))
5903 gnus-newsgroup-ignored-charsets)))
b0b63450 5904 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
16409b0b
GM
5905 (goto-char (point-max)))
5906 ((and text not-attachment)
5907 (when move
23f87bed 5908 (forward-line -1)
16409b0b
GM
5909 (setq beg (point)))
5910 (gnus-article-insert-newline)
f205c6e7 5911 (mm-display-inline handle)
16409b0b
GM
5912 (goto-char (point-max))))
5913 ;; Do highlighting.
5914 (save-excursion
5915 (save-restriction
5916 (narrow-to-region beg (point))
01c52d31
MB
5917 (if (eq handle gnus-article-mime-handles)
5918 ;; The format=flowed case.
5919 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5920 ;; Don't count signature parts that are never displayed.
5921 ;; The part number should be re-calculated supposing this
5922 ;; might be a message/rfc822 part.
5923 (let (handles)
5924 (dolist (part gnus-article-mime-handles)
5925 (unless (or (stringp part)
5926 (equal (car (mm-handle-type part))
5927 "application/pgp-signature"))
5928 (push part handles)))
5929 (gnus-treat-article
5930 nil (length (memq handle handles)) (length handles)
5931 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5932
5933(defun gnus-unbuttonized-mime-type-p (type)
5934 "Say whether TYPE is to be unbuttonized."
5935 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5936 (when (catch 'found
5937 (let ((types gnus-unbuttonized-mime-types))
5938 (while types
5939 (when (string-match (pop types) type)
5940 (throw 'found t)))))
5941 (not (catch 'found
5942 (let ((types gnus-buttonized-mime-types))
5943 (while types
5944 (when (string-match (pop types) type)
5945 (throw 'found t)))))))))
16409b0b
GM
5946
5947(defun gnus-article-insert-newline ()
5948 "Insert a newline, but mark it as undeletable."
5949 (gnus-put-text-property
5950 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5951
5952(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5953 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5954 (ihandles handles)
5955 (point (point))
23f87bed 5956 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5957 (save-window-excursion
5958 (save-restriction
5959 (when ibegend
5960 (narrow-to-region (car ibegend)
5961 (or (cdr ibegend)
5962 (progn
5963 (goto-char (car ibegend))
5964 (forward-line 2)
5965 (point))))
5966 (delete-region (point-min) (point-max))
5967 (mm-remove-parts handles))
5968 (setq begend (list (point-marker)))
5969 ;; Do the toggle.
5970 (unless (setq not-pref (cadr (member preferred ihandles)))
5971 (setq not-pref (car ihandles)))
5972 (when (or ibegend
23f87bed 5973 (not preferred)
16409b0b
GM
5974 (not (gnus-unbuttonized-mime-type-p
5975 "multipart/alternative")))
5976 (gnus-add-text-properties
5977 (setq from (point))
5978 (progn
5979 (insert (format "%d. " id))
5980 (point))
5981 `(gnus-callback
5982 (lambda (handles)
5983 (unless ,(not ibegend)
5984 (setq gnus-article-mime-handle-alist
5985 ',gnus-article-mime-handle-alist))
5986 (gnus-mime-display-alternative
5987 ',ihandles ',not-pref ',begend ,id))
01c52d31 5988 keymap ,gnus-mime-button-map
16409b0b
GM
5989 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5990 face ,gnus-article-button-face
16409b0b 5991 gnus-part ,id
7dafe00b 5992 article-type multipart))
16409b0b
GM
5993 (widget-convert-button 'link from (point)
5994 :action 'gnus-widget-press-button
5995 :button-keymap gnus-widget-button-keymap)
5996 ;; Do the handles
5997 (while (setq handle (pop handles))
5998 (gnus-add-text-properties
5999 (setq from (point))
6000 (progn
6001 (insert (format "(%c) %-18s"
6002 (if (equal handle preferred) ?* ? )
6003 (mm-handle-media-type handle)))
6004 (point))
6005 `(gnus-callback
6006 (lambda (handles)
6007 (unless ,(not ibegend)
6008 (setq gnus-article-mime-handle-alist
6009 ',gnus-article-mime-handle-alist))
6010 (gnus-mime-display-alternative
6011 ',ihandles ',handle ',begend ,id))
01c52d31 6012 keymap ,gnus-mime-button-map
16409b0b
GM
6013 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6014 face ,gnus-article-button-face
16409b0b
GM
6015 gnus-part ,id
6016 gnus-data ,handle))
6017 (widget-convert-button 'link from (point)
6018 :action 'gnus-widget-press-button
6019 :button-keymap gnus-widget-button-keymap)
6020 (insert " "))
6021 (insert "\n\n"))
6022 (when preferred
6023 (if (stringp (car preferred))
6024 (gnus-display-mime preferred)
6025 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 6026 (mail-parse-ignored-charsets
01c52d31
MB
6027 (with-current-buffer gnus-summary-buffer
6028 gnus-newsgroup-ignored-charsets)))
b0b63450 6029 (gnus-bind-safe-url-regexp (mm-display-part preferred))
16409b0b
GM
6030 ;; Do highlighting.
6031 (save-excursion
6032 (save-restriction
6033 (narrow-to-region (car begend) (point-max))
6034 (gnus-treat-article
6035 nil (length gnus-article-mime-handle-alist)
e0bad764 6036 (gnus-article-mime-total-parts)
389b76fa 6037 (mm-handle-media-type preferred))))))
16409b0b
GM
6038 (goto-char (point-max))
6039 (setcdr begend (point-marker)))))
6040 (when ibegend
6041 (goto-char point))))
6042
23f87bed
MB
6043(defconst gnus-article-wash-status-strings
6044 (let ((alist '((cite "c" "Possible hidden citation text"
6045 " " "All citation text visible")
6046 (headers "h" "Hidden headers"
6047 " " "All headers visible.")
6048 (pgp "p" "Encrypted or signed message status hidden"
6049 " " "No hidden encryption nor digital signature status")
6050 (signature "s" "Signature has been hidden"
6051 " " "Signature is visible")
6052 (overstrike "o" "Overstrike (^H) characters applied"
6053 " " "No overstrike characters applied")
6054 (emphasis "e" "/*_Emphasis_*/ characters applied"
6055 " " "No /*_emphasis_*/ characters applied")))
6056 result)
6057 (dolist (entry alist result)
6058 (let ((key (nth 0 entry))
6059 (on (copy-sequence (nth 1 entry)))
6060 (on-help (nth 2 entry))
6061 (off (copy-sequence (nth 3 entry)))
6062 (off-help (nth 4 entry)))
6063 (put-text-property 0 1 'help-echo on-help on)
6064 (put-text-property 0 1 'help-echo off-help off)
6065 (push (list key on off) result))))
6066 "Alist of strings describing wash status in the mode line.
6067Each entry has the form (KEY ON OF), where the KEY is a symbol
6068representing the particular washing function, ON is the string to use
6069in the article mode line when the washing function is active, and OFF
6070is the string to use when it is inactive.")
6071
6072(defun gnus-article-wash-status-entry (key value)
6073 (let ((entry (assoc key gnus-article-wash-status-strings)))
6074 (if value (nth 1 entry) (nth 2 entry))))
6075
eec82323
LMI
6076(defun gnus-article-wash-status ()
6077 "Return a string which display status of article washing."
01c52d31 6078 (with-current-buffer gnus-article-buffer
16409b0b
GM
6079 (let ((cite (memq 'cite gnus-article-wash-types))
6080 (headers (memq 'headers gnus-article-wash-types))
6081 (boring (memq 'boring-headers gnus-article-wash-types))
6082 (pgp (memq 'pgp gnus-article-wash-types))
6083 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
6084 (signed (memq 'signed gnus-article-wash-types))
6085 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
6086 (signature (memq 'signature gnus-article-wash-types))
6087 (overstrike (memq 'overstrike gnus-article-wash-types))
6088 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
6089 (concat
6090 (gnus-article-wash-status-entry 'cite cite)
6091 (gnus-article-wash-status-entry 'headers (or headers boring))
6092 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6093 (gnus-article-wash-status-entry 'signature signature)
6094 (gnus-article-wash-status-entry 'overstrike overstrike)
6095 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6096
6097(defun gnus-add-wash-type (type)
6098 "Add a washing of TYPE to the current status."
6099 (add-to-list 'gnus-article-wash-types type))
6100
6101(defun gnus-delete-wash-type (type)
6102 "Add a washing of TYPE to the current status."
6103 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6104
6105(defun gnus-add-image (category image)
6106 "Add IMAGE of CATEGORY to the list of displayed images."
6107 (let ((entry (assq category gnus-article-image-alist)))
6108 (unless entry
6109 (setq entry (list category))
6110 (push entry gnus-article-image-alist))
6111 (nconc entry (list image))))
6112
6113(defun gnus-delete-images (category)
6114 "Delete all images in CATEGORY."
6115 (let ((entry (assq category gnus-article-image-alist)))
6116 (dolist (image (cdr entry))
6117 (gnus-remove-image image category))
6118 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6119 (gnus-delete-wash-type category)))
eec82323 6120
16409b0b 6121(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
6122
6123(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
6124 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6125Provided for backwards compatibility."
16409b0b 6126 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
6127 (not (with-current-buffer gnus-summary-buffer
6128 gnus-have-all-headers)))
16409b0b
GM
6129 (not gnus-inhibit-hiding))
6130 (gnus-article-hide-headers)))
eec82323
LMI
6131
6132;;; Article savers.
6133
6134(defun gnus-output-to-file (file-name)
26c9afc3
MB
6135 "Append the current article to a file named FILE-NAME.
6136If `gnus-article-save-coding-system' is non-nil, it is used to encode
6137text and used as the value of the coding cookie which is added to the
6138top of a file. Otherwise, this function saves a raw article without
6139the coding cookie."
6140 (let* ((artbuf (current-buffer))
6141 (file-name-coding-system nnmail-pathname-coding-system)
6142 (coding gnus-article-save-coding-system)
6143 (coding-system-for-read (if coding
6144 nil ;; Rely on the coding cookie.
6145 mm-text-coding-system))
6146 (coding-system-for-write (or coding
6147 mm-text-coding-system-for-write
6148 mm-text-coding-system))
6149 (exists (file-exists-p file-name)))
16409b0b 6150 (with-temp-buffer
26c9afc3
MB
6151 (when exists
6152 (insert-file-contents file-name)
6153 (goto-char (point-min))
6154 ;; Remove the existing coding cookie.
6155 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6156 (delete-region (match-beginning 0) (match-end 0))))
6157 (goto-char (point-max))
eec82323
LMI
6158 (insert-buffer-substring artbuf)
6159 ;; Append newline at end of the buffer as separator, and then
6160 ;; save it to file.
6161 (goto-char (point-max))
6162 (insert "\n")
26c9afc3
MB
6163 (when coding
6164 ;; If the coding system is not suitable to encode the text,
6165 ;; ask a user for a proper one.
6166 (when (fboundp 'select-safe-coding-system)
6167 (setq coding (coding-system-base
6168 (save-window-excursion
6169 (select-safe-coding-system (point-min) (point-max)
6170 coding))))
6171 (setq coding-system-for-write
6172 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6173 coding)))
6174 (goto-char (point-min))
6175 ;; Add the coding cookie.
6176 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6177 coding-system-for-write)))
6178 (if exists
6179 (progn
6180 (write-region (point-min) (point-max) file-name nil 'no-message)
6181 (message "Appended to %s" file-name))
6182 (write-region (point-min) (point-max) file-name))))
6183 t)
eec82323
LMI
6184
6185(defun gnus-narrow-to-page (&optional arg)
6186 "Narrow the article buffer to a page.
6187If given a numerical ARG, move forward ARG pages."
6188 (interactive "P")
6189 (setq arg (if arg (prefix-numeric-value arg) 0))
80de1778 6190 (with-current-buffer gnus-article-buffer
eec82323
LMI
6191 (widen)
6192 ;; Remove any old next/prev buttons.
6193 (when (gnus-visual-p 'page-marker)
4e7d0221 6194 (let ((inhibit-read-only t))
eec82323
LMI
6195 (gnus-remove-text-with-property 'gnus-prev)
6196 (gnus-remove-text-with-property 'gnus-next)))
8f7abae3
MB
6197 (let (st nd pt)
6198 (when (save-excursion
6199 (cond ((< arg 0)
6200 (if (re-search-backward page-delimiter nil 'move (abs arg))
6201 (prog1
6202 (setq nd (match-beginning 0)
6203 pt nd)
6204 (when (re-search-backward page-delimiter nil t)
6205 (setq st (match-end 0))))
6206 (when (re-search-forward page-delimiter nil t)
6207 (setq nd (match-beginning 0)
6208 pt (point-min)))))
6209 ((> arg 0)
6210 (if (re-search-forward page-delimiter nil 'move arg)
6211 (prog1
6212 (setq st (match-end 0)
6213 pt st)
6214 (when (re-search-forward page-delimiter nil t)
6215 (setq nd (match-beginning 0))))
6216 (when (re-search-backward page-delimiter nil t)
6217 (setq st (match-end 0)
6218 pt (point-max)))))
6219 (t
6220 (when (re-search-backward page-delimiter nil t)
6221 (goto-char (setq st (match-end 0))))
6222 (when (re-search-forward page-delimiter nil t)
6223 (setq nd (match-beginning 0)))
6224 (or st nd))))
6225 (setq gnus-page-broken t)
6226 (when pt (goto-char pt))
6227 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6228 (when (gnus-visual-p 'page-marker)
6229 (save-excursion
6230 (when nd
6231 (goto-char nd)
6232 (gnus-insert-next-page-button))
6233 (when st
6234 (goto-char st)
6235 (gnus-insert-prev-page-button))))))))
eec82323
LMI
6236
6237;; Article mode commands
6238
6239(defun gnus-article-goto-next-page ()
6240 "Show the next page of the article."
6241 (interactive)
6242 (when (gnus-article-next-page)
6243 (goto-char (point-min))
6244 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6245
23f87bed 6246
eec82323 6247(defun gnus-article-goto-prev-page ()
23f87bed 6248 "Show the previous page of the article."
eec82323 6249 (interactive)
8f7abae3 6250 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
23f87bed 6251 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6252 (gnus-article-prev-page nil)))
6253
23f87bed
MB
6254;; This is cleaner but currently breaks `gnus-pick-mode':
6255;;
6256;; (defun gnus-article-goto-next-page ()
6257;; "Show the next page of the article."
6258;; (interactive)
6259;; (gnus-eval-in-buffer-window gnus-summary-buffer
6260;; (gnus-summary-next-page)))
6261;;
6262;; (defun gnus-article-goto-prev-page ()
6263;; "Show the next page of the article."
6264;; (interactive)
6265;; (gnus-eval-in-buffer-window gnus-summary-buffer
6266;; (gnus-summary-prev-page)))
6267
eec82323
LMI
6268(defun gnus-article-next-page (&optional lines)
6269 "Show the next page of the current article.
6270If end of article, return non-nil. Otherwise return nil.
6271Argument LINES specifies lines to be scrolled up."
6272 (interactive "p")
9153f10d 6273 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
60ece9b0
MB
6274 (if (and (not (and gnus-article-over-scroll
6275 (> (count-lines (window-start) (point-max))
9153f10d
MB
6276 (if (featurep 'xemacs)
6277 (or lines (1- (window-height)))
6278 (+ (or lines (1- (window-height))) scroll-margin)))))
60ece9b0
MB
6279 (save-excursion
6280 (end-of-line)
6281 (and (pos-visible-in-window-p) ;Not continuation line.
647559c2 6282 (>= (point) (point-max)))))
eec82323
LMI
6283 ;; Nothing in this page.
6284 (if (or (not gnus-page-broken)
6285 (save-excursion
6286 (save-restriction
23f87bed
MB
6287 (widen)
6288 (forward-line)
6289 (eobp)))) ;Real end-of-buffer?
6290 (progn
6291 (when gnus-article-over-scroll
6292 (gnus-article-next-page-1 lines))
6293 t) ;Nothing more.
eec82323
LMI
6294 (gnus-narrow-to-page 1) ;Go to next page.
6295 nil)
6296 ;; More in this page.
23f87bed 6297 (gnus-article-next-page-1 lines)
eec82323
LMI
6298 nil))
6299
b1992461 6300(defun gnus-article-beginning-of-window ()
d8a88581
MB
6301 "Move point to the beginning of the window.
6302In Emacs, the point is placed at the line number which `scroll-margin'
6303specifies."
6304 (if (featurep 'xemacs)
b1992461
KY
6305 (move-to-window-line 0)
6306 ;; There is an obscure bug in Emacs that makes it impossible to
6307 ;; scroll past big pictures in the article buffer. Try to fix
6308 ;; this by adding a sanity check by counting the lines visible.
6309 (when (> (count-lines (window-start) (window-end)) 30)
6310 (move-to-window-line
6311 (min (max 0 scroll-margin)
6312 (max 1 (- (window-height)
6313 (if mode-line-format 1 0)
6314 (if header-line-format 1 0)
6315 2)))))))
d8a88581 6316
23f87bed 6317(defun gnus-article-next-page-1 (lines)
4b91459a
MB
6318 (condition-case ()
6319 (let ((scroll-in-place nil))
6320 (scroll-up lines))
6321 (end-of-buffer
6322 ;; Long lines may cause an end-of-buffer error.
6323 (goto-char (point-max))))
6324 (gnus-article-beginning-of-window))
23f87bed 6325
eec82323
LMI
6326(defun gnus-article-prev-page (&optional lines)
6327 "Show previous page of current article.
6328Argument LINES specifies lines to be scrolled down."
6329 (interactive "p")
d8a88581 6330 (move-to-window-line 0)
eec82323
LMI
6331 (if (and gnus-page-broken
6332 (bobp)
6333 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6334 (progn
6335 (gnus-narrow-to-page -1) ;Go to previous page.
6336 (goto-char (point-max))
60ece9b0
MB
6337 (recenter (if gnus-article-over-scroll
6338 (if lines
9153f10d
MB
6339 (max (if (featurep 'xemacs)
6340 lines
6341 (+ lines scroll-margin))
60ece9b0
MB
6342 3)
6343 (- (window-height) 2))
6344 -1)))
c03ac728
MB
6345 (prog1
6346 (condition-case ()
6347 (let ((scroll-in-place nil))
6348 (scroll-down lines))
6349 (beginning-of-buffer
6350 (goto-char (point-min))))
6351 (gnus-article-beginning-of-window))))
eec82323 6352
23f87bed
MB
6353(defun gnus-article-only-boring-p ()
6354 "Decide whether there is only boring text remaining in the article.
6355Something \"interesting\" is a word of at least two letters that does
6356not have a face in `gnus-article-boring-faces'."
6357 (when (and gnus-article-skip-boring
6358 (boundp 'gnus-article-boring-faces)
6359 (symbol-value 'gnus-article-boring-faces))
6360 (save-excursion
531bedc3
MB
6361 (let ((inhibit-point-motion-hooks t))
6362 (catch 'only-boring
6363 (while (re-search-forward "\\b\\w\\w" nil t)
6364 (forward-char -1)
6365 (when (not (gnus-intersection
6366 (gnus-faces-at (point))
6367 (symbol-value 'gnus-article-boring-faces)))
6368 (throw 'only-boring nil)))
6369 (throw 'only-boring t))))))
23f87bed 6370
eec82323
LMI
6371(defun gnus-article-refer-article ()
6372 "Read article specified by message-id around point."
6373 (interactive)
23f87bed 6374 (save-excursion
01c52d31
MB
6375 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6376 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6377 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6378 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6379 (set-buffer gnus-summary-buffer)
23f87bed 6380 (gnus-summary-refer-article msg-id))
eec82323
LMI
6381 (error "No references around point"))))
6382
6383(defun gnus-article-show-summary ()
6384 "Reconfigure windows to show summary buffer."
6385 (interactive)
6386 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6387 (error "There is no summary buffer for this article buffer")
a8151ef7 6388 (gnus-article-set-globals)
eec82323 6389 (gnus-configure-windows 'article)
6748645f
LMI
6390 (gnus-summary-goto-subject gnus-current-article)
6391 (gnus-summary-position-point)))
eec82323
LMI
6392
6393(defun gnus-article-describe-briefly ()
6394 "Describe article mode commands briefly."
6395 (interactive)
bdaa75c7 6396 (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")))
eec82323 6397
16409b0b
GM
6398(defun gnus-article-check-buffer ()
6399 "Beep if not in an article buffer."
6400 (unless (equal major-mode 'gnus-article-mode)
6401 (error "Command invoked outside of a Gnus article buffer")))
6402
eec82323
LMI
6403(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6404 "Read a summary buffer key sequence and execute it from the article buffer."
6405 (interactive "P")
16409b0b 6406 (gnus-article-check-buffer)
eec82323 6407 (let ((nosaves
23f87bed
MB
6408 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6409 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6410 "=" "^" "\M-^" "|"))
6411 (nosave-but-article
0b6799c3
MB
6412 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6413 "An" "Ap" [?A (meta return)] [?A delete]))
23f87bed 6414 (nosave-in-article
0b6799c3 6415 '("AS" "\C-d"))
23f87bed
MB
6416 (up-to-top
6417 '("n" "Gn" "p" "Gp"))
6418 keys new-sum-point)
80de1778 6419 (with-current-buffer gnus-article-current-summary
eec82323 6420 (let (gnus-pick-mode)
95838435
MB
6421 (setq unread-command-events (nconc unread-command-events
6422 (list (or key last-command-event)))
6423 keys (if (featurep 'xemacs)
6424 (events-to-keys (read-key-sequence nil t))
6425 (read-key-sequence nil t)))))
a1506d29 6426
eec82323
LMI
6427 (message "")
6428
01c52d31
MB
6429 (cond
6430 ((eq (aref keys (1- (length keys))) ?\C-h)
0b6799c3 6431 (gnus-article-describe-bindings (substring keys 0 -1)))
01c52d31
MB
6432 ((or (member keys nosaves)
6433 (member keys nosave-but-article)
6434 (member keys nosave-in-article))
6435 (let (func)
6436 (save-window-excursion
6437 (pop-to-buffer gnus-article-current-summary)
6438 ;; We disable the pick minor mode commands.
6439 (let (gnus-pick-mode)
6ab2c7a8 6440 (setq func (key-binding keys t))))
01c52d31
MB
6441 (if (or (not func)
6442 (numberp func))
6443 (ding)
6444 (unless (member keys nosave-in-article)
6445 (set-buffer gnus-article-current-summary))
cb51ba08
LI
6446 (when (get func 'disabled)
6447 (error "Function %s disabled" func))
01c52d31
MB
6448 (call-interactively func)
6449 (setq new-sum-point (point)))
6450 (when (member keys nosave-but-article)
6451 (pop-to-buffer gnus-article-buffer))))
6452 (t
eec82323
LMI
6453 ;; These commands should restore window configuration.
6454 (let ((obuf (current-buffer))
23f87bed 6455 (owin (current-window-configuration))
01c52d31 6456 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6457 (cond (not-restore-window
01c52d31
MB
6458 (pop-to-buffer gnus-article-current-summary)
6459 (setq win (selected-window)))
23f87bed
MB
6460 ((setq win (get-buffer-window gnus-article-current-summary))
6461 (select-window win))
6462 (t
01c52d31
MB
6463 (let ((summary-buffer gnus-article-current-summary))
6464 (gnus-configure-windows 'article)
6465 (unless (setq win (get-buffer-window summary-buffer 'visible))
6466 (let ((gnus-buffer-configuration
de0bdfe7
KY
6467 '((article ((vertical 1.0
6468 (summary 0.25 point)
6469 (article 1.0)))))))
01c52d31
MB
6470 (gnus-configure-windows 'article))
6471 (setq win (get-buffer-window summary-buffer 'visible)))
6472 (gnus-select-frame-set-input-focus (window-frame win))
6473 (select-window win))))
23f87bed
MB
6474 (setq in-buffer (current-buffer))
6475 ;; We disable the pick minor mode commands.
cb51ba08
LI
6476 (setq func (let (gnus-pick-mode)
6477 (key-binding keys t)))
6478 (when (get func 'disabled)
6479 (error "Function %s disabled" func))
6480 (if (and func
01c52d31
MB
6481 (functionp func)
6482 (condition-case code
6483 (progn
6484 (call-interactively func)
6485 t)
6486 (error
6487 (setq err code)
6488 nil)))
23f87bed 6489 (progn
23f87bed
MB
6490 (when (eq win (selected-window))
6491 (setq new-sum-point (point)
6492 new-sum-start (window-start win)
9a89f5b0 6493 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6494 (when (or (eq in-buffer (current-buffer))
6495 (when (eq obuf (current-buffer))
6496 (set-buffer in-buffer)
6497 t))
520aa572
SZ
6498 (setq selected (gnus-summary-select-article))
6499 (set-buffer obuf)
6500 (unless not-restore-window
6501 (set-window-configuration owin))
01c52d31
MB
6502 (when (and (eq selected 'old)
6503 new-sum-point)
520aa572
SZ
6504 (set-window-start (get-buffer-window (current-buffer))
6505 1)
6506 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6507 (if (article-goto-body)
6508 (1- (point))
6509 (point))))
23f87bed 6510 (when (and (not not-restore-window)
01c52d31 6511 new-sum-point
4520e527 6512 (window-live-p win)
01c52d31
MB
6513 (with-current-buffer (window-buffer win)
6514 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6515 (set-window-point win new-sum-point)
6516 (set-window-start win new-sum-start)
9a89f5b0 6517 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6518 (set-window-configuration owin)
01c52d31
MB
6519 (if err
6520 (signal (car err) (cdr err))
6521 (ding))))))))
520aa572 6522
95838435
MB
6523(defun gnus-article-read-summary-send-keys ()
6524 (interactive)
0b6799c3 6525 (let ((unread-command-events (list (gnus-character-to-event ?S))))
95838435
MB
6526 (gnus-article-read-summary-keys)))
6527
520aa572 6528(defun gnus-article-describe-key (key)
95838435
MB
6529 "Display documentation of the function invoked by KEY.
6530KEY is a string or a vector."
6531 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6532 (read-key-sequence "Describe key: "))))
520aa572 6533 (gnus-article-check-buffer)
95838435
MB
6534 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6535 gnus-article-read-summary-send-keys))
80de1778 6536 (with-current-buffer gnus-article-current-summary
95838435
MB
6537 (setq unread-command-events
6538 (if (featurep 'xemacs)
6539 (append key nil)
6540 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6541 (list 'meta (- x 128))
6542 x))
6543 key)))
6544 (let ((cursor-in-echo-area t)
6545 gnus-pick-mode)
6546 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6547 (describe-key key)))
6548
6549(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6550 "Display documentation of the function invoked by KEY.
6551KEY is a string or a vector."
6552 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6553 (read-key-sequence "Describe key: "))
6554 current-prefix-arg))
520aa572 6555 (gnus-article-check-buffer)
95838435
MB
6556 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6557 gnus-article-read-summary-send-keys))
80de1778 6558 (with-current-buffer gnus-article-current-summary
95838435
MB
6559 (setq unread-command-events
6560 (if (featurep 'xemacs)
6561 (append key nil)
6562 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6563 (list 'meta (- x 128))
6564 x))
6565 key)))
6566 (let ((cursor-in-echo-area t)
6567 gnus-pick-mode)
6568 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6569 (describe-key-briefly key insert)))
eec82323 6570
0b6799c3
MB
6571;;`gnus-agent-mode' in gnus-agent.el will define it.
6572(defvar gnus-agent-summary-mode)
e9198520 6573(defvar gnus-draft-mode)
12ea3d65
GM
6574;; Calling help-buffer will autoload help-mode.
6575(defvar help-xref-stack-item)
5843126b
KY
6576;; Emacs 22 doesn't load it in the batch mode.
6577(eval-when-compile
6578 (autoload 'help-buffer "help-mode"))
0b6799c3
MB
6579
6580(defun gnus-article-describe-bindings (&optional prefix)
6581 "Show a list of all defined keys, and their definitions.
6582The optional argument PREFIX, if non-nil, should be a key sequence;
6583then we display only bindings that start with that prefix."
6584 (interactive)
6585 (gnus-article-check-buffer)
6586 (let ((keymap (copy-keymap gnus-article-mode-map))
6587 (map (copy-keymap gnus-article-send-map))
6588 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
8a908224 6589 parent agent draft)
0b6799c3
MB
6590 (define-key keymap "S" map)
6591 (define-key map [t] nil)
6592 (with-current-buffer gnus-article-current-summary
8a908224
KY
6593 (set-keymap-parent
6594 keymap
6595 (if (setq parent (keymap-parent gnus-article-mode-map))
6596 (prog1
6597 (setq parent (copy-keymap parent))
6598 (set-keymap-parent parent (current-local-map)))
6599 (current-local-map)))
0b6799c3 6600 (set-keymap-parent map (key-binding "S"))
8f7abae3
MB
6601 (let (key def gnus-pick-mode)
6602 (while sumkeys
6603 (setq key (pop sumkeys))
6604 (cond ((and (vectorp key) (= (length key) 1)
6605 (consp (setq def (aref key 0)))
6606 (numberp (car def)) (numberp (cdr def)))
6607 (when (< (max (car def) (cdr def)) 128)
6608 (setq sumkeys
6609 (append (mapcar
6610 #'vector
6611 (nreverse (gnus-uncompress-range def)))
6612 sumkeys))))
6613 ((setq def (key-binding key))
6614 (unless (eq def 'undefined)
6615 (define-key keymap key def))))))
0b6799c3 6616 (when (boundp 'gnus-agent-summary-mode)
e9198520
MB
6617 (setq agent gnus-agent-summary-mode))
6618 (when (boundp 'gnus-draft-mode)
6619 (setq draft gnus-draft-mode)))
0b6799c3
MB
6620 (with-temp-buffer
6621 (use-local-map keymap)
6622 (set (make-local-variable 'gnus-agent-summary-mode) agent)
e9198520 6623 (set (make-local-variable 'gnus-draft-mode) draft)
0b6799c3
MB
6624 (describe-bindings prefix))
6625 (let ((item `((lambda (prefix)
80de1778 6626 (with-current-buffer ,(current-buffer)
0b6799c3
MB
6627 (gnus-article-describe-bindings prefix)))
6628 ,prefix)))
5843126b 6629 (with-current-buffer (let (help-xref-following) (help-buffer))
0b6799c3
MB
6630 (setq help-xref-stack-item item)))))
6631
23f87bed
MB
6632(defun gnus-article-reply-with-original (&optional wide)
6633 "Start composing a reply mail to the current message.
6634The text in the region will be yanked. If the region isn't active,
6635the entire article will be yanked."
95838435 6636 (interactive)
23f87bed
MB
6637 (let ((article (cdr gnus-article-current))
6638 contents)
1d0df8af 6639 (if (not (gnus-region-active-p))
23f87bed
MB
6640 (with-current-buffer gnus-summary-buffer
6641 (gnus-summary-reply (list (list article)) wide))
6642 (setq contents (buffer-substring (point) (mark t)))
6643 ;; Deactivate active regions.
6644 (when (and (boundp 'transient-mark-mode)
6645 transient-mark-mode)
6646 (setq mark-active nil))
6647 (with-current-buffer gnus-summary-buffer
6648 (gnus-summary-reply
6649 (list (list article contents)) wide)))))
6650
95838435
MB
6651(defun gnus-article-wide-reply-with-original ()
6652 "Start composing a wide reply mail to the current message.
6653The text in the region will be yanked. If the region isn't active,
6654the entire article will be yanked."
6655 (interactive)
6656 (gnus-article-reply-with-original t))
6657
23f87bed
MB
6658(defun gnus-article-followup-with-original ()
6659 "Compose a followup to the current article.
6660The text in the region will be yanked. If the region isn't active,
6661the entire article will be yanked."
6662 (interactive)
6663 (let ((article (cdr gnus-article-current))
6664 contents)
1d0df8af 6665 (if (not (gnus-region-active-p))
23f87bed
MB
6666 (with-current-buffer gnus-summary-buffer
6667 (gnus-summary-followup (list (list article))))
6668 (setq contents (buffer-substring (point) (mark t)))
6669 ;; Deactivate active regions.
6670 (when (and (boundp 'transient-mark-mode)
6671 transient-mark-mode)
6672 (setq mark-active nil))
6673 (with-current-buffer gnus-summary-buffer
6674 (gnus-summary-followup
6675 (list (list article contents)))))))
6676
eec82323
LMI
6677(defun gnus-article-hide (&optional arg force)
6678 "Hide all the gruft in the current article.
23f87bed
MB
6679This means that signatures, cited text and (some) headers will be
6680hidden.
eec82323 6681If given a prefix, show the hidden text instead."
6748645f 6682 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6683 (gnus-article-hide-headers arg)
16409b0b 6684 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6685 (gnus-article-hide-citation-maybe arg force)
6686 (gnus-article-hide-signature arg))
6687
6688(defun gnus-article-maybe-highlight ()
6748645f 6689 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6690 (when (gnus-visual-p 'article-highlight 'highlight)
6691 (gnus-article-highlight-some)))
6692
6748645f
LMI
6693(defun gnus-check-group-server ()
6694 ;; Make sure the connection to the server is alive.
6695 (unless (gnus-server-opened
6696 (gnus-find-method-for-group gnus-newsgroup-name))
6697 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6698 (gnus-request-group gnus-newsgroup-name t)))
6699
23f87bed
MB
6700(eval-when-compile
6701 (autoload 'nneething-get-file-name "nneething"))
6702
eec82323
LMI
6703(defun gnus-request-article-this-buffer (article group)
6704 "Get an article and insert it into this buffer."
6748645f 6705 (let (do-update-line sparse-header)
eec82323
LMI
6706 (prog1
6707 (save-excursion
6708 (erase-buffer)
6709 (gnus-kill-all-overlays)
6710 (setq group (or group gnus-newsgroup-name))
6711
eec82323
LMI
6712 ;; Using `gnus-request-article' directly will insert the article into
6713 ;; `nntp-server-buffer' - so we'll save some time by not having to
6714 ;; copy it from the server buffer into the article buffer.
6715
6716 ;; We only request an article by message-id when we do not have the
6717 ;; headers for it, so we'll have to get those.
6718 (when (stringp article)
16409b0b 6719 (gnus-read-header article))
eec82323
LMI
6720
6721 ;; If the article number is negative, that means that this article
6722 ;; doesn't belong in this newsgroup (possibly), so we find its
6723 ;; message-id and request it by id instead of number.
6724 (when (and (numberp article)
6725 gnus-summary-buffer
6726 (get-buffer gnus-summary-buffer)
6748645f 6727 (gnus-buffer-exists-p gnus-summary-buffer))
80de1778 6728 (with-current-buffer gnus-summary-buffer
eec82323
LMI
6729 (let ((header (gnus-summary-article-header article)))
6730 (when (< article 0)
6731 (cond
6732 ((memq article gnus-newsgroup-sparse)
6733 ;; This is a sparse gap article.
6734 (setq do-update-line article)
6735 (setq article (mail-header-id header))
16409b0b 6736 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6737 (setq gnus-newsgroup-sparse
6738 (delq article gnus-newsgroup-sparse)))
6739 ((vectorp header)
6740 ;; It's a real article.
6741 (setq article (mail-header-id header)))
6742 (t
6743 ;; It is an extracted pseudo-article.
6744 (setq article 'pseudo)
6745 (gnus-request-pseudo-article header))))
6746
6747 (let ((method (gnus-find-method-for-group
6748 gnus-newsgroup-name)))
6748645f
LMI
6749 (when (and (eq (car method) 'nneething)
6750 (vectorp header))
23f87bed
MB
6751 (let ((dir (nneething-get-file-name
6752 (mail-header-id header))))
6753 (when (and (stringp dir)
6754 (file-directory-p dir))
eec82323
LMI
6755 (setq article 'nneething)
6756 (gnus-group-enter-directory dir))))))))
6757
6758 (cond
6759 ;; Refuse to select canceled articles.
6760 ((and (numberp article)
6761 gnus-summary-buffer
6762 (get-buffer gnus-summary-buffer)
6748645f 6763 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6764 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6765 (assq article gnus-newsgroup-reads)))
6766 gnus-canceled-mark))
6767 nil)
6768 ;; We first check `gnus-original-article-buffer'.
6769 ((and (get-buffer gnus-original-article-buffer)
6770 (numberp article)
01c52d31 6771 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6772 (and (equal (car gnus-original-article) group)
6773 (eq (cdr gnus-original-article) article))))
75eda25b
SM
6774 ;; `insert-buffer-substring' would incorrectly use the
6775 ;; equivalent of string-make-multibyte which amount to decoding
6776 ;; with locale-coding-system, causing failure of
6777 ;; subsequent decoding.
6778 (insert (mm-string-to-multibyte
6779 (with-current-buffer gnus-original-article-buffer
6780 (buffer-substring (point-min) (point-max)))))
eec82323
LMI
6781 'article)
6782 ;; Check the backlog.
6783 ((and gnus-keep-backlog
6784 (gnus-backlog-request-article group article (current-buffer)))
6785 'article)
6786 ;; Check asynchronous pre-fetch.
6787 ((gnus-async-request-fetched-article group article (current-buffer))
6788 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6789 (when (and (numberp article) gnus-keep-backlog)
6790 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6791 'article)
6792 ;; Check the cache.
6793 ((and gnus-use-cache
6794 (numberp article)
6795 (gnus-cache-request-article article group))
6796 'article)
23f87bed
MB
6797 ;; Check the agent cache.
6798 ((gnus-agent-request-article article group)
6799 'article)
eec82323 6800 ;; Get the article and put into the article buffer.
16409b0b
GM
6801 ((or (stringp article)
6802 (numberp article))
6803 (let ((gnus-override-method gnus-override-method)
a1506d29 6804 (methods (and (stringp article)
16409b0b 6805 gnus-refer-article-method))
23f87bed
MB
6806 (backend (car (gnus-find-method-for-group
6807 gnus-newsgroup-name)))
16409b0b 6808 result
4e7d0221 6809 (inhibit-read-only t))
e0bad764
DL
6810 (if (or (not (listp methods))
6811 (and (symbolp (car methods))
6812 (assq (car methods) nnoo-definition-alist)))
6813 (setq methods (list methods)))
16409b0b
GM
6814 (when (and (null gnus-override-method)
6815 methods)
6816 (setq gnus-override-method (pop methods)))
6817 (while (not result)
6818 (when (eq gnus-override-method 'current)
c55f89a5
GM
6819 (setq gnus-override-method
6820 (with-current-buffer gnus-summary-buffer
6821 gnus-current-select-method)))
16409b0b
GM
6822 (erase-buffer)
6823 (gnus-kill-all-overlays)
6824 (let ((gnus-newsgroup-name group))
6825 (gnus-check-group-server))
23f87bed
MB
6826 (cond
6827 ((gnus-request-article article group (current-buffer))
16409b0b 6828 (when (numberp article)
a1506d29 6829 (gnus-async-prefetch-next group article
16409b0b
GM
6830 gnus-summary-buffer)
6831 (when gnus-keep-backlog
6832 (gnus-backlog-enter-article
6833 group article (current-buffer))))
6834 (setq result 'article))
23f87bed
MB
6835 (methods
6836 (setq gnus-override-method (pop methods)))
6837 ((not (string-match "^400 "
6838 (nnheader-get-report backend)))
6839 ;; If we get 400 server disconnect, reconnect and
6840 ;; retry; otherwise, assume the article has expired.
6841 (setq result 'done))))
16409b0b 6842 (and (eq result 'article) 'article)))
eec82323
LMI
6843 ;; It was a pseudo.
6844 (t article)))
6845
6748645f
LMI
6846 ;; Associate this article with the current summary buffer.
6847 (setq gnus-article-current-summary gnus-summary-buffer)
6848
eec82323
LMI
6849 ;; Take the article from the original article buffer
6850 ;; and place it in the buffer it's supposed to be in.
6851 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6852 (equal (buffer-name (current-buffer))
6853 (buffer-name (get-buffer gnus-article-buffer))))
6854 (save-excursion
6855 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6856 (set-buffer gnus-original-article-buffer)
6857 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6858 (buffer-disable-undo)
eec82323 6859 (setq major-mode 'gnus-original-article-mode)
6748645f 6860 (setq buffer-read-only t))
23f87bed 6861 (let ((inhibit-read-only t))
eec82323
LMI
6862 (erase-buffer)
6863 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6864 (setq gnus-original-article (cons group article)))
6865
6866 ;; Decode charsets.
6867 (run-hooks 'gnus-article-decode-hook)
6868 ;; Mark article as decoded or not.
6869 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6870
6871 ;; Update sparse articles.
6872 (when (and do-update-line
6873 (or (numberp article)
6874 (stringp article)))
6875 (let ((buf (current-buffer)))
6876 (set-buffer gnus-summary-buffer)
6748645f 6877 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6878 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6879 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6880 (point))
6881 (set-buffer buf))))))
6882
2526f423
G
6883(defun gnus-block-private-groups (group)
6884 (if (gnus-news-group-p group)
6885 ;; Block nothing in news groups.
6886 nil
6887 ;; Block everything anywhere else.
6888 "."))
6889
6890(defun gnus-blocked-images ()
6891 (if (functionp gnus-blocked-images)
6892 (funcall gnus-blocked-images gnus-newsgroup-name)
6893 gnus-blocked-images))
6894
eec82323
LMI
6895;;;
6896;;; Article editing
6897;;;
6898
6899(defcustom gnus-article-edit-mode-hook nil
6900 "Hook run in article edit mode buffers."
6901 :group 'gnus-article-various
6902 :type 'hook)
6903
6904(defvar gnus-article-edit-done-function nil)
6905
6906(defvar gnus-article-edit-mode-map nil)
6907
16409b0b 6908;; Should we be using derived.el for this?
eec82323 6909(unless gnus-article-edit-mode-map
23f87bed 6910 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6911 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6912
6913 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6914 "\C-c?" describe-mode
eec82323 6915 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6916 "\C-c\C-k" gnus-article-edit-exit
6917 "\C-c\C-f\C-t" message-goto-to
6918 "\C-c\C-f\C-o" message-goto-from
6919 "\C-c\C-f\C-b" message-goto-bcc
6920 ;;"\C-c\C-f\C-w" message-goto-fcc
6921 "\C-c\C-f\C-c" message-goto-cc
6922 "\C-c\C-f\C-s" message-goto-subject
6923 "\C-c\C-f\C-r" message-goto-reply-to
6924 "\C-c\C-f\C-n" message-goto-newsgroups
6925 "\C-c\C-f\C-d" message-goto-distribution
6926 "\C-c\C-f\C-f" message-goto-followup-to
6927 "\C-c\C-f\C-m" message-goto-mail-followup-to
6928 "\C-c\C-f\C-k" message-goto-keywords
6929 "\C-c\C-f\C-u" message-goto-summary
6930 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6931 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6932 "\C-c\C-b" message-goto-body
6933 "\C-c\C-i" message-goto-signature
6934
6935 "\C-c\C-t" message-insert-to
6936 "\C-c\C-n" message-insert-newsgroups
6937 "\C-c\C-o" message-sort-headers
6938 "\C-c\C-e" message-elide-region
6939 "\C-c\C-v" message-delete-not-region
6940 "\C-c\C-z" message-kill-to-signature
6941 "\M-\r" message-newline-and-reformat
6942 "\C-c\C-a" mml-attach-file
6943 "\C-a" message-beginning-of-line
6944 "\t" message-tab
6945 "\M-;" comment-region)
eec82323
LMI
6946
6947 (gnus-define-keys (gnus-article-edit-wash-map
6948 "\C-c\C-w" gnus-article-edit-mode-map)
6949 "f" gnus-article-edit-full-stops))
6950
23f87bed
MB
6951(easy-menu-define
6952 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6953 '("Field"
6954 ["Fetch To" message-insert-to t]
6955 ["Fetch Newsgroups" message-insert-newsgroups t]
6956 "----"
6957 ["To" message-goto-to t]
6958 ["From" message-goto-from t]
6959 ["Subject" message-goto-subject t]
6960 ["Cc" message-goto-cc t]
6961 ["Reply-To" message-goto-reply-to t]
6962 ["Summary" message-goto-summary t]
6963 ["Keywords" message-goto-keywords t]
6964 ["Newsgroups" message-goto-newsgroups t]
6965 ["Followup-To" message-goto-followup-to t]
6966 ["Mail-Followup-To" message-goto-mail-followup-to t]
6967 ["Distribution" message-goto-distribution t]
6968 ["Body" message-goto-body t]
6969 ["Signature" message-goto-signature t]))
6970
4e7d0221 6971(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6972 "Major mode for editing articles.
6973This is an extended text-mode.
6974
6975\\{gnus-article-edit-mode-map}"
eec82323
LMI
6976 (make-local-variable 'gnus-article-edit-done-function)
6977 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6978 (set (make-local-variable 'font-lock-defaults)
6979 '(message-font-lock-keywords t))
23f87bed
MB
6980 (set (make-local-variable 'mail-header-separator) "")
6981 (set (make-local-variable 'gnus-article-edit-mode) t)
6982 (easy-menu-add message-mode-field-menu message-mode-map)
6983 (mml-mode)
eec82323
LMI
6984 (setq buffer-read-only nil)
6985 (buffer-enable-undo)
80b47379 6986 (widen))
eec82323
LMI
6987
6988(defun gnus-article-edit (&optional force)
6989 "Edit the current article.
6990This will have permanent effect only in mail groups.
6991If FORCE is non-nil, allow editing of articles even in read-only
6992groups."
6993 (interactive "P")
6994 (when (and (not force)
6995 (gnus-group-read-only-p))
a8151ef7 6996 (error "The current newsgroup does not support article editing"))
6748645f 6997 (gnus-article-date-original)
eec82323 6998 (gnus-article-edit-article
16409b0b 6999 'ignore
6748645f 7000 `(lambda (no-highlight)
16409b0b 7001 'ignore
eec82323
LMI
7002 (gnus-summary-edit-article-done
7003 ,(or (mail-header-references gnus-current-headers) "")
6748645f 7004 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 7005
01c52d31 7006(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
7007 "Start editing the contents of the current article buffer."
7008 (let ((winconf (current-window-configuration)))
7009 (set-buffer gnus-article-buffer)
0683d241
MB
7010 (let ((message-auto-save-directory
7011 ;; Don't associate the article buffer with a draft file.
7012 nil))
7013 (gnus-article-edit-mode))
16409b0b 7014 (funcall start-func)
23f87bed 7015 (set-buffer-modified-p nil)
eec82323
LMI
7016 (gnus-configure-windows 'edit-article)
7017 (setq gnus-article-edit-done-function exit-func)
7018 (setq gnus-prev-winconf winconf)
01c52d31
MB
7019 (unless quiet
7020 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 7021
6748645f 7022(defun gnus-article-edit-done (&optional arg)
eec82323 7023 "Update the article edits and exit."
6748645f 7024 (interactive "P")
eec82323
LMI
7025 (let ((func gnus-article-edit-done-function)
7026 (buf (current-buffer))
23f87bed
MB
7027 (start (window-start))
7028 (p (point))
7029 (winconf gnus-prev-winconf))
7030 (widen) ;; Widen it in case that users narrowed the buffer.
7031 (funcall func arg)
7032 (set-buffer buf)
7033 ;; The cache and backlog have to be flushed somewhat.
7034 (when gnus-keep-backlog
7035 (gnus-backlog-remove-article
7036 (car gnus-article-current) (cdr gnus-article-current)))
7037 ;; Flush original article as well.
8ccbef23 7038 (gnus-flush-original-article-buffer)
23f87bed
MB
7039 (when gnus-use-cache
7040 (gnus-cache-update-article
7041 (car gnus-article-current) (cdr gnus-article-current)))
7042 ;; We remove all text props from the article buffer.
7043 (kill-all-local-variables)
01c52d31 7044 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
7045 (gnus-article-mode)
7046 (set-window-configuration winconf)
eec82323
LMI
7047 (set-buffer buf)
7048 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
7049 (set-window-point (get-buffer-window buf) (point)))
7050 (gnus-summary-show-article))
eec82323 7051
8ccbef23
G
7052(defun gnus-flush-original-article-buffer ()
7053 (when (get-buffer gnus-original-article-buffer)
7054 (with-current-buffer gnus-original-article-buffer
7055 (setq gnus-original-article nil))))
7056
eec82323
LMI
7057(defun gnus-article-edit-exit ()
7058 "Exit the article editing without updating."
7059 (interactive)
23f87bed
MB
7060 (when (or (not (buffer-modified-p))
7061 (yes-or-no-p "Article modified; kill anyway? "))
7062 (let ((curbuf (current-buffer))
7063 (p (point))
7064 (window-start (window-start)))
7065 (erase-buffer)
7066 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 7067 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
7068 (let ((winconf gnus-prev-winconf))
7069 (kill-all-local-variables)
7070 (gnus-article-mode)
7071 (set-window-configuration winconf)
7072 ;; Tippy-toe some to make sure that point remains where it was.
7073 (save-current-buffer
7074 (set-buffer curbuf)
7075 (set-window-start (get-buffer-window (current-buffer)) window-start)
7076 (goto-char p))))
7077 (gnus-summary-show-article)))
eec82323
LMI
7078
7079(defun gnus-article-edit-full-stops ()
7080 "Interactively repair spacing at end of sentences."
7081 (interactive)
7082 (save-excursion
7083 (goto-char (point-min))
7084 (search-forward-regexp "^$" nil t)
7085 (let ((case-fold-search nil))
7086 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7087
7088;;;
7089;;; Article highlights
7090;;;
7091
7092;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7093
7094;;; Internal Variables:
7095
a1506d29 7096(defcustom gnus-button-url-regexp
01c52d31
MB
7097 (concat
7098 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7099 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7100 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7101 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7102 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7103 (punct "!?:;.,"))
7104 (concat
7105 "\\(?:"
7106 ;; Match paired parentheses, e.g. in Wikipedia URLs:
9b3ebcb6
MB
7107 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7108 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
01c52d31
MB
7109 "\\|"
7110 "[" chars punct "]+" "[" chars "]"
7111 "\\)"))
7112 (concat ;; XEmacs 21.4 doesn't support POSIX.
7113 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7114 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7115 "\\)")
eec82323
LMI
7116 "Regular expression that matches URLs."
7117 :group 'gnus-article-buttons
7118 :type 'regexp)
7119
23f87bed
MB
7120(defcustom gnus-button-valid-fqdn-regexp
7121 message-valid-fqdn-regexp
7122 "Regular expression that matches a valid FQDN."
bf247b6e 7123 :version "22.1"
23f87bed
MB
7124 :group 'gnus-article-buttons
7125 :type 'regexp)
7126
97f78c9b
MB
7127;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7128(defcustom gnus-button-valid-localpart-regexp
14e6dc54 7129 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
7130 "Regular expression that matches a localpart of mail addresses or MIDs."
7131 :version "22.1"
7132 :group 'gnus-article-buttons
7133 :type 'regexp)
7134
23f87bed
MB
7135(defcustom gnus-button-man-handler 'manual-entry
7136 "Function to use for displaying man pages.
7137The function must take at least one argument with a string naming the
7138man page."
bf247b6e 7139 :version "22.1"
23f87bed
MB
7140 :type '(choice (function-item :tag "Man" manual-entry)
7141 (function-item :tag "Woman" woman)
7142 (function :tag "Other"))
7143 :group 'gnus-article-buttons)
7144
23f87bed 7145(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 7146 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
7147 gnus-button-valid-fqdn-regexp
7148 ">?\\)\\b")
7149 "Regular expression that matches a message ID or a mail address."
bf247b6e 7150 :version "22.1"
23f87bed
MB
7151 :group 'gnus-article-buttons
7152 :type 'regexp)
7153
7154(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7155 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7156Strings like this can be either a message ID or a mail address. If it is one
7157of the symbols `mid' or `mail', Gnus will always assume that the string is a
7158message ID or a mail address, respectively. If this variable is set to the
7159symbol `ask', always query the user what do do. If it is a function, this
aa819354 7160function will be called with the string as its only argument. The function
23f87bed 7161must return `mid', `mail', `invalid' or `ask'."
bf247b6e 7162 :version "22.1"
23f87bed
MB
7163 :group 'gnus-article-buttons
7164 :type '(choice (function-item :tag "Heuristic function"
7165 gnus-button-mid-or-mail-heuristic)
7166 (const ask)
7167 (const mid)
7168 (const mail)))
7169
7170(defcustom gnus-button-mid-or-mail-heuristic-alist
7171 '((-10.0 . ".+\\$.+@")
7172 (-10.0 . "#")
7173 (-10.0 . "\\*")
7174 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7175 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7176 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7177 (-1.0 . "^[^a-z]+@")
7178 ;;
7179 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7180 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7181 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7182 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7183 ;;
7184 (-2.0 . "^[0-9]")
7185 (-1.0 . "^[0-9][0-9]")
7186 ;;
7187 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7188 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7189 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7190 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7191 ;;
7192 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7193 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7194 ;; "[0-9]{8,}.*\@"
7195 (-3.0
7196 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7197 ;; "[0-9]{12,}.*\@"
7198 ;; compensation for TDMA dated mail addresses:
7199 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7200 ;;
7201 (-20.0 . "\\.fsf@") ;; Gnus
7202 (-20.0 . "^slrn")
7203 (-20.0 . "^Pine")
437ce4be 7204 (-20.0 . "^alpine\\.")
23f87bed
MB
7205 (-20.0 . "_-_") ;; Subject change in thread
7206 ;;
7207 (-20.0 . "\\.ln@") ;; leafnode
7208 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7209 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7210 ;;
7211 ;; (5.0 . "") ;; $local_part_len <= 7
7212 (10.0 . "^[^0-9]+@")
7213 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7214 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7215 (3.0 . "\@stud")
7216 ;;
7217 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7218 ;;
7219 (0.5 . "^[A-Z][a-z]")
7220 (0.5 . "^[A-Z][a-z][a-z]")
7221 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7222 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7223 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7224
7225A negative RATE indicates a message IDs, whereas a positive indicates a mail
7226address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7227 :version "22.1"
23f87bed
MB
7228 :group 'gnus-article-buttons
7229 :type '(repeat (cons (number :tag "Rate")
7230 (regexp :tag "Regexp"))))
7231
7232(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7233 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7234Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7235address, `ask' if unsure and `invalid' if the string is invalid."
7236 (let ((case-fold-search nil)
7237 (list gnus-button-mid-or-mail-heuristic-alist)
7238 (result 0) rate regexp lpartlen elem)
7239 (setq lpartlen
7240 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7241 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7242 ;; Certain special cases...
7243 (when (string-match
7244 (concat
7245 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7246 "^[0-9]+\\.[0-9]+@compuserve\\|"
7247 "@public\\.gmane\\.org")
7248 mid-or-mail)
7249 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7250 (setq result 'mail))
7251 (when (string-match "@.*@\\| " mid-or-mail)
7252 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7253 (setq result 'invalid))
7254 ;; Nothing more to do, if result is not a number here...
7255 (when (numberp result)
7256 (while list
7257 (setq elem (car list)
7258 rate (car elem)
7259 regexp (cdr elem)
7260 list (cdr list))
7261 (when (string-match regexp mid-or-mail)
7262 (setq result (+ result rate))
7263 (gnus-message
7264 9 "`%s' matched `%s', rate `%s', result `%s'."
7265 mid-or-mail regexp rate result)))
7266 (when (<= lpartlen 7)
7267 (setq result (+ result 5.0))
7268 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7269 mid-or-mail result))
7270 (when (>= lpartlen 12)
7271 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7272 (cond
7273 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7274 ;; Long local part should contain realname if e-mail address,
7275 ;; too many digits: message-id.
7276 ;; $score -= 5.0 + 0.1 * $local_part_len;
7277 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7278 (setq result (+ result rate))
7279 (gnus-message
7280 9 "Many digits in `%s', rate `%s', result `%s'."
7281 mid-or-mail rate result))
7282 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7283 mid-or-mail)
7284 ;; Too few vowels [^aeiouy]{4,}.*\@
7285 (setq result (+ result -5.0))
7286 (gnus-message
7287 9 "Few vowels in `%s', rate `%s', result `%s'."
7288 mid-or-mail -5.0 result))
7289 (t
7290 (setq result (+ result 5.0))
7291 (gnus-message
7292 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7293 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7294 ;; Maybe we should make this a customizable alist: (condition . 'result)
7295 (cond
7296 ((symbolp result) result)
7297 ;; Now convert number into proper results:
7298 ((< result -10.0) 'mid)
7299 ((> result 10.0) 'mail)
7300 (t 'ask))))
7301
7302(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7303 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7304 (url-mid (concat "news" ":" mid-or-mail))
7305 (url-mailto (concat "mailto" ":" mid-or-mail)))
7306 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7307 (when (fboundp pref)
7308 (setq guessed
7309 ;; get rid of surrounding angles...
7310 (funcall pref
7311 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7312 (if (or (eq 'mid guessed) (eq 'mail guessed))
7313 (setq pref guessed)
7314 (setq pref 'ask)))
7315 (if (eq pref 'ask)
7316 (save-window-excursion
7317 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7318 (setq pref 'mail)
7319 (setq pref 'mid))))
7320 (cond ((eq pref 'mid)
7321 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7322 (gnus-button-handle-news url-mid))
7323 ((eq pref 'mail)
7324 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7325 (gnus-url-mailto url-mailto))
7326 (t (gnus-message 3 "Invalid string.")))))
7327
01c52d31
MB
7328(defun gnus-button-handle-custom (fun arg)
7329 "Call function FUN on argument ARG.
7330Both FUN and ARG are supposed to be strings. ARG will be passed
7331as a symbol to FUN."
7332 (funcall (intern fun)
7333 (if (string-match "^customize-apropos" fun)
7334 arg
7335 (intern arg))))
23f87bed
MB
7336
7337(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7338
7339;; FIXME: Maybe we should merge some of the functions that do quite similar
7340;; stuff?
7341
7342(defun gnus-button-handle-describe-function (url)
7343 "Call `describe-function' when pushing the corresponding URL button."
7344 (describe-function
7345 (intern
7346 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7347
7348(defun gnus-button-handle-describe-variable (url)
7349 "Call `describe-variable' when pushing the corresponding URL button."
7350 (describe-variable
7351 (intern
7352 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7353
7354(defun gnus-button-handle-symbol (url)
7355"Display help on variable or function.
7356Calls `describe-variable' or `describe-function'."
7357 (let ((sym (intern url)))
7358 (cond
7359 ((fboundp sym) (describe-function sym))
7360 ((boundp sym) (describe-variable sym))
7361 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7362
7363(defun gnus-button-handle-describe-key (url)
7364 "Call `describe-key' when pushing the corresponding URL button."
7365 (let* ((key-string
7366 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7367 (keys (ignore-errors (eval `(kbd ,key-string)))))
7368 (if keys
7369 (describe-key keys)
7370 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7371
7372(defun gnus-button-handle-apropos (url)
7373 "Call `apropos' when pushing the corresponding URL button."
7374 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7375
7376(defun gnus-button-handle-apropos-command (url)
7377 "Call `apropos' when pushing the corresponding URL button."
7378 (apropos-command
7379 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7380
7381(defun gnus-button-handle-apropos-variable (url)
7382 "Call `apropos' when pushing the corresponding URL button."
7383 (funcall
7384 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7385 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7386
7387(defun gnus-button-handle-apropos-documentation (url)
7388 "Call `apropos' when pushing the corresponding URL button."
7389 (funcall
7390 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7391 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7392
7393(defun gnus-button-handle-library (url)
7394 "Call `locate-library' when pushing the corresponding URL button."
7395 (gnus-message 9 "url=`%s'" url)
7396 (let* ((lib (locate-library url))
7397 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7398 (if (not lib)
7399 (gnus-message 1 "Cannot locale library `%s'." url)
7400 (find-file-read-only file))))
7401
23f87bed
MB
7402(defcustom gnus-button-man-level 5
7403 "*Integer that says how many man-related buttons Gnus will show.
7404The higher the number, the more buttons will appear and the more false
7405positives are possible. Note that you can set this variable local to
7406specific groups. Setting it higher in Unix groups is probably a good idea.
7407See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7408how to set variables in specific groups."
bf247b6e 7409 :version "22.1"
23f87bed
MB
7410 :group 'gnus-article-buttons
7411 :link '(custom-manual "(gnus)Group Parameters")
7412 :type 'integer)
7413
7414(defcustom gnus-button-emacs-level 5
7415 "*Integer that says how many emacs-related buttons Gnus will show.
7416The higher the number, the more buttons will appear and the more false
7417positives are possible. Note that you can set this variable local to
7418specific groups. Setting it higher in Emacs or Gnus related groups is
7419probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7420`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7421 :version "22.1"
23f87bed
MB
7422 :group 'gnus-article-buttons
7423 :link '(custom-manual "(gnus)Group Parameters")
7424 :type 'integer)
7425
7426(defcustom gnus-button-message-level 5
7427 "*Integer that says how many buttons for news or mail messages will appear.
7428The higher the number, the more buttons will appear and the more false
7429positives are possible."
7430 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7431 :version "22.1"
23f87bed
MB
7432 :group 'gnus-article-buttons
7433 :type 'integer)
7434
7435(defcustom gnus-button-browse-level 5
7436 "*Integer that says how many buttons for browsing will appear.
7437The higher the number, the more buttons will appear and the more false
7438positives are possible."
7439 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7440 :version "22.1"
23f87bed
MB
7441 :group 'gnus-article-buttons
7442 :type 'integer)
7443
eec82323 7444(defcustom gnus-button-alist
23f87bed
MB
7445 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7446 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7447 ((concat "\\b\\(nntp\\|news\\):\\("
7448 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7449 0 t gnus-button-handle-news 2)
23f87bed
MB
7450 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7451 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7452 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7453 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7454 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7455 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7456 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7457 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7458 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7459 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7460 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7461 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7462 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7463 ;; RFC 2368 (The mailto URL scheme)
531e5812 7464 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7465 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7466 ("\\bmailto:\\([^ \n\t]+\\)"
7467 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
9eb59592
MB
7468 ;; Info Konqueror style <info:/foo/bar baz>.
7469 ;; Must come before " Gnus home-grown style".
7470 ("\\binfo://?\\([^'\">\n\t]+\\)"
7471 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7472 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
23f87bed
MB
7473 ("\\binfo://\\([^'\">\n\t ]+\\)"
7474 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7475 ;; Info GNOME style <info:foo#bar_baz>
7476 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7477 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7478 ;; Info KDE style <info:(foo)bar baz>
7479 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7480 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7481 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7482 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
9b3ebcb6
MB
7483 ("\\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,]*\\)\\)?"
7484 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7485 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
23f87bed 7486 ;; This is custom
e425f18b 7487 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
01c52d31 7488 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed 7489 ;; Emacs help commands
e425f18b 7490 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed
MB
7491 ;; regexp doesn't match arguments containing ` '.
7492 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
e425f18b 7493 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed 7494 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
e425f18b 7495 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed 7496 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
e425f18b 7497 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed
MB
7498 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7499 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7500 ;; them by default (use a high button level).
7501 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7502 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7503 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7504 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7505 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7506 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7507 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7508 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7509 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7510 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7511 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
e425f18b 7512 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed 7513 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
e425f18b 7514 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed 7515 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
e425f18b 7516 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
23f87bed 7517 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7518 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7519 ;; Unlike the other regexps we really have to require quoting
7520 ;; here to determine where it ends.
7521 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7522 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7523 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7524 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7525 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7526 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7527 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7528 ;; Raw URLs.
23f87bed
MB
7529 (gnus-button-url-regexp
7530 0 (>= gnus-button-browse-level 0) browse-url 0)
7531 ;; man pages
531e5812 7532 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7533 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7534 gnus-button-handle-man 1)
7535 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7536 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7537 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7538 gnus-button-handle-man 1)
7539 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7540 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7541 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7542 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7543 ;; Recognizing patches to .el files. This is somewhat obscure,
7544 ;; but considering the percentage of Gnus users who hack Emacs
7545 ;; Lisp files...
7546 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7547 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7548 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7549 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7550 ;; MID or mail: To avoid too many false positives we don't try to catch
7551 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7552 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7553 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7554 ;; so that non-ambiguous entries (see above) match first.
7555 (gnus-button-mid-or-mail-regexp
7556 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7557 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7558
7559Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7560REGEXP: is the string (case insensitive) matching text around the button (can
7561also be Lisp expression evaluating to a string),
eec82323 7562BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7563FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7564be added,
7565CALLBACK: is the function to call when the user push this button, and each
7566PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7567
7568CALLBACK can also be a variable, in that case the value of that
7569variable it the real callback function."
7570 :group 'gnus-article-buttons
23f87bed 7571 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7572 (integer :tag "Button")
7573 (sexp :tag "Form")
7574 (function :tag "Callback")
7575 (repeat :tag "Par"
7576 :inline t
7577 (integer :tag "Regexp group")))))
60ece9b0 7578(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7579
7580(defcustom gnus-header-button-alist
23f87bed
MB
7581 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7582 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7583 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7584 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7585 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7586 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7587 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7588 0 (>= gnus-button-browse-level 0) browse-url 0)
7589 ("^Subject:" gnus-button-url-regexp
7590 0 (>= gnus-button-browse-level 0) browse-url 0)
7591 ("^[^:]+:" gnus-button-url-regexp
7592 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7593 ("^OpenPGP:.*url=" gnus-button-url-regexp
7594 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7595 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7596 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7597 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7598 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7599 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7600
7601This alist is very similar to `gnus-button-alist', except that each
7602alist has an additional HEADER element first in each entry:
7603
7604\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7605
7606HEADER is a regexp to match a header. For a fuller explanation, see
7607`gnus-button-alist'."
7608 :group 'gnus-article-buttons
7609 :group 'gnus-article-headers
7610 :type '(repeat (list (regexp :tag "Header")
23f87bed 7611 (choice regexp variable)
eec82323
LMI
7612 (integer :tag "Button")
7613 (sexp :tag "Form")
7614 (function :tag "Callback")
7615 (repeat :tag "Par"
7616 :inline t
7617 (integer :tag "Regexp group")))))
60ece9b0 7618(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7619
eec82323
LMI
7620;;; Commands:
7621
7622(defun gnus-article-push-button (event)
7623 "Check text under the mouse pointer for a callback function.
7624If the text under the mouse pointer has a `gnus-callback' property,
7625call it with the value of the `gnus-data' text property."
7626 (interactive "e")
7627 (set-buffer (window-buffer (posn-window (event-start event))))
7628 (let* ((pos (posn-point (event-start event)))
23f87bed 7629 (data (get-text-property pos 'gnus-data))
eec82323 7630 (fun (get-text-property pos 'gnus-callback)))
6748645f 7631 (goto-char pos)
eec82323
LMI
7632 (when fun
7633 (funcall fun data))))
7634
7635(defun gnus-article-press-button ()
7636 "Check text at point for a callback function.
7637If the text at point has a `gnus-callback' property,
7638call it with the value of the `gnus-data' text property."
7639 (interactive)
23f87bed
MB
7640 (let ((data (get-text-property (point) 'gnus-data))
7641 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7642 (when fun
7643 (funcall fun data))))
7644
eec82323
LMI
7645(defun gnus-article-highlight (&optional force)
7646 "Highlight current article.
7647This function calls `gnus-article-highlight-headers',
7648`gnus-article-highlight-citation',
7649`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7650do the highlighting. See the documentation for those functions."
7651 (interactive (list 'force))
7652 (gnus-article-highlight-headers)
7653 (gnus-article-highlight-citation force)
7654 (gnus-article-highlight-signature)
a2e3ac99 7655 (gnus-article-add-buttons)
eec82323
LMI
7656 (gnus-article-add-buttons-to-head))
7657
7658(defun gnus-article-highlight-some (&optional force)
7659 "Highlight current article.
7660This function calls `gnus-article-highlight-headers',
7661`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7662do the highlighting. See the documentation for those functions."
7663 (interactive (list 'force))
7664 (gnus-article-highlight-headers)
7665 (gnus-article-highlight-signature)
7666 (gnus-article-add-buttons))
7667
7668(defun gnus-article-highlight-headers ()
7669 "Highlight article headers as specified by `gnus-header-face-alist'."
7670 (interactive)
01c52d31
MB
7671 (gnus-with-article-headers
7672 (let (regexp header-face field-face from hpoints fpoints)
7673 (dolist (entry gnus-header-face-alist)
7674 (goto-char (point-min))
7675 (setq regexp (concat "^\\("
7676 (if (string-equal "" (nth 0 entry))
7677 "[^\t ]"
7678 (nth 0 entry))
7679 "\\)")
7680 header-face (nth 1 entry)
7681 field-face (nth 2 entry))
7682 (while (and (re-search-forward regexp nil t)
7683 (not (eobp)))
7684 (beginning-of-line)
7685 (setq from (point))
7686 (unless (search-forward ":" nil t)
7687 (forward-char 1))
7688 (when (and header-face
7689 (not (memq (point) hpoints)))
7690 (push (point) hpoints)
7691 (gnus-put-text-property from (point) 'face header-face))
7692 (when (and field-face
7693 (not (memq (setq from (point)) fpoints)))
7694 (push from fpoints)
7695 (if (re-search-forward "^[^ \t]" nil t)
7696 (forward-char -2)
7697 (goto-char (point-max)))
7698 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7699
7700(defun gnus-article-highlight-signature ()
7701 "Highlight the signature in an article.
7702It does this by highlighting everything after
0f49874b 7703`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7704 (interactive)
01c52d31
MB
7705 (gnus-with-article-buffer
7706 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7707 (save-restriction
7708 (when (and gnus-signature-face
7709 (gnus-article-narrow-to-signature))
01c52d31 7710 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7711 'face gnus-signature-face)
7712 (widen)
7713 (gnus-article-search-signature)
7714 (let ((start (match-beginning 0))
7715 (end (set-marker (make-marker) (1+ (match-end 0)))))
7716 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7717 end)))))))
7718
7719(defun gnus-button-in-region-p (b e prop)
7720 "Say whether PROP exists in the region."
7721 (text-property-not-all b e prop nil))
7722
672022e7 7723(defun gnus-article-add-buttons ()
eec82323
LMI
7724 "Find external references in the article and make buttons of them.
7725\"External references\" are things like Message-IDs and URLs, as
7726specified by `gnus-button-alist'."
672022e7 7727 (interactive)
01c52d31
MB
7728 (gnus-with-article-buffer
7729 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7730 (case-fold-search t)
7731 (alist gnus-button-alist)
7732 beg entry regexp)
eec82323 7733 ;; We skip the headers.
16409b0b 7734 (article-goto-body)
eec82323
LMI
7735 (setq beg (point))
7736 (while (setq entry (pop alist))
23f87bed 7737 (setq regexp (eval (car entry)))
eec82323
LMI
7738 (goto-char beg)
7739 (while (re-search-forward regexp nil t)
01c52d31
MB
7740 (let ((start (match-beginning (nth 1 entry)))
7741 (end (match-end (nth 1 entry)))
7742 (from (match-beginning 0)))
672022e7 7743 (when (and (eval (nth 2 entry))
eec82323
LMI
7744 (not (gnus-button-in-region-p
7745 start end 'gnus-callback)))
7746 ;; That optional form returned non-nil, so we add the
7747 ;; button.
01c52d31 7748 (setq from (set-marker (make-marker) from))
01c52d31
MB
7749 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7750 (gnus-article-extend-url-button from start end))
7751 (gnus-article-add-button start end
672022e7 7752 'gnus-button-push (list from entry))
7426b4f7
LMI
7753 (gnus-put-text-property
7754 start end
10e91ca9
LMI
7755 'gnus-string (buffer-substring-no-properties
7756 start end))))))))))
01c52d31
MB
7757
7758(defun gnus-article-extend-url-button (beg start end)
7759 "Extend url button if url is folded into two or more lines.
7760Return non-nil if button is extended. BEG is a marker that points to
7761the beginning position of a text containing url. START and END are
7762the endpoints of a url button before it is extended. The concatenated
7763url is put as the `gnus-button-url' overlay property on the button."
7764 (let ((opoint (point))
7765 (points (list start end))
7766 url delim regexp)
7767 (prog1
7768 (when (and (progn
7769 (goto-char end)
7770 (not (looking-at "[\t ]*[\">]")))
7771 (progn
7772 (goto-char start)
7773 (string-match
7774 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7775 (buffer-substring (point-at-bol) start)))
7776 (progn
7777 (setq url (list (buffer-substring start end))
7778 delim (if (match-beginning 1) ">" "\""))
7779 (beginning-of-line)
7780 (setq regexp (concat
7781 (when (and (looking-at
7782 message-cite-prefix-regexp)
7783 (< (match-end 0) start))
7784 (regexp-quote (match-string 0)))
7785 "\
7786\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7787 delim "\\)"))
7788 (while (progn
7789 (forward-line 1)
7790 (and (looking-at regexp)
7791 (prog1
7792 (match-beginning 1)
7793 (push (or (match-string 2)
7794 (match-string 1))
7795 url)
7796 (push (setq end (or (match-end 2)
7797 (match-end 1)))
7798 points)
7799 (push (or (match-beginning 2)
7800 (match-beginning 1))
7801 points)))))
7802 (match-beginning 2)))
7803 (let (gnus-article-mouse-face widget-mouse-face)
7804 (while points
7805 (gnus-article-add-button (pop points) (pop points)
7806 'gnus-button-push beg)))
7807 (let ((overlay (gnus-make-overlay start end)))
7808 (gnus-overlay-put overlay 'evaporate t)
7809 (gnus-overlay-put overlay 'gnus-button-url
7810 (list (mapconcat 'identity (nreverse url) "")))
7811 (when gnus-article-mouse-face
7812 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7813 t)
7814 (goto-char opoint))))
eec82323
LMI
7815
7816;; Add buttons to the head of an article.
7817(defun gnus-article-add-buttons-to-head ()
7818 "Add buttons to the head of the article."
7819 (interactive)
01c52d31
MB
7820 (gnus-with-article-headers
7821 (let (beg end)
7822 (dolist (entry gnus-header-button-alist)
7823 ;; Each alist entry.
7824 (goto-char (point-min))
7825 (while (re-search-forward (car entry) nil t)
7826 ;; Each header matching the entry.
7827 (setq beg (match-beginning 0))
7828 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7829 (match-beginning 0))
7830 (point-max)))
7831 (goto-char beg)
7832 (while (re-search-forward (eval (nth 1 entry)) end t)
7833 ;; Each match within a header.
7834 (let* ((entry (cdr entry))
7835 (start (match-beginning (nth 1 entry)))
7836 (end (match-end (nth 1 entry)))
7837 (form (nth 2 entry)))
7838 (goto-char (match-end 0))
7839 (when (eval form)
7840 (gnus-article-add-button
7841 start end (nth 3 entry)
7842 (buffer-substring (match-beginning (nth 4 entry))
7843 (match-end (nth 4 entry)))))))
7844 (goto-char end))))))
eec82323
LMI
7845
7846;;; External functions:
7847
b1992461 7848(defun gnus-article-add-button (from to fun &optional data text)
eec82323
LMI
7849 "Create a button between FROM and TO with callback FUN and data DATA."
7850 (when gnus-article-button-face
01c52d31 7851 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7852 'face gnus-article-button-face))
7853 (gnus-add-text-properties
7854 from to
7855 (nconc (and gnus-article-mouse-face
7856 (list gnus-mouse-face-prop gnus-article-mouse-face))
7857 (list 'gnus-callback fun)
16409b0b
GM
7858 (and data (list 'gnus-data data))))
7859 (widget-convert-button 'link from to :action 'gnus-widget-press-button
b1992461 7860 :help-echo (or text "Follow the link")
7426b4f7 7861 :keymap gnus-url-button-map
16409b0b 7862 :button-keymap gnus-widget-button-keymap))
eec82323 7863
7426b4f7
LMI
7864(defun gnus-article-copy-string ()
7865 "Copy the string in the button to the kill ring."
7866 (interactive)
7867 (gnus-article-check-buffer)
10e91ca9 7868 (let ((data (get-text-property (point) 'gnus-string)))
7426b4f7
LMI
7869 (when data
7870 (with-temp-buffer
7871 (insert data)
c25d60ab
LMI
7872 (copy-region-as-kill (point-min) (point-max))
7873 (message "Copied %s" data)))))
7426b4f7 7874
eec82323
LMI
7875;;; Internal functions:
7876
a8151ef7 7877(defun gnus-article-set-globals ()
01c52d31 7878 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7879 (gnus-set-global-variables)))
7880
eec82323 7881(defun gnus-signature-toggle (end)
01c52d31
MB
7882 (gnus-with-article-buffer
7883 (let ((inhibit-point-motion-hooks t))
520aa572 7884 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7885 (progn
7886 (gnus-delete-wash-type 'signature)
7887 (gnus-remove-text-properties-when
7888 'article-type 'signature end (point-max)
7889 (cons 'article-type (cons 'signature
7890 gnus-hidden-properties))))
7891 (gnus-add-wash-type 'signature)
520aa572
SZ
7892 (gnus-add-text-properties-when
7893 'article-type nil end (point-max)
7894 (cons 'article-type (cons 'signature
23f87bed
MB
7895 gnus-hidden-properties)))))
7896 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7897 (gnus-set-mode-line 'article))))
eec82323 7898
672022e7 7899(defun gnus-button-push (marker-and-entry)
eec82323
LMI
7900 ;; Push button starting at MARKER.
7901 (save-excursion
672022e7
G
7902 (let* ((marker (car marker-and-entry))
7903 (entry (cadr marker-and-entry))
7904 (regexp (car entry))
7905 (inhibit-point-motion-hooks t))
7906 (goto-char marker)
7907 ;; This is obviously true, or something bad is happening :)
7908 ;; But we need it to have the match-data
7909 (when (looking-at (or (if (symbolp regexp)
7910 (symbol-value regexp)
7911 regexp)))
7912 (let ((fun (nth 3 entry))
7913 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7914 (get-char-property marker 'gnus-button-url))
7915 (mapcar (lambda (group)
7916 (let ((string (match-string group)))
7917 (set-text-properties
7918 0 (length string) nil string)
7919 string))
7920 (nthcdr 4 entry)))))
7921
7922 (cond
7923 ((fboundp fun)
7924 (apply fun args))
7925 ((and (boundp fun)
7926 (fboundp (symbol-value fun)))
7927 (apply (symbol-value fun) args))
7928 (t
7929 (gnus-message 1 "You must define `%S' to use this button"
7930 (cons fun args)))))))))
eec82323 7931
23f87bed 7932(defun gnus-parse-news-url (url)
82a8ad04 7933 (let (scheme server port group message-id articles)
23f87bed
MB
7934 (with-temp-buffer
7935 (insert url)
7936 (goto-char (point-min))
7937 (when (looking-at "\\([A-Za-z]+\\):")
7938 (setq scheme (match-string 1))
7939 (goto-char (match-end 0)))
82a8ad04 7940 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7941 (setq server (match-string 1))
82a8ad04
MB
7942 (setq port (if (stringp (match-string 3))
7943 (string-to-number (match-string 3))
7944 (match-string 3)))
23f87bed
MB
7945 (goto-char (match-end 0)))
7946
7947 (cond
7948 ((looking-at "\\(.*@.*\\)")
7949 (setq message-id (match-string 1)))
7950 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7951 (setq group (match-string 1)
7952 articles (split-string (match-string 2) "-")))
7953 ((looking-at "\\([^/]+\\)/?")
7954 (setq group (match-string 1)))
7955 (t
7956 (error "Unknown news URL syntax"))))
82a8ad04 7957 (list scheme server port group message-id articles)))
23f87bed
MB
7958
7959(defun gnus-button-handle-news (url)
7960 "Fetch a news URL."
82a8ad04 7961 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7962 (gnus-parse-news-url url)
7963 (cond
7964 (message-id
80de1778 7965 (with-current-buffer gnus-summary-buffer
23f87bed 7966 (if server
ff4d3926
MB
7967 (let ((gnus-refer-article-method
7968 (nconc (list (list 'nntp server))
7969 gnus-refer-article-method))
82a8ad04 7970 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7971 (gnus-message 7 "Fetching %s with %s"
7972 message-id gnus-refer-article-method)
23f87bed
MB
7973 (gnus-summary-refer-article message-id))
7974 (gnus-summary-refer-article message-id))))
7975 (group
7976 (gnus-button-fetch-group url)))))
7977
01c52d31
MB
7978(defun gnus-button-patch (library line)
7979 "Visit an Emacs Lisp library LIBRARY on line LINE."
7980 (interactive)
7981 (let ((file (locate-library (file-name-nondirectory library))))
7982 (unless file
7983 (error "Couldn't find library %s" library))
7984 (find-file file)
5dcc825f
GM
7985 (goto-char (point-min))
7986 (forward-line (1- (string-to-number line)))))
01c52d31 7987
23f87bed
MB
7988(defun gnus-button-handle-man (url)
7989 "Fetch a man page."
531e5812
MB
7990 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7991 (when (eq gnus-button-man-handler 'woman)
7992 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7993 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
7994 (funcall gnus-button-man-handler url))
7995
7996(defun gnus-button-handle-info-url (url)
7997 "Fetch an info URL."
7998 (setq url (mm-subst-char-in-string ?+ ?\ url))
7999 (cond
8000 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8001 (gnus-info-find-node
8002 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8003 "Gnus")
8004 ")" (gnus-url-unhex-string (match-string 2 url)))))
8005 ((string-match "([^)\"]+)[^\"]+" url)
8006 (setq url
8007 (gnus-replace-in-string
8008 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8009 (gnus-info-find-node url))
8010 (t (error "Can't parse %s" url))))
8011
8012(defun gnus-button-handle-info-url-gnome (url)
8013 "Fetch GNOME style info URL."
8014 (setq url (mm-subst-char-in-string ?_ ?\ url))
8015 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8016 (gnus-info-find-node
8017 (concat "("
bf247b6e 8018 (gnus-url-unhex-string
23f87bed
MB
8019 (match-string 1 url))
8020 ")"
bf247b6e 8021 (or (gnus-url-unhex-string
23f87bed
MB
8022 (match-string 2 url))
8023 "Top")))
8024 (error "Can't parse %s" url)))
8025
8026(defun gnus-button-handle-info-url-kde (url)
8027 "Fetch KDE style info URL."
8028 (gnus-info-find-node (gnus-url-unhex-string url)))
8029
9640c3bc
GM
8030;; (info) will autoload info.el
8031(declare-function Info-menu "info" (menu-item &optional fork))
9b3ebcb6 8032(declare-function Info-index-next "info" (num))
9640c3bc 8033
23f87bed
MB
8034(defun gnus-button-handle-info-keystrokes (url)
8035 "Call `info' when pushing the corresponding URL button."
9b3ebcb6
MB
8036 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8037 (let (node indx comma)
8038 (if (string-match
8039 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8040 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
e425f18b 8041 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
9b3ebcb6
MB
8042 "\\(?:[ \t\n,]*\\)\\)?")
8043 url)
8044 (setq node (match-string 2 url)
8045 indx (match-string 3 url))
8046 (error "Can't parse %s" url))
8047 (info)
8048 (Info-directory)
8049 (Info-menu node)
8050 (when (> (length indx) 0)
e425f18b 8051 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
9b3ebcb6
MB
8052 "\\([ \t\n,]*\\)")
8053 indx)
8054 (setq comma (match-string 2 indx))
8055 (setq indx (match-string 1 indx))
8056 (Info-index indx)
8057 (when comma
8058 (dotimes (i (with-temp-buffer
8059 (insert comma)
8060 ;; Note: the XEmacs version of `how-many' takes
8061 ;; no optional argument.
8062 (goto-char (point-min))
8063 (how-many ",")))
8064 (Info-index-next 1)))
8065 nil)))
1888e568 8066
9d9cfd53 8067(autoload 'pgg-snarf-keys-region "pgg")
1888e568
GM
8068;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8069(declare-function pgg-display-output-buffer "pgg" (start end status))
23f87bed 8070
01c52d31
MB
8071(defun gnus-button-openpgp (url)
8072 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8073 (with-temp-buffer
8074 (mm-url-insert-file-contents-external url)
8075 (pgg-snarf-keys-region (point-min) (point-max))
8076 (pgg-display-output-buffer nil nil nil)))
8077
eec82323
LMI
8078(defun gnus-button-message-id (message-id)
8079 "Fetch MESSAGE-ID."
01c52d31 8080 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8081 (gnus-summary-refer-article message-id)))
8082
01c52d31 8083(defun gnus-button-fetch-group (address &rest ignore)
eec82323 8084 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
8085 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8086 address)
8087 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8088 ;; for nntp:// and news://
8089 (setq address (match-string 3 address)))
eec82323
LMI
8090 (if (not (string-match "[:/]" address))
8091 ;; This is just a simple group url.
8092 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
8093 (if (not
8094 (string-match
8095 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8096 address))
eec82323
LMI
8097 (error "Can't parse %s" address)
8098 (gnus-group-read-ephemeral-group
8099 (match-string 4 address)
8100 `(nntp ,(match-string 1 address)
8101 (nntp-address ,(match-string 1 address))
8102 (nntp-port-number ,(if (match-end 3)
8103 (match-string 3 address)
23f87bed
MB
8104 "nntp")))
8105 nil nil nil
e9bd5782 8106 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 8107
eec82323
LMI
8108(defun gnus-url-parse-query-string (query &optional downcase)
8109 (let (retval pairs cur key val)
16409b0b 8110 (setq pairs (split-string query "&"))
eec82323
LMI
8111 (while pairs
8112 (setq cur (car pairs)
23f87bed 8113 pairs (cdr pairs))
eec82323 8114 (if (not (string-match "=" cur))
23f87bed
MB
8115 nil ; Grace
8116 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8117 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8118 (if downcase
8119 (setq key (downcase key)))
8120 (setq cur (assoc key retval))
8121 (if cur
8122 (setcdr cur (cons val (cdr cur)))
8123 (setq retval (cons (list key val) retval)))))
eec82323
LMI
8124 retval))
8125
eec82323
LMI
8126(defun gnus-url-mailto (url)
8127 ;; Send mail to someone
1e91d0eb 8128 (setq url (replace-regexp-in-string "\n" " " url))
eec82323
LMI
8129 (when (string-match "mailto:/*\\(.*\\)" url)
8130 (setq url (substring url (match-beginning 1) nil)))
6748645f 8131 (let (to args subject func)
23f87bed
MB
8132 (setq args (gnus-url-parse-query-string
8133 (if (string-match "^\\?" url)
8134 (substring url 1)
8135 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8136 (concat "to=" (match-string 1 url) "&"
8137 (match-string 2 url))
440b1345 8138 (concat "to=" url))))
23f87bed
MB
8139 subject (cdr-safe (assoc "subject" args)))
8140 (gnus-msg-mail)
eec82323
LMI
8141 (while args
8142 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8143 (if (fboundp func)
23f87bed
MB
8144 (funcall func)
8145 (message-position-on-field (caar args)))
8146 (insert (gnus-replace-in-string
8147 (mapconcat 'identity (reverse (cdar args)) ", ")
8148 "\r\n" "\n" t))
eec82323
LMI
8149 (setq args (cdr args)))
8150 (if subject
23f87bed 8151 (message-goto-body)
eec82323
LMI
8152 (message-goto-subject))))
8153
eec82323 8154(defun gnus-button-embedded-url (address)
e0bad764 8155 "Activate ADDRESS with `browse-url'."
1b978bfc 8156 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
8157
8158;;; Next/prev buttons in the article buffer.
8159
8160(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8161(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8162
23f87bed
MB
8163(defvar gnus-prev-page-map
8164 (let ((map (make-sparse-keymap)))
23f87bed
MB
8165 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8166 (define-key map "\r" 'gnus-button-prev-page)
8167 map))
8168
8169(defvar gnus-next-page-map
8170 (let ((map (make-sparse-keymap)))
23f87bed
MB
8171 (define-key map gnus-mouse-2 'gnus-button-next-page)
8172 (define-key map "\r" 'gnus-button-next-page)
8173 map))
eec82323
LMI
8174
8175(defun gnus-insert-prev-page-button ()
01c52d31 8176 (let ((b (point)) e
23f87bed 8177 (inhibit-read-only t))
eec82323
LMI
8178 (gnus-eval-format
8179 gnus-prev-page-line-format nil
01c52d31
MB
8180 `(keymap ,gnus-prev-page-map
8181 gnus-prev t
8182 gnus-callback gnus-article-button-prev-page
8183 article-type annotation))
8184 (setq e (if (bolp)
8185 ;; Exclude a newline.
8186 (1- (point))
8187 (point)))
8188 (when gnus-article-button-face
8189 (gnus-overlay-put (gnus-make-overlay b e nil t)
8190 'face gnus-article-button-face))
23f87bed 8191 (widget-convert-button
01c52d31 8192 'link b e
23f87bed
MB
8193 :action 'gnus-button-prev-page
8194 :button-keymap gnus-prev-page-map)))
8195
8196(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8197 "Go to the next page."
8198 (interactive)
8199 (let ((win (selected-window)))
23f87bed 8200 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8201 (gnus-article-next-page)
8202 (select-window win)))
8203
23f87bed 8204(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8205 "Go to the prev page."
8206 (interactive)
8207 (let ((win (selected-window)))
23f87bed 8208 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8209 (gnus-article-prev-page)
8210 (select-window win)))
8211
8212(defun gnus-insert-next-page-button ()
01c52d31 8213 (let ((b (point)) e
23f87bed 8214 (inhibit-read-only t))
eec82323 8215 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8216 `(keymap ,gnus-next-page-map
8217 gnus-next t
8218 gnus-callback gnus-article-button-next-page
8219 article-type annotation))
8220 (setq e (if (bolp)
8221 ;; Exclude a newline.
8222 (1- (point))
8223 (point)))
8224 (when gnus-article-button-face
8225 (gnus-overlay-put (gnus-make-overlay b e nil t)
8226 'face gnus-article-button-face))
23f87bed 8227 (widget-convert-button
01c52d31 8228 'link b e
23f87bed
MB
8229 :action 'gnus-button-next-page
8230 :button-keymap gnus-next-page-map)))
eec82323
LMI
8231
8232(defun gnus-article-button-next-page (arg)
8233 "Go to the next page."
8234 (interactive "P")
8235 (let ((win (selected-window)))
23f87bed 8236 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8237 (gnus-article-next-page)
8238 (select-window win)))
8239
8240(defun gnus-article-button-prev-page (arg)
8241 "Go to the prev page."
8242 (interactive "P")
8243 (let ((win (selected-window)))
23f87bed 8244 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8245 (gnus-article-prev-page)
8246 (select-window win)))
8247
16409b0b
GM
8248(defvar gnus-decode-header-methods
8249 '(mail-decode-encoded-word-region)
8250 "List of methods used to decode headers.
8251
8252This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8253is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8254\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8255whose names match REGEXP.
8256
8257For example:
8f688cb0 8258\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8259 mail-decode-encoded-word-region
8260 (\"chinese\" . rfc1843-decode-region))
8261")
8262
8263(defvar gnus-decode-header-methods-cache nil)
8264
8265(defun gnus-multi-decode-header (start end)
8266 "Apply the functions from `gnus-encoded-word-methods' that match."
8267 (unless (and gnus-decode-header-methods-cache
8268 (eq gnus-newsgroup-name
8269 (car gnus-decode-header-methods-cache)))
8270 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8271 (dolist (x gnus-decode-header-methods)
8272 (if (symbolp x)
8273 (nconc gnus-decode-header-methods-cache (list x))
8274 (if (and gnus-newsgroup-name
8275 (string-match (car x) gnus-newsgroup-name))
8276 (nconc gnus-decode-header-methods-cache
8277 (list (cdr x)))))))
16409b0b
GM
8278 (let ((xlist gnus-decode-header-methods-cache))
8279 (pop xlist)
8280 (save-restriction
8281 (narrow-to-region start end)
8282 (while xlist
8283 (funcall (pop xlist) (point-min) (point-max))))))
8284
8285;;;
8286;;; Treatment top-level handling.
8287;;;
8288
389b76fa
G
8289(defvar gnus-inhibit-article-treatments nil)
8290
c497474b
GM
8291(defun gnus-treat-article (gnus-treat-condition
8292 &optional part-number total-parts gnus-treat-type)
8293 (let ((gnus-treat-length (- (point-max) (point-min)))
16409b0b
GM
8294 (alist gnus-treatment-function-alist)
8295 (article-goto-body-goes-to-point-min-p t)
8296 (treated-type
c497474b 8297 (or (not gnus-treat-type)
16409b0b
GM
8298 (catch 'found
8299 (let ((list gnus-article-treat-types))
8300 (while list
c497474b 8301 (when (string-match (pop list) gnus-treat-type)
16409b0b
GM
8302 (throw 'found t)))))))
8303 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8304 val elem)
8305 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8306 (dolist (elem alist)
16409b0b
GM
8307 (setq val
8308 (save-excursion
23f87bed
MB
8309 (when (gnus-buffer-live-p gnus-summary-buffer)
8310 (set-buffer gnus-summary-buffer))
16409b0b
GM
8311 (symbol-value (car elem))))
8312 (when (and (or (consp val)
8313 treated-type)
389b76fa 8314 (or (not gnus-inhibit-article-treatments)
c497474b 8315 (eq gnus-treat-condition 'head))
16409b0b
GM
8316 (gnus-treat-predicate val)
8317 (or (not (get (car elem) 'highlight))
8318 highlightp))
8319 (save-restriction
8320 (funcall (cadr elem)))))))
8321
8322;; Dynamic variables.
9efa445f
DN
8323(defvar part-number)
8324(defvar total-parts)
c497474b
GM
8325(defvar gnus-treat-type)
8326(defvar gnus-treat-condition)
8327(defvar gnus-treat-length)
e0bad764 8328
16409b0b
GM
8329(defun gnus-treat-predicate (val)
8330 (cond
8331 ((null val)
8332 nil)
c497474b
GM
8333 (gnus-treat-condition
8334 (eq gnus-treat-condition val))
16409b0b
GM
8335 ((and (listp val)
8336 (stringp (car val)))
8337 (apply 'gnus-or (mapcar `(lambda (s)
8338 (string-match s ,(or gnus-newsgroup-name "")))
8339 val)))
8340 ((listp val)
8341 (let ((pred (pop val)))
8342 (cond
8343 ((eq pred 'or)
8344 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8345 ((eq pred 'and)
8346 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8347 ((eq pred 'not)
8348 (not (gnus-treat-predicate (car val))))
8349 ((eq pred 'typep)
c497474b 8350 (equal (car val) gnus-treat-type))
16409b0b
GM
8351 (t
8352 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8353 ((eq val t)
8354 t)
8355 ((eq val 'head)
8356 nil)
01c52d31
MB
8357 ((eq val 'first)
8358 (eq part-number 1))
16409b0b
GM
8359 ((eq val 'last)
8360 (eq part-number total-parts))
8361 ((numberp val)
c497474b 8362 (< gnus-treat-length val))
16409b0b
GM
8363 (t
8364 (error "%S is not a valid value" val))))
8365
23f87bed
MB
8366(defun gnus-article-encrypt-body (protocol &optional n)
8367 "Encrypt the article body."
8368 (interactive
8369 (list
8370 (or gnus-article-encrypt-protocol
229b59da
G
8371 (gnus-completing-read "Encrypt protocol"
8372 (mapcar 'car gnus-article-encrypt-protocol-alist)
8373 t))
23f87bed 8374 current-prefix-arg))
bbbe940b
MB
8375 ;; User might hit `K E' instead of `K e', so prompt once.
8376 (when (and gnus-article-encrypt-protocol
8377 gnus-novice-user)
8378 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
d93ec753 8379 (error "Encrypt aborted")))
23f87bed
MB
8380 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8381 (unless func
998a5a95 8382 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8383 (if (member gnus-newsgroup-name '("nndraft:delayed"
8384 "nndraft:drafts"
8385 "nndraft:queue"))
8386 (error "Can't encrypt the article in group %s"
8387 gnus-newsgroup-name))
8388 (gnus-summary-iterate n
80de1778 8389 (with-current-buffer gnus-summary-buffer
23f87bed
MB
8390 (let ((mail-parse-charset gnus-newsgroup-charset)
8391 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8392 (summary-buffer gnus-summary-buffer)
8393 references point)
8394 (gnus-set-global-variables)
8395 (when (gnus-group-read-only-p)
8396 (error "The current newsgroup does not support article encrypt"))
8397 (gnus-summary-show-article t)
8398 (setq references
8399 (or (mail-header-references gnus-current-headers) ""))
8400 (set-buffer gnus-article-buffer)
8401 (let* ((inhibit-read-only t)
8402 (headers
8403 (mapcar (lambda (field)
8404 (and (save-restriction
8405 (message-narrow-to-head)
8406 (goto-char (point-min))
8407 (search-forward field nil t))
8408 (prog2
8409 (message-narrow-to-field)
8410 (buffer-string)
8411 (delete-region (point-min) (point-max))
8412 (widen))))
8413 '("Content-Type:" "Content-Transfer-Encoding:"
8414 "Content-Disposition:"))))
8415 (message-narrow-to-head)
8416 (message-remove-header "MIME-Version")
8417 (goto-char (point-max))
8418 (setq point (point))
8419 (insert (apply 'concat headers))
8420 (widen)
8421 (narrow-to-region point (point-max))
8422 (let ((message-options message-options))
8423 (message-options-set 'message-sender user-mail-address)
8424 (message-options-set 'message-recipients user-mail-address)
8425 (message-options-set 'message-sign-encrypt 'not)
8426 (funcall func))
8427 (goto-char (point-min))
8428 (insert "MIME-Version: 1.0\n")
8429 (widen)
8430 (gnus-summary-edit-article-done
8431 references nil summary-buffer t))
8432 (when gnus-keep-backlog
8433 (gnus-backlog-remove-article
8434 (car gnus-article-current) (cdr gnus-article-current)))
8ccbef23 8435 (gnus-flush-original-article-buffer)
23f87bed
MB
8436 (when gnus-use-cache
8437 (gnus-cache-update-article
8438 (car gnus-article-current) (cdr gnus-article-current))))))))
8439
8440(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8441 "The following specs can be used:
8442%t The security MIME type
8443%i Additional info
8444%d Details
8445%D Details if button is pressed")
8446
8447(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8448 "The following specs can be used:
8449%t The security MIME type
8450%i Additional info
8451%d Details
8452%D Details if button is pressed")
8453
8454(defvar gnus-mime-security-button-line-format-alist
8455 '((?t gnus-tmp-type ?s)
8456 (?i gnus-tmp-info ?s)
8457 (?d gnus-tmp-details ?s)
8458 (?D gnus-tmp-pressed-details ?s)))
8459
01c52d31
MB
8460(defvar gnus-mime-security-button-commands
8461 '((gnus-article-press-button "\r" "Show Detail")
8462 (undefined "v")
8463 (undefined "t")
8464 (undefined "C")
8465 (gnus-mime-security-save-part "o" "Save...")
8466 (undefined "\C-o")
8467 (undefined "r")
8468 (undefined "d")
8469 (undefined "c")
8470 (undefined "i")
8471 (undefined "E")
8472 (undefined "e")
8473 (undefined "p")
8474 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8475 (undefined ".")))
8476
23f87bed
MB
8477(defvar gnus-mime-security-button-map
8478 (let ((map (make-sparse-keymap)))
23f87bed 8479 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8480 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8481 (dolist (c gnus-mime-security-button-commands)
8482 (define-key map (cadr c) (car c)))
23f87bed
MB
8483 map))
8484
01c52d31
MB
8485(easy-menu-define
8486 gnus-mime-security-button-menu gnus-mime-security-button-map
8487 "Security button menu."
8488 `("Security Part"
8489 ,@(delq nil
8490 (mapcar (lambda (c)
8491 (unless (eq (car c) 'undefined)
8492 (vector (caddr c) (car c) :active t)))
8493 gnus-mime-security-button-commands))))
8494
8495(defun gnus-mime-security-button-menu (event prefix)
8496 "Construct a context-sensitive menu of security commands."
8497 (interactive "e\nP")
8498 (save-window-excursion
8499 (let ((pos (event-start event)))
8500 (select-window (posn-window pos))
8501 (goto-char (posn-point pos))
8502 (gnus-article-check-buffer)
8503 (popup-menu gnus-mime-security-button-menu nil prefix))))
8504
23f87bed
MB
8505(defvar gnus-mime-security-details-buffer nil)
8506
8507(defvar gnus-mime-security-button-pressed nil)
8508
8509(defvar gnus-mime-security-show-details-inline t
8510 "If non-nil, show details in the article buffer.")
8511
8512(defun gnus-mime-security-verify-or-decrypt (handle)
8513 (mm-remove-parts (cdr handle))
8514 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8515 point (inhibit-read-only t))
8516 (if region
8517 (goto-char (car region)))
01c52d31
MB
8518 (setq point (point))
8519 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8520 (let* ((mm-verify-option 'known)
8521 (mm-decrypt-option 'known)
8522 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8523 (unless (eq nparts (cdr handle))
8524 (mm-destroy-parts (cdr handle))
8525 (setcdr handle nparts))))
8526 (gnus-mime-display-security handle)
23f87bed
MB
8527 (when region
8528 (delete-region (point) (cdr region))
8529 (set-marker (car region) nil)
8530 (set-marker (cdr region) nil))
8531 (goto-char point)))
8532
8533(defun gnus-mime-security-show-details (handle)
8534 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8535 (if (not details)
8536 (gnus-message 5 "No details.")
8537 (if gnus-mime-security-show-details-inline
8538 (let ((gnus-mime-security-button-pressed
8539 (not (get-text-property (point) 'gnus-mime-details)))
8540 (gnus-mime-security-button-line-format
8541 (get-text-property (point) 'gnus-line-format))
8542 (inhibit-read-only t))
8543 (forward-char -1)
8544 (while (eq (get-text-property (point) 'gnus-line-format)
8545 gnus-mime-security-button-line-format)
8546 (forward-char -1))
8547 (forward-char)
8548 (save-restriction
8549 (narrow-to-region (point) (point))
8550 (gnus-insert-mime-security-button handle))
8551 (delete-region (point)
8552 (or (text-property-not-all
8553 (point) (point-max)
8554 'gnus-line-format
8555 gnus-mime-security-button-line-format)
8556 (point-max))))
8557 ;; Not inlined.
8558 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8559 (with-current-buffer gnus-mime-security-details-buffer
8560 (erase-buffer)
8561 t)
8562 (setq gnus-mime-security-details-buffer
8563 (gnus-get-buffer-create "*MIME Security Details*")))
8564 (with-current-buffer gnus-mime-security-details-buffer
8565 (insert details)
8566 (goto-char (point-min)))
8567 (pop-to-buffer gnus-mime-security-details-buffer)))))
8568
8569(defun gnus-mime-security-press-button (handle)
8570 (save-excursion
8571 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8572 (gnus-mime-security-show-details handle)
8573 (gnus-mime-security-verify-or-decrypt handle))))
8574
8575(defun gnus-insert-mime-security-button (handle &optional displayed)
8576 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8577 (gnus-tmp-type
8578 (concat
8579 (or (nth 2 (assoc protocol mm-verify-function-alist))
8580 (nth 2 (assoc protocol mm-decrypt-function-alist))
8581 "Unknown")
8582 (if (equal (car handle) "multipart/signed")
8583 " Signed" " Encrypted")
8584 " Part"))
8585 (gnus-tmp-info
8586 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8587 "Undecided"))
8588 (gnus-tmp-details
8589 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8590 gnus-tmp-pressed-details
8591 b e)
8592 (setq gnus-tmp-details
8593 (if gnus-tmp-details
8594 (concat "\n" gnus-tmp-details)
8595 ""))
8596 (setq gnus-tmp-pressed-details
8597 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8598 (unless (bolp)
8599 (insert "\n"))
8600 (setq b (point))
8601 (gnus-eval-format
8602 gnus-mime-security-button-line-format
8603 gnus-mime-security-button-line-format-alist
01c52d31 8604 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8605 gnus-callback gnus-mime-security-press-button
8606 gnus-line-format ,gnus-mime-security-button-line-format
8607 gnus-mime-details ,gnus-mime-security-button-pressed
8608 article-type annotation
8609 gnus-data ,handle))
8610 (setq e (if (bolp)
8611 ;; Exclude a newline.
8612 (1- (point))
8613 (point)))
01c52d31
MB
8614 (when gnus-article-button-face
8615 (gnus-overlay-put (gnus-make-overlay b e nil t)
8616 'face gnus-article-button-face))
23f87bed
MB
8617 (widget-convert-button
8618 'link b e
8619 :mime-handle handle
8620 :action 'gnus-widget-press-button
8621 :button-keymap gnus-mime-security-button-map
8622 :help-echo
5843126b 8623 (lambda (widget)
23f87bed
MB
8624 ;; Needed to properly clear the message due to a bug in
8625 ;; wid-edit (XEmacs only).
8626 (when (boundp 'help-echo-owns-message)
8627 (setq help-echo-owns-message t))
8628 (format
01c52d31
MB
8629 "%S: show detail; %S: more options"
8630 (aref gnus-mouse-2 0)
8631 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8632
8633(defun gnus-mime-display-security (handle)
8634 (save-restriction
8635 (narrow-to-region (point) (point))
8636 (unless (gnus-unbuttonized-mime-type-p (car handle))
8637 (gnus-insert-mime-security-button handle))
01c52d31 8638 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8639 (unless (bolp)
8640 (insert "\n"))
8641 (unless (gnus-unbuttonized-mime-type-p (car handle))
8642 (let ((gnus-mime-security-button-line-format
8643 gnus-mime-security-button-end-line-format))
8644 (gnus-insert-mime-security-button handle)))
8645 (mm-set-handle-multipart-parameter
8646 handle 'gnus-region
8647 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8648 (set-marker (make-marker) (point-max))))
8649 (goto-char (point-max))))
8650
8651(defun gnus-mime-security-run-function (function)
8652 "Run FUNCTION with the security part under point."
8653 (gnus-article-check-buffer)
8654 (let ((data (get-text-property (point) 'gnus-data))
8655 buffer handle)
8656 (when (and (stringp (car-safe data))
8657 (setq buffer (mm-handle-multipart-original-buffer data))
8658 (setq handle (cadr data)))
8659 (if (bufferp (mm-handle-buffer handle))
8660 (progn
8661 (setq handle (cons buffer (copy-sequence (cdr handle))))
8662 (mm-handle-set-undisplayer handle nil))
8663 (setq handle (mm-make-handle
8664 buffer
8665 (mm-handle-multipart-ctl-parameter handle 'protocol)
8666 nil nil nil nil nil nil)))
8667 (funcall function handle))))
8668
8669(defun gnus-mime-security-save-part ()
8670 "Save the security part under point."
8671 (interactive)
8672 (gnus-mime-security-run-function 'mm-save-part))
8673
8674(defun gnus-mime-security-pipe-part ()
8675 "Pipe the security part under point to a process."
8676 (interactive)
8677 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8678
eec82323
LMI
8679(gnus-ems-redefine)
8680
8681(provide 'gnus-art)
8682
8683(run-hooks 'gnus-art-load-hook)
8684
8685;;; gnus-art.el ends here