Merge from emacs-23
[bpt/emacs.git] / lisp / gnus / gnus-art.el
CommitLineData
eec82323 1;;; gnus-art.el --- article mode commands for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
5e809f55 11;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 12;; it under the terms of the GNU General Public License as published by
5e809f55
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
eec82323
LMI
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2ff9f5b4 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
5e809f55 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
23
24;;; Commentary:
25
26;;; Code:
27
9640c3bc
GM
28;; For Emacs < 22.2.
29(eval-and-compile
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
23f87bed 31(eval-when-compile
9efa445f
DN
32 (require 'cl))
33(defvar tool-bar-map)
34(defvar w3m-minor-mode-map)
5ab7173c 35
eec82323 36(require 'gnus)
01c52d31
MB
37;; Avoid the "Recursive load suspected" error in Emacs 21.1.
38(eval-and-compile
39 (let ((recursive-load-depth-limit 100))
40 (require 'gnus-sum)))
eec82323
LMI
41(require 'gnus-spec)
42(require 'gnus-int)
23f87bed 43(require 'gnus-win)
16409b0b
GM
44(require 'mm-bodies)
45(require 'mail-parse)
46(require 'mm-decode)
47(require 'mm-view)
48(require 'wid-edit)
49(require 'mm-uu)
23f87bed
MB
50(require 'message)
51
52(autoload 'gnus-msg-mail "gnus-msg" nil t)
53(autoload 'gnus-button-mailto "gnus-msg")
54(autoload 'gnus-button-reply "gnus-msg" nil t)
498063ec 55(autoload 'parse-time-string "parse-time" nil nil)
01c52d31
MB
56(autoload 'ansi-color-apply-on-region "ansi-color")
57(autoload 'mm-url-insert-file-contents-external "mm-url")
531bedc3 58(autoload 'mm-extern-cache-contents "mm-extern")
eec82323
LMI
59
60(defgroup gnus-article nil
61 "Article display."
23f87bed 62 :link '(custom-manual "(gnus)Article Buffer")
eec82323
LMI
63 :group 'gnus)
64
16409b0b
GM
65(defgroup gnus-article-treat nil
66 "Treating article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
69
eec82323
LMI
70(defgroup gnus-article-hiding nil
71 "Hiding article parts."
72 :link '(custom-manual "(gnus)Article Hiding")
73 :group 'gnus-article)
74
75(defgroup gnus-article-highlight nil
76 "Article highlighting."
77 :link '(custom-manual "(gnus)Article Highlighting")
78 :group 'gnus-article
79 :group 'gnus-visual)
80
81(defgroup gnus-article-signature nil
82 "Article signatures."
83 :link '(custom-manual "(gnus)Article Signature")
84 :group 'gnus-article)
85
86(defgroup gnus-article-headers nil
87 "Article headers."
88 :link '(custom-manual "(gnus)Hiding Headers")
89 :group 'gnus-article)
90
91(defgroup gnus-article-washing nil
92 "Special commands on articles."
93 :link '(custom-manual "(gnus)Article Washing")
94 :group 'gnus-article)
95
96(defgroup gnus-article-emphasis nil
97 "Fontisizing articles."
98 :link '(custom-manual "(gnus)Article Fontisizing")
99 :group 'gnus-article)
100
101(defgroup gnus-article-saving nil
102 "Saving articles."
103 :link '(custom-manual "(gnus)Saving Articles")
104 :group 'gnus-article)
105
106(defgroup gnus-article-mime nil
107 "Worshiping the MIME wonder."
108 :link '(custom-manual "(gnus)Using MIME")
109 :group 'gnus-article)
110
111(defgroup gnus-article-buttons nil
112 "Pushable buttons in the article buffer."
113 :link '(custom-manual "(gnus)Article Buttons")
114 :group 'gnus-article)
115
116(defgroup gnus-article-various nil
117 "Other article options."
118 :link '(custom-manual "(gnus)Misc Article")
119 :group 'gnus-article)
120
121(defcustom gnus-ignored-headers
23f87bed
MB
122 (mapcar
123 (lambda (header)
124 (concat "^" header ":"))
125 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
126 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
127 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
128 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
129 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
130 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
131 "X-Attribution" "X-Originating-IP" "Delivered-To"
132 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
133 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
134 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
135 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
136 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
137 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
138 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
139 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
140 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
141 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
142 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
143 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
144 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
145 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
146 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
147 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
148 "List-[A-Za-z]+" "X-Listprocessor-Version"
149 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
150 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
151 "X-Received" "Content-length" "X-precedence"
152 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
153 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
154 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
155 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
156 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
157 "X-Content-length" "X-Posting-Agent" "Original-Received"
158 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
159 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
160 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
161 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
01c52d31
MB
162 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
163 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
164 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
165 "Envelope-Sender" "Envelope-Recipients"))
6748645f 166 "*All headers that start with this regexp will be hidden.
eec82323
LMI
167This variable can also be a list of regexps of headers to be ignored.
168If `gnus-visible-headers' is non-nil, this variable will be ignored."
169 :type '(choice :custom-show nil
170 regexp
171 (repeat regexp))
172 :group 'gnus-article-hiding)
173
174(defcustom gnus-visible-headers
23f87bed 175 "^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:\\|^X-Sent:"
6748645f 176 "*All headers that do not match this regexp will be hidden.
eec82323
LMI
177This variable can also be a list of regexp of headers to remain visible.
178If this variable is non-nil, `gnus-ignored-headers' will be ignored."
9b3ebcb6
MB
179 :type '(choice
180 (repeat :value-to-internal (lambda (widget value)
181 (custom-split-regexp-maybe value))
182 :match (lambda (widget value)
183 (or (stringp value)
184 (widget-editable-list-match widget value)))
185 regexp)
186 (const :tag "Use gnus-ignored-headers" nil)
187 regexp)
eec82323
LMI
188 :group 'gnus-article-hiding)
189
190(defcustom gnus-sorted-header-list
191 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
192 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
6748645f 193 "*This variable is a list of regular expressions.
eec82323
LMI
194If it is non-nil, headers that match the regular expressions will
195be placed first in the article buffer in the sequence specified by
196this list."
197 :type '(repeat regexp)
198 :group 'gnus-article-hiding)
199
200(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
201 "Headers that are only to be displayed if they have interesting data.
23f87bed
MB
202Possible values in this list are:
203
204 'empty Headers with no content.
205 'newsgroups Newsgroup identical to Gnus group.
206 'to-address To identical to To-address.
207 'to-list To identical to To-list.
208 'cc-list CC identical to To-list.
209 'followup-to Followup-to identical to Newsgroups.
210 'reply-to Reply-to identical to From.
211 'date Date less than four days old.
212 'long-to To and/or Cc longer than 1024 characters.
213 'many-to Multiple To and/or Cc."
eec82323 214 :type '(set (const :tag "Headers with no content." empty)
23f87bed
MB
215 (const :tag "Newsgroups identical to Gnus group." newsgroups)
216 (const :tag "To identical to To-address." to-address)
217 (const :tag "To identical to To-list." to-list)
218 (const :tag "CC identical to To-list." cc-list)
219 (const :tag "Followup-to identical to Newsgroups." followup-to)
220 (const :tag "Reply-to identical to From." reply-to)
6748645f 221 (const :tag "Date less than four days old." date)
23f87bed 222 (const :tag "To and/or Cc longer than 1024 characters." long-to)
16409b0b 223 (const :tag "Multiple To and/or Cc headers." many-to))
eec82323
LMI
224 :group 'gnus-article-hiding)
225
23f87bed
MB
226(defcustom gnus-article-skip-boring nil
227 "Skip over text that is not worth reading.
228By default, if you set this t, then Gnus will display citations and
229signatures, but will never scroll down to show you a page consisting
230only of boring text. Boring text is controlled by
231`gnus-article-boring-faces'."
bf247b6e 232 :version "22.1"
23f87bed
MB
233 :type 'boolean
234 :group 'gnus-article-hiding)
235
eec82323
LMI
236(defcustom gnus-signature-separator '("^-- $" "^-- *$")
237 "Regexp matching signature separator.
238This can also be a list of regexps. In that case, it will be checked
239from head to tail looking for a separator. Searches will be done from
240the end of the buffer."
3031d8b0
MB
241 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
242 (regexp)
243 (repeat :tag "List of regexp" regexp))
eec82323
LMI
244 :group 'gnus-article-signature)
245
246(defcustom gnus-signature-limit nil
16409b0b 247 "Provide a limit to what is considered a signature.
eec82323
LMI
248If it is a number, no signature may not be longer (in characters) than
249that number. If it is a floating point number, no signature may be
250longer (in lines) than that number. If it is a function, the function
251will be called without any parameters, and if it returns nil, there is
252no signature in the buffer. If it is a string, it will be used as a
01c52d31
MB
253regexp. If it matches, the text in question is not a signature.
254
255This can also be a list of the above values."
4a2358e9
MB
256 :type '(choice (const nil)
257 (integer :value 200)
6748645f 258 (number :value 4.0)
b28080e3 259 function
6748645f 260 (regexp :value ".*"))
eec82323
LMI
261 :group 'gnus-article-signature)
262
263(defcustom gnus-hidden-properties '(invisible t intangible t)
264 "Property list to use for hiding text."
265 :type 'sexp
266 :group 'gnus-article-hiding)
267
23f87bed
MB
268;; Fixme: This isn't the right thing for mixed graphical and non-graphical
269;; frames in a session.
eec82323 270(defcustom gnus-article-x-face-command
23f87bed
MB
271 (if (featurep 'xemacs)
272 (if (or (gnus-image-type-available-p 'xface)
273 (gnus-image-type-available-p 'pbm))
274 'gnus-display-x-face-in-from
275 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
e0bad764
DL
278 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
279display -"))
6748645f 280 "*String or function to be executed to display an X-Face header.
eec82323 281If it is a string, the command will be executed in a sub-shell
2ff9f5b4 282asynchronously. The compressed face will be piped to this command."
23f87bed
MB
283 :type `(choice string
284 (function-item gnus-display-x-face-in-from)
16409b0b 285 function)
b5a206e7 286 :version "21.1"
23f87bed 287 :group 'gnus-picon
eec82323
LMI
288 :group 'gnus-article-washing)
289
290(defcustom gnus-article-x-face-too-ugly nil
291 "Regexp matching posters whose face shouldn't be shown automatically."
4bb6a3a6 292 :type '(choice regexp (const nil))
eec82323
LMI
293 :group 'gnus-article-washing)
294
e0bad764
DL
295(defcustom gnus-article-banner-alist nil
296 "Banner alist for stripping.
a1506d29 297For example,
23f87bed 298 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
fc2c2db8 299 :version "21.1"
e0bad764
DL
300 :type '(repeat (cons symbol regexp))
301 :group 'gnus-article-washing)
302
23f87bed
MB
303(gnus-define-group-parameter
304 banner
305 :variable-document
306 "Alist of regexps (to match group names) and banner."
307 :variable-group gnus-article-washing
308 :parameter-type
309 '(choice :tag "Banner"
310 :value nil
311 (const :tag "Remove signature" signature)
312 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 regexp
314 (const :tag "None" nil))
315 :parameter-document
316 "If non-nil, specify how to remove `banners' from articles.
317
318Symbol `signature' means to remove signatures delimited by
319`gnus-signature-separator'. Any other symbol is used to look up a
320regular expression to match the banner in `gnus-article-banner-alist'.
321A string is used as a regular expression to match the banner
322directly.")
323
324(defcustom gnus-article-address-banner-alist nil
325 "Alist of mail addresses and banners.
326Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
327to match a mail address in the From: header, BANNER is one of a symbol
328`signature', an item in `gnus-article-banner-alist', a regexp and nil.
329If ADDRESS matches author's mail address, it will remove things like
330advertisements. For example:
331
332\((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333"
334 :type '(repeat
335 (cons
336 (regexp :tag "Address")
337 (choice :tag "Banner" :value nil
338 (const :tag "Remove signature" signature)
339 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 regexp
341 (const :tag "None" nil))))
bf247b6e 342 :version "22.1"
23f87bed
MB
343 :group 'gnus-article-washing)
344
ae465fa7
MB
345(defmacro gnus-emphasis-custom-with-format (&rest body)
346 `(let ((format "\
347\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
348\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
349 ,@body))
350
351(defun gnus-emphasis-custom-value-to-external (value)
352 (gnus-emphasis-custom-with-format
353 (if (consp (car value))
354 (list (format format (car (car value)) (cdr (car value)))
355 2
356 (if (nth 1 value) 2 3)
357 (nth 2 value))
358 value)))
359
360(defun gnus-emphasis-custom-value-to-internal (value)
361 (gnus-emphasis-custom-with-format
362 (let ((regexp (concat "\\`"
363 (format (regexp-quote format)
364 "\\([^()]+\\)" "\\([^()]+\\)")
365 "\\'"))
366 pattern)
367 (if (string-match regexp (setq pattern (car value)))
368 (list (cons (match-string 1 pattern) (match-string 2 pattern))
369 (= (nth 2 value) 2)
370 (nth 3 value))
371 value))))
372
eec82323 373(defcustom gnus-emphasis-alist
ae465fa7
MB
374 (let ((types
375 '(("\\*" "\\*" bold nil 2)
23f87bed 376 ("_" "_" underline)
eec82323 377 ("/" "/" italic)
eec82323
LMI
378 ("_/" "/_" underline-italic)
379 ("_\\*" "\\*_" underline-bold)
380 ("\\*/" "/\\*" bold-italic)
381 ("_\\*/" "/\\*_" underline-bold-italic))))
ae465fa7
MB
382 (nconc
383 (gnus-emphasis-custom-with-format
384 (mapcar (lambda (spec)
385 (list (format format (car spec) (cadr spec))
386 (or (nth 3 spec) 2)
387 (or (nth 4 spec) 3)
388 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 types))
95f75c75
SM
390 '(;; I've never seen anyone use this strikethru convention whereas I've
391 ;; several times seen it triggered by normal text. --Stef
392 ;; Miles suggests that this form is sometimes used but for italics,
393 ;; so maybe we should map it to `italic'.
394 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
395 ;; 2 3 gnus-emphasis-strikethru)
ae465fa7
MB
396 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
397 2 3 gnus-emphasis-underline))))
6748645f 398 "*Alist that says how to fontify certain phrases.
eec82323
LMI
399Each item looks like this:
400
401 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402
403The first element is a regular expression to be matched. The second
404is a number that says what regular expression grouping used to find
405the entire emphasized word. The third is a number that says what
406regexp grouping should be displayed and highlighted. The fourth
407is the face used for highlighting."
ae465fa7
MB
408 :type
409 '(repeat
410 (menu-choice
411 :format "%[Customizing Style%]\n%v"
412 :indent 2
413 (group :tag "Default"
414 :value ("" 0 0 default)
415 :value-create
416 (lambda (widget)
417 (let ((value (widget-get
418 (cadr (widget-get (widget-get widget :parent)
419 :args))
420 :value)))
421 (if (not (eq (nth 2 value) 'default))
422 (widget-put
423 widget
424 :value
425 (gnus-emphasis-custom-value-to-external value))))
426 (widget-group-value-create widget))
ad136a7c
MB
427 regexp
428 (integer :format "Match group: %v")
01c52d31 429 (integer :format "Emphasize group: %v")
ae465fa7
MB
430 face)
431 (group :tag "Simple"
432 :value (("_" . "_") nil default)
433 (cons :format "%v"
ad136a7c
MB
434 (regexp :format "Start regexp: %v")
435 (regexp :format "End regexp: %v"))
ae465fa7
MB
436 (boolean :format "Show start and end patterns: %[%v%]\n"
437 :on " On " :off " Off ")
438 face)))
439 :get (lambda (symbol)
440 (mapcar 'gnus-emphasis-custom-value-to-internal
441 (default-value symbol)))
442 :set (lambda (symbol value)
443 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 value)))
eec82323
LMI
445 :group 'gnus-article-emphasis)
446
16409b0b
GM
447(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
448 "A regexp to describe whitespace which should not be emphasized.
449Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
450The former avoids underlining of leading and trailing whitespace,
451and the latter avoids underlining any whitespace at all."
fc2c2db8 452 :version "21.1"
16409b0b
GM
453 :group 'gnus-article-emphasis
454 :type 'regexp)
455
23f87bed 456(defface gnus-emphasis-bold '((t (:bold t)))
eec82323
LMI
457 "Face used for displaying strong emphasized text (*word*)."
458 :group 'gnus-article-emphasis)
459
23f87bed 460(defface gnus-emphasis-italic '((t (:italic t)))
eec82323
LMI
461 "Face used for displaying italic emphasized text (/word/)."
462 :group 'gnus-article-emphasis)
463
464(defface gnus-emphasis-underline '((t (:underline t)))
465 "Face used for displaying underlined emphasized text (_word_)."
466 :group 'gnus-article-emphasis)
467
23f87bed 468(defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
eec82323
LMI
469 "Face used for displaying underlined bold emphasized text (_*word*_)."
470 :group 'gnus-article-emphasis)
471
23f87bed 472(defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
8de38c21 473 "Face used for displaying underlined italic emphasized text (_/word/_)."
eec82323
LMI
474 :group 'gnus-article-emphasis)
475
23f87bed 476(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
eec82323
LMI
477 "Face used for displaying bold italic emphasized text (/*word*/)."
478 :group 'gnus-article-emphasis)
479
480(defface gnus-emphasis-underline-bold-italic
23f87bed 481 '((t (:bold t :italic t :underline t)))
eec82323 482 "Face used for displaying underlined bold italic emphasized text.
8f688cb0 483Example: (_/*word*/_)."
eec82323
LMI
484 :group 'gnus-article-emphasis)
485
23f87bed
MB
486(defface gnus-emphasis-strikethru (if (featurep 'xemacs)
487 '((t (:strikethru t)))
488 '((t (:strike-through t))))
489 "Face used for displaying strike-through text (-word-)."
490 :group 'gnus-article-emphasis)
491
16409b0b
GM
492(defface gnus-emphasis-highlight-words
493 '((t (:background "black" :foreground "yellow")))
494 "Face used for displaying highlighted words."
495 :group 'gnus-article-emphasis)
496
01c52d31 497(defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
eec82323 498 "Format for display of Date headers in article bodies.
6748645f
LMI
499See `format-time-string' for the possible values.
500
501The variable can also be function, which should return a complete Date
502header. The function is called with one argument, the time, which can
503be fed to `format-time-string'."
01c52d31 504 :type '(choice string function)
eec82323
LMI
505 :link '(custom-manual "(gnus)Article Date")
506 :group 'gnus-article-washing)
507
eec82323 508(defcustom gnus-save-all-headers t
26c9afc3
MB
509 "*If non-nil, don't remove any headers before saving.
510This will be overridden by the `:headers' property that the symbol of
511the saver function, which is specified by `gnus-default-article-saver',
512might have."
eec82323
LMI
513 :group 'gnus-article-saving
514 :type 'boolean)
515
516(defcustom gnus-prompt-before-saving 'always
517 "*This variable says how much prompting is to be done when saving articles.
518If it is nil, no prompting will be done, and the articles will be
519saved to the default files. If this variable is `always', each and
520every article that is saved will be preceded by a prompt, even when
521saving large batches of articles. If this variable is neither nil not
522`always', there the user will be prompted once for a file name for
523each invocation of the saving commands."
524 :group 'gnus-article-saving
525 :type '(choice (item always)
526 (item :tag "never" nil)
6748645f 527 (sexp :tag "once" :format "%t\n" :value t)))
eec82323
LMI
528
529(defcustom gnus-saved-headers gnus-visible-headers
530 "Headers to keep if `gnus-save-all-headers' is nil.
531If `gnus-save-all-headers' is non-nil, this variable will be ignored.
532If that variable is nil, however, all headers that match this regexp
26c9afc3
MB
533will be kept while the rest will be deleted before saving. This and
534`gnus-save-all-headers' will be overridden by the `:headers' property
535that the symbol of the saver function, which is specified by
536`gnus-default-article-saver', might have."
eec82323 537 :group 'gnus-article-saving
4bb6a3a6 538 :type 'regexp)
eec82323 539
fef8d38e 540;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
eec82323
LMI
541(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
542 "A function to save articles in your favourite format.
26c9afc3
MB
543The function will be called by way of the `gnus-summary-save-article'
544command, and friends such as `gnus-summary-save-article-rmail'.
eec82323
LMI
545
546Gnus provides the following functions:
547
548* gnus-summary-save-in-rmail (Rmail format)
549* gnus-summary-save-in-mail (Unix mail format)
550* gnus-summary-save-in-folder (MH folder)
551* gnus-summary-save-in-file (article format)
23f87bed 552* gnus-summary-save-body-in-file (article body)
eec82323 553* gnus-summary-save-in-vm (use VM's folder format)
26c9afc3
MB
554* gnus-summary-write-to-file (article format -- overwrite)
555* gnus-summary-write-body-to-file (article body -- overwrite)
89167438 556* gnus-summary-save-in-pipe (article format)
26c9afc3
MB
557
558The symbol of each function may have the following properties:
559
560* :decode
561The value non-nil means save decoded articles. This is meaningful
562only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
89167438
MB
563`gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
564`gnus-summary-save-in-pipe'.
26c9afc3
MB
565
566* :function
567The value specifies an alternative function which appends, not
568overwrites, articles to a file. This implies that when saving many
569articles at a time, `gnus-prompt-before-saving' is bound to t and all
570articles are saved in a single file. This is meaningful only with
571`gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
572
573* :headers
574The value specifies the symbol of a variable of which the value
575specifies headers to be saved. If it is omitted,
576`gnus-save-all-headers' and `gnus-saved-headers' control what
577headers should be saved."
eec82323
LMI
578 :group 'gnus-article-saving
579 :type '(radio (function-item gnus-summary-save-in-rmail)
580 (function-item gnus-summary-save-in-mail)
581 (function-item gnus-summary-save-in-folder)
582 (function-item gnus-summary-save-in-file)
23f87bed 583 (function-item gnus-summary-save-body-in-file)
eec82323 584 (function-item gnus-summary-save-in-vm)
58090a8d 585 (function-item gnus-summary-write-to-file)
26c9afc3 586 (function-item gnus-summary-write-body-to-file)
89167438 587 (function-item gnus-summary-save-in-pipe)
58090a8d 588 (function)))
eec82323 589
26c9afc3
MB
590(defcustom gnus-article-save-coding-system
591 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
592 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
593 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
594 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
595 "Coding system used to save decoded articles to a file.
596
597The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
598which can safely encode any characters in text. This is used by the
599commands including:
600
601* gnus-summary-save-article-file
602* gnus-summary-save-article-body-file
603* gnus-summary-write-article-file
604* gnus-summary-write-article-body-file
605
606and the functions to which you may set `gnus-default-article-saver':
607
608* gnus-summary-save-in-file
609* gnus-summary-save-body-in-file
610* gnus-summary-write-to-file
611* gnus-summary-write-body-to-file
612
613Those commands and functions save just text displayed in the article
614buffer to a file if the value of this variable is non-nil. Note that
615buttonized MIME parts will be lost in a saved file in that case.
616Otherwise, raw articles will be saved."
617 :group 'gnus-article-saving
618 :type `(choice
619 :format "%{%t%}:\n %[Value Menu%] %v"
620 (const :tag "Save raw articles" nil)
621 ,@(delq nil
622 (mapcar
623 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
624 '((const :tag "UTF-8" utf-8)
625 (const :tag "iso-2022-7bit" iso-2022-7bit)
626 (const :tag "Emacs internal" emacs-mule)
627 (const :tag "escape-quoted" escape-quoted))))
628 (symbol :tag "Coding system")))
629
eec82323
LMI
630(defcustom gnus-rmail-save-name 'gnus-plain-save-name
631 "A function generating a file name to save articles in Rmail format.
632The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
633 :group 'gnus-article-saving
634 :type 'function)
635
636(defcustom gnus-mail-save-name 'gnus-plain-save-name
637 "A function generating a file name to save articles in Unix mail format.
638The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
639 :group 'gnus-article-saving
640 :type 'function)
641
642(defcustom gnus-folder-save-name 'gnus-folder-save-name
643 "A function generating a file name to save articles in MH folder.
644The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
645 :group 'gnus-article-saving
646 :type 'function)
647
648(defcustom gnus-file-save-name 'gnus-numeric-save-name
649 "A function generating a file name to save articles in article format.
650The function is called with NEWSGROUP, HEADERS, and optional
651LAST-FILE."
652 :group 'gnus-article-saving
653 :type 'function)
654
655(defcustom gnus-split-methods
656 '((gnus-article-archive-name)
657 (gnus-article-nndoc-name))
6748645f 658 "*Variable used to suggest where articles are to be saved.
eec82323
LMI
659For instance, if you would like to save articles related to Gnus in
660the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
661you could set this variable to something like:
662
663 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
664 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665
01c52d31
MB
666This variable is an alist where the key is the match and the
667value is a list of possible files to save in if the match is
668non-nil.
eec82323
LMI
669
670If the match is a string, it is used as a regexp match on the
671article. If the match is a symbol, that symbol will be funcalled
672from the buffer of the article to be saved with the newsgroup as the
01c52d31 673parameter. If it is a list, it will be evaled in the same buffer.
eec82323 674
01c52d31
MB
675If this form or function returns a string, this string will be used as a
676possible file name; and if it returns a non-nil list, that list will be
677used as possible file names."
eec82323 678 :group 'gnus-article-saving
6748645f
LMI
679 :type '(repeat (choice (list :value (fun) function)
680 (cons :value ("" "") regexp (repeat string))
681 (sexp :value nil))))
eec82323 682
eec82323
LMI
683(defcustom gnus-page-delimiter "^\^L"
684 "*Regexp describing what to use as article page delimiters.
685The default value is \"^\^L\", which is a form linefeed at the
686beginning of a line."
687 :type 'regexp
688 :group 'gnus-article-various)
689
16409b0b 690(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
eec82323 691 "*The format specification for the article mode line.
16409b0b
GM
692See `gnus-summary-mode-line-format' for a closer description.
693
694The following additional specs are available:
695
696%w The article washing status.
697%m The number of MIME parts in the article."
eec82323
LMI
698 :type 'string
699 :group 'gnus-article-various)
700
701(defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
703 :type 'hook
704 :group 'gnus-article-various)
705
23f87bed
MB
706(when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
712
eec82323
LMI
713(defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
715 :type 'hook
716 :group 'gnus-article-various)
717
718(defcustom gnus-article-prepare-hook nil
16409b0b 719 "*A hook called after an article has been prepared in the article buffer."
eec82323
LMI
720 :type 'hook
721 :group 'gnus-article-various)
722
01c52d31
MB
723(defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725Each element is a regular expression."
330f707b 726 :version "23.1" ;; No Gnus
01c52d31
MB
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
729
265ac10b
SM
730(make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs-22.1)")
a8151ef7 732
01c52d31
MB
733(defface gnus-button
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
737
738(defcustom gnus-article-button-face 'gnus-button
eec82323
LMI
739 "Face used for highlighting buttons in the article buffer.
740
741An article button is a piece of text that you can activate by pressing
742`RET' or `mouse-2' above it."
743 :type 'face
744 :group 'gnus-article-buttons)
745
746(defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
748
749Article buttons will be displayed in this face when the cursor is
750above them."
751 :type 'face
752 :group 'gnus-article-buttons)
753
0f49874b 754(defcustom gnus-signature-face 'gnus-signature
a8151ef7 755 "Face used for highlighting a signature in the article buffer.
0f49874b 756Obsolete; use the face `gnus-signature' for customizations instead."
eec82323
LMI
757 :type 'face
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
760
0f49874b 761(defface gnus-signature
f59a3415 762 '((t
23f87bed 763 (:italic t)))
a8151ef7
LMI
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
0f49874b
MB
767;; backward-compatibility alias
768(put 'gnus-signature-face 'face-alias 'gnus-signature)
3d493bef 769(put 'gnus-signature-face 'obsolete-face "22.1")
a8151ef7 770
0f49874b 771(defface gnus-header-from
eec82323
LMI
772 '((((class color)
773 (background dark))
01c52d31 774 (:foreground "PaleGreen1"))
eec82323
LMI
775 (((class color)
776 (background light))
6748645f 777 (:foreground "red3"))
eec82323 778 (t
23f87bed 779 (:italic t)))
eec82323
LMI
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
0f49874b
MB
783;; backward-compatibility alias
784(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
3d493bef 785(put 'gnus-header-from-face 'obsolete-face "22.1")
eec82323 786
0f49874b 787(defface gnus-header-subject
eec82323
LMI
788 '((((class color)
789 (background dark))
01c52d31 790 (:foreground "SeaGreen1"))
eec82323
LMI
791 (((class color)
792 (background light))
6748645f 793 (:foreground "red4"))
eec82323 794 (t
23f87bed 795 (:bold t :italic t)))
eec82323
LMI
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
0f49874b
MB
799;; backward-compatibility alias
800(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
3d493bef 801(put 'gnus-header-subject-face 'obsolete-face "22.1")
eec82323 802
0f49874b 803(defface gnus-header-newsgroups
eec82323
LMI
804 '((((class color)
805 (background dark))
23f87bed 806 (:foreground "yellow" :italic t))
eec82323
LMI
807 (((class color)
808 (background light))
23f87bed 809 (:foreground "MidnightBlue" :italic t))
eec82323 810 (t
23f87bed
MB
811 (:italic t)))
812 "Face used for displaying newsgroups headers.
813In the default setup this face is only used for crossposted
814articles."
eec82323
LMI
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
0f49874b
MB
817;; backward-compatibility alias
818(put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
3d493bef 819(put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
eec82323 820
0f49874b 821(defface gnus-header-name
eec82323
LMI
822 '((((class color)
823 (background dark))
01c52d31 824 (:foreground "SpringGreen2"))
eec82323
LMI
825 (((class color)
826 (background light))
827 (:foreground "maroon"))
828 (t
23f87bed 829 (:bold t)))
eec82323
LMI
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
0f49874b
MB
833;; backward-compatibility alias
834(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
3d493bef 835(put 'gnus-header-name-face 'obsolete-face "22.1")
eec82323 836
0f49874b 837(defface gnus-header-content
eec82323
LMI
838 '((((class color)
839 (background dark))
01c52d31 840 (:foreground "SpringGreen1" :italic t))
eec82323
LMI
841 (((class color)
842 (background light))
23f87bed 843 (:foreground "indianred4" :italic t))
eec82323 844 (t
23f87bed 845 (:italic t))) "Face used for displaying header content."
eec82323
LMI
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
0f49874b
MB
848;; backward-compatibility alias
849(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
3d493bef 850(put 'gnus-header-content-face 'obsolete-face "22.1")
eec82323
LMI
851
852(defcustom gnus-header-face-alist
0f49874b
MB
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
23f87bed 857 "*Controls highlighting of article headers.
eec82323
LMI
858
859An alist of the form (HEADER NAME CONTENT).
860
23f87bed
MB
861HEADER is a regular expression which should match the name of a
862header and NAME and CONTENT are either face names or nil.
eec82323
LMI
863
864The name of each header field will be displayed using the face
23f87bed
MB
865specified by the first element in the list where HEADER matches
866the header name and NAME is non-nil. Similarly, the content will
867be displayed by the first non-nil matching CONTENT face."
eec82323
LMI
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
871 (choice :tag "Name"
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
877
01c52d31
MB
878(defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
881 (png . nil)))
882 "Alist of image types and properties applied to Face and X-Face images.
883Here are examples:
884
885;; Specify the altitude of Face images in the From header.
886\(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
889
890;; Show Face images as pressed buttons.
891\(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
894
895See the manual for the valid properties for various image types.
896Currently, `pbm' is used for X-Face images and `png' is used for Face
897images in Emacs. Only the `:face' property is effective on the `xface'
898image type in XEmacs if it is built with the libcompface library."
330f707b 899 :version "23.1" ;; No Gnus
01c52d31
MB
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
902
16409b0b 903(defcustom gnus-article-decode-hook
23f87bed
MB
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
16409b0b
GM
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
908 :type 'hook)
909
910(defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
913 :type 'function)
914
915(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
917
343d6628
MB
918(defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
920
16409b0b 921(defvar gnus-article-dumbquotes-map
23f87bed
MB
922 '(("\200" "EUR")
923 ("\202" ",")
16409b0b
GM
924 ("\203" "f")
925 ("\204" ",,")
926 ("\205" "...")
927 ("\213" "<")
928 ("\214" "OE")
929 ("\221" "`")
930 ("\222" "'")
931 ("\223" "``")
932 ("\224" "\"")
933 ("\225" "*")
e0bad764
DL
934 ("\226" "-")
935 ("\227" "--")
23f87bed 936 ("\230" "~")
16409b0b
GM
937 ("\231" "(TM)")
938 ("\233" ">")
939 ("\234" "oe")
940 ("\264" "'"))
941 "Table for MS-to-Latin1 translation.")
942
943(defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
fc2c2db8 945 :version "21.1"
16409b0b
GM
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
948
949(defcustom gnus-unbuttonized-mime-types '(".*/.*")
23f87bed
MB
950 "List of MIME types that should not be given buttons when rendered inline.
951See also `gnus-buttonized-mime-types' which may override this variable.
952This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
953 :version "21.1"
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
956
957(defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959If set, this variable overrides `gnus-unbuttonized-mime-types'.
960To see e.g. security buttons you could set this to
3031d8b0
MB
961`(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962this list to display radio buttons that allow you to choose one of two
963media types those mails include. See also `mm-discouraged-alternatives'.
23f87bed 964This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
bf247b6e 965 :version "22.1"
16409b0b
GM
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
968
23f87bed
MB
969(defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971When nil (the default value), then some MIME parts do not get buttons,
972as described by the variables `gnus-buttonized-mime-types' and
973`gnus-unbuttonized-mime-types'."
bf247b6e 974 :version "22.1"
d0859c9a 975 :group 'gnus-article-mime
23f87bed
MB
976 :type 'boolean)
977
978(defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980This variable is used by `gnus-article-treat-body-boundary' which can
981be controlled by `gnus-treat-body-boundary'."
bf247b6e 982 :version "22.1"
23f87bed
MB
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
985 string))
986
97f78c9b
MB
987(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
988 "/usr/share/picons")
23f87bed
MB
989 "Defines the location of the faces database.
990For information on obtaining this database of pretty pictures, please
991see http://www.cs.indiana.edu/picons/ftp/index.html"
bf247b6e 992 :version "22.1"
23f87bed
MB
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
997 :group 'gnus-picon)
998
999(defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1005 installed))
1006
16409b0b
GM
1007(defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009This is meant for people who want to do something automatic based
1010on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
4a2358e9
MB
1012 :type '(choice (const nil)
1013 function))
16409b0b
GM
1014
1015(defcustom gnus-mime-multipart-functions nil
fc2c2db8
DL
1016 "An alist of MIME types to functions to display them."
1017 :version "21.1"
1018 :group 'gnus-article-mime
01c52d31 1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
16409b0b
GM
1020
1021(defcustom gnus-article-date-lapsed-new-header nil
1022 "Whether the X-Sent and Date headers can coexist.
1023When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1024either replace the old \"Date:\" header (if this variable is nil), or
1025be added below it (otherwise)."
fc2c2db8 1026 :version "21.1"
16409b0b
GM
1027 :group 'gnus-article-headers
1028 :type 'boolean)
1029
1030(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1031 "Function called with a MIME handle as the argument.
1032This is meant for people who want to view first matched part.
a1506d29
JB
1033For `undisplayed-alternative' (default), the first undisplayed
1034part or alternative part is used. For `undisplayed', the first
1035undisplayed part is used. For a function, the first part which
f20b2f5c 1036the function return t is used. For nil, the first part is
16409b0b 1037used."
fc2c2db8 1038 :version "21.1"
16409b0b 1039 :group 'gnus-article-mime
a1506d29 1040 :type '(choice
16409b0b
GM
1041 (item :tag "first" :value nil)
1042 (item :tag "undisplayed" :value undisplayed)
a1506d29 1043 (item :tag "undisplayed or alternative"
16409b0b
GM
1044 :value undisplayed-alternative)
1045 (function)))
1046
e0bad764
DL
1047(defcustom gnus-mime-action-alist
1048 '(("save to file" . gnus-mime-save-part)
23f87bed 1049 ("save and strip" . gnus-mime-save-part-and-strip)
01c52d31 1050 ("replace with file" . gnus-mime-replace-part)
23f87bed 1051 ("delete part" . gnus-mime-delete-part)
e0bad764
DL
1052 ("display as text" . gnus-mime-inline-part)
1053 ("view the part" . gnus-mime-view-part)
1054 ("pipe to command" . gnus-mime-pipe-part)
1055 ("toggle display" . gnus-article-press-button)
23f87bed 1056 ("toggle display" . gnus-article-view-part-as-charset)
e0bad764 1057 ("view as type" . gnus-mime-view-part-as-type)
23f87bed
MB
1058 ("view internally" . gnus-mime-view-part-internally)
1059 ("view externally" . gnus-mime-view-part-externally))
e0bad764
DL
1060 "An alist of actions that run on the MIME attachment."
1061 :group 'gnus-article-mime
1062 :type '(repeat (cons (string :tag "name")
1063 (function))))
1064
01c52d31
MB
1065(defcustom gnus-auto-select-part 1
1066 "Advance to next MIME part when deleting or stripping parts.
1067
1068When 0, point will be placed on the same part as before. When
1069positive (negative), move point forward (backwards) this many
1070parts. When nil, redisplay article."
330f707b 1071 :version "23.1" ;; No Gnus
01c52d31
MB
1072 :group 'gnus-article-mime
1073 :type '(choice (const nil :tag "Redisplay article.")
1074 (const 1 :tag "Next part.")
1075 (const 0 :tag "Current part.")
1076 integer))
1077
16409b0b
GM
1078;;;
1079;;; The treatment variables
1080;;;
1081
1082(defvar gnus-part-display-hook nil
1083 "Hook called on parts that are to receive treatment.")
1084
1085(defvar gnus-article-treat-custom
1086 '(choice (const :tag "Off" nil)
1087 (const :tag "On" t)
1088 (const :tag "Header" head)
01c52d31 1089 (const :tag "First" first)
16409b0b
GM
1090 (const :tag "Last" last)
1091 (integer :tag "Less")
1092 (repeat :tag "Groups" regexp)
1093 (sexp :tag "Predicate")))
1094
1095(defvar gnus-article-treat-head-custom
1096 '(choice (const :tag "Off" nil)
1097 (const :tag "Header" head)))
1098
01c52d31
MB
1099(defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1100 "text/x-patch")
16409b0b
GM
1101 "Parts to treat.")
1102
1103(defvar gnus-inhibit-treatment nil
1104 "Whether to inhibit treatment.")
1105
23f87bed 1106(defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
16409b0b 1107 "Highlight the signature.
01c52d31
MB
1108Valid values are nil, t, `head', `first', `last', an integer or a
1109predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1110 :group 'gnus-article-treat
23f87bed 1111 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1112 :type gnus-article-treat-custom)
1113(put 'gnus-treat-highlight-signature 'highlight t)
1114
1115(defcustom gnus-treat-buttonize 100000
1116 "Add buttons.
01c52d31
MB
1117Valid values are nil, t, `head', `first', `last', an integer or a
1118predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1119 :group 'gnus-article-treat
23f87bed 1120 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1121 :type gnus-article-treat-custom)
1122(put 'gnus-treat-buttonize 'highlight t)
1123
1124(defcustom gnus-treat-buttonize-head 'head
1125 "Add buttons to the head.
01c52d31
MB
1126Valid values are nil, t, `head', `first', `last', an integer or a
1127predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1128 :group 'gnus-article-treat
23f87bed 1129 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1130 :type gnus-article-treat-head-custom)
1131(put 'gnus-treat-buttonize-head 'highlight t)
1132
437ce4be 1133(defcustom gnus-treat-emphasize 50000
16409b0b 1134 "Emphasize text.
01c52d31
MB
1135Valid values are nil, t, `head', `first', `last', an integer or a
1136predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1137 :group 'gnus-article-treat
23f87bed 1138 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1139 :type gnus-article-treat-custom)
1140(put 'gnus-treat-emphasize 'highlight t)
1141
1142(defcustom gnus-treat-strip-cr nil
1143 "Remove carriage returns.
01c52d31
MB
1144Valid values are nil, t, `head', `first', `last', an integer or a
1145predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1146 :version "22.1"
16409b0b 1147 :group 'gnus-article-treat
23f87bed
MB
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1150
1151(defcustom gnus-treat-unsplit-urls nil
1152 "Remove newlines from within URLs.
01c52d31
MB
1153Valid values are nil, t, `head', `first', `last', an integer or a
1154predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1155 :version "22.1"
23f87bed
MB
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-custom)
1159
1160(defcustom gnus-treat-leading-whitespace nil
1161 "Remove leading whitespace in headers.
01c52d31
MB
1162Valid values are nil, t, `head', `first', `last', an integer or a
1163predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1164 :version "22.1"
23f87bed
MB
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1167 :type gnus-article-treat-custom)
1168
1169(defcustom gnus-treat-hide-headers 'head
1170 "Hide headers.
01c52d31
MB
1171Valid values are nil, t, `head', `first', `last', an integer or a
1172predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1173 :group 'gnus-article-treat
23f87bed 1174 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1175 :type gnus-article-treat-head-custom)
1176
1177(defcustom gnus-treat-hide-boring-headers nil
1178 "Hide boring headers.
01c52d31
MB
1179Valid values are nil, t, `head', `first', `last', an integer or a
1180predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1181 :group 'gnus-article-treat
23f87bed 1182 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1183 :type gnus-article-treat-head-custom)
1184
1185(defcustom gnus-treat-hide-signature nil
1186 "Hide the signature.
01c52d31
MB
1187Valid values are nil, t, `head', `first', `last', an integer or a
1188predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1189 :group 'gnus-article-treat
23f87bed 1190 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1191 :type gnus-article-treat-custom)
1192
1193(defcustom gnus-treat-fill-article nil
1194 "Fill the article.
01c52d31
MB
1195Valid values are nil, t, `head', `first', `last', an integer or a
1196predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1197 :group 'gnus-article-treat
23f87bed 1198 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1199 :type gnus-article-treat-custom)
1200
1201(defcustom gnus-treat-hide-citation nil
1202 "Hide cited text.
01c52d31
MB
1203Valid values are nil, t, `head', `first', `last', an integer or a
1204predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1205 :group 'gnus-article-treat
23f87bed 1206 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1207 :type gnus-article-treat-custom)
1208
e0bad764
DL
1209(defcustom gnus-treat-hide-citation-maybe nil
1210 "Hide cited text.
01c52d31
MB
1211Valid values are nil, t, `head', `first', `last', an integer or a
1212predicate. See Info node `(gnus)Customizing Articles'."
e0bad764 1213 :group 'gnus-article-treat
23f87bed 1214 :link '(custom-manual "(gnus)Customizing Articles")
e0bad764
DL
1215 :type gnus-article-treat-custom)
1216
16409b0b
GM
1217(defcustom gnus-treat-strip-list-identifiers 'head
1218 "Strip list identifiers from `gnus-list-identifiers`.
01c52d31
MB
1219Valid values are nil, t, `head', `first', `last', an integer or a
1220predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1221 :version "21.1"
16409b0b 1222 :group 'gnus-article-treat
23f87bed 1223 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1224 :type gnus-article-treat-custom)
1225
265ac10b
SM
1226(make-obsolete-variable 'gnus-treat-strip-pgp nil
1227 "Gnus 5.10 (Emacs 22.1)")
16409b0b
GM
1228
1229(defcustom gnus-treat-strip-pem nil
1230 "Strip PEM signatures.
01c52d31
MB
1231Valid values are nil, t, `head', `first', `last', an integer or a
1232predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1233 :group 'gnus-article-treat
23f87bed 1234 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1235 :type gnus-article-treat-custom)
1236
1237(defcustom gnus-treat-strip-banner t
1238 "Strip banners from articles.
1239The banner to be stripped is specified in the `banner' group parameter.
01c52d31
MB
1240Valid values are nil, t, `head', `first', `last', an integer or a
1241predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1242 :group 'gnus-article-treat
23f87bed 1243 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1244 :type gnus-article-treat-custom)
1245
1246(defcustom gnus-treat-highlight-headers 'head
1247 "Highlight the headers.
01c52d31
MB
1248Valid values are nil, t, `head', `first', `last', an integer or a
1249predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1250 :group 'gnus-article-treat
23f87bed 1251 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1252 :type gnus-article-treat-head-custom)
1253(put 'gnus-treat-highlight-headers 'highlight t)
1254
1255(defcustom gnus-treat-highlight-citation t
1256 "Highlight cited text.
01c52d31
MB
1257Valid values are nil, t, `head', `first', `last', an integer or a
1258predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1259 :group 'gnus-article-treat
23f87bed 1260 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1261 :type gnus-article-treat-custom)
1262(put 'gnus-treat-highlight-citation 'highlight t)
1263
1264(defcustom gnus-treat-date-ut nil
1265 "Display the Date in UT (GMT).
01c52d31
MB
1266Valid values are nil, t, `head', `first', `last', an integer or a
1267predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1268 :group 'gnus-article-treat
23f87bed 1269 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1270 :type gnus-article-treat-head-custom)
1271
1272(defcustom gnus-treat-date-local nil
1273 "Display the Date in the local timezone.
01c52d31
MB
1274Valid values are nil, t, `head', `first', `last', an integer or a
1275predicate. See Info node `(gnus)Customizing Articles'."
23f87bed
MB
1276 :group 'gnus-article-treat
1277 :link '(custom-manual "(gnus)Customizing Articles")
1278 :type gnus-article-treat-head-custom)
1279
1280(defcustom gnus-treat-date-english nil
1281 "Display the Date in a format that can be read aloud in English.
01c52d31
MB
1282Valid values are nil, t, `head', `first', `last', an integer or a
1283predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1284 :version "22.1"
16409b0b 1285 :group 'gnus-article-treat
23f87bed 1286 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1287 :type gnus-article-treat-head-custom)
1288
1289(defcustom gnus-treat-date-lapsed nil
1290 "Display the Date header in a way that says how much time has elapsed.
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
1297(defcustom gnus-treat-date-original nil
1298 "Display the date in the original timezone.
01c52d31
MB
1299Valid values are nil, t, `head', `first', `last', an integer or a
1300predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1301 :group 'gnus-article-treat
23f87bed 1302 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1303 :type gnus-article-treat-head-custom)
1304
1305(defcustom gnus-treat-date-iso8601 nil
1306 "Display the date in the ISO8601 format.
01c52d31
MB
1307Valid values are nil, t, `head', `first', `last', an integer or a
1308predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1309 :version "21.1"
16409b0b 1310 :group 'gnus-article-treat
23f87bed 1311 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1312 :type gnus-article-treat-head-custom)
1313
1314(defcustom gnus-treat-date-user-defined nil
1315 "Display the date in a user-defined format.
1316The format is defined by the `gnus-article-time-format' variable.
01c52d31
MB
1317Valid values are nil, t, `head', `first', `last', an integer or a
1318predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1319 :group 'gnus-article-treat
23f87bed 1320 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1321 :type gnus-article-treat-head-custom)
1322
1323(defcustom gnus-treat-strip-headers-in-body t
1324 "Strip the X-No-Archive header line from the beginning of the body.
01c52d31
MB
1325Valid values are nil, t, `head', `first', `last', an integer or a
1326predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1327 :version "21.1"
16409b0b 1328 :group 'gnus-article-treat
23f87bed 1329 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1330 :type gnus-article-treat-custom)
1331
1332(defcustom gnus-treat-strip-trailing-blank-lines nil
1333 "Strip trailing blank lines.
01c52d31
MB
1334Valid values are nil, t, `head', `first', `last', an integer or a
1335predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1336
1337When set to t, it also strips trailing blanks in all MIME parts.
1338Consider to use `last' instead."
16409b0b 1339 :group 'gnus-article-treat
23f87bed 1340 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1341 :type gnus-article-treat-custom)
1342
1343(defcustom gnus-treat-strip-leading-blank-lines nil
1344 "Strip leading blank lines.
01c52d31
MB
1345Valid values are nil, t, `head', `first', `last', an integer or a
1346predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1347
1348When set to t, it also strips trailing blanks in all MIME parts."
16409b0b 1349 :group 'gnus-article-treat
23f87bed 1350 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1351 :type gnus-article-treat-custom)
1352
1353(defcustom gnus-treat-strip-multiple-blank-lines nil
1354 "Strip multiple blank lines.
01c52d31
MB
1355Valid values are nil, t, `head', `first', `last', an integer or a
1356predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1357 :group 'gnus-article-treat
23f87bed
MB
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1360
1361(defcustom gnus-treat-unfold-headers 'head
1362 "Unfold folded header lines.
01c52d31
MB
1363Valid values are nil, t, `head', `first', `last', an integer or a
1364predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1365 :version "22.1"
23f87bed
MB
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1369
01c52d31
MB
1370(defcustom gnus-article-unfold-long-headers nil
1371 "If non-nil, allow unfolding headers even if the header is long.
1372If it is a regexp, only long headers matching this regexp are unfolded.
1373If it is t, all long headers are unfolded.
1374
1375This variable has no effect if `gnus-treat-unfold-headers' is nil."
330f707b 1376 :version "23.1" ;; No Gnus
01c52d31
MB
1377 :group 'gnus-article-treat
1378 :type '(choice (const nil)
1379 (const :tag "all" t)
1380 (regexp)))
1381
23f87bed
MB
1382(defcustom gnus-treat-fold-headers nil
1383 "Fold headers.
01c52d31
MB
1384Valid values are nil, t, `head', `first', `last', an integer or a
1385predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1386 :version "22.1"
23f87bed
MB
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1390
1391(defcustom gnus-treat-fold-newsgroups 'head
1392 "Fold the Newsgroups and Followup-To headers.
01c52d31
MB
1393Valid values are nil, t, `head', `first', `last', an integer or a
1394predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1395 :version "22.1"
23f87bed
MB
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1398 :type gnus-article-treat-custom)
1399
1400(defcustom gnus-treat-overstrike t
1401 "Treat overstrike highlighting.
01c52d31
MB
1402Valid values are nil, t, `head', `first', `last', an integer or a
1403predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1404 :group 'gnus-article-treat
23f87bed 1405 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1406 :type gnus-article-treat-custom)
1407(put 'gnus-treat-overstrike 'highlight t)
1408
01c52d31
MB
1409(defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1410 "Treat ANSI SGR control sequences.
1411Valid values are nil, t, `head', `first', `last', an integer or a
1412predicate. See Info node `(gnus)Customizing Articles'."
1413 :group 'gnus-article-treat
1414 :link '(custom-manual "(gnus)Customizing Articles")
1415 :type gnus-article-treat-custom)
1416
23f87bed 1417(make-obsolete-variable 'gnus-treat-display-xface
265ac10b 1418 'gnus-treat-display-x-face "22.1")
23f87bed
MB
1419
1420(defcustom gnus-treat-display-x-face
1421 (and (not noninteractive)
11e95b02
MB
1422 (gnus-image-type-available-p 'xbm)
1423 (if (featurep 'xemacs)
1424 (featurep 'xface)
86f5c034
SM
1425 (condition-case nil
1426 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1427 (executable-find "icontopbm"))
1428 ;; shell-command-to-string may signal an error, e.g. if
1429 ;; shell-file-name is not found.
1430 (error nil)))
8b93df01 1431 'head)
16409b0b 1432 "Display X-Face headers.
87ba2830 1433Valid values are nil and `head'.
23f87bed
MB
1434See Info node `(gnus)Customizing Articles' and Info node
1435`(gnus)X-Face' for details."
1436 :group 'gnus-article-treat
1437 :version "21.1"
1438 :link '(custom-manual "(gnus)Customizing Articles")
1439 :link '(custom-manual "(gnus)X-Face")
1440 :type gnus-article-treat-head-custom
1441 :set (lambda (symbol value)
1442 (set-default
1443 symbol
1444 (cond ((or (boundp symbol) (get symbol 'saved-value))
1445 value)
1446 ((boundp 'gnus-treat-display-xface)
1447 (message "\
1448** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (default-value 'gnus-treat-display-xface))
1451 ((get 'gnus-treat-display-xface 'saved-value)
1452 (message "\
1453** gnus-treat-display-xface is an obsolete variable;\
1454 use gnus-treat-display-x-face instead")
1455 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1456 (t
1457 value)))))
1458(put 'gnus-treat-display-x-face 'highlight t)
1459
1460(defcustom gnus-treat-display-face
1461 (and (not noninteractive)
11e95b02 1462 (gnus-image-type-available-p 'png)
23f87bed
MB
1463 'head)
1464 "Display Face headers.
01c52d31
MB
1465Valid values are nil, t, `head', `first', `last', an integer or a
1466predicate. See Info node `(gnus)Customizing Articles' and Info
41ec3f54 1467node `(gnus)Face' for details."
16409b0b 1468 :group 'gnus-article-treat
bf247b6e 1469 :version "22.1"
23f87bed
MB
1470 :link '(custom-manual "(gnus)Customizing Articles")
1471 :link '(custom-manual "(gnus)X-Face")
16409b0b 1472 :type gnus-article-treat-head-custom)
23f87bed 1473(put 'gnus-treat-display-face 'highlight t)
16409b0b 1474
11e95b02 1475(defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
16409b0b 1476 "Display smileys.
01c52d31
MB
1477Valid values are nil, t, `head', `first', `last', an integer or a
1478predicate. See Info node `(gnus)Customizing Articles' and Info
1479node `(gnus)Smileys' for details."
16409b0b 1480 :group 'gnus-article-treat
b5a206e7 1481 :version "21.1"
23f87bed
MB
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Smileys")
16409b0b
GM
1484 :type gnus-article-treat-custom)
1485(put 'gnus-treat-display-smileys 'highlight t)
1486
23f87bed
MB
1487(defcustom gnus-treat-from-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1490 'head nil)
1491 "Display picons in the From header.
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"
16409b0b 1496 :group 'gnus-article-treat
23f87bed
MB
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-from-picon 'highlight t)
1502
1503(defcustom gnus-treat-mail-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1506 'head nil)
1507 "Display picons in To and Cc 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-mail-picon 'highlight t)
1518
1519(defcustom gnus-treat-newsgroups-picon
1520 (if (and (gnus-image-type-available-p 'xpm)
1521 (gnus-picons-installed-p))
1522 'head nil)
1523 "Display picons in the Newsgroups and Followup-To headers.
01c52d31
MB
1524Valid values are nil, t, `head', `first', `last', an integer or a
1525predicate. See Info node `(gnus)Customizing Articles' and Info
1526node `(gnus)Picons' for details."
bf247b6e 1527 :version "22.1"
23f87bed
MB
1528 :group 'gnus-article-treat
1529 :group 'gnus-picon
1530 :link '(custom-manual "(gnus)Customizing Articles")
1531 :link '(custom-manual "(gnus)Picons")
1532 :type gnus-article-treat-head-custom)
1533(put 'gnus-treat-newsgroups-picon 'highlight t)
1534
1535(defcustom gnus-treat-body-boundary
437ce4be
MB
1536 (if (or gnus-treat-newsgroups-picon
1537 gnus-treat-mail-picon
1538 gnus-treat-from-picon)
1539 ;; If there's much decoration, the user might prefer a boundery.
1540 'head
1541 nil)
23f87bed
MB
1542 "Draw a boundary at the end of the headers.
1543Valid values are nil and `head'.
1544See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1545 :version "22.1"
23f87bed
MB
1546 :group 'gnus-article-treat
1547 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b 1548 :type gnus-article-treat-head-custom)
16409b0b
GM
1549
1550(defcustom gnus-treat-capitalize-sentences nil
1551 "Capitalize sentence-starting words.
01c52d31
MB
1552Valid values are nil, t, `head', `first', `last', an integer or a
1553predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1554 :version "21.1"
16409b0b 1555 :group 'gnus-article-treat
23f87bed
MB
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :type gnus-article-treat-custom)
1558
1559(defcustom gnus-treat-wash-html nil
1560 "Format as HTML.
01c52d31
MB
1561Valid values are nil, t, `head', `first', `last', an integer or a
1562predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1563 :version "22.1"
23f87bed
MB
1564 :group 'gnus-article-treat
1565 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1566 :type gnus-article-treat-custom)
1567
1568(defcustom gnus-treat-fill-long-lines nil
1569 "Fill long lines.
01c52d31
MB
1570Valid values are nil, t, `head', `first', `last', an integer or a
1571predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1572 :group 'gnus-article-treat
23f87bed 1573 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1574 :type gnus-article-treat-custom)
1575
1576(defcustom gnus-treat-play-sounds nil
1577 "Play sounds.
01c52d31
MB
1578Valid values are nil, t, `head', `first', `last', an integer or a
1579predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1580 :version "21.1"
16409b0b 1581 :group 'gnus-article-treat
23f87bed 1582 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1583 :type gnus-article-treat-custom)
1584
1585(defcustom gnus-treat-translate nil
1586 "Translate articles from one language to another.
01c52d31
MB
1587Valid values are nil, t, `head', `first', `last', an integer or a
1588predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1589 :version "21.1"
16409b0b 1590 :group 'gnus-article-treat
23f87bed 1591 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1592 :type gnus-article-treat-custom)
1593
23f87bed
MB
1594(defcustom gnus-treat-x-pgp-sig nil
1595 "Verify X-PGP-Sig.
1596To automatically treat X-PGP-Sig, set it to head.
01c52d31
MB
1597Valid values are nil, t, `head', `first', `last', an integer or a
1598predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1599 :version "22.1"
23f87bed
MB
1600 :group 'gnus-article-treat
1601 :group 'mime-security
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1604
1605(defvar gnus-article-encrypt-protocol-alist
1606 '(("PGP" . mml2015-self-encrypt)))
1607
1608;; Set to nil if more than one protocol added to
1609;; gnus-article-encrypt-protocol-alist.
1610(defcustom gnus-article-encrypt-protocol "PGP"
1611 "The protocol used for encrypt articles.
1612It is a string, such as \"PGP\". If nil, ask user."
bf247b6e 1613 :version "22.1"
23f87bed
MB
1614 :type 'string
1615 :group 'mime-security)
1616
1617(defvar gnus-article-wash-function nil
1618 "Function used for converting HTML into text.")
1619
1620(defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1621 (mm-coding-system-p 'utf-8)
1622 (executable-find idna-program))
1623 "Whether IDNA decoding of headers is used when viewing messages.
1624This requires GNU Libidn, and by default only enabled if it is found."
bf247b6e 1625 :version "22.1"
23f87bed
MB
1626 :group 'gnus-article-headers
1627 :type 'boolean)
1628
1629(defcustom gnus-article-over-scroll nil
1630 "If non-nil, allow scrolling the article buffer even when there no more text."
bf247b6e 1631 :version "22.1"
23f87bed
MB
1632 :group 'gnus-article
1633 :type 'boolean)
1634
eec82323
LMI
1635;;; Internal variables
1636
23f87bed
MB
1637(defvar gnus-english-month-names
1638 '("January" "February" "March" "April" "May" "June" "July" "August"
1639 "September" "October" "November" "December"))
1640
16409b0b
GM
1641(defvar article-goto-body-goes-to-point-min-p nil)
1642(defvar gnus-article-wash-types nil)
1643(defvar gnus-article-emphasis-alist nil)
23f87bed 1644(defvar gnus-article-image-alist nil)
16409b0b
GM
1645
1646(defvar gnus-article-mime-handle-alist-1 nil)
1647(defvar gnus-treatment-function-alist
23f87bed
MB
1648 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1649 (gnus-treat-strip-banner gnus-article-strip-banner)
16409b0b
GM
1650 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1651 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1652 (gnus-treat-buttonize gnus-article-add-buttons)
1653 (gnus-treat-fill-article gnus-article-fill-cited-article)
1654 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1655 (gnus-treat-strip-cr gnus-article-remove-cr)
23f87bed
MB
1656 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1657 (gnus-treat-date-ut gnus-article-date-ut)
1658 (gnus-treat-date-local gnus-article-date-local)
1659 (gnus-treat-date-english gnus-article-date-english)
23f87bed
MB
1660 (gnus-treat-date-original gnus-article-date-original)
1661 (gnus-treat-date-user-defined gnus-article-date-user)
1662 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
f3f01d5d 1663 (gnus-treat-date-lapsed gnus-article-date-lapsed)
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)
16409b0b 1671 (gnus-treat-strip-pem gnus-article-hide-pem)
23f87bed
MB
1672 (gnus-treat-from-picon gnus-treat-from-picon)
1673 (gnus-treat-mail-picon gnus-treat-mail-picon)
1674 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
16409b0b 1675 (gnus-treat-highlight-headers gnus-article-highlight-headers)
16409b0b 1676 (gnus-treat-highlight-signature gnus-article-highlight-signature)
16409b0b
GM
1677 (gnus-treat-strip-trailing-blank-lines
1678 gnus-article-remove-trailing-blank-lines)
1679 (gnus-treat-strip-leading-blank-lines
1680 gnus-article-strip-leading-blank-lines)
1681 (gnus-treat-strip-multiple-blank-lines
1682 gnus-article-strip-multiple-blank-lines)
1683 (gnus-treat-overstrike gnus-article-treat-overstrike)
01c52d31 1684 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
23f87bed 1685 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
23f87bed 1686 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
01c52d31 1687 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
16409b0b 1688 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
23f87bed 1689 (gnus-treat-display-smileys gnus-treat-smiley)
16409b0b 1690 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
23f87bed
MB
1691 (gnus-treat-wash-html gnus-article-wash-html)
1692 (gnus-treat-emphasize gnus-article-emphasize)
1693 (gnus-treat-hide-citation gnus-article-hide-citation)
1694 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1695 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1696 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
16409b0b
GM
1697 (gnus-treat-play-sounds gnus-earcon-display)))
1698
1699(defvar gnus-article-mime-handle-alist nil)
6748645f
LMI
1700(defvar article-lapsed-timer nil)
1701(defvar gnus-article-current-summary nil)
1702
eec82323
LMI
1703(defvar gnus-article-mode-syntax-table
1704 (let ((table (copy-syntax-table text-mode-syntax-table)))
23f87bed
MB
1705 ;; This causes the citation match run O(2^n).
1706 ;; (modify-syntax-entry ?- "w" table)
1707 (modify-syntax-entry ?> ")<" table)
1708 (modify-syntax-entry ?< "(>" table)
1709 ;; make M-. in article buffers work for `foo' strings
1710 (modify-syntax-entry ?' " " table)
1711 (modify-syntax-entry ?` " " table)
eec82323
LMI
1712 table)
1713 "Syntax table used in article mode buffers.
1714Initialized from `text-mode-syntax-table.")
1715
1716(defvar gnus-save-article-buffer nil)
1717
eec82323
LMI
1718(defvar gnus-number-of-articles-to-be-saved nil)
1719
1720(defvar gnus-inhibit-hiding nil)
1721
c1d7d285
MB
1722(defvar gnus-article-edit-mode nil)
1723
23f87bed
MB
1724;;; Macros for dealing with the article buffer.
1725
1726(defmacro gnus-with-article-headers (&rest forms)
80de1778 1727 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1728 (save-restriction
1729 (let ((inhibit-read-only t)
1730 (inhibit-point-motion-hooks t)
1731 (case-fold-search t))
1732 (article-narrow-to-head)
1733 ,@forms))))
1734
1735(put 'gnus-with-article-headers 'lisp-indent-function 0)
1736(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1737
1738(defmacro gnus-with-article-buffer (&rest forms)
80de1778 1739 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1740 (let ((inhibit-read-only t))
1741 ,@forms)))
1742
1743(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1744(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1745
1746(defun gnus-article-goto-header (header)
1747 "Go to HEADER, which is a regular expression."
1748 (re-search-forward (concat "^\\(" header "\\):") nil t))
1749
eec82323
LMI
1750(defsubst gnus-article-hide-text (b e props)
1751 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1752 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1753 (when (memq 'intangible props)
1754 (put-text-property
1755 (max (1- b) (point-min))
1756 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1757
eec82323
LMI
1758(defsubst gnus-article-unhide-text (b e)
1759 "Remove hidden text properties from region between B and E."
1760 (remove-text-properties b e gnus-hidden-properties)
1761 (when (memq 'intangible gnus-hidden-properties)
1762 (put-text-property (max (1- b) (point-min))
1763 b 'intangible nil)))
1764
1765(defun gnus-article-hide-text-type (b e type)
1766 "Hide text of TYPE between B and E."
23f87bed 1767 (gnus-add-wash-type type)
eec82323
LMI
1768 (gnus-article-hide-text
1769 b e (cons 'article-type (cons type gnus-hidden-properties))))
1770
1771(defun gnus-article-unhide-text-type (b e type)
6748645f 1772 "Unhide text of TYPE between B and E."
23f87bed 1773 (gnus-delete-wash-type type)
eec82323
LMI
1774 (remove-text-properties
1775 b e (cons 'article-type (cons type gnus-hidden-properties)))
1776 (when (memq 'intangible gnus-hidden-properties)
1777 (put-text-property (max (1- b) (point-min))
1778 b 'intangible nil)))
1779
1780(defun gnus-article-hide-text-of-type (type)
1781 "Hide text of TYPE in the current buffer."
1782 (save-excursion
1783 (let ((b (point-min))
1784 (e (point-max)))
1785 (while (setq b (text-property-any b e 'article-type type))
1786 (add-text-properties b (incf b) gnus-hidden-properties)))))
1787
1788(defun gnus-article-delete-text-of-type (type)
1789 "Delete text of TYPE in the current buffer."
1790 (save-excursion
a8151ef7 1791 (let ((b (point-min)))
7dafe00b
MB
1792 (if (eq type 'multipart)
1793 ;; Remove MIME buttons associated with multipart/alternative parts.
1794 (progn
1795 (goto-char b)
1796 (while (if (get-text-property (point) 'gnus-part)
1797 (setq b (point))
1798 (when (setq b (next-single-property-change (point)
1799 'gnus-part))
1800 (goto-char b)
1801 t))
1802 (end-of-line)
1803 (skip-chars-forward "\n")
1804 (when (eq (get-text-property b 'article-type) 'multipart)
1805 (delete-region b (point)))))
1806 (while (setq b (text-property-any b (point-max) 'article-type type))
1807 (delete-region
1808 b (or (text-property-not-all b (point-max) 'article-type type)
1809 (point-max))))))))
eec82323
LMI
1810
1811(defun gnus-article-delete-invisible-text ()
1812 "Delete all invisible text in the current buffer."
1813 (save-excursion
a8151ef7
LMI
1814 (let ((b (point-min)))
1815 (while (setq b (text-property-any b (point-max) 'invisible t))
1816 (delete-region
1817 b (or (text-property-not-all b (point-max) 'invisible t)
1818 (point-max)))))))
eec82323
LMI
1819
1820(defun gnus-article-text-type-exists-p (type)
1821 "Say whether any text of type TYPE exists in the buffer."
1822 (text-property-any (point-min) (point-max) 'article-type type))
1823
1824(defsubst gnus-article-header-rank ()
1825 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1826 (let ((list gnus-sorted-header-list)
23f87bed 1827 (i 1))
eec82323 1828 (while list
23f87bed
MB
1829 (if (looking-at (car list))
1830 (setq list nil)
1831 (setq list (cdr list))
1832 (incf i)))
1833 i))
eec82323
LMI
1834
1835(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1836 "Hide unwanted headers and possibly sort them as well."
1837 (interactive)
1838 ;; This function might be inhibited.
1839 (unless gnus-inhibit-hiding
37cc095b 1840 (let ((inhibit-read-only t)
23f87bed
MB
1841 (case-fold-search t)
1842 (max (1+ (length gnus-sorted-header-list)))
1843 (inhibit-point-motion-hooks t)
1844 (cur (current-buffer))
1845 ignored visible beg)
1846 (save-excursion
1847 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1848 ;; group parameters, so we should go to the summary buffer.
1849 (when (prog1
1850 (condition-case nil
1851 (progn (set-buffer gnus-summary-buffer) t)
1852 (error nil))
1853 (setq ignored (when (not gnus-visible-headers)
1854 (cond ((stringp gnus-ignored-headers)
1855 gnus-ignored-headers)
1856 ((listp gnus-ignored-headers)
1857 (mapconcat 'identity
1858 gnus-ignored-headers
1859 "\\|"))))
1860 visible (cond ((stringp gnus-visible-headers)
1861 gnus-visible-headers)
1862 ((and gnus-visible-headers
1863 (listp gnus-visible-headers))
1864 (mapconcat 'identity
1865 gnus-visible-headers
1866 "\\|")))))
1867 (set-buffer cur))
1868 (save-restriction
16409b0b
GM
1869 ;; First we narrow to just the headers.
1870 (article-narrow-to-head)
1871 ;; Hide any "From " lines at the beginning of (mail) articles.
1872 (while (looking-at "From ")
1873 (forward-line 1))
1874 (unless (bobp)
1875 (delete-region (point-min) (point)))
1876 ;; Then treat the rest of the header lines.
1877 ;; Then we use the two regular expressions
1878 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1879 ;; select which header lines is to remain visible in the
1880 ;; article buffer.
23f87bed 1881 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
1882 (beginning-of-line)
1883 ;; Mark the rank of the header.
1884 (put-text-property
1885 (point) (1+ (point)) 'message-rank
1886 (if (or (and visible (looking-at visible))
1887 (and ignored
1888 (not (looking-at ignored))))
1889 (gnus-article-header-rank)
1890 (+ 2 max)))
1891 (forward-line 1))
1892 (message-sort-headers-1)
1893 (when (setq beg (text-property-any
1894 (point-min) (point-max) 'message-rank (+ 2 max)))
1895 ;; We delete the unwanted headers.
23f87bed 1896 (gnus-add-wash-type 'headers)
16409b0b
GM
1897 (add-text-properties (point-min) (+ 5 (point-min))
1898 '(article-type headers dummy-invisible t))
1899 (delete-region beg (point-max))))))))
eec82323
LMI
1900
1901(defun article-hide-boring-headers (&optional arg)
1902 "Toggle hiding of headers that aren't very interesting.
1903If given a negative prefix, always show; if given a positive prefix,
1904always hide."
1905 (interactive (gnus-article-hidden-arg))
1906 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1907 (not gnus-show-all-headers))
1908 (save-excursion
1909 (save-restriction
4e7d0221 1910 (let ((inhibit-read-only t)
01c52d31 1911 (inhibit-point-motion-hooks t))
16409b0b 1912 (article-narrow-to-head)
01c52d31 1913 (dolist (elem gnus-boring-article-headers)
eec82323
LMI
1914 (goto-char (point-min))
1915 (cond
1916 ;; Hide empty headers.
1917 ((eq elem 'empty)
16409b0b 1918 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1919 (forward-line -1)
1920 (gnus-article-hide-text-type
01c52d31 1921 (point-at-bol)
eec82323
LMI
1922 (progn
1923 (end-of-line)
1924 (if (re-search-forward "^[^ \t]" nil t)
1925 (match-beginning 0)
1926 (point-max)))
1927 'boring-headers)))
1928 ;; Hide boring Newsgroups header.
1929 ((eq elem 'newsgroups)
23f87bed
MB
1930 (when (gnus-string-equal
1931 (gnus-fetch-field "newsgroups")
1932 (gnus-group-real-name
1933 (if (boundp 'gnus-newsgroup-name)
1934 gnus-newsgroup-name
1935 "")))
eec82323 1936 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
1937 ((eq elem 'to-address)
1938 (let ((to (message-fetch-field "to"))
1939 (to-address
1940 (gnus-parameter-to-address
1941 (if (boundp 'gnus-newsgroup-name)
1942 gnus-newsgroup-name ""))))
1943 (when (and to to-address
1944 (ignore-errors
1945 (gnus-string-equal
1946 ;; only one address in To
1947 (nth 1 (mail-extract-address-components to))
1948 to-address)))
1949 (gnus-article-hide-header "to"))))
1950 ((eq elem 'to-list)
1951 (let ((to (message-fetch-field "to"))
1952 (to-list
1953 (gnus-parameter-to-list
1954 (if (boundp 'gnus-newsgroup-name)
1955 gnus-newsgroup-name ""))))
1956 (when (and to to-list
1957 (ignore-errors
1958 (gnus-string-equal
1959 ;; only one address in To
1960 (nth 1 (mail-extract-address-components to))
1961 to-list)))
1962 (gnus-article-hide-header "to"))))
1963 ((eq elem 'cc-list)
1964 (let ((cc (message-fetch-field "cc"))
1965 (to-list
1966 (gnus-parameter-to-list
1967 (if (boundp 'gnus-newsgroup-name)
1968 gnus-newsgroup-name ""))))
1969 (when (and cc to-list
1970 (ignore-errors
1971 (gnus-string-equal
1972 ;; only one address in CC
1973 (nth 1 (mail-extract-address-components cc))
1974 to-list)))
1975 (gnus-article-hide-header "cc"))))
eec82323 1976 ((eq elem 'followup-to)
23f87bed
MB
1977 (when (gnus-string-equal
1978 (message-fetch-field "followup-to")
1979 (message-fetch-field "newsgroups"))
eec82323
LMI
1980 (gnus-article-hide-header "followup-to")))
1981 ((eq elem 'reply-to)
23f87bed
MB
1982 (if (gnus-group-find-parameter
1983 gnus-newsgroup-name 'broken-reply-to)
1984 (gnus-article-hide-header "reply-to")
1985 (let ((from (message-fetch-field "from"))
1986 (reply-to (message-fetch-field "reply-to")))
1987 (when
1988 (and
eec82323
LMI
1989 from reply-to
1990 (ignore-errors
1991 (equal
23f87bed
MB
1992 (sort (mapcar
1993 (lambda (x) (downcase (cadr x)))
1994 (mail-extract-address-components from t))
1995 'string<)
1996 (sort (mapcar
1997 (lambda (x) (downcase (cadr x)))
1998 (mail-extract-address-components reply-to t))
1999 'string<))))
2000 (gnus-article-hide-header "reply-to")))))
eec82323 2001 ((eq elem 'date)
b193caa3
MB
2002 (let ((date (with-current-buffer gnus-original-article-buffer
2003 ;; If date in `gnus-article-buffer' is localized
2004 ;; (`gnus-treat-date-user-defined'),
2005 ;; `days-between' might fail.
2006 (message-fetch-field "date"))))
eec82323 2007 (when (and date
16409b0b 2008 (< (days-between (current-time-string) date)
eec82323 2009 4))
6748645f
LMI
2010 (gnus-article-hide-header "date"))))
2011 ((eq elem 'long-to)
16409b0b
GM
2012 (let ((to (message-fetch-field "to"))
2013 (cc (message-fetch-field "cc")))
6748645f 2014 (when (> (length to) 1024)
16409b0b
GM
2015 (gnus-article-hide-header "to"))
2016 (when (> (length cc) 1024)
2017 (gnus-article-hide-header "cc"))))
6748645f 2018 ((eq elem 'many-to)
16409b0b
GM
2019 (let ((to-count 0)
2020 (cc-count 0))
6748645f
LMI
2021 (goto-char (point-min))
2022 (while (re-search-forward "^to:" nil t)
2023 (setq to-count (1+ to-count)))
2024 (when (> to-count 1)
2025 (while (> to-count 0)
2026 (goto-char (point-min))
2027 (save-restriction
2028 (re-search-forward "^to:" nil nil to-count)
2029 (forward-line -1)
2030 (narrow-to-region (point) (point-max))
2031 (gnus-article-hide-header "to"))
16409b0b
GM
2032 (setq to-count (1- to-count))))
2033 (goto-char (point-min))
2034 (while (re-search-forward "^cc:" nil t)
2035 (setq cc-count (1+ cc-count)))
2036 (when (> cc-count 1)
2037 (while (> cc-count 0)
2038 (goto-char (point-min))
2039 (save-restriction
2040 (re-search-forward "^cc:" nil nil cc-count)
2041 (forward-line -1)
2042 (narrow-to-region (point) (point-max))
2043 (gnus-article-hide-header "cc"))
2044 (setq cc-count (1- cc-count)))))))))))))
eec82323
LMI
2045
2046(defun gnus-article-hide-header (header)
2047 (save-excursion
2048 (goto-char (point-min))
2049 (when (re-search-forward (concat "^" header ":") nil t)
2050 (gnus-article-hide-text-type
01c52d31 2051 (point-at-bol)
eec82323
LMI
2052 (progn
2053 (end-of-line)
2054 (if (re-search-forward "^[^ \t]" nil t)
2055 (match-beginning 0)
2056 (point-max)))
2057 'boring-headers))))
2058
16409b0b
GM
2059(defvar gnus-article-normalized-header-length 40
2060 "Length of normalized headers.")
2061
2062(defun article-normalize-headers ()
2063 "Make all header lines 40 characters long."
2064 (interactive)
4e7d0221 2065 (let ((inhibit-read-only t)
16409b0b
GM
2066 column)
2067 (save-excursion
2068 (save-restriction
2069 (article-narrow-to-head)
2070 (while (not (eobp))
2071 (cond
01c52d31 2072 ((< (setq column (- (point-at-eol) (point)))
16409b0b
GM
2073 gnus-article-normalized-header-length)
2074 (end-of-line)
2075 (insert (make-string
2076 (- gnus-article-normalized-header-length column)
2077 ? )))
2078 ((> column gnus-article-normalized-header-length)
2079 (gnus-put-text-property
2080 (progn
2081 (forward-char gnus-article-normalized-header-length)
2082 (point))
01c52d31 2083 (point-at-eol)
16409b0b
GM
2084 'invisible t))
2085 (t
2086 ;; Do nothing.
2087 ))
2088 (forward-line 1))))))
2089
6748645f 2090(defun article-treat-dumbquotes ()
23f87bed 2091 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 2092Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
2093not, so it should only be used interactively.
2094
23f87bed
MB
2095Sm*rtq**t*s are M****s***'s unilateral extension to the
2096iso-8859-1 character map in an attempt to provide more quoting
2097characters. If you see something like \\222 or \\264 where
2098you're expecting some kind of apostrophe or quotation mark, then
2099try this wash."
6748645f 2100 (interactive)
16409b0b 2101 (article-translate-strings gnus-article-dumbquotes-map))
6748645f
LMI
2102
2103(defun article-translate-characters (from to)
2104 "Translate all characters in the body of the article according to FROM and TO.
2105FROM is a string of characters to translate from; to is a string of
2106characters to translate to."
2107 (save-excursion
16409b0b 2108 (when (article-goto-body)
4e7d0221 2109 (let ((inhibit-read-only t)
6748645f
LMI
2110 (x (make-string 225 ?x))
2111 (i -1))
2112 (while (< (incf i) (length x))
2113 (aset x i i))
2114 (setq i 0)
2115 (while (< i (length from))
2116 (aset x (aref from i) (aref to i))
2117 (incf i))
2118 (translate-region (point) (point-max) x)))))
2119
16409b0b
GM
2120(defun article-translate-strings (map)
2121 "Translate all string in the body of the article according to MAP.
2122MAP is an alist where the elements are on the form (\"from\" \"to\")."
2123 (save-excursion
2124 (when (article-goto-body)
01c52d31
MB
2125 (let ((inhibit-read-only t))
2126 (dolist (elem map)
16409b0b
GM
2127 (save-excursion
2128 (while (search-forward (car elem) nil t)
2129 (replace-match (cadr elem)))))))))
2130
eec82323
LMI
2131(defun article-treat-overstrike ()
2132 "Translate overstrikes into bold text."
2133 (interactive)
2134 (save-excursion
16409b0b 2135 (when (article-goto-body)
4e7d0221 2136 (let ((inhibit-read-only t))
eec82323 2137 (while (search-forward "\b" nil t)
16409b0b 2138 (let ((next (char-after))
eec82323
LMI
2139 (previous (char-after (- (point) 2))))
2140 ;; We do the boldification/underlining by hiding the
2141 ;; overstrikes and putting the proper text property
2142 ;; on the letters.
2143 (cond
2144 ((eq next previous)
2145 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2146 (put-text-property (point) (1+ (point)) 'face 'bold))
2147 ((eq next ?_)
2148 (gnus-article-hide-text-type
2149 (1- (point)) (1+ (point)) 'overstrike)
2150 (put-text-property
2151 (- (point) 2) (1- (point)) 'face 'underline))
2152 ((eq previous ?_)
2153 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2154 (put-text-property
2155 (point) (1+ (point)) 'face 'underline)))))))))
2156
01c52d31
MB
2157(defun article-treat-ansi-sequences ()
2158 "Translate ANSI SGR control sequences into overlays or extents."
2159 (interactive)
2160 (save-excursion
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (ansi-color-apply-on-region (point) (point-max))))))
2164
23f87bed
MB
2165(defun gnus-article-treat-unfold-headers ()
2166 "Unfold folded message headers.
2167Only the headers that fit into the current window width will be
2168unfolded."
2169 (interactive)
2170 (gnus-with-article-headers
2171 (let (length)
2172 (while (not (eobp))
2173 (save-restriction
2174 (mail-header-narrow-to-field)
01c52d31
MB
2175 (let* ((header (buffer-string))
2176 (unfoldable
2177 (or (equal gnus-article-unfold-long-headers t)
2178 (and (stringp gnus-article-unfold-long-headers)
2179 (string-match gnus-article-unfold-long-headers header)))))
23f87bed
MB
2180 (with-temp-buffer
2181 (insert header)
2182 (goto-char (point-min))
2183 (while (re-search-forward "\n[\t ]" nil t)
2184 (replace-match " " t t)))
01c52d31
MB
2185 (setq length (- (point-max) (point-min) 1))
2186 (when (or unfoldable
2187 (< length (window-width)))
2188 (while (re-search-forward "\n[\t ]" nil t)
2189 (replace-match " " t t))))
23f87bed
MB
2190 (goto-char (point-max)))))))
2191
2192(defun gnus-article-treat-fold-headers ()
2193 "Fold message headers."
2194 (interactive)
2195 (gnus-with-article-headers
2196 (while (not (eobp))
2197 (save-restriction
2198 (mail-header-narrow-to-field)
2199 (mail-header-fold-field)
2200 (goto-char (point-max))))))
2201
2202(defun gnus-treat-smiley ()
2203 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2204 (interactive)
2205 (gnus-with-article-buffer
2206 (if (memq 'smiley gnus-article-wash-types)
2207 (gnus-delete-images 'smiley)
2208 (article-goto-body)
2209 (let ((images (smiley-region (point) (point-max))))
2210 (when images
2211 (gnus-add-wash-type 'smiley)
2212 (dolist (image images)
2213 (gnus-add-image 'smiley image)))))))
2214
2215(defun gnus-article-remove-images ()
2216 "Remove all images from the article buffer."
2217 (interactive)
2218 (gnus-with-article-buffer
2219 (dolist (elem gnus-article-image-alist)
2220 (gnus-delete-images (car elem)))))
2221
2222(defun gnus-article-treat-fold-newsgroups ()
2223 "Unfold folded message headers.
2224Only the headers that fit into the current window width will be
2225unfolded."
2226 (interactive)
2227 (gnus-with-article-headers
2228 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2229 (save-restriction
2230 (mail-header-narrow-to-field)
2231 (while (re-search-forward ", *" nil t)
2232 (replace-match ", " t t))
2233 (mail-header-fold-field)
2234 (goto-char (point-max))))))
2235
b7b80032 2236(defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
01c52d31
MB
2237 "Value of `truncate-lines' in Gnus Article buffer.
2238Valid values are nil, t, `head', `first', `last', an integer or a
2239predicate. See Info node `(gnus)Customizing Articles'."
330f707b 2240 :version "23.1" ;; No Gnus
01c52d31
MB
2241 :group 'gnus-article
2242 ;; :link '(custom-manual "(gnus)Customizing Articles")
2243 :type 'boolean)
2244
2245(defun gnus-article-toggle-truncate-lines (&optional arg)
2246 "Toggle whether to fold or truncate long lines in article the buffer.
2247If ARG is non-nil and not a number, toggle
2248`gnus-article-truncate-lines' too. If ARG is a number, truncate
5229211e 2249long lines if and only if arg is positive."
01c52d31
MB
2250 (interactive "P")
2251 (cond
2252 ((and (numberp arg) (> arg 0))
2253 (setq gnus-article-truncate-lines t))
2254 ((numberp arg)
2255 (setq gnus-article-truncate-lines nil))
2256 (arg
2257 (setq gnus-article-truncate-lines
2258 (not gnus-article-truncate-lines))))
2259 (gnus-with-article-buffer
2260 (cond
2261 ((and (numberp arg) (> arg 0))
2262 (setq truncate-lines nil))
2263 ((numberp arg)
2264 (setq truncate-lines t)))
2265 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2266 ;; `toggle-truncate-lines' needs an argument.
2267 (toggle-truncate-lines)))
2268
23f87bed
MB
2269(defun gnus-article-treat-body-boundary ()
2270 "Place a boundary line at the end of the headers."
2271 (interactive)
2272 (when (and gnus-body-boundary-delimiter
2273 (> (length gnus-body-boundary-delimiter) 0))
2274 (gnus-with-article-headers
2275 (goto-char (point-max))
2276 (let ((start (point)))
2277 (insert "X-Boundary: ")
2278 (gnus-add-text-properties start (point) '(invisible t intangible t))
2279 (insert (let (str)
2280 (while (>= (1- (window-width)) (length str))
2281 (setq str (concat str gnus-body-boundary-delimiter)))
2282 (substring str 0 (1- (window-width))))
2283 "\n")
2284 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2285
16409b0b
GM
2286(defun article-fill-long-lines ()
2287 "Fill lines that are wider than the window width."
eec82323
LMI
2288 (interactive)
2289 (save-excursion
4e7d0221 2290 (let ((inhibit-read-only t)
16409b0b
GM
2291 (width (window-width (get-buffer-window (current-buffer)))))
2292 (save-restriction
2293 (article-goto-body)
80b47379 2294 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2295 (while (not (eobp))
2296 (end-of-line)
2297 (when (>= (current-column) (min fill-column width))
23f87bed 2298 (narrow-to-region (min (1+ (point)) (point-max))
01c52d31 2299 (point-at-bol))
23f87bed
MB
2300 (let ((goback (point-marker)))
2301 (fill-paragraph nil)
2302 (goto-char (marker-position goback)))
16409b0b
GM
2303 (widen))
2304 (forward-line 1)))))))
2305
2306(defun article-capitalize-sentences ()
2307 "Capitalize the first word in each sentence."
2308 (interactive)
2309 (save-excursion
4e7d0221 2310 (let ((inhibit-read-only t)
16409b0b
GM
2311 (paragraph-start "^[\n\^L]"))
2312 (article-goto-body)
2313 (while (not (eobp))
2314 (capitalize-word 1)
2315 (forward-sentence)))))
eec82323
LMI
2316
2317(defun article-remove-cr ()
16409b0b 2318 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2319 (interactive)
2320 (save-excursion
4e7d0221 2321 (let ((inhibit-read-only t))
eec82323 2322 (goto-char (point-min))
16409b0b
GM
2323 (while (re-search-forward "\r+$" nil t)
2324 (replace-match "" t t))
2325 (goto-char (point-min))
eec82323 2326 (while (search-forward "\r" nil t)
16409b0b 2327 (replace-match "\n" t t)))))
eec82323
LMI
2328
2329(defun article-remove-trailing-blank-lines ()
2330 "Remove all trailing blank lines from the article."
2331 (interactive)
2332 (save-excursion
4e7d0221 2333 (let ((inhibit-read-only t))
eec82323
LMI
2334 (goto-char (point-max))
2335 (delete-region
2336 (point)
2337 (progn
2338 (while (and (not (bobp))
16409b0b
GM
2339 (looking-at "^[ \t]*$")
2340 (not (gnus-annotation-in-region-p
01c52d31 2341 (point) (point-at-eol))))
eec82323
LMI
2342 (forward-line -1))
2343 (forward-line 1)
2344 (point))))))
2345
9efa445f 2346(defvar gnus-face-properties-alist)
01c52d31 2347
b890d447 2348(defun article-display-face (&optional force)
23f87bed 2349 "Display any Face headers in the header."
b890d447 2350 (interactive (list 'force))
23f87bed
MB
2351 (let ((wash-face-p buffer-read-only))
2352 (gnus-with-article-headers
2353 ;; When displaying parts, this function can be called several times on
2354 ;; the same article, without any intended toggle semantic (as typing `W
2355 ;; D d' would have). So face deletion must occur only when we come from
2356 ;; an interactive command, that is when the *Article* buffer is
2357 ;; read-only.
2358 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2359 (gnus-delete-images 'face)
b890d447
MB
2360 (let ((from (message-fetch-field "from"))
2361 face faces)
7d0c69be 2362 (save-current-buffer
23f87bed 2363 (when (and wash-face-p
7d0c69be
MB
2364 (gnus-buffer-live-p gnus-original-article-buffer)
2365 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2366 (set-buffer gnus-original-article-buffer))
2367 (save-restriction
2368 (mail-narrow-to-head)
b890d447
MB
2369 (when (or force
2370 ;; Check whether this face is censored.
2371 (not (and gnus-article-x-face-too-ugly
2372 (or from
2373 (setq from (message-fetch-field "from")))
2374 (string-match gnus-article-x-face-too-ugly
2375 from))))
2376 (while (gnus-article-goto-header "Face")
2377 (push (mail-header-field-value) faces)))))
d6697c02 2378 (when faces
7d0c69be 2379 (goto-char (point-min))
b890d447
MB
2380 (let (png image)
2381 (unless (setq from (gnus-article-goto-header "from"))
7d0c69be
MB
2382 (insert "From:")
2383 (setq from (point))
b890d447 2384 (insert " [no `from' set]\n"))
7d0c69be
MB
2385 (while faces
2386 (when (setq png (gnus-convert-face-to-png (pop faces)))
01c52d31
MB
2387 (setq image
2388 (apply 'gnus-create-image png 'png t
2389 (cdr (assq 'png gnus-face-properties-alist))))
d6697c02
MB
2390 (goto-char from)
2391 (gnus-add-wash-type 'face)
2392 (gnus-add-image 'face image)
2393 (gnus-put-image image nil 'face))))))))))
23f87bed 2394
eec82323
LMI
2395(defun article-display-x-face (&optional force)
2396 "Look for an X-Face header and display it if present."
2397 (interactive (list 'force))
23f87bed
MB
2398 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2399 (gnus-with-article-headers
2400 ;; Delete the old process, if any.
2401 (when (process-status "article-x-face")
2402 (delete-process "article-x-face"))
2403 ;; See the comment in `article-display-face'.
2404 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2405 ;; We have already displayed X-Faces, so we remove them
2406 ;; instead.
2407 (gnus-delete-images 'xface)
2408 ;; Display X-Faces.
b890d447
MB
2409 (let ((from (message-fetch-field "from"))
2410 x-faces face)
7d0c69be 2411 (save-current-buffer
23f87bed 2412 (when (and wash-face-p
7d0c69be
MB
2413 (gnus-buffer-live-p gnus-original-article-buffer)
2414 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2415 ;; If type `W f', use gnus-original-article-buffer,
2416 ;; otherwise use the current buffer because displaying
2417 ;; RFC822 parts calls this function too.
2418 (set-buffer gnus-original-article-buffer))
2419 (save-restriction
2420 (mail-narrow-to-head)
b890d447
MB
2421 (and gnus-article-x-face-command
2422 (or force
2423 ;; Check whether this face is censored.
2424 (not (and gnus-article-x-face-too-ugly
2425 (or from
2426 (setq from (message-fetch-field "from")))
2427 (string-match gnus-article-x-face-too-ugly
2428 from))))
2429 (while (gnus-article-goto-header "X-Face")
2430 (push (mail-header-field-value) x-faces)))))
2431 (when x-faces
2432 ;; We display the face.
2433 (cond ((functionp gnus-article-x-face-command)
2434 ;; The command is a lisp function, so we call it.
2435 (mapc gnus-article-x-face-command x-faces))
2436 ((stringp gnus-article-x-face-command)
2437 ;; The command is a string, so we interpret the command
2438 ;; as a, well, command, and fork it off.
2439 (let ((process-connection-type nil))
2440 (gnus-set-process-query-on-exit-flag
2441 (start-process
2442 "article-x-face" nil shell-file-name
2443 shell-command-switch gnus-article-x-face-command)
2444 nil)
2445 ;; Sending multiple EOFs to xv doesn't work,
2446 ;; so we only do a single external face.
2447 (with-temp-buffer
2448 (insert (car x-faces))
2449 (process-send-region "article-x-face"
2450 (point-min) (point-max)))
2451 (process-send-eof "article-x-face")))
2452 (t
2453 (error "`%s' set to `%s' is not a function"
2454 gnus-article-x-face-command
2455 'gnus-article-x-face-command)))))))))
a8151ef7 2456
16409b0b
GM
2457(defun article-decode-mime-words ()
2458 "Decode all MIME-encoded words in the article."
2459 (interactive)
01c52d31 2460 (gnus-with-article-buffer
16409b0b 2461 (let ((inhibit-point-motion-hooks t)
16409b0b 2462 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2463 (mail-parse-ignored-charsets
01c52d31
MB
2464 (with-current-buffer gnus-summary-buffer
2465 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
2466 (mail-decode-encoded-word-region (point-min) (point-max)))))
2467
2468(defun article-decode-charset (&optional prompt)
2469 "Decode charset-encoded text in the article.
2470If PROMPT (the prefix), prompt for a coding system to use."
2471 (interactive "P")
2472 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2473 (inhibit-read-only t)
16409b0b 2474 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2475 (mail-parse-ignored-charsets
16409b0b
GM
2476 (save-excursion (condition-case nil
2477 (set-buffer gnus-summary-buffer)
2478 (error))
2479 gnus-newsgroup-ignored-charsets))
2480 ct cte ctl charset format)
c96ec15a
MB
2481 (save-excursion
2482 (save-restriction
2483 (article-narrow-to-head)
2484 (setq ct (message-fetch-field "Content-Type" t)
2485 cte (message-fetch-field "Content-Transfer-Encoding" t)
2486 ctl (and ct (mail-header-parse-content-type ct))
2487 charset (cond
2488 (prompt
2489 (mm-read-coding-system "Charset to decode: "))
2490 (ctl
2491 (mail-content-type-get ctl 'charset)))
2492 format (and ctl (mail-content-type-get ctl 'format)))
2493 (when cte
2494 (setq cte (mail-header-strip cte)))
2495 (if (and ctl (not (string-match "/" (car ctl))))
2496 (setq ctl nil))
2497 (goto-char (point-max)))
2498 (forward-line 1)
2499 (save-restriction
2500 (narrow-to-region (point) (point-max))
2501 (when (and (eq mail-parse-charset 'gnus-decoded)
2502 (eq (mm-body-7-or-8) '8bit))
2503 ;; The text code could have been decoded.
2504 (setq charset mail-parse-charset))
2505 (when (and (or (not ctl)
2506 (equal (car ctl) "text/plain"))
2507 (not format)) ;; article with format will decode later.
2508 (mm-decode-body
2509 charset (and cte (intern (downcase
2510 (gnus-strip-whitespace cte))))
2511 (car ctl)))))))
16409b0b
GM
2512
2513(defun article-decode-encoded-words ()
2514 "Remove encoded-word encoding from headers."
2515 (let ((inhibit-point-motion-hooks t)
2516 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2517 (mail-parse-ignored-charsets
16409b0b
GM
2518 (save-excursion (condition-case nil
2519 (set-buffer gnus-summary-buffer)
2520 (error))
2521 gnus-newsgroup-ignored-charsets))
343d6628 2522 (inhibit-read-only t)
8fbdffe5
MB
2523 end start)
2524 (goto-char (point-min))
2525 (when (search-forward "\n\n" nil 'move)
2526 (forward-line -1))
2527 (setq end (point))
2528 (while (not (bobp))
2529 (while (progn
2530 (forward-line -1)
2531 (and (not (bobp))
2532 (memq (char-after) '(?\t ? )))))
2533 (setq start (point))
2534 (if (looking-at "\
343d6628
MB
2535\\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2536\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
8fbdffe5
MB
2537 (funcall gnus-decode-address-function start end)
2538 (funcall gnus-decode-header-function start end))
2539 (goto-char (setq end start)))))
eec82323 2540
23f87bed 2541(defun article-decode-group-name ()
01c52d31 2542 "Decode group names in Newsgroups, Followup-To and Xref headers."
23f87bed
MB
2543 (let ((inhibit-point-motion-hooks t)
2544 (inhibit-read-only t)
01c52d31
MB
2545 (method (gnus-find-method-for-group gnus-newsgroup-name))
2546 regexp)
23f87bed
MB
2547 (when (and (or gnus-group-name-charset-method-alist
2548 gnus-group-name-charset-group-alist)
2549 (gnus-buffer-live-p gnus-original-article-buffer))
2550 (save-restriction
2551 (article-narrow-to-head)
01c52d31
MB
2552 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2553 (with-current-buffer gnus-original-article-buffer
2554 (goto-char (point-min)))
2555 (setq regexp (concat "^" header
2556 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2557 (while (re-search-forward regexp nil t)
2558 (replace-match (save-match-data
2559 (gnus-decode-newsgroups
2560 ;; XXX how to use data in article buffer?
2561 (with-current-buffer gnus-original-article-buffer
2562 (re-search-forward regexp nil t)
2563 (match-string 1))
2564 gnus-newsgroup-name method))
2565 t t nil 1))
2566 (goto-char (point-min)))))))
23f87bed
MB
2567
2568(autoload 'idna-to-unicode "idna")
2569
2570(defun article-decode-idna-rhs ()
53cfefc8
MB
2571 "Decode IDNA strings in RHS in various headers in current buffer.
2572The following headers are decoded: From:, To:, Cc:, Reply-To:,
2573Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2574 (when gnus-use-idna
2575 (save-restriction
2576 (let ((inhibit-point-motion-hooks t)
2577 (inhibit-read-only t))
2578 (article-narrow-to-head)
2579 (goto-char (point-min))
53cfefc8 2580 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2581 (let (ace unicode)
2582 (when (save-match-data
2583 (and (setq ace (match-string 1))
2584 (save-excursion
2585 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2586 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2587 (setq unicode (idna-to-unicode ace))))
2588 (unless (string= ace unicode)
2589 (replace-match unicode nil nil nil 1)))))))))
2590
2591(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2592 "Translate a quoted-printable-encoded article.
eec82323 2593If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2594or not.
2595If READ-CHARSET, ask for a coding system."
2596 (interactive (list 'force current-prefix-arg))
eec82323 2597 (save-excursion
4e7d0221 2598 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2599 (if (gnus-buffer-live-p gnus-original-article-buffer)
2600 (with-current-buffer gnus-original-article-buffer
2601 (setq type
2602 (gnus-fetch-field "content-transfer-encoding"))
2603 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2604 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2605 (setq charset (and ctl
2606 (mail-content-type-get ctl 'charset)))
2607 (if (stringp charset)
2608 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2609 (if read-charset
2610 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2611 (unless charset
8b93df01 2612 (setq charset gnus-newsgroup-charset))
eec82323 2613 (when (or force
eb806ef3
DL
2614 (and type (let ((case-fold-search t))
2615 (string-match "quoted-printable" type))))
16409b0b 2616 (article-goto-body)
eb806ef3
DL
2617 (quoted-printable-decode-region
2618 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2619
23f87bed 2620(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2621 "Translate a base64 article.
23f87bed
MB
2622If FORCE, decode the article whether it is marked as base64 not.
2623If READ-CHARSET, ask for a coding system."
2624 (interactive (list 'force current-prefix-arg))
16409b0b 2625 (save-excursion
4e7d0221 2626 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2627 (if (gnus-buffer-live-p gnus-original-article-buffer)
2628 (with-current-buffer gnus-original-article-buffer
2629 (setq type
2630 (gnus-fetch-field "content-transfer-encoding"))
2631 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2632 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2633 (setq charset (and ctl
2634 (mail-content-type-get ctl 'charset)))
2635 (if (stringp charset)
2636 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2637 (if read-charset
2638 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2639 (unless charset
8b93df01 2640 (setq charset gnus-newsgroup-charset))
16409b0b 2641 (when (or force
eb806ef3
DL
2642 (and type (let ((case-fold-search t))
2643 (string-match "base64" type))))
16409b0b
GM
2644 (article-goto-body)
2645 (save-restriction
2646 (narrow-to-region (point) (point-max))
2647 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2648 (mm-decode-coding-region
2649 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2650
2651(eval-when-compile
2652 (require 'rfc1843))
2653
2654(defun article-decode-HZ ()
2655 "Translate a HZ-encoded article."
2656 (interactive)
2657 (require 'rfc1843)
2658 (save-excursion
4e7d0221 2659 (let ((inhibit-read-only t))
16409b0b
GM
2660 (rfc1843-decode-region (point-min) (point-max)))))
2661
23f87bed
MB
2662(defun article-unsplit-urls ()
2663 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2664 (interactive)
23f87bed
MB
2665 (save-excursion
2666 (let ((inhibit-read-only t))
2667 (goto-char (point-min))
2668 (while (re-search-forward
97f78c9b 2669 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2670 (replace-match "\\1\\3" t)))
2671 (when (interactive-p)
2672 (gnus-treat-article nil))))
2673
2674
2675(defun article-wash-html (&optional read-charset)
2676 "Format an HTML article.
73043f7d
MB
2677If READ-CHARSET, ask for a coding system. If it is a number, the
2678charset defined in `gnus-summary-show-article-charset-alist' is used."
23f87bed 2679 (interactive "P")
16409b0b 2680 (save-excursion
4e7d0221 2681 (let ((inhibit-read-only t)
8b93df01 2682 charset)
73043f7d
MB
2683 (if read-charset
2684 (if (or (and (numberp read-charset)
2685 (setq charset
2686 (cdr
2687 (assq read-charset
2688 gnus-summary-show-article-charset-alist))))
2689 (setq charset (mm-read-coding-system "Charset: ")))
2690 (let ((gnus-summary-show-article-charset-alist
2691 (list (cons 1 charset))))
2692 (with-current-buffer gnus-summary-buffer
2693 (gnus-summary-show-article 1)))
2694 (error "No charset is given"))
2695 (when (gnus-buffer-live-p gnus-original-article-buffer)
2696 (with-current-buffer gnus-original-article-buffer
2697 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2698 (ctl (and ct (mail-header-parse-content-type ct))))
73043f7d
MB
2699 (setq charset (and ctl
2700 (mail-content-type-get ctl 'charset)))
2701 (when (stringp charset)
2702 (setq charset (intern (downcase charset)))))))
2703 (unless charset
2704 (setq charset gnus-newsgroup-charset)))
16409b0b
GM
2705 (article-goto-body)
2706 (save-window-excursion
2707 (save-restriction
2708 (narrow-to-region (point) (point-max))
23f87bed
MB
2709 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2710 (entry (assq func mm-text-html-washer-alist)))
2711 (when entry
2712 (setq func (cdr entry)))
2713 (cond
2714 ((functionp func)
2715 (funcall func))
2716 (t
2717 (apply (car func) (cdr func))))))))))
2718
9640c3bc
GM
2719;; External.
2720(declare-function w3-region "ext:w3-display" (st nd))
2721
23f87bed
MB
2722(defun gnus-article-wash-html-with-w3 ()
2723 "Wash the current buffer with w3."
2724 (mm-setup-w3)
2725 (let ((w3-strict-width (window-width))
2726 (url-standalone-mode t)
2727 (url-gateway-unplugged t)
2728 (w3-honor-stylesheets nil))
2729 (condition-case ()
2730 (w3-region (point-min) (point-max))
2731 (error))))
2732
9640c3bc
GM
2733;; External.
2734(declare-function w3m-region "ext:w3m" (start end &optional url charset))
2735
23f87bed
MB
2736(defun gnus-article-wash-html-with-w3m ()
2737 "Wash the current buffer with emacs-w3m."
2738 (mm-setup-w3m)
7dafe00b
MB
2739 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2740 w3m-force-redisplay)
2741 (w3m-region (point-min) (point-max)))
1250af7b
KY
2742 ;; Put the mark meaning this part was rendered by emacs-w3m.
2743 (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
7dafe00b
MB
2744 (when (and mm-inline-text-html-with-w3m-keymap
2745 (boundp 'w3m-minor-mode-map)
2746 w3m-minor-mode-map)
886367d8
KY
2747 (if (and (boundp 'w3m-link-map)
2748 w3m-link-map)
1250af7b
KY
2749 (let* ((start (point-min))
2750 (end (point-max))
2751 (on (get-text-property start 'w3m-href-anchor))
2752 (map (copy-keymap w3m-link-map))
2753 next)
886367d8 2754 (set-keymap-parent map w3m-minor-mode-map)
1250af7b
KY
2755 (while (< start end)
2756 (if on
2757 (progn
2758 (setq next (or (text-property-any start end
2759 'w3m-href-anchor nil)
2760 end))
2761 (put-text-property start next 'keymap map))
2762 (setq next (or (text-property-not-all start end
2763 'w3m-href-anchor nil)
2764 end))
2765 (put-text-property start next 'keymap w3m-minor-mode-map))
2766 (setq start next
2767 on (not on))))
2768 (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
16409b0b 2769
9efa445f 2770(defvar charset) ;; Bound by `article-wash-html'.
73043f7d
MB
2771
2772(defun gnus-article-wash-html-with-w3m-standalone ()
2773 "Wash the current buffer with w3m."
7347faa8
MB
2774 (if (mm-w3m-standalone-supports-m17n-p)
2775 (progn
2776 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2777 ;; The default.
2778 (setq charset 'iso-8859-1))
2779 (let ((coding-system-for-write charset)
2780 (coding-system-for-read charset))
2781 (call-process-region
2782 (point-min) (point-max)
2783 "w3m" t t nil "-dump" "-T" "text/html"
2784 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2785 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
73043f7d 2786
01c52d31
MB
2787(defvar gnus-article-browse-html-temp-list nil
2788 "List of temporary files created by `gnus-article-browse-html-parts'.
2789Internal variable.")
2790
2791(defcustom gnus-article-browse-delete-temp 'ask
2792 "What to do with temporary files from `gnus-article-browse-html-parts'.
2793If nil, don't delete temporary files. If it is t, delete them on
2794exit from the summary buffer. If it is the symbol `file', query
2795on each file, if it is `ask' ask once when exiting from the
2796summary buffer."
2797 :group 'gnus-article
330f707b 2798 :version "23.1" ;; No Gnus
01c52d31
MB
2799 :type '(choice (const :tag "Don't delete" nil)
2800 (const :tag "Don't ask" t)
2801 (const :tag "Ask" ask)
2802 (const :tag "Ask for each file" file)))
2803
2804;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2805
2806(defun gnus-article-browse-delete-temp-files (&optional how)
2807 "Delete temp-files created by `gnus-article-browse-html-parts'."
2808 (when (and gnus-article-browse-html-temp-list
2809 (or how
2810 (setq how gnus-article-browse-delete-temp)))
2811 (when (and (eq how 'ask)
bbbe940b
MB
2812 (gnus-y-or-n-p (format
2813 "Delete all %s temporary HTML file(s)? "
2814 (length gnus-article-browse-html-temp-list)))
01c52d31
MB
2815 (setq how t)))
2816 (dolist (file gnus-article-browse-html-temp-list)
2817 (when (and (file-exists-p file)
2818 (or (eq how t)
2819 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2820 (gnus-y-or-n-p
2821 (format "Delete temporary HTML file `%s'? " file))))
20c0b2ce
KY
2822 (if (file-directory-p file)
2823 (gnus-delete-directory file)
2824 (delete-file file))))
01c52d31
MB
2825 ;; Also remove file from the list when not deleted or if file doesn't
2826 ;; exist anymore.
2827 (setq gnus-article-browse-html-temp-list nil))
2828 gnus-article-browse-html-temp-list)
2829
d40d713a
KY
2830(defun gnus-article-browse-html-save-cid-content (cid handles directory)
2831 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2832Return file name."
20c0b2ce 2833 (save-match-data
d40d713a
KY
2834 (let (file type)
2835 (catch 'found
2836 (dolist (handle handles)
2837 (cond
2838 ((not (listp handle)))
2839 ((equal (mm-handle-media-supertype handle) "multipart")
2840 (when (setq file (gnus-article-browse-html-save-cid-content
2841 cid handle directory))
2842 (throw 'found file)))
2843 ((equal (concat "<" cid ">") (mm-handle-id handle))
2844 (setq file
2845 (expand-file-name
2846 (or (mail-content-type-get
2847 (mm-handle-disposition handle) 'filename)
2848 (mail-content-type-get
2849 (setq type (mm-handle-type handle)) 'name)
2850 (concat
2851 (make-temp-name "cid")
2852 (car (rassoc (car type) mailcap-mime-extensions))))
2853 directory))
2854 (mm-save-part-to-file handle file)
2855 (throw 'found file))))))))
20c0b2ce 2856
87035689 2857(defun gnus-article-browse-html-parts (list &optional header)
01c52d31 2858 "View all \"text/html\" parts from LIST.
87035689
MB
2859Recurse into multiparts. The optional HEADER that should be a decoded
2860message header will be added to the bodies of the \"text/html\" parts."
01c52d31 2861 ;; Internal function used by `gnus-article-browse-html-article'.
d40d713a 2862 (let (type file charset content cid-dir tmp-file showed)
01c52d31
MB
2863 ;; Find and show the html-parts.
2864 (dolist (handle list)
2865 ;; If HTML, show it:
bbbe940b
MB
2866 (cond ((not (listp handle)))
2867 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2868 (and (equal (car type) "message/external-body")
87035689
MB
2869 (or header
2870 (setq file (or (mail-content-type-get type 'name)
2871 (mail-content-type-get
2872 (mm-handle-disposition handle)
2873 'filename))))
bbbe940b
MB
2874 (or (mm-handle-cache handle)
2875 (condition-case code
2876 (progn (mm-extern-cache-contents handle) t)
2877 (error
2878 (gnus-message 3 "%s" (error-message-string code))
2879 (when (>= gnus-verbose 3) (sit-for 2))
2880 nil)))
2881 (progn
2882 (setq handle (mm-handle-cache handle)
2883 type (mm-handle-type handle))
2884 (equal (car type) "text/html"))))
d40d713a
KY
2885 (setq charset (mail-content-type-get type 'charset)
2886 content (mm-get-part handle))
2887 (with-temp-buffer
2888 (if (eq charset 'gnus-decoded)
2889 (mm-enable-multibyte)
2890 (mm-disable-multibyte))
2891 (insert content)
2892 ;; resolve cid contents
2893 (let ((case-fold-search t)
2894 cid-file)
2895 (goto-char (point-min))
2896 (while (re-search-forward "\
2897<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2898 nil t)
2899 (unless cid-dir
2900 (setq cid-dir (make-temp-file "cid" t))
2901 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2902 (setq file nil
2903 content nil)
2904 (when (setq cid-file
2905 (gnus-article-browse-html-save-cid-content
2906 (match-string 2)
2907 (with-current-buffer gnus-article-buffer
2908 gnus-article-mime-handles)
2909 cid-dir))
2910 (replace-match (concat "file://" cid-file)
2911 nil nil nil 1))))
2912 (unless content (setq content (buffer-string))))
2913 (when (or charset header (not file))
bbbe940b
MB
2914 (setq tmp-file (mm-make-temp-file
2915 ;; Do we need to care for 8.3 filenames?
2916 "mm-" nil ".html")))
87035689
MB
2917 ;; Add a meta html tag to specify charset and a header.
2918 (cond
2919 (header
d40d713a 2920 (let (title eheader body hcharset coding force-charset)
87035689
MB
2921 (with-temp-buffer
2922 (mm-enable-multibyte)
2923 (setq case-fold-search t)
2924 (insert header "\n")
2925 (setq title (message-fetch-field "subject"))
2926 (goto-char (point-min))
2927 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2928 (replace-match (cond ((match-beginning 1) "&lt;")
2929 ((match-beginning 2) "&gt;")
2930 (t "&amp;"))))
2931 (goto-char (point-min))
2932 (insert "<pre>\n")
2933 (goto-char (point-max))
2934 (insert "</pre>\n<hr>\n")
2935 ;; We have to examine charset one by one since
2936 ;; charset specified in parts might be different.
2937 (if (eq charset 'gnus-decoded)
2938 (setq charset 'utf-8
2939 eheader (mm-encode-coding-string (buffer-string)
2940 charset)
2941 title (when title
2942 (mm-encode-coding-string title charset))
d40d713a 2943 body (mm-encode-coding-string content charset)
82fc7980 2944 force-charset t)
87035689
MB
2945 (setq hcharset (mm-find-mime-charset-region (point-min)
2946 (point-max)))
2947 (cond ((= (length hcharset) 1)
2948 (setq hcharset (car hcharset)
2949 coding (mm-charset-to-coding-system
2950 hcharset)))
2951 ((> (length hcharset) 1)
2952 (setq hcharset 'utf-8
2953 coding hcharset)))
2954 (if coding
2955 (if charset
2956 (progn
2957 (setq body
2958 (mm-charset-to-coding-system charset))
2959 (if (eq coding body)
2960 (setq eheader (mm-encode-coding-string
2961 (buffer-string) coding)
2962 title (when title
2963 (mm-encode-coding-string
2964 title coding))
d40d713a 2965 body content)
87035689
MB
2966 (setq charset 'utf-8
2967 eheader (mm-encode-coding-string
2968 (buffer-string) charset)
2969 title (when title
2970 (mm-encode-coding-string
2971 title charset))
2972 body (mm-encode-coding-string
2973 (mm-decode-coding-string
d40d713a 2974 content body)
82fc7980
KY
2975 charset)
2976 force-charset t)))
87035689
MB
2977 (setq charset hcharset
2978 eheader (mm-encode-coding-string
2979 (buffer-string) coding)
2980 title (when title
2981 (mm-encode-coding-string
2982 title coding))
d40d713a 2983 body content))
87035689 2984 (setq eheader (mm-string-as-unibyte (buffer-string))
d40d713a 2985 body content)))
87035689
MB
2986 (erase-buffer)
2987 (mm-disable-multibyte)
2988 (insert body)
2989 (when charset
82fc7980 2990 (mm-add-meta-html-tag handle charset force-charset))
87035689
MB
2991 (when title
2992 (goto-char (point-min))
2993 (unless (search-forward "<title>" nil t)
2994 (re-search-forward "<head>\\s-*" nil t)
2995 (insert "<title>" title "</title>\n")))
2996 (goto-char (point-min))
2997 (or (re-search-forward
2998 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2999 (re-search-forward
3000 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
3001 (insert eheader)
3002 (mm-write-region (point-min) (point-max)
3003 tmp-file nil nil nil 'binary t))))
3004 (charset
3005 (mm-with-unibyte-buffer
3006 (insert (if (eq charset 'gnus-decoded)
d40d713a
KY
3007 (mm-encode-coding-string content
3008 (setq charset 'utf-8))
3009 content))
87035689
MB
3010 (if (or (mm-add-meta-html-tag handle charset)
3011 (not file))
3012 (mm-write-region (point-min) (point-max)
3013 tmp-file nil nil nil 'binary t)
3014 (setq tmp-file nil))))
3015 (tmp-file
3016 (mm-save-part-to-file handle tmp-file)))
bbbe940b
MB
3017 (when tmp-file
3018 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3019 (add-hook 'gnus-summary-prepare-exit-hook
3020 'gnus-article-browse-delete-temp-files)
3021 (add-hook 'gnus-exit-gnus-hook
3022 (lambda ()
3023 (gnus-article-browse-delete-temp-files t)))
3024 ;; FIXME: Warn if there's an <img> tag?
3025 (browse-url-of-file (or tmp-file (expand-file-name file)))
3026 (setq showed t))
3027 ;; If multipart, recurse
87035689
MB
3028 ((equal (mm-handle-media-supertype handle) "multipart")
3029 (when (gnus-article-browse-html-parts handle header)
3030 (setq showed t)))
3031 ((equal (mm-handle-media-type handle) "message/rfc822")
3032 (mm-with-multibyte-buffer
3033 (mm-insert-part handle)
3034 (setq handle (mm-dissect-buffer t t))
3035 (when (and (bufferp (car handle))
3036 (stringp (car (mm-handle-type handle))))
3037 (setq handle (list handle)))
3038 (when header
3039 (article-decode-encoded-words)
3040 (let ((gnus-visible-headers
3041 (or (get 'gnus-visible-headers 'standard-value)
3042 gnus-visible-headers)))
3043 (article-hide-headers))
3044 (goto-char (point-min))
3045 (search-forward "\n\n" nil 'move)
3046 (skip-chars-backward "\t\n ")
3047 (setq header (buffer-substring (point-min) (point)))))
3048 (when (prog1
3049 (gnus-article-browse-html-parts handle header)
3050 (mm-destroy-parts handle))
3051 (setq showed t)))))
01c52d31
MB
3052 showed))
3053
87035689 3054(defun gnus-article-browse-html-article (&optional arg)
01c52d31 3055 "View \"text/html\" parts of the current article with a WWW browser.
d40d713a
KY
3056Inline images embedded in a message using the cid scheme, as they are
3057generally considered to be safe, will be processed properly.
87035689
MB
3058The message header is added to the beginning of every html part unless
3059the prefix argument ARG is given.
01c52d31 3060
d40d713a
KY
3061Warning: Spammers use links to images (using the http scheme) in HTML
3062articles to verify whether you have read the message. As
9b3ebcb6
MB
3063`gnus-article-browse-html-article' passes the HTML content to the
3064browser without eliminating these \"web bugs\" you should only
3065use it for mails from trusted senders.
b890d447 3066
9b3ebcb6 3067If you always want to display HTML parts in the browser, set
d40d713a
KY
3068`mm-text-html-renderer' to nil.
3069
3070This command creates temporary files to pass HTML contents including
3071images if any to the browser, and deletes them when exiting the group
3072\(if you want)."
01c52d31 3073 ;; Cf. `mm-w3m-safe-url-regexp'
87035689
MB
3074 (interactive "P")
3075 (if arg
3076 (gnus-summary-show-article)
3077 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
9b3ebcb6
MB
3078 gnus-visible-headers))
3079 ;; As we insert a <hr>, there's no need for the body boundary.
3080 (gnus-treat-body-boundary nil))
87035689
MB
3081 (gnus-summary-show-article)))
3082 (with-current-buffer gnus-article-buffer
3083 (let ((header (unless arg
3084 (save-restriction
3085 (widen)
3086 (buffer-substring-no-properties
3087 (goto-char (point-min))
3088 (if (search-forward "\n\n" nil t)
3089 (match-beginning 0)
3090 (goto-char (point-max))
3091 (skip-chars-backward "\t\n ")
3092 (point))))))
3093 parts)
3094 (set-buffer gnus-original-article-buffer)
3095 (setq parts (mm-dissect-buffer t t))
01c52d31
MB
3096 ;; If singlepart, enforce a list.
3097 (when (and (bufferp (car parts))
3098 (stringp (car (mm-handle-type parts))))
3099 (setq parts (list parts)))
3100 ;; Process the list
87035689 3101 (unless (gnus-article-browse-html-parts parts header)
01c52d31 3102 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
87035689
MB
3103 (mm-destroy-parts parts)
3104 (unless arg
3105 (gnus-summary-show-article)))))
01c52d31 3106
16409b0b
GM
3107(defun article-hide-list-identifiers ()
3108 "Remove list identifies from the Subject header.
3109The `gnus-list-identifiers' variable specifies what to do."
3110 (interactive)
23f87bed
MB
3111 (let ((inhibit-point-motion-hooks t)
3112 (regexp (if (consp gnus-list-identifiers)
3113 (mapconcat 'identity gnus-list-identifiers " *\\|")
3114 gnus-list-identifiers))
3115 (inhibit-read-only t))
3116 (when regexp
3117 (save-excursion
3118 (save-restriction
3119 (article-narrow-to-head)
3120 (goto-char (point-min))
3121 (while (re-search-forward
3122 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3123 nil t)
3124 (delete-region (match-beginning 2) (match-end 0))
3125 (beginning-of-line))
3126 (when (re-search-forward
3127 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3128 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
3129
3130(defun article-hide-pem (&optional arg)
3131 "Toggle hiding of any PEM headers and signatures in the current article.
3132If given a negative prefix, always show; if given a positive prefix,
3133always hide."
3134 (interactive (gnus-article-hidden-arg))
3135 (unless (gnus-article-check-hidden-text 'pem arg)
3136 (save-excursion
23f87bed 3137 (let ((inhibit-read-only t) end)
eec82323 3138 (goto-char (point-min))
16409b0b
GM
3139 ;; Hide the horrendously ugly "header".
3140 (when (and (search-forward
3141 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3142 nil t)
3143 (setq end (1+ (match-beginning 0))))
23f87bed 3144 (gnus-add-wash-type 'pem)
16409b0b
GM
3145 (gnus-article-hide-text-type
3146 end
3147 (if (search-forward "\n\n" nil t)
3148 (match-end 0)
3149 (point-max))
3150 'pem)
3151 ;; Hide the trailer as well
3152 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3153 nil t)
3154 (gnus-article-hide-text-type
3155 (match-beginning 0) (match-end 0) 'pem)))))))
3156
3157(defun article-strip-banner ()
23f87bed
MB
3158 "Strip the banners specified by the `banner' group parameter and by
3159`gnus-article-address-banner-alist'."
16409b0b 3160 (interactive)
23f87bed
MB
3161 (save-excursion
3162 (save-restriction
3163 (let ((inhibit-point-motion-hooks t))
3164 (when (gnus-parameter-banner gnus-newsgroup-name)
3165 (article-really-strip-banner
3166 (gnus-parameter-banner gnus-newsgroup-name)))
3167 (when gnus-article-address-banner-alist
cf5a5c38
MB
3168 ;; Note that the From header is decoded here, so it is
3169 ;; required that the *-extract-address-components function
3170 ;; supports non-ASCII text.
d71c0855
MB
3171 (let ((from (save-restriction
3172 (widen)
3173 (article-narrow-to-head)
3174 (mail-fetch-field "from"))))
3175 (when (and from
3176 (setq from
3177 (cadr (funcall gnus-extract-address-components
3178 from))))
3179 (catch 'found
3180 (dolist (pair gnus-article-address-banner-alist)
3181 (when (string-match (car pair) from)
3182 (throw 'found
3183 (article-really-strip-banner (cdr pair)))))))))))))
23f87bed
MB
3184
3185(defun article-really-strip-banner (banner)
3186 "Strip the banner specified by the argument."
16409b0b
GM
3187 (save-excursion
3188 (save-restriction
3189 (let ((inhibit-point-motion-hooks t)
16409b0b 3190 (gnus-signature-limit nil)
23f87bed
MB
3191 (inhibit-read-only t))
3192 (article-goto-body)
3193 (cond
3194 ((eq banner 'signature)
3195 (when (gnus-article-narrow-to-signature)
3196 (widen)
3197 (forward-line -1)
3198 (delete-region (point) (point-max))))
3199 ((symbolp banner)
3200 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3201 (while (re-search-forward banner nil t)
3202 (delete-region (match-beginning 0) (match-end 0)))))
3203 ((stringp banner)
3204 (while (re-search-forward banner nil t)
3205 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
3206
3207(defun article-babel ()
3208 "Translate article using an online translation service."
3209 (interactive)
3210 (require 'babel)
01c52d31 3211 (gnus-with-article-buffer
16409b0b 3212 (when (article-goto-body)
01c52d31 3213 (let* ((start (point))
16409b0b
GM
3214 (end (point-max))
3215 (orig (buffer-substring start end))
23f87bed 3216 (trans (babel-as-string orig)))
16409b0b
GM
3217 (save-restriction
3218 (narrow-to-region start end)
3219 (delete-region start end)
23f87bed 3220 (insert trans))))))
eec82323
LMI
3221
3222(defun article-hide-signature (&optional arg)
3223 "Hide the signature in the current article.
3224If given a negative prefix, always show; if given a positive prefix,
3225always hide."
3226 (interactive (gnus-article-hidden-arg))
3227 (unless (gnus-article-check-hidden-text 'signature arg)
3228 (save-excursion
3229 (save-restriction
4e7d0221 3230 (let ((inhibit-read-only t))
eec82323
LMI
3231 (when (gnus-article-narrow-to-signature)
3232 (gnus-article-hide-text-type
23f87bed
MB
3233 (point-min) (point-max) 'signature))))))
3234 (gnus-set-mode-line 'article))
eec82323 3235
16409b0b
GM
3236(defun article-strip-headers-in-body ()
3237 "Strip offensive headers from bodies."
3238 (interactive)
3239 (save-excursion
3240 (article-goto-body)
3241 (let ((case-fold-search t))
3242 (when (looking-at "x-no-archive:")
3243 (gnus-delete-line)))))
3244
eec82323
LMI
3245(defun article-strip-leading-blank-lines ()
3246 "Remove all blank lines from the beginning of the article."
3247 (interactive)
3248 (save-excursion
3249 (let ((inhibit-point-motion-hooks t)
23f87bed 3250 (inhibit-read-only t))
16409b0b 3251 (when (article-goto-body)
eec82323
LMI
3252 (while (and (not (eobp))
3253 (looking-at "[ \t]*$"))
3254 (gnus-delete-line))))))
3255
16409b0b
GM
3256(defun article-narrow-to-head ()
3257 "Narrow the buffer to the head of the message.
3258Point is left at the beginning of the narrowed-to region."
3259 (narrow-to-region
3260 (goto-char (point-min))
3261 (if (search-forward "\n\n" nil 1)
3262 (1- (point))
3263 (point-max)))
3264 (goto-char (point-min)))
3265
3266(defun article-goto-body ()
3267 "Place point at the start of the body."
3268 (goto-char (point-min))
3269 (cond
3270 ;; This variable is only bound when dealing with separate
3271 ;; MIME body parts.
3272 (article-goto-body-goes-to-point-min-p
3273 t)
3274 ((search-forward "\n\n" nil t)
3275 t)
3276 (t
3277 (goto-char (point-max))
3278 nil)))
3279
eec82323
LMI
3280(defun article-strip-multiple-blank-lines ()
3281 "Replace consecutive blank lines with one empty line."
3282 (interactive)
3283 (save-excursion
3284 (let ((inhibit-point-motion-hooks t)
23f87bed 3285 (inhibit-read-only t))
eec82323 3286 ;; First make all blank lines empty.
16409b0b 3287 (article-goto-body)
eec82323 3288 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
3289 (unless (gnus-annotation-in-region-p
3290 (match-beginning 0) (match-end 0))
3291 (replace-match "" nil t)))
eec82323 3292 ;; Then replace multiple empty lines with a single empty line.
16409b0b 3293 (article-goto-body)
23f87bed 3294 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
3295 (unless (gnus-annotation-in-region-p
3296 (match-beginning 0) (match-end 0))
23f87bed 3297 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3298
3299(defun article-strip-leading-space ()
3300 "Remove all white space from the beginning of the lines in the article."
3301 (interactive)
3302 (save-excursion
3303 (let ((inhibit-point-motion-hooks t)
23f87bed 3304 (inhibit-read-only t))
16409b0b 3305 (article-goto-body)
eec82323
LMI
3306 (while (re-search-forward "^[ \t]+" nil t)
3307 (replace-match "" t t)))))
3308
16409b0b
GM
3309(defun article-strip-trailing-space ()
3310 "Remove all white space from the end of the lines in the article."
3311 (interactive)
3312 (save-excursion
3313 (let ((inhibit-point-motion-hooks t)
23f87bed 3314 (inhibit-read-only t))
16409b0b
GM
3315 (article-goto-body)
3316 (while (re-search-forward "[ \t]+$" nil t)
3317 (replace-match "" t t)))))
3318
eec82323
LMI
3319(defun article-strip-blank-lines ()
3320 "Strip leading, trailing and multiple blank lines."
3321 (interactive)
3322 (article-strip-leading-blank-lines)
3323 (article-remove-trailing-blank-lines)
3324 (article-strip-multiple-blank-lines))
3325
6748645f
LMI
3326(defun article-strip-all-blank-lines ()
3327 "Strip all blank lines."
3328 (interactive)
3329 (save-excursion
3330 (let ((inhibit-point-motion-hooks t)
23f87bed 3331 (inhibit-read-only t))
16409b0b 3332 (article-goto-body)
6748645f
LMI
3333 (while (re-search-forward "^[ \t]*\n" nil t)
3334 (replace-match "" t t)))))
3335
eec82323
LMI
3336(defun gnus-article-narrow-to-signature ()
3337 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 3338 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
3339 (when (gnus-article-search-signature)
3340 (forward-line 1)
3341 ;; Check whether we have some limits to what we consider
3342 ;; to be a signature.
3343 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3344 (list gnus-signature-limit)))
3345 limit limited)
3346 (while (setq limit (pop limits))
3347 (if (or (and (integerp limit)
3348 (< (- (point-max) (point)) limit))
3349 (and (floatp limit)
3350 (< (count-lines (point) (point-max)) limit))
23f87bed 3351 (and (functionp limit)
6748645f
LMI
3352 (funcall limit))
3353 (and (stringp limit)
3354 (not (re-search-forward limit nil t))))
3355 () ; This limit did not succeed.
3356 (setq limited t
3357 limits nil)))
3358 (unless limited
3359 (narrow-to-region (point) (point-max))
3360 t)))))
eec82323
LMI
3361
3362(defun gnus-article-search-signature ()
3363 "Search the current buffer for the signature separator.
3364Put point at the beginning of the signature separator."
3365 (let ((cur (point)))
3366 (goto-char (point-max))
3367 (if (if (stringp gnus-signature-separator)
3368 (re-search-backward gnus-signature-separator nil t)
3369 (let ((seps gnus-signature-separator))
3370 (while (and seps
3371 (not (re-search-backward (car seps) nil t)))
3372 (pop seps))
3373 seps))
3374 t
3375 (goto-char cur)
3376 nil)))
3377
eec82323
LMI
3378(defun gnus-article-hidden-arg ()
3379 "Return the current prefix arg as a number, or 0 if no prefix."
3380 (list (if current-prefix-arg
3381 (prefix-numeric-value current-prefix-arg)
3382 0)))
3383
3384(defun gnus-article-check-hidden-text (type arg)
3385 "Return nil if hiding is necessary.
f0529b5b 3386Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
3387means show, 0 means toggle."
3388 (save-excursion
3389 (save-restriction
eec82323
LMI
3390 (let ((hide (gnus-article-hidden-text-p type)))
3391 (cond
3392 ((or (null arg)
3393 (> arg 0))
3394 nil)
3395 ((< arg 0)
4481aa98
SZ
3396 (gnus-article-show-hidden-text type)
3397 t)
eec82323
LMI
3398 (t
3399 (if (eq hide 'hidden)
4481aa98
SZ
3400 (progn
3401 (gnus-article-show-hidden-text type)
3402 t)
eec82323
LMI
3403 nil)))))))
3404
3405(defun gnus-article-hidden-text-p (type)
3406 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 3407 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 3408 (while (and pos
16409b0b
GM
3409 (not (get-text-property pos 'invisible))
3410 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
3411 (setq pos
3412 (text-property-any (1+ pos) (point-max) 'article-type type)))
3413 (if pos
3414 'hidden
16409b0b 3415 nil)))
eec82323 3416
520aa572 3417(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 3418 "Show all hidden text of type TYPE.
520aa572 3419Originally it is hide instead of DUMMY."
4e7d0221 3420 (let ((inhibit-read-only t)
520aa572 3421 (inhibit-point-motion-hooks t))
a1506d29 3422 (gnus-remove-text-properties-when
520aa572 3423 'article-type type
a1506d29 3424 (point-min) (point-max)
520aa572 3425 (cons 'article-type (cons type
23f87bed
MB
3426 gnus-hidden-properties)))
3427 (gnus-delete-wash-type type)))
eec82323
LMI
3428
3429(defconst article-time-units
3430 `((year . ,(* 365.25 24 60 60))
3431 (week . ,(* 7 24 60 60))
3432 (day . ,(* 24 60 60))
3433 (hour . ,(* 60 60))
3434 (minute . 60)
3435 (second . 1))
3436 "Mapping from time units to seconds.")
3437
23f87bed
MB
3438(defun gnus-article-forward-header ()
3439 "Move point to the start of the next header.
3440If the current header is a continuation header, this can be several
3441lines forward."
3442 (let ((ended nil))
3443 (while (not ended)
3444 (forward-line 1)
3445 (if (looking-at "[ \t]+[^ \t]")
3446 (forward-line 1)
3447 (setq ended t)))))
3448
31640842 3449(defun article-date-ut (&optional type highlight)
eec82323
LMI
3450 "Convert DATE date to universal time in the current article.
3451If TYPE is `local', convert to local time; if it is `lapsed', output
16409b0b
GM
3452how much time has lapsed since DATE. For `lapsed', the value of
3453`gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3454should replace the \"Date:\" one, or should be added below it."
eec82323 3455 (interactive (list 'ut t))
31640842
MB
3456 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3457 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3458 tdate-regexp)
3459 ((eq type 'lapsed)
3460 "^X-Sent:[ \t]")
3461 (article-lapsed-timer
3462 "^Date:[ \t]")
3463 (t
3464 tdate-regexp)))
3465 (case-fold-search t)
3466 (inhibit-read-only t)
eec82323 3467 (inhibit-point-motion-hooks t)
31640842 3468 pos date bface eface)
16409b0b
GM
3469 (save-excursion
3470 (save-restriction
31640842
MB
3471 (widen)
3472 (goto-char (point-min))
3473 (while (or (setq date (get-text-property (setq pos (point))
3474 'original-date))
3475 (when (setq pos (next-single-property-change
3476 (point) 'original-date))
3477 (setq date (get-text-property pos 'original-date))
3478 t))
548f737d
MB
3479 (narrow-to-region
3480 pos (if (setq pos (text-property-any pos (point-max)
3481 'original-date nil))
3482 (progn
3483 (goto-char pos)
3484 (if (or (bolp) (eobp))
3485 (point)
3486 (1+ (point))))
3487 (point-max)))
16409b0b 3488 (goto-char (point-min))
31640842 3489 (when (re-search-forward tdate-regexp nil t)
01c52d31
MB
3490 (setq bface (get-text-property (point-at-bol) 'face)
3491 eface (get-text-property (1- (point-at-eol)) 'face)))
31640842
MB
3492 (goto-char (point-min))
3493 (setq pos nil)
3494 ;; Delete any old Date headers.
3495 (while (re-search-forward date-regexp nil t)
3496 (if pos
01c52d31
MB
3497 (delete-region (point-at-bol) (progn
3498 (gnus-article-forward-header)
3499 (point)))
3500 (delete-region (point-at-bol) (progn
3501 (gnus-article-forward-header)
3502 (forward-char -1)
3503 (point)))
31640842
MB
3504 (setq pos (point))))
3505 (when (and (not pos)
3506 (re-search-forward tdate-regexp nil t))
3507 (forward-line 1))
3508 (gnus-goto-char pos)
3509 (insert (article-make-date-line date (or type 'ut)))
3510 (unless pos
3511 (insert "\n")
3512 (forward-line -1))
3513 ;; Do highlighting.
3514 (beginning-of-line)
3515 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3516 (put-text-property (match-beginning 1) (1+ (match-end 1))
3517 'face bface)
3518 (put-text-property (match-beginning 2) (match-end 2)
3519 'face eface))
3520 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3521 (goto-char (point-max))
3522 (widen))))))
eec82323
LMI
3523
3524(defun article-make-date-line (date type)
3525 "Return a DATE line of TYPE."
23f87bed
MB
3526 (unless (memq type '(local ut original user iso8601 lapsed english))
3527 (error "Unknown conversion type: %s" type))
3528 (condition-case ()
3529 (let ((time (date-to-time date)))
16409b0b 3530 (cond
23f87bed
MB
3531 ;; Convert to the local timezone.
3532 ((eq type 'local)
01c52d31 3533 (concat "Date: " (message-make-date time)))
23f87bed
MB
3534 ;; Convert to Universal Time.
3535 ((eq type 'ut)
3536 (concat "Date: "
01c52d31
MB
3537 (substring
3538 (message-make-date
3539 (let* ((e (parse-time-string date))
3540 (tm (apply 'encode-time e))
3541 (ms (car tm))
3542 (ls (- (cadr tm) (car (current-time-zone time)))))
3543 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3544 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3545 (t (list ms ls)))))
3546 0 -5)
3547 "UT"))
23f87bed
MB
3548 ;; Get the original date from the article.
3549 ((eq type 'original)
3550 (concat "Date: " (if (string-match "\n+$" date)
3551 (substring date 0 (match-beginning 0))
3552 date)))
3553 ;; Let the user define the format.
3554 ((eq type 'user)
3555 (let ((format (or (condition-case nil
3556 (with-current-buffer gnus-summary-buffer
3557 gnus-article-time-format)
3558 (error nil))
3559 gnus-article-time-format)))
3560 (if (functionp format)
3561 (funcall format time)
3562 (concat "Date: " (format-time-string format time)))))
3563 ;; ISO 8601.
3564 ((eq type 'iso8601)
3565 (let ((tz (car (current-time-zone time))))
3566 (concat
3567 "Date: "
3568 (format-time-string "%Y%m%dT%H%M%S" time)
3569 (format "%s%02d%02d"
3570 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3571 (/ (% (abs tz) 3600) 60)))))
3572 ;; Do an X-Sent lapsed format.
3573 ((eq type 'lapsed)
3574 ;; If the date is seriously mangled, the timezone functions are
3575 ;; liable to bug out, so we ignore all errors.
3576 (let* ((now (current-time))
3577 (real-time (subtract-time now time))
3578 (real-sec (and real-time
3579 (+ (* (float (car real-time)) 65536)
3580 (cadr real-time))))
3581 (sec (and real-time (abs real-sec)))
3582 num prev)
3583 (cond
3584 ((null real-time)
3585 "X-Sent: Unknown")
3586 ((zerop sec)
3587 "X-Sent: Now")
3588 (t
3589 (concat
3590 "X-Sent: "
3591 ;; This is a bit convoluted, but basically we go
3592 ;; through the time units for years, weeks, etc,
3593 ;; and divide things to see whether that results
3594 ;; in positive answers.
3595 (mapconcat
3596 (lambda (unit)
3597 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3598 ;; The (remaining) seconds are too few to
3599 ;; be divided into this time unit.
3600 ""
3601 ;; It's big enough, so we output it.
3602 (setq sec (- sec (* num (cdr unit))))
3603 (prog1
3604 (concat (if prev ", " "") (int-to-string
3605 (floor num))
3606 " " (symbol-name (car unit))
3607 (if (> num 1) "s" ""))
3608 (setq prev t))))
3609 article-time-units "")
3610 ;; If dates are odd, then it might appear like the
3611 ;; article was sent in the future.
3612 (if (> real-sec 0)
3613 " ago"
3614 " in the future"))))))
3615 ;; Display the date in proper English
3616 ((eq type 'english)
3617 (let ((dtime (decode-time time)))
3618 (concat
3619 "Date: the "
3620 (number-to-string (nth 3 dtime))
3621 (let ((digit (% (nth 3 dtime) 10)))
3622 (cond
3623 ((memq (nth 3 dtime) '(11 12 13)) "th")
3624 ((= digit 1) "st")
3625 ((= digit 2) "nd")
3626 ((= digit 3) "rd")
3627 (t "th")))
3628 " of "
3629 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3630 " "
3631 (number-to-string (nth 5 dtime))
3632 " at "
3633 (format "%02d" (nth 2 dtime))
3634 ":"
3635 (format "%02d" (nth 1 dtime)))))))
3636 (error
a601fb74 3637 (format "Date: %s (from Gnus)" date))))
eec82323
LMI
3638
3639(defun article-date-local (&optional highlight)
3640 "Convert the current article date to the local timezone."
3641 (interactive (list t))
3642 (article-date-ut 'local highlight))
3643
23f87bed
MB
3644(defun article-date-english (&optional highlight)
3645 "Convert the current article date to something that is proper English."
3646 (interactive (list t))
3647 (article-date-ut 'english highlight))
3648
eec82323
LMI
3649(defun article-date-original (&optional highlight)
3650 "Convert the current article date to what it was originally.
3651This is only useful if you have used some other date conversion
3652function and want to see what the date was before converting."
3653 (interactive (list t))
3654 (article-date-ut 'original highlight))
3655
3656(defun article-date-lapsed (&optional highlight)
3657 "Convert the current article date to time lapsed since it was sent."
3658 (interactive (list t))
3659 (article-date-ut 'lapsed highlight))
3660
6748645f
LMI
3661(defun article-update-date-lapsed ()
3662 "Function to be run from a timer to update the lapsed time line."
e0a8aa09
LT
3663 (save-match-data
3664 (let (deactivate-mark)
3665 (save-excursion
3666 (ignore-errors
3667 (walk-windows
3668 (lambda (w)
3669 (set-buffer (window-buffer w))
3670 (when (eq major-mode 'gnus-article-mode)
3671 (let ((mark (point-marker)))
3672 (goto-char (point-min))
3673 (when (re-search-forward "^X-Sent:" nil t)
3674 (article-date-lapsed t))
3675 (goto-char (marker-position mark))
3676 (move-marker mark nil))))
3677 nil 'visible))))))
6748645f
LMI
3678
3679(defun gnus-start-date-timer (&optional n)
3680 "Start a timer to update the X-Sent header in the article buffers.
3681The numerical prefix says how frequently (in seconds) the function
3682is to run."
3683 (interactive "p")
3684 (unless n
3685 (setq n 1))
3686 (gnus-stop-date-timer)
3687 (setq article-lapsed-timer
01c52d31 3688 (run-at-time 1 n 'article-update-date-lapsed)))
6748645f
LMI
3689
3690(defun gnus-stop-date-timer ()
3691 "Stop the X-Sent timer."
3692 (interactive)
3693 (when article-lapsed-timer
3694 (nnheader-cancel-timer article-lapsed-timer)
3695 (setq article-lapsed-timer nil)))
3696
eec82323
LMI
3697(defun article-date-user (&optional highlight)
3698 "Convert the current article date to the user-defined format.
3699This format is defined by the `gnus-article-time-format' variable."
3700 (interactive (list t))
3701 (article-date-ut 'user highlight))
3702
6748645f
LMI
3703(defun article-date-iso8601 (&optional highlight)
3704 "Convert the current article date to ISO8601."
3705 (interactive (list t))
3706 (article-date-ut 'iso8601 highlight))
3707
31640842
MB
3708(defmacro gnus-article-save-original-date (&rest forms)
3709 "Save the original date as a text property and evaluate FORMS."
3710 `(let* ((case-fold-search t)
3711 (start (progn
3712 (goto-char (point-min))
3713 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3714 (not (bolp)))
3715 (match-end 0))))
3716 (date (when (and start
01c52d31 3717 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
31640842
MB
3718 nil t))
3719 (buffer-substring-no-properties start
3720 (match-beginning 0)))))
3721 (goto-char (point-max))
3722 (skip-chars-backward "\n")
3723 (put-text-property (point-min) (point) 'original-date date)
3724 ,@forms
3725 (goto-char (point-max))
3726 (skip-chars-backward "\n")
3727 (put-text-property (point-min) (point) 'original-date date)))
3728
23f87bed
MB
3729;; (defun article-show-all ()
3730;; "Show all hidden text in the article buffer."
3731;; (interactive)
3732;; (save-excursion
3733;; (let ((inhibit-read-only t))
3734;; (gnus-article-unhide-text (point-min) (point-max)))))
3735
3736(defun article-remove-leading-whitespace ()
3737 "Remove excessive whitespace from all headers."
eec82323
LMI
3738 (interactive)
3739 (save-excursion
23f87bed
MB
3740 (save-restriction
3741 (let ((inhibit-read-only t))
3742 (article-narrow-to-head)
3743 (goto-char (point-min))
3744 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3745 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3746
3747(defun article-emphasize (&optional arg)
3748 "Emphasize text according to `gnus-emphasis-alist'."
3749 (interactive (gnus-article-hidden-arg))
3750 (unless (gnus-article-check-hidden-text 'emphasis arg)
3751 (save-excursion
a1506d29 3752 (let ((alist (or
16409b0b 3753 (condition-case nil
a1506d29
JB
3754 (with-current-buffer gnus-summary-buffer
3755 gnus-article-emphasis-alist)
16409b0b
GM
3756 (error))
3757 gnus-emphasis-alist))
4e7d0221 3758 (inhibit-read-only t)
eec82323
LMI
3759 (props (append '(article-type emphasis)
3760 gnus-hidden-properties))
3761 regexp elem beg invisible visible face)
16409b0b 3762 (article-goto-body)
eec82323
LMI
3763 (setq beg (point))
3764 (while (setq elem (pop alist))
3765 (goto-char beg)
3766 (setq regexp (car elem)
3767 invisible (nth 1 elem)
3768 visible (nth 2 elem)
3769 face (nth 3 elem))
3770 (while (re-search-forward regexp nil t)
23f87bed
MB
3771 (when (and (match-beginning visible) (match-beginning invisible))
3772 (gnus-article-hide-text
3773 (match-beginning invisible) (match-end invisible) props)
3774 (gnus-article-unhide-text-type
3775 (match-beginning visible) (match-end visible) 'emphasis)
3776 (gnus-put-overlay-excluding-newlines
3777 (match-beginning visible) (match-end visible) 'face face)
3778 (gnus-add-wash-type 'emphasis)
3779 (goto-char (match-end invisible)))))))))
eec82323 3780
16409b0b
GM
3781(defun gnus-article-setup-highlight-words (&optional highlight-words)
3782 "Setup newsgroup emphasis alist."
3783 (unless gnus-article-emphasis-alist
3784 (let ((name (and gnus-newsgroup-name
3785 (gnus-group-real-name gnus-newsgroup-name))))
3786 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3787 (setq gnus-article-emphasis-alist
3788 (nconc
16409b0b
GM
3789 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3790 (while (setq elem (pop alist))
3791 (when (and name (string-match (car elem) name))
3792 (setq alist nil
3793 highlight (copy-sequence (cdr elem)))))
3794 highlight)
3795 (copy-sequence highlight-words)
3796 (if gnus-newsgroup-name
a1506d29 3797 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3798 gnus-newsgroup-name 'highlight-words t)))
3799 gnus-emphasis-alist)))))
3800
9efa445f
DN
3801(defvar gnus-summary-article-menu)
3802(defvar gnus-summary-post-menu)
eec82323
LMI
3803
3804;;; Saving functions.
3805
3806(defun gnus-article-save (save-buffer file &optional num)
3807 "Save the currently selected article."
26c9afc3
MB
3808 (when (or (get gnus-default-article-saver :headers)
3809 (not gnus-save-all-headers))
3810 ;; Remove headers according to `gnus-saved-headers' or the value
3811 ;; of the `:headers' property that the saver function might have.
eec82323 3812 (let ((gnus-visible-headers
26c9afc3
MB
3813 (or (symbol-value (get gnus-default-article-saver :headers))
3814 gnus-saved-headers gnus-visible-headers))
16c85f26
MB
3815 ;; Ignore group parameter. See `article-hide-headers'.
3816 (gnus-summary-buffer nil))
80de1778 3817 (with-current-buffer save-buffer
6748645f 3818 (article-hide-headers 1 t))))
eec82323
LMI
3819 (save-window-excursion
3820 (if (not gnus-default-article-saver)
a8151ef7 3821 (error "No default saver is defined")
eec82323 3822 ;; !!! Magic! The saving functions all save
16409b0b 3823 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3824 ;; bind that variable to our save-buffer.
3825 (set-buffer gnus-article-buffer)
3826 (let* ((gnus-save-article-buffer save-buffer)
3827 (filename
3828 (cond
3829 ((not gnus-prompt-before-saving) 'default)
3830 ((eq gnus-prompt-before-saving 'always) nil)
3831 (t file)))
3832 (gnus-number-of-articles-to-be-saved
3833 (when (eq gnus-prompt-before-saving t)
3834 num))) ; Magic
6748645f 3835 (set-buffer gnus-article-current-summary)
eec82323
LMI
3836 (funcall gnus-default-article-saver filename)))))
3837
3838(defun gnus-read-save-file-name (prompt &optional filename
26c9afc3
MB
3839 function group headers variable
3840 dir-var)
eec82323
LMI
3841 (let ((default-name
3842 (funcall function group headers (symbol-value variable)))
3843 result)
4325195c 3844 (setq result
a1506d29 3845 (expand-file-name
4325195c
DL
3846 (cond
3847 ((eq filename 'default)
3848 default-name)
3849 ((eq filename t)
3850 default-name)
3851 (filename filename)
3852 (t
26c9afc3
MB
3853 (when (symbol-value dir-var)
3854 (setq default-name (expand-file-name
3855 (file-name-nondirectory default-name)
3856 (symbol-value dir-var))))
4325195c
DL
3857 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3858 (prompt
3859 (format prompt
3860 (if (and gnus-number-of-articles-to-be-saved
3861 (> gnus-number-of-articles-to-be-saved 1))
3862 (format "these %d articles"
3863 gnus-number-of-articles-to-be-saved)
3864 "this article")))
3865 (file
3866 ;; Let the split methods have their say.
3867 (cond
3868 ;; No split name was found.
3869 ((null split-name)
3870 (read-file-name
3871 (concat prompt " (default "
81df110a 3872 (file-name-nondirectory default-name) "): ")
4325195c
DL
3873 (file-name-directory default-name)
3874 default-name))
3875 ;; A single group name is returned.
3876 ((stringp split-name)
3877 (setq default-name
3878 (funcall function split-name headers
3879 (symbol-value variable)))
3880 (read-file-name
3881 (concat prompt " (default "
81df110a 3882 (file-name-nondirectory default-name) "): ")
4325195c
DL
3883 (file-name-directory default-name)
3884 default-name))
3885 ;; A single split name was found
3886 ((= 1 (length split-name))
3887 (let* ((name (expand-file-name
23f87bed
MB
3888 (car split-name)
3889 gnus-article-save-directory))
4325195c
DL
3890 (dir (cond ((file-directory-p name)
3891 (file-name-as-directory name))
3892 ((file-exists-p name) name)
3893 (t gnus-article-save-directory))))
3894 (read-file-name
81df110a 3895 (concat prompt " (default " name "): ")
4325195c
DL
3896 dir name)))
3897 ;; A list of splits was found.
3898 (t
3899 (setq split-name (nreverse split-name))
3900 (let (result)
3901 (let ((file-name-history
3902 (nconc split-name file-name-history)))
3903 (setq result
3904 (expand-file-name
3905 (read-file-name
81df110a 3906 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3907 gnus-article-save-directory
3908 (car split-name))
3909 gnus-article-save-directory)))
3910 (car (push result file-name-history)))))))
3911 ;; Create the directory.
3912 (gnus-make-directory (file-name-directory file))
23f87bed 3913 ;; If we have read a directory, we append the default file name.
4325195c 3914 (when (file-directory-p file)
23f87bed
MB
3915 (setq file (expand-file-name (file-name-nondirectory
3916 default-name)
4325195c
DL
3917 (file-name-as-directory file))))
3918 ;; Possibly translate some characters.
3919 (nnheader-translate-file-chars file))))))
eec82323 3920 (gnus-make-directory (file-name-directory result))
26c9afc3
MB
3921 (when variable
3922 (set variable result))
3923 (when dir-var
3924 (set dir-var (file-name-directory result)))
3925 result))
eec82323
LMI
3926
3927(defun gnus-article-archive-name (group)
3928 "Return the first instance of an \"Archive-name\" in the current buffer."
3929 (let ((case-fold-search t))
3930 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3931 (nnheader-concat gnus-article-save-directory
3932 (match-string 1)))))
3933
3934(defun gnus-article-nndoc-name (group)
3935 "If GROUP is an nndoc group, return the name of the parent group."
3936 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3937 (gnus-group-get-parameter group 'save-article-group)))
3938
3939(defun gnus-summary-save-in-rmail (&optional filename)
3940 "Append this article to Rmail file.
3941Optional argument FILENAME specifies file name.
3942Directory to save to is default to `gnus-article-save-directory'."
eec82323 3943 (setq filename (gnus-read-save-file-name
81df110a 3944 "Save %s in rmail file" filename
eec82323
LMI
3945 gnus-rmail-save-name gnus-newsgroup-name
3946 gnus-current-headers 'gnus-newsgroup-last-rmail))
3947 (gnus-eval-in-buffer-window gnus-save-article-buffer
3948 (save-excursion
3949 (save-restriction
3950 (widen)
fef8d38e
GM
3951 ;; Note that unlike gnus-summary-save-in-mail, there is no
3952 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3953 ;; not use Babyl.
6748645f
LMI
3954 (gnus-output-to-rmail filename))))
3955 filename)
eec82323
LMI
3956
3957(defun gnus-summary-save-in-mail (&optional filename)
3958 "Append this article to Unix mail file.
3959Optional argument FILENAME specifies file name.
3960Directory to save to is default to `gnus-article-save-directory'."
eec82323 3961 (setq filename (gnus-read-save-file-name
81df110a 3962 "Save %s in Unix mail file" filename
eec82323
LMI
3963 gnus-mail-save-name gnus-newsgroup-name
3964 gnus-current-headers 'gnus-newsgroup-last-mail))
3965 (gnus-eval-in-buffer-window gnus-save-article-buffer
3966 (save-excursion
3967 (save-restriction
3968 (widen)
3969 (if (and (file-readable-p filename)
23f87bed 3970 (file-regular-p filename)
eec82323 3971 (mail-file-babyl-p filename))
fef8d38e 3972 (gnus-output-to-rmail filename)
6748645f
LMI
3973 (gnus-output-to-mail filename)))))
3974 filename)
eec82323 3975
26c9afc3
MB
3976(put 'gnus-summary-save-in-file :decode t)
3977(put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
eec82323
LMI
3978(defun gnus-summary-save-in-file (&optional filename overwrite)
3979 "Append this article to file.
3980Optional argument FILENAME specifies file name.
3981Directory to save to is default to `gnus-article-save-directory'."
eec82323 3982 (setq filename (gnus-read-save-file-name
81df110a 3983 "Save %s in file" filename
eec82323
LMI
3984 gnus-file-save-name gnus-newsgroup-name
3985 gnus-current-headers 'gnus-newsgroup-last-file))
3986 (gnus-eval-in-buffer-window gnus-save-article-buffer
3987 (save-excursion
3988 (save-restriction
3989 (widen)
3990 (when (and overwrite
3991 (file-exists-p filename))
3992 (delete-file filename))
6748645f
LMI
3993 (gnus-output-to-file filename))))
3994 filename)
eec82323 3995
26c9afc3
MB
3996(put 'gnus-summary-write-to-file :decode t)
3997(put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3998(put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
eec82323 3999(defun gnus-summary-write-to-file (&optional filename)
23f87bed 4000 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
4001Optional argument FILENAME specifies file name.
4002The directory to save in defaults to `gnus-article-save-directory'."
26c9afc3
MB
4003 (setq filename (gnus-read-save-file-name
4004 "Save %s in file" filename
4005 gnus-file-save-name gnus-newsgroup-name
4006 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4007 (gnus-summary-save-in-file filename t))
eec82323 4008
26c9afc3
MB
4009(put 'gnus-summary-save-body-in-file :decode t)
4010(defun gnus-summary-save-body-in-file (&optional filename overwrite)
eec82323
LMI
4011 "Append this article body to a file.
4012Optional argument FILENAME specifies file name.
4013The directory to save in defaults to `gnus-article-save-directory'."
eec82323 4014 (setq filename (gnus-read-save-file-name
81df110a 4015 "Save %s body in file" filename
eec82323
LMI
4016 gnus-file-save-name gnus-newsgroup-name
4017 gnus-current-headers 'gnus-newsgroup-last-file))
4018 (gnus-eval-in-buffer-window gnus-save-article-buffer
4019 (save-excursion
4020 (save-restriction
4021 (widen)
16409b0b 4022 (when (article-goto-body)
eec82323 4023 (narrow-to-region (point) (point-max)))
26c9afc3
MB
4024 (when (and overwrite
4025 (file-exists-p filename))
4026 (delete-file filename))
6748645f
LMI
4027 (gnus-output-to-file filename))))
4028 filename)
eec82323 4029
26c9afc3
MB
4030(put 'gnus-summary-write-body-to-file :decode t)
4031(put 'gnus-summary-write-body-to-file
4032 :function 'gnus-summary-save-body-in-file)
4033(defun gnus-summary-write-body-to-file (&optional filename)
4034 "Write this article body to a file, overwriting it if the file exists.
4035Optional argument FILENAME specifies file name.
4036The directory to save in defaults to `gnus-article-save-directory'."
4037 (setq filename (gnus-read-save-file-name
4038 "Save %s body in file" filename
4039 gnus-file-save-name gnus-newsgroup-name
4040 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4041 (gnus-summary-save-body-in-file filename t))
4042
89167438
MB
4043(put 'gnus-summary-save-in-pipe :decode t)
4044(put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
d62672f3
MB
4045(defun gnus-summary-save-in-pipe (&optional command raw)
4046 "Pipe this article to subprocess COMMAND.
4047Valid values for COMMAND include:
4048 a string
4049 The executable command name and possibly arguments.
4050 nil
4051 You will be prompted for the command in the minibuffer.
4052 the symbol `default'
4053 It will be replaced with the command which the variable
4054 `gnus-summary-pipe-output-default-command' holds or the command
4055 last used for saving.
4056Non-nil value for RAW overrides `:decode' and `:headers' properties
4057and the raw article including all headers will be piped."
6ecfe5c2
MB
4058 (let ((article (gnus-summary-article-number))
4059 (decode (unless raw
4060 (get 'gnus-summary-save-in-pipe :decode)))
4061 save-buffer default)
4062 (if article
4063 (if (vectorp (gnus-summary-article-header article))
4064 (save-current-buffer
4065 (gnus-summary-select-article decode decode nil article)
4066 (insert-buffer-substring
4067 (prog1
4068 (if decode
4069 gnus-article-buffer
4070 gnus-original-article-buffer)
4071 (setq save-buffer
4072 (nnheader-set-temp-buffer " *Gnus Save*"))))
4073 ;; Remove unwanted headers.
4074 (when (and (not raw)
4075 (or (get 'gnus-summary-save-in-pipe :headers)
4076 (not gnus-save-all-headers)))
4077 (let ((gnus-visible-headers
4078 (or (symbol-value (get 'gnus-summary-save-in-pipe
4079 :headers))
4080 gnus-saved-headers gnus-visible-headers))
4081 (gnus-summary-buffer nil))
4082 (article-hide-headers 1 t))))
4083 (error "%d is not a real article" article))
4084 (error "No article to pipe"))
4085 (setq default (or gnus-summary-pipe-output-default-command
4086 gnus-last-shell-command))
89167438
MB
4087 (unless (stringp command)
4088 (setq command
4089 (if (and (eq command 'default) default)
4090 default
6ecfe5c2
MB
4091 (gnus-read-shell-command "Shell command on this article: "
4092 default))))
89167438
MB
4093 (when (string-equal command "")
4094 (if default
4095 (setq command default)
16c85f26
MB
4096 (error "A command is required")))
4097 (gnus-eval-in-buffer-window save-buffer
4098 (save-restriction
4099 (widen)
4100 (shell-command-on-region (point-min) (point-max) command nil)))
4101 (gnus-kill-buffer save-buffer))
89167438 4102 (setq gnus-summary-pipe-output-default-command command))
eec82323 4103
23f87bed
MB
4104(defun gnus-summary-pipe-to-muttprint (&optional command)
4105 "Pipe this article to muttprint."
16c85f26
MB
4106 (unless (stringp command)
4107 (setq command (read-string
4108 "Print using command: " gnus-summary-muttprint-program
4109 nil gnus-summary-muttprint-program)))
4110 (let ((gnus-summary-pipe-output-default-command
4111 gnus-summary-pipe-output-default-command))
4112 (gnus-summary-save-in-pipe command))
4113 (setq gnus-summary-muttprint-program command))
23f87bed 4114
eec82323
LMI
4115;;; Article file names when saving.
4116
4117(defun gnus-capitalize-newsgroup (newsgroup)
4118 "Capitalize NEWSGROUP name."
4119 (when (not (zerop (length newsgroup)))
4120 (concat (char-to-string (upcase (aref newsgroup 0)))
4121 (substring newsgroup 1))))
4122
4123(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4124 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4125If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4126Otherwise, it is like ~/News/news/group/num."
4127 (let ((default
4128 (expand-file-name
4129 (concat (if (gnus-use-long-file-name 'not-save)
4130 (gnus-capitalize-newsgroup newsgroup)
4131 (gnus-newsgroup-directory-form newsgroup))
4132 "/" (int-to-string (mail-header-number headers)))
4133 gnus-article-save-directory)))
4134 (if (and last-file
4135 (string-equal (file-name-directory default)
4136 (file-name-directory last-file))
4137 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4138 default
4139 (or last-file default))))
4140
4141(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4142 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4143If variable `gnus-use-long-file-name' is non-nil, it is
2ff9f5b4 4144~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
eec82323
LMI
4145 (let ((default
4146 (expand-file-name
4147 (concat (if (gnus-use-long-file-name 'not-save)
4148 newsgroup
4149 (gnus-newsgroup-directory-form newsgroup))
4150 "/" (int-to-string (mail-header-number headers)))
4151 gnus-article-save-directory)))
4152 (if (and last-file
4153 (string-equal (file-name-directory default)
4154 (file-name-directory last-file))
4155 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4156 default
4157 (or last-file default))))
4158
eec82323
LMI
4159(defun gnus-plain-save-name (newsgroup headers &optional last-file)
4160 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4161If variable `gnus-use-long-file-name' is non-nil, it is
4162~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4163 (or last-file
4164 (expand-file-name
4165 (if (gnus-use-long-file-name 'not-save)
4166 newsgroup
23f87bed
MB
4167 (file-relative-name
4168 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4169 default-directory))
eec82323
LMI
4170 gnus-article-save-directory)))
4171
23f87bed
MB
4172(defun gnus-sender-save-name (newsgroup headers &optional last-file)
4173 "Generate file name from sender."
4174 (let ((from (mail-header-from headers)))
4175 (expand-file-name
4176 (if (and from (string-match "\\([^ <]+\\)@" from))
4177 (match-string 1 from)
4178 "nobody")
4179 gnus-article-save-directory)))
4180
4181(defun article-verify-x-pgp-sig ()
4182 "Verify X-PGP-Sig."
bbbe940b 4183 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
23f87bed
MB
4184 (interactive)
4185 (if (gnus-buffer-live-p gnus-original-article-buffer)
4186 (let ((sig (with-current-buffer gnus-original-article-buffer
4187 (gnus-fetch-field "X-PGP-Sig")))
4188 items info headers)
4189 (when (and sig
4190 mml2015-use
4191 (mml2015-clear-verify-function))
4192 (with-temp-buffer
4193 (insert-buffer-substring gnus-original-article-buffer)
4194 (setq items (split-string sig))
4195 (message-narrow-to-head)
4196 (let ((inhibit-point-motion-hooks t)
4197 (case-fold-search t))
4198 ;; Don't verify multiple headers.
4199 (setq headers (mapconcat (lambda (header)
4200 (concat header ": "
4201 (mail-fetch-field header)
4202 "\n"))
4203 (split-string (nth 1 items) ",") "")))
4204 (delete-region (point-min) (point-max))
4205 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4206 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4207 (insert headers)
4208 (widen)
4209 (forward-line)
4210 (while (not (eobp))
4211 (if (looking-at "^-")
4212 (insert "- "))
4213 (forward-line))
4214 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4215 (insert "Version: " (car items) "\n\n")
4216 (insert (mapconcat 'identity (cddr items) "\n"))
4217 (insert "\n-----END PGP SIGNATURE-----\n")
4218 (let ((mm-security-handle (list (format "multipart/signed"))))
4219 (mml2015-clean-buffer)
4220 (let ((coding-system-for-write (or gnus-newsgroup-charset
4221 'iso-8859-1)))
4222 (funcall (mml2015-clear-verify-function)))
4223 (setq info
4224 (or (mm-handle-multipart-ctl-parameter
4225 mm-security-handle 'gnus-details)
4226 (mm-handle-multipart-ctl-parameter
4227 mm-security-handle 'gnus-info)))))
4228 (when info
4229 (let ((inhibit-read-only t) bface eface)
4230 (save-restriction
4231 (message-narrow-to-head)
4232 (goto-char (point-max))
4233 (forward-line -1)
01c52d31
MB
4234 (setq bface (get-text-property (point-at-bol) 'face)
4235 eface (get-text-property (1- (point-at-eol)) 'face))
23f87bed
MB
4236 (message-remove-header "X-Gnus-PGP-Verify")
4237 (if (re-search-forward "^X-PGP-Sig:" nil t)
4238 (forward-line)
4239 (goto-char (point-max)))
4240 (narrow-to-region (point) (point))
4241 (insert "X-Gnus-PGP-Verify: " info "\n")
4242 (goto-char (point-min))
4243 (forward-line)
4244 (while (not (eobp))
4245 (if (not (looking-at "^[ \t]"))
4246 (insert " "))
4247 (forward-line))
4248 ;; Do highlighting.
4249 (goto-char (point-min))
4250 (when (looking-at "\\([^:]+\\): *")
4251 (put-text-property (match-beginning 1) (1+ (match-end 1))
4252 'face bface)
4253 (put-text-property (match-end 0) (point-max)
4254 'face eface)))))))))
4255
ec7995fa
KY
4256(autoload 'canlock-verify "canlock" nil t) ;; for Emacs 21.
4257
23f87bed
MB
4258(defun article-verify-cancel-lock ()
4259 "Verify Cancel-Lock header."
4260 (interactive)
4261 (if (gnus-buffer-live-p gnus-original-article-buffer)
4262 (canlock-verify gnus-original-article-buffer)))
4263
eec82323 4264(eval-and-compile
01c52d31 4265 (mapc
eec82323
LMI
4266 (lambda (func)
4267 (let (afunc gfunc)
4268 (if (consp func)
4269 (setq afunc (car func)
4270 gfunc (cdr func))
4271 (setq afunc func
4272 gfunc (intern (format "gnus-%s" func))))
16409b0b 4273 (defalias gfunc
23f87bed 4274 (when (fboundp afunc)
16409b0b
GM
4275 `(lambda (&optional interactive &rest args)
4276 ,(documentation afunc t)
4277 (interactive (list t))
80de1778 4278 (with-current-buffer gnus-article-buffer
16409b0b
GM
4279 (if interactive
4280 (call-interactively ',afunc)
4281 (apply ',afunc args))))))))
eec82323 4282 '(article-hide-headers
23f87bed
MB
4283 article-verify-x-pgp-sig
4284 article-verify-cancel-lock
eec82323
LMI
4285 article-hide-boring-headers
4286 article-treat-overstrike
01c52d31 4287 article-treat-ansi-sequences
16409b0b
GM
4288 article-fill-long-lines
4289 article-capitalize-sentences
eec82323 4290 article-remove-cr
23f87bed 4291 article-remove-leading-whitespace
eec82323 4292 article-display-x-face
23f87bed 4293 article-display-face
eec82323 4294 article-de-quoted-unreadable
16409b0b
GM
4295 article-de-base64-unreadable
4296 article-decode-HZ
4297 article-wash-html
23f87bed 4298 article-unsplit-urls
16409b0b 4299 article-hide-list-identifiers
16409b0b
GM
4300 article-strip-banner
4301 article-babel
eec82323
LMI
4302 article-hide-pem
4303 article-hide-signature
16409b0b 4304 article-strip-headers-in-body
eec82323
LMI
4305 article-remove-trailing-blank-lines
4306 article-strip-leading-blank-lines
4307 article-strip-multiple-blank-lines
4308 article-strip-leading-space
16409b0b 4309 article-strip-trailing-space
eec82323 4310 article-strip-blank-lines
6748645f 4311 article-strip-all-blank-lines
eec82323 4312 article-date-local
23f87bed 4313 article-date-english
6748645f 4314 article-date-iso8601
eec82323
LMI
4315 article-date-original
4316 article-date-ut
16409b0b
GM
4317 article-decode-mime-words
4318 article-decode-charset
4319 article-decode-encoded-words
eec82323
LMI
4320 article-date-user
4321 article-date-lapsed
4322 article-emphasize
6748645f 4323 article-treat-dumbquotes
16409b0b 4324 article-normalize-headers
01c52d31 4325 ;;(article-show-all . gnus-article-show-all-headers)
23f87bed 4326 )))
eec82323
LMI
4327\f
4328;;;
4329;;; Gnus article mode
4330;;;
4331
4332(put 'gnus-article-mode 'mode-class 'special)
4333
16409b0b
GM
4334(set-keymap-parent gnus-article-mode-map widget-keymap)
4335
a8151ef7
LMI
4336(gnus-define-keys gnus-article-mode-map
4337 " " gnus-article-goto-next-page
4338 "\177" gnus-article-goto-prev-page
4339 [delete] gnus-article-goto-prev-page
16409b0b 4340 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
4341 "\C-c^" gnus-article-refer-article
4342 "h" gnus-article-show-summary
4343 "s" gnus-article-show-summary
4344 "\C-c\C-m" gnus-article-mail
4345 "?" gnus-article-describe-briefly
a8151ef7
LMI
4346 "<" beginning-of-buffer
4347 ">" end-of-buffer
4348 "\C-c\C-i" gnus-info-find-node
4349 "\C-c\C-b" gnus-bug
23f87bed
MB
4350 "R" gnus-article-reply-with-original
4351 "F" gnus-article-followup-with-original
520aa572
SZ
4352 "\C-hk" gnus-article-describe-key
4353 "\C-hc" gnus-article-describe-key-briefly
0b6799c3 4354 "\C-hb" gnus-article-describe-bindings
a8151ef7 4355
6ab2c7a8 4356 "e" gnus-article-read-summary-keys
a8151ef7
LMI
4357 "\C-d" gnus-article-read-summary-keys
4358 "\M-*" gnus-article-read-summary-keys
4359 "\M-#" gnus-article-read-summary-keys
4360 "\M-^" gnus-article-read-summary-keys
4361 "\M-g" gnus-article-read-summary-keys)
4362
4363(substitute-key-definition
4364 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323 4365
95838435
MB
4366(gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4367 "W" gnus-article-wide-reply-with-original)
4368(if (featurep 'xemacs)
4369 (set-keymap-default-binding gnus-article-send-map
4370 'gnus-article-read-summary-send-keys)
4371 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4372
eec82323 4373(defun gnus-article-make-menu-bar ()
23f87bed
MB
4374 (unless (boundp 'gnus-article-commands-menu)
4375 (gnus-summary-make-menu-bar))
eec82323
LMI
4376 (gnus-turn-off-edit-menu 'article)
4377 (unless (boundp 'gnus-article-article-menu)
4378 (easy-menu-define
4379 gnus-article-article-menu gnus-article-mode-map ""
4380 '("Article"
4381 ["Scroll forwards" gnus-article-goto-next-page t]
4382 ["Scroll backwards" gnus-article-goto-prev-page t]
4383 ["Show summary" gnus-article-show-summary t]
4384 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
4385 ["Mail to address at point" gnus-article-mail t]
4386 ["Send a bug report" gnus-bug t]))
eec82323
LMI
4387
4388 (easy-menu-define
4389 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 4390 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
4391 '("Treatment"
4392 ["Hide headers" gnus-article-hide-headers t]
4393 ["Hide signature" gnus-article-hide-signature t]
4394 ["Hide citation" gnus-article-hide-citation t]
4395 ["Treat overstrike" gnus-article-treat-overstrike t]
01c52d31 4396 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
eec82323 4397 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 4398 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
4399 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4400 ["Remove base64" gnus-article-de-base64-unreadable t]
4401 ["Treat html" gnus-article-wash-html t]
23f87bed 4402 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 4403 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 4404
6748645f 4405 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 4406
23f87bed 4407 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 4408
6748645f 4409 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323
LMI
4410
4411(defun gnus-article-mode ()
4412 "Major mode for displaying an article.
4413
4414All normal editing commands are switched off.
4415
4416The following commands are available in addition to all summary mode
4417commands:
4418\\<gnus-article-mode-map>
4419\\[gnus-article-next-page]\t Scroll the article one page forwards
4420\\[gnus-article-prev-page]\t Scroll the article one page backwards
4421\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4422\\[gnus-article-show-summary]\t Display the summary buffer
4423\\[gnus-article-mail]\t Send a reply to the address near point
4424\\[gnus-article-describe-briefly]\t Describe the current mode briefly
4425\\[gnus-info-find-node]\t Go to the Gnus info node"
4426 (interactive)
0eb586fc 4427 (kill-all-local-variables)
eec82323
LMI
4428 (gnus-simplify-mode-line)
4429 (setq mode-name "Article")
4430 (setq major-mode 'gnus-article-mode)
4431 (make-local-variable 'minor-mode-alist)
eec82323 4432 (use-local-map gnus-article-mode-map)
1653df0f 4433 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
4434 (gnus-article-make-menu-bar)
4435 (when gnus-summary-tool-bar-map
4436 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
4437 (gnus-update-format-specifications nil 'article-mode)
4438 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 4439 (set (make-local-variable 'gnus-page-broken) nil)
6748645f
LMI
4440 (make-local-variable 'gnus-button-marker-list)
4441 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
4442 (make-local-variable 'gnus-article-mime-handles)
4443 (make-local-variable 'gnus-article-decoded-p)
4444 (make-local-variable 'gnus-article-mime-handle-alist)
4445 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
4446 (make-local-variable 'gnus-article-image-alist)
4447 (make-local-variable 'gnus-article-charset)
4448 (make-local-variable 'gnus-article-ignored-charsets)
524705ae
MB
4449 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4450 ;; face.
fc1c32c1 4451 (set (make-local-variable 'nobreak-char-display) nil)
e4a89ccf 4452 (setq cursor-in-non-selected-windows nil)
01c52d31 4453 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4454 (gnus-set-default-directory)
16409b0b 4455 (buffer-disable-undo)
01c52d31
MB
4456 (setq buffer-read-only t
4457 show-trailing-whitespace nil)
eec82323 4458 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 4459 (mm-enable-multibyte)
cfcd5c91 4460 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323 4461
676c1893 4462(defvar gnus-button-marker-list nil
01c52d31
MB
4463 "Regexp matching any of the regexps from `gnus-button-alist'.
4464Internal variable.")
676c1893 4465
eec82323
LMI
4466(defun gnus-article-setup-buffer ()
4467 "Initialize the article buffer."
4468 (let* ((name (if gnus-single-article-buffer "*Article*"
4469 (concat "*Article " gnus-newsgroup-name "*")))
4470 (original
4471 (progn (string-match "\\*Article" name)
4472 (concat " *Original Article"
4473 (substring name (match-end 0))))))
4474 (setq gnus-article-buffer name)
4475 (setq gnus-original-article-buffer original)
16409b0b 4476 (setq gnus-article-mime-handle-alist nil)
01c52d31
MB
4477 (with-current-buffer gnus-summary-buffer
4478 ;; This might be a variable local to the summary buffer.
4479 (unless gnus-single-article-buffer
eec82323
LMI
4480 (setq gnus-article-buffer name)
4481 (setq gnus-original-article-buffer original)
4482 (gnus-set-global-variables)))
16409b0b 4483 (gnus-article-setup-highlight-words)
eec82323 4484 ;; Init original article buffer.
80de1778 4485 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
16409b0b 4486 (mm-enable-multibyte)
eec82323 4487 (setq major-mode 'gnus-original-article-mode)
eec82323 4488 (make-local-variable 'gnus-original-article))
aba1948a
MB
4489 (if (and (get-buffer name)
4490 (with-current-buffer name
4491 (if gnus-article-edit-mode
4492 (if (y-or-n-p "Article mode edit in progress; discard? ")
4493 (progn
4494 (set-buffer-modified-p nil)
4495 (gnus-kill-buffer name)
4496 (message "")
4497 nil)
4498 (error "Action aborted"))
4499 t)))
80de1778 4500 (with-current-buffer name
23f87bed 4501 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
4502 (when gnus-article-mime-handles
4503 (mm-destroy-parts gnus-article-mime-handles)
4504 (setq gnus-article-mime-handles nil))
4505 ;; Set it to nil in article-buffer!
a1506d29 4506 (setq gnus-article-mime-handle-alist nil)
16409b0b 4507 (buffer-disable-undo)
eec82323 4508 (setq buffer-read-only t)
23f87bed
MB
4509 ;; This list just keeps growing if we don't reset it.
4510 (setq gnus-button-marker-list nil)
eec82323
LMI
4511 (unless (eq major-mode 'gnus-article-mode)
4512 (gnus-article-mode))
4513 (current-buffer))
80de1778 4514 (with-current-buffer (gnus-get-buffer-create name)
eec82323
LMI
4515 (gnus-article-mode)
4516 (make-local-variable 'gnus-summary-buffer)
01c52d31
MB
4517 (setq gnus-summary-buffer
4518 (gnus-summary-buffer-name gnus-newsgroup-name))
16409b0b 4519 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
4520 (current-buffer)))))
4521
4522;; Set article window start at LINE, where LINE is the number of lines
4523;; from the head of the article.
4524(defun gnus-article-set-window-start (&optional line)
01c52d31
MB
4525 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4526 (when article-window
4527 (set-window-start
4528 article-window
80de1778 4529 (with-current-buffer gnus-article-buffer
01c52d31
MB
4530 (goto-char (point-min))
4531 (if (not line)
4532 (point-min)
4533 (gnus-message 6 "Moved to bookmark")
4534 (search-forward "\n\n" nil t)
4535 (forward-line line)
4536 (point)))))))
eec82323
LMI
4537
4538(defun gnus-article-prepare (article &optional all-headers header)
4539 "Prepare ARTICLE in article mode buffer.
4540ARTICLE should either be an article number or a Message-ID.
4541If ARTICLE is an id, HEADER should be the article headers.
4542If ALL-HEADERS is non-nil, no headers are hidden."
4543 (save-excursion
4544 ;; Make sure we start in a summary buffer.
4545 (unless (eq major-mode 'gnus-summary-mode)
4546 (set-buffer gnus-summary-buffer))
4547 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
4548 (let* ((gnus-article (if header (mail-header-number header) article))
4549 (summary-buffer (current-buffer))
6748645f 4550 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
4551 (group gnus-newsgroup-name)
4552 result)
4553 (save-excursion
4554 (gnus-article-setup-buffer)
4555 (set-buffer gnus-article-buffer)
4556 ;; Deactivate active regions.
4557 (when (and (boundp 'transient-mark-mode)
4558 transient-mark-mode)
4559 (setq mark-active nil))
4e7d0221 4560 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
4561 (gnus-request-article-this-buffer
4562 article group))))
4563 ;; There is no such article.
4564 (save-excursion
4565 (when (and (numberp article)
4566 (not (memq article gnus-newsgroup-sparse)))
4567 (setq gnus-article-current
4568 (cons gnus-newsgroup-name article))
4569 (set-buffer gnus-summary-buffer)
4570 (setq gnus-current-article article)
23f87bed
MB
4571 (if (and (memq article gnus-newsgroup-undownloaded)
4572 (not (gnus-online (gnus-find-method-for-group
4573 gnus-newsgroup-name))))
6748645f
LMI
4574 (progn
4575 (gnus-summary-set-agent-mark article)
4576 (message "Message marked for downloading"))
4577 (gnus-summary-mark-article article gnus-canceled-mark)
4578 (unless (memq article gnus-newsgroup-sparse)
16409b0b 4579 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
4580 (if (or (eq result 'pseudo)
4581 (eq result 'nneething))
eec82323 4582 (progn
80de1778 4583 (with-current-buffer summary-buffer
6748645f 4584 (push article gnus-newsgroup-history)
eec82323 4585 (setq gnus-last-article gnus-current-article
eec82323
LMI
4586 gnus-current-article 0
4587 gnus-current-headers nil
4588 gnus-article-current nil)
4589 (if (eq result 'nneething)
4590 (gnus-configure-windows 'summary)
4591 (gnus-configure-windows 'article))
4592 (gnus-set-global-variables))
16409b0b
GM
4593 (let ((gnus-article-mime-handle-alist-1
4594 gnus-article-mime-handle-alist))
4595 (gnus-set-mode-line 'article)))
eec82323
LMI
4596 ;; The result from the `request' was an actual article -
4597 ;; or at least some text that is now displayed in the
4598 ;; article buffer.
4599 (when (and (numberp article)
4600 (not (eq article gnus-current-article)))
4601 ;; Seems like a new article has been selected.
4602 ;; `gnus-current-article' must be an article number.
80de1778 4603 (with-current-buffer summary-buffer
6748645f 4604 (push article gnus-newsgroup-history)
eec82323 4605 (setq gnus-last-article gnus-current-article
eec82323
LMI
4606 gnus-current-article article
4607 gnus-current-headers
4608 (gnus-summary-article-header gnus-current-article)
4609 gnus-article-current
4610 (cons gnus-newsgroup-name gnus-current-article))
4611 (unless (vectorp gnus-current-headers)
4612 (setq gnus-current-headers nil))
6748645f
LMI
4613 (gnus-summary-goto-subject gnus-current-article)
4614 (when (gnus-summary-show-thread)
4615 ;; If the summary buffer really was folded, the
4616 ;; previous goto may not actually have gone to
4617 ;; the right article, but the thread root instead.
4618 ;; So we go again.
4619 (gnus-summary-goto-subject gnus-current-article))
4620 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
4621 (gnus-set-mode-line 'summary)
4622 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 4623 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 4624 ;; Set the global newsgroup variables here.
eec82323
LMI
4625 (gnus-set-global-variables)
4626 (setq gnus-have-all-headers
6748645f 4627 (or all-headers gnus-show-all-headers))))
e0bad764
DL
4628 (save-excursion
4629 (gnus-configure-windows 'article))
eec82323
LMI
4630 (when (or (numberp article)
4631 (stringp article))
16409b0b 4632 (gnus-article-prepare-display)
eec82323
LMI
4633 ;; Do page break.
4634 (goto-char (point-min))
23f87bed
MB
4635 (when gnus-break-pages
4636 (gnus-narrow-to-page)))
16409b0b
GM
4637 (let ((gnus-article-mime-handle-alist-1
4638 gnus-article-mime-handle-alist))
4639 (gnus-set-mode-line 'article))
4640 (article-goto-body)
23f87bed
MB
4641 (unless (bobp)
4642 (forward-line -1))
6748645f 4643 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 4644 (gnus-configure-windows 'article)
eec82323
LMI
4645 t))))))
4646
16409b0b
GM
4647;;;###autoload
4648(defun gnus-article-prepare-display ()
4649 "Make the current buffer look like a nice article."
4650 ;; Hooks for getting information from the article.
4651 ;; This hook must be called before being narrowed.
4652 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
4653 buffer-read-only
4654 (inhibit-read-only t))
16409b0b
GM
4655 (unless (eq major-mode 'gnus-article-mode)
4656 (gnus-article-mode))
4657 (setq buffer-read-only nil
23f87bed
MB
4658 gnus-article-wash-types nil
4659 gnus-article-image-alist nil)
16409b0b
GM
4660 (gnus-run-hooks 'gnus-tmp-internal-hook)
4661 (when gnus-display-mime-function
4662 (funcall gnus-display-mime-function))
4663 (gnus-run-hooks 'gnus-article-prepare-hook)))
4664
01c52d31
MB
4665;;;
4666;;; Gnus Sticky Article Mode
4667;;;
4668
4669(define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4670 "Mode for sticky articles."
4671 ;; Release bindings that won't work.
4672 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4673 gnus-sticky-article-mode-map)
4674 (substitute-key-definition 'gnus-article-refer-article 'undefined
4675 gnus-sticky-article-mode-map)
4676 (dolist (k '("e" "h" "s" "F" "R"))
4677 (define-key gnus-sticky-article-mode-map k nil))
4678 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4679 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4680 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4681 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4682
4683(defun gnus-sticky-article (arg)
4684 "Make the current article sticky.
4685If a prefix ARG is given, ask for a name for this sticky article buffer."
4686 (interactive "P")
4687 (gnus-summary-show-thread)
4688 (gnus-summary-select-article nil nil 'pseudo)
4689 (let (new-art-buf-name)
4690 (gnus-eval-in-buffer-window gnus-article-buffer
4691 (setq new-art-buf-name
4692 (concat
4693 "*Sticky Article: "
4694 (if arg
4695 (read-from-minibuffer "Sticky article buffer name: ")
4696 (gnus-with-article-headers
4697 (gnus-article-goto-header "subject")
4698 (setq new-art-buf-name
4699 (buffer-substring-no-properties
4700 (line-beginning-position) (line-end-position)))
4701 (goto-char (point-min))
4702 (gnus-article-goto-header "from")
4703 (setq new-art-buf-name
4704 (concat
4705 new-art-buf-name ", "
4706 (buffer-substring-no-properties
4707 (line-beginning-position) (line-end-position))))
4708 (goto-char (point-min))
4709 (gnus-article-goto-header "date")
4710 (setq new-art-buf-name
4711 (concat
4712 new-art-buf-name ", "
4713 (buffer-substring-no-properties
4714 (line-beginning-position) (line-end-position))))))
4715 "*"))
4716 (if (and (gnus-buffer-live-p new-art-buf-name)
4717 (with-current-buffer new-art-buf-name
4718 (eq major-mode 'gnus-sticky-article-mode)))
4719 (switch-to-buffer new-art-buf-name)
4720 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4721 (gnus-sticky-article-mode))
4722 (setq gnus-article-buffer new-art-buf-name))
4723 (gnus-summary-recenter)
4724 (gnus-summary-position-point))
4725
4726(defun gnus-kill-sticky-article-buffer (&optional buffer)
4727 "Kill the given sticky article BUFFER.
4728If none is given, assume the current buffer and kill it if it has
4729`gnus-sticky-article-mode'."
4730 (interactive)
4731 (unless buffer
4732 (setq buffer (current-buffer)))
4733 (with-current-buffer buffer
4734 (when (eq major-mode 'gnus-sticky-article-mode)
4735 (gnus-kill-buffer buffer))))
4736
4737(defun gnus-kill-sticky-article-buffers (arg)
4738 "Kill all sticky article buffers.
4739If a prefix ARG is given, ask for confirmation."
4740 (interactive "P")
4741 (dolist (buf (gnus-buffers))
4742 (with-current-buffer buf
4743 (when (eq major-mode 'gnus-sticky-article-mode)
4744 (if (not arg)
4745 (gnus-kill-buffer buf)
4746 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4747 (gnus-kill-buffer buf)))))))
4748
16409b0b
GM
4749;;;
4750;;; Gnus MIME viewing functions
4751;;;
4752
4753(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
4754 "Format of the MIME buttons.
4755
4756Valid specifiers include:
16409b0b
GM
4757%t The MIME type
4758%T MIME type, along with additional info
4759%n The `name' parameter
4760%d The description, if any
4761%l The length of the encoded part
4762%p The part identifier number
23f87bed
MB
4763%e Dots if the part isn't displayed
4764
4765General format specifiers can also be used. See Info node
4766`(gnus)Formatting Variables'.")
16409b0b
GM
4767
4768(defvar gnus-mime-button-line-format-alist
4769 '((?t gnus-tmp-type ?s)
4770 (?T gnus-tmp-type-long ?s)
4771 (?n gnus-tmp-name ?s)
4772 (?d gnus-tmp-description ?s)
4773 (?p gnus-tmp-id ?s)
4774 (?l gnus-tmp-length ?d)
4775 (?e gnus-tmp-dots ?s)))
4776
4777(defvar gnus-mime-button-commands
4778 '((gnus-article-press-button "\r" "Toggle Display")
4779 (gnus-mime-view-part "v" "View Interactively...")
4780 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4781 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4782 (gnus-mime-save-part "o" "Save...")
23f87bed 4783 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
01c52d31 4784 (gnus-mime-replace-part "r" "Replace part")
23f87bed 4785 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4786 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4787 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
01c52d31 4788 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
23f87bed
MB
4789 (gnus-mime-view-part-externally "e" "View Externally")
4790 (gnus-mime-print-part "p" "Print")
e0bad764 4791 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4792 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4793
4794(defun gnus-article-mime-part-status ()
4795 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4796 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4797 " (1 part)"
4798 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4799 ""))
4800
4801(defvar gnus-mime-button-map
4802 (let ((map (make-sparse-keymap)))
16409b0b
GM
4803 (define-key map gnus-mouse-2 'gnus-article-push-button)
4804 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4805 (dolist (c gnus-mime-button-commands)
4806 (define-key map (cadr c) (car c)))
4807 map))
4808
23f87bed
MB
4809(easy-menu-define
4810 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4811 `("MIME Part"
4812 ,@(mapcar (lambda (c)
01c52d31 4813 (vector (caddr c) (car c) :active t))
23f87bed
MB
4814 gnus-mime-button-commands)))
4815
b0b63450
MB
4816(defmacro gnus-bind-safe-url-regexp (&rest body)
4817 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4818 `(let ((mm-w3m-safe-url-regexp
4819 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4820 (gnus-buffer-live-p
4821 gnus-article-current-summary))
4822 (with-current-buffer gnus-article-current-summary
4823 gnus-newsgroup-name)
4824 gnus-newsgroup-name)))
4825 (if (cond ((stringp gnus-safe-html-newsgroups)
4826 (string-match gnus-safe-html-newsgroups group))
4827 ((consp gnus-safe-html-newsgroups)
4828 (member group gnus-safe-html-newsgroups)))
4829 nil
4830 mm-w3m-safe-url-regexp))))
4831 ,@body))
4832
23f87bed
MB
4833(defun gnus-mime-button-menu (event prefix)
4834 "Construct a context-sensitive menu of MIME commands."
4835 (interactive "e\nP")
4836 (save-window-excursion
4837 (let ((pos (event-start event)))
4838 (select-window (posn-window pos))
4839 (goto-char (posn-point pos))
4840 (gnus-article-check-buffer)
4841 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4842
4843(defun gnus-mime-view-all-parts (&optional handles)
4844 "View all the MIME parts."
4845 (interactive)
01c52d31 4846 (with-current-buffer gnus-article-buffer
16409b0b
GM
4847 (let ((handles (or handles gnus-article-mime-handles))
4848 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4849 (mail-parse-ignored-charsets
23f87bed
MB
4850 (with-current-buffer gnus-summary-buffer
4851 gnus-newsgroup-ignored-charsets)))
4852 (when handles
4853 (mm-remove-parts handles)
4854 (goto-char (point-min))
4855 (or (search-forward "\n\n") (goto-char (point-max)))
4856 (let ((inhibit-read-only t))
4857 (delete-region (point) (point-max))
b0b63450 4858 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
23f87bed 4859
01c52d31
MB
4860(defun gnus-article-jump-to-part (n)
4861 "Jump to MIME part N."
4862 (interactive "P")
4863 (pop-to-buffer gnus-article-buffer)
4864 ;; FIXME: why is it necessary?
4865 (sit-for 0)
4866 (let ((parts (length gnus-article-mime-handle-alist)))
4867 (or n (setq n
4868 (string-to-number
4869 (read-string ;; Emacs 21 doesn't have `read-number'.
4870 (format "Jump to part (2..%s): " parts)))))
4871 (unless (and (integerp n) (<= n parts) (>= n 1))
4872 (setq n
4873 (progn
4874 (gnus-message 7 "Invalid part `%s', using %s instead."
4875 n parts)
4876 parts)))
4877 (gnus-message 9 "Jumping to part %s." n)
4878 (cond ((>= gnus-auto-select-part 1)
4879 (while (and (<= n parts)
4880 (not (gnus-article-goto-part n)))
4881 (setq n (1+ n))))
4882 ((< gnus-auto-select-part 0)
4883 (while (and (>= n 1)
4884 (not (gnus-article-goto-part n)))
4885 (setq n (1- n))))
4886 (t
4887 (gnus-article-goto-part n)))))
4888
4889(eval-when-compile
4890 (defsubst gnus-article-edit-part (handles &optional current-id)
4891 "Edit an article in order to delete a mime part.
4892This function is exclusively used by `gnus-mime-save-part-and-strip'
4893and `gnus-mime-delete-part', and not provided at run-time normally."
4894 (gnus-article-edit-article
4895 `(lambda ()
4896 (buffer-disable-undo)
4897 (erase-buffer)
4898 (let ((mail-parse-charset (or gnus-article-charset
4899 ',gnus-newsgroup-charset))
4900 (mail-parse-ignored-charsets
4901 (or gnus-article-ignored-charsets
4902 ',gnus-newsgroup-ignored-charsets))
4903 (mbl mml-buffer-list))
4904 (setq mml-buffer-list nil)
4905 (insert-buffer-substring gnus-original-article-buffer)
4906 (mime-to-mml ',handles)
4907 (setq gnus-article-mime-handles nil)
4908 (let ((mbl1 mml-buffer-list))
4909 (setq mml-buffer-list mbl)
4910 (set (make-local-variable 'mml-buffer-list) mbl1))
4911 (gnus-make-local-hook 'kill-buffer-hook)
4912 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4913 `(lambda (no-highlight)
4914 (let ((mail-parse-charset (or gnus-article-charset
4915 ',gnus-newsgroup-charset))
4916 (message-options message-options)
4917 (message-options-set-recipient)
4918 (mail-parse-ignored-charsets
4919 (or gnus-article-ignored-charsets
4920 ',gnus-newsgroup-ignored-charsets)))
4921 (mml-to-mime)
4922 (mml-destroy-buffers)
4923 (remove-hook 'kill-buffer-hook
4924 'mml-destroy-buffers t)
4925 (kill-local-variable 'mml-buffer-list))
4926 (gnus-summary-edit-article-done
4927 ,(or (mail-header-references gnus-current-headers) "")
4928 ,(gnus-group-read-only-p)
4929 ,gnus-summary-buffer no-highlight))
4930 t)
4931 (gnus-article-edit-done)
54c72c31 4932 (gnus-configure-windows 'article)
01c52d31 4933 (when (and current-id (integerp gnus-auto-select-part))
54c72c31 4934 (gnus-article-jump-to-part (+ current-id gnus-auto-select-part)))))
01c52d31
MB
4935
4936(defun gnus-mime-replace-part (file)
4937 "Replace MIME part under point with an external body."
4938 ;; Useful if file has already been saved to disk
4939 (interactive
4940 (list
75eda25b
SM
4941 (read-file-name "Replace MIME part with file: "
4942 (or mm-default-directory default-directory)
4943 nil nil)))
01c52d31
MB
4944 (gnus-mime-save-part-and-strip file))
4945
4946(defun gnus-mime-save-part-and-strip (&optional file)
4947 "Save the MIME part under point then replace it with an external body.
4948If FILE is given, use it for the external part."
23f87bed
MB
4949 (interactive)
4950 (gnus-article-check-buffer)
4951 (when (gnus-group-read-only-p)
4952 (error "The current group does not support deleting of parts"))
4953 (when (mm-complicated-handles gnus-article-mime-handles)
4954 (error "\
4955The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4956 (let* ((data (get-text-property (point) 'gnus-data))
4957 (id (get-text-property (point) 'gnus-part))
4958 param
4959 (handles gnus-article-mime-handles))
4960 (unless file
4961 (setq file
4962 (and data (mm-save-part data "Delete MIME part and save to: "))))
4963 (when file
4964 (with-current-buffer (mm-handle-buffer data)
4965 (erase-buffer)
4966 (insert "Content-Type: " (mm-handle-media-type data))
4967 (mml-insert-parameter-string (cdr (mm-handle-type data))
4968 '(charset))
4969 ;; Add a filename for the sake of saving the part again.
4970 (mml-insert-parameter
4971 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4972 (insert "\n")
4973 (insert "Content-ID: " (message-make-message-id) "\n")
4974 (insert "Content-Transfer-Encoding: binary\n")
4975 (insert "\n"))
4976 (setcdr data
4977 (cdr (mm-make-handle nil
4978 `("message/external-body"
4979 (access-type . "LOCAL-FILE")
4980 (name . ,file)))))
4981 ;; (set-buffer gnus-summary-buffer)
4982 (gnus-article-edit-part handles id))))
4983
4984;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4985;; parts...>') but with stripping would be nice.
23f87bed
MB
4986
4987(defun gnus-mime-delete-part ()
4988 "Delete the MIME part under point.
4989Replace it with some information about the removed part."
4990 (interactive)
4991 (gnus-article-check-buffer)
4992 (when (gnus-group-read-only-p)
4993 (error "The current group does not support deleting of parts"))
4994 (when (mm-complicated-handles gnus-article-mime-handles)
4995 (error "\
4996The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4997 (when (or gnus-expert-user
4998 (gnus-yes-or-no-p "\
4999Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 5000 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 5001 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
5002 (handles gnus-article-mime-handles)
5003 (none "(none)")
5004 (description
bbbe940b
MB
5005 (let ((desc (mm-handle-description data)))
5006 (when desc
5007 (mail-decode-encoded-word-string desc))))
23f87bed
MB
5008 (filename
5009 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5010 none))
5011 (type (mm-handle-media-type data)))
5012 (unless data
5013 (error "No MIME part under point"))
5014 (with-current-buffer (mm-handle-buffer data)
5015 (let ((bsize (format "%s" (buffer-size))))
5016 (erase-buffer)
5017 (insert
5018 (concat
5019 ",----\n"
5020 "| The following attachment has been deleted:\n"
5021 "|\n"
5022 "| Type: " type "\n"
5023 "| Filename: " filename "\n"
5024 "| Size (encoded): " bsize " Byte\n"
bbbe940b
MB
5025 (when description
5026 (concat "| Description: " description "\n"))
23f87bed
MB
5027 "`----\n"))
5028 (setcdr data
5029 (cdr (mm-make-handle
0cf681b6 5030 nil `("text/plain" (charset . gnus-decoded)) nil nil
23f87bed
MB
5031 (list "attachment")
5032 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
5033 ;; (set-buffer gnus-summary-buffer)
5034 (gnus-article-edit-part handles id))))
16409b0b
GM
5035
5036(defun gnus-mime-save-part ()
5037 "Save the MIME part under point."
5038 (interactive)
5039 (gnus-article-check-buffer)
5040 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5041 (when data
5042 (mm-save-part data))))
16409b0b
GM
5043
5044(defun gnus-mime-pipe-part ()
5045 "Pipe the MIME part under point to a process."
5046 (interactive)
5047 (gnus-article-check-buffer)
5048 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5049 (when data
5050 (mm-pipe-part data))))
16409b0b
GM
5051
5052(defun gnus-mime-view-part ()
5053 "Interactively choose a viewing method for the MIME part under point."
5054 (interactive)
5055 (gnus-article-check-buffer)
5056 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5057 (when data
5058 (setq gnus-article-mime-handles
5059 (mm-merge-handles
5060 gnus-article-mime-handles (setq data (copy-sequence data))))
5061 (mm-interactively-view-part data))))
16409b0b
GM
5062
5063(defun gnus-mime-view-part-as-type-internal ()
5064 (gnus-article-check-buffer)
54e573e6
MB
5065 (let* ((handle (get-text-property (point) 'gnus-data))
5066 (name (or
5067 ;; Content-Type: foo/bar; name=...
5068 (mail-content-type-get (mm-handle-type handle) 'name)
5069 ;; Content-Disposition: attachment; filename=...
5070 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 5071 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
5072 (or (and def-type (cons def-type 0))
5073 (and handle
5074 (equal (mm-handle-media-supertype handle) "text")
5075 '("text/plain" . 0))
5076 '("application/octet-stream" . 0))))
16409b0b 5077
54e573e6
MB
5078(defun gnus-mime-view-part-as-type (&optional mime-type pred)
5079 "Choose a MIME media type, and view the part as such.
5080If non-nil, PRED is a predicate to use during completion to limit the
5081available media-types."
23f87bed
MB
5082 (interactive)
5083 (unless mime-type
54e573e6
MB
5084 (setq mime-type
5085 (let ((default (gnus-mime-view-part-as-type-internal)))
5086 (completing-read
5087 (format "View as MIME type (default %s): "
5088 (car default))
5089 (mapcar #'list (mailcap-mime-types))
5090 pred nil nil nil
5091 (car default)))))
16409b0b
GM
5092 (gnus-article-check-buffer)
5093 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 5094 (when handle
531bedc3
MB
5095 (when (equal (mm-handle-media-type handle) "message/external-body")
5096 (unless (mm-handle-cache handle)
5097 (mm-extern-cache-contents handle))
5098 (setq handle (mm-handle-cache handle)))
23f87bed
MB
5099 (setq handle
5100 (mm-make-handle (mm-handle-buffer handle)
5101 (cons mime-type (cdr (mm-handle-type handle)))
5102 (mm-handle-encoding handle)
5103 (mm-handle-undisplayer handle)
5104 (mm-handle-disposition handle)
5105 (mm-handle-description handle)
5106 nil
5107 (mm-handle-id handle)))
5108 (setq gnus-article-mime-handles
5109 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
5110 (when (mm-handle-displayed-p handle)
5111 (mm-remove-part handle))
23f87bed
MB
5112 (gnus-mm-display-part handle))))
5113
01c52d31 5114(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
5115 "Put the MIME part under point into a new buffer.
5116If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5117are decompressed."
01c52d31 5118 (interactive (list nil current-prefix-arg))
16409b0b 5119 (gnus-article-check-buffer)
01c52d31
MB
5120 (unless handle
5121 (setq handle (get-text-property (point) 'gnus-data)))
5122 (when handle
5123 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5124 'name)
5125 (mail-content-type-get (mm-handle-disposition handle)
5126 'filename)))
5127 contents dont-decode charset coding-system)
5128 (mm-with-unibyte-buffer
5129 (mm-insert-part handle)
5130 (setq contents (or (condition-case nil
5131 (mm-decompress-buffer filename nil 'sig)
5132 (error
5133 (setq dont-decode t)
5134 nil))
5135 (buffer-string))))
5136 (setq filename (cond (filename (file-name-nondirectory filename))
5137 (dont-decode "*raw data*")
5138 (t "*decoded*")))
5139 (cond
5140 (dont-decode)
5141 ((not arg)
5142 (unless (setq charset (mail-content-type-get
5143 (mm-handle-type handle) 'charset))
5144 (unless (setq coding-system (mm-with-unibyte-buffer
5145 (insert contents)
5146 (mm-find-buffer-file-coding-system)))
5147 (setq charset gnus-newsgroup-charset))))
5148 ((numberp arg)
5149 (setq charset (or (cdr (assq arg
5150 gnus-summary-show-article-charset-alist))
5151 (mm-read-coding-system "Charset: ")))))
5152 (switch-to-buffer (generate-new-buffer filename))
5153 (if (or coding-system
5154 (and charset
5155 (setq coding-system (mm-charset-to-coding-system charset))
5156 (not (eq charset 'ascii))))
5157 (progn
5158 (mm-enable-multibyte)
5159 (insert (mm-decode-coding-string contents coding-system))
5160 (setq buffer-file-coding-system
5161 (if (boundp 'last-coding-system-used)
5162 (symbol-value 'last-coding-system-used)
5163 coding-system)))
5164 (mm-disable-multibyte)
5165 (insert contents)
5166 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5167 ;; We do it this way to make `normal-mode' set the appropriate mode.
5168 (unwind-protect
5169 (progn
01c52d31 5170 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5171 (normal-mode))
5172 (setq buffer-file-name nil))
5173 (goto-char (point-min)))))
5174
5175(defun gnus-mime-print-part (&optional handle filename)
5176 "Print the MIME part under point."
5177 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5178 (gnus-article-check-buffer)
5179 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5180 (contents (and handle (mm-get-part handle)))
5181 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5182 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5183 (when contents
5184 (if printer
5185 (unwind-protect
5186 (progn
5187 (mm-save-part-to-file handle file)
5188 (call-process shell-file-name nil
5189 (generate-new-buffer " *mm*")
5190 nil
5191 shell-command-switch
5192 (mm-mailcap-command
5193 printer file (mm-handle-type handle))))
5194 (delete-file file))
5195 (with-temp-buffer
5196 (insert contents)
5197 (gnus-print-buffer))
5198 (ps-despool filename)))))
16409b0b 5199
e0bad764 5200(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5201 "Insert the MIME part under point into the current buffer.
5202Compressed files like .gz and .bz2 are decompressed."
e0bad764 5203 (interactive (list nil current-prefix-arg))
16409b0b 5204 (gnus-article-check-buffer)
01c52d31
MB
5205 (unless handle
5206 (setq handle (get-text-property (point) 'gnus-data)))
5207 (when handle
5208 (let ((b (point))
5209 (inhibit-read-only t)
5210 contents charset coding-system)
23f87bed
MB
5211 (if (and (not arg) (mm-handle-undisplayer handle))
5212 (mm-remove-part handle)
01c52d31
MB
5213 (mm-with-unibyte-buffer
5214 (mm-insert-part handle)
5215 (setq contents
5216 (or (mm-decompress-buffer
5217 (or (mail-content-type-get (mm-handle-type handle)
5218 'name)
5219 (mail-content-type-get (mm-handle-disposition handle)
5220 'filename))
5221 nil t)
5222 (buffer-string))))
23f87bed
MB
5223 (cond
5224 ((not arg)
01c52d31
MB
5225 (unless (setq charset (mail-content-type-get
5226 (mm-handle-type handle) 'charset))
5227 (unless (setq coding-system
5228 (mm-with-unibyte-buffer
5229 (insert contents)
5230 (mm-find-buffer-file-coding-system)))
5231 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5232 ((numberp arg)
5233 (if (mm-handle-undisplayer handle)
5234 (mm-remove-part handle))
5235 (setq charset
5236 (or (cdr (assq arg
5237 gnus-summary-show-article-charset-alist))
56c30d72
MB
5238 (mm-read-coding-system "Charset: "))))
5239 (t
5240 (if (mm-handle-undisplayer handle)
850c333d 5241 (mm-remove-part handle))))
23f87bed 5242 (forward-line 2)
850c333d
MB
5243 (mm-insert-inline
5244 handle
01c52d31
MB
5245 (if (or coding-system
5246 (and charset
5247 (setq coding-system
5248 (mm-charset-to-coding-system charset))
5249 (not (eq coding-system 'ascii))))
5250 (mm-decode-coding-string contents coding-system)
850c333d 5251 (mm-string-to-multibyte contents)))
23f87bed
MB
5252 (goto-char b)))))
5253
c0ccb0d6
KY
5254(defun gnus-mime-set-charset-parameters (handle charset)
5255 "Set CHARSET to parameters in HANDLE.
5256CHARSET may either be a string or a symbol."
5257 (unless (stringp charset)
5258 (setq charset (symbol-name charset)))
6b554e88 5259 (if (stringp (car handle))
c0ccb0d6
KY
5260 (dolist (h (cdr handle))
5261 (gnus-mime-set-charset-parameters h charset))
6b554e88
MB
5262 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5263 "message/external-body")
5264 (progn
5265 (unless (mm-handle-cache handle)
5266 (mm-extern-cache-contents handle))
5267 (mm-handle-cache handle))
5268 handle)))
c0ccb0d6
KY
5269 (param (assq 'charset (cdr type))))
5270 (if param
5271 (setcdr param charset)
5272 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
6b554e88 5273
23f87bed
MB
5274(defun gnus-mime-view-part-as-charset (&optional handle arg)
5275 "Insert the MIME part under point into the current buffer using the
5276specified charset."
5277 (interactive (list nil current-prefix-arg))
5278 (gnus-article-check-buffer)
163cb72d
MB
5279 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5280 (fun (get-text-property (point) 'gnus-callback))
5281 (gnus-newsgroup-ignored-charsets 'gnus-all)
c0ccb0d6 5282 charset form preferred parts)
23f87bed 5283 (when handle
01c52d31
MB
5284 (when (prog1
5285 (and fun
c0ccb0d6 5286 (setq charset
01c52d31
MB
5287 (or (cdr (assq
5288 arg
5289 gnus-summary-show-article-charset-alist))
5290 (mm-read-coding-system "Charset: "))))
5291 (if (mm-handle-undisplayer handle)
5292 (mm-remove-part handle)))
c0ccb0d6 5293 (gnus-mime-set-charset-parameters handle charset)
6b554e88
MB
5294 (when (and (consp (setq form (cdr-safe fun)))
5295 (setq form (ignore-errors
5296 (assq 'gnus-mime-display-alternative form)))
5297 (setq preferred (caddr form))
5298 (progn
5299 (when (eq (car preferred) 'quote)
5300 (setq preferred (cadr preferred)))
5301 (not (equal preferred
5302 (get-text-property (point) 'gnus-data))))
5303 (setq parts (get-text-property (point) 'gnus-part))
5304 (setq parts (cdr (assq parts
5305 gnus-article-mime-handle-alist)))
5306 (equal (mm-handle-media-type parts) "multipart/alternative")
5307 (setq parts (reverse (cdr parts))))
5308 (setcar (cddr form)
5309 (list 'quote (or (cadr (member preferred parts))
5310 (car parts)))))
163cb72d 5311 (funcall fun handle)))))
23f87bed
MB
5312
5313(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5314 "View the MIME part under point with an external viewer."
5315 (interactive)
5316 (gnus-article-check-buffer)
5317 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5318 (mm-user-display-methods nil)
5319 (mm-inlined-types nil)
5320 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5321 (mail-parse-ignored-charsets
54e573e6
MB
5322 (with-current-buffer gnus-summary-buffer
5323 gnus-newsgroup-ignored-charsets))
5324 (type (mm-handle-media-type handle))
5325 (method (mailcap-mime-info type))
5326 (mm-enable-external t))
5327 (if (not (stringp method))
5328 (gnus-mime-view-part-as-type
524705ae 5329 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
54e573e6
MB
5330 (when handle
5331 (if (mm-handle-undisplayer handle)
5332 (mm-remove-part handle)
5333 (mm-display-part handle))))))
16409b0b 5334
23f87bed 5335(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5336 "View the MIME part under point with an internal viewer.
23f87bed 5337If no internal viewer is available, use an external viewer."
16409b0b
GM
5338 (interactive)
5339 (gnus-article-check-buffer)
5340 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5341 (mm-inlined-types '(".*"))
5342 (mm-inline-large-images t)
5343 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5344 (mail-parse-ignored-charsets
54e573e6
MB
5345 (with-current-buffer gnus-summary-buffer
5346 gnus-newsgroup-ignored-charsets))
23f87bed 5347 (inhibit-read-only t))
54e573e6
MB
5348 (if (not (mm-inlinable-p handle))
5349 (gnus-mime-view-part-as-type
524705ae 5350 nil (lambda (types) (mm-inlinable-p handle (car types))))
54e573e6
MB
5351 (when handle
5352 (if (mm-handle-undisplayer handle)
5353 (mm-remove-part handle)
b0b63450 5354 (gnus-bind-safe-url-regexp (mm-display-part handle)))))))
16409b0b 5355
e0bad764
DL
5356(defun gnus-mime-action-on-part (&optional action)
5357 "Do something with the MIME attachment at \(point\)."
5358 (interactive
23f87bed 5359 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
e0bad764
DL
5360 (gnus-article-check-buffer)
5361 (let ((action-pair (assoc action gnus-mime-action-alist)))
5362 (if action-pair
5363 (funcall (cdr action-pair)))))
5364
01c52d31
MB
5365(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5366 "Call FUNCTION on MIME part N.
5367Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5368If INTERACTIVE, call FUNCTION interactivly."
5369 (let (window frame)
5370 ;; Check whether the article is displayed.
5371 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5372 (setq window (get-buffer-window gnus-article-buffer t))
5373 (frame-visible-p (setq frame (window-frame window))))
5374 (error "No article is displayed"))
5375 (with-current-buffer gnus-article-buffer
5376 ;; Check whether the article displays the right contents.
5377 (unless (with-current-buffer gnus-summary-buffer
5378 (eq gnus-current-article (gnus-summary-article-number)))
5379 (error "You should select the right article first"))
5380 (if n
5381 (setq n (prefix-numeric-value n))
5382 (let ((pt (point)))
5383 (setq n (or (get-text-property pt 'gnus-part)
5384 (and (not (bobp))
5385 (get-text-property (1- pt) 'gnus-part))
5386 (get-text-property (prog2
5387 (forward-line 1)
5388 (point)
5389 (goto-char pt))
5390 'gnus-part)
5391 (get-text-property
5392 (or (and (setq pt (previous-single-property-change
5393 pt 'gnus-part))
5394 (1- pt))
5395 (next-single-property-change (point) 'gnus-part)
5396 (point))
5397 'gnus-part)
5398 1))))
5399 ;; Check whether the specified part exists.
5400 (when (> n (length gnus-article-mime-handle-alist))
5401 (error "No such part")))
5402 (unless
5403 (progn
5404 ;; To select the window is needed so that the cursor
5405 ;; might be visible on the MIME button.
5406 (select-window (prog1
5407 window
5408 (setq window (selected-window))
5409 ;; Article may be displayed in the other frame.
5410 (gnus-select-frame-set-input-focus
5411 (prog1
5412 frame
5413 (setq frame (selected-frame))))))
5414 (when (gnus-article-goto-part n)
5415 ;; We point the cursor and the arrow at the MIME button
5416 ;; when the `function' prompt the user for something.
5417 (let ((cursor-in-non-selected-windows t)
5418 (overlay-arrow-string "=>")
5419 (overlay-arrow-position (point-marker)))
5420 (unwind-protect
5421 (cond
5422 ((and no-handle interactive)
5423 (call-interactively function))
5424 (no-handle
5425 (funcall function))
5426 (interactive
5427 (call-interactively
5428 function
5429 (cdr (assq n gnus-article-mime-handle-alist))))
5430 (t
5431 (funcall function
5432 (cdr (assq n gnus-article-mime-handle-alist)))))
5433 (set-marker overlay-arrow-position nil)
5434 (unless gnus-auto-select-part
5435 (gnus-select-frame-set-input-focus frame)
5436 (select-window window))))
5437 t))
5438 (if gnus-inhibit-mime-unbuttonizing
5439 ;; This is the default though the program shouldn't reach here.
5440 (error "No such part")
5441 ;; The part which doesn't have the MIME button is selected.
5442 ;; So, we display all the buttons and redo it.
5443 (let ((gnus-inhibit-mime-unbuttonizing t))
5444 (gnus-summary-show-article)
5445 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5446
5447(defun gnus-article-pipe-part (n)
5448 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5449 (interactive "P")
16409b0b
GM
5450 (gnus-article-part-wrapper n 'mm-pipe-part))
5451
5452(defun gnus-article-save-part (n)
5453 "Save MIME part N, which is the numerical prefix."
01c52d31 5454 (interactive "P")
16409b0b
GM
5455 (gnus-article-part-wrapper n 'mm-save-part))
5456
5457(defun gnus-article-interactively-view-part (n)
5458 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5459 (interactive "P")
16409b0b
GM
5460 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5461
5462(defun gnus-article-copy-part (n)
5463 "Copy MIME part N, which is the numerical prefix."
01c52d31 5464 (interactive "P")
16409b0b
GM
5465 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5466
23f87bed
MB
5467(defun gnus-article-view-part-as-charset (n)
5468 "View MIME part N using a specified charset.
5469N is the numerical prefix."
01c52d31 5470 (interactive "P")
23f87bed
MB
5471 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5472
5473(defun gnus-article-view-part-externally (n)
16409b0b 5474 "View MIME part N externally, which is the numerical prefix."
01c52d31 5475 (interactive "P")
23f87bed 5476 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5477
5478(defun gnus-article-inline-part (n)
5479 "Inline MIME part N, which is the numerical prefix."
01c52d31 5480 (interactive "P")
16409b0b
GM
5481 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5482
01c52d31
MB
5483(defun gnus-article-save-part-and-strip (n)
5484 "Save MIME part N and replace it with an external body.
5485N is the numerical prefix."
5486 (interactive "P")
5487 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5488
5489(defun gnus-article-replace-part (n)
5490 "Replace MIME part N with an external body.
5491N is the numerical prefix."
5492 (interactive "P")
5493 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5494
5495(defun gnus-article-delete-part (n)
5496 "Delete MIME part N and add some information about the removed part.
5497N is the numerical prefix."
5498 (interactive "P")
5499 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5500
5501(defun gnus-article-view-part-as-type (n)
5502 "Choose a MIME media type, and view part N as such.
5503N is the numerical prefix."
5504 (interactive "P")
5505 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5506
16409b0b
GM
5507(defun gnus-article-mime-match-handle-first (condition)
5508 (if condition
01c52d31
MB
5509 (let (n)
5510 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5511 (if (and (cond
16409b0b
GM
5512 ((functionp condition)
5513 (funcall condition (cdr ihandle)))
a1506d29 5514 ((eq condition 'undisplayed)
16409b0b
GM
5515 (not (or (mm-handle-undisplayer (cdr ihandle))
5516 (equal (mm-handle-media-type (cdr ihandle))
5517 "multipart/alternative"))))
5518 ((eq condition 'undisplayed-alternative)
5519 (not (mm-handle-undisplayer (cdr ihandle))))
5520 (t t))
5521 (gnus-article-goto-part (car ihandle))
5522 (or (not n) (< (car ihandle) n)))
5523 (setq n (car ihandle))))
5524 (or n 1))
5525 1))
5526
5527(defun gnus-article-view-part (&optional n)
5528 "View MIME part N, which is the numerical prefix."
5529 (interactive "P")
01c52d31 5530 (with-current-buffer gnus-article-buffer
a1506d29 5531 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5532 gnus-article-mime-match-handle-function)))
5533 (when (> n (length gnus-article-mime-handle-alist))
5534 (error "No such part"))
5535 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5536 (when (gnus-article-goto-part n)
5537 (if (equal (car handle) "multipart/alternative")
5538 (gnus-article-press-button)
5539 (when (eq (gnus-mm-display-part handle) 'internal)
5540 (gnus-set-window-start)))))))
5541
e0bad764
DL
5542(defsubst gnus-article-mime-total-parts ()
5543 (if (bufferp (car gnus-article-mime-handles))
5544 1 ;; single part
5545 (1- (length gnus-article-mime-handles))))
5546
16409b0b
GM
5547(defun gnus-mm-display-part (handle)
5548 "Display HANDLE and fix MIME button."
5549 (let ((id (get-text-property (point) 'gnus-part))
5550 (point (point))
23f87bed 5551 (inhibit-read-only t))
16409b0b
GM
5552 (forward-line 1)
5553 (prog1
5554 (let ((window (selected-window))
5555 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5556 (mail-parse-ignored-charsets
23f87bed 5557 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5558 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5559 gnus-newsgroup-ignored-charsets)
5560 nil)))
16409b0b
GM
5561 (save-excursion
5562 (unwind-protect
23f87bed 5563 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5564 (beg (point)))
5565 (when win
5566 (select-window win))
5567 (goto-char point)
5568 (forward-line)
5569 (if (mm-handle-displayed-p handle)
5570 ;; This will remove the part.
5571 (mm-display-part handle)
5572 (save-restriction
23f87bed
MB
5573 (narrow-to-region (point)
5574 (if (eobp) (point) (1+ (point))))
b0b63450 5575 (gnus-bind-safe-url-regexp (mm-display-part handle))
16409b0b
GM
5576 ;; We narrow to the part itself and
5577 ;; then call the treatment functions.
5578 (goto-char (point-min))
5579 (forward-line 1)
5580 (narrow-to-region (point) (point-max))
5581 (gnus-treat-article
5582 nil id
e0bad764 5583 (gnus-article-mime-total-parts)
16409b0b 5584 (mm-handle-media-type handle)))))
23f87bed
MB
5585 (if (window-live-p window)
5586 (select-window window)))))
16409b0b 5587 (goto-char point)
23f87bed 5588 (gnus-delete-line)
16409b0b
GM
5589 (gnus-insert-mime-button
5590 handle id (list (mm-handle-displayed-p handle)))
5591 (goto-char point))))
5592
5593(defun gnus-article-goto-part (n)
5594 "Go to MIME part N."
23f87bed 5595 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
5596
5597(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5598 (let ((gnus-tmp-name
23f87bed
MB
5599 (or (mail-content-type-get (mm-handle-type handle) 'name)
5600 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5601 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5602 ""))
5603 (gnus-tmp-type (mm-handle-media-type handle))
4599d0ec 5604 (gnus-tmp-description (or (mm-handle-description handle) ""))
16409b0b
GM
5605 (gnus-tmp-dots
5606 (if (if displayed (car displayed)
5607 (mm-handle-displayed-p handle))
5608 "" "..."))
5609 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5610 (buffer-size)))
5611 gnus-tmp-type-long b e)
5612 (when (string-match ".*/" gnus-tmp-name)
5613 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5614 (setq gnus-tmp-type-long (concat gnus-tmp-type
5615 (and (not (equal gnus-tmp-name ""))
5616 (concat "; " gnus-tmp-name))))
23f87bed
MB
5617 (unless (equal gnus-tmp-description "")
5618 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5619 (unless (bolp)
5620 (insert "\n"))
5621 (setq b (point))
5622 (gnus-eval-format
5623 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5624 `(keymap ,gnus-mime-button-map
5625 gnus-callback gnus-mm-display-part
5626 gnus-part ,gnus-tmp-id
5627 article-type annotation
5628 gnus-data ,handle))
23f87bed
MB
5629 (setq e (if (bolp)
5630 ;; Exclude a newline.
5631 (1- (point))
5632 (point)))
01c52d31
MB
5633 (when gnus-article-button-face
5634 (gnus-overlay-put (gnus-make-overlay b e nil t)
5635 'face gnus-article-button-face))
16409b0b
GM
5636 (widget-convert-button
5637 'link b e
5638 :mime-handle handle
5639 :action 'gnus-widget-press-button
5640 :button-keymap gnus-mime-button-map
5641 :help-echo
5642 (lambda (widget/window &optional overlay pos)
5643 ;; Needed to properly clear the message due to a bug in
5644 ;; wid-edit (XEmacs only).
5645 (if (boundp 'help-echo-owns-message)
5646 (setq help-echo-owns-message t))
5647 (format
5648 "%S: %s the MIME part; %S: more options"
5649 (aref gnus-mouse-2 0)
5650 ;; XEmacs will get a single widget arg; Emacs 21 will get
5651 ;; window, overlay, position.
5652 (if (mm-handle-displayed-p
5653 (if overlay
e0bad764
DL
5654 (with-current-buffer (gnus-overlay-buffer overlay)
5655 (widget-get (widget-at (gnus-overlay-start overlay))
16409b0b
GM
5656 :mime-handle))
5657 (widget-get widget/window :mime-handle)))
5658 "hide" "show")
5659 (aref gnus-down-mouse-3 0))))))
5660
5661(defun gnus-widget-press-button (elems el)
5662 (goto-char (widget-get elems :from))
5663 (gnus-article-press-button))
5664
5665(defvar gnus-displaying-mime nil)
5666
5667(defun gnus-display-mime (&optional ihandles)
5668 "Display the MIME parts."
5669 (save-excursion
5670 (save-selected-window
5671 (let ((window (get-buffer-window gnus-article-buffer))
5672 (point (point)))
5673 (when window
5674 (select-window window)
5675 ;; We have to do this since selecting the window
5676 ;; may change the point. So we set the window point.
5677 (set-window-point window point)))
73043f7d
MB
5678 (let ((handles ihandles)
5679 (inhibit-read-only t)
5680 handle)
5681 (cond (handles)
5682 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5683 (when gnus-article-emulate-mime
5684 (mm-uu-dissect-text-parts handles)))
5685 (gnus-article-emulate-mime
5686 (setq handles (mm-uu-dissect))))
16409b0b
GM
5687 (when (and (not ihandles)
5688 (not gnus-displaying-mime))
5689 ;; Top-level call; we clean up.
5690 (when gnus-article-mime-handles
5691 (mm-destroy-parts gnus-article-mime-handles)
5692 (setq gnus-article-mime-handle-alist nil));; A trick.
5693 (setq gnus-article-mime-handles handles)
5694 ;; We allow users to glean info from the handles.
5695 (when gnus-article-mime-part-function
5696 (gnus-mime-part-function handles)))
5697 (if (and handles
5698 (or (not (stringp (car handles)))
5699 (cdr handles)))
5700 (progn
5701 (when (and (not ihandles)
5702 (not gnus-displaying-mime))
5703 ;; Clean up for mime parts.
5704 (article-goto-body)
5705 (delete-region (point) (point-max)))
5706 (let ((gnus-displaying-mime t))
5707 (gnus-mime-display-part handles)))
5708 (save-restriction
5709 (article-goto-body)
5710 (narrow-to-region (point) (point-max))
5711 (gnus-treat-article nil 1 1)
5712 (widen)))
5713 (unless ihandles
5714 ;; Highlight the headers.
5715 (save-excursion
5716 (save-restriction
5717 (article-goto-body)
5718 (narrow-to-region (point-min) (point))
31640842 5719 (gnus-article-save-original-date
f362b760
MB
5720 (gnus-treat-article 'head)))))))
5721 ;; Cope with broken MIME messages.
5722 (goto-char (point-max))
5723 (unless (bolp)
5724 (insert "\n"))))
16409b0b 5725
23f87bed
MB
5726(defcustom gnus-mime-display-multipart-as-mixed nil
5727 "Display \"multipart\" parts as \"multipart/mixed\".
5728
5729If t, it overrides nil values of
5730`gnus-mime-display-multipart-alternative-as-mixed' and
5731`gnus-mime-display-multipart-related-as-mixed'."
5732 :group 'gnus-article-mime
5733 :type 'boolean)
5734
5735(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5736 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5737 :version "22.1"
23f87bed
MB
5738 :group 'gnus-article-mime
5739 :type 'boolean)
5740
5741(defcustom gnus-mime-display-multipart-related-as-mixed nil
5742 "Display \"multipart/related\" parts as \"multipart/mixed\".
5743
5744If displaying \"text/html\" is discouraged \(see
5745`mm-discouraged-alternatives'\) images or other material inside a
5746\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5747 :version "22.1"
23f87bed
MB
5748 :group 'gnus-article-mime
5749 :type 'boolean)
16409b0b
GM
5750
5751(defun gnus-mime-display-part (handle)
5752 (cond
430d3ed7
MB
5753 ;; Maybe a broken MIME message.
5754 ((null handle))
16409b0b
GM
5755 ;; Single part.
5756 ((not (stringp (car handle)))
5757 (gnus-mime-display-single handle))
5758 ;; User-defined multipart
5759 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5760 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5761 handle))
5762 ;; multipart/alternative
5763 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5764 (not (or gnus-mime-display-multipart-as-mixed
5765 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5766 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5767 (push (cons id handle) gnus-article-mime-handle-alist)
5768 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5769 ;; multipart/related
5770 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5771 (not (or gnus-mime-display-multipart-as-mixed
5772 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5773 ;;;!!!We should find the start part, but we just default
5774 ;;;!!!to the first part.
23f87bed
MB
5775 ;;(gnus-mime-display-part (cadr handle))
5776 ;;;!!! Most multipart/related is an HTML message plus images.
5777 ;;;!!! Unfortunately we are unable to let W3 display those
5778 ;;;!!! included images, so we just display it as a mixed multipart.
5779 ;;(gnus-mime-display-mixed (cdr handle))
5780 ;;;!!! No, w3 can display everything just fine.
16409b0b 5781 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5782 ((equal (car handle) "multipart/signed")
5783 (gnus-add-wash-type 'signed)
5784 (gnus-mime-display-security handle))
5785 ((equal (car handle) "multipart/encrypted")
5786 (gnus-add-wash-type 'encrypted)
5787 (gnus-mime-display-security handle))
16409b0b
GM
5788 ;; Other multiparts are handled like multipart/mixed.
5789 (t
5790 (gnus-mime-display-mixed (cdr handle)))))
5791
5792(defun gnus-mime-part-function (handles)
5793 (if (stringp (car handles))
5794 (mapcar 'gnus-mime-part-function (cdr handles))
5795 (funcall gnus-article-mime-part-function handles)))
5796
5797(defun gnus-mime-display-mixed (handles)
5798 (mapcar 'gnus-mime-display-part handles))
5799
5800(defun gnus-mime-display-single (handle)
5801 (let ((type (mm-handle-media-type handle))
5802 (ignored gnus-ignored-mime-types)
5803 (not-attachment t)
5804 (move nil)
5805 display text)
5806 (catch 'ignored
5807 (progn
5808 (while ignored
5809 (when (string-match (pop ignored) type)
5810 (throw 'ignored nil)))
5811 (if (and (setq not-attachment
5812 (and (not (mm-inline-override-p handle))
5813 (or (not (mm-handle-disposition handle))
5814 (equal (car (mm-handle-disposition handle))
5815 "inline")
5816 (mm-attachment-override-p handle))))
5817 (mm-automatic-display-p handle)
23f87bed
MB
5818 (or (and
5819 (mm-inlinable-p handle)
5820 (mm-inlined-p handle))
16409b0b
GM
5821 (mm-automatic-external-display-p type)))
5822 (setq display t)
5823 (when (equal (mm-handle-media-supertype handle) "text")
5824 (setq text t)))
e0bad764
DL
5825 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5826 beg)
16409b0b 5827 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5828 (when (and display
5829 (equal (mm-handle-media-supertype handle) "message"))
5830 (insert-char
5831 ?\n
5832 (cond ((not (bolp)) 2)
5833 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5834 (t 1))))
16409b0b
GM
5835 (when (or (not display)
5836 (not (gnus-unbuttonized-mime-type-p type)))
16409b0b
GM
5837 (gnus-insert-mime-button
5838 handle id (list (or display (and not-attachment text))))
5839 (gnus-article-insert-newline)
23f87bed 5840 ;; Remember modify the number of forward lines.
e0bad764
DL
5841 (setq move t))
5842 (setq beg (point))
16409b0b
GM
5843 (cond
5844 (display
5845 (when move
23f87bed 5846 (forward-line -1)
16409b0b
GM
5847 (setq beg (point)))
5848 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5849 (mail-parse-ignored-charsets
16409b0b
GM
5850 (save-excursion (condition-case ()
5851 (set-buffer gnus-summary-buffer)
5852 (error))
5853 gnus-newsgroup-ignored-charsets)))
b0b63450 5854 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
16409b0b
GM
5855 (goto-char (point-max)))
5856 ((and text not-attachment)
5857 (when move
23f87bed 5858 (forward-line -1)
16409b0b
GM
5859 (setq beg (point)))
5860 (gnus-article-insert-newline)
53cfefc8
MB
5861 (mm-insert-inline
5862 handle
01c52d31
MB
5863 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5864 'charset)
5865 (and (equal type "text/calendar") 'utf-8))))
53cfefc8
MB
5866 (cond ((not charset)
5867 (mm-string-as-multibyte (mm-get-part handle)))
5868 ((eq charset 'gnus-decoded)
5869 (with-current-buffer (mm-handle-buffer handle)
5870 (buffer-string)))
5871 (t
5872 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
5873 (goto-char (point-max))))
5874 ;; Do highlighting.
5875 (save-excursion
5876 (save-restriction
5877 (narrow-to-region beg (point))
01c52d31
MB
5878 (if (eq handle gnus-article-mime-handles)
5879 ;; The format=flowed case.
5880 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5881 ;; Don't count signature parts that are never displayed.
5882 ;; The part number should be re-calculated supposing this
5883 ;; might be a message/rfc822 part.
5884 (let (handles)
5885 (dolist (part gnus-article-mime-handles)
5886 (unless (or (stringp part)
5887 (equal (car (mm-handle-type part))
5888 "application/pgp-signature"))
5889 (push part handles)))
5890 (gnus-treat-article
5891 nil (length (memq handle handles)) (length handles)
5892 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5893
5894(defun gnus-unbuttonized-mime-type-p (type)
5895 "Say whether TYPE is to be unbuttonized."
5896 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5897 (when (catch 'found
5898 (let ((types gnus-unbuttonized-mime-types))
5899 (while types
5900 (when (string-match (pop types) type)
5901 (throw 'found t)))))
5902 (not (catch 'found
5903 (let ((types gnus-buttonized-mime-types))
5904 (while types
5905 (when (string-match (pop types) type)
5906 (throw 'found t)))))))))
16409b0b
GM
5907
5908(defun gnus-article-insert-newline ()
5909 "Insert a newline, but mark it as undeletable."
5910 (gnus-put-text-property
5911 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5912
5913(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5914 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5915 (ihandles handles)
5916 (point (point))
23f87bed 5917 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5918 (save-window-excursion
5919 (save-restriction
5920 (when ibegend
5921 (narrow-to-region (car ibegend)
5922 (or (cdr ibegend)
5923 (progn
5924 (goto-char (car ibegend))
5925 (forward-line 2)
5926 (point))))
5927 (delete-region (point-min) (point-max))
5928 (mm-remove-parts handles))
5929 (setq begend (list (point-marker)))
5930 ;; Do the toggle.
5931 (unless (setq not-pref (cadr (member preferred ihandles)))
5932 (setq not-pref (car ihandles)))
5933 (when (or ibegend
23f87bed 5934 (not preferred)
16409b0b
GM
5935 (not (gnus-unbuttonized-mime-type-p
5936 "multipart/alternative")))
5937 (gnus-add-text-properties
5938 (setq from (point))
5939 (progn
5940 (insert (format "%d. " id))
5941 (point))
5942 `(gnus-callback
5943 (lambda (handles)
5944 (unless ,(not ibegend)
5945 (setq gnus-article-mime-handle-alist
5946 ',gnus-article-mime-handle-alist))
5947 (gnus-mime-display-alternative
5948 ',ihandles ',not-pref ',begend ,id))
01c52d31 5949 keymap ,gnus-mime-button-map
16409b0b
GM
5950 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5951 face ,gnus-article-button-face
16409b0b 5952 gnus-part ,id
7dafe00b 5953 article-type multipart))
16409b0b
GM
5954 (widget-convert-button 'link from (point)
5955 :action 'gnus-widget-press-button
5956 :button-keymap gnus-widget-button-keymap)
5957 ;; Do the handles
5958 (while (setq handle (pop handles))
5959 (gnus-add-text-properties
5960 (setq from (point))
5961 (progn
5962 (insert (format "(%c) %-18s"
5963 (if (equal handle preferred) ?* ? )
5964 (mm-handle-media-type handle)))
5965 (point))
5966 `(gnus-callback
5967 (lambda (handles)
5968 (unless ,(not ibegend)
5969 (setq gnus-article-mime-handle-alist
5970 ',gnus-article-mime-handle-alist))
5971 (gnus-mime-display-alternative
5972 ',ihandles ',handle ',begend ,id))
01c52d31 5973 keymap ,gnus-mime-button-map
16409b0b
GM
5974 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5975 face ,gnus-article-button-face
16409b0b
GM
5976 gnus-part ,id
5977 gnus-data ,handle))
5978 (widget-convert-button 'link from (point)
5979 :action 'gnus-widget-press-button
5980 :button-keymap gnus-widget-button-keymap)
5981 (insert " "))
5982 (insert "\n\n"))
5983 (when preferred
5984 (if (stringp (car preferred))
5985 (gnus-display-mime preferred)
5986 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5987 (mail-parse-ignored-charsets
01c52d31
MB
5988 (with-current-buffer gnus-summary-buffer
5989 gnus-newsgroup-ignored-charsets)))
b0b63450 5990 (gnus-bind-safe-url-regexp (mm-display-part preferred))
16409b0b
GM
5991 ;; Do highlighting.
5992 (save-excursion
5993 (save-restriction
5994 (narrow-to-region (car begend) (point-max))
5995 (gnus-treat-article
5996 nil (length gnus-article-mime-handle-alist)
e0bad764 5997 (gnus-article-mime-total-parts)
16409b0b
GM
5998 (mm-handle-media-type handle))))))
5999 (goto-char (point-max))
6000 (setcdr begend (point-marker)))))
6001 (when ibegend
6002 (goto-char point))))
6003
23f87bed
MB
6004(defconst gnus-article-wash-status-strings
6005 (let ((alist '((cite "c" "Possible hidden citation text"
6006 " " "All citation text visible")
6007 (headers "h" "Hidden headers"
6008 " " "All headers visible.")
6009 (pgp "p" "Encrypted or signed message status hidden"
6010 " " "No hidden encryption nor digital signature status")
6011 (signature "s" "Signature has been hidden"
6012 " " "Signature is visible")
6013 (overstrike "o" "Overstrike (^H) characters applied"
6014 " " "No overstrike characters applied")
6015 (emphasis "e" "/*_Emphasis_*/ characters applied"
6016 " " "No /*_emphasis_*/ characters applied")))
6017 result)
6018 (dolist (entry alist result)
6019 (let ((key (nth 0 entry))
6020 (on (copy-sequence (nth 1 entry)))
6021 (on-help (nth 2 entry))
6022 (off (copy-sequence (nth 3 entry)))
6023 (off-help (nth 4 entry)))
6024 (put-text-property 0 1 'help-echo on-help on)
6025 (put-text-property 0 1 'help-echo off-help off)
6026 (push (list key on off) result))))
6027 "Alist of strings describing wash status in the mode line.
6028Each entry has the form (KEY ON OF), where the KEY is a symbol
6029representing the particular washing function, ON is the string to use
6030in the article mode line when the washing function is active, and OFF
6031is the string to use when it is inactive.")
6032
6033(defun gnus-article-wash-status-entry (key value)
6034 (let ((entry (assoc key gnus-article-wash-status-strings)))
6035 (if value (nth 1 entry) (nth 2 entry))))
6036
eec82323
LMI
6037(defun gnus-article-wash-status ()
6038 "Return a string which display status of article washing."
01c52d31 6039 (with-current-buffer gnus-article-buffer
16409b0b
GM
6040 (let ((cite (memq 'cite gnus-article-wash-types))
6041 (headers (memq 'headers gnus-article-wash-types))
6042 (boring (memq 'boring-headers gnus-article-wash-types))
6043 (pgp (memq 'pgp gnus-article-wash-types))
6044 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
6045 (signed (memq 'signed gnus-article-wash-types))
6046 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
6047 (signature (memq 'signature gnus-article-wash-types))
6048 (overstrike (memq 'overstrike gnus-article-wash-types))
6049 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
6050 (concat
6051 (gnus-article-wash-status-entry 'cite cite)
6052 (gnus-article-wash-status-entry 'headers (or headers boring))
6053 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6054 (gnus-article-wash-status-entry 'signature signature)
6055 (gnus-article-wash-status-entry 'overstrike overstrike)
6056 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6057
6058(defun gnus-add-wash-type (type)
6059 "Add a washing of TYPE to the current status."
6060 (add-to-list 'gnus-article-wash-types type))
6061
6062(defun gnus-delete-wash-type (type)
6063 "Add a washing of TYPE to the current status."
6064 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6065
6066(defun gnus-add-image (category image)
6067 "Add IMAGE of CATEGORY to the list of displayed images."
6068 (let ((entry (assq category gnus-article-image-alist)))
6069 (unless entry
6070 (setq entry (list category))
6071 (push entry gnus-article-image-alist))
6072 (nconc entry (list image))))
6073
6074(defun gnus-delete-images (category)
6075 "Delete all images in CATEGORY."
6076 (let ((entry (assq category gnus-article-image-alist)))
6077 (dolist (image (cdr entry))
6078 (gnus-remove-image image category))
6079 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6080 (gnus-delete-wash-type category)))
eec82323 6081
16409b0b 6082(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
6083
6084(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
6085 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6086Provided for backwards compatibility."
16409b0b 6087 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
6088 (not (with-current-buffer gnus-summary-buffer
6089 gnus-have-all-headers)))
16409b0b
GM
6090 (not gnus-inhibit-hiding))
6091 (gnus-article-hide-headers)))
eec82323
LMI
6092
6093;;; Article savers.
6094
6095(defun gnus-output-to-file (file-name)
26c9afc3
MB
6096 "Append the current article to a file named FILE-NAME.
6097If `gnus-article-save-coding-system' is non-nil, it is used to encode
6098text and used as the value of the coding cookie which is added to the
6099top of a file. Otherwise, this function saves a raw article without
6100the coding cookie."
6101 (let* ((artbuf (current-buffer))
6102 (file-name-coding-system nnmail-pathname-coding-system)
6103 (coding gnus-article-save-coding-system)
6104 (coding-system-for-read (if coding
6105 nil ;; Rely on the coding cookie.
6106 mm-text-coding-system))
6107 (coding-system-for-write (or coding
6108 mm-text-coding-system-for-write
6109 mm-text-coding-system))
6110 (exists (file-exists-p file-name)))
16409b0b 6111 (with-temp-buffer
26c9afc3
MB
6112 (when exists
6113 (insert-file-contents file-name)
6114 (goto-char (point-min))
6115 ;; Remove the existing coding cookie.
6116 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6117 (delete-region (match-beginning 0) (match-end 0))))
6118 (goto-char (point-max))
eec82323
LMI
6119 (insert-buffer-substring artbuf)
6120 ;; Append newline at end of the buffer as separator, and then
6121 ;; save it to file.
6122 (goto-char (point-max))
6123 (insert "\n")
26c9afc3
MB
6124 (when coding
6125 ;; If the coding system is not suitable to encode the text,
6126 ;; ask a user for a proper one.
6127 (when (fboundp 'select-safe-coding-system)
6128 (setq coding (coding-system-base
6129 (save-window-excursion
6130 (select-safe-coding-system (point-min) (point-max)
6131 coding))))
6132 (setq coding-system-for-write
6133 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6134 coding)))
6135 (goto-char (point-min))
6136 ;; Add the coding cookie.
6137 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6138 coding-system-for-write)))
6139 (if exists
6140 (progn
6141 (write-region (point-min) (point-max) file-name nil 'no-message)
6142 (message "Appended to %s" file-name))
6143 (write-region (point-min) (point-max) file-name))))
6144 t)
eec82323
LMI
6145
6146(defun gnus-narrow-to-page (&optional arg)
6147 "Narrow the article buffer to a page.
6148If given a numerical ARG, move forward ARG pages."
6149 (interactive "P")
6150 (setq arg (if arg (prefix-numeric-value arg) 0))
80de1778 6151 (with-current-buffer gnus-article-buffer
eec82323
LMI
6152 (widen)
6153 ;; Remove any old next/prev buttons.
6154 (when (gnus-visual-p 'page-marker)
4e7d0221 6155 (let ((inhibit-read-only t))
eec82323
LMI
6156 (gnus-remove-text-with-property 'gnus-prev)
6157 (gnus-remove-text-with-property 'gnus-next)))
8f7abae3
MB
6158 (let (st nd pt)
6159 (when (save-excursion
6160 (cond ((< arg 0)
6161 (if (re-search-backward page-delimiter nil 'move (abs arg))
6162 (prog1
6163 (setq nd (match-beginning 0)
6164 pt nd)
6165 (when (re-search-backward page-delimiter nil t)
6166 (setq st (match-end 0))))
6167 (when (re-search-forward page-delimiter nil t)
6168 (setq nd (match-beginning 0)
6169 pt (point-min)))))
6170 ((> arg 0)
6171 (if (re-search-forward page-delimiter nil 'move arg)
6172 (prog1
6173 (setq st (match-end 0)
6174 pt st)
6175 (when (re-search-forward page-delimiter nil t)
6176 (setq nd (match-beginning 0))))
6177 (when (re-search-backward page-delimiter nil t)
6178 (setq st (match-end 0)
6179 pt (point-max)))))
6180 (t
6181 (when (re-search-backward page-delimiter nil t)
6182 (goto-char (setq st (match-end 0))))
6183 (when (re-search-forward page-delimiter nil t)
6184 (setq nd (match-beginning 0)))
6185 (or st nd))))
6186 (setq gnus-page-broken t)
6187 (when pt (goto-char pt))
6188 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6189 (when (gnus-visual-p 'page-marker)
6190 (save-excursion
6191 (when nd
6192 (goto-char nd)
6193 (gnus-insert-next-page-button))
6194 (when st
6195 (goto-char st)
6196 (gnus-insert-prev-page-button))))))))
eec82323
LMI
6197
6198;; Article mode commands
6199
6200(defun gnus-article-goto-next-page ()
6201 "Show the next page of the article."
6202 (interactive)
6203 (when (gnus-article-next-page)
6204 (goto-char (point-min))
6205 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6206
23f87bed 6207
eec82323 6208(defun gnus-article-goto-prev-page ()
23f87bed 6209 "Show the previous page of the article."
eec82323 6210 (interactive)
8f7abae3 6211 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
23f87bed 6212 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6213 (gnus-article-prev-page nil)))
6214
23f87bed
MB
6215;; This is cleaner but currently breaks `gnus-pick-mode':
6216;;
6217;; (defun gnus-article-goto-next-page ()
6218;; "Show the next page of the article."
6219;; (interactive)
6220;; (gnus-eval-in-buffer-window gnus-summary-buffer
6221;; (gnus-summary-next-page)))
6222;;
6223;; (defun gnus-article-goto-prev-page ()
6224;; "Show the next page of the article."
6225;; (interactive)
6226;; (gnus-eval-in-buffer-window gnus-summary-buffer
6227;; (gnus-summary-prev-page)))
6228
eec82323
LMI
6229(defun gnus-article-next-page (&optional lines)
6230 "Show the next page of the current article.
6231If end of article, return non-nil. Otherwise return nil.
6232Argument LINES specifies lines to be scrolled up."
6233 (interactive "p")
9153f10d 6234 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
60ece9b0
MB
6235 (if (and (not (and gnus-article-over-scroll
6236 (> (count-lines (window-start) (point-max))
9153f10d
MB
6237 (if (featurep 'xemacs)
6238 (or lines (1- (window-height)))
6239 (+ (or lines (1- (window-height))) scroll-margin)))))
60ece9b0
MB
6240 (save-excursion
6241 (end-of-line)
6242 (and (pos-visible-in-window-p) ;Not continuation line.
6243 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
eec82323
LMI
6244 ;; Nothing in this page.
6245 (if (or (not gnus-page-broken)
6246 (save-excursion
6247 (save-restriction
23f87bed
MB
6248 (widen)
6249 (forward-line)
6250 (eobp)))) ;Real end-of-buffer?
6251 (progn
6252 (when gnus-article-over-scroll
6253 (gnus-article-next-page-1 lines))
6254 t) ;Nothing more.
eec82323
LMI
6255 (gnus-narrow-to-page 1) ;Go to next page.
6256 nil)
6257 ;; More in this page.
23f87bed 6258 (gnus-article-next-page-1 lines)
eec82323
LMI
6259 nil))
6260
d8a88581
MB
6261(defmacro gnus-article-beginning-of-window ()
6262 "Move point to the beginning of the window.
6263In Emacs, the point is placed at the line number which `scroll-margin'
6264specifies."
6265 (if (featurep 'xemacs)
6266 '(move-to-window-line 0)
6267 '(move-to-window-line
6268 (min (max 0 scroll-margin)
6269 (max 1 (- (window-height)
6270 (if mode-line-format 1 0)
9153f10d
MB
6271 (if header-line-format 1 0)
6272 2))))))
d8a88581 6273
23f87bed 6274(defun gnus-article-next-page-1 (lines)
9153f10d 6275 (unless (featurep 'xemacs)
4b91459a
MB
6276 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6277 ;; too many number of lines if `scroll-margin' is set as two or greater.
9153f10d
MB
6278 (when (and (numberp lines)
6279 (> lines 0)
6280 (> scroll-margin 0))
6281 (setq lines (min lines
6282 (max 0 (- (count-lines (window-start) (point-max))
6283 scroll-margin))))))
4b91459a
MB
6284 (condition-case ()
6285 (let ((scroll-in-place nil))
6286 (scroll-up lines))
6287 (end-of-buffer
6288 ;; Long lines may cause an end-of-buffer error.
6289 (goto-char (point-max))))
6290 (gnus-article-beginning-of-window))
23f87bed 6291
eec82323
LMI
6292(defun gnus-article-prev-page (&optional lines)
6293 "Show previous page of current article.
6294Argument LINES specifies lines to be scrolled down."
6295 (interactive "p")
d8a88581 6296 (move-to-window-line 0)
eec82323
LMI
6297 (if (and gnus-page-broken
6298 (bobp)
6299 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6300 (progn
6301 (gnus-narrow-to-page -1) ;Go to previous page.
6302 (goto-char (point-max))
60ece9b0
MB
6303 (recenter (if gnus-article-over-scroll
6304 (if lines
9153f10d
MB
6305 (max (if (featurep 'xemacs)
6306 lines
6307 (+ lines scroll-margin))
60ece9b0
MB
6308 3)
6309 (- (window-height) 2))
6310 -1)))
c03ac728
MB
6311 (prog1
6312 (condition-case ()
6313 (let ((scroll-in-place nil))
6314 (scroll-down lines))
6315 (beginning-of-buffer
6316 (goto-char (point-min))))
6317 (gnus-article-beginning-of-window))))
eec82323 6318
23f87bed
MB
6319(defun gnus-article-only-boring-p ()
6320 "Decide whether there is only boring text remaining in the article.
6321Something \"interesting\" is a word of at least two letters that does
6322not have a face in `gnus-article-boring-faces'."
6323 (when (and gnus-article-skip-boring
6324 (boundp 'gnus-article-boring-faces)
6325 (symbol-value 'gnus-article-boring-faces))
6326 (save-excursion
531bedc3
MB
6327 (let ((inhibit-point-motion-hooks t))
6328 (catch 'only-boring
6329 (while (re-search-forward "\\b\\w\\w" nil t)
6330 (forward-char -1)
6331 (when (not (gnus-intersection
6332 (gnus-faces-at (point))
6333 (symbol-value 'gnus-article-boring-faces)))
6334 (throw 'only-boring nil)))
6335 (throw 'only-boring t))))))
23f87bed 6336
eec82323
LMI
6337(defun gnus-article-refer-article ()
6338 "Read article specified by message-id around point."
6339 (interactive)
23f87bed 6340 (save-excursion
01c52d31
MB
6341 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6342 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6343 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6344 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6345 (set-buffer gnus-summary-buffer)
23f87bed 6346 (gnus-summary-refer-article msg-id))
eec82323
LMI
6347 (error "No references around point"))))
6348
6349(defun gnus-article-show-summary ()
6350 "Reconfigure windows to show summary buffer."
6351 (interactive)
6352 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6353 (error "There is no summary buffer for this article buffer")
a8151ef7 6354 (gnus-article-set-globals)
eec82323 6355 (gnus-configure-windows 'article)
6748645f
LMI
6356 (gnus-summary-goto-subject gnus-current-article)
6357 (gnus-summary-position-point)))
eec82323
LMI
6358
6359(defun gnus-article-describe-briefly ()
6360 "Describe article mode commands briefly."
6361 (interactive)
16409b0b 6362 (gnus-message 6 (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 6363
16409b0b
GM
6364(defun gnus-article-check-buffer ()
6365 "Beep if not in an article buffer."
6366 (unless (equal major-mode 'gnus-article-mode)
6367 (error "Command invoked outside of a Gnus article buffer")))
6368
eec82323
LMI
6369(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6370 "Read a summary buffer key sequence and execute it from the article buffer."
6371 (interactive "P")
16409b0b 6372 (gnus-article-check-buffer)
eec82323 6373 (let ((nosaves
23f87bed
MB
6374 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6375 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6376 "=" "^" "\M-^" "|"))
6377 (nosave-but-article
0b6799c3
MB
6378 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6379 "An" "Ap" [?A (meta return)] [?A delete]))
23f87bed 6380 (nosave-in-article
0b6799c3 6381 '("AS" "\C-d"))
23f87bed
MB
6382 (up-to-top
6383 '("n" "Gn" "p" "Gp"))
6384 keys new-sum-point)
80de1778 6385 (with-current-buffer gnus-article-current-summary
eec82323 6386 (let (gnus-pick-mode)
95838435
MB
6387 (setq unread-command-events (nconc unread-command-events
6388 (list (or key last-command-event)))
6389 keys (if (featurep 'xemacs)
6390 (events-to-keys (read-key-sequence nil t))
6391 (read-key-sequence nil t)))))
a1506d29 6392
eec82323
LMI
6393 (message "")
6394
01c52d31
MB
6395 (cond
6396 ((eq (aref keys (1- (length keys))) ?\C-h)
0b6799c3 6397 (gnus-article-describe-bindings (substring keys 0 -1)))
01c52d31
MB
6398 ((or (member keys nosaves)
6399 (member keys nosave-but-article)
6400 (member keys nosave-in-article))
6401 (let (func)
6402 (save-window-excursion
6403 (pop-to-buffer gnus-article-current-summary)
6404 ;; We disable the pick minor mode commands.
6405 (let (gnus-pick-mode)
6ab2c7a8 6406 (setq func (key-binding keys t))))
01c52d31
MB
6407 (if (or (not func)
6408 (numberp func))
6409 (ding)
6410 (unless (member keys nosave-in-article)
6411 (set-buffer gnus-article-current-summary))
6412 (call-interactively func)
6413 (setq new-sum-point (point)))
6414 (when (member keys nosave-but-article)
6415 (pop-to-buffer gnus-article-buffer))))
6416 (t
eec82323
LMI
6417 ;; These commands should restore window configuration.
6418 (let ((obuf (current-buffer))
23f87bed 6419 (owin (current-window-configuration))
01c52d31 6420 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6421 (cond (not-restore-window
01c52d31
MB
6422 (pop-to-buffer gnus-article-current-summary)
6423 (setq win (selected-window)))
23f87bed
MB
6424 ((setq win (get-buffer-window gnus-article-current-summary))
6425 (select-window win))
6426 (t
01c52d31
MB
6427 (let ((summary-buffer gnus-article-current-summary))
6428 (gnus-configure-windows 'article)
6429 (unless (setq win (get-buffer-window summary-buffer 'visible))
6430 (let ((gnus-buffer-configuration
de0bdfe7
KY
6431 '((article ((vertical 1.0
6432 (summary 0.25 point)
6433 (article 1.0)))))))
01c52d31
MB
6434 (gnus-configure-windows 'article))
6435 (setq win (get-buffer-window summary-buffer 'visible)))
6436 (gnus-select-frame-set-input-focus (window-frame win))
6437 (select-window win))))
23f87bed
MB
6438 (setq in-buffer (current-buffer))
6439 ;; We disable the pick minor mode commands.
6440 (if (and (setq func (let (gnus-pick-mode)
6ab2c7a8 6441 (key-binding keys t)))
01c52d31
MB
6442 (functionp func)
6443 (condition-case code
6444 (progn
6445 (call-interactively func)
6446 t)
6447 (error
6448 (setq err code)
6449 nil)))
23f87bed 6450 (progn
23f87bed
MB
6451 (when (eq win (selected-window))
6452 (setq new-sum-point (point)
6453 new-sum-start (window-start win)
9a89f5b0 6454 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6455 (when (or (eq in-buffer (current-buffer))
6456 (when (eq obuf (current-buffer))
6457 (set-buffer in-buffer)
6458 t))
520aa572
SZ
6459 (setq selected (gnus-summary-select-article))
6460 (set-buffer obuf)
6461 (unless not-restore-window
6462 (set-window-configuration owin))
01c52d31
MB
6463 (when (and (eq selected 'old)
6464 new-sum-point)
520aa572
SZ
6465 (set-window-start (get-buffer-window (current-buffer))
6466 1)
6467 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6468 (if (article-goto-body)
6469 (1- (point))
6470 (point))))
23f87bed 6471 (when (and (not not-restore-window)
01c52d31 6472 new-sum-point
4520e527 6473 (window-live-p win)
01c52d31
MB
6474 (with-current-buffer (window-buffer win)
6475 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6476 (set-window-point win new-sum-point)
6477 (set-window-start win new-sum-start)
9a89f5b0 6478 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6479 (set-window-configuration owin)
01c52d31
MB
6480 (if err
6481 (signal (car err) (cdr err))
6482 (ding))))))))
520aa572 6483
95838435
MB
6484(defun gnus-article-read-summary-send-keys ()
6485 (interactive)
0b6799c3 6486 (let ((unread-command-events (list (gnus-character-to-event ?S))))
95838435
MB
6487 (gnus-article-read-summary-keys)))
6488
520aa572 6489(defun gnus-article-describe-key (key)
95838435
MB
6490 "Display documentation of the function invoked by KEY.
6491KEY is a string or a vector."
6492 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6493 (read-key-sequence "Describe key: "))))
520aa572 6494 (gnus-article-check-buffer)
95838435
MB
6495 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6496 gnus-article-read-summary-send-keys))
80de1778 6497 (with-current-buffer gnus-article-current-summary
95838435
MB
6498 (setq unread-command-events
6499 (if (featurep 'xemacs)
6500 (append key nil)
6501 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6502 (list 'meta (- x 128))
6503 x))
6504 key)))
6505 (let ((cursor-in-echo-area t)
6506 gnus-pick-mode)
6507 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6508 (describe-key key)))
6509
6510(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6511 "Display documentation of the function invoked by KEY.
6512KEY is a string or a vector."
6513 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6514 (read-key-sequence "Describe key: "))
6515 current-prefix-arg))
520aa572 6516 (gnus-article-check-buffer)
95838435
MB
6517 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6518 gnus-article-read-summary-send-keys))
80de1778 6519 (with-current-buffer gnus-article-current-summary
95838435
MB
6520 (setq unread-command-events
6521 (if (featurep 'xemacs)
6522 (append key nil)
6523 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6524 (list 'meta (- x 128))
6525 x))
6526 key)))
6527 (let ((cursor-in-echo-area t)
6528 gnus-pick-mode)
6529 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6530 (describe-key-briefly key insert)))
eec82323 6531
0b6799c3
MB
6532;;`gnus-agent-mode' in gnus-agent.el will define it.
6533(defvar gnus-agent-summary-mode)
e9198520 6534(defvar gnus-draft-mode)
12ea3d65
GM
6535;; Calling help-buffer will autoload help-mode.
6536(defvar help-xref-stack-item)
0b6799c3
MB
6537
6538(defun gnus-article-describe-bindings (&optional prefix)
6539 "Show a list of all defined keys, and their definitions.
6540The optional argument PREFIX, if non-nil, should be a key sequence;
6541then we display only bindings that start with that prefix."
6542 (interactive)
6543 (gnus-article-check-buffer)
6544 (let ((keymap (copy-keymap gnus-article-mode-map))
6545 (map (copy-keymap gnus-article-send-map))
6546 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
8a908224 6547 parent agent draft)
0b6799c3
MB
6548 (define-key keymap "S" map)
6549 (define-key map [t] nil)
6550 (with-current-buffer gnus-article-current-summary
8a908224
KY
6551 (set-keymap-parent
6552 keymap
6553 (if (setq parent (keymap-parent gnus-article-mode-map))
6554 (prog1
6555 (setq parent (copy-keymap parent))
6556 (set-keymap-parent parent (current-local-map)))
6557 (current-local-map)))
0b6799c3 6558 (set-keymap-parent map (key-binding "S"))
8f7abae3
MB
6559 (let (key def gnus-pick-mode)
6560 (while sumkeys
6561 (setq key (pop sumkeys))
6562 (cond ((and (vectorp key) (= (length key) 1)
6563 (consp (setq def (aref key 0)))
6564 (numberp (car def)) (numberp (cdr def)))
6565 (when (< (max (car def) (cdr def)) 128)
6566 (setq sumkeys
6567 (append (mapcar
6568 #'vector
6569 (nreverse (gnus-uncompress-range def)))
6570 sumkeys))))
6571 ((setq def (key-binding key))
6572 (unless (eq def 'undefined)
6573 (define-key keymap key def))))))
0b6799c3 6574 (when (boundp 'gnus-agent-summary-mode)
e9198520
MB
6575 (setq agent gnus-agent-summary-mode))
6576 (when (boundp 'gnus-draft-mode)
6577 (setq draft gnus-draft-mode)))
0b6799c3
MB
6578 (with-temp-buffer
6579 (use-local-map keymap)
6580 (set (make-local-variable 'gnus-agent-summary-mode) agent)
e9198520 6581 (set (make-local-variable 'gnus-draft-mode) draft)
0b6799c3
MB
6582 (describe-bindings prefix))
6583 (let ((item `((lambda (prefix)
80de1778 6584 (with-current-buffer ,(current-buffer)
0b6799c3
MB
6585 (gnus-article-describe-bindings prefix)))
6586 ,prefix)))
6587 (with-current-buffer (if (fboundp 'help-buffer)
6588 (let (help-xref-following) (help-buffer))
6589 "*Help*") ;; Emacs 21
6590 (setq help-xref-stack-item item)))))
6591
23f87bed
MB
6592(defun gnus-article-reply-with-original (&optional wide)
6593 "Start composing a reply mail to the current message.
6594The text in the region will be yanked. If the region isn't active,
6595the entire article will be yanked."
95838435 6596 (interactive)
23f87bed
MB
6597 (let ((article (cdr gnus-article-current))
6598 contents)
1d0df8af 6599 (if (not (gnus-region-active-p))
23f87bed
MB
6600 (with-current-buffer gnus-summary-buffer
6601 (gnus-summary-reply (list (list article)) wide))
6602 (setq contents (buffer-substring (point) (mark t)))
6603 ;; Deactivate active regions.
6604 (when (and (boundp 'transient-mark-mode)
6605 transient-mark-mode)
6606 (setq mark-active nil))
6607 (with-current-buffer gnus-summary-buffer
6608 (gnus-summary-reply
6609 (list (list article contents)) wide)))))
6610
95838435
MB
6611(defun gnus-article-wide-reply-with-original ()
6612 "Start composing a wide reply mail to the current message.
6613The text in the region will be yanked. If the region isn't active,
6614the entire article will be yanked."
6615 (interactive)
6616 (gnus-article-reply-with-original t))
6617
23f87bed
MB
6618(defun gnus-article-followup-with-original ()
6619 "Compose a followup to the current article.
6620The text in the region will be yanked. If the region isn't active,
6621the entire article will be yanked."
6622 (interactive)
6623 (let ((article (cdr gnus-article-current))
6624 contents)
1d0df8af 6625 (if (not (gnus-region-active-p))
23f87bed
MB
6626 (with-current-buffer gnus-summary-buffer
6627 (gnus-summary-followup (list (list article))))
6628 (setq contents (buffer-substring (point) (mark t)))
6629 ;; Deactivate active regions.
6630 (when (and (boundp 'transient-mark-mode)
6631 transient-mark-mode)
6632 (setq mark-active nil))
6633 (with-current-buffer gnus-summary-buffer
6634 (gnus-summary-followup
6635 (list (list article contents)))))))
6636
eec82323
LMI
6637(defun gnus-article-hide (&optional arg force)
6638 "Hide all the gruft in the current article.
23f87bed
MB
6639This means that signatures, cited text and (some) headers will be
6640hidden.
eec82323 6641If given a prefix, show the hidden text instead."
6748645f 6642 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6643 (gnus-article-hide-headers arg)
16409b0b 6644 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6645 (gnus-article-hide-citation-maybe arg force)
6646 (gnus-article-hide-signature arg))
6647
6648(defun gnus-article-maybe-highlight ()
6748645f 6649 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6650 (when (gnus-visual-p 'article-highlight 'highlight)
6651 (gnus-article-highlight-some)))
6652
6748645f
LMI
6653(defun gnus-check-group-server ()
6654 ;; Make sure the connection to the server is alive.
6655 (unless (gnus-server-opened
6656 (gnus-find-method-for-group gnus-newsgroup-name))
6657 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6658 (gnus-request-group gnus-newsgroup-name t)))
6659
23f87bed
MB
6660(eval-when-compile
6661 (autoload 'nneething-get-file-name "nneething"))
6662
eec82323
LMI
6663(defun gnus-request-article-this-buffer (article group)
6664 "Get an article and insert it into this buffer."
6748645f 6665 (let (do-update-line sparse-header)
eec82323
LMI
6666 (prog1
6667 (save-excursion
6668 (erase-buffer)
6669 (gnus-kill-all-overlays)
6670 (setq group (or group gnus-newsgroup-name))
6671
eec82323
LMI
6672 ;; Using `gnus-request-article' directly will insert the article into
6673 ;; `nntp-server-buffer' - so we'll save some time by not having to
6674 ;; copy it from the server buffer into the article buffer.
6675
6676 ;; We only request an article by message-id when we do not have the
6677 ;; headers for it, so we'll have to get those.
6678 (when (stringp article)
16409b0b 6679 (gnus-read-header article))
eec82323
LMI
6680
6681 ;; If the article number is negative, that means that this article
6682 ;; doesn't belong in this newsgroup (possibly), so we find its
6683 ;; message-id and request it by id instead of number.
6684 (when (and (numberp article)
6685 gnus-summary-buffer
6686 (get-buffer gnus-summary-buffer)
6748645f 6687 (gnus-buffer-exists-p gnus-summary-buffer))
80de1778 6688 (with-current-buffer gnus-summary-buffer
eec82323
LMI
6689 (let ((header (gnus-summary-article-header article)))
6690 (when (< article 0)
6691 (cond
6692 ((memq article gnus-newsgroup-sparse)
6693 ;; This is a sparse gap article.
6694 (setq do-update-line article)
6695 (setq article (mail-header-id header))
16409b0b 6696 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6697 (setq gnus-newsgroup-sparse
6698 (delq article gnus-newsgroup-sparse)))
6699 ((vectorp header)
6700 ;; It's a real article.
6701 (setq article (mail-header-id header)))
6702 (t
6703 ;; It is an extracted pseudo-article.
6704 (setq article 'pseudo)
6705 (gnus-request-pseudo-article header))))
6706
6707 (let ((method (gnus-find-method-for-group
6708 gnus-newsgroup-name)))
6748645f
LMI
6709 (when (and (eq (car method) 'nneething)
6710 (vectorp header))
23f87bed
MB
6711 (let ((dir (nneething-get-file-name
6712 (mail-header-id header))))
6713 (when (and (stringp dir)
6714 (file-directory-p dir))
eec82323
LMI
6715 (setq article 'nneething)
6716 (gnus-group-enter-directory dir))))))))
6717
6718 (cond
6719 ;; Refuse to select canceled articles.
6720 ((and (numberp article)
6721 gnus-summary-buffer
6722 (get-buffer gnus-summary-buffer)
6748645f 6723 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6724 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6725 (assq article gnus-newsgroup-reads)))
6726 gnus-canceled-mark))
6727 nil)
6728 ;; We first check `gnus-original-article-buffer'.
6729 ((and (get-buffer gnus-original-article-buffer)
6730 (numberp article)
01c52d31 6731 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6732 (and (equal (car gnus-original-article) group)
6733 (eq (cdr gnus-original-article) article))))
75eda25b
SM
6734 ;; `insert-buffer-substring' would incorrectly use the
6735 ;; equivalent of string-make-multibyte which amount to decoding
6736 ;; with locale-coding-system, causing failure of
6737 ;; subsequent decoding.
6738 (insert (mm-string-to-multibyte
6739 (with-current-buffer gnus-original-article-buffer
6740 (buffer-substring (point-min) (point-max)))))
eec82323
LMI
6741 'article)
6742 ;; Check the backlog.
6743 ((and gnus-keep-backlog
6744 (gnus-backlog-request-article group article (current-buffer)))
6745 'article)
6746 ;; Check asynchronous pre-fetch.
6747 ((gnus-async-request-fetched-article group article (current-buffer))
6748 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6749 (when (and (numberp article) gnus-keep-backlog)
6750 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6751 'article)
6752 ;; Check the cache.
6753 ((and gnus-use-cache
6754 (numberp article)
6755 (gnus-cache-request-article article group))
6756 'article)
23f87bed
MB
6757 ;; Check the agent cache.
6758 ((gnus-agent-request-article article group)
6759 'article)
eec82323 6760 ;; Get the article and put into the article buffer.
16409b0b
GM
6761 ((or (stringp article)
6762 (numberp article))
6763 (let ((gnus-override-method gnus-override-method)
a1506d29 6764 (methods (and (stringp article)
16409b0b 6765 gnus-refer-article-method))
23f87bed
MB
6766 (backend (car (gnus-find-method-for-group
6767 gnus-newsgroup-name)))
16409b0b 6768 result
4e7d0221 6769 (inhibit-read-only t))
e0bad764
DL
6770 (if (or (not (listp methods))
6771 (and (symbolp (car methods))
6772 (assq (car methods) nnoo-definition-alist)))
6773 (setq methods (list methods)))
16409b0b
GM
6774 (when (and (null gnus-override-method)
6775 methods)
6776 (setq gnus-override-method (pop methods)))
6777 (while (not result)
6778 (when (eq gnus-override-method 'current)
c55f89a5
GM
6779 (setq gnus-override-method
6780 (with-current-buffer gnus-summary-buffer
6781 gnus-current-select-method)))
16409b0b
GM
6782 (erase-buffer)
6783 (gnus-kill-all-overlays)
6784 (let ((gnus-newsgroup-name group))
6785 (gnus-check-group-server))
23f87bed
MB
6786 (cond
6787 ((gnus-request-article article group (current-buffer))
16409b0b 6788 (when (numberp article)
a1506d29 6789 (gnus-async-prefetch-next group article
16409b0b
GM
6790 gnus-summary-buffer)
6791 (when gnus-keep-backlog
6792 (gnus-backlog-enter-article
6793 group article (current-buffer))))
6794 (setq result 'article))
23f87bed
MB
6795 (methods
6796 (setq gnus-override-method (pop methods)))
6797 ((not (string-match "^400 "
6798 (nnheader-get-report backend)))
6799 ;; If we get 400 server disconnect, reconnect and
6800 ;; retry; otherwise, assume the article has expired.
6801 (setq result 'done))))
16409b0b 6802 (and (eq result 'article) 'article)))
eec82323
LMI
6803 ;; It was a pseudo.
6804 (t article)))
6805
6748645f
LMI
6806 ;; Associate this article with the current summary buffer.
6807 (setq gnus-article-current-summary gnus-summary-buffer)
6808
eec82323
LMI
6809 ;; Take the article from the original article buffer
6810 ;; and place it in the buffer it's supposed to be in.
6811 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6812 (equal (buffer-name (current-buffer))
6813 (buffer-name (get-buffer gnus-article-buffer))))
6814 (save-excursion
6815 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6816 (set-buffer gnus-original-article-buffer)
6817 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6818 (buffer-disable-undo)
eec82323 6819 (setq major-mode 'gnus-original-article-mode)
6748645f 6820 (setq buffer-read-only t))
23f87bed 6821 (let ((inhibit-read-only t))
eec82323
LMI
6822 (erase-buffer)
6823 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6824 (setq gnus-original-article (cons group article)))
6825
6826 ;; Decode charsets.
6827 (run-hooks 'gnus-article-decode-hook)
6828 ;; Mark article as decoded or not.
6829 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6830
6831 ;; Update sparse articles.
6832 (when (and do-update-line
6833 (or (numberp article)
6834 (stringp article)))
6835 (let ((buf (current-buffer)))
6836 (set-buffer gnus-summary-buffer)
6748645f 6837 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6838 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6839 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6840 (point))
6841 (set-buffer buf))))))
6842
6843;;;
6844;;; Article editing
6845;;;
6846
6847(defcustom gnus-article-edit-mode-hook nil
6848 "Hook run in article edit mode buffers."
6849 :group 'gnus-article-various
6850 :type 'hook)
6851
6852(defvar gnus-article-edit-done-function nil)
6853
6854(defvar gnus-article-edit-mode-map nil)
6855
16409b0b 6856;; Should we be using derived.el for this?
eec82323 6857(unless gnus-article-edit-mode-map
23f87bed 6858 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6859 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6860
6861 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6862 "\C-c?" describe-mode
eec82323 6863 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6864 "\C-c\C-k" gnus-article-edit-exit
6865 "\C-c\C-f\C-t" message-goto-to
6866 "\C-c\C-f\C-o" message-goto-from
6867 "\C-c\C-f\C-b" message-goto-bcc
6868 ;;"\C-c\C-f\C-w" message-goto-fcc
6869 "\C-c\C-f\C-c" message-goto-cc
6870 "\C-c\C-f\C-s" message-goto-subject
6871 "\C-c\C-f\C-r" message-goto-reply-to
6872 "\C-c\C-f\C-n" message-goto-newsgroups
6873 "\C-c\C-f\C-d" message-goto-distribution
6874 "\C-c\C-f\C-f" message-goto-followup-to
6875 "\C-c\C-f\C-m" message-goto-mail-followup-to
6876 "\C-c\C-f\C-k" message-goto-keywords
6877 "\C-c\C-f\C-u" message-goto-summary
6878 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6879 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6880 "\C-c\C-b" message-goto-body
6881 "\C-c\C-i" message-goto-signature
6882
6883 "\C-c\C-t" message-insert-to
6884 "\C-c\C-n" message-insert-newsgroups
6885 "\C-c\C-o" message-sort-headers
6886 "\C-c\C-e" message-elide-region
6887 "\C-c\C-v" message-delete-not-region
6888 "\C-c\C-z" message-kill-to-signature
6889 "\M-\r" message-newline-and-reformat
6890 "\C-c\C-a" mml-attach-file
6891 "\C-a" message-beginning-of-line
6892 "\t" message-tab
6893 "\M-;" comment-region)
eec82323
LMI
6894
6895 (gnus-define-keys (gnus-article-edit-wash-map
6896 "\C-c\C-w" gnus-article-edit-mode-map)
6897 "f" gnus-article-edit-full-stops))
6898
23f87bed
MB
6899(easy-menu-define
6900 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6901 '("Field"
6902 ["Fetch To" message-insert-to t]
6903 ["Fetch Newsgroups" message-insert-newsgroups t]
6904 "----"
6905 ["To" message-goto-to t]
6906 ["From" message-goto-from t]
6907 ["Subject" message-goto-subject t]
6908 ["Cc" message-goto-cc t]
6909 ["Reply-To" message-goto-reply-to t]
6910 ["Summary" message-goto-summary t]
6911 ["Keywords" message-goto-keywords t]
6912 ["Newsgroups" message-goto-newsgroups t]
6913 ["Followup-To" message-goto-followup-to t]
6914 ["Mail-Followup-To" message-goto-mail-followup-to t]
6915 ["Distribution" message-goto-distribution t]
6916 ["Body" message-goto-body t]
6917 ["Signature" message-goto-signature t]))
6918
4e7d0221 6919(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6920 "Major mode for editing articles.
6921This is an extended text-mode.
6922
6923\\{gnus-article-edit-mode-map}"
eec82323
LMI
6924 (make-local-variable 'gnus-article-edit-done-function)
6925 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6926 (set (make-local-variable 'font-lock-defaults)
6927 '(message-font-lock-keywords t))
23f87bed
MB
6928 (set (make-local-variable 'mail-header-separator) "")
6929 (set (make-local-variable 'gnus-article-edit-mode) t)
6930 (easy-menu-add message-mode-field-menu message-mode-map)
6931 (mml-mode)
eec82323
LMI
6932 (setq buffer-read-only nil)
6933 (buffer-enable-undo)
80b47379 6934 (widen))
eec82323
LMI
6935
6936(defun gnus-article-edit (&optional force)
6937 "Edit the current article.
6938This will have permanent effect only in mail groups.
6939If FORCE is non-nil, allow editing of articles even in read-only
6940groups."
6941 (interactive "P")
6942 (when (and (not force)
6943 (gnus-group-read-only-p))
a8151ef7 6944 (error "The current newsgroup does not support article editing"))
6748645f 6945 (gnus-article-date-original)
eec82323 6946 (gnus-article-edit-article
16409b0b 6947 'ignore
6748645f 6948 `(lambda (no-highlight)
16409b0b 6949 'ignore
eec82323
LMI
6950 (gnus-summary-edit-article-done
6951 ,(or (mail-header-references gnus-current-headers) "")
6748645f 6952 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 6953
01c52d31 6954(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
6955 "Start editing the contents of the current article buffer."
6956 (let ((winconf (current-window-configuration)))
6957 (set-buffer gnus-article-buffer)
0683d241
MB
6958 (let ((message-auto-save-directory
6959 ;; Don't associate the article buffer with a draft file.
6960 nil))
6961 (gnus-article-edit-mode))
16409b0b 6962 (funcall start-func)
23f87bed 6963 (set-buffer-modified-p nil)
eec82323
LMI
6964 (gnus-configure-windows 'edit-article)
6965 (setq gnus-article-edit-done-function exit-func)
6966 (setq gnus-prev-winconf winconf)
01c52d31
MB
6967 (unless quiet
6968 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 6969
6748645f 6970(defun gnus-article-edit-done (&optional arg)
eec82323 6971 "Update the article edits and exit."
6748645f 6972 (interactive "P")
eec82323
LMI
6973 (let ((func gnus-article-edit-done-function)
6974 (buf (current-buffer))
23f87bed
MB
6975 (start (window-start))
6976 (p (point))
6977 (winconf gnus-prev-winconf))
6978 (widen) ;; Widen it in case that users narrowed the buffer.
6979 (funcall func arg)
6980 (set-buffer buf)
6981 ;; The cache and backlog have to be flushed somewhat.
6982 (when gnus-keep-backlog
6983 (gnus-backlog-remove-article
6984 (car gnus-article-current) (cdr gnus-article-current)))
6985 ;; Flush original article as well.
80de1778
SM
6986 (when (get-buffer gnus-original-article-buffer)
6987 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
6988 (setq gnus-original-article nil)))
6989 (when gnus-use-cache
6990 (gnus-cache-update-article
6991 (car gnus-article-current) (cdr gnus-article-current)))
6992 ;; We remove all text props from the article buffer.
6993 (kill-all-local-variables)
01c52d31 6994 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
6995 (gnus-article-mode)
6996 (set-window-configuration winconf)
eec82323
LMI
6997 (set-buffer buf)
6998 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
6999 (set-window-point (get-buffer-window buf) (point)))
7000 (gnus-summary-show-article))
eec82323
LMI
7001
7002(defun gnus-article-edit-exit ()
7003 "Exit the article editing without updating."
7004 (interactive)
23f87bed
MB
7005 (when (or (not (buffer-modified-p))
7006 (yes-or-no-p "Article modified; kill anyway? "))
7007 (let ((curbuf (current-buffer))
7008 (p (point))
7009 (window-start (window-start)))
7010 (erase-buffer)
7011 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 7012 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
7013 (let ((winconf gnus-prev-winconf))
7014 (kill-all-local-variables)
7015 (gnus-article-mode)
7016 (set-window-configuration winconf)
7017 ;; Tippy-toe some to make sure that point remains where it was.
7018 (save-current-buffer
7019 (set-buffer curbuf)
7020 (set-window-start (get-buffer-window (current-buffer)) window-start)
7021 (goto-char p))))
7022 (gnus-summary-show-article)))
eec82323
LMI
7023
7024(defun gnus-article-edit-full-stops ()
7025 "Interactively repair spacing at end of sentences."
7026 (interactive)
7027 (save-excursion
7028 (goto-char (point-min))
7029 (search-forward-regexp "^$" nil t)
7030 (let ((case-fold-search nil))
7031 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7032
7033;;;
7034;;; Article highlights
7035;;;
7036
7037;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7038
7039;;; Internal Variables:
7040
a1506d29 7041(defcustom gnus-button-url-regexp
01c52d31
MB
7042 (concat
7043 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7044 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7045 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7046 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7047 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7048 (punct "!?:;.,"))
7049 (concat
7050 "\\(?:"
7051 ;; Match paired parentheses, e.g. in Wikipedia URLs:
9b3ebcb6
MB
7052 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7053 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
01c52d31
MB
7054 "\\|"
7055 "[" chars punct "]+" "[" chars "]"
7056 "\\)"))
7057 (concat ;; XEmacs 21.4 doesn't support POSIX.
7058 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7059 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7060 "\\)")
eec82323
LMI
7061 "Regular expression that matches URLs."
7062 :group 'gnus-article-buttons
7063 :type 'regexp)
7064
23f87bed
MB
7065(defcustom gnus-button-valid-fqdn-regexp
7066 message-valid-fqdn-regexp
7067 "Regular expression that matches a valid FQDN."
bf247b6e 7068 :version "22.1"
23f87bed
MB
7069 :group 'gnus-article-buttons
7070 :type 'regexp)
7071
97f78c9b
MB
7072;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7073(defcustom gnus-button-valid-localpart-regexp
14e6dc54 7074 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
7075 "Regular expression that matches a localpart of mail addresses or MIDs."
7076 :version "22.1"
7077 :group 'gnus-article-buttons
7078 :type 'regexp)
7079
23f87bed
MB
7080(defcustom gnus-button-man-handler 'manual-entry
7081 "Function to use for displaying man pages.
7082The function must take at least one argument with a string naming the
7083man page."
bf247b6e 7084 :version "22.1"
23f87bed
MB
7085 :type '(choice (function-item :tag "Man" manual-entry)
7086 (function-item :tag "Woman" woman)
7087 (function :tag "Other"))
7088 :group 'gnus-article-buttons)
7089
7090(defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
7091 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
7092If the default site is too slow, try to find a CTAN mirror, see
7093<URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
7094the variable `gnus-button-handle-ctan'."
bf247b6e 7095 :version "22.1"
23f87bed
MB
7096 :group 'gnus-article-buttons
7097 :link '(custom-manual "(gnus)Group Parameters")
7098 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
7099 (const "http://tug.ctan.org/tex-archive/")
7100 (const "http://www.dante.de/CTAN/")
7101 (string :tag "Other")))
7102
7103(defcustom gnus-button-ctan-handler 'browse-url
7104 "Function to use for displaying CTAN links.
7105The function must take one argument, the string naming the URL."
bf247b6e 7106 :version "22.1"
23f87bed
MB
7107 :type '(choice (function-item :tag "Browse Url" browse-url)
7108 (function :tag "Other"))
7109 :group 'gnus-article-buttons)
7110
7111(defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
7112 "Bogus strings removed from CTAN URLs."
bf247b6e 7113 :version "22.1"
23f87bed
MB
7114 :group 'gnus-article-buttons
7115 :type '(choice (const "^/?tex-archive/\\|/")
7116 (regexp :tag "Other")))
7117
7118(defcustom gnus-button-ctan-directory-regexp
97f78c9b
MB
7119 (regexp-opt
7120 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
7121 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
7122 "languages" "macros" "nonfree" "obsolete" "support" "systems"
7123 "tds" "tools" "usergrps" "web") t)
23f87bed
MB
7124 "Regular expression for ctan directories.
7125It should match all directories in the top level of `gnus-ctan-url'."
bf247b6e 7126 :version "22.1"
23f87bed
MB
7127 :group 'gnus-article-buttons
7128 :type 'regexp)
7129
7130(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 7131 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
7132 gnus-button-valid-fqdn-regexp
7133 ">?\\)\\b")
7134 "Regular expression that matches a message ID or a mail address."
bf247b6e 7135 :version "22.1"
23f87bed
MB
7136 :group 'gnus-article-buttons
7137 :type 'regexp)
7138
7139(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7140 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7141Strings like this can be either a message ID or a mail address. If it is one
7142of the symbols `mid' or `mail', Gnus will always assume that the string is a
7143message ID or a mail address, respectively. If this variable is set to the
7144symbol `ask', always query the user what do do. If it is a function, this
aa819354 7145function will be called with the string as its only argument. The function
23f87bed 7146must return `mid', `mail', `invalid' or `ask'."
bf247b6e 7147 :version "22.1"
23f87bed
MB
7148 :group 'gnus-article-buttons
7149 :type '(choice (function-item :tag "Heuristic function"
7150 gnus-button-mid-or-mail-heuristic)
7151 (const ask)
7152 (const mid)
7153 (const mail)))
7154
7155(defcustom gnus-button-mid-or-mail-heuristic-alist
7156 '((-10.0 . ".+\\$.+@")
7157 (-10.0 . "#")
7158 (-10.0 . "\\*")
7159 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7160 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7161 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7162 (-1.0 . "^[^a-z]+@")
7163 ;;
7164 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7165 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7166 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7167 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7168 ;;
7169 (-2.0 . "^[0-9]")
7170 (-1.0 . "^[0-9][0-9]")
7171 ;;
7172 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7173 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7174 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7175 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7176 ;;
7177 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7178 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7179 ;; "[0-9]{8,}.*\@"
7180 (-3.0
7181 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7182 ;; "[0-9]{12,}.*\@"
7183 ;; compensation for TDMA dated mail addresses:
7184 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7185 ;;
7186 (-20.0 . "\\.fsf@") ;; Gnus
7187 (-20.0 . "^slrn")
7188 (-20.0 . "^Pine")
437ce4be 7189 (-20.0 . "^alpine\\.")
23f87bed
MB
7190 (-20.0 . "_-_") ;; Subject change in thread
7191 ;;
7192 (-20.0 . "\\.ln@") ;; leafnode
7193 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7194 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7195 ;;
7196 ;; (5.0 . "") ;; $local_part_len <= 7
7197 (10.0 . "^[^0-9]+@")
7198 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7199 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7200 (3.0 . "\@stud")
7201 ;;
7202 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7203 ;;
7204 (0.5 . "^[A-Z][a-z]")
7205 (0.5 . "^[A-Z][a-z][a-z]")
7206 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7207 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7208 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7209
7210A negative RATE indicates a message IDs, whereas a positive indicates a mail
7211address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7212 :version "22.1"
23f87bed
MB
7213 :group 'gnus-article-buttons
7214 :type '(repeat (cons (number :tag "Rate")
7215 (regexp :tag "Regexp"))))
7216
7217(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7218 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7219Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7220address, `ask' if unsure and `invalid' if the string is invalid."
7221 (let ((case-fold-search nil)
7222 (list gnus-button-mid-or-mail-heuristic-alist)
7223 (result 0) rate regexp lpartlen elem)
7224 (setq lpartlen
7225 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7226 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7227 ;; Certain special cases...
7228 (when (string-match
7229 (concat
7230 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7231 "^[0-9]+\\.[0-9]+@compuserve\\|"
7232 "@public\\.gmane\\.org")
7233 mid-or-mail)
7234 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7235 (setq result 'mail))
7236 (when (string-match "@.*@\\| " mid-or-mail)
7237 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7238 (setq result 'invalid))
7239 ;; Nothing more to do, if result is not a number here...
7240 (when (numberp result)
7241 (while list
7242 (setq elem (car list)
7243 rate (car elem)
7244 regexp (cdr elem)
7245 list (cdr list))
7246 (when (string-match regexp mid-or-mail)
7247 (setq result (+ result rate))
7248 (gnus-message
7249 9 "`%s' matched `%s', rate `%s', result `%s'."
7250 mid-or-mail regexp rate result)))
7251 (when (<= lpartlen 7)
7252 (setq result (+ result 5.0))
7253 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7254 mid-or-mail result))
7255 (when (>= lpartlen 12)
7256 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7257 (cond
7258 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7259 ;; Long local part should contain realname if e-mail address,
7260 ;; too many digits: message-id.
7261 ;; $score -= 5.0 + 0.1 * $local_part_len;
7262 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7263 (setq result (+ result rate))
7264 (gnus-message
7265 9 "Many digits in `%s', rate `%s', result `%s'."
7266 mid-or-mail rate result))
7267 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7268 mid-or-mail)
7269 ;; Too few vowels [^aeiouy]{4,}.*\@
7270 (setq result (+ result -5.0))
7271 (gnus-message
7272 9 "Few vowels in `%s', rate `%s', result `%s'."
7273 mid-or-mail -5.0 result))
7274 (t
7275 (setq result (+ result 5.0))
7276 (gnus-message
7277 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7278 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7279 ;; Maybe we should make this a customizable alist: (condition . 'result)
7280 (cond
7281 ((symbolp result) result)
7282 ;; Now convert number into proper results:
7283 ((< result -10.0) 'mid)
7284 ((> result 10.0) 'mail)
7285 (t 'ask))))
7286
7287(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7288 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7289 (url-mid (concat "news" ":" mid-or-mail))
7290 (url-mailto (concat "mailto" ":" mid-or-mail)))
7291 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7292 (when (fboundp pref)
7293 (setq guessed
7294 ;; get rid of surrounding angles...
7295 (funcall pref
7296 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7297 (if (or (eq 'mid guessed) (eq 'mail guessed))
7298 (setq pref guessed)
7299 (setq pref 'ask)))
7300 (if (eq pref 'ask)
7301 (save-window-excursion
7302 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7303 (setq pref 'mail)
7304 (setq pref 'mid))))
7305 (cond ((eq pref 'mid)
7306 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7307 (gnus-button-handle-news url-mid))
7308 ((eq pref 'mail)
7309 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7310 (gnus-url-mailto url-mailto))
7311 (t (gnus-message 3 "Invalid string.")))))
7312
01c52d31
MB
7313(defun gnus-button-handle-custom (fun arg)
7314 "Call function FUN on argument ARG.
7315Both FUN and ARG are supposed to be strings. ARG will be passed
7316as a symbol to FUN."
7317 (funcall (intern fun)
7318 (if (string-match "^customize-apropos" fun)
7319 arg
7320 (intern arg))))
23f87bed
MB
7321
7322(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7323
7324;; FIXME: Maybe we should merge some of the functions that do quite similar
7325;; stuff?
7326
7327(defun gnus-button-handle-describe-function (url)
7328 "Call `describe-function' when pushing the corresponding URL button."
7329 (describe-function
7330 (intern
7331 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7332
7333(defun gnus-button-handle-describe-variable (url)
7334 "Call `describe-variable' when pushing the corresponding URL button."
7335 (describe-variable
7336 (intern
7337 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7338
7339(defun gnus-button-handle-symbol (url)
7340"Display help on variable or function.
7341Calls `describe-variable' or `describe-function'."
7342 (let ((sym (intern url)))
7343 (cond
7344 ((fboundp sym) (describe-function sym))
7345 ((boundp sym) (describe-variable sym))
7346 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7347
7348(defun gnus-button-handle-describe-key (url)
7349 "Call `describe-key' when pushing the corresponding URL button."
7350 (let* ((key-string
7351 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7352 (keys (ignore-errors (eval `(kbd ,key-string)))))
7353 (if keys
7354 (describe-key keys)
7355 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7356
7357(defun gnus-button-handle-apropos (url)
7358 "Call `apropos' when pushing the corresponding URL button."
7359 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7360
7361(defun gnus-button-handle-apropos-command (url)
7362 "Call `apropos' when pushing the corresponding URL button."
7363 (apropos-command
7364 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7365
7366(defun gnus-button-handle-apropos-variable (url)
7367 "Call `apropos' when pushing the corresponding URL button."
7368 (funcall
7369 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7370 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7371
7372(defun gnus-button-handle-apropos-documentation (url)
7373 "Call `apropos' when pushing the corresponding URL button."
7374 (funcall
7375 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7376 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7377
7378(defun gnus-button-handle-library (url)
7379 "Call `locate-library' when pushing the corresponding URL button."
7380 (gnus-message 9 "url=`%s'" url)
7381 (let* ((lib (locate-library url))
7382 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7383 (if (not lib)
7384 (gnus-message 1 "Cannot locale library `%s'." url)
7385 (find-file-read-only file))))
7386
7387(defun gnus-button-handle-ctan (url)
7388 "Call `browse-url' when pushing a CTAN URL button."
7389 (funcall
7390 gnus-button-ctan-handler
7391 (concat
7392 gnus-ctan-url
7393 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7394
7395(defcustom gnus-button-tex-level 5
7396 "*Integer that says how many TeX-related buttons Gnus will show.
7397The higher the number, the more buttons will appear and the more false
7398positives are possible. Note that you can set this variable local to
7399specific groups. Setting it higher in TeX groups is probably a good idea.
7400See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7401how to set variables in specific groups."
bf247b6e 7402 :version "22.1"
23f87bed
MB
7403 :group 'gnus-article-buttons
7404 :link '(custom-manual "(gnus)Group Parameters")
7405 :type 'integer)
7406
7407(defcustom gnus-button-man-level 5
7408 "*Integer that says how many man-related buttons Gnus will show.
7409The higher the number, the more buttons will appear and the more false
7410positives are possible. Note that you can set this variable local to
7411specific groups. Setting it higher in Unix groups is probably a good idea.
7412See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7413how to set variables in specific groups."
bf247b6e 7414 :version "22.1"
23f87bed
MB
7415 :group 'gnus-article-buttons
7416 :link '(custom-manual "(gnus)Group Parameters")
7417 :type 'integer)
7418
7419(defcustom gnus-button-emacs-level 5
7420 "*Integer that says how many emacs-related buttons Gnus will show.
7421The higher the number, the more buttons will appear and the more false
7422positives are possible. Note that you can set this variable local to
7423specific groups. Setting it higher in Emacs or Gnus related groups is
7424probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7425`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7426 :version "22.1"
23f87bed
MB
7427 :group 'gnus-article-buttons
7428 :link '(custom-manual "(gnus)Group Parameters")
7429 :type 'integer)
7430
7431(defcustom gnus-button-message-level 5
7432 "*Integer that says how many buttons for news or mail messages will appear.
7433The higher the number, the more buttons will appear and the more false
7434positives are possible."
7435 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7436 :version "22.1"
23f87bed
MB
7437 :group 'gnus-article-buttons
7438 :type 'integer)
7439
7440(defcustom gnus-button-browse-level 5
7441 "*Integer that says how many buttons for browsing will appear.
7442The higher the number, the more buttons will appear and the more false
7443positives are possible."
7444 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7445 :version "22.1"
23f87bed
MB
7446 :group 'gnus-article-buttons
7447 :type 'integer)
7448
eec82323 7449(defcustom gnus-button-alist
23f87bed
MB
7450 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7451 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7452 ((concat "\\b\\(nntp\\|news\\):\\("
7453 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7454 0 t gnus-button-handle-news 2)
23f87bed
MB
7455 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7456 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7457 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7458 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7459 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7460 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7461 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7462 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7463 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7464 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7465 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7466 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7467 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7468 ;; RFC 2368 (The mailto URL scheme)
531e5812 7469 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7470 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7471 ("\\bmailto:\\([^ \n\t]+\\)"
7472 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7473 ;; CTAN
7474 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7475 gnus-button-ctan-directory-regexp
7476 "[^][>)!;:,'\n\t ]+\\)")
7477 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7478 ((concat "\\btex-archive/\\("
7479 gnus-button-ctan-directory-regexp
7480 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7481 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7482 ((concat
7483 "\\b\\("
7484 gnus-button-ctan-directory-regexp
7485 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7486 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
9eb59592
MB
7487 ;; Info Konqueror style <info:/foo/bar baz>.
7488 ;; Must come before " Gnus home-grown style".
7489 ("\\binfo://?\\([^'\">\n\t]+\\)"
7490 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7491 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
23f87bed
MB
7492 ("\\binfo://\\([^'\">\n\t ]+\\)"
7493 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7494 ;; Info GNOME style <info:foo#bar_baz>
7495 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7496 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7497 ;; Info KDE style <info:(foo)bar baz>
7498 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7499 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7500 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7501 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
9b3ebcb6
MB
7502 ("\\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,]*\\)\\)?"
7503 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7504 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
23f87bed 7505 ;; This is custom
01c52d31
MB
7506 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7507 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed
MB
7508 ;; Emacs help commands
7509 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7510 ;; regexp doesn't match arguments containing ` '.
7511 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7512 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7513 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7514 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7515 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7516 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7517 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7518 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7519 ;; them by default (use a high button level).
7520 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7521 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7522 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7523 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7524 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7525 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7526 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7527 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7528 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7529 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7530 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7531 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7532 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7533 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7534 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7535 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7536 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7537 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7538 ;; Unlike the other regexps we really have to require quoting
7539 ;; here to determine where it ends.
7540 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7541 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7542 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7543 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7544 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7545 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7546 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7547 ;; Raw URLs.
23f87bed
MB
7548 (gnus-button-url-regexp
7549 0 (>= gnus-button-browse-level 0) browse-url 0)
7550 ;; man pages
531e5812 7551 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7552 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7553 gnus-button-handle-man 1)
7554 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7555 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7556 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7557 gnus-button-handle-man 1)
7558 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7559 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7560 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7561 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7562 ;; Recognizing patches to .el files. This is somewhat obscure,
7563 ;; but considering the percentage of Gnus users who hack Emacs
7564 ;; Lisp files...
7565 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7566 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7567 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7568 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7569 ;; MID or mail: To avoid too many false positives we don't try to catch
7570 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7571 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7572 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7573 ;; so that non-ambiguous entries (see above) match first.
7574 (gnus-button-mid-or-mail-regexp
7575 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7576 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7577
7578Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7579REGEXP: is the string (case insensitive) matching text around the button (can
7580also be Lisp expression evaluating to a string),
eec82323 7581BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7582FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7583be added,
7584CALLBACK: is the function to call when the user push this button, and each
7585PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7586
7587CALLBACK can also be a variable, in that case the value of that
7588variable it the real callback function."
7589 :group 'gnus-article-buttons
23f87bed 7590 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7591 (integer :tag "Button")
7592 (sexp :tag "Form")
7593 (function :tag "Callback")
7594 (repeat :tag "Par"
7595 :inline t
7596 (integer :tag "Regexp group")))))
60ece9b0 7597(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7598
7599(defcustom gnus-header-button-alist
23f87bed
MB
7600 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7601 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7602 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7603 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7604 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7605 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7606 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7607 0 (>= gnus-button-browse-level 0) browse-url 0)
7608 ("^Subject:" gnus-button-url-regexp
7609 0 (>= gnus-button-browse-level 0) browse-url 0)
7610 ("^[^:]+:" gnus-button-url-regexp
7611 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7612 ("^OpenPGP:.*url=" gnus-button-url-regexp
7613 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7614 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7615 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7616 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7617 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7618 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7619
7620This alist is very similar to `gnus-button-alist', except that each
7621alist has an additional HEADER element first in each entry:
7622
7623\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7624
7625HEADER is a regexp to match a header. For a fuller explanation, see
7626`gnus-button-alist'."
7627 :group 'gnus-article-buttons
7628 :group 'gnus-article-headers
7629 :type '(repeat (list (regexp :tag "Header")
23f87bed 7630 (choice regexp variable)
eec82323
LMI
7631 (integer :tag "Button")
7632 (sexp :tag "Form")
7633 (function :tag "Callback")
7634 (repeat :tag "Par"
7635 :inline t
7636 (integer :tag "Regexp group")))))
60ece9b0 7637(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7638
eec82323
LMI
7639;;; Commands:
7640
7641(defun gnus-article-push-button (event)
7642 "Check text under the mouse pointer for a callback function.
7643If the text under the mouse pointer has a `gnus-callback' property,
7644call it with the value of the `gnus-data' text property."
7645 (interactive "e")
7646 (set-buffer (window-buffer (posn-window (event-start event))))
7647 (let* ((pos (posn-point (event-start event)))
23f87bed 7648 (data (get-text-property pos 'gnus-data))
eec82323 7649 (fun (get-text-property pos 'gnus-callback)))
6748645f 7650 (goto-char pos)
eec82323
LMI
7651 (when fun
7652 (funcall fun data))))
7653
7654(defun gnus-article-press-button ()
7655 "Check text at point for a callback function.
7656If the text at point has a `gnus-callback' property,
7657call it with the value of the `gnus-data' text property."
7658 (interactive)
23f87bed
MB
7659 (let ((data (get-text-property (point) 'gnus-data))
7660 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7661 (when fun
7662 (funcall fun data))))
7663
eec82323
LMI
7664(defun gnus-article-highlight (&optional force)
7665 "Highlight current article.
7666This function calls `gnus-article-highlight-headers',
7667`gnus-article-highlight-citation',
7668`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7669do the highlighting. See the documentation for those functions."
7670 (interactive (list 'force))
7671 (gnus-article-highlight-headers)
7672 (gnus-article-highlight-citation force)
7673 (gnus-article-highlight-signature)
7674 (gnus-article-add-buttons force)
7675 (gnus-article-add-buttons-to-head))
7676
7677(defun gnus-article-highlight-some (&optional force)
7678 "Highlight current article.
7679This function calls `gnus-article-highlight-headers',
7680`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7681do the highlighting. See the documentation for those functions."
7682 (interactive (list 'force))
7683 (gnus-article-highlight-headers)
7684 (gnus-article-highlight-signature)
7685 (gnus-article-add-buttons))
7686
7687(defun gnus-article-highlight-headers ()
7688 "Highlight article headers as specified by `gnus-header-face-alist'."
7689 (interactive)
01c52d31
MB
7690 (gnus-with-article-headers
7691 (let (regexp header-face field-face from hpoints fpoints)
7692 (dolist (entry gnus-header-face-alist)
7693 (goto-char (point-min))
7694 (setq regexp (concat "^\\("
7695 (if (string-equal "" (nth 0 entry))
7696 "[^\t ]"
7697 (nth 0 entry))
7698 "\\)")
7699 header-face (nth 1 entry)
7700 field-face (nth 2 entry))
7701 (while (and (re-search-forward regexp nil t)
7702 (not (eobp)))
7703 (beginning-of-line)
7704 (setq from (point))
7705 (unless (search-forward ":" nil t)
7706 (forward-char 1))
7707 (when (and header-face
7708 (not (memq (point) hpoints)))
7709 (push (point) hpoints)
7710 (gnus-put-text-property from (point) 'face header-face))
7711 (when (and field-face
7712 (not (memq (setq from (point)) fpoints)))
7713 (push from fpoints)
7714 (if (re-search-forward "^[^ \t]" nil t)
7715 (forward-char -2)
7716 (goto-char (point-max)))
7717 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7718
7719(defun gnus-article-highlight-signature ()
7720 "Highlight the signature in an article.
7721It does this by highlighting everything after
0f49874b 7722`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7723 (interactive)
01c52d31
MB
7724 (gnus-with-article-buffer
7725 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7726 (save-restriction
7727 (when (and gnus-signature-face
7728 (gnus-article-narrow-to-signature))
01c52d31 7729 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7730 'face gnus-signature-face)
7731 (widen)
7732 (gnus-article-search-signature)
7733 (let ((start (match-beginning 0))
7734 (end (set-marker (make-marker) (1+ (match-end 0)))))
7735 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7736 end)))))))
7737
7738(defun gnus-button-in-region-p (b e prop)
7739 "Say whether PROP exists in the region."
7740 (text-property-not-all b e prop nil))
7741
7742(defun gnus-article-add-buttons (&optional force)
7743 "Find external references in the article and make buttons of them.
7744\"External references\" are things like Message-IDs and URLs, as
7745specified by `gnus-button-alist'."
7746 (interactive (list 'force))
01c52d31
MB
7747 (gnus-with-article-buffer
7748 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7749 (case-fold-search t)
7750 (alist gnus-button-alist)
7751 beg entry regexp)
7752 ;; Remove all old markers.
16409b0b 7753 (let (marker entry new-list)
eec82323 7754 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
7755 (if (or (< marker (point-min)) (>= marker (point-max)))
7756 (push marker new-list)
7757 (goto-char marker)
7758 (when (setq entry (gnus-button-entry))
7759 (put-text-property (match-beginning (nth 1 entry))
7760 (match-end (nth 1 entry))
7761 'gnus-callback nil))
7762 (set-marker marker nil)))
7763 (setq gnus-button-marker-list new-list))
eec82323 7764 ;; We skip the headers.
16409b0b 7765 (article-goto-body)
eec82323
LMI
7766 (setq beg (point))
7767 (while (setq entry (pop alist))
23f87bed 7768 (setq regexp (eval (car entry)))
eec82323
LMI
7769 (goto-char beg)
7770 (while (re-search-forward regexp nil t)
01c52d31
MB
7771 (let ((start (match-beginning (nth 1 entry)))
7772 (end (match-end (nth 1 entry)))
7773 (from (match-beginning 0)))
eec82323
LMI
7774 (when (and (or (eq t (nth 2 entry))
7775 (eval (nth 2 entry)))
7776 (not (gnus-button-in-region-p
7777 start end 'gnus-callback)))
7778 ;; That optional form returned non-nil, so we add the
7779 ;; button.
01c52d31
MB
7780 (setq from (set-marker (make-marker) from))
7781 (push from gnus-button-marker-list)
7782 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7783 (gnus-article-extend-url-button from start end))
7784 (gnus-article-add-button start end
7785 'gnus-button-push from)))))))))
7786
7787(defun gnus-article-extend-url-button (beg start end)
7788 "Extend url button if url is folded into two or more lines.
7789Return non-nil if button is extended. BEG is a marker that points to
7790the beginning position of a text containing url. START and END are
7791the endpoints of a url button before it is extended. The concatenated
7792url is put as the `gnus-button-url' overlay property on the button."
7793 (let ((opoint (point))
7794 (points (list start end))
7795 url delim regexp)
7796 (prog1
7797 (when (and (progn
7798 (goto-char end)
7799 (not (looking-at "[\t ]*[\">]")))
7800 (progn
7801 (goto-char start)
7802 (string-match
7803 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7804 (buffer-substring (point-at-bol) start)))
7805 (progn
7806 (setq url (list (buffer-substring start end))
7807 delim (if (match-beginning 1) ">" "\""))
7808 (beginning-of-line)
7809 (setq regexp (concat
7810 (when (and (looking-at
7811 message-cite-prefix-regexp)
7812 (< (match-end 0) start))
7813 (regexp-quote (match-string 0)))
7814 "\
7815\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7816 delim "\\)"))
7817 (while (progn
7818 (forward-line 1)
7819 (and (looking-at regexp)
7820 (prog1
7821 (match-beginning 1)
7822 (push (or (match-string 2)
7823 (match-string 1))
7824 url)
7825 (push (setq end (or (match-end 2)
7826 (match-end 1)))
7827 points)
7828 (push (or (match-beginning 2)
7829 (match-beginning 1))
7830 points)))))
7831 (match-beginning 2)))
7832 (let (gnus-article-mouse-face widget-mouse-face)
7833 (while points
7834 (gnus-article-add-button (pop points) (pop points)
7835 'gnus-button-push beg)))
7836 (let ((overlay (gnus-make-overlay start end)))
7837 (gnus-overlay-put overlay 'evaporate t)
7838 (gnus-overlay-put overlay 'gnus-button-url
7839 (list (mapconcat 'identity (nreverse url) "")))
7840 (when gnus-article-mouse-face
7841 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7842 t)
7843 (goto-char opoint))))
eec82323
LMI
7844
7845;; Add buttons to the head of an article.
7846(defun gnus-article-add-buttons-to-head ()
7847 "Add buttons to the head of the article."
7848 (interactive)
01c52d31
MB
7849 (gnus-with-article-headers
7850 (let (beg end)
7851 (dolist (entry gnus-header-button-alist)
7852 ;; Each alist entry.
7853 (goto-char (point-min))
7854 (while (re-search-forward (car entry) nil t)
7855 ;; Each header matching the entry.
7856 (setq beg (match-beginning 0))
7857 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7858 (match-beginning 0))
7859 (point-max)))
7860 (goto-char beg)
7861 (while (re-search-forward (eval (nth 1 entry)) end t)
7862 ;; Each match within a header.
7863 (let* ((entry (cdr entry))
7864 (start (match-beginning (nth 1 entry)))
7865 (end (match-end (nth 1 entry)))
7866 (form (nth 2 entry)))
7867 (goto-char (match-end 0))
7868 (when (eval form)
7869 (gnus-article-add-button
7870 start end (nth 3 entry)
7871 (buffer-substring (match-beginning (nth 4 entry))
7872 (match-end (nth 4 entry)))))))
7873 (goto-char end))))))
eec82323
LMI
7874
7875;;; External functions:
7876
7877(defun gnus-article-add-button (from to fun &optional data)
7878 "Create a button between FROM and TO with callback FUN and data DATA."
7879 (when gnus-article-button-face
01c52d31 7880 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7881 'face gnus-article-button-face))
7882 (gnus-add-text-properties
7883 from to
7884 (nconc (and gnus-article-mouse-face
7885 (list gnus-mouse-face-prop gnus-article-mouse-face))
7886 (list 'gnus-callback fun)
16409b0b
GM
7887 (and data (list 'gnus-data data))))
7888 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7889 :button-keymap gnus-widget-button-keymap))
eec82323
LMI
7890
7891;;; Internal functions:
7892
a8151ef7 7893(defun gnus-article-set-globals ()
01c52d31 7894 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7895 (gnus-set-global-variables)))
7896
eec82323 7897(defun gnus-signature-toggle (end)
01c52d31
MB
7898 (gnus-with-article-buffer
7899 (let ((inhibit-point-motion-hooks t))
520aa572 7900 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7901 (progn
7902 (gnus-delete-wash-type 'signature)
7903 (gnus-remove-text-properties-when
7904 'article-type 'signature end (point-max)
7905 (cons 'article-type (cons 'signature
7906 gnus-hidden-properties))))
7907 (gnus-add-wash-type 'signature)
520aa572
SZ
7908 (gnus-add-text-properties-when
7909 'article-type nil end (point-max)
7910 (cons 'article-type (cons 'signature
23f87bed
MB
7911 gnus-hidden-properties)))))
7912 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7913 (gnus-set-mode-line 'article))))
eec82323
LMI
7914
7915(defun gnus-button-entry ()
7916 ;; Return the first entry in `gnus-button-alist' matching this place.
7917 (let ((alist gnus-button-alist)
7918 (entry nil))
7919 (while alist
7920 (setq entry (pop alist))
23f87bed 7921 (if (looking-at (eval (car entry)))
eec82323
LMI
7922 (setq alist nil)
7923 (setq entry nil)))
7924 entry))
7925
7926(defun gnus-button-push (marker)
7927 ;; Push button starting at MARKER.
7928 (save-excursion
eec82323
LMI
7929 (goto-char marker)
7930 (let* ((entry (gnus-button-entry))
7931 (inhibit-point-motion-hooks t)
7932 (fun (nth 3 entry))
01c52d31
MB
7933 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7934 (get-char-property marker 'gnus-button-url))
7935 (mapcar (lambda (group)
7936 (let ((string (match-string group)))
7937 (set-text-properties
7938 0 (length string) nil string)
7939 string))
7940 (nthcdr 4 entry)))))
eec82323
LMI
7941 (cond
7942 ((fboundp fun)
7943 (apply fun args))
7944 ((and (boundp fun)
7945 (fboundp (symbol-value fun)))
7946 (apply (symbol-value fun) args))
7947 (t
7948 (gnus-message 1 "You must define `%S' to use this button"
7949 (cons fun args)))))))
7950
23f87bed 7951(defun gnus-parse-news-url (url)
82a8ad04 7952 (let (scheme server port group message-id articles)
23f87bed
MB
7953 (with-temp-buffer
7954 (insert url)
7955 (goto-char (point-min))
7956 (when (looking-at "\\([A-Za-z]+\\):")
7957 (setq scheme (match-string 1))
7958 (goto-char (match-end 0)))
82a8ad04 7959 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7960 (setq server (match-string 1))
82a8ad04
MB
7961 (setq port (if (stringp (match-string 3))
7962 (string-to-number (match-string 3))
7963 (match-string 3)))
23f87bed
MB
7964 (goto-char (match-end 0)))
7965
7966 (cond
7967 ((looking-at "\\(.*@.*\\)")
7968 (setq message-id (match-string 1)))
7969 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7970 (setq group (match-string 1)
7971 articles (split-string (match-string 2) "-")))
7972 ((looking-at "\\([^/]+\\)/?")
7973 (setq group (match-string 1)))
7974 (t
7975 (error "Unknown news URL syntax"))))
82a8ad04 7976 (list scheme server port group message-id articles)))
23f87bed
MB
7977
7978(defun gnus-button-handle-news (url)
7979 "Fetch a news URL."
82a8ad04 7980 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7981 (gnus-parse-news-url url)
7982 (cond
7983 (message-id
80de1778 7984 (with-current-buffer gnus-summary-buffer
23f87bed 7985 (if server
ff4d3926
MB
7986 (let ((gnus-refer-article-method
7987 (nconc (list (list 'nntp server))
7988 gnus-refer-article-method))
82a8ad04 7989 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7990 (gnus-message 7 "Fetching %s with %s"
7991 message-id gnus-refer-article-method)
23f87bed
MB
7992 (gnus-summary-refer-article message-id))
7993 (gnus-summary-refer-article message-id))))
7994 (group
7995 (gnus-button-fetch-group url)))))
7996
01c52d31
MB
7997(defun gnus-button-patch (library line)
7998 "Visit an Emacs Lisp library LIBRARY on line LINE."
7999 (interactive)
8000 (let ((file (locate-library (file-name-nondirectory library))))
8001 (unless file
8002 (error "Couldn't find library %s" library))
8003 (find-file file)
5dcc825f
GM
8004 (goto-char (point-min))
8005 (forward-line (1- (string-to-number line)))))
01c52d31 8006
23f87bed
MB
8007(defun gnus-button-handle-man (url)
8008 "Fetch a man page."
531e5812
MB
8009 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8010 (when (eq gnus-button-man-handler 'woman)
8011 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8012 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
8013 (funcall gnus-button-man-handler url))
8014
8015(defun gnus-button-handle-info-url (url)
8016 "Fetch an info URL."
8017 (setq url (mm-subst-char-in-string ?+ ?\ url))
8018 (cond
8019 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8020 (gnus-info-find-node
8021 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8022 "Gnus")
8023 ")" (gnus-url-unhex-string (match-string 2 url)))))
8024 ((string-match "([^)\"]+)[^\"]+" url)
8025 (setq url
8026 (gnus-replace-in-string
8027 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8028 (gnus-info-find-node url))
8029 (t (error "Can't parse %s" url))))
8030
8031(defun gnus-button-handle-info-url-gnome (url)
8032 "Fetch GNOME style info URL."
8033 (setq url (mm-subst-char-in-string ?_ ?\ url))
8034 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8035 (gnus-info-find-node
8036 (concat "("
bf247b6e 8037 (gnus-url-unhex-string
23f87bed
MB
8038 (match-string 1 url))
8039 ")"
bf247b6e 8040 (or (gnus-url-unhex-string
23f87bed
MB
8041 (match-string 2 url))
8042 "Top")))
8043 (error "Can't parse %s" url)))
8044
8045(defun gnus-button-handle-info-url-kde (url)
8046 "Fetch KDE style info URL."
8047 (gnus-info-find-node (gnus-url-unhex-string url)))
8048
9640c3bc
GM
8049;; (info) will autoload info.el
8050(declare-function Info-menu "info" (menu-item &optional fork))
9b3ebcb6 8051(declare-function Info-index-next "info" (num))
9640c3bc 8052
23f87bed
MB
8053(defun gnus-button-handle-info-keystrokes (url)
8054 "Call `info' when pushing the corresponding URL button."
9b3ebcb6
MB
8055 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8056 (let (node indx comma)
8057 (if (string-match
8058 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8059 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8060 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
8061 "\\(?:[ \t\n,]*\\)\\)?")
8062 url)
8063 (setq node (match-string 2 url)
8064 indx (match-string 3 url))
8065 (error "Can't parse %s" url))
8066 (info)
8067 (Info-directory)
8068 (Info-menu node)
8069 (when (> (length indx) 0)
8070 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8071 "\\([ \t\n,]*\\)")
8072 indx)
8073 (setq comma (match-string 2 indx))
8074 (setq indx (match-string 1 indx))
8075 (Info-index indx)
8076 (when comma
8077 (dotimes (i (with-temp-buffer
8078 (insert comma)
8079 ;; Note: the XEmacs version of `how-many' takes
8080 ;; no optional argument.
8081 (goto-char (point-min))
8082 (how-many ",")))
8083 (Info-index-next 1)))
8084 nil)))
1888e568
GM
8085
8086;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8087(declare-function pgg-display-output-buffer "pgg" (start end status))
23f87bed 8088
01c52d31
MB
8089(defun gnus-button-openpgp (url)
8090 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8091 (with-temp-buffer
8092 (mm-url-insert-file-contents-external url)
8093 (pgg-snarf-keys-region (point-min) (point-max))
8094 (pgg-display-output-buffer nil nil nil)))
8095
eec82323
LMI
8096(defun gnus-button-message-id (message-id)
8097 "Fetch MESSAGE-ID."
01c52d31 8098 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8099 (gnus-summary-refer-article message-id)))
8100
01c52d31 8101(defun gnus-button-fetch-group (address &rest ignore)
eec82323 8102 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
8103 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8104 address)
8105 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8106 ;; for nntp:// and news://
8107 (setq address (match-string 3 address)))
eec82323
LMI
8108 (if (not (string-match "[:/]" address))
8109 ;; This is just a simple group url.
8110 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
8111 (if (not
8112 (string-match
8113 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8114 address))
eec82323
LMI
8115 (error "Can't parse %s" address)
8116 (gnus-group-read-ephemeral-group
8117 (match-string 4 address)
8118 `(nntp ,(match-string 1 address)
8119 (nntp-address ,(match-string 1 address))
8120 (nntp-port-number ,(if (match-end 3)
8121 (match-string 3 address)
23f87bed
MB
8122 "nntp")))
8123 nil nil nil
e9bd5782 8124 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 8125
eec82323
LMI
8126(defun gnus-url-parse-query-string (query &optional downcase)
8127 (let (retval pairs cur key val)
16409b0b 8128 (setq pairs (split-string query "&"))
eec82323
LMI
8129 (while pairs
8130 (setq cur (car pairs)
23f87bed 8131 pairs (cdr pairs))
eec82323 8132 (if (not (string-match "=" cur))
23f87bed
MB
8133 nil ; Grace
8134 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8135 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8136 (if downcase
8137 (setq key (downcase key)))
8138 (setq cur (assoc key retval))
8139 (if cur
8140 (setcdr cur (cons val (cdr cur)))
8141 (setq retval (cons (list key val) retval)))))
eec82323
LMI
8142 retval))
8143
eec82323
LMI
8144(defun gnus-url-mailto (url)
8145 ;; Send mail to someone
8146 (when (string-match "mailto:/*\\(.*\\)" url)
8147 (setq url (substring url (match-beginning 1) nil)))
6748645f 8148 (let (to args subject func)
23f87bed
MB
8149 (setq args (gnus-url-parse-query-string
8150 (if (string-match "^\\?" url)
8151 (substring url 1)
8152 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8153 (concat "to=" (match-string 1 url) "&"
8154 (match-string 2 url))
8155 (concat "to=" url)))
8156 t)
8157 subject (cdr-safe (assoc "subject" args)))
8158 (gnus-msg-mail)
eec82323
LMI
8159 (while args
8160 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8161 (if (fboundp func)
23f87bed
MB
8162 (funcall func)
8163 (message-position-on-field (caar args)))
8164 (insert (gnus-replace-in-string
8165 (mapconcat 'identity (reverse (cdar args)) ", ")
8166 "\r\n" "\n" t))
eec82323
LMI
8167 (setq args (cdr args)))
8168 (if subject
23f87bed 8169 (message-goto-body)
eec82323
LMI
8170 (message-goto-subject))))
8171
eec82323 8172(defun gnus-button-embedded-url (address)
e0bad764 8173 "Activate ADDRESS with `browse-url'."
1b978bfc 8174 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
8175
8176;;; Next/prev buttons in the article buffer.
8177
8178(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8179(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8180
23f87bed
MB
8181(defvar gnus-prev-page-map
8182 (let ((map (make-sparse-keymap)))
23f87bed
MB
8183 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8184 (define-key map "\r" 'gnus-button-prev-page)
8185 map))
8186
8187(defvar gnus-next-page-map
8188 (let ((map (make-sparse-keymap)))
8189 (unless (>= emacs-major-version 21)
8190 ;; XEmacs doesn't care.
8191 (set-keymap-parent map gnus-article-mode-map))
8192 (define-key map gnus-mouse-2 'gnus-button-next-page)
8193 (define-key map "\r" 'gnus-button-next-page)
8194 map))
eec82323
LMI
8195
8196(defun gnus-insert-prev-page-button ()
01c52d31 8197 (let ((b (point)) e
23f87bed 8198 (inhibit-read-only t))
eec82323
LMI
8199 (gnus-eval-format
8200 gnus-prev-page-line-format nil
01c52d31
MB
8201 `(keymap ,gnus-prev-page-map
8202 gnus-prev t
8203 gnus-callback gnus-article-button-prev-page
8204 article-type annotation))
8205 (setq e (if (bolp)
8206 ;; Exclude a newline.
8207 (1- (point))
8208 (point)))
8209 (when gnus-article-button-face
8210 (gnus-overlay-put (gnus-make-overlay b e nil t)
8211 'face gnus-article-button-face))
23f87bed 8212 (widget-convert-button
01c52d31 8213 'link b e
23f87bed
MB
8214 :action 'gnus-button-prev-page
8215 :button-keymap gnus-prev-page-map)))
8216
8217(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8218 "Go to the next page."
8219 (interactive)
8220 (let ((win (selected-window)))
23f87bed 8221 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8222 (gnus-article-next-page)
8223 (select-window win)))
8224
23f87bed 8225(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8226 "Go to the prev page."
8227 (interactive)
8228 (let ((win (selected-window)))
23f87bed 8229 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8230 (gnus-article-prev-page)
8231 (select-window win)))
8232
8233(defun gnus-insert-next-page-button ()
01c52d31 8234 (let ((b (point)) e
23f87bed 8235 (inhibit-read-only t))
eec82323 8236 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8237 `(keymap ,gnus-next-page-map
8238 gnus-next t
8239 gnus-callback gnus-article-button-next-page
8240 article-type annotation))
8241 (setq e (if (bolp)
8242 ;; Exclude a newline.
8243 (1- (point))
8244 (point)))
8245 (when gnus-article-button-face
8246 (gnus-overlay-put (gnus-make-overlay b e nil t)
8247 'face gnus-article-button-face))
23f87bed 8248 (widget-convert-button
01c52d31 8249 'link b e
23f87bed
MB
8250 :action 'gnus-button-next-page
8251 :button-keymap gnus-next-page-map)))
eec82323
LMI
8252
8253(defun gnus-article-button-next-page (arg)
8254 "Go to the next page."
8255 (interactive "P")
8256 (let ((win (selected-window)))
23f87bed 8257 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8258 (gnus-article-next-page)
8259 (select-window win)))
8260
8261(defun gnus-article-button-prev-page (arg)
8262 "Go to the prev page."
8263 (interactive "P")
8264 (let ((win (selected-window)))
23f87bed 8265 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8266 (gnus-article-prev-page)
8267 (select-window win)))
8268
16409b0b
GM
8269(defvar gnus-decode-header-methods
8270 '(mail-decode-encoded-word-region)
8271 "List of methods used to decode headers.
8272
8273This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8274is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8275\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8276whose names match REGEXP.
8277
8278For example:
8f688cb0 8279\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8280 mail-decode-encoded-word-region
8281 (\"chinese\" . rfc1843-decode-region))
8282")
8283
8284(defvar gnus-decode-header-methods-cache nil)
8285
8286(defun gnus-multi-decode-header (start end)
8287 "Apply the functions from `gnus-encoded-word-methods' that match."
8288 (unless (and gnus-decode-header-methods-cache
8289 (eq gnus-newsgroup-name
8290 (car gnus-decode-header-methods-cache)))
8291 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8292 (dolist (x gnus-decode-header-methods)
8293 (if (symbolp x)
8294 (nconc gnus-decode-header-methods-cache (list x))
8295 (if (and gnus-newsgroup-name
8296 (string-match (car x) gnus-newsgroup-name))
8297 (nconc gnus-decode-header-methods-cache
8298 (list (cdr x)))))))
16409b0b
GM
8299 (let ((xlist gnus-decode-header-methods-cache))
8300 (pop xlist)
8301 (save-restriction
8302 (narrow-to-region start end)
8303 (while xlist
8304 (funcall (pop xlist) (point-min) (point-max))))))
8305
8306;;;
8307;;; Treatment top-level handling.
8308;;;
8309
8310(defun gnus-treat-article (condition &optional part-number total-parts type)
8311 (let ((length (- (point-max) (point-min)))
8312 (alist gnus-treatment-function-alist)
8313 (article-goto-body-goes-to-point-min-p t)
8314 (treated-type
8315 (or (not type)
8316 (catch 'found
8317 (let ((list gnus-article-treat-types))
8318 (while list
8319 (when (string-match (pop list) type)
8320 (throw 'found t)))))))
8321 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8322 val elem)
8323 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8324 (dolist (elem alist)
16409b0b
GM
8325 (setq val
8326 (save-excursion
23f87bed
MB
8327 (when (gnus-buffer-live-p gnus-summary-buffer)
8328 (set-buffer gnus-summary-buffer))
16409b0b
GM
8329 (symbol-value (car elem))))
8330 (when (and (or (consp val)
8331 treated-type)
8332 (gnus-treat-predicate val)
8333 (or (not (get (car elem) 'highlight))
8334 highlightp))
8335 (save-restriction
8336 (funcall (cadr elem)))))))
8337
8338;; Dynamic variables.
9efa445f
DN
8339(defvar part-number)
8340(defvar total-parts)
8341(defvar type)
8342(defvar condition)
8343(defvar length)
e0bad764 8344
16409b0b
GM
8345(defun gnus-treat-predicate (val)
8346 (cond
8347 ((null val)
8348 nil)
23f87bed
MB
8349 (condition
8350 (eq condition val))
16409b0b
GM
8351 ((and (listp val)
8352 (stringp (car val)))
8353 (apply 'gnus-or (mapcar `(lambda (s)
8354 (string-match s ,(or gnus-newsgroup-name "")))
8355 val)))
8356 ((listp val)
8357 (let ((pred (pop val)))
8358 (cond
8359 ((eq pred 'or)
8360 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8361 ((eq pred 'and)
8362 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8363 ((eq pred 'not)
8364 (not (gnus-treat-predicate (car val))))
8365 ((eq pred 'typep)
8366 (equal (car val) type))
8367 (t
8368 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8369 ((eq val t)
8370 t)
8371 ((eq val 'head)
8372 nil)
01c52d31
MB
8373 ((eq val 'first)
8374 (eq part-number 1))
16409b0b
GM
8375 ((eq val 'last)
8376 (eq part-number total-parts))
8377 ((numberp val)
8378 (< length val))
8379 (t
8380 (error "%S is not a valid value" val))))
8381
23f87bed
MB
8382(defun gnus-article-encrypt-body (protocol &optional n)
8383 "Encrypt the article body."
8384 (interactive
8385 (list
8386 (or gnus-article-encrypt-protocol
8387 (completing-read "Encrypt protocol: "
8388 gnus-article-encrypt-protocol-alist
8389 nil t))
8390 current-prefix-arg))
bbbe940b
MB
8391 ;; User might hit `K E' instead of `K e', so prompt once.
8392 (when (and gnus-article-encrypt-protocol
8393 gnus-novice-user)
8394 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
d93ec753 8395 (error "Encrypt aborted")))
23f87bed
MB
8396 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8397 (unless func
998a5a95 8398 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8399 (if (member gnus-newsgroup-name '("nndraft:delayed"
8400 "nndraft:drafts"
8401 "nndraft:queue"))
8402 (error "Can't encrypt the article in group %s"
8403 gnus-newsgroup-name))
8404 (gnus-summary-iterate n
80de1778 8405 (with-current-buffer gnus-summary-buffer
23f87bed
MB
8406 (let ((mail-parse-charset gnus-newsgroup-charset)
8407 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8408 (summary-buffer gnus-summary-buffer)
8409 references point)
8410 (gnus-set-global-variables)
8411 (when (gnus-group-read-only-p)
8412 (error "The current newsgroup does not support article encrypt"))
8413 (gnus-summary-show-article t)
8414 (setq references
8415 (or (mail-header-references gnus-current-headers) ""))
8416 (set-buffer gnus-article-buffer)
8417 (let* ((inhibit-read-only t)
8418 (headers
8419 (mapcar (lambda (field)
8420 (and (save-restriction
8421 (message-narrow-to-head)
8422 (goto-char (point-min))
8423 (search-forward field nil t))
8424 (prog2
8425 (message-narrow-to-field)
8426 (buffer-string)
8427 (delete-region (point-min) (point-max))
8428 (widen))))
8429 '("Content-Type:" "Content-Transfer-Encoding:"
8430 "Content-Disposition:"))))
8431 (message-narrow-to-head)
8432 (message-remove-header "MIME-Version")
8433 (goto-char (point-max))
8434 (setq point (point))
8435 (insert (apply 'concat headers))
8436 (widen)
8437 (narrow-to-region point (point-max))
8438 (let ((message-options message-options))
8439 (message-options-set 'message-sender user-mail-address)
8440 (message-options-set 'message-recipients user-mail-address)
8441 (message-options-set 'message-sign-encrypt 'not)
8442 (funcall func))
8443 (goto-char (point-min))
8444 (insert "MIME-Version: 1.0\n")
8445 (widen)
8446 (gnus-summary-edit-article-done
8447 references nil summary-buffer t))
8448 (when gnus-keep-backlog
8449 (gnus-backlog-remove-article
8450 (car gnus-article-current) (cdr gnus-article-current)))
80de1778
SM
8451 (when (get-buffer gnus-original-article-buffer)
8452 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
8453 (setq gnus-original-article nil)))
8454 (when gnus-use-cache
8455 (gnus-cache-update-article
8456 (car gnus-article-current) (cdr gnus-article-current))))))))
8457
8458(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8459 "The following specs can be used:
8460%t The security MIME type
8461%i Additional info
8462%d Details
8463%D Details if button is pressed")
8464
8465(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8466 "The following specs can be used:
8467%t The security MIME type
8468%i Additional info
8469%d Details
8470%D Details if button is pressed")
8471
8472(defvar gnus-mime-security-button-line-format-alist
8473 '((?t gnus-tmp-type ?s)
8474 (?i gnus-tmp-info ?s)
8475 (?d gnus-tmp-details ?s)
8476 (?D gnus-tmp-pressed-details ?s)))
8477
01c52d31
MB
8478(defvar gnus-mime-security-button-commands
8479 '((gnus-article-press-button "\r" "Show Detail")
8480 (undefined "v")
8481 (undefined "t")
8482 (undefined "C")
8483 (gnus-mime-security-save-part "o" "Save...")
8484 (undefined "\C-o")
8485 (undefined "r")
8486 (undefined "d")
8487 (undefined "c")
8488 (undefined "i")
8489 (undefined "E")
8490 (undefined "e")
8491 (undefined "p")
8492 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8493 (undefined ".")))
8494
23f87bed
MB
8495(defvar gnus-mime-security-button-map
8496 (let ((map (make-sparse-keymap)))
23f87bed 8497 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8498 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8499 (dolist (c gnus-mime-security-button-commands)
8500 (define-key map (cadr c) (car c)))
23f87bed
MB
8501 map))
8502
01c52d31
MB
8503(easy-menu-define
8504 gnus-mime-security-button-menu gnus-mime-security-button-map
8505 "Security button menu."
8506 `("Security Part"
8507 ,@(delq nil
8508 (mapcar (lambda (c)
8509 (unless (eq (car c) 'undefined)
8510 (vector (caddr c) (car c) :active t)))
8511 gnus-mime-security-button-commands))))
8512
8513(defun gnus-mime-security-button-menu (event prefix)
8514 "Construct a context-sensitive menu of security commands."
8515 (interactive "e\nP")
8516 (save-window-excursion
8517 (let ((pos (event-start event)))
8518 (select-window (posn-window pos))
8519 (goto-char (posn-point pos))
8520 (gnus-article-check-buffer)
8521 (popup-menu gnus-mime-security-button-menu nil prefix))))
8522
23f87bed
MB
8523(defvar gnus-mime-security-details-buffer nil)
8524
8525(defvar gnus-mime-security-button-pressed nil)
8526
8527(defvar gnus-mime-security-show-details-inline t
8528 "If non-nil, show details in the article buffer.")
8529
8530(defun gnus-mime-security-verify-or-decrypt (handle)
8531 (mm-remove-parts (cdr handle))
8532 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8533 point (inhibit-read-only t))
8534 (if region
8535 (goto-char (car region)))
01c52d31
MB
8536 (setq point (point))
8537 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8538 (let* ((mm-verify-option 'known)
8539 (mm-decrypt-option 'known)
8540 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8541 (unless (eq nparts (cdr handle))
8542 (mm-destroy-parts (cdr handle))
8543 (setcdr handle nparts))))
8544 (gnus-mime-display-security handle)
23f87bed
MB
8545 (when region
8546 (delete-region (point) (cdr region))
8547 (set-marker (car region) nil)
8548 (set-marker (cdr region) nil))
8549 (goto-char point)))
8550
8551(defun gnus-mime-security-show-details (handle)
8552 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8553 (if (not details)
8554 (gnus-message 5 "No details.")
8555 (if gnus-mime-security-show-details-inline
8556 (let ((gnus-mime-security-button-pressed
8557 (not (get-text-property (point) 'gnus-mime-details)))
8558 (gnus-mime-security-button-line-format
8559 (get-text-property (point) 'gnus-line-format))
8560 (inhibit-read-only t))
8561 (forward-char -1)
8562 (while (eq (get-text-property (point) 'gnus-line-format)
8563 gnus-mime-security-button-line-format)
8564 (forward-char -1))
8565 (forward-char)
8566 (save-restriction
8567 (narrow-to-region (point) (point))
8568 (gnus-insert-mime-security-button handle))
8569 (delete-region (point)
8570 (or (text-property-not-all
8571 (point) (point-max)
8572 'gnus-line-format
8573 gnus-mime-security-button-line-format)
8574 (point-max))))
8575 ;; Not inlined.
8576 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8577 (with-current-buffer gnus-mime-security-details-buffer
8578 (erase-buffer)
8579 t)
8580 (setq gnus-mime-security-details-buffer
8581 (gnus-get-buffer-create "*MIME Security Details*")))
8582 (with-current-buffer gnus-mime-security-details-buffer
8583 (insert details)
8584 (goto-char (point-min)))
8585 (pop-to-buffer gnus-mime-security-details-buffer)))))
8586
8587(defun gnus-mime-security-press-button (handle)
8588 (save-excursion
8589 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8590 (gnus-mime-security-show-details handle)
8591 (gnus-mime-security-verify-or-decrypt handle))))
8592
8593(defun gnus-insert-mime-security-button (handle &optional displayed)
8594 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8595 (gnus-tmp-type
8596 (concat
8597 (or (nth 2 (assoc protocol mm-verify-function-alist))
8598 (nth 2 (assoc protocol mm-decrypt-function-alist))
8599 "Unknown")
8600 (if (equal (car handle) "multipart/signed")
8601 " Signed" " Encrypted")
8602 " Part"))
8603 (gnus-tmp-info
8604 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8605 "Undecided"))
8606 (gnus-tmp-details
8607 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8608 gnus-tmp-pressed-details
8609 b e)
8610 (setq gnus-tmp-details
8611 (if gnus-tmp-details
8612 (concat "\n" gnus-tmp-details)
8613 ""))
8614 (setq gnus-tmp-pressed-details
8615 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8616 (unless (bolp)
8617 (insert "\n"))
8618 (setq b (point))
8619 (gnus-eval-format
8620 gnus-mime-security-button-line-format
8621 gnus-mime-security-button-line-format-alist
01c52d31 8622 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8623 gnus-callback gnus-mime-security-press-button
8624 gnus-line-format ,gnus-mime-security-button-line-format
8625 gnus-mime-details ,gnus-mime-security-button-pressed
8626 article-type annotation
8627 gnus-data ,handle))
8628 (setq e (if (bolp)
8629 ;; Exclude a newline.
8630 (1- (point))
8631 (point)))
01c52d31
MB
8632 (when gnus-article-button-face
8633 (gnus-overlay-put (gnus-make-overlay b e nil t)
8634 'face gnus-article-button-face))
23f87bed
MB
8635 (widget-convert-button
8636 'link b e
8637 :mime-handle handle
8638 :action 'gnus-widget-press-button
8639 :button-keymap gnus-mime-security-button-map
8640 :help-echo
8641 (lambda (widget/window &optional overlay pos)
8642 ;; Needed to properly clear the message due to a bug in
8643 ;; wid-edit (XEmacs only).
8644 (when (boundp 'help-echo-owns-message)
8645 (setq help-echo-owns-message t))
8646 (format
01c52d31
MB
8647 "%S: show detail; %S: more options"
8648 (aref gnus-mouse-2 0)
8649 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8650
8651(defun gnus-mime-display-security (handle)
8652 (save-restriction
8653 (narrow-to-region (point) (point))
8654 (unless (gnus-unbuttonized-mime-type-p (car handle))
8655 (gnus-insert-mime-security-button handle))
01c52d31 8656 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8657 (unless (bolp)
8658 (insert "\n"))
8659 (unless (gnus-unbuttonized-mime-type-p (car handle))
8660 (let ((gnus-mime-security-button-line-format
8661 gnus-mime-security-button-end-line-format))
8662 (gnus-insert-mime-security-button handle)))
8663 (mm-set-handle-multipart-parameter
8664 handle 'gnus-region
8665 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8666 (set-marker (make-marker) (point-max))))
8667 (goto-char (point-max))))
8668
8669(defun gnus-mime-security-run-function (function)
8670 "Run FUNCTION with the security part under point."
8671 (gnus-article-check-buffer)
8672 (let ((data (get-text-property (point) 'gnus-data))
8673 buffer handle)
8674 (when (and (stringp (car-safe data))
8675 (setq buffer (mm-handle-multipart-original-buffer data))
8676 (setq handle (cadr data)))
8677 (if (bufferp (mm-handle-buffer handle))
8678 (progn
8679 (setq handle (cons buffer (copy-sequence (cdr handle))))
8680 (mm-handle-set-undisplayer handle nil))
8681 (setq handle (mm-make-handle
8682 buffer
8683 (mm-handle-multipart-ctl-parameter handle 'protocol)
8684 nil nil nil nil nil nil)))
8685 (funcall function handle))))
8686
8687(defun gnus-mime-security-save-part ()
8688 "Save the security part under point."
8689 (interactive)
8690 (gnus-mime-security-run-function 'mm-save-part))
8691
8692(defun gnus-mime-security-pipe-part ()
8693 "Pipe the security part under point to a process."
8694 (interactive)
8695 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8696
eec82323
LMI
8697(gnus-ems-redefine)
8698
8699(provide 'gnus-art)
8700
8701(run-hooks 'gnus-art-load-hook)
8702
80de1778 8703;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
eec82323 8704;;; gnus-art.el ends here