(image-type-header-regexps): Use only JPEG magic number
[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
23f87bed
MB
4743(defun gnus-mime-button-menu (event prefix)
4744 "Construct a context-sensitive menu of MIME commands."
4745 (interactive "e\nP")
4746 (save-window-excursion
4747 (let ((pos (event-start event)))
4748 (select-window (posn-window pos))
4749 (goto-char (posn-point pos))
4750 (gnus-article-check-buffer)
4751 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4752
4753(defun gnus-mime-view-all-parts (&optional handles)
4754 "View all the MIME parts."
4755 (interactive)
01c52d31 4756 (with-current-buffer gnus-article-buffer
16409b0b
GM
4757 (let ((handles (or handles gnus-article-mime-handles))
4758 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4759 (mail-parse-ignored-charsets
23f87bed
MB
4760 (with-current-buffer gnus-summary-buffer
4761 gnus-newsgroup-ignored-charsets)))
4762 (when handles
4763 (mm-remove-parts handles)
4764 (goto-char (point-min))
4765 (or (search-forward "\n\n") (goto-char (point-max)))
4766 (let ((inhibit-read-only t))
4767 (delete-region (point) (point-max))
4768 (mm-display-parts handles))))))
4769
01c52d31
MB
4770(defun gnus-article-jump-to-part (n)
4771 "Jump to MIME part N."
4772 (interactive "P")
4773 (pop-to-buffer gnus-article-buffer)
4774 ;; FIXME: why is it necessary?
4775 (sit-for 0)
4776 (let ((parts (length gnus-article-mime-handle-alist)))
4777 (or n (setq n
4778 (string-to-number
4779 (read-string ;; Emacs 21 doesn't have `read-number'.
4780 (format "Jump to part (2..%s): " parts)))))
4781 (unless (and (integerp n) (<= n parts) (>= n 1))
4782 (setq n
4783 (progn
4784 (gnus-message 7 "Invalid part `%s', using %s instead."
4785 n parts)
4786 parts)))
4787 (gnus-message 9 "Jumping to part %s." n)
4788 (cond ((>= gnus-auto-select-part 1)
4789 (while (and (<= n parts)
4790 (not (gnus-article-goto-part n)))
4791 (setq n (1+ n))))
4792 ((< gnus-auto-select-part 0)
4793 (while (and (>= n 1)
4794 (not (gnus-article-goto-part n)))
4795 (setq n (1- n))))
4796 (t
4797 (gnus-article-goto-part n)))))
4798
4799(eval-when-compile
4800 (defsubst gnus-article-edit-part (handles &optional current-id)
4801 "Edit an article in order to delete a mime part.
4802This function is exclusively used by `gnus-mime-save-part-and-strip'
4803and `gnus-mime-delete-part', and not provided at run-time normally."
4804 (gnus-article-edit-article
4805 `(lambda ()
4806 (buffer-disable-undo)
4807 (erase-buffer)
4808 (let ((mail-parse-charset (or gnus-article-charset
4809 ',gnus-newsgroup-charset))
4810 (mail-parse-ignored-charsets
4811 (or gnus-article-ignored-charsets
4812 ',gnus-newsgroup-ignored-charsets))
4813 (mbl mml-buffer-list))
4814 (setq mml-buffer-list nil)
4815 (insert-buffer-substring gnus-original-article-buffer)
4816 (mime-to-mml ',handles)
4817 (setq gnus-article-mime-handles nil)
4818 (let ((mbl1 mml-buffer-list))
4819 (setq mml-buffer-list mbl)
4820 (set (make-local-variable 'mml-buffer-list) mbl1))
4821 (gnus-make-local-hook 'kill-buffer-hook)
4822 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4823 `(lambda (no-highlight)
4824 (let ((mail-parse-charset (or gnus-article-charset
4825 ',gnus-newsgroup-charset))
4826 (message-options message-options)
4827 (message-options-set-recipient)
4828 (mail-parse-ignored-charsets
4829 (or gnus-article-ignored-charsets
4830 ',gnus-newsgroup-ignored-charsets)))
4831 (mml-to-mime)
4832 (mml-destroy-buffers)
4833 (remove-hook 'kill-buffer-hook
4834 'mml-destroy-buffers t)
4835 (kill-local-variable 'mml-buffer-list))
4836 (gnus-summary-edit-article-done
4837 ,(or (mail-header-references gnus-current-headers) "")
4838 ,(gnus-group-read-only-p)
4839 ,gnus-summary-buffer no-highlight))
4840 t)
4841 (gnus-article-edit-done)
4842 (gnus-summary-expand-window)
4843 (gnus-summary-show-article)
4844 (when (and current-id (integerp gnus-auto-select-part))
4845 (gnus-article-jump-to-part
4846 (if (text-property-any (point-min) (point-max)
4847 'gnus-part (+ current-id gnus-auto-select-part))
4848 (+ current-id gnus-auto-select-part)
4849 (with-current-buffer gnus-article-buffer
4850 (length gnus-article-mime-handle-alist)))))))
4851
4852(defun gnus-mime-replace-part (file)
4853 "Replace MIME part under point with an external body."
4854 ;; Useful if file has already been saved to disk
4855 (interactive
4856 (list
75eda25b
SM
4857 (read-file-name "Replace MIME part with file: "
4858 (or mm-default-directory default-directory)
4859 nil nil)))
01c52d31
MB
4860 (gnus-mime-save-part-and-strip file))
4861
4862(defun gnus-mime-save-part-and-strip (&optional file)
4863 "Save the MIME part under point then replace it with an external body.
4864If FILE is given, use it for the external part."
23f87bed
MB
4865 (interactive)
4866 (gnus-article-check-buffer)
4867 (when (gnus-group-read-only-p)
4868 (error "The current group does not support deleting of parts"))
4869 (when (mm-complicated-handles gnus-article-mime-handles)
4870 (error "\
4871The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4872 (let* ((data (get-text-property (point) 'gnus-data))
4873 (id (get-text-property (point) 'gnus-part))
4874 param
4875 (handles gnus-article-mime-handles))
4876 (unless file
4877 (setq file
4878 (and data (mm-save-part data "Delete MIME part and save to: "))))
4879 (when file
4880 (with-current-buffer (mm-handle-buffer data)
4881 (erase-buffer)
4882 (insert "Content-Type: " (mm-handle-media-type data))
4883 (mml-insert-parameter-string (cdr (mm-handle-type data))
4884 '(charset))
4885 ;; Add a filename for the sake of saving the part again.
4886 (mml-insert-parameter
4887 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4888 (insert "\n")
4889 (insert "Content-ID: " (message-make-message-id) "\n")
4890 (insert "Content-Transfer-Encoding: binary\n")
4891 (insert "\n"))
4892 (setcdr data
4893 (cdr (mm-make-handle nil
4894 `("message/external-body"
4895 (access-type . "LOCAL-FILE")
4896 (name . ,file)))))
4897 ;; (set-buffer gnus-summary-buffer)
4898 (gnus-article-edit-part handles id))))
4899
4900;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4901;; parts...>') but with stripping would be nice.
23f87bed
MB
4902
4903(defun gnus-mime-delete-part ()
4904 "Delete the MIME part under point.
4905Replace it with some information about the removed part."
4906 (interactive)
4907 (gnus-article-check-buffer)
4908 (when (gnus-group-read-only-p)
4909 (error "The current group does not support deleting of parts"))
4910 (when (mm-complicated-handles gnus-article-mime-handles)
4911 (error "\
4912The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4913 (when (or gnus-expert-user
4914 (gnus-yes-or-no-p "\
4915Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 4916 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 4917 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
4918 (handles gnus-article-mime-handles)
4919 (none "(none)")
4920 (description
bbbe940b
MB
4921 (let ((desc (mm-handle-description data)))
4922 (when desc
4923 (mail-decode-encoded-word-string desc))))
23f87bed
MB
4924 (filename
4925 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4926 none))
4927 (type (mm-handle-media-type data)))
4928 (unless data
4929 (error "No MIME part under point"))
4930 (with-current-buffer (mm-handle-buffer data)
4931 (let ((bsize (format "%s" (buffer-size))))
4932 (erase-buffer)
4933 (insert
4934 (concat
4935 ",----\n"
4936 "| The following attachment has been deleted:\n"
4937 "|\n"
4938 "| Type: " type "\n"
4939 "| Filename: " filename "\n"
4940 "| Size (encoded): " bsize " Byte\n"
bbbe940b
MB
4941 (when description
4942 (concat "| Description: " description "\n"))
23f87bed
MB
4943 "`----\n"))
4944 (setcdr data
4945 (cdr (mm-make-handle
0cf681b6 4946 nil `("text/plain" (charset . gnus-decoded)) nil nil
23f87bed
MB
4947 (list "attachment")
4948 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
4949 ;; (set-buffer gnus-summary-buffer)
4950 (gnus-article-edit-part handles id))))
16409b0b
GM
4951
4952(defun gnus-mime-save-part ()
4953 "Save the MIME part under point."
4954 (interactive)
4955 (gnus-article-check-buffer)
4956 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4957 (when data
4958 (mm-save-part data))))
16409b0b
GM
4959
4960(defun gnus-mime-pipe-part ()
4961 "Pipe the MIME part under point to a process."
4962 (interactive)
4963 (gnus-article-check-buffer)
4964 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4965 (when data
4966 (mm-pipe-part data))))
16409b0b
GM
4967
4968(defun gnus-mime-view-part ()
4969 "Interactively choose a viewing method for the MIME part under point."
4970 (interactive)
4971 (gnus-article-check-buffer)
4972 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4973 (when data
4974 (setq gnus-article-mime-handles
4975 (mm-merge-handles
4976 gnus-article-mime-handles (setq data (copy-sequence data))))
4977 (mm-interactively-view-part data))))
16409b0b
GM
4978
4979(defun gnus-mime-view-part-as-type-internal ()
4980 (gnus-article-check-buffer)
54e573e6
MB
4981 (let* ((handle (get-text-property (point) 'gnus-data))
4982 (name (or
4983 ;; Content-Type: foo/bar; name=...
4984 (mail-content-type-get (mm-handle-type handle) 'name)
4985 ;; Content-Disposition: attachment; filename=...
4986 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 4987 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
4988 (or (and def-type (cons def-type 0))
4989 (and handle
4990 (equal (mm-handle-media-supertype handle) "text")
4991 '("text/plain" . 0))
4992 '("application/octet-stream" . 0))))
16409b0b 4993
54e573e6
MB
4994(defun gnus-mime-view-part-as-type (&optional mime-type pred)
4995 "Choose a MIME media type, and view the part as such.
4996If non-nil, PRED is a predicate to use during completion to limit the
4997available media-types."
23f87bed
MB
4998 (interactive)
4999 (unless mime-type
54e573e6
MB
5000 (setq mime-type
5001 (let ((default (gnus-mime-view-part-as-type-internal)))
5002 (completing-read
5003 (format "View as MIME type (default %s): "
5004 (car default))
5005 (mapcar #'list (mailcap-mime-types))
5006 pred nil nil nil
5007 (car default)))))
16409b0b
GM
5008 (gnus-article-check-buffer)
5009 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 5010 (when handle
531bedc3
MB
5011 (when (equal (mm-handle-media-type handle) "message/external-body")
5012 (unless (mm-handle-cache handle)
5013 (mm-extern-cache-contents handle))
5014 (setq handle (mm-handle-cache handle)))
23f87bed
MB
5015 (setq handle
5016 (mm-make-handle (mm-handle-buffer handle)
5017 (cons mime-type (cdr (mm-handle-type handle)))
5018 (mm-handle-encoding handle)
5019 (mm-handle-undisplayer handle)
5020 (mm-handle-disposition handle)
5021 (mm-handle-description handle)
5022 nil
5023 (mm-handle-id handle)))
5024 (setq gnus-article-mime-handles
5025 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
5026 (when (mm-handle-displayed-p handle)
5027 (mm-remove-part handle))
23f87bed
MB
5028 (gnus-mm-display-part handle))))
5029
01c52d31 5030(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
5031 "Put the MIME part under point into a new buffer.
5032If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5033are decompressed."
01c52d31 5034 (interactive (list nil current-prefix-arg))
16409b0b 5035 (gnus-article-check-buffer)
01c52d31
MB
5036 (unless handle
5037 (setq handle (get-text-property (point) 'gnus-data)))
5038 (when handle
5039 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5040 'name)
5041 (mail-content-type-get (mm-handle-disposition handle)
5042 'filename)))
5043 contents dont-decode charset coding-system)
5044 (mm-with-unibyte-buffer
5045 (mm-insert-part handle)
5046 (setq contents (or (condition-case nil
5047 (mm-decompress-buffer filename nil 'sig)
5048 (error
5049 (setq dont-decode t)
5050 nil))
5051 (buffer-string))))
5052 (setq filename (cond (filename (file-name-nondirectory filename))
5053 (dont-decode "*raw data*")
5054 (t "*decoded*")))
5055 (cond
5056 (dont-decode)
5057 ((not arg)
5058 (unless (setq charset (mail-content-type-get
5059 (mm-handle-type handle) 'charset))
5060 (unless (setq coding-system (mm-with-unibyte-buffer
5061 (insert contents)
5062 (mm-find-buffer-file-coding-system)))
5063 (setq charset gnus-newsgroup-charset))))
5064 ((numberp arg)
5065 (setq charset (or (cdr (assq arg
5066 gnus-summary-show-article-charset-alist))
5067 (mm-read-coding-system "Charset: ")))))
5068 (switch-to-buffer (generate-new-buffer filename))
5069 (if (or coding-system
5070 (and charset
5071 (setq coding-system (mm-charset-to-coding-system charset))
5072 (not (eq charset 'ascii))))
5073 (progn
5074 (mm-enable-multibyte)
5075 (insert (mm-decode-coding-string contents coding-system))
5076 (setq buffer-file-coding-system
5077 (if (boundp 'last-coding-system-used)
5078 (symbol-value 'last-coding-system-used)
5079 coding-system)))
5080 (mm-disable-multibyte)
5081 (insert contents)
5082 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5083 ;; We do it this way to make `normal-mode' set the appropriate mode.
5084 (unwind-protect
5085 (progn
01c52d31 5086 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5087 (normal-mode))
5088 (setq buffer-file-name nil))
5089 (goto-char (point-min)))))
5090
5091(defun gnus-mime-print-part (&optional handle filename)
5092 "Print the MIME part under point."
5093 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5094 (gnus-article-check-buffer)
5095 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5096 (contents (and handle (mm-get-part handle)))
5097 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5098 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5099 (when contents
5100 (if printer
5101 (unwind-protect
5102 (progn
5103 (mm-save-part-to-file handle file)
5104 (call-process shell-file-name nil
5105 (generate-new-buffer " *mm*")
5106 nil
5107 shell-command-switch
5108 (mm-mailcap-command
5109 printer file (mm-handle-type handle))))
5110 (delete-file file))
5111 (with-temp-buffer
5112 (insert contents)
5113 (gnus-print-buffer))
5114 (ps-despool filename)))))
16409b0b 5115
e0bad764 5116(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5117 "Insert the MIME part under point into the current buffer.
5118Compressed files like .gz and .bz2 are decompressed."
e0bad764 5119 (interactive (list nil current-prefix-arg))
16409b0b 5120 (gnus-article-check-buffer)
01c52d31
MB
5121 (unless handle
5122 (setq handle (get-text-property (point) 'gnus-data)))
5123 (when handle
5124 (let ((b (point))
5125 (inhibit-read-only t)
5126 contents charset coding-system)
23f87bed
MB
5127 (if (and (not arg) (mm-handle-undisplayer handle))
5128 (mm-remove-part handle)
01c52d31
MB
5129 (mm-with-unibyte-buffer
5130 (mm-insert-part handle)
5131 (setq contents
5132 (or (mm-decompress-buffer
5133 (or (mail-content-type-get (mm-handle-type handle)
5134 'name)
5135 (mail-content-type-get (mm-handle-disposition handle)
5136 'filename))
5137 nil t)
5138 (buffer-string))))
23f87bed
MB
5139 (cond
5140 ((not arg)
01c52d31
MB
5141 (unless (setq charset (mail-content-type-get
5142 (mm-handle-type handle) 'charset))
5143 (unless (setq coding-system
5144 (mm-with-unibyte-buffer
5145 (insert contents)
5146 (mm-find-buffer-file-coding-system)))
5147 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5148 ((numberp arg)
5149 (if (mm-handle-undisplayer handle)
5150 (mm-remove-part handle))
5151 (setq charset
5152 (or (cdr (assq arg
5153 gnus-summary-show-article-charset-alist))
56c30d72
MB
5154 (mm-read-coding-system "Charset: "))))
5155 (t
5156 (if (mm-handle-undisplayer handle)
850c333d 5157 (mm-remove-part handle))))
23f87bed 5158 (forward-line 2)
850c333d
MB
5159 (mm-insert-inline
5160 handle
01c52d31
MB
5161 (if (or coding-system
5162 (and charset
5163 (setq coding-system
5164 (mm-charset-to-coding-system charset))
5165 (not (eq coding-system 'ascii))))
5166 (mm-decode-coding-string contents coding-system)
850c333d 5167 (mm-string-to-multibyte contents)))
23f87bed
MB
5168 (goto-char b)))))
5169
c0ccb0d6
KY
5170(defun gnus-mime-set-charset-parameters (handle charset)
5171 "Set CHARSET to parameters in HANDLE.
5172CHARSET may either be a string or a symbol."
5173 (unless (stringp charset)
5174 (setq charset (symbol-name charset)))
6b554e88 5175 (if (stringp (car handle))
c0ccb0d6
KY
5176 (dolist (h (cdr handle))
5177 (gnus-mime-set-charset-parameters h charset))
6b554e88
MB
5178 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5179 "message/external-body")
5180 (progn
5181 (unless (mm-handle-cache handle)
5182 (mm-extern-cache-contents handle))
5183 (mm-handle-cache handle))
5184 handle)))
c0ccb0d6
KY
5185 (param (assq 'charset (cdr type))))
5186 (if param
5187 (setcdr param charset)
5188 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
6b554e88 5189
23f87bed
MB
5190(defun gnus-mime-view-part-as-charset (&optional handle arg)
5191 "Insert the MIME part under point into the current buffer using the
5192specified charset."
5193 (interactive (list nil current-prefix-arg))
5194 (gnus-article-check-buffer)
163cb72d
MB
5195 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5196 (fun (get-text-property (point) 'gnus-callback))
5197 (gnus-newsgroup-ignored-charsets 'gnus-all)
c0ccb0d6 5198 charset form preferred parts)
23f87bed 5199 (when handle
01c52d31
MB
5200 (when (prog1
5201 (and fun
c0ccb0d6 5202 (setq charset
01c52d31
MB
5203 (or (cdr (assq
5204 arg
5205 gnus-summary-show-article-charset-alist))
5206 (mm-read-coding-system "Charset: "))))
5207 (if (mm-handle-undisplayer handle)
5208 (mm-remove-part handle)))
c0ccb0d6 5209 (gnus-mime-set-charset-parameters handle charset)
6b554e88
MB
5210 (when (and (consp (setq form (cdr-safe fun)))
5211 (setq form (ignore-errors
5212 (assq 'gnus-mime-display-alternative form)))
5213 (setq preferred (caddr form))
5214 (progn
5215 (when (eq (car preferred) 'quote)
5216 (setq preferred (cadr preferred)))
5217 (not (equal preferred
5218 (get-text-property (point) 'gnus-data))))
5219 (setq parts (get-text-property (point) 'gnus-part))
5220 (setq parts (cdr (assq parts
5221 gnus-article-mime-handle-alist)))
5222 (equal (mm-handle-media-type parts) "multipart/alternative")
5223 (setq parts (reverse (cdr parts))))
5224 (setcar (cddr form)
5225 (list 'quote (or (cadr (member preferred parts))
5226 (car parts)))))
163cb72d 5227 (funcall fun handle)))))
23f87bed
MB
5228
5229(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5230 "View the MIME part under point with an external viewer."
5231 (interactive)
5232 (gnus-article-check-buffer)
5233 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5234 (mm-user-display-methods nil)
5235 (mm-inlined-types nil)
5236 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5237 (mail-parse-ignored-charsets
54e573e6
MB
5238 (with-current-buffer gnus-summary-buffer
5239 gnus-newsgroup-ignored-charsets))
5240 (type (mm-handle-media-type handle))
5241 (method (mailcap-mime-info type))
5242 (mm-enable-external t))
5243 (if (not (stringp method))
5244 (gnus-mime-view-part-as-type
524705ae 5245 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
54e573e6
MB
5246 (when handle
5247 (if (mm-handle-undisplayer handle)
5248 (mm-remove-part handle)
5249 (mm-display-part handle))))))
16409b0b 5250
23f87bed 5251(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5252 "View the MIME part under point with an internal viewer.
23f87bed 5253If no internal viewer is available, use an external viewer."
16409b0b
GM
5254 (interactive)
5255 (gnus-article-check-buffer)
5256 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5257 (mm-inlined-types '(".*"))
5258 (mm-inline-large-images t)
5259 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5260 (mail-parse-ignored-charsets
54e573e6
MB
5261 (with-current-buffer gnus-summary-buffer
5262 gnus-newsgroup-ignored-charsets))
23f87bed 5263 (inhibit-read-only t))
54e573e6
MB
5264 (if (not (mm-inlinable-p handle))
5265 (gnus-mime-view-part-as-type
524705ae 5266 nil (lambda (types) (mm-inlinable-p handle (car types))))
54e573e6
MB
5267 (when handle
5268 (if (mm-handle-undisplayer handle)
5269 (mm-remove-part handle)
5270 (mm-display-part handle))))))
16409b0b 5271
e0bad764
DL
5272(defun gnus-mime-action-on-part (&optional action)
5273 "Do something with the MIME attachment at \(point\)."
5274 (interactive
23f87bed 5275 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
e0bad764
DL
5276 (gnus-article-check-buffer)
5277 (let ((action-pair (assoc action gnus-mime-action-alist)))
5278 (if action-pair
5279 (funcall (cdr action-pair)))))
5280
01c52d31
MB
5281(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5282 "Call FUNCTION on MIME part N.
5283Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5284If INTERACTIVE, call FUNCTION interactivly."
5285 (let (window frame)
5286 ;; Check whether the article is displayed.
5287 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5288 (setq window (get-buffer-window gnus-article-buffer t))
5289 (frame-visible-p (setq frame (window-frame window))))
5290 (error "No article is displayed"))
5291 (with-current-buffer gnus-article-buffer
5292 ;; Check whether the article displays the right contents.
5293 (unless (with-current-buffer gnus-summary-buffer
5294 (eq gnus-current-article (gnus-summary-article-number)))
5295 (error "You should select the right article first"))
5296 (if n
5297 (setq n (prefix-numeric-value n))
5298 (let ((pt (point)))
5299 (setq n (or (get-text-property pt 'gnus-part)
5300 (and (not (bobp))
5301 (get-text-property (1- pt) 'gnus-part))
5302 (get-text-property (prog2
5303 (forward-line 1)
5304 (point)
5305 (goto-char pt))
5306 'gnus-part)
5307 (get-text-property
5308 (or (and (setq pt (previous-single-property-change
5309 pt 'gnus-part))
5310 (1- pt))
5311 (next-single-property-change (point) 'gnus-part)
5312 (point))
5313 'gnus-part)
5314 1))))
5315 ;; Check whether the specified part exists.
5316 (when (> n (length gnus-article-mime-handle-alist))
5317 (error "No such part")))
5318 (unless
5319 (progn
5320 ;; To select the window is needed so that the cursor
5321 ;; might be visible on the MIME button.
5322 (select-window (prog1
5323 window
5324 (setq window (selected-window))
5325 ;; Article may be displayed in the other frame.
5326 (gnus-select-frame-set-input-focus
5327 (prog1
5328 frame
5329 (setq frame (selected-frame))))))
5330 (when (gnus-article-goto-part n)
5331 ;; We point the cursor and the arrow at the MIME button
5332 ;; when the `function' prompt the user for something.
5333 (let ((cursor-in-non-selected-windows t)
5334 (overlay-arrow-string "=>")
5335 (overlay-arrow-position (point-marker)))
5336 (unwind-protect
5337 (cond
5338 ((and no-handle interactive)
5339 (call-interactively function))
5340 (no-handle
5341 (funcall function))
5342 (interactive
5343 (call-interactively
5344 function
5345 (cdr (assq n gnus-article-mime-handle-alist))))
5346 (t
5347 (funcall function
5348 (cdr (assq n gnus-article-mime-handle-alist)))))
5349 (set-marker overlay-arrow-position nil)
5350 (unless gnus-auto-select-part
5351 (gnus-select-frame-set-input-focus frame)
5352 (select-window window))))
5353 t))
5354 (if gnus-inhibit-mime-unbuttonizing
5355 ;; This is the default though the program shouldn't reach here.
5356 (error "No such part")
5357 ;; The part which doesn't have the MIME button is selected.
5358 ;; So, we display all the buttons and redo it.
5359 (let ((gnus-inhibit-mime-unbuttonizing t))
5360 (gnus-summary-show-article)
5361 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5362
5363(defun gnus-article-pipe-part (n)
5364 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5365 (interactive "P")
16409b0b
GM
5366 (gnus-article-part-wrapper n 'mm-pipe-part))
5367
5368(defun gnus-article-save-part (n)
5369 "Save MIME part N, which is the numerical prefix."
01c52d31 5370 (interactive "P")
16409b0b
GM
5371 (gnus-article-part-wrapper n 'mm-save-part))
5372
5373(defun gnus-article-interactively-view-part (n)
5374 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5375 (interactive "P")
16409b0b
GM
5376 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5377
5378(defun gnus-article-copy-part (n)
5379 "Copy MIME part N, which is the numerical prefix."
01c52d31 5380 (interactive "P")
16409b0b
GM
5381 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5382
23f87bed
MB
5383(defun gnus-article-view-part-as-charset (n)
5384 "View MIME part N using a specified charset.
5385N is the numerical prefix."
01c52d31 5386 (interactive "P")
23f87bed
MB
5387 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5388
5389(defun gnus-article-view-part-externally (n)
16409b0b 5390 "View MIME part N externally, which is the numerical prefix."
01c52d31 5391 (interactive "P")
23f87bed 5392 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5393
5394(defun gnus-article-inline-part (n)
5395 "Inline MIME part N, which is the numerical prefix."
01c52d31 5396 (interactive "P")
16409b0b
GM
5397 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5398
01c52d31
MB
5399(defun gnus-article-save-part-and-strip (n)
5400 "Save MIME part N and replace it with an external body.
5401N is the numerical prefix."
5402 (interactive "P")
5403 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5404
5405(defun gnus-article-replace-part (n)
5406 "Replace MIME part N with an external body.
5407N is the numerical prefix."
5408 (interactive "P")
5409 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5410
5411(defun gnus-article-delete-part (n)
5412 "Delete MIME part N and add some information about the removed part.
5413N is the numerical prefix."
5414 (interactive "P")
5415 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5416
5417(defun gnus-article-view-part-as-type (n)
5418 "Choose a MIME media type, and view part N as such.
5419N is the numerical prefix."
5420 (interactive "P")
5421 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5422
16409b0b
GM
5423(defun gnus-article-mime-match-handle-first (condition)
5424 (if condition
01c52d31
MB
5425 (let (n)
5426 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5427 (if (and (cond
16409b0b
GM
5428 ((functionp condition)
5429 (funcall condition (cdr ihandle)))
a1506d29 5430 ((eq condition 'undisplayed)
16409b0b
GM
5431 (not (or (mm-handle-undisplayer (cdr ihandle))
5432 (equal (mm-handle-media-type (cdr ihandle))
5433 "multipart/alternative"))))
5434 ((eq condition 'undisplayed-alternative)
5435 (not (mm-handle-undisplayer (cdr ihandle))))
5436 (t t))
5437 (gnus-article-goto-part (car ihandle))
5438 (or (not n) (< (car ihandle) n)))
5439 (setq n (car ihandle))))
5440 (or n 1))
5441 1))
5442
5443(defun gnus-article-view-part (&optional n)
5444 "View MIME part N, which is the numerical prefix."
5445 (interactive "P")
01c52d31 5446 (with-current-buffer gnus-article-buffer
a1506d29 5447 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5448 gnus-article-mime-match-handle-function)))
5449 (when (> n (length gnus-article-mime-handle-alist))
5450 (error "No such part"))
5451 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5452 (when (gnus-article-goto-part n)
5453 (if (equal (car handle) "multipart/alternative")
5454 (gnus-article-press-button)
5455 (when (eq (gnus-mm-display-part handle) 'internal)
5456 (gnus-set-window-start)))))))
5457
e0bad764
DL
5458(defsubst gnus-article-mime-total-parts ()
5459 (if (bufferp (car gnus-article-mime-handles))
5460 1 ;; single part
5461 (1- (length gnus-article-mime-handles))))
5462
16409b0b
GM
5463(defun gnus-mm-display-part (handle)
5464 "Display HANDLE and fix MIME button."
5465 (let ((id (get-text-property (point) 'gnus-part))
5466 (point (point))
23f87bed 5467 (inhibit-read-only t))
16409b0b
GM
5468 (forward-line 1)
5469 (prog1
5470 (let ((window (selected-window))
5471 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5472 (mail-parse-ignored-charsets
23f87bed 5473 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5474 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5475 gnus-newsgroup-ignored-charsets)
5476 nil)))
16409b0b
GM
5477 (save-excursion
5478 (unwind-protect
23f87bed 5479 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5480 (beg (point)))
5481 (when win
5482 (select-window win))
5483 (goto-char point)
5484 (forward-line)
5485 (if (mm-handle-displayed-p handle)
5486 ;; This will remove the part.
5487 (mm-display-part handle)
5488 (save-restriction
23f87bed
MB
5489 (narrow-to-region (point)
5490 (if (eobp) (point) (1+ (point))))
16409b0b
GM
5491 (mm-display-part handle)
5492 ;; We narrow to the part itself and
5493 ;; then call the treatment functions.
5494 (goto-char (point-min))
5495 (forward-line 1)
5496 (narrow-to-region (point) (point-max))
5497 (gnus-treat-article
5498 nil id
e0bad764 5499 (gnus-article-mime-total-parts)
16409b0b 5500 (mm-handle-media-type handle)))))
23f87bed
MB
5501 (if (window-live-p window)
5502 (select-window window)))))
16409b0b 5503 (goto-char point)
23f87bed 5504 (gnus-delete-line)
16409b0b
GM
5505 (gnus-insert-mime-button
5506 handle id (list (mm-handle-displayed-p handle)))
5507 (goto-char point))))
5508
5509(defun gnus-article-goto-part (n)
5510 "Go to MIME part N."
23f87bed 5511 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
5512
5513(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5514 (let ((gnus-tmp-name
23f87bed
MB
5515 (or (mail-content-type-get (mm-handle-type handle) 'name)
5516 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5517 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5518 ""))
5519 (gnus-tmp-type (mm-handle-media-type handle))
4599d0ec 5520 (gnus-tmp-description (or (mm-handle-description handle) ""))
16409b0b
GM
5521 (gnus-tmp-dots
5522 (if (if displayed (car displayed)
5523 (mm-handle-displayed-p handle))
5524 "" "..."))
5525 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5526 (buffer-size)))
5527 gnus-tmp-type-long b e)
5528 (when (string-match ".*/" gnus-tmp-name)
5529 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5530 (setq gnus-tmp-type-long (concat gnus-tmp-type
5531 (and (not (equal gnus-tmp-name ""))
5532 (concat "; " gnus-tmp-name))))
23f87bed
MB
5533 (unless (equal gnus-tmp-description "")
5534 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5535 (unless (bolp)
5536 (insert "\n"))
5537 (setq b (point))
5538 (gnus-eval-format
5539 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5540 `(keymap ,gnus-mime-button-map
5541 gnus-callback gnus-mm-display-part
5542 gnus-part ,gnus-tmp-id
5543 article-type annotation
5544 gnus-data ,handle))
23f87bed
MB
5545 (setq e (if (bolp)
5546 ;; Exclude a newline.
5547 (1- (point))
5548 (point)))
01c52d31
MB
5549 (when gnus-article-button-face
5550 (gnus-overlay-put (gnus-make-overlay b e nil t)
5551 'face gnus-article-button-face))
16409b0b
GM
5552 (widget-convert-button
5553 'link b e
5554 :mime-handle handle
5555 :action 'gnus-widget-press-button
5556 :button-keymap gnus-mime-button-map
5557 :help-echo
5558 (lambda (widget/window &optional overlay pos)
5559 ;; Needed to properly clear the message due to a bug in
5560 ;; wid-edit (XEmacs only).
5561 (if (boundp 'help-echo-owns-message)
5562 (setq help-echo-owns-message t))
5563 (format
5564 "%S: %s the MIME part; %S: more options"
5565 (aref gnus-mouse-2 0)
5566 ;; XEmacs will get a single widget arg; Emacs 21 will get
5567 ;; window, overlay, position.
5568 (if (mm-handle-displayed-p
5569 (if overlay
e0bad764
DL
5570 (with-current-buffer (gnus-overlay-buffer overlay)
5571 (widget-get (widget-at (gnus-overlay-start overlay))
16409b0b
GM
5572 :mime-handle))
5573 (widget-get widget/window :mime-handle)))
5574 "hide" "show")
5575 (aref gnus-down-mouse-3 0))))))
5576
5577(defun gnus-widget-press-button (elems el)
5578 (goto-char (widget-get elems :from))
5579 (gnus-article-press-button))
5580
5581(defvar gnus-displaying-mime nil)
5582
5583(defun gnus-display-mime (&optional ihandles)
5584 "Display the MIME parts."
5585 (save-excursion
5586 (save-selected-window
5587 (let ((window (get-buffer-window gnus-article-buffer))
5588 (point (point)))
5589 (when window
5590 (select-window window)
5591 ;; We have to do this since selecting the window
5592 ;; may change the point. So we set the window point.
5593 (set-window-point window point)))
73043f7d
MB
5594 (let ((handles ihandles)
5595 (inhibit-read-only t)
5596 handle)
5597 (cond (handles)
5598 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5599 (when gnus-article-emulate-mime
5600 (mm-uu-dissect-text-parts handles)))
5601 (gnus-article-emulate-mime
5602 (setq handles (mm-uu-dissect))))
16409b0b
GM
5603 (when (and (not ihandles)
5604 (not gnus-displaying-mime))
5605 ;; Top-level call; we clean up.
5606 (when gnus-article-mime-handles
5607 (mm-destroy-parts gnus-article-mime-handles)
5608 (setq gnus-article-mime-handle-alist nil));; A trick.
5609 (setq gnus-article-mime-handles handles)
5610 ;; We allow users to glean info from the handles.
5611 (when gnus-article-mime-part-function
5612 (gnus-mime-part-function handles)))
5613 (if (and handles
5614 (or (not (stringp (car handles)))
5615 (cdr handles)))
5616 (progn
5617 (when (and (not ihandles)
5618 (not gnus-displaying-mime))
5619 ;; Clean up for mime parts.
5620 (article-goto-body)
5621 (delete-region (point) (point-max)))
5622 (let ((gnus-displaying-mime t))
5623 (gnus-mime-display-part handles)))
5624 (save-restriction
5625 (article-goto-body)
5626 (narrow-to-region (point) (point-max))
5627 (gnus-treat-article nil 1 1)
5628 (widen)))
5629 (unless ihandles
5630 ;; Highlight the headers.
5631 (save-excursion
5632 (save-restriction
5633 (article-goto-body)
5634 (narrow-to-region (point-min) (point))
31640842 5635 (gnus-article-save-original-date
f362b760
MB
5636 (gnus-treat-article 'head)))))))
5637 ;; Cope with broken MIME messages.
5638 (goto-char (point-max))
5639 (unless (bolp)
5640 (insert "\n"))))
16409b0b 5641
23f87bed
MB
5642(defcustom gnus-mime-display-multipart-as-mixed nil
5643 "Display \"multipart\" parts as \"multipart/mixed\".
5644
5645If t, it overrides nil values of
5646`gnus-mime-display-multipart-alternative-as-mixed' and
5647`gnus-mime-display-multipart-related-as-mixed'."
5648 :group 'gnus-article-mime
5649 :type 'boolean)
5650
5651(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5652 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5653 :version "22.1"
23f87bed
MB
5654 :group 'gnus-article-mime
5655 :type 'boolean)
5656
5657(defcustom gnus-mime-display-multipart-related-as-mixed nil
5658 "Display \"multipart/related\" parts as \"multipart/mixed\".
5659
5660If displaying \"text/html\" is discouraged \(see
5661`mm-discouraged-alternatives'\) images or other material inside a
5662\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5663 :version "22.1"
23f87bed
MB
5664 :group 'gnus-article-mime
5665 :type 'boolean)
16409b0b
GM
5666
5667(defun gnus-mime-display-part (handle)
5668 (cond
430d3ed7
MB
5669 ;; Maybe a broken MIME message.
5670 ((null handle))
16409b0b
GM
5671 ;; Single part.
5672 ((not (stringp (car handle)))
5673 (gnus-mime-display-single handle))
5674 ;; User-defined multipart
5675 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5676 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5677 handle))
5678 ;; multipart/alternative
5679 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5680 (not (or gnus-mime-display-multipart-as-mixed
5681 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5682 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5683 (push (cons id handle) gnus-article-mime-handle-alist)
5684 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5685 ;; multipart/related
5686 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5687 (not (or gnus-mime-display-multipart-as-mixed
5688 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5689 ;;;!!!We should find the start part, but we just default
5690 ;;;!!!to the first part.
23f87bed
MB
5691 ;;(gnus-mime-display-part (cadr handle))
5692 ;;;!!! Most multipart/related is an HTML message plus images.
5693 ;;;!!! Unfortunately we are unable to let W3 display those
5694 ;;;!!! included images, so we just display it as a mixed multipart.
5695 ;;(gnus-mime-display-mixed (cdr handle))
5696 ;;;!!! No, w3 can display everything just fine.
16409b0b 5697 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5698 ((equal (car handle) "multipart/signed")
5699 (gnus-add-wash-type 'signed)
5700 (gnus-mime-display-security handle))
5701 ((equal (car handle) "multipart/encrypted")
5702 (gnus-add-wash-type 'encrypted)
5703 (gnus-mime-display-security handle))
16409b0b
GM
5704 ;; Other multiparts are handled like multipart/mixed.
5705 (t
5706 (gnus-mime-display-mixed (cdr handle)))))
5707
5708(defun gnus-mime-part-function (handles)
5709 (if (stringp (car handles))
5710 (mapcar 'gnus-mime-part-function (cdr handles))
5711 (funcall gnus-article-mime-part-function handles)))
5712
5713(defun gnus-mime-display-mixed (handles)
5714 (mapcar 'gnus-mime-display-part handles))
5715
5716(defun gnus-mime-display-single (handle)
5717 (let ((type (mm-handle-media-type handle))
5718 (ignored gnus-ignored-mime-types)
5719 (not-attachment t)
5720 (move nil)
5721 display text)
5722 (catch 'ignored
5723 (progn
5724 (while ignored
5725 (when (string-match (pop ignored) type)
5726 (throw 'ignored nil)))
5727 (if (and (setq not-attachment
5728 (and (not (mm-inline-override-p handle))
5729 (or (not (mm-handle-disposition handle))
5730 (equal (car (mm-handle-disposition handle))
5731 "inline")
5732 (mm-attachment-override-p handle))))
5733 (mm-automatic-display-p handle)
23f87bed
MB
5734 (or (and
5735 (mm-inlinable-p handle)
5736 (mm-inlined-p handle))
16409b0b
GM
5737 (mm-automatic-external-display-p type)))
5738 (setq display t)
5739 (when (equal (mm-handle-media-supertype handle) "text")
5740 (setq text t)))
e0bad764
DL
5741 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5742 beg)
16409b0b 5743 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5744 (when (and display
5745 (equal (mm-handle-media-supertype handle) "message"))
5746 (insert-char
5747 ?\n
5748 (cond ((not (bolp)) 2)
5749 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5750 (t 1))))
16409b0b
GM
5751 (when (or (not display)
5752 (not (gnus-unbuttonized-mime-type-p type)))
16409b0b
GM
5753 (gnus-insert-mime-button
5754 handle id (list (or display (and not-attachment text))))
5755 (gnus-article-insert-newline)
23f87bed 5756 ;; Remember modify the number of forward lines.
e0bad764
DL
5757 (setq move t))
5758 (setq beg (point))
16409b0b
GM
5759 (cond
5760 (display
5761 (when move
23f87bed 5762 (forward-line -1)
16409b0b
GM
5763 (setq beg (point)))
5764 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5765 (mail-parse-ignored-charsets
16409b0b
GM
5766 (save-excursion (condition-case ()
5767 (set-buffer gnus-summary-buffer)
5768 (error))
5769 gnus-newsgroup-ignored-charsets)))
5770 (mm-display-part handle t))
5771 (goto-char (point-max)))
5772 ((and text not-attachment)
5773 (when move
23f87bed 5774 (forward-line -1)
16409b0b
GM
5775 (setq beg (point)))
5776 (gnus-article-insert-newline)
53cfefc8
MB
5777 (mm-insert-inline
5778 handle
01c52d31
MB
5779 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5780 'charset)
5781 (and (equal type "text/calendar") 'utf-8))))
53cfefc8
MB
5782 (cond ((not charset)
5783 (mm-string-as-multibyte (mm-get-part handle)))
5784 ((eq charset 'gnus-decoded)
5785 (with-current-buffer (mm-handle-buffer handle)
5786 (buffer-string)))
5787 (t
5788 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
5789 (goto-char (point-max))))
5790 ;; Do highlighting.
5791 (save-excursion
5792 (save-restriction
5793 (narrow-to-region beg (point))
01c52d31
MB
5794 (if (eq handle gnus-article-mime-handles)
5795 ;; The format=flowed case.
5796 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5797 ;; Don't count signature parts that are never displayed.
5798 ;; The part number should be re-calculated supposing this
5799 ;; might be a message/rfc822 part.
5800 (let (handles)
5801 (dolist (part gnus-article-mime-handles)
5802 (unless (or (stringp part)
5803 (equal (car (mm-handle-type part))
5804 "application/pgp-signature"))
5805 (push part handles)))
5806 (gnus-treat-article
5807 nil (length (memq handle handles)) (length handles)
5808 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5809
5810(defun gnus-unbuttonized-mime-type-p (type)
5811 "Say whether TYPE is to be unbuttonized."
5812 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5813 (when (catch 'found
5814 (let ((types gnus-unbuttonized-mime-types))
5815 (while types
5816 (when (string-match (pop types) type)
5817 (throw 'found t)))))
5818 (not (catch 'found
5819 (let ((types gnus-buttonized-mime-types))
5820 (while types
5821 (when (string-match (pop types) type)
5822 (throw 'found t)))))))))
16409b0b
GM
5823
5824(defun gnus-article-insert-newline ()
5825 "Insert a newline, but mark it as undeletable."
5826 (gnus-put-text-property
5827 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5828
5829(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5830 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5831 (ihandles handles)
5832 (point (point))
23f87bed 5833 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5834 (save-window-excursion
5835 (save-restriction
5836 (when ibegend
5837 (narrow-to-region (car ibegend)
5838 (or (cdr ibegend)
5839 (progn
5840 (goto-char (car ibegend))
5841 (forward-line 2)
5842 (point))))
5843 (delete-region (point-min) (point-max))
5844 (mm-remove-parts handles))
5845 (setq begend (list (point-marker)))
5846 ;; Do the toggle.
5847 (unless (setq not-pref (cadr (member preferred ihandles)))
5848 (setq not-pref (car ihandles)))
5849 (when (or ibegend
23f87bed 5850 (not preferred)
16409b0b
GM
5851 (not (gnus-unbuttonized-mime-type-p
5852 "multipart/alternative")))
5853 (gnus-add-text-properties
5854 (setq from (point))
5855 (progn
5856 (insert (format "%d. " id))
5857 (point))
5858 `(gnus-callback
5859 (lambda (handles)
5860 (unless ,(not ibegend)
5861 (setq gnus-article-mime-handle-alist
5862 ',gnus-article-mime-handle-alist))
5863 (gnus-mime-display-alternative
5864 ',ihandles ',not-pref ',begend ,id))
01c52d31 5865 keymap ,gnus-mime-button-map
16409b0b
GM
5866 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5867 face ,gnus-article-button-face
16409b0b 5868 gnus-part ,id
7dafe00b 5869 article-type multipart))
16409b0b
GM
5870 (widget-convert-button 'link from (point)
5871 :action 'gnus-widget-press-button
5872 :button-keymap gnus-widget-button-keymap)
5873 ;; Do the handles
5874 (while (setq handle (pop handles))
5875 (gnus-add-text-properties
5876 (setq from (point))
5877 (progn
5878 (insert (format "(%c) %-18s"
5879 (if (equal handle preferred) ?* ? )
5880 (mm-handle-media-type handle)))
5881 (point))
5882 `(gnus-callback
5883 (lambda (handles)
5884 (unless ,(not ibegend)
5885 (setq gnus-article-mime-handle-alist
5886 ',gnus-article-mime-handle-alist))
5887 (gnus-mime-display-alternative
5888 ',ihandles ',handle ',begend ,id))
01c52d31 5889 keymap ,gnus-mime-button-map
16409b0b
GM
5890 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5891 face ,gnus-article-button-face
16409b0b
GM
5892 gnus-part ,id
5893 gnus-data ,handle))
5894 (widget-convert-button 'link from (point)
5895 :action 'gnus-widget-press-button
5896 :button-keymap gnus-widget-button-keymap)
5897 (insert " "))
5898 (insert "\n\n"))
5899 (when preferred
5900 (if (stringp (car preferred))
5901 (gnus-display-mime preferred)
5902 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5903 (mail-parse-ignored-charsets
01c52d31
MB
5904 (with-current-buffer gnus-summary-buffer
5905 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
5906 (mm-display-part preferred)
5907 ;; Do highlighting.
5908 (save-excursion
5909 (save-restriction
5910 (narrow-to-region (car begend) (point-max))
5911 (gnus-treat-article
5912 nil (length gnus-article-mime-handle-alist)
e0bad764 5913 (gnus-article-mime-total-parts)
16409b0b
GM
5914 (mm-handle-media-type handle))))))
5915 (goto-char (point-max))
5916 (setcdr begend (point-marker)))))
5917 (when ibegend
5918 (goto-char point))))
5919
23f87bed
MB
5920(defconst gnus-article-wash-status-strings
5921 (let ((alist '((cite "c" "Possible hidden citation text"
5922 " " "All citation text visible")
5923 (headers "h" "Hidden headers"
5924 " " "All headers visible.")
5925 (pgp "p" "Encrypted or signed message status hidden"
5926 " " "No hidden encryption nor digital signature status")
5927 (signature "s" "Signature has been hidden"
5928 " " "Signature is visible")
5929 (overstrike "o" "Overstrike (^H) characters applied"
5930 " " "No overstrike characters applied")
5931 (emphasis "e" "/*_Emphasis_*/ characters applied"
5932 " " "No /*_emphasis_*/ characters applied")))
5933 result)
5934 (dolist (entry alist result)
5935 (let ((key (nth 0 entry))
5936 (on (copy-sequence (nth 1 entry)))
5937 (on-help (nth 2 entry))
5938 (off (copy-sequence (nth 3 entry)))
5939 (off-help (nth 4 entry)))
5940 (put-text-property 0 1 'help-echo on-help on)
5941 (put-text-property 0 1 'help-echo off-help off)
5942 (push (list key on off) result))))
5943 "Alist of strings describing wash status in the mode line.
5944Each entry has the form (KEY ON OF), where the KEY is a symbol
5945representing the particular washing function, ON is the string to use
5946in the article mode line when the washing function is active, and OFF
5947is the string to use when it is inactive.")
5948
5949(defun gnus-article-wash-status-entry (key value)
5950 (let ((entry (assoc key gnus-article-wash-status-strings)))
5951 (if value (nth 1 entry) (nth 2 entry))))
5952
eec82323
LMI
5953(defun gnus-article-wash-status ()
5954 "Return a string which display status of article washing."
01c52d31 5955 (with-current-buffer gnus-article-buffer
16409b0b
GM
5956 (let ((cite (memq 'cite gnus-article-wash-types))
5957 (headers (memq 'headers gnus-article-wash-types))
5958 (boring (memq 'boring-headers gnus-article-wash-types))
5959 (pgp (memq 'pgp gnus-article-wash-types))
5960 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
5961 (signed (memq 'signed gnus-article-wash-types))
5962 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
5963 (signature (memq 'signature gnus-article-wash-types))
5964 (overstrike (memq 'overstrike gnus-article-wash-types))
5965 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
5966 (concat
5967 (gnus-article-wash-status-entry 'cite cite)
5968 (gnus-article-wash-status-entry 'headers (or headers boring))
5969 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5970 (gnus-article-wash-status-entry 'signature signature)
5971 (gnus-article-wash-status-entry 'overstrike overstrike)
5972 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5973
5974(defun gnus-add-wash-type (type)
5975 "Add a washing of TYPE to the current status."
5976 (add-to-list 'gnus-article-wash-types type))
5977
5978(defun gnus-delete-wash-type (type)
5979 "Add a washing of TYPE to the current status."
5980 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5981
5982(defun gnus-add-image (category image)
5983 "Add IMAGE of CATEGORY to the list of displayed images."
5984 (let ((entry (assq category gnus-article-image-alist)))
5985 (unless entry
5986 (setq entry (list category))
5987 (push entry gnus-article-image-alist))
5988 (nconc entry (list image))))
5989
5990(defun gnus-delete-images (category)
5991 "Delete all images in CATEGORY."
5992 (let ((entry (assq category gnus-article-image-alist)))
5993 (dolist (image (cdr entry))
5994 (gnus-remove-image image category))
5995 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5996 (gnus-delete-wash-type category)))
eec82323 5997
16409b0b 5998(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
5999
6000(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
6001 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6002Provided for backwards compatibility."
16409b0b 6003 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
6004 (not (with-current-buffer gnus-summary-buffer
6005 gnus-have-all-headers)))
16409b0b
GM
6006 (not gnus-inhibit-hiding))
6007 (gnus-article-hide-headers)))
eec82323
LMI
6008
6009;;; Article savers.
6010
6011(defun gnus-output-to-file (file-name)
26c9afc3
MB
6012 "Append the current article to a file named FILE-NAME.
6013If `gnus-article-save-coding-system' is non-nil, it is used to encode
6014text and used as the value of the coding cookie which is added to the
6015top of a file. Otherwise, this function saves a raw article without
6016the coding cookie."
6017 (let* ((artbuf (current-buffer))
6018 (file-name-coding-system nnmail-pathname-coding-system)
6019 (coding gnus-article-save-coding-system)
6020 (coding-system-for-read (if coding
6021 nil ;; Rely on the coding cookie.
6022 mm-text-coding-system))
6023 (coding-system-for-write (or coding
6024 mm-text-coding-system-for-write
6025 mm-text-coding-system))
6026 (exists (file-exists-p file-name)))
16409b0b 6027 (with-temp-buffer
26c9afc3
MB
6028 (when exists
6029 (insert-file-contents file-name)
6030 (goto-char (point-min))
6031 ;; Remove the existing coding cookie.
6032 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6033 (delete-region (match-beginning 0) (match-end 0))))
6034 (goto-char (point-max))
eec82323
LMI
6035 (insert-buffer-substring artbuf)
6036 ;; Append newline at end of the buffer as separator, and then
6037 ;; save it to file.
6038 (goto-char (point-max))
6039 (insert "\n")
26c9afc3
MB
6040 (when coding
6041 ;; If the coding system is not suitable to encode the text,
6042 ;; ask a user for a proper one.
6043 (when (fboundp 'select-safe-coding-system)
6044 (setq coding (coding-system-base
6045 (save-window-excursion
6046 (select-safe-coding-system (point-min) (point-max)
6047 coding))))
6048 (setq coding-system-for-write
6049 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6050 coding)))
6051 (goto-char (point-min))
6052 ;; Add the coding cookie.
6053 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6054 coding-system-for-write)))
6055 (if exists
6056 (progn
6057 (write-region (point-min) (point-max) file-name nil 'no-message)
6058 (message "Appended to %s" file-name))
6059 (write-region (point-min) (point-max) file-name))))
6060 t)
eec82323
LMI
6061
6062(defun gnus-narrow-to-page (&optional arg)
6063 "Narrow the article buffer to a page.
6064If given a numerical ARG, move forward ARG pages."
6065 (interactive "P")
6066 (setq arg (if arg (prefix-numeric-value arg) 0))
80de1778 6067 (with-current-buffer gnus-article-buffer
eec82323
LMI
6068 (widen)
6069 ;; Remove any old next/prev buttons.
6070 (when (gnus-visual-p 'page-marker)
4e7d0221 6071 (let ((inhibit-read-only t))
eec82323
LMI
6072 (gnus-remove-text-with-property 'gnus-prev)
6073 (gnus-remove-text-with-property 'gnus-next)))
8f7abae3
MB
6074 (let (st nd pt)
6075 (when (save-excursion
6076 (cond ((< arg 0)
6077 (if (re-search-backward page-delimiter nil 'move (abs arg))
6078 (prog1
6079 (setq nd (match-beginning 0)
6080 pt nd)
6081 (when (re-search-backward page-delimiter nil t)
6082 (setq st (match-end 0))))
6083 (when (re-search-forward page-delimiter nil t)
6084 (setq nd (match-beginning 0)
6085 pt (point-min)))))
6086 ((> arg 0)
6087 (if (re-search-forward page-delimiter nil 'move arg)
6088 (prog1
6089 (setq st (match-end 0)
6090 pt st)
6091 (when (re-search-forward page-delimiter nil t)
6092 (setq nd (match-beginning 0))))
6093 (when (re-search-backward page-delimiter nil t)
6094 (setq st (match-end 0)
6095 pt (point-max)))))
6096 (t
6097 (when (re-search-backward page-delimiter nil t)
6098 (goto-char (setq st (match-end 0))))
6099 (when (re-search-forward page-delimiter nil t)
6100 (setq nd (match-beginning 0)))
6101 (or st nd))))
6102 (setq gnus-page-broken t)
6103 (when pt (goto-char pt))
6104 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6105 (when (gnus-visual-p 'page-marker)
6106 (save-excursion
6107 (when nd
6108 (goto-char nd)
6109 (gnus-insert-next-page-button))
6110 (when st
6111 (goto-char st)
6112 (gnus-insert-prev-page-button))))))))
eec82323
LMI
6113
6114;; Article mode commands
6115
6116(defun gnus-article-goto-next-page ()
6117 "Show the next page of the article."
6118 (interactive)
6119 (when (gnus-article-next-page)
6120 (goto-char (point-min))
6121 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6122
23f87bed 6123
eec82323 6124(defun gnus-article-goto-prev-page ()
23f87bed 6125 "Show the previous page of the article."
eec82323 6126 (interactive)
8f7abae3 6127 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
23f87bed 6128 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6129 (gnus-article-prev-page nil)))
6130
23f87bed
MB
6131;; This is cleaner but currently breaks `gnus-pick-mode':
6132;;
6133;; (defun gnus-article-goto-next-page ()
6134;; "Show the next page of the article."
6135;; (interactive)
6136;; (gnus-eval-in-buffer-window gnus-summary-buffer
6137;; (gnus-summary-next-page)))
6138;;
6139;; (defun gnus-article-goto-prev-page ()
6140;; "Show the next page of the article."
6141;; (interactive)
6142;; (gnus-eval-in-buffer-window gnus-summary-buffer
6143;; (gnus-summary-prev-page)))
6144
eec82323
LMI
6145(defun gnus-article-next-page (&optional lines)
6146 "Show the next page of the current article.
6147If end of article, return non-nil. Otherwise return nil.
6148Argument LINES specifies lines to be scrolled up."
6149 (interactive "p")
9153f10d 6150 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
60ece9b0
MB
6151 (if (and (not (and gnus-article-over-scroll
6152 (> (count-lines (window-start) (point-max))
9153f10d
MB
6153 (if (featurep 'xemacs)
6154 (or lines (1- (window-height)))
6155 (+ (or lines (1- (window-height))) scroll-margin)))))
60ece9b0
MB
6156 (save-excursion
6157 (end-of-line)
6158 (and (pos-visible-in-window-p) ;Not continuation line.
6159 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
eec82323
LMI
6160 ;; Nothing in this page.
6161 (if (or (not gnus-page-broken)
6162 (save-excursion
6163 (save-restriction
23f87bed
MB
6164 (widen)
6165 (forward-line)
6166 (eobp)))) ;Real end-of-buffer?
6167 (progn
6168 (when gnus-article-over-scroll
6169 (gnus-article-next-page-1 lines))
6170 t) ;Nothing more.
eec82323
LMI
6171 (gnus-narrow-to-page 1) ;Go to next page.
6172 nil)
6173 ;; More in this page.
23f87bed 6174 (gnus-article-next-page-1 lines)
eec82323
LMI
6175 nil))
6176
d8a88581
MB
6177(defmacro gnus-article-beginning-of-window ()
6178 "Move point to the beginning of the window.
6179In Emacs, the point is placed at the line number which `scroll-margin'
6180specifies."
6181 (if (featurep 'xemacs)
6182 '(move-to-window-line 0)
6183 '(move-to-window-line
6184 (min (max 0 scroll-margin)
6185 (max 1 (- (window-height)
6186 (if mode-line-format 1 0)
9153f10d
MB
6187 (if header-line-format 1 0)
6188 2))))))
d8a88581 6189
23f87bed 6190(defun gnus-article-next-page-1 (lines)
9153f10d 6191 (unless (featurep 'xemacs)
4b91459a
MB
6192 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6193 ;; too many number of lines if `scroll-margin' is set as two or greater.
9153f10d
MB
6194 (when (and (numberp lines)
6195 (> lines 0)
6196 (> scroll-margin 0))
6197 (setq lines (min lines
6198 (max 0 (- (count-lines (window-start) (point-max))
6199 scroll-margin))))))
4b91459a
MB
6200 (condition-case ()
6201 (let ((scroll-in-place nil))
6202 (scroll-up lines))
6203 (end-of-buffer
6204 ;; Long lines may cause an end-of-buffer error.
6205 (goto-char (point-max))))
6206 (gnus-article-beginning-of-window))
23f87bed 6207
eec82323
LMI
6208(defun gnus-article-prev-page (&optional lines)
6209 "Show previous page of current article.
6210Argument LINES specifies lines to be scrolled down."
6211 (interactive "p")
d8a88581 6212 (move-to-window-line 0)
eec82323
LMI
6213 (if (and gnus-page-broken
6214 (bobp)
6215 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6216 (progn
6217 (gnus-narrow-to-page -1) ;Go to previous page.
6218 (goto-char (point-max))
60ece9b0
MB
6219 (recenter (if gnus-article-over-scroll
6220 (if lines
9153f10d
MB
6221 (max (if (featurep 'xemacs)
6222 lines
6223 (+ lines scroll-margin))
60ece9b0
MB
6224 3)
6225 (- (window-height) 2))
6226 -1)))
c03ac728
MB
6227 (prog1
6228 (condition-case ()
6229 (let ((scroll-in-place nil))
6230 (scroll-down lines))
6231 (beginning-of-buffer
6232 (goto-char (point-min))))
6233 (gnus-article-beginning-of-window))))
eec82323 6234
23f87bed
MB
6235(defun gnus-article-only-boring-p ()
6236 "Decide whether there is only boring text remaining in the article.
6237Something \"interesting\" is a word of at least two letters that does
6238not have a face in `gnus-article-boring-faces'."
6239 (when (and gnus-article-skip-boring
6240 (boundp 'gnus-article-boring-faces)
6241 (symbol-value 'gnus-article-boring-faces))
6242 (save-excursion
531bedc3
MB
6243 (let ((inhibit-point-motion-hooks t))
6244 (catch 'only-boring
6245 (while (re-search-forward "\\b\\w\\w" nil t)
6246 (forward-char -1)
6247 (when (not (gnus-intersection
6248 (gnus-faces-at (point))
6249 (symbol-value 'gnus-article-boring-faces)))
6250 (throw 'only-boring nil)))
6251 (throw 'only-boring t))))))
23f87bed 6252
eec82323
LMI
6253(defun gnus-article-refer-article ()
6254 "Read article specified by message-id around point."
6255 (interactive)
23f87bed 6256 (save-excursion
01c52d31
MB
6257 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6258 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6259 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6260 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6261 (set-buffer gnus-summary-buffer)
23f87bed 6262 (gnus-summary-refer-article msg-id))
eec82323
LMI
6263 (error "No references around point"))))
6264
6265(defun gnus-article-show-summary ()
6266 "Reconfigure windows to show summary buffer."
6267 (interactive)
6268 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6269 (error "There is no summary buffer for this article buffer")
a8151ef7 6270 (gnus-article-set-globals)
eec82323 6271 (gnus-configure-windows 'article)
6748645f
LMI
6272 (gnus-summary-goto-subject gnus-current-article)
6273 (gnus-summary-position-point)))
eec82323
LMI
6274
6275(defun gnus-article-describe-briefly ()
6276 "Describe article mode commands briefly."
6277 (interactive)
16409b0b 6278 (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 6279
16409b0b
GM
6280(defun gnus-article-check-buffer ()
6281 "Beep if not in an article buffer."
6282 (unless (equal major-mode 'gnus-article-mode)
6283 (error "Command invoked outside of a Gnus article buffer")))
6284
eec82323
LMI
6285(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6286 "Read a summary buffer key sequence and execute it from the article buffer."
6287 (interactive "P")
16409b0b 6288 (gnus-article-check-buffer)
eec82323 6289 (let ((nosaves
23f87bed
MB
6290 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6291 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6292 "=" "^" "\M-^" "|"))
6293 (nosave-but-article
0b6799c3
MB
6294 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6295 "An" "Ap" [?A (meta return)] [?A delete]))
23f87bed 6296 (nosave-in-article
0b6799c3 6297 '("AS" "\C-d"))
23f87bed
MB
6298 (up-to-top
6299 '("n" "Gn" "p" "Gp"))
6300 keys new-sum-point)
80de1778 6301 (with-current-buffer gnus-article-current-summary
eec82323 6302 (let (gnus-pick-mode)
95838435
MB
6303 (setq unread-command-events (nconc unread-command-events
6304 (list (or key last-command-event)))
6305 keys (if (featurep 'xemacs)
6306 (events-to-keys (read-key-sequence nil t))
6307 (read-key-sequence nil t)))))
a1506d29 6308
eec82323
LMI
6309 (message "")
6310
01c52d31
MB
6311 (cond
6312 ((eq (aref keys (1- (length keys))) ?\C-h)
0b6799c3 6313 (gnus-article-describe-bindings (substring keys 0 -1)))
01c52d31
MB
6314 ((or (member keys nosaves)
6315 (member keys nosave-but-article)
6316 (member keys nosave-in-article))
6317 (let (func)
6318 (save-window-excursion
6319 (pop-to-buffer gnus-article-current-summary)
6320 ;; We disable the pick minor mode commands.
6321 (let (gnus-pick-mode)
6ab2c7a8 6322 (setq func (key-binding keys t))))
01c52d31
MB
6323 (if (or (not func)
6324 (numberp func))
6325 (ding)
6326 (unless (member keys nosave-in-article)
6327 (set-buffer gnus-article-current-summary))
6328 (call-interactively func)
6329 (setq new-sum-point (point)))
6330 (when (member keys nosave-but-article)
6331 (pop-to-buffer gnus-article-buffer))))
6332 (t
eec82323
LMI
6333 ;; These commands should restore window configuration.
6334 (let ((obuf (current-buffer))
23f87bed 6335 (owin (current-window-configuration))
01c52d31 6336 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6337 (cond (not-restore-window
01c52d31
MB
6338 (pop-to-buffer gnus-article-current-summary)
6339 (setq win (selected-window)))
23f87bed
MB
6340 ((setq win (get-buffer-window gnus-article-current-summary))
6341 (select-window win))
6342 (t
01c52d31
MB
6343 (let ((summary-buffer gnus-article-current-summary))
6344 (gnus-configure-windows 'article)
6345 (unless (setq win (get-buffer-window summary-buffer 'visible))
6346 (let ((gnus-buffer-configuration
6347 '(article ((vertical 1.0
6348 (summary 0.25 point)
6349 (article 1.0))))))
6350 (gnus-configure-windows 'article))
6351 (setq win (get-buffer-window summary-buffer 'visible)))
6352 (gnus-select-frame-set-input-focus (window-frame win))
6353 (select-window win))))
23f87bed
MB
6354 (setq in-buffer (current-buffer))
6355 ;; We disable the pick minor mode commands.
6356 (if (and (setq func (let (gnus-pick-mode)
6ab2c7a8 6357 (key-binding keys t)))
01c52d31
MB
6358 (functionp func)
6359 (condition-case code
6360 (progn
6361 (call-interactively func)
6362 t)
6363 (error
6364 (setq err code)
6365 nil)))
23f87bed 6366 (progn
23f87bed
MB
6367 (when (eq win (selected-window))
6368 (setq new-sum-point (point)
6369 new-sum-start (window-start win)
9a89f5b0 6370 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6371 (when (or (eq in-buffer (current-buffer))
6372 (when (eq obuf (current-buffer))
6373 (set-buffer in-buffer)
6374 t))
520aa572
SZ
6375 (setq selected (gnus-summary-select-article))
6376 (set-buffer obuf)
6377 (unless not-restore-window
6378 (set-window-configuration owin))
01c52d31
MB
6379 (when (and (eq selected 'old)
6380 new-sum-point)
520aa572
SZ
6381 (set-window-start (get-buffer-window (current-buffer))
6382 1)
6383 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6384 (if (article-goto-body)
6385 (1- (point))
6386 (point))))
23f87bed 6387 (when (and (not not-restore-window)
01c52d31 6388 new-sum-point
4520e527 6389 (window-live-p win)
01c52d31
MB
6390 (with-current-buffer (window-buffer win)
6391 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6392 (set-window-point win new-sum-point)
6393 (set-window-start win new-sum-start)
9a89f5b0 6394 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6395 (set-window-configuration owin)
01c52d31
MB
6396 (if err
6397 (signal (car err) (cdr err))
6398 (ding))))))))
520aa572 6399
95838435
MB
6400(defun gnus-article-read-summary-send-keys ()
6401 (interactive)
0b6799c3 6402 (let ((unread-command-events (list (gnus-character-to-event ?S))))
95838435
MB
6403 (gnus-article-read-summary-keys)))
6404
520aa572 6405(defun gnus-article-describe-key (key)
95838435
MB
6406 "Display documentation of the function invoked by KEY.
6407KEY is a string or a vector."
6408 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6409 (read-key-sequence "Describe key: "))))
520aa572 6410 (gnus-article-check-buffer)
95838435
MB
6411 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6412 gnus-article-read-summary-send-keys))
80de1778 6413 (with-current-buffer gnus-article-current-summary
95838435
MB
6414 (setq unread-command-events
6415 (if (featurep 'xemacs)
6416 (append key nil)
6417 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6418 (list 'meta (- x 128))
6419 x))
6420 key)))
6421 (let ((cursor-in-echo-area t)
6422 gnus-pick-mode)
6423 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6424 (describe-key key)))
6425
6426(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6427 "Display documentation of the function invoked by KEY.
6428KEY is a string or a vector."
6429 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6430 (read-key-sequence "Describe key: "))
6431 current-prefix-arg))
520aa572 6432 (gnus-article-check-buffer)
95838435
MB
6433 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6434 gnus-article-read-summary-send-keys))
80de1778 6435 (with-current-buffer gnus-article-current-summary
95838435
MB
6436 (setq unread-command-events
6437 (if (featurep 'xemacs)
6438 (append key nil)
6439 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6440 (list 'meta (- x 128))
6441 x))
6442 key)))
6443 (let ((cursor-in-echo-area t)
6444 gnus-pick-mode)
6445 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6446 (describe-key-briefly key insert)))
eec82323 6447
0b6799c3
MB
6448;;`gnus-agent-mode' in gnus-agent.el will define it.
6449(defvar gnus-agent-summary-mode)
e9198520 6450(defvar gnus-draft-mode)
0b6799c3
MB
6451
6452(defun gnus-article-describe-bindings (&optional prefix)
6453 "Show a list of all defined keys, and their definitions.
6454The optional argument PREFIX, if non-nil, should be a key sequence;
6455then we display only bindings that start with that prefix."
6456 (interactive)
6457 (gnus-article-check-buffer)
6458 (let ((keymap (copy-keymap gnus-article-mode-map))
6459 (map (copy-keymap gnus-article-send-map))
6460 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
e9198520 6461 agent draft)
0b6799c3
MB
6462 (define-key keymap "S" map)
6463 (define-key map [t] nil)
6464 (with-current-buffer gnus-article-current-summary
6465 (set-keymap-parent map (key-binding "S"))
8f7abae3
MB
6466 (let (key def gnus-pick-mode)
6467 (while sumkeys
6468 (setq key (pop sumkeys))
6469 (cond ((and (vectorp key) (= (length key) 1)
6470 (consp (setq def (aref key 0)))
6471 (numberp (car def)) (numberp (cdr def)))
6472 (when (< (max (car def) (cdr def)) 128)
6473 (setq sumkeys
6474 (append (mapcar
6475 #'vector
6476 (nreverse (gnus-uncompress-range def)))
6477 sumkeys))))
6478 ((setq def (key-binding key))
6479 (unless (eq def 'undefined)
6480 (define-key keymap key def))))))
0b6799c3 6481 (when (boundp 'gnus-agent-summary-mode)
e9198520
MB
6482 (setq agent gnus-agent-summary-mode))
6483 (when (boundp 'gnus-draft-mode)
6484 (setq draft gnus-draft-mode)))
0b6799c3
MB
6485 (with-temp-buffer
6486 (use-local-map keymap)
6487 (set (make-local-variable 'gnus-agent-summary-mode) agent)
e9198520 6488 (set (make-local-variable 'gnus-draft-mode) draft)
0b6799c3
MB
6489 (describe-bindings prefix))
6490 (let ((item `((lambda (prefix)
80de1778 6491 (with-current-buffer ,(current-buffer)
0b6799c3
MB
6492 (gnus-article-describe-bindings prefix)))
6493 ,prefix)))
6494 (with-current-buffer (if (fboundp 'help-buffer)
6495 (let (help-xref-following) (help-buffer))
6496 "*Help*") ;; Emacs 21
6497 (setq help-xref-stack-item item)))))
6498
23f87bed
MB
6499(defun gnus-article-reply-with-original (&optional wide)
6500 "Start composing a reply mail to the current message.
6501The text in the region will be yanked. If the region isn't active,
6502the entire article will be yanked."
95838435 6503 (interactive)
23f87bed
MB
6504 (let ((article (cdr gnus-article-current))
6505 contents)
1d0df8af 6506 (if (not (gnus-region-active-p))
23f87bed
MB
6507 (with-current-buffer gnus-summary-buffer
6508 (gnus-summary-reply (list (list article)) wide))
6509 (setq contents (buffer-substring (point) (mark t)))
6510 ;; Deactivate active regions.
6511 (when (and (boundp 'transient-mark-mode)
6512 transient-mark-mode)
6513 (setq mark-active nil))
6514 (with-current-buffer gnus-summary-buffer
6515 (gnus-summary-reply
6516 (list (list article contents)) wide)))))
6517
95838435
MB
6518(defun gnus-article-wide-reply-with-original ()
6519 "Start composing a wide reply mail to the current message.
6520The text in the region will be yanked. If the region isn't active,
6521the entire article will be yanked."
6522 (interactive)
6523 (gnus-article-reply-with-original t))
6524
23f87bed
MB
6525(defun gnus-article-followup-with-original ()
6526 "Compose a followup to the current article.
6527The text in the region will be yanked. If the region isn't active,
6528the entire article will be yanked."
6529 (interactive)
6530 (let ((article (cdr gnus-article-current))
6531 contents)
1d0df8af 6532 (if (not (gnus-region-active-p))
23f87bed
MB
6533 (with-current-buffer gnus-summary-buffer
6534 (gnus-summary-followup (list (list article))))
6535 (setq contents (buffer-substring (point) (mark t)))
6536 ;; Deactivate active regions.
6537 (when (and (boundp 'transient-mark-mode)
6538 transient-mark-mode)
6539 (setq mark-active nil))
6540 (with-current-buffer gnus-summary-buffer
6541 (gnus-summary-followup
6542 (list (list article contents)))))))
6543
eec82323
LMI
6544(defun gnus-article-hide (&optional arg force)
6545 "Hide all the gruft in the current article.
23f87bed
MB
6546This means that signatures, cited text and (some) headers will be
6547hidden.
eec82323 6548If given a prefix, show the hidden text instead."
6748645f 6549 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6550 (gnus-article-hide-headers arg)
16409b0b 6551 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6552 (gnus-article-hide-citation-maybe arg force)
6553 (gnus-article-hide-signature arg))
6554
6555(defun gnus-article-maybe-highlight ()
6748645f 6556 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6557 (when (gnus-visual-p 'article-highlight 'highlight)
6558 (gnus-article-highlight-some)))
6559
6748645f
LMI
6560(defun gnus-check-group-server ()
6561 ;; Make sure the connection to the server is alive.
6562 (unless (gnus-server-opened
6563 (gnus-find-method-for-group gnus-newsgroup-name))
6564 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6565 (gnus-request-group gnus-newsgroup-name t)))
6566
23f87bed
MB
6567(eval-when-compile
6568 (autoload 'nneething-get-file-name "nneething"))
6569
eec82323
LMI
6570(defun gnus-request-article-this-buffer (article group)
6571 "Get an article and insert it into this buffer."
6748645f 6572 (let (do-update-line sparse-header)
eec82323
LMI
6573 (prog1
6574 (save-excursion
6575 (erase-buffer)
6576 (gnus-kill-all-overlays)
6577 (setq group (or group gnus-newsgroup-name))
6578
eec82323
LMI
6579 ;; Using `gnus-request-article' directly will insert the article into
6580 ;; `nntp-server-buffer' - so we'll save some time by not having to
6581 ;; copy it from the server buffer into the article buffer.
6582
6583 ;; We only request an article by message-id when we do not have the
6584 ;; headers for it, so we'll have to get those.
6585 (when (stringp article)
16409b0b 6586 (gnus-read-header article))
eec82323
LMI
6587
6588 ;; If the article number is negative, that means that this article
6589 ;; doesn't belong in this newsgroup (possibly), so we find its
6590 ;; message-id and request it by id instead of number.
6591 (when (and (numberp article)
6592 gnus-summary-buffer
6593 (get-buffer gnus-summary-buffer)
6748645f 6594 (gnus-buffer-exists-p gnus-summary-buffer))
80de1778 6595 (with-current-buffer gnus-summary-buffer
eec82323
LMI
6596 (let ((header (gnus-summary-article-header article)))
6597 (when (< article 0)
6598 (cond
6599 ((memq article gnus-newsgroup-sparse)
6600 ;; This is a sparse gap article.
6601 (setq do-update-line article)
6602 (setq article (mail-header-id header))
16409b0b 6603 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6604 (setq gnus-newsgroup-sparse
6605 (delq article gnus-newsgroup-sparse)))
6606 ((vectorp header)
6607 ;; It's a real article.
6608 (setq article (mail-header-id header)))
6609 (t
6610 ;; It is an extracted pseudo-article.
6611 (setq article 'pseudo)
6612 (gnus-request-pseudo-article header))))
6613
6614 (let ((method (gnus-find-method-for-group
6615 gnus-newsgroup-name)))
6748645f
LMI
6616 (when (and (eq (car method) 'nneething)
6617 (vectorp header))
23f87bed
MB
6618 (let ((dir (nneething-get-file-name
6619 (mail-header-id header))))
6620 (when (and (stringp dir)
6621 (file-directory-p dir))
eec82323
LMI
6622 (setq article 'nneething)
6623 (gnus-group-enter-directory dir))))))))
6624
6625 (cond
6626 ;; Refuse to select canceled articles.
6627 ((and (numberp article)
6628 gnus-summary-buffer
6629 (get-buffer gnus-summary-buffer)
6748645f 6630 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6631 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6632 (assq article gnus-newsgroup-reads)))
6633 gnus-canceled-mark))
6634 nil)
6635 ;; We first check `gnus-original-article-buffer'.
6636 ((and (get-buffer gnus-original-article-buffer)
6637 (numberp article)
01c52d31 6638 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6639 (and (equal (car gnus-original-article) group)
6640 (eq (cdr gnus-original-article) article))))
75eda25b
SM
6641 ;; `insert-buffer-substring' would incorrectly use the
6642 ;; equivalent of string-make-multibyte which amount to decoding
6643 ;; with locale-coding-system, causing failure of
6644 ;; subsequent decoding.
6645 (insert (mm-string-to-multibyte
6646 (with-current-buffer gnus-original-article-buffer
6647 (buffer-substring (point-min) (point-max)))))
eec82323
LMI
6648 'article)
6649 ;; Check the backlog.
6650 ((and gnus-keep-backlog
6651 (gnus-backlog-request-article group article (current-buffer)))
6652 'article)
6653 ;; Check asynchronous pre-fetch.
6654 ((gnus-async-request-fetched-article group article (current-buffer))
6655 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6656 (when (and (numberp article) gnus-keep-backlog)
6657 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6658 'article)
6659 ;; Check the cache.
6660 ((and gnus-use-cache
6661 (numberp article)
6662 (gnus-cache-request-article article group))
6663 'article)
23f87bed
MB
6664 ;; Check the agent cache.
6665 ((gnus-agent-request-article article group)
6666 'article)
eec82323 6667 ;; Get the article and put into the article buffer.
16409b0b
GM
6668 ((or (stringp article)
6669 (numberp article))
6670 (let ((gnus-override-method gnus-override-method)
a1506d29 6671 (methods (and (stringp article)
16409b0b 6672 gnus-refer-article-method))
23f87bed
MB
6673 (backend (car (gnus-find-method-for-group
6674 gnus-newsgroup-name)))
16409b0b 6675 result
4e7d0221 6676 (inhibit-read-only t))
e0bad764
DL
6677 (if (or (not (listp methods))
6678 (and (symbolp (car methods))
6679 (assq (car methods) nnoo-definition-alist)))
6680 (setq methods (list methods)))
16409b0b
GM
6681 (when (and (null gnus-override-method)
6682 methods)
6683 (setq gnus-override-method (pop methods)))
6684 (while (not result)
6685 (when (eq gnus-override-method 'current)
c55f89a5
GM
6686 (setq gnus-override-method
6687 (with-current-buffer gnus-summary-buffer
6688 gnus-current-select-method)))
16409b0b
GM
6689 (erase-buffer)
6690 (gnus-kill-all-overlays)
6691 (let ((gnus-newsgroup-name group))
6692 (gnus-check-group-server))
23f87bed
MB
6693 (cond
6694 ((gnus-request-article article group (current-buffer))
16409b0b 6695 (when (numberp article)
a1506d29 6696 (gnus-async-prefetch-next group article
16409b0b
GM
6697 gnus-summary-buffer)
6698 (when gnus-keep-backlog
6699 (gnus-backlog-enter-article
6700 group article (current-buffer))))
6701 (setq result 'article))
23f87bed
MB
6702 (methods
6703 (setq gnus-override-method (pop methods)))
6704 ((not (string-match "^400 "
6705 (nnheader-get-report backend)))
6706 ;; If we get 400 server disconnect, reconnect and
6707 ;; retry; otherwise, assume the article has expired.
6708 (setq result 'done))))
16409b0b 6709 (and (eq result 'article) 'article)))
eec82323
LMI
6710 ;; It was a pseudo.
6711 (t article)))
6712
6748645f
LMI
6713 ;; Associate this article with the current summary buffer.
6714 (setq gnus-article-current-summary gnus-summary-buffer)
6715
eec82323
LMI
6716 ;; Take the article from the original article buffer
6717 ;; and place it in the buffer it's supposed to be in.
6718 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6719 (equal (buffer-name (current-buffer))
6720 (buffer-name (get-buffer gnus-article-buffer))))
6721 (save-excursion
6722 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6723 (set-buffer gnus-original-article-buffer)
6724 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6725 (buffer-disable-undo)
eec82323 6726 (setq major-mode 'gnus-original-article-mode)
6748645f 6727 (setq buffer-read-only t))
23f87bed 6728 (let ((inhibit-read-only t))
eec82323
LMI
6729 (erase-buffer)
6730 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6731 (setq gnus-original-article (cons group article)))
6732
6733 ;; Decode charsets.
6734 (run-hooks 'gnus-article-decode-hook)
6735 ;; Mark article as decoded or not.
6736 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6737
6738 ;; Update sparse articles.
6739 (when (and do-update-line
6740 (or (numberp article)
6741 (stringp article)))
6742 (let ((buf (current-buffer)))
6743 (set-buffer gnus-summary-buffer)
6748645f 6744 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6745 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6746 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6747 (point))
6748 (set-buffer buf))))))
6749
6750;;;
6751;;; Article editing
6752;;;
6753
6754(defcustom gnus-article-edit-mode-hook nil
6755 "Hook run in article edit mode buffers."
6756 :group 'gnus-article-various
6757 :type 'hook)
6758
6759(defvar gnus-article-edit-done-function nil)
6760
6761(defvar gnus-article-edit-mode-map nil)
6762
16409b0b 6763;; Should we be using derived.el for this?
eec82323 6764(unless gnus-article-edit-mode-map
23f87bed 6765 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6766 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6767
6768 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6769 "\C-c?" describe-mode
eec82323 6770 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6771 "\C-c\C-k" gnus-article-edit-exit
6772 "\C-c\C-f\C-t" message-goto-to
6773 "\C-c\C-f\C-o" message-goto-from
6774 "\C-c\C-f\C-b" message-goto-bcc
6775 ;;"\C-c\C-f\C-w" message-goto-fcc
6776 "\C-c\C-f\C-c" message-goto-cc
6777 "\C-c\C-f\C-s" message-goto-subject
6778 "\C-c\C-f\C-r" message-goto-reply-to
6779 "\C-c\C-f\C-n" message-goto-newsgroups
6780 "\C-c\C-f\C-d" message-goto-distribution
6781 "\C-c\C-f\C-f" message-goto-followup-to
6782 "\C-c\C-f\C-m" message-goto-mail-followup-to
6783 "\C-c\C-f\C-k" message-goto-keywords
6784 "\C-c\C-f\C-u" message-goto-summary
6785 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6786 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6787 "\C-c\C-b" message-goto-body
6788 "\C-c\C-i" message-goto-signature
6789
6790 "\C-c\C-t" message-insert-to
6791 "\C-c\C-n" message-insert-newsgroups
6792 "\C-c\C-o" message-sort-headers
6793 "\C-c\C-e" message-elide-region
6794 "\C-c\C-v" message-delete-not-region
6795 "\C-c\C-z" message-kill-to-signature
6796 "\M-\r" message-newline-and-reformat
6797 "\C-c\C-a" mml-attach-file
6798 "\C-a" message-beginning-of-line
6799 "\t" message-tab
6800 "\M-;" comment-region)
eec82323
LMI
6801
6802 (gnus-define-keys (gnus-article-edit-wash-map
6803 "\C-c\C-w" gnus-article-edit-mode-map)
6804 "f" gnus-article-edit-full-stops))
6805
23f87bed
MB
6806(easy-menu-define
6807 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6808 '("Field"
6809 ["Fetch To" message-insert-to t]
6810 ["Fetch Newsgroups" message-insert-newsgroups t]
6811 "----"
6812 ["To" message-goto-to t]
6813 ["From" message-goto-from t]
6814 ["Subject" message-goto-subject t]
6815 ["Cc" message-goto-cc t]
6816 ["Reply-To" message-goto-reply-to t]
6817 ["Summary" message-goto-summary t]
6818 ["Keywords" message-goto-keywords t]
6819 ["Newsgroups" message-goto-newsgroups t]
6820 ["Followup-To" message-goto-followup-to t]
6821 ["Mail-Followup-To" message-goto-mail-followup-to t]
6822 ["Distribution" message-goto-distribution t]
6823 ["Body" message-goto-body t]
6824 ["Signature" message-goto-signature t]))
6825
4e7d0221 6826(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6827 "Major mode for editing articles.
6828This is an extended text-mode.
6829
6830\\{gnus-article-edit-mode-map}"
eec82323
LMI
6831 (make-local-variable 'gnus-article-edit-done-function)
6832 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6833 (set (make-local-variable 'font-lock-defaults)
6834 '(message-font-lock-keywords t))
23f87bed
MB
6835 (set (make-local-variable 'mail-header-separator) "")
6836 (set (make-local-variable 'gnus-article-edit-mode) t)
6837 (easy-menu-add message-mode-field-menu message-mode-map)
6838 (mml-mode)
eec82323
LMI
6839 (setq buffer-read-only nil)
6840 (buffer-enable-undo)
80b47379 6841 (widen))
eec82323
LMI
6842
6843(defun gnus-article-edit (&optional force)
6844 "Edit the current article.
6845This will have permanent effect only in mail groups.
6846If FORCE is non-nil, allow editing of articles even in read-only
6847groups."
6848 (interactive "P")
6849 (when (and (not force)
6850 (gnus-group-read-only-p))
a8151ef7 6851 (error "The current newsgroup does not support article editing"))
6748645f 6852 (gnus-article-date-original)
eec82323 6853 (gnus-article-edit-article
16409b0b 6854 'ignore
6748645f 6855 `(lambda (no-highlight)
16409b0b 6856 'ignore
eec82323
LMI
6857 (gnus-summary-edit-article-done
6858 ,(or (mail-header-references gnus-current-headers) "")
6748645f 6859 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 6860
01c52d31 6861(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
6862 "Start editing the contents of the current article buffer."
6863 (let ((winconf (current-window-configuration)))
6864 (set-buffer gnus-article-buffer)
0683d241
MB
6865 (let ((message-auto-save-directory
6866 ;; Don't associate the article buffer with a draft file.
6867 nil))
6868 (gnus-article-edit-mode))
16409b0b 6869 (funcall start-func)
23f87bed 6870 (set-buffer-modified-p nil)
eec82323
LMI
6871 (gnus-configure-windows 'edit-article)
6872 (setq gnus-article-edit-done-function exit-func)
6873 (setq gnus-prev-winconf winconf)
01c52d31
MB
6874 (unless quiet
6875 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 6876
6748645f 6877(defun gnus-article-edit-done (&optional arg)
eec82323 6878 "Update the article edits and exit."
6748645f 6879 (interactive "P")
eec82323
LMI
6880 (let ((func gnus-article-edit-done-function)
6881 (buf (current-buffer))
23f87bed
MB
6882 (start (window-start))
6883 (p (point))
6884 (winconf gnus-prev-winconf))
6885 (widen) ;; Widen it in case that users narrowed the buffer.
6886 (funcall func arg)
6887 (set-buffer buf)
6888 ;; The cache and backlog have to be flushed somewhat.
6889 (when gnus-keep-backlog
6890 (gnus-backlog-remove-article
6891 (car gnus-article-current) (cdr gnus-article-current)))
6892 ;; Flush original article as well.
80de1778
SM
6893 (when (get-buffer gnus-original-article-buffer)
6894 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
6895 (setq gnus-original-article nil)))
6896 (when gnus-use-cache
6897 (gnus-cache-update-article
6898 (car gnus-article-current) (cdr gnus-article-current)))
6899 ;; We remove all text props from the article buffer.
6900 (kill-all-local-variables)
01c52d31 6901 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
6902 (gnus-article-mode)
6903 (set-window-configuration winconf)
eec82323
LMI
6904 (set-buffer buf)
6905 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
6906 (set-window-point (get-buffer-window buf) (point)))
6907 (gnus-summary-show-article))
eec82323
LMI
6908
6909(defun gnus-article-edit-exit ()
6910 "Exit the article editing without updating."
6911 (interactive)
23f87bed
MB
6912 (when (or (not (buffer-modified-p))
6913 (yes-or-no-p "Article modified; kill anyway? "))
6914 (let ((curbuf (current-buffer))
6915 (p (point))
6916 (window-start (window-start)))
6917 (erase-buffer)
6918 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 6919 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
6920 (let ((winconf gnus-prev-winconf))
6921 (kill-all-local-variables)
6922 (gnus-article-mode)
6923 (set-window-configuration winconf)
6924 ;; Tippy-toe some to make sure that point remains where it was.
6925 (save-current-buffer
6926 (set-buffer curbuf)
6927 (set-window-start (get-buffer-window (current-buffer)) window-start)
6928 (goto-char p))))
6929 (gnus-summary-show-article)))
eec82323
LMI
6930
6931(defun gnus-article-edit-full-stops ()
6932 "Interactively repair spacing at end of sentences."
6933 (interactive)
6934 (save-excursion
6935 (goto-char (point-min))
6936 (search-forward-regexp "^$" nil t)
6937 (let ((case-fold-search nil))
6938 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6939
6940;;;
6941;;; Article highlights
6942;;;
6943
6944;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6945
6946;;; Internal Variables:
6947
a1506d29 6948(defcustom gnus-button-url-regexp
01c52d31
MB
6949 (concat
6950 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6951 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6952 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6953 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6954 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6955 (punct "!?:;.,"))
6956 (concat
6957 "\\(?:"
6958 ;; Match paired parentheses, e.g. in Wikipedia URLs:
9b3ebcb6
MB
6959 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
6960 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
01c52d31
MB
6961 "\\|"
6962 "[" chars punct "]+" "[" chars "]"
6963 "\\)"))
6964 (concat ;; XEmacs 21.4 doesn't support POSIX.
6965 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6966 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6967 "\\)")
eec82323
LMI
6968 "Regular expression that matches URLs."
6969 :group 'gnus-article-buttons
6970 :type 'regexp)
6971
23f87bed
MB
6972(defcustom gnus-button-valid-fqdn-regexp
6973 message-valid-fqdn-regexp
6974 "Regular expression that matches a valid FQDN."
bf247b6e 6975 :version "22.1"
23f87bed
MB
6976 :group 'gnus-article-buttons
6977 :type 'regexp)
6978
97f78c9b
MB
6979;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6980(defcustom gnus-button-valid-localpart-regexp
14e6dc54 6981 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
6982 "Regular expression that matches a localpart of mail addresses or MIDs."
6983 :version "22.1"
6984 :group 'gnus-article-buttons
6985 :type 'regexp)
6986
23f87bed
MB
6987(defcustom gnus-button-man-handler 'manual-entry
6988 "Function to use for displaying man pages.
6989The function must take at least one argument with a string naming the
6990man page."
bf247b6e 6991 :version "22.1"
23f87bed
MB
6992 :type '(choice (function-item :tag "Man" manual-entry)
6993 (function-item :tag "Woman" woman)
6994 (function :tag "Other"))
6995 :group 'gnus-article-buttons)
6996
6997(defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6998 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6999If the default site is too slow, try to find a CTAN mirror, see
7000<URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
7001the variable `gnus-button-handle-ctan'."
bf247b6e 7002 :version "22.1"
23f87bed
MB
7003 :group 'gnus-article-buttons
7004 :link '(custom-manual "(gnus)Group Parameters")
7005 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
7006 (const "http://tug.ctan.org/tex-archive/")
7007 (const "http://www.dante.de/CTAN/")
7008 (string :tag "Other")))
7009
7010(defcustom gnus-button-ctan-handler 'browse-url
7011 "Function to use for displaying CTAN links.
7012The function must take one argument, the string naming the URL."
bf247b6e 7013 :version "22.1"
23f87bed
MB
7014 :type '(choice (function-item :tag "Browse Url" browse-url)
7015 (function :tag "Other"))
7016 :group 'gnus-article-buttons)
7017
7018(defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
7019 "Bogus strings removed from CTAN URLs."
bf247b6e 7020 :version "22.1"
23f87bed
MB
7021 :group 'gnus-article-buttons
7022 :type '(choice (const "^/?tex-archive/\\|/")
7023 (regexp :tag "Other")))
7024
7025(defcustom gnus-button-ctan-directory-regexp
97f78c9b
MB
7026 (regexp-opt
7027 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
7028 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
7029 "languages" "macros" "nonfree" "obsolete" "support" "systems"
7030 "tds" "tools" "usergrps" "web") t)
23f87bed
MB
7031 "Regular expression for ctan directories.
7032It should match all directories in the top level of `gnus-ctan-url'."
bf247b6e 7033 :version "22.1"
23f87bed
MB
7034 :group 'gnus-article-buttons
7035 :type 'regexp)
7036
7037(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 7038 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
7039 gnus-button-valid-fqdn-regexp
7040 ">?\\)\\b")
7041 "Regular expression that matches a message ID or a mail address."
bf247b6e 7042 :version "22.1"
23f87bed
MB
7043 :group 'gnus-article-buttons
7044 :type 'regexp)
7045
7046(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7047 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7048Strings like this can be either a message ID or a mail address. If it is one
7049of the symbols `mid' or `mail', Gnus will always assume that the string is a
7050message ID or a mail address, respectively. If this variable is set to the
7051symbol `ask', always query the user what do do. If it is a function, this
aa819354 7052function will be called with the string as its only argument. The function
23f87bed 7053must return `mid', `mail', `invalid' or `ask'."
bf247b6e 7054 :version "22.1"
23f87bed
MB
7055 :group 'gnus-article-buttons
7056 :type '(choice (function-item :tag "Heuristic function"
7057 gnus-button-mid-or-mail-heuristic)
7058 (const ask)
7059 (const mid)
7060 (const mail)))
7061
7062(defcustom gnus-button-mid-or-mail-heuristic-alist
7063 '((-10.0 . ".+\\$.+@")
7064 (-10.0 . "#")
7065 (-10.0 . "\\*")
7066 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7067 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7068 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7069 (-1.0 . "^[^a-z]+@")
7070 ;;
7071 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7072 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7073 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7074 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7075 ;;
7076 (-2.0 . "^[0-9]")
7077 (-1.0 . "^[0-9][0-9]")
7078 ;;
7079 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7080 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7081 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7082 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7083 ;;
7084 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7085 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7086 ;; "[0-9]{8,}.*\@"
7087 (-3.0
7088 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7089 ;; "[0-9]{12,}.*\@"
7090 ;; compensation for TDMA dated mail addresses:
7091 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7092 ;;
7093 (-20.0 . "\\.fsf@") ;; Gnus
7094 (-20.0 . "^slrn")
7095 (-20.0 . "^Pine")
437ce4be 7096 (-20.0 . "^alpine\\.")
23f87bed
MB
7097 (-20.0 . "_-_") ;; Subject change in thread
7098 ;;
7099 (-20.0 . "\\.ln@") ;; leafnode
7100 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7101 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7102 ;;
7103 ;; (5.0 . "") ;; $local_part_len <= 7
7104 (10.0 . "^[^0-9]+@")
7105 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7106 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7107 (3.0 . "\@stud")
7108 ;;
7109 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7110 ;;
7111 (0.5 . "^[A-Z][a-z]")
7112 (0.5 . "^[A-Z][a-z][a-z]")
7113 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7114 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7115 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7116
7117A negative RATE indicates a message IDs, whereas a positive indicates a mail
7118address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7119 :version "22.1"
23f87bed
MB
7120 :group 'gnus-article-buttons
7121 :type '(repeat (cons (number :tag "Rate")
7122 (regexp :tag "Regexp"))))
7123
7124(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7125 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7126Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7127address, `ask' if unsure and `invalid' if the string is invalid."
7128 (let ((case-fold-search nil)
7129 (list gnus-button-mid-or-mail-heuristic-alist)
7130 (result 0) rate regexp lpartlen elem)
7131 (setq lpartlen
7132 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7133 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7134 ;; Certain special cases...
7135 (when (string-match
7136 (concat
7137 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7138 "^[0-9]+\\.[0-9]+@compuserve\\|"
7139 "@public\\.gmane\\.org")
7140 mid-or-mail)
7141 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7142 (setq result 'mail))
7143 (when (string-match "@.*@\\| " mid-or-mail)
7144 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7145 (setq result 'invalid))
7146 ;; Nothing more to do, if result is not a number here...
7147 (when (numberp result)
7148 (while list
7149 (setq elem (car list)
7150 rate (car elem)
7151 regexp (cdr elem)
7152 list (cdr list))
7153 (when (string-match regexp mid-or-mail)
7154 (setq result (+ result rate))
7155 (gnus-message
7156 9 "`%s' matched `%s', rate `%s', result `%s'."
7157 mid-or-mail regexp rate result)))
7158 (when (<= lpartlen 7)
7159 (setq result (+ result 5.0))
7160 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7161 mid-or-mail result))
7162 (when (>= lpartlen 12)
7163 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7164 (cond
7165 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7166 ;; Long local part should contain realname if e-mail address,
7167 ;; too many digits: message-id.
7168 ;; $score -= 5.0 + 0.1 * $local_part_len;
7169 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7170 (setq result (+ result rate))
7171 (gnus-message
7172 9 "Many digits in `%s', rate `%s', result `%s'."
7173 mid-or-mail rate result))
7174 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7175 mid-or-mail)
7176 ;; Too few vowels [^aeiouy]{4,}.*\@
7177 (setq result (+ result -5.0))
7178 (gnus-message
7179 9 "Few vowels in `%s', rate `%s', result `%s'."
7180 mid-or-mail -5.0 result))
7181 (t
7182 (setq result (+ result 5.0))
7183 (gnus-message
7184 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7185 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7186 ;; Maybe we should make this a customizable alist: (condition . 'result)
7187 (cond
7188 ((symbolp result) result)
7189 ;; Now convert number into proper results:
7190 ((< result -10.0) 'mid)
7191 ((> result 10.0) 'mail)
7192 (t 'ask))))
7193
7194(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7195 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7196 (url-mid (concat "news" ":" mid-or-mail))
7197 (url-mailto (concat "mailto" ":" mid-or-mail)))
7198 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7199 (when (fboundp pref)
7200 (setq guessed
7201 ;; get rid of surrounding angles...
7202 (funcall pref
7203 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7204 (if (or (eq 'mid guessed) (eq 'mail guessed))
7205 (setq pref guessed)
7206 (setq pref 'ask)))
7207 (if (eq pref 'ask)
7208 (save-window-excursion
7209 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7210 (setq pref 'mail)
7211 (setq pref 'mid))))
7212 (cond ((eq pref 'mid)
7213 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7214 (gnus-button-handle-news url-mid))
7215 ((eq pref 'mail)
7216 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7217 (gnus-url-mailto url-mailto))
7218 (t (gnus-message 3 "Invalid string.")))))
7219
01c52d31
MB
7220(defun gnus-button-handle-custom (fun arg)
7221 "Call function FUN on argument ARG.
7222Both FUN and ARG are supposed to be strings. ARG will be passed
7223as a symbol to FUN."
7224 (funcall (intern fun)
7225 (if (string-match "^customize-apropos" fun)
7226 arg
7227 (intern arg))))
23f87bed
MB
7228
7229(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7230
7231;; FIXME: Maybe we should merge some of the functions that do quite similar
7232;; stuff?
7233
7234(defun gnus-button-handle-describe-function (url)
7235 "Call `describe-function' when pushing the corresponding URL button."
7236 (describe-function
7237 (intern
7238 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7239
7240(defun gnus-button-handle-describe-variable (url)
7241 "Call `describe-variable' when pushing the corresponding URL button."
7242 (describe-variable
7243 (intern
7244 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7245
7246(defun gnus-button-handle-symbol (url)
7247"Display help on variable or function.
7248Calls `describe-variable' or `describe-function'."
7249 (let ((sym (intern url)))
7250 (cond
7251 ((fboundp sym) (describe-function sym))
7252 ((boundp sym) (describe-variable sym))
7253 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7254
7255(defun gnus-button-handle-describe-key (url)
7256 "Call `describe-key' when pushing the corresponding URL button."
7257 (let* ((key-string
7258 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7259 (keys (ignore-errors (eval `(kbd ,key-string)))))
7260 (if keys
7261 (describe-key keys)
7262 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7263
7264(defun gnus-button-handle-apropos (url)
7265 "Call `apropos' when pushing the corresponding URL button."
7266 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7267
7268(defun gnus-button-handle-apropos-command (url)
7269 "Call `apropos' when pushing the corresponding URL button."
7270 (apropos-command
7271 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7272
7273(defun gnus-button-handle-apropos-variable (url)
7274 "Call `apropos' when pushing the corresponding URL button."
7275 (funcall
7276 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7277 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7278
7279(defun gnus-button-handle-apropos-documentation (url)
7280 "Call `apropos' when pushing the corresponding URL button."
7281 (funcall
7282 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7283 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7284
7285(defun gnus-button-handle-library (url)
7286 "Call `locate-library' when pushing the corresponding URL button."
7287 (gnus-message 9 "url=`%s'" url)
7288 (let* ((lib (locate-library url))
7289 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7290 (if (not lib)
7291 (gnus-message 1 "Cannot locale library `%s'." url)
7292 (find-file-read-only file))))
7293
7294(defun gnus-button-handle-ctan (url)
7295 "Call `browse-url' when pushing a CTAN URL button."
7296 (funcall
7297 gnus-button-ctan-handler
7298 (concat
7299 gnus-ctan-url
7300 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7301
7302(defcustom gnus-button-tex-level 5
7303 "*Integer that says how many TeX-related buttons Gnus will show.
7304The higher the number, the more buttons will appear and the more false
7305positives are possible. Note that you can set this variable local to
7306specific groups. Setting it higher in TeX groups is probably a good idea.
7307See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7308how to set variables in specific groups."
bf247b6e 7309 :version "22.1"
23f87bed
MB
7310 :group 'gnus-article-buttons
7311 :link '(custom-manual "(gnus)Group Parameters")
7312 :type 'integer)
7313
7314(defcustom gnus-button-man-level 5
7315 "*Integer that says how many man-related buttons Gnus will show.
7316The higher the number, the more buttons will appear and the more false
7317positives are possible. Note that you can set this variable local to
7318specific groups. Setting it higher in Unix groups is probably a good idea.
7319See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7320how to set variables in specific groups."
bf247b6e 7321 :version "22.1"
23f87bed
MB
7322 :group 'gnus-article-buttons
7323 :link '(custom-manual "(gnus)Group Parameters")
7324 :type 'integer)
7325
7326(defcustom gnus-button-emacs-level 5
7327 "*Integer that says how many emacs-related buttons Gnus will show.
7328The higher the number, the more buttons will appear and the more false
7329positives are possible. Note that you can set this variable local to
7330specific groups. Setting it higher in Emacs or Gnus related groups is
7331probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7332`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7333 :version "22.1"
23f87bed
MB
7334 :group 'gnus-article-buttons
7335 :link '(custom-manual "(gnus)Group Parameters")
7336 :type 'integer)
7337
7338(defcustom gnus-button-message-level 5
7339 "*Integer that says how many buttons for news or mail messages will appear.
7340The higher the number, the more buttons will appear and the more false
7341positives are possible."
7342 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7343 :version "22.1"
23f87bed
MB
7344 :group 'gnus-article-buttons
7345 :type 'integer)
7346
7347(defcustom gnus-button-browse-level 5
7348 "*Integer that says how many buttons for browsing will appear.
7349The higher the number, the more buttons will appear and the more false
7350positives are possible."
7351 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7352 :version "22.1"
23f87bed
MB
7353 :group 'gnus-article-buttons
7354 :type 'integer)
7355
eec82323 7356(defcustom gnus-button-alist
23f87bed
MB
7357 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7358 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7359 ((concat "\\b\\(nntp\\|news\\):\\("
7360 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7361 0 t gnus-button-handle-news 2)
23f87bed
MB
7362 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7363 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7364 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7365 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7366 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7367 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7368 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7369 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7370 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7371 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7372 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7373 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7374 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7375 ;; RFC 2368 (The mailto URL scheme)
531e5812 7376 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7377 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7378 ("\\bmailto:\\([^ \n\t]+\\)"
7379 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7380 ;; CTAN
7381 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7382 gnus-button-ctan-directory-regexp
7383 "[^][>)!;:,'\n\t ]+\\)")
7384 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7385 ((concat "\\btex-archive/\\("
7386 gnus-button-ctan-directory-regexp
7387 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7388 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7389 ((concat
7390 "\\b\\("
7391 gnus-button-ctan-directory-regexp
7392 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7393 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
9eb59592
MB
7394 ;; Info Konqueror style <info:/foo/bar baz>.
7395 ;; Must come before " Gnus home-grown style".
7396 ("\\binfo://?\\([^'\">\n\t]+\\)"
7397 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7398 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
23f87bed
MB
7399 ("\\binfo://\\([^'\">\n\t ]+\\)"
7400 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7401 ;; Info GNOME style <info:foo#bar_baz>
7402 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7403 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7404 ;; Info KDE style <info:(foo)bar baz>
7405 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7406 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7407 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7408 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
9b3ebcb6
MB
7409 ("\\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,]*\\)\\)?"
7410 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7411 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
23f87bed 7412 ;; This is custom
01c52d31
MB
7413 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7414 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed
MB
7415 ;; Emacs help commands
7416 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7417 ;; regexp doesn't match arguments containing ` '.
7418 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7419 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7420 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7421 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7422 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7423 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7424 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7425 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7426 ;; them by default (use a high button level).
7427 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7428 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7429 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7430 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7431 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7432 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7433 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7434 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7435 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7436 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7437 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7438 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7439 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7440 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7441 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7442 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7443 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7444 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7445 ;; Unlike the other regexps we really have to require quoting
7446 ;; here to determine where it ends.
7447 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7448 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7449 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7450 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7451 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7452 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7453 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7454 ;; Raw URLs.
23f87bed
MB
7455 (gnus-button-url-regexp
7456 0 (>= gnus-button-browse-level 0) browse-url 0)
7457 ;; man pages
531e5812 7458 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7459 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7460 gnus-button-handle-man 1)
7461 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7462 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7463 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7464 gnus-button-handle-man 1)
7465 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7466 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7467 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7468 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7469 ;; Recognizing patches to .el files. This is somewhat obscure,
7470 ;; but considering the percentage of Gnus users who hack Emacs
7471 ;; Lisp files...
7472 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7473 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7474 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7475 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7476 ;; MID or mail: To avoid too many false positives we don't try to catch
7477 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7478 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7479 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7480 ;; so that non-ambiguous entries (see above) match first.
7481 (gnus-button-mid-or-mail-regexp
7482 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7483 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7484
7485Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7486REGEXP: is the string (case insensitive) matching text around the button (can
7487also be Lisp expression evaluating to a string),
eec82323 7488BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7489FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7490be added,
7491CALLBACK: is the function to call when the user push this button, and each
7492PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7493
7494CALLBACK can also be a variable, in that case the value of that
7495variable it the real callback function."
7496 :group 'gnus-article-buttons
23f87bed 7497 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7498 (integer :tag "Button")
7499 (sexp :tag "Form")
7500 (function :tag "Callback")
7501 (repeat :tag "Par"
7502 :inline t
7503 (integer :tag "Regexp group")))))
60ece9b0 7504(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7505
7506(defcustom gnus-header-button-alist
23f87bed
MB
7507 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7508 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7509 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7510 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7511 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7512 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7513 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7514 0 (>= gnus-button-browse-level 0) browse-url 0)
7515 ("^Subject:" gnus-button-url-regexp
7516 0 (>= gnus-button-browse-level 0) browse-url 0)
7517 ("^[^:]+:" gnus-button-url-regexp
7518 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7519 ("^OpenPGP:.*url=" gnus-button-url-regexp
7520 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7521 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7522 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7523 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7524 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7525 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7526
7527This alist is very similar to `gnus-button-alist', except that each
7528alist has an additional HEADER element first in each entry:
7529
7530\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7531
7532HEADER is a regexp to match a header. For a fuller explanation, see
7533`gnus-button-alist'."
7534 :group 'gnus-article-buttons
7535 :group 'gnus-article-headers
7536 :type '(repeat (list (regexp :tag "Header")
23f87bed 7537 (choice regexp variable)
eec82323
LMI
7538 (integer :tag "Button")
7539 (sexp :tag "Form")
7540 (function :tag "Callback")
7541 (repeat :tag "Par"
7542 :inline t
7543 (integer :tag "Regexp group")))))
60ece9b0 7544(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7545
eec82323
LMI
7546;;; Commands:
7547
7548(defun gnus-article-push-button (event)
7549 "Check text under the mouse pointer for a callback function.
7550If the text under the mouse pointer has a `gnus-callback' property,
7551call it with the value of the `gnus-data' text property."
7552 (interactive "e")
7553 (set-buffer (window-buffer (posn-window (event-start event))))
7554 (let* ((pos (posn-point (event-start event)))
23f87bed 7555 (data (get-text-property pos 'gnus-data))
eec82323 7556 (fun (get-text-property pos 'gnus-callback)))
6748645f 7557 (goto-char pos)
eec82323
LMI
7558 (when fun
7559 (funcall fun data))))
7560
7561(defun gnus-article-press-button ()
7562 "Check text at point for a callback function.
7563If the text at point has a `gnus-callback' property,
7564call it with the value of the `gnus-data' text property."
7565 (interactive)
23f87bed
MB
7566 (let ((data (get-text-property (point) 'gnus-data))
7567 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7568 (when fun
7569 (funcall fun data))))
7570
eec82323
LMI
7571(defun gnus-article-highlight (&optional force)
7572 "Highlight current article.
7573This function calls `gnus-article-highlight-headers',
7574`gnus-article-highlight-citation',
7575`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7576do the highlighting. See the documentation for those functions."
7577 (interactive (list 'force))
7578 (gnus-article-highlight-headers)
7579 (gnus-article-highlight-citation force)
7580 (gnus-article-highlight-signature)
7581 (gnus-article-add-buttons force)
7582 (gnus-article-add-buttons-to-head))
7583
7584(defun gnus-article-highlight-some (&optional force)
7585 "Highlight current article.
7586This function calls `gnus-article-highlight-headers',
7587`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7588do the highlighting. See the documentation for those functions."
7589 (interactive (list 'force))
7590 (gnus-article-highlight-headers)
7591 (gnus-article-highlight-signature)
7592 (gnus-article-add-buttons))
7593
7594(defun gnus-article-highlight-headers ()
7595 "Highlight article headers as specified by `gnus-header-face-alist'."
7596 (interactive)
01c52d31
MB
7597 (gnus-with-article-headers
7598 (let (regexp header-face field-face from hpoints fpoints)
7599 (dolist (entry gnus-header-face-alist)
7600 (goto-char (point-min))
7601 (setq regexp (concat "^\\("
7602 (if (string-equal "" (nth 0 entry))
7603 "[^\t ]"
7604 (nth 0 entry))
7605 "\\)")
7606 header-face (nth 1 entry)
7607 field-face (nth 2 entry))
7608 (while (and (re-search-forward regexp nil t)
7609 (not (eobp)))
7610 (beginning-of-line)
7611 (setq from (point))
7612 (unless (search-forward ":" nil t)
7613 (forward-char 1))
7614 (when (and header-face
7615 (not (memq (point) hpoints)))
7616 (push (point) hpoints)
7617 (gnus-put-text-property from (point) 'face header-face))
7618 (when (and field-face
7619 (not (memq (setq from (point)) fpoints)))
7620 (push from fpoints)
7621 (if (re-search-forward "^[^ \t]" nil t)
7622 (forward-char -2)
7623 (goto-char (point-max)))
7624 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7625
7626(defun gnus-article-highlight-signature ()
7627 "Highlight the signature in an article.
7628It does this by highlighting everything after
0f49874b 7629`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7630 (interactive)
01c52d31
MB
7631 (gnus-with-article-buffer
7632 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7633 (save-restriction
7634 (when (and gnus-signature-face
7635 (gnus-article-narrow-to-signature))
01c52d31 7636 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7637 'face gnus-signature-face)
7638 (widen)
7639 (gnus-article-search-signature)
7640 (let ((start (match-beginning 0))
7641 (end (set-marker (make-marker) (1+ (match-end 0)))))
7642 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7643 end)))))))
7644
7645(defun gnus-button-in-region-p (b e prop)
7646 "Say whether PROP exists in the region."
7647 (text-property-not-all b e prop nil))
7648
7649(defun gnus-article-add-buttons (&optional force)
7650 "Find external references in the article and make buttons of them.
7651\"External references\" are things like Message-IDs and URLs, as
7652specified by `gnus-button-alist'."
7653 (interactive (list 'force))
01c52d31
MB
7654 (gnus-with-article-buffer
7655 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7656 (case-fold-search t)
7657 (alist gnus-button-alist)
7658 beg entry regexp)
7659 ;; Remove all old markers.
16409b0b 7660 (let (marker entry new-list)
eec82323 7661 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
7662 (if (or (< marker (point-min)) (>= marker (point-max)))
7663 (push marker new-list)
7664 (goto-char marker)
7665 (when (setq entry (gnus-button-entry))
7666 (put-text-property (match-beginning (nth 1 entry))
7667 (match-end (nth 1 entry))
7668 'gnus-callback nil))
7669 (set-marker marker nil)))
7670 (setq gnus-button-marker-list new-list))
eec82323 7671 ;; We skip the headers.
16409b0b 7672 (article-goto-body)
eec82323
LMI
7673 (setq beg (point))
7674 (while (setq entry (pop alist))
23f87bed 7675 (setq regexp (eval (car entry)))
eec82323
LMI
7676 (goto-char beg)
7677 (while (re-search-forward regexp nil t)
01c52d31
MB
7678 (let ((start (match-beginning (nth 1 entry)))
7679 (end (match-end (nth 1 entry)))
7680 (from (match-beginning 0)))
eec82323
LMI
7681 (when (and (or (eq t (nth 2 entry))
7682 (eval (nth 2 entry)))
7683 (not (gnus-button-in-region-p
7684 start end 'gnus-callback)))
7685 ;; That optional form returned non-nil, so we add the
7686 ;; button.
01c52d31
MB
7687 (setq from (set-marker (make-marker) from))
7688 (push from gnus-button-marker-list)
7689 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7690 (gnus-article-extend-url-button from start end))
7691 (gnus-article-add-button start end
7692 'gnus-button-push from)))))))))
7693
7694(defun gnus-article-extend-url-button (beg start end)
7695 "Extend url button if url is folded into two or more lines.
7696Return non-nil if button is extended. BEG is a marker that points to
7697the beginning position of a text containing url. START and END are
7698the endpoints of a url button before it is extended. The concatenated
7699url is put as the `gnus-button-url' overlay property on the button."
7700 (let ((opoint (point))
7701 (points (list start end))
7702 url delim regexp)
7703 (prog1
7704 (when (and (progn
7705 (goto-char end)
7706 (not (looking-at "[\t ]*[\">]")))
7707 (progn
7708 (goto-char start)
7709 (string-match
7710 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7711 (buffer-substring (point-at-bol) start)))
7712 (progn
7713 (setq url (list (buffer-substring start end))
7714 delim (if (match-beginning 1) ">" "\""))
7715 (beginning-of-line)
7716 (setq regexp (concat
7717 (when (and (looking-at
7718 message-cite-prefix-regexp)
7719 (< (match-end 0) start))
7720 (regexp-quote (match-string 0)))
7721 "\
7722\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7723 delim "\\)"))
7724 (while (progn
7725 (forward-line 1)
7726 (and (looking-at regexp)
7727 (prog1
7728 (match-beginning 1)
7729 (push (or (match-string 2)
7730 (match-string 1))
7731 url)
7732 (push (setq end (or (match-end 2)
7733 (match-end 1)))
7734 points)
7735 (push (or (match-beginning 2)
7736 (match-beginning 1))
7737 points)))))
7738 (match-beginning 2)))
7739 (let (gnus-article-mouse-face widget-mouse-face)
7740 (while points
7741 (gnus-article-add-button (pop points) (pop points)
7742 'gnus-button-push beg)))
7743 (let ((overlay (gnus-make-overlay start end)))
7744 (gnus-overlay-put overlay 'evaporate t)
7745 (gnus-overlay-put overlay 'gnus-button-url
7746 (list (mapconcat 'identity (nreverse url) "")))
7747 (when gnus-article-mouse-face
7748 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7749 t)
7750 (goto-char opoint))))
eec82323
LMI
7751
7752;; Add buttons to the head of an article.
7753(defun gnus-article-add-buttons-to-head ()
7754 "Add buttons to the head of the article."
7755 (interactive)
01c52d31
MB
7756 (gnus-with-article-headers
7757 (let (beg end)
7758 (dolist (entry gnus-header-button-alist)
7759 ;; Each alist entry.
7760 (goto-char (point-min))
7761 (while (re-search-forward (car entry) nil t)
7762 ;; Each header matching the entry.
7763 (setq beg (match-beginning 0))
7764 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7765 (match-beginning 0))
7766 (point-max)))
7767 (goto-char beg)
7768 (while (re-search-forward (eval (nth 1 entry)) end t)
7769 ;; Each match within a header.
7770 (let* ((entry (cdr entry))
7771 (start (match-beginning (nth 1 entry)))
7772 (end (match-end (nth 1 entry)))
7773 (form (nth 2 entry)))
7774 (goto-char (match-end 0))
7775 (when (eval form)
7776 (gnus-article-add-button
7777 start end (nth 3 entry)
7778 (buffer-substring (match-beginning (nth 4 entry))
7779 (match-end (nth 4 entry)))))))
7780 (goto-char end))))))
eec82323
LMI
7781
7782;;; External functions:
7783
7784(defun gnus-article-add-button (from to fun &optional data)
7785 "Create a button between FROM and TO with callback FUN and data DATA."
7786 (when gnus-article-button-face
01c52d31 7787 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7788 'face gnus-article-button-face))
7789 (gnus-add-text-properties
7790 from to
7791 (nconc (and gnus-article-mouse-face
7792 (list gnus-mouse-face-prop gnus-article-mouse-face))
7793 (list 'gnus-callback fun)
16409b0b
GM
7794 (and data (list 'gnus-data data))))
7795 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7796 :button-keymap gnus-widget-button-keymap))
eec82323
LMI
7797
7798;;; Internal functions:
7799
a8151ef7 7800(defun gnus-article-set-globals ()
01c52d31 7801 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7802 (gnus-set-global-variables)))
7803
eec82323 7804(defun gnus-signature-toggle (end)
01c52d31
MB
7805 (gnus-with-article-buffer
7806 (let ((inhibit-point-motion-hooks t))
520aa572 7807 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7808 (progn
7809 (gnus-delete-wash-type 'signature)
7810 (gnus-remove-text-properties-when
7811 'article-type 'signature end (point-max)
7812 (cons 'article-type (cons 'signature
7813 gnus-hidden-properties))))
7814 (gnus-add-wash-type 'signature)
520aa572
SZ
7815 (gnus-add-text-properties-when
7816 'article-type nil end (point-max)
7817 (cons 'article-type (cons 'signature
23f87bed
MB
7818 gnus-hidden-properties)))))
7819 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7820 (gnus-set-mode-line 'article))))
eec82323
LMI
7821
7822(defun gnus-button-entry ()
7823 ;; Return the first entry in `gnus-button-alist' matching this place.
7824 (let ((alist gnus-button-alist)
7825 (entry nil))
7826 (while alist
7827 (setq entry (pop alist))
23f87bed 7828 (if (looking-at (eval (car entry)))
eec82323
LMI
7829 (setq alist nil)
7830 (setq entry nil)))
7831 entry))
7832
7833(defun gnus-button-push (marker)
7834 ;; Push button starting at MARKER.
7835 (save-excursion
eec82323
LMI
7836 (goto-char marker)
7837 (let* ((entry (gnus-button-entry))
7838 (inhibit-point-motion-hooks t)
7839 (fun (nth 3 entry))
01c52d31
MB
7840 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7841 (get-char-property marker 'gnus-button-url))
7842 (mapcar (lambda (group)
7843 (let ((string (match-string group)))
7844 (set-text-properties
7845 0 (length string) nil string)
7846 string))
7847 (nthcdr 4 entry)))))
eec82323
LMI
7848 (cond
7849 ((fboundp fun)
7850 (apply fun args))
7851 ((and (boundp fun)
7852 (fboundp (symbol-value fun)))
7853 (apply (symbol-value fun) args))
7854 (t
7855 (gnus-message 1 "You must define `%S' to use this button"
7856 (cons fun args)))))))
7857
23f87bed 7858(defun gnus-parse-news-url (url)
82a8ad04 7859 (let (scheme server port group message-id articles)
23f87bed
MB
7860 (with-temp-buffer
7861 (insert url)
7862 (goto-char (point-min))
7863 (when (looking-at "\\([A-Za-z]+\\):")
7864 (setq scheme (match-string 1))
7865 (goto-char (match-end 0)))
82a8ad04 7866 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7867 (setq server (match-string 1))
82a8ad04
MB
7868 (setq port (if (stringp (match-string 3))
7869 (string-to-number (match-string 3))
7870 (match-string 3)))
23f87bed
MB
7871 (goto-char (match-end 0)))
7872
7873 (cond
7874 ((looking-at "\\(.*@.*\\)")
7875 (setq message-id (match-string 1)))
7876 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7877 (setq group (match-string 1)
7878 articles (split-string (match-string 2) "-")))
7879 ((looking-at "\\([^/]+\\)/?")
7880 (setq group (match-string 1)))
7881 (t
7882 (error "Unknown news URL syntax"))))
82a8ad04 7883 (list scheme server port group message-id articles)))
23f87bed
MB
7884
7885(defun gnus-button-handle-news (url)
7886 "Fetch a news URL."
82a8ad04 7887 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7888 (gnus-parse-news-url url)
7889 (cond
7890 (message-id
80de1778 7891 (with-current-buffer gnus-summary-buffer
23f87bed 7892 (if server
ff4d3926
MB
7893 (let ((gnus-refer-article-method
7894 (nconc (list (list 'nntp server))
7895 gnus-refer-article-method))
82a8ad04 7896 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7897 (gnus-message 7 "Fetching %s with %s"
7898 message-id gnus-refer-article-method)
23f87bed
MB
7899 (gnus-summary-refer-article message-id))
7900 (gnus-summary-refer-article message-id))))
7901 (group
7902 (gnus-button-fetch-group url)))))
7903
01c52d31
MB
7904(defun gnus-button-patch (library line)
7905 "Visit an Emacs Lisp library LIBRARY on line LINE."
7906 (interactive)
7907 (let ((file (locate-library (file-name-nondirectory library))))
7908 (unless file
7909 (error "Couldn't find library %s" library))
7910 (find-file file)
5dcc825f
GM
7911 (goto-char (point-min))
7912 (forward-line (1- (string-to-number line)))))
01c52d31 7913
23f87bed
MB
7914(defun gnus-button-handle-man (url)
7915 "Fetch a man page."
531e5812
MB
7916 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7917 (when (eq gnus-button-man-handler 'woman)
7918 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7919 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
7920 (funcall gnus-button-man-handler url))
7921
7922(defun gnus-button-handle-info-url (url)
7923 "Fetch an info URL."
7924 (setq url (mm-subst-char-in-string ?+ ?\ url))
7925 (cond
7926 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7927 (gnus-info-find-node
7928 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7929 "Gnus")
7930 ")" (gnus-url-unhex-string (match-string 2 url)))))
7931 ((string-match "([^)\"]+)[^\"]+" url)
7932 (setq url
7933 (gnus-replace-in-string
7934 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7935 (gnus-info-find-node url))
7936 (t (error "Can't parse %s" url))))
7937
7938(defun gnus-button-handle-info-url-gnome (url)
7939 "Fetch GNOME style info URL."
7940 (setq url (mm-subst-char-in-string ?_ ?\ url))
7941 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7942 (gnus-info-find-node
7943 (concat "("
bf247b6e 7944 (gnus-url-unhex-string
23f87bed
MB
7945 (match-string 1 url))
7946 ")"
bf247b6e 7947 (or (gnus-url-unhex-string
23f87bed
MB
7948 (match-string 2 url))
7949 "Top")))
7950 (error "Can't parse %s" url)))
7951
7952(defun gnus-button-handle-info-url-kde (url)
7953 "Fetch KDE style info URL."
7954 (gnus-info-find-node (gnus-url-unhex-string url)))
7955
9640c3bc
GM
7956;; (info) will autoload info.el
7957(declare-function Info-menu "info" (menu-item &optional fork))
9b3ebcb6 7958(declare-function Info-index-next "info" (num))
9640c3bc 7959
23f87bed
MB
7960(defun gnus-button-handle-info-keystrokes (url)
7961 "Call `info' when pushing the corresponding URL button."
9b3ebcb6
MB
7962 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
7963 (let (node indx comma)
7964 (if (string-match
7965 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
7966 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7967 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
7968 "\\(?:[ \t\n,]*\\)\\)?")
7969 url)
7970 (setq node (match-string 2 url)
7971 indx (match-string 3 url))
7972 (error "Can't parse %s" url))
7973 (info)
7974 (Info-directory)
7975 (Info-menu node)
7976 (when (> (length indx) 0)
7977 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7978 "\\([ \t\n,]*\\)")
7979 indx)
7980 (setq comma (match-string 2 indx))
7981 (setq indx (match-string 1 indx))
7982 (Info-index indx)
7983 (when comma
7984 (dotimes (i (with-temp-buffer
7985 (insert comma)
7986 ;; Note: the XEmacs version of `how-many' takes
7987 ;; no optional argument.
7988 (goto-char (point-min))
7989 (how-many ",")))
7990 (Info-index-next 1)))
7991 nil)))
1888e568
GM
7992
7993;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
7994(declare-function pgg-display-output-buffer "pgg" (start end status))
23f87bed 7995
01c52d31
MB
7996(defun gnus-button-openpgp (url)
7997 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7998 (with-temp-buffer
7999 (mm-url-insert-file-contents-external url)
8000 (pgg-snarf-keys-region (point-min) (point-max))
8001 (pgg-display-output-buffer nil nil nil)))
8002
eec82323
LMI
8003(defun gnus-button-message-id (message-id)
8004 "Fetch MESSAGE-ID."
01c52d31 8005 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8006 (gnus-summary-refer-article message-id)))
8007
01c52d31 8008(defun gnus-button-fetch-group (address &rest ignore)
eec82323 8009 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
8010 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8011 address)
8012 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8013 ;; for nntp:// and news://
8014 (setq address (match-string 3 address)))
eec82323
LMI
8015 (if (not (string-match "[:/]" address))
8016 ;; This is just a simple group url.
8017 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
8018 (if (not
8019 (string-match
8020 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8021 address))
eec82323
LMI
8022 (error "Can't parse %s" address)
8023 (gnus-group-read-ephemeral-group
8024 (match-string 4 address)
8025 `(nntp ,(match-string 1 address)
8026 (nntp-address ,(match-string 1 address))
8027 (nntp-port-number ,(if (match-end 3)
8028 (match-string 3 address)
23f87bed
MB
8029 "nntp")))
8030 nil nil nil
e9bd5782 8031 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 8032
eec82323
LMI
8033(defun gnus-url-parse-query-string (query &optional downcase)
8034 (let (retval pairs cur key val)
16409b0b 8035 (setq pairs (split-string query "&"))
eec82323
LMI
8036 (while pairs
8037 (setq cur (car pairs)
23f87bed 8038 pairs (cdr pairs))
eec82323 8039 (if (not (string-match "=" cur))
23f87bed
MB
8040 nil ; Grace
8041 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8042 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8043 (if downcase
8044 (setq key (downcase key)))
8045 (setq cur (assoc key retval))
8046 (if cur
8047 (setcdr cur (cons val (cdr cur)))
8048 (setq retval (cons (list key val) retval)))))
eec82323
LMI
8049 retval))
8050
eec82323
LMI
8051(defun gnus-url-mailto (url)
8052 ;; Send mail to someone
8053 (when (string-match "mailto:/*\\(.*\\)" url)
8054 (setq url (substring url (match-beginning 1) nil)))
6748645f 8055 (let (to args subject func)
23f87bed
MB
8056 (setq args (gnus-url-parse-query-string
8057 (if (string-match "^\\?" url)
8058 (substring url 1)
8059 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8060 (concat "to=" (match-string 1 url) "&"
8061 (match-string 2 url))
8062 (concat "to=" url)))
8063 t)
8064 subject (cdr-safe (assoc "subject" args)))
8065 (gnus-msg-mail)
eec82323
LMI
8066 (while args
8067 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8068 (if (fboundp func)
23f87bed
MB
8069 (funcall func)
8070 (message-position-on-field (caar args)))
8071 (insert (gnus-replace-in-string
8072 (mapconcat 'identity (reverse (cdar args)) ", ")
8073 "\r\n" "\n" t))
eec82323
LMI
8074 (setq args (cdr args)))
8075 (if subject
23f87bed 8076 (message-goto-body)
eec82323
LMI
8077 (message-goto-subject))))
8078
eec82323 8079(defun gnus-button-embedded-url (address)
e0bad764 8080 "Activate ADDRESS with `browse-url'."
1b978bfc 8081 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
8082
8083;;; Next/prev buttons in the article buffer.
8084
8085(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8086(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8087
23f87bed
MB
8088(defvar gnus-prev-page-map
8089 (let ((map (make-sparse-keymap)))
23f87bed
MB
8090 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8091 (define-key map "\r" 'gnus-button-prev-page)
8092 map))
8093
8094(defvar gnus-next-page-map
8095 (let ((map (make-sparse-keymap)))
8096 (unless (>= emacs-major-version 21)
8097 ;; XEmacs doesn't care.
8098 (set-keymap-parent map gnus-article-mode-map))
8099 (define-key map gnus-mouse-2 'gnus-button-next-page)
8100 (define-key map "\r" 'gnus-button-next-page)
8101 map))
eec82323
LMI
8102
8103(defun gnus-insert-prev-page-button ()
01c52d31 8104 (let ((b (point)) e
23f87bed 8105 (inhibit-read-only t))
eec82323
LMI
8106 (gnus-eval-format
8107 gnus-prev-page-line-format nil
01c52d31
MB
8108 `(keymap ,gnus-prev-page-map
8109 gnus-prev t
8110 gnus-callback gnus-article-button-prev-page
8111 article-type annotation))
8112 (setq e (if (bolp)
8113 ;; Exclude a newline.
8114 (1- (point))
8115 (point)))
8116 (when gnus-article-button-face
8117 (gnus-overlay-put (gnus-make-overlay b e nil t)
8118 'face gnus-article-button-face))
23f87bed 8119 (widget-convert-button
01c52d31 8120 'link b e
23f87bed
MB
8121 :action 'gnus-button-prev-page
8122 :button-keymap gnus-prev-page-map)))
8123
8124(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8125 "Go to the next page."
8126 (interactive)
8127 (let ((win (selected-window)))
23f87bed 8128 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8129 (gnus-article-next-page)
8130 (select-window win)))
8131
23f87bed 8132(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8133 "Go to the prev page."
8134 (interactive)
8135 (let ((win (selected-window)))
23f87bed 8136 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8137 (gnus-article-prev-page)
8138 (select-window win)))
8139
8140(defun gnus-insert-next-page-button ()
01c52d31 8141 (let ((b (point)) e
23f87bed 8142 (inhibit-read-only t))
eec82323 8143 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8144 `(keymap ,gnus-next-page-map
8145 gnus-next t
8146 gnus-callback gnus-article-button-next-page
8147 article-type annotation))
8148 (setq e (if (bolp)
8149 ;; Exclude a newline.
8150 (1- (point))
8151 (point)))
8152 (when gnus-article-button-face
8153 (gnus-overlay-put (gnus-make-overlay b e nil t)
8154 'face gnus-article-button-face))
23f87bed 8155 (widget-convert-button
01c52d31 8156 'link b e
23f87bed
MB
8157 :action 'gnus-button-next-page
8158 :button-keymap gnus-next-page-map)))
eec82323
LMI
8159
8160(defun gnus-article-button-next-page (arg)
8161 "Go to the next page."
8162 (interactive "P")
8163 (let ((win (selected-window)))
23f87bed 8164 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8165 (gnus-article-next-page)
8166 (select-window win)))
8167
8168(defun gnus-article-button-prev-page (arg)
8169 "Go to the prev page."
8170 (interactive "P")
8171 (let ((win (selected-window)))
23f87bed 8172 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8173 (gnus-article-prev-page)
8174 (select-window win)))
8175
16409b0b
GM
8176(defvar gnus-decode-header-methods
8177 '(mail-decode-encoded-word-region)
8178 "List of methods used to decode headers.
8179
8180This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8181is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8182\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8183whose names match REGEXP.
8184
8185For example:
8f688cb0 8186\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8187 mail-decode-encoded-word-region
8188 (\"chinese\" . rfc1843-decode-region))
8189")
8190
8191(defvar gnus-decode-header-methods-cache nil)
8192
8193(defun gnus-multi-decode-header (start end)
8194 "Apply the functions from `gnus-encoded-word-methods' that match."
8195 (unless (and gnus-decode-header-methods-cache
8196 (eq gnus-newsgroup-name
8197 (car gnus-decode-header-methods-cache)))
8198 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8199 (dolist (x gnus-decode-header-methods)
8200 (if (symbolp x)
8201 (nconc gnus-decode-header-methods-cache (list x))
8202 (if (and gnus-newsgroup-name
8203 (string-match (car x) gnus-newsgroup-name))
8204 (nconc gnus-decode-header-methods-cache
8205 (list (cdr x)))))))
16409b0b
GM
8206 (let ((xlist gnus-decode-header-methods-cache))
8207 (pop xlist)
8208 (save-restriction
8209 (narrow-to-region start end)
8210 (while xlist
8211 (funcall (pop xlist) (point-min) (point-max))))))
8212
8213;;;
8214;;; Treatment top-level handling.
8215;;;
8216
8217(defun gnus-treat-article (condition &optional part-number total-parts type)
8218 (let ((length (- (point-max) (point-min)))
8219 (alist gnus-treatment-function-alist)
8220 (article-goto-body-goes-to-point-min-p t)
8221 (treated-type
8222 (or (not type)
8223 (catch 'found
8224 (let ((list gnus-article-treat-types))
8225 (while list
8226 (when (string-match (pop list) type)
8227 (throw 'found t)))))))
8228 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8229 val elem)
8230 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8231 (dolist (elem alist)
16409b0b
GM
8232 (setq val
8233 (save-excursion
23f87bed
MB
8234 (when (gnus-buffer-live-p gnus-summary-buffer)
8235 (set-buffer gnus-summary-buffer))
16409b0b
GM
8236 (symbol-value (car elem))))
8237 (when (and (or (consp val)
8238 treated-type)
8239 (gnus-treat-predicate val)
8240 (or (not (get (car elem) 'highlight))
8241 highlightp))
8242 (save-restriction
8243 (funcall (cadr elem)))))))
8244
8245;; Dynamic variables.
9efa445f
DN
8246(defvar part-number)
8247(defvar total-parts)
8248(defvar type)
8249(defvar condition)
8250(defvar length)
e0bad764 8251
16409b0b
GM
8252(defun gnus-treat-predicate (val)
8253 (cond
8254 ((null val)
8255 nil)
23f87bed
MB
8256 (condition
8257 (eq condition val))
16409b0b
GM
8258 ((and (listp val)
8259 (stringp (car val)))
8260 (apply 'gnus-or (mapcar `(lambda (s)
8261 (string-match s ,(or gnus-newsgroup-name "")))
8262 val)))
8263 ((listp val)
8264 (let ((pred (pop val)))
8265 (cond
8266 ((eq pred 'or)
8267 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8268 ((eq pred 'and)
8269 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8270 ((eq pred 'not)
8271 (not (gnus-treat-predicate (car val))))
8272 ((eq pred 'typep)
8273 (equal (car val) type))
8274 (t
8275 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8276 ((eq val t)
8277 t)
8278 ((eq val 'head)
8279 nil)
01c52d31
MB
8280 ((eq val 'first)
8281 (eq part-number 1))
16409b0b
GM
8282 ((eq val 'last)
8283 (eq part-number total-parts))
8284 ((numberp val)
8285 (< length val))
8286 (t
8287 (error "%S is not a valid value" val))))
8288
23f87bed
MB
8289(defun gnus-article-encrypt-body (protocol &optional n)
8290 "Encrypt the article body."
8291 (interactive
8292 (list
8293 (or gnus-article-encrypt-protocol
8294 (completing-read "Encrypt protocol: "
8295 gnus-article-encrypt-protocol-alist
8296 nil t))
8297 current-prefix-arg))
bbbe940b
MB
8298 ;; User might hit `K E' instead of `K e', so prompt once.
8299 (when (and gnus-article-encrypt-protocol
8300 gnus-novice-user)
8301 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8302 (error "Encrypt aborted.")))
23f87bed
MB
8303 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8304 (unless func
998a5a95 8305 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8306 (if (member gnus-newsgroup-name '("nndraft:delayed"
8307 "nndraft:drafts"
8308 "nndraft:queue"))
8309 (error "Can't encrypt the article in group %s"
8310 gnus-newsgroup-name))
8311 (gnus-summary-iterate n
80de1778 8312 (with-current-buffer gnus-summary-buffer
23f87bed
MB
8313 (let ((mail-parse-charset gnus-newsgroup-charset)
8314 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8315 (summary-buffer gnus-summary-buffer)
8316 references point)
8317 (gnus-set-global-variables)
8318 (when (gnus-group-read-only-p)
8319 (error "The current newsgroup does not support article encrypt"))
8320 (gnus-summary-show-article t)
8321 (setq references
8322 (or (mail-header-references gnus-current-headers) ""))
8323 (set-buffer gnus-article-buffer)
8324 (let* ((inhibit-read-only t)
8325 (headers
8326 (mapcar (lambda (field)
8327 (and (save-restriction
8328 (message-narrow-to-head)
8329 (goto-char (point-min))
8330 (search-forward field nil t))
8331 (prog2
8332 (message-narrow-to-field)
8333 (buffer-string)
8334 (delete-region (point-min) (point-max))
8335 (widen))))
8336 '("Content-Type:" "Content-Transfer-Encoding:"
8337 "Content-Disposition:"))))
8338 (message-narrow-to-head)
8339 (message-remove-header "MIME-Version")
8340 (goto-char (point-max))
8341 (setq point (point))
8342 (insert (apply 'concat headers))
8343 (widen)
8344 (narrow-to-region point (point-max))
8345 (let ((message-options message-options))
8346 (message-options-set 'message-sender user-mail-address)
8347 (message-options-set 'message-recipients user-mail-address)
8348 (message-options-set 'message-sign-encrypt 'not)
8349 (funcall func))
8350 (goto-char (point-min))
8351 (insert "MIME-Version: 1.0\n")
8352 (widen)
8353 (gnus-summary-edit-article-done
8354 references nil summary-buffer t))
8355 (when gnus-keep-backlog
8356 (gnus-backlog-remove-article
8357 (car gnus-article-current) (cdr gnus-article-current)))
80de1778
SM
8358 (when (get-buffer gnus-original-article-buffer)
8359 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
8360 (setq gnus-original-article nil)))
8361 (when gnus-use-cache
8362 (gnus-cache-update-article
8363 (car gnus-article-current) (cdr gnus-article-current))))))))
8364
8365(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8366 "The following specs can be used:
8367%t The security MIME type
8368%i Additional info
8369%d Details
8370%D Details if button is pressed")
8371
8372(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8373 "The following specs can be used:
8374%t The security MIME type
8375%i Additional info
8376%d Details
8377%D Details if button is pressed")
8378
8379(defvar gnus-mime-security-button-line-format-alist
8380 '((?t gnus-tmp-type ?s)
8381 (?i gnus-tmp-info ?s)
8382 (?d gnus-tmp-details ?s)
8383 (?D gnus-tmp-pressed-details ?s)))
8384
01c52d31
MB
8385(defvar gnus-mime-security-button-commands
8386 '((gnus-article-press-button "\r" "Show Detail")
8387 (undefined "v")
8388 (undefined "t")
8389 (undefined "C")
8390 (gnus-mime-security-save-part "o" "Save...")
8391 (undefined "\C-o")
8392 (undefined "r")
8393 (undefined "d")
8394 (undefined "c")
8395 (undefined "i")
8396 (undefined "E")
8397 (undefined "e")
8398 (undefined "p")
8399 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8400 (undefined ".")))
8401
23f87bed
MB
8402(defvar gnus-mime-security-button-map
8403 (let ((map (make-sparse-keymap)))
23f87bed 8404 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8405 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8406 (dolist (c gnus-mime-security-button-commands)
8407 (define-key map (cadr c) (car c)))
23f87bed
MB
8408 map))
8409
01c52d31
MB
8410(easy-menu-define
8411 gnus-mime-security-button-menu gnus-mime-security-button-map
8412 "Security button menu."
8413 `("Security Part"
8414 ,@(delq nil
8415 (mapcar (lambda (c)
8416 (unless (eq (car c) 'undefined)
8417 (vector (caddr c) (car c) :active t)))
8418 gnus-mime-security-button-commands))))
8419
8420(defun gnus-mime-security-button-menu (event prefix)
8421 "Construct a context-sensitive menu of security commands."
8422 (interactive "e\nP")
8423 (save-window-excursion
8424 (let ((pos (event-start event)))
8425 (select-window (posn-window pos))
8426 (goto-char (posn-point pos))
8427 (gnus-article-check-buffer)
8428 (popup-menu gnus-mime-security-button-menu nil prefix))))
8429
23f87bed
MB
8430(defvar gnus-mime-security-details-buffer nil)
8431
8432(defvar gnus-mime-security-button-pressed nil)
8433
8434(defvar gnus-mime-security-show-details-inline t
8435 "If non-nil, show details in the article buffer.")
8436
8437(defun gnus-mime-security-verify-or-decrypt (handle)
8438 (mm-remove-parts (cdr handle))
8439 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8440 point (inhibit-read-only t))
8441 (if region
8442 (goto-char (car region)))
01c52d31
MB
8443 (setq point (point))
8444 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8445 (let* ((mm-verify-option 'known)
8446 (mm-decrypt-option 'known)
8447 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8448 (unless (eq nparts (cdr handle))
8449 (mm-destroy-parts (cdr handle))
8450 (setcdr handle nparts))))
8451 (gnus-mime-display-security handle)
23f87bed
MB
8452 (when region
8453 (delete-region (point) (cdr region))
8454 (set-marker (car region) nil)
8455 (set-marker (cdr region) nil))
8456 (goto-char point)))
8457
8458(defun gnus-mime-security-show-details (handle)
8459 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8460 (if (not details)
8461 (gnus-message 5 "No details.")
8462 (if gnus-mime-security-show-details-inline
8463 (let ((gnus-mime-security-button-pressed
8464 (not (get-text-property (point) 'gnus-mime-details)))
8465 (gnus-mime-security-button-line-format
8466 (get-text-property (point) 'gnus-line-format))
8467 (inhibit-read-only t))
8468 (forward-char -1)
8469 (while (eq (get-text-property (point) 'gnus-line-format)
8470 gnus-mime-security-button-line-format)
8471 (forward-char -1))
8472 (forward-char)
8473 (save-restriction
8474 (narrow-to-region (point) (point))
8475 (gnus-insert-mime-security-button handle))
8476 (delete-region (point)
8477 (or (text-property-not-all
8478 (point) (point-max)
8479 'gnus-line-format
8480 gnus-mime-security-button-line-format)
8481 (point-max))))
8482 ;; Not inlined.
8483 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8484 (with-current-buffer gnus-mime-security-details-buffer
8485 (erase-buffer)
8486 t)
8487 (setq gnus-mime-security-details-buffer
8488 (gnus-get-buffer-create "*MIME Security Details*")))
8489 (with-current-buffer gnus-mime-security-details-buffer
8490 (insert details)
8491 (goto-char (point-min)))
8492 (pop-to-buffer gnus-mime-security-details-buffer)))))
8493
8494(defun gnus-mime-security-press-button (handle)
8495 (save-excursion
8496 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8497 (gnus-mime-security-show-details handle)
8498 (gnus-mime-security-verify-or-decrypt handle))))
8499
8500(defun gnus-insert-mime-security-button (handle &optional displayed)
8501 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8502 (gnus-tmp-type
8503 (concat
8504 (or (nth 2 (assoc protocol mm-verify-function-alist))
8505 (nth 2 (assoc protocol mm-decrypt-function-alist))
8506 "Unknown")
8507 (if (equal (car handle) "multipart/signed")
8508 " Signed" " Encrypted")
8509 " Part"))
8510 (gnus-tmp-info
8511 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8512 "Undecided"))
8513 (gnus-tmp-details
8514 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8515 gnus-tmp-pressed-details
8516 b e)
8517 (setq gnus-tmp-details
8518 (if gnus-tmp-details
8519 (concat "\n" gnus-tmp-details)
8520 ""))
8521 (setq gnus-tmp-pressed-details
8522 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8523 (unless (bolp)
8524 (insert "\n"))
8525 (setq b (point))
8526 (gnus-eval-format
8527 gnus-mime-security-button-line-format
8528 gnus-mime-security-button-line-format-alist
01c52d31 8529 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8530 gnus-callback gnus-mime-security-press-button
8531 gnus-line-format ,gnus-mime-security-button-line-format
8532 gnus-mime-details ,gnus-mime-security-button-pressed
8533 article-type annotation
8534 gnus-data ,handle))
8535 (setq e (if (bolp)
8536 ;; Exclude a newline.
8537 (1- (point))
8538 (point)))
01c52d31
MB
8539 (when gnus-article-button-face
8540 (gnus-overlay-put (gnus-make-overlay b e nil t)
8541 'face gnus-article-button-face))
23f87bed
MB
8542 (widget-convert-button
8543 'link b e
8544 :mime-handle handle
8545 :action 'gnus-widget-press-button
8546 :button-keymap gnus-mime-security-button-map
8547 :help-echo
8548 (lambda (widget/window &optional overlay pos)
8549 ;; Needed to properly clear the message due to a bug in
8550 ;; wid-edit (XEmacs only).
8551 (when (boundp 'help-echo-owns-message)
8552 (setq help-echo-owns-message t))
8553 (format
01c52d31
MB
8554 "%S: show detail; %S: more options"
8555 (aref gnus-mouse-2 0)
8556 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8557
8558(defun gnus-mime-display-security (handle)
8559 (save-restriction
8560 (narrow-to-region (point) (point))
8561 (unless (gnus-unbuttonized-mime-type-p (car handle))
8562 (gnus-insert-mime-security-button handle))
01c52d31 8563 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8564 (unless (bolp)
8565 (insert "\n"))
8566 (unless (gnus-unbuttonized-mime-type-p (car handle))
8567 (let ((gnus-mime-security-button-line-format
8568 gnus-mime-security-button-end-line-format))
8569 (gnus-insert-mime-security-button handle)))
8570 (mm-set-handle-multipart-parameter
8571 handle 'gnus-region
8572 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8573 (set-marker (make-marker) (point-max))))
8574 (goto-char (point-max))))
8575
8576(defun gnus-mime-security-run-function (function)
8577 "Run FUNCTION with the security part under point."
8578 (gnus-article-check-buffer)
8579 (let ((data (get-text-property (point) 'gnus-data))
8580 buffer handle)
8581 (when (and (stringp (car-safe data))
8582 (setq buffer (mm-handle-multipart-original-buffer data))
8583 (setq handle (cadr data)))
8584 (if (bufferp (mm-handle-buffer handle))
8585 (progn
8586 (setq handle (cons buffer (copy-sequence (cdr handle))))
8587 (mm-handle-set-undisplayer handle nil))
8588 (setq handle (mm-make-handle
8589 buffer
8590 (mm-handle-multipart-ctl-parameter handle 'protocol)
8591 nil nil nil nil nil nil)))
8592 (funcall function handle))))
8593
8594(defun gnus-mime-security-save-part ()
8595 "Save the security part under point."
8596 (interactive)
8597 (gnus-mime-security-run-function 'mm-save-part))
8598
8599(defun gnus-mime-security-pipe-part ()
8600 "Pipe the security part under point to a process."
8601 (interactive)
8602 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8603
eec82323
LMI
8604(gnus-ems-redefine)
8605
8606(provide 'gnus-art)
8607
8608(run-hooks 'gnus-art-load-hook)
8609
80de1778 8610;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
eec82323 8611;;; gnus-art.el ends here