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