nnimap.el (gnutls-negotiate): Silence the byte compiler.
[bpt/emacs.git] / lisp / gnus / gnus-art.el
CommitLineData
eec82323 1;;; gnus-art.el --- article mode commands for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
5e809f55 11;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 12;; it under the terms of the GNU General Public License as published by
5e809f55
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
eec82323
LMI
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2ff9f5b4 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
5e809f55 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
23
24;;; Commentary:
25
26;;; Code:
27
f0b7f5a8 28;; For Emacs <22.2 and XEmacs.
9640c3bc
GM
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)
5843126b 37(require 'gnus-sum)
eec82323
LMI
38(require 'gnus-spec)
39(require 'gnus-int)
23f87bed 40(require 'gnus-win)
16409b0b
GM
41(require 'mm-bodies)
42(require 'mail-parse)
43(require 'mm-decode)
44(require 'mm-view)
45(require 'wid-edit)
46(require 'mm-uu)
23f87bed
MB
47(require 'message)
48
49(autoload 'gnus-msg-mail "gnus-msg" nil t)
50(autoload 'gnus-button-mailto "gnus-msg")
51(autoload 'gnus-button-reply "gnus-msg" nil t)
498063ec 52(autoload 'parse-time-string "parse-time" nil nil)
01c52d31
MB
53(autoload 'ansi-color-apply-on-region "ansi-color")
54(autoload 'mm-url-insert-file-contents-external "mm-url")
531bedc3 55(autoload 'mm-extern-cache-contents "mm-extern")
eec82323
LMI
56
57(defgroup gnus-article nil
58 "Article display."
23f87bed 59 :link '(custom-manual "(gnus)Article Buffer")
eec82323
LMI
60 :group 'gnus)
61
16409b0b
GM
62(defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
65 :group 'gnus-article)
66
eec82323
LMI
67(defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
71
72(defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
75 :group 'gnus-article
76 :group 'gnus-visual)
77
78(defgroup gnus-article-signature nil
79 "Article signatures."
80 :link '(custom-manual "(gnus)Article Signature")
81 :group 'gnus-article)
82
83(defgroup gnus-article-headers nil
84 "Article headers."
85 :link '(custom-manual "(gnus)Hiding Headers")
86 :group 'gnus-article)
87
88(defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
91 :group 'gnus-article)
92
93(defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
96 :group 'gnus-article)
97
98(defgroup gnus-article-saving nil
99 "Saving articles."
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
102
103(defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
107
108(defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
112
113(defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
117
118(defcustom gnus-ignored-headers
23f87bed
MB
119 (mapcar
120 (lambda (header)
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
01c52d31
MB
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
6748645f 163 "*All headers that start with this regexp will be hidden.
eec82323
LMI
164This variable can also be a list of regexps of headers to be ignored.
165If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice :custom-show nil
167 regexp
168 (repeat regexp))
169 :group 'gnus-article-hiding)
170
171(defcustom gnus-visible-headers
23f87bed 172 "^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 173 "*All headers that do not match this regexp will be hidden.
eec82323
LMI
174This variable can also be a list of regexp of headers to remain visible.
175If this variable is non-nil, `gnus-ignored-headers' will be ignored."
9b3ebcb6
MB
176 :type '(choice
177 (repeat :value-to-internal (lambda (widget value)
178 (custom-split-regexp-maybe value))
179 :match (lambda (widget value)
180 (or (stringp value)
181 (widget-editable-list-match widget value)))
182 regexp)
183 (const :tag "Use gnus-ignored-headers" nil)
184 regexp)
eec82323
LMI
185 :group 'gnus-article-hiding)
186
187(defcustom gnus-sorted-header-list
188 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
189 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
6748645f 190 "*This variable is a list of regular expressions.
eec82323
LMI
191If it is non-nil, headers that match the regular expressions will
192be placed first in the article buffer in the sequence specified by
193this list."
194 :type '(repeat regexp)
195 :group 'gnus-article-hiding)
196
197(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
198 "Headers that are only to be displayed if they have interesting data.
23f87bed
MB
199Possible values in this list are:
200
201 'empty Headers with no content.
202 'newsgroups Newsgroup identical to Gnus group.
203 'to-address To identical to To-address.
204 'to-list To identical to To-list.
205 'cc-list CC identical to To-list.
206 'followup-to Followup-to identical to Newsgroups.
207 'reply-to Reply-to identical to From.
208 'date Date less than four days old.
209 'long-to To and/or Cc longer than 1024 characters.
210 'many-to Multiple To and/or Cc."
eec82323 211 :type '(set (const :tag "Headers with no content." empty)
23f87bed
MB
212 (const :tag "Newsgroups identical to Gnus group." newsgroups)
213 (const :tag "To identical to To-address." to-address)
214 (const :tag "To identical to To-list." to-list)
215 (const :tag "CC identical to To-list." cc-list)
216 (const :tag "Followup-to identical to Newsgroups." followup-to)
217 (const :tag "Reply-to identical to From." reply-to)
6748645f 218 (const :tag "Date less than four days old." date)
23f87bed 219 (const :tag "To and/or Cc longer than 1024 characters." long-to)
16409b0b 220 (const :tag "Multiple To and/or Cc headers." many-to))
eec82323
LMI
221 :group 'gnus-article-hiding)
222
23f87bed
MB
223(defcustom gnus-article-skip-boring nil
224 "Skip over text that is not worth reading.
225By default, if you set this t, then Gnus will display citations and
226signatures, but will never scroll down to show you a page consisting
227only of boring text. Boring text is controlled by
228`gnus-article-boring-faces'."
bf247b6e 229 :version "22.1"
23f87bed
MB
230 :type 'boolean
231 :group 'gnus-article-hiding)
232
eec82323
LMI
233(defcustom gnus-signature-separator '("^-- $" "^-- *$")
234 "Regexp matching signature separator.
235This can also be a list of regexps. In that case, it will be checked
236from head to tail looking for a separator. Searches will be done from
237the end of the buffer."
3031d8b0
MB
238 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
239 (regexp)
240 (repeat :tag "List of regexp" regexp))
eec82323
LMI
241 :group 'gnus-article-signature)
242
243(defcustom gnus-signature-limit nil
16409b0b 244 "Provide a limit to what is considered a signature.
eec82323
LMI
245If it is a number, no signature may not be longer (in characters) than
246that number. If it is a floating point number, no signature may be
247longer (in lines) than that number. If it is a function, the function
248will be called without any parameters, and if it returns nil, there is
249no signature in the buffer. If it is a string, it will be used as a
01c52d31
MB
250regexp. If it matches, the text in question is not a signature.
251
252This can also be a list of the above values."
4a2358e9
MB
253 :type '(choice (const nil)
254 (integer :value 200)
6748645f 255 (number :value 4.0)
b28080e3 256 function
6748645f 257 (regexp :value ".*"))
eec82323
LMI
258 :group 'gnus-article-signature)
259
260(defcustom gnus-hidden-properties '(invisible t intangible t)
261 "Property list to use for hiding text."
262 :type 'sexp
263 :group 'gnus-article-hiding)
264
23f87bed
MB
265;; Fixme: This isn't the right thing for mixed graphical and non-graphical
266;; frames in a session.
eec82323 267(defcustom gnus-article-x-face-command
23f87bed
MB
268 (if (featurep 'xemacs)
269 (if (or (gnus-image-type-available-p 'xface)
270 (gnus-image-type-available-p 'pbm))
271 'gnus-display-x-face-in-from
272 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
273 (if (gnus-image-type-available-p 'pbm)
274 'gnus-display-x-face-in-from
e0bad764
DL
275 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
276display -"))
6748645f 277 "*String or function to be executed to display an X-Face header.
eec82323 278If it is a string, the command will be executed in a sub-shell
2ff9f5b4 279asynchronously. The compressed face will be piped to this command."
23f87bed
MB
280 :type `(choice string
281 (function-item gnus-display-x-face-in-from)
16409b0b 282 function)
b5a206e7 283 :version "21.1"
23f87bed 284 :group 'gnus-picon
eec82323
LMI
285 :group 'gnus-article-washing)
286
287(defcustom gnus-article-x-face-too-ugly nil
288 "Regexp matching posters whose face shouldn't be shown automatically."
4bb6a3a6 289 :type '(choice regexp (const nil))
eec82323
LMI
290 :group 'gnus-article-washing)
291
e0bad764
DL
292(defcustom gnus-article-banner-alist nil
293 "Banner alist for stripping.
a1506d29 294For example,
23f87bed 295 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
fc2c2db8 296 :version "21.1"
e0bad764
DL
297 :type '(repeat (cons symbol regexp))
298 :group 'gnus-article-washing)
299
23f87bed
MB
300(gnus-define-group-parameter
301 banner
302 :variable-document
303 "Alist of regexps (to match group names) and banner."
304 :variable-group gnus-article-washing
305 :parameter-type
306 '(choice :tag "Banner"
307 :value nil
308 (const :tag "Remove signature" signature)
309 (symbol :tag "Item in `gnus-article-banner-alist'" none)
310 regexp
311 (const :tag "None" nil))
312 :parameter-document
313 "If non-nil, specify how to remove `banners' from articles.
314
315Symbol `signature' means to remove signatures delimited by
316`gnus-signature-separator'. Any other symbol is used to look up a
317regular expression to match the banner in `gnus-article-banner-alist'.
318A string is used as a regular expression to match the banner
319directly.")
320
321(defcustom gnus-article-address-banner-alist nil
322 "Alist of mail addresses and banners.
323Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
324to match a mail address in the From: header, BANNER is one of a symbol
325`signature', an item in `gnus-article-banner-alist', a regexp and nil.
326If ADDRESS matches author's mail address, it will remove things like
327advertisements. For example:
328
329\((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330"
331 :type '(repeat
332 (cons
333 (regexp :tag "Address")
334 (choice :tag "Banner" :value nil
335 (const :tag "Remove signature" signature)
336 (symbol :tag "Item in `gnus-article-banner-alist'" none)
337 regexp
338 (const :tag "None" nil))))
bf247b6e 339 :version "22.1"
23f87bed
MB
340 :group 'gnus-article-washing)
341
ae465fa7
MB
342(defmacro gnus-emphasis-custom-with-format (&rest body)
343 `(let ((format "\
344\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
345\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
346 ,@body))
347
348(defun gnus-emphasis-custom-value-to-external (value)
349 (gnus-emphasis-custom-with-format
350 (if (consp (car value))
351 (list (format format (car (car value)) (cdr (car value)))
352 2
353 (if (nth 1 value) 2 3)
354 (nth 2 value))
355 value)))
356
357(defun gnus-emphasis-custom-value-to-internal (value)
358 (gnus-emphasis-custom-with-format
359 (let ((regexp (concat "\\`"
360 (format (regexp-quote format)
361 "\\([^()]+\\)" "\\([^()]+\\)")
362 "\\'"))
363 pattern)
364 (if (string-match regexp (setq pattern (car value)))
365 (list (cons (match-string 1 pattern) (match-string 2 pattern))
366 (= (nth 2 value) 2)
367 (nth 3 value))
368 value))))
369
eec82323 370(defcustom gnus-emphasis-alist
ae465fa7
MB
371 (let ((types
372 '(("\\*" "\\*" bold nil 2)
23f87bed 373 ("_" "_" underline)
eec82323 374 ("/" "/" italic)
eec82323
LMI
375 ("_/" "/_" underline-italic)
376 ("_\\*" "\\*_" underline-bold)
377 ("\\*/" "/\\*" bold-italic)
378 ("_\\*/" "/\\*_" underline-bold-italic))))
ae465fa7
MB
379 (nconc
380 (gnus-emphasis-custom-with-format
381 (mapcar (lambda (spec)
382 (list (format format (car spec) (cadr spec))
383 (or (nth 3 spec) 2)
384 (or (nth 4 spec) 3)
385 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386 types))
95f75c75
SM
387 '(;; I've never seen anyone use this strikethru convention whereas I've
388 ;; several times seen it triggered by normal text. --Stef
389 ;; Miles suggests that this form is sometimes used but for italics,
390 ;; so maybe we should map it to `italic'.
391 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
392 ;; 2 3 gnus-emphasis-strikethru)
ae465fa7
MB
393 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
394 2 3 gnus-emphasis-underline))))
6748645f 395 "*Alist that says how to fontify certain phrases.
eec82323
LMI
396Each item looks like this:
397
398 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399
400The first element is a regular expression to be matched. The second
401is a number that says what regular expression grouping used to find
402the entire emphasized word. The third is a number that says what
403regexp grouping should be displayed and highlighted. The fourth
404is the face used for highlighting."
ae465fa7
MB
405 :type
406 '(repeat
407 (menu-choice
408 :format "%[Customizing Style%]\n%v"
409 :indent 2
410 (group :tag "Default"
411 :value ("" 0 0 default)
412 :value-create
413 (lambda (widget)
414 (let ((value (widget-get
415 (cadr (widget-get (widget-get widget :parent)
416 :args))
417 :value)))
418 (if (not (eq (nth 2 value) 'default))
419 (widget-put
420 widget
421 :value
422 (gnus-emphasis-custom-value-to-external value))))
423 (widget-group-value-create widget))
ad136a7c
MB
424 regexp
425 (integer :format "Match group: %v")
01c52d31 426 (integer :format "Emphasize group: %v")
ae465fa7
MB
427 face)
428 (group :tag "Simple"
429 :value (("_" . "_") nil default)
430 (cons :format "%v"
ad136a7c
MB
431 (regexp :format "Start regexp: %v")
432 (regexp :format "End regexp: %v"))
ae465fa7
MB
433 (boolean :format "Show start and end patterns: %[%v%]\n"
434 :on " On " :off " Off ")
435 face)))
436 :get (lambda (symbol)
437 (mapcar 'gnus-emphasis-custom-value-to-internal
438 (default-value symbol)))
439 :set (lambda (symbol value)
440 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441 value)))
eec82323
LMI
442 :group 'gnus-article-emphasis)
443
16409b0b
GM
444(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
445 "A regexp to describe whitespace which should not be emphasized.
446Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
447The former avoids underlining of leading and trailing whitespace,
448and the latter avoids underlining any whitespace at all."
fc2c2db8 449 :version "21.1"
16409b0b
GM
450 :group 'gnus-article-emphasis
451 :type 'regexp)
452
23f87bed 453(defface gnus-emphasis-bold '((t (:bold t)))
eec82323
LMI
454 "Face used for displaying strong emphasized text (*word*)."
455 :group 'gnus-article-emphasis)
456
23f87bed 457(defface gnus-emphasis-italic '((t (:italic t)))
eec82323
LMI
458 "Face used for displaying italic emphasized text (/word/)."
459 :group 'gnus-article-emphasis)
460
461(defface gnus-emphasis-underline '((t (:underline t)))
462 "Face used for displaying underlined emphasized text (_word_)."
463 :group 'gnus-article-emphasis)
464
23f87bed 465(defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
eec82323
LMI
466 "Face used for displaying underlined bold emphasized text (_*word*_)."
467 :group 'gnus-article-emphasis)
468
23f87bed 469(defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
8de38c21 470 "Face used for displaying underlined italic emphasized text (_/word/_)."
eec82323
LMI
471 :group 'gnus-article-emphasis)
472
23f87bed 473(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
eec82323
LMI
474 "Face used for displaying bold italic emphasized text (/*word*/)."
475 :group 'gnus-article-emphasis)
476
477(defface gnus-emphasis-underline-bold-italic
23f87bed 478 '((t (:bold t :italic t :underline t)))
eec82323 479 "Face used for displaying underlined bold italic emphasized text.
8f688cb0 480Example: (_/*word*/_)."
eec82323
LMI
481 :group 'gnus-article-emphasis)
482
23f87bed
MB
483(defface gnus-emphasis-strikethru (if (featurep 'xemacs)
484 '((t (:strikethru t)))
485 '((t (:strike-through t))))
486 "Face used for displaying strike-through text (-word-)."
487 :group 'gnus-article-emphasis)
488
16409b0b
GM
489(defface gnus-emphasis-highlight-words
490 '((t (:background "black" :foreground "yellow")))
491 "Face used for displaying highlighted words."
492 :group 'gnus-article-emphasis)
493
01c52d31 494(defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
eec82323 495 "Format for display of Date headers in article bodies.
6748645f
LMI
496See `format-time-string' for the possible values.
497
498The variable can also be function, which should return a complete Date
499header. The function is called with one argument, the time, which can
500be fed to `format-time-string'."
01c52d31 501 :type '(choice string function)
eec82323
LMI
502 :link '(custom-manual "(gnus)Article Date")
503 :group 'gnus-article-washing)
504
eec82323 505(defcustom gnus-save-all-headers t
26c9afc3
MB
506 "*If non-nil, don't remove any headers before saving.
507This will be overridden by the `:headers' property that the symbol of
508the saver function, which is specified by `gnus-default-article-saver',
509might have."
eec82323
LMI
510 :group 'gnus-article-saving
511 :type 'boolean)
512
513(defcustom gnus-prompt-before-saving 'always
514 "*This variable says how much prompting is to be done when saving articles.
515If it is nil, no prompting will be done, and the articles will be
516saved to the default files. If this variable is `always', each and
517every article that is saved will be preceded by a prompt, even when
518saving large batches of articles. If this variable is neither nil not
519`always', there the user will be prompted once for a file name for
520each invocation of the saving commands."
521 :group 'gnus-article-saving
522 :type '(choice (item always)
523 (item :tag "never" nil)
6748645f 524 (sexp :tag "once" :format "%t\n" :value t)))
eec82323
LMI
525
526(defcustom gnus-saved-headers gnus-visible-headers
527 "Headers to keep if `gnus-save-all-headers' is nil.
528If `gnus-save-all-headers' is non-nil, this variable will be ignored.
529If that variable is nil, however, all headers that match this regexp
26c9afc3
MB
530will be kept while the rest will be deleted before saving. This and
531`gnus-save-all-headers' will be overridden by the `:headers' property
532that the symbol of the saver function, which is specified by
533`gnus-default-article-saver', might have."
eec82323 534 :group 'gnus-article-saving
4bb6a3a6 535 :type 'regexp)
eec82323 536
fef8d38e 537;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
eec82323
LMI
538(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
539 "A function to save articles in your favourite format.
26c9afc3
MB
540The function will be called by way of the `gnus-summary-save-article'
541command, and friends such as `gnus-summary-save-article-rmail'.
eec82323
LMI
542
543Gnus provides the following functions:
544
545* gnus-summary-save-in-rmail (Rmail format)
546* gnus-summary-save-in-mail (Unix mail format)
547* gnus-summary-save-in-folder (MH folder)
548* gnus-summary-save-in-file (article format)
23f87bed 549* gnus-summary-save-body-in-file (article body)
eec82323 550* gnus-summary-save-in-vm (use VM's folder format)
26c9afc3
MB
551* gnus-summary-write-to-file (article format -- overwrite)
552* gnus-summary-write-body-to-file (article body -- overwrite)
89167438 553* gnus-summary-save-in-pipe (article format)
26c9afc3
MB
554
555The symbol of each function may have the following properties:
556
557* :decode
558The value non-nil means save decoded articles. This is meaningful
559only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
89167438
MB
560`gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
561`gnus-summary-save-in-pipe'.
26c9afc3
MB
562
563* :function
564The value specifies an alternative function which appends, not
565overwrites, articles to a file. This implies that when saving many
566articles at a time, `gnus-prompt-before-saving' is bound to t and all
567articles are saved in a single file. This is meaningful only with
568`gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569
570* :headers
571The value specifies the symbol of a variable of which the value
572specifies headers to be saved. If it is omitted,
573`gnus-save-all-headers' and `gnus-saved-headers' control what
574headers should be saved."
eec82323
LMI
575 :group 'gnus-article-saving
576 :type '(radio (function-item gnus-summary-save-in-rmail)
577 (function-item gnus-summary-save-in-mail)
578 (function-item gnus-summary-save-in-folder)
579 (function-item gnus-summary-save-in-file)
23f87bed 580 (function-item gnus-summary-save-body-in-file)
eec82323 581 (function-item gnus-summary-save-in-vm)
58090a8d 582 (function-item gnus-summary-write-to-file)
26c9afc3 583 (function-item gnus-summary-write-body-to-file)
89167438 584 (function-item gnus-summary-save-in-pipe)
58090a8d 585 (function)))
eec82323 586
26c9afc3
MB
587(defcustom gnus-article-save-coding-system
588 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
589 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
590 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
591 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
592 "Coding system used to save decoded articles to a file.
593
594The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
595which can safely encode any characters in text. This is used by the
596commands including:
597
598* gnus-summary-save-article-file
599* gnus-summary-save-article-body-file
600* gnus-summary-write-article-file
601* gnus-summary-write-article-body-file
602
603and the functions to which you may set `gnus-default-article-saver':
604
605* gnus-summary-save-in-file
606* gnus-summary-save-body-in-file
607* gnus-summary-write-to-file
608* gnus-summary-write-body-to-file
609
610Those commands and functions save just text displayed in the article
611buffer to a file if the value of this variable is non-nil. Note that
612buttonized MIME parts will be lost in a saved file in that case.
613Otherwise, raw articles will be saved."
614 :group 'gnus-article-saving
615 :type `(choice
616 :format "%{%t%}:\n %[Value Menu%] %v"
617 (const :tag "Save raw articles" nil)
618 ,@(delq nil
619 (mapcar
620 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
621 '((const :tag "UTF-8" utf-8)
622 (const :tag "iso-2022-7bit" iso-2022-7bit)
623 (const :tag "Emacs internal" emacs-mule)
624 (const :tag "escape-quoted" escape-quoted))))
625 (symbol :tag "Coding system")))
626
eec82323
LMI
627(defcustom gnus-rmail-save-name 'gnus-plain-save-name
628 "A function generating a file name to save articles in Rmail format.
629The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
630 :group 'gnus-article-saving
631 :type 'function)
632
633(defcustom gnus-mail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Unix mail format.
635The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
637 :type 'function)
638
639(defcustom gnus-folder-save-name 'gnus-folder-save-name
640 "A function generating a file name to save articles in MH folder.
641The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
642 :group 'gnus-article-saving
643 :type 'function)
644
645(defcustom gnus-file-save-name 'gnus-numeric-save-name
646 "A function generating a file name to save articles in article format.
647The function is called with NEWSGROUP, HEADERS, and optional
648LAST-FILE."
649 :group 'gnus-article-saving
650 :type 'function)
651
652(defcustom gnus-split-methods
653 '((gnus-article-archive-name)
654 (gnus-article-nndoc-name))
6748645f 655 "*Variable used to suggest where articles are to be saved.
eec82323
LMI
656For instance, if you would like to save articles related to Gnus in
657the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
658you could set this variable to something like:
659
660 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
661 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662
01c52d31
MB
663This variable is an alist where the key is the match and the
664value is a list of possible files to save in if the match is
665non-nil.
eec82323
LMI
666
667If the match is a string, it is used as a regexp match on the
668article. If the match is a symbol, that symbol will be funcalled
669from the buffer of the article to be saved with the newsgroup as the
01c52d31 670parameter. If it is a list, it will be evaled in the same buffer.
eec82323 671
01c52d31
MB
672If this form or function returns a string, this string will be used as a
673possible file name; and if it returns a non-nil list, that list will be
674used as possible file names."
eec82323 675 :group 'gnus-article-saving
6748645f
LMI
676 :type '(repeat (choice (list :value (fun) function)
677 (cons :value ("" "") regexp (repeat string))
678 (sexp :value nil))))
eec82323 679
eec82323
LMI
680(defcustom gnus-page-delimiter "^\^L"
681 "*Regexp describing what to use as article page delimiters.
682The default value is \"^\^L\", which is a form linefeed at the
683beginning of a line."
684 :type 'regexp
685 :group 'gnus-article-various)
686
16409b0b 687(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
eec82323 688 "*The format specification for the article mode line.
16409b0b
GM
689See `gnus-summary-mode-line-format' for a closer description.
690
691The following additional specs are available:
692
693%w The article washing status.
694%m The number of MIME parts in the article."
eec82323
LMI
695 :type 'string
696 :group 'gnus-article-various)
697
698(defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
700 :type 'hook
701 :group 'gnus-article-various)
702
23f87bed
MB
703(when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
709
eec82323
LMI
710(defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
714
715(defcustom gnus-article-prepare-hook nil
16409b0b 716 "*A hook called after an article has been prepared in the article buffer."
eec82323
LMI
717 :type 'hook
718 :group 'gnus-article-various)
719
01c52d31
MB
720(defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722Each element is a regular expression."
330f707b 723 :version "23.1" ;; No Gnus
01c52d31
MB
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
726
265ac10b 727(make-obsolete-variable 'gnus-article-hide-pgp-hook nil
6b958814 728 "Gnus 5.10 (Emacs 22.1)")
a8151ef7 729
01c52d31
MB
730(defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
734
735(defcustom gnus-article-button-face 'gnus-button
eec82323
LMI
736 "Face used for highlighting buttons in the article buffer.
737
738An article button is a piece of text that you can activate by pressing
739`RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
742
743(defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
745
746Article buttons will be displayed in this face when the cursor is
747above them."
748 :type 'face
749 :group 'gnus-article-buttons)
750
0f49874b 751(defcustom gnus-signature-face 'gnus-signature
a8151ef7 752 "Face used for highlighting a signature in the article buffer.
0f49874b 753Obsolete; use the face `gnus-signature' for customizations instead."
eec82323
LMI
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
757
0f49874b 758(defface gnus-signature
f59a3415 759 '((t
23f87bed 760 (:italic t)))
a8151ef7
LMI
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
0f49874b
MB
764;; backward-compatibility alias
765(put 'gnus-signature-face 'face-alias 'gnus-signature)
3d493bef 766(put 'gnus-signature-face 'obsolete-face "22.1")
a8151ef7 767
0f49874b 768(defface gnus-header-from
eec82323
LMI
769 '((((class color)
770 (background dark))
01c52d31 771 (:foreground "PaleGreen1"))
eec82323
LMI
772 (((class color)
773 (background light))
6748645f 774 (:foreground "red3"))
eec82323 775 (t
23f87bed 776 (:italic t)))
eec82323
LMI
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
0f49874b
MB
780;; backward-compatibility alias
781(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
3d493bef 782(put 'gnus-header-from-face 'obsolete-face "22.1")
eec82323 783
0f49874b 784(defface gnus-header-subject
eec82323
LMI
785 '((((class color)
786 (background dark))
01c52d31 787 (:foreground "SeaGreen1"))
eec82323
LMI
788 (((class color)
789 (background light))
6748645f 790 (:foreground "red4"))
eec82323 791 (t
23f87bed 792 (:bold t :italic t)))
eec82323
LMI
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
0f49874b
MB
796;; backward-compatibility alias
797(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
3d493bef 798(put 'gnus-header-subject-face 'obsolete-face "22.1")
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)
3d493bef 816(put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
eec82323 817
0f49874b 818(defface gnus-header-name
eec82323
LMI
819 '((((class color)
820 (background dark))
01c52d31 821 (:foreground "SpringGreen2"))
eec82323
LMI
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
825 (t
23f87bed 826 (:bold t)))
eec82323
LMI
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
0f49874b
MB
830;; backward-compatibility alias
831(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
3d493bef 832(put 'gnus-header-name-face 'obsolete-face "22.1")
eec82323 833
0f49874b 834(defface gnus-header-content
eec82323
LMI
835 '((((class color)
836 (background dark))
01c52d31 837 (:foreground "SpringGreen1" :italic t))
eec82323
LMI
838 (((class color)
839 (background light))
23f87bed 840 (:foreground "indianred4" :italic t))
eec82323 841 (t
23f87bed 842 (:italic t))) "Face used for displaying header content."
eec82323
LMI
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
0f49874b
MB
845;; backward-compatibility alias
846(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
3d493bef 847(put 'gnus-header-content-face 'obsolete-face "22.1")
eec82323
LMI
848
849(defcustom gnus-header-face-alist
0f49874b
MB
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
23f87bed 854 "*Controls highlighting of article headers.
eec82323
LMI
855
856An alist of the form (HEADER NAME CONTENT).
857
23f87bed
MB
858HEADER is a regular expression which should match the name of a
859header and NAME and CONTENT are either face names or nil.
eec82323
LMI
860
861The name of each header field will be displayed using the face
23f87bed
MB
862specified by the first element in the list where HEADER matches
863the header name and NAME is non-nil. Similarly, the content will
864be displayed by the first non-nil matching CONTENT face."
eec82323
LMI
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
874
01c52d31
MB
875(defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
878 (png . nil)))
879 "Alist of image types and properties applied to Face and X-Face images.
880Here are examples:
881
882;; Specify the altitude of Face images in the From header.
883\(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
886
887;; Show Face images as pressed buttons.
888\(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
891
892See the manual for the valid properties for various image types.
893Currently, `pbm' is used for X-Face images and `png' is used for Face
894images in Emacs. Only the `:face' property is effective on the `xface'
895image type in XEmacs if it is built with the libcompface library."
330f707b 896 :version "23.1" ;; No Gnus
01c52d31
MB
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
899
16409b0b 900(defcustom gnus-article-decode-hook
23f87bed
MB
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
16409b0b
GM
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
905 :type 'hook)
906
907(defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
910 :type 'function)
911
912(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
914
343d6628
MB
915(defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
917
16409b0b 918(defvar gnus-article-dumbquotes-map
23f87bed
MB
919 '(("\200" "EUR")
920 ("\202" ",")
16409b0b
GM
921 ("\203" "f")
922 ("\204" ",,")
923 ("\205" "...")
924 ("\213" "<")
925 ("\214" "OE")
926 ("\221" "`")
927 ("\222" "'")
928 ("\223" "``")
929 ("\224" "\"")
930 ("\225" "*")
e0bad764
DL
931 ("\226" "-")
932 ("\227" "--")
23f87bed 933 ("\230" "~")
16409b0b
GM
934 ("\231" "(TM)")
935 ("\233" ">")
936 ("\234" "oe")
937 ("\264" "'"))
938 "Table for MS-to-Latin1 translation.")
939
940(defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
fc2c2db8 942 :version "21.1"
16409b0b
GM
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
945
946(defcustom gnus-unbuttonized-mime-types '(".*/.*")
23f87bed
MB
947 "List of MIME types that should not be given buttons when rendered inline.
948See also `gnus-buttonized-mime-types' which may override this variable.
949This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :version "21.1"
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
953
954(defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956If set, this variable overrides `gnus-unbuttonized-mime-types'.
957To see e.g. security buttons you could set this to
3031d8b0
MB
958`(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959this list to display radio buttons that allow you to choose one of two
960media types those mails include. See also `mm-discouraged-alternatives'.
23f87bed 961This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
bf247b6e 962 :version "22.1"
16409b0b
GM
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
965
23f87bed
MB
966(defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968When nil (the default value), then some MIME parts do not get buttons,
969as described by the variables `gnus-buttonized-mime-types' and
970`gnus-unbuttonized-mime-types'."
bf247b6e 971 :version "22.1"
d0859c9a 972 :group 'gnus-article-mime
23f87bed
MB
973 :type 'boolean)
974
975(defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977This variable is used by `gnus-article-treat-body-boundary' which can
978be controlled by `gnus-treat-body-boundary'."
bf247b6e 979 :version "22.1"
23f87bed
MB
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
982 string))
983
97f78c9b
MB
984(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "/usr/share/picons")
23f87bed
MB
986 "Defines the location of the faces database.
987For information on obtaining this database of pretty pictures, please
988see http://www.cs.indiana.edu/picons/ftp/index.html"
bf247b6e 989 :version "22.1"
23f87bed
MB
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
994 :group 'gnus-picon)
995
996(defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1002 installed))
1003
16409b0b
GM
1004(defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006This is meant for people who want to do something automatic based
1007on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
4a2358e9
MB
1009 :type '(choice (const nil)
1010 function))
16409b0b
GM
1011
1012(defcustom gnus-mime-multipart-functions nil
fc2c2db8
DL
1013 "An alist of MIME types to functions to display them."
1014 :version "21.1"
1015 :group 'gnus-article-mime
01c52d31 1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
16409b0b
GM
1017
1018(defcustom gnus-article-date-lapsed-new-header nil
1019 "Whether the X-Sent and Date headers can coexist.
1020When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1021either replace the old \"Date:\" header (if this variable is nil), or
1022be added below it (otherwise)."
fc2c2db8 1023 :version "21.1"
16409b0b
GM
1024 :group 'gnus-article-headers
1025 :type 'boolean)
1026
1027(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1028 "Function called with a MIME handle as the argument.
1029This is meant for people who want to view first matched part.
a1506d29
JB
1030For `undisplayed-alternative' (default), the first undisplayed
1031part or alternative part is used. For `undisplayed', the first
1032undisplayed part is used. For a function, the first part which
f20b2f5c 1033the function return t is used. For nil, the first part is
16409b0b 1034used."
fc2c2db8 1035 :version "21.1"
16409b0b 1036 :group 'gnus-article-mime
a1506d29 1037 :type '(choice
16409b0b
GM
1038 (item :tag "first" :value nil)
1039 (item :tag "undisplayed" :value undisplayed)
a1506d29 1040 (item :tag "undisplayed or alternative"
16409b0b
GM
1041 :value undisplayed-alternative)
1042 (function)))
1043
e0bad764
DL
1044(defcustom gnus-mime-action-alist
1045 '(("save to file" . gnus-mime-save-part)
23f87bed 1046 ("save and strip" . gnus-mime-save-part-and-strip)
01c52d31 1047 ("replace with file" . gnus-mime-replace-part)
23f87bed 1048 ("delete part" . gnus-mime-delete-part)
e0bad764
DL
1049 ("display as text" . gnus-mime-inline-part)
1050 ("view the part" . gnus-mime-view-part)
1051 ("pipe to command" . gnus-mime-pipe-part)
1052 ("toggle display" . gnus-article-press-button)
23f87bed 1053 ("toggle display" . gnus-article-view-part-as-charset)
e0bad764 1054 ("view as type" . gnus-mime-view-part-as-type)
23f87bed
MB
1055 ("view internally" . gnus-mime-view-part-internally)
1056 ("view externally" . gnus-mime-view-part-externally))
e0bad764
DL
1057 "An alist of actions that run on the MIME attachment."
1058 :group 'gnus-article-mime
1059 :type '(repeat (cons (string :tag "name")
1060 (function))))
1061
01c52d31
MB
1062(defcustom gnus-auto-select-part 1
1063 "Advance to next MIME part when deleting or stripping parts.
1064
1065When 0, point will be placed on the same part as before. When
1066positive (negative), move point forward (backwards) this many
1067parts. When nil, redisplay article."
330f707b 1068 :version "23.1" ;; No Gnus
01c52d31
MB
1069 :group 'gnus-article-mime
1070 :type '(choice (const nil :tag "Redisplay article.")
1071 (const 1 :tag "Next part.")
1072 (const 0 :tag "Current part.")
1073 integer))
1074
16409b0b
GM
1075;;;
1076;;; The treatment variables
1077;;;
1078
1079(defvar gnus-part-display-hook nil
1080 "Hook called on parts that are to receive treatment.")
1081
1082(defvar gnus-article-treat-custom
1083 '(choice (const :tag "Off" nil)
1084 (const :tag "On" t)
1085 (const :tag "Header" head)
01c52d31 1086 (const :tag "First" first)
16409b0b
GM
1087 (const :tag "Last" last)
1088 (integer :tag "Less")
1089 (repeat :tag "Groups" regexp)
1090 (sexp :tag "Predicate")))
1091
1092(defvar gnus-article-treat-head-custom
1093 '(choice (const :tag "Off" nil)
1094 (const :tag "Header" head)))
1095
01c52d31
MB
1096(defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1097 "text/x-patch")
16409b0b
GM
1098 "Parts to treat.")
1099
1100(defvar gnus-inhibit-treatment nil
1101 "Whether to inhibit treatment.")
1102
23f87bed 1103(defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
16409b0b 1104 "Highlight the signature.
01c52d31
MB
1105Valid values are nil, t, `head', `first', `last', an integer or a
1106predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1107 :group 'gnus-article-treat
23f87bed 1108 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1109 :type gnus-article-treat-custom)
1110(put 'gnus-treat-highlight-signature 'highlight t)
1111
1112(defcustom gnus-treat-buttonize 100000
1113 "Add buttons.
01c52d31
MB
1114Valid values are nil, t, `head', `first', `last', an integer or a
1115predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1116 :group 'gnus-article-treat
23f87bed 1117 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1118 :type gnus-article-treat-custom)
1119(put 'gnus-treat-buttonize 'highlight t)
1120
1121(defcustom gnus-treat-buttonize-head 'head
1122 "Add buttons to the head.
01c52d31
MB
1123Valid values are nil, t, `head', `first', `last', an integer or a
1124predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1125 :group 'gnus-article-treat
23f87bed 1126 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1127 :type gnus-article-treat-head-custom)
1128(put 'gnus-treat-buttonize-head 'highlight t)
1129
437ce4be 1130(defcustom gnus-treat-emphasize 50000
16409b0b 1131 "Emphasize text.
01c52d31
MB
1132Valid values are nil, t, `head', `first', `last', an integer or a
1133predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1134 :group 'gnus-article-treat
23f87bed 1135 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1136 :type gnus-article-treat-custom)
1137(put 'gnus-treat-emphasize 'highlight t)
1138
1139(defcustom gnus-treat-strip-cr nil
1140 "Remove carriage returns.
01c52d31
MB
1141Valid values are nil, t, `head', `first', `last', an integer or a
1142predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1143 :version "22.1"
16409b0b 1144 :group 'gnus-article-treat
23f87bed
MB
1145 :link '(custom-manual "(gnus)Customizing Articles")
1146 :type gnus-article-treat-custom)
1147
1148(defcustom gnus-treat-unsplit-urls nil
1149 "Remove newlines from within URLs.
01c52d31
MB
1150Valid values are nil, t, `head', `first', `last', an integer or a
1151predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1152 :version "22.1"
23f87bed
MB
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-custom)
1156
1157(defcustom gnus-treat-leading-whitespace nil
1158 "Remove leading whitespace in headers.
01c52d31
MB
1159Valid values are nil, t, `head', `first', `last', an integer or a
1160predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1161 :version "22.1"
23f87bed
MB
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1164 :type gnus-article-treat-custom)
1165
1166(defcustom gnus-treat-hide-headers 'head
1167 "Hide headers.
01c52d31
MB
1168Valid values are nil, t, `head', `first', `last', an integer or a
1169predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1170 :group 'gnus-article-treat
23f87bed 1171 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1172 :type gnus-article-treat-head-custom)
1173
1174(defcustom gnus-treat-hide-boring-headers nil
1175 "Hide boring headers.
01c52d31
MB
1176Valid values are nil, t, `head', `first', `last', an integer or a
1177predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1178 :group 'gnus-article-treat
23f87bed 1179 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1180 :type gnus-article-treat-head-custom)
1181
1182(defcustom gnus-treat-hide-signature nil
1183 "Hide the signature.
01c52d31
MB
1184Valid values are nil, t, `head', `first', `last', an integer or a
1185predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1186 :group 'gnus-article-treat
23f87bed 1187 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1188 :type gnus-article-treat-custom)
1189
1190(defcustom gnus-treat-fill-article nil
1191 "Fill the article.
01c52d31
MB
1192Valid values are nil, t, `head', `first', `last', an integer or a
1193predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1194 :group 'gnus-article-treat
23f87bed 1195 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1196 :type gnus-article-treat-custom)
1197
1198(defcustom gnus-treat-hide-citation nil
1199 "Hide cited text.
01c52d31
MB
1200Valid values are nil, t, `head', `first', `last', an integer or a
1201predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1202 :group 'gnus-article-treat
23f87bed 1203 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1204 :type gnus-article-treat-custom)
1205
e0bad764
DL
1206(defcustom gnus-treat-hide-citation-maybe nil
1207 "Hide cited text.
01c52d31
MB
1208Valid values are nil, t, `head', `first', `last', an integer or a
1209predicate. See Info node `(gnus)Customizing Articles'."
e0bad764 1210 :group 'gnus-article-treat
23f87bed 1211 :link '(custom-manual "(gnus)Customizing Articles")
e0bad764
DL
1212 :type gnus-article-treat-custom)
1213
16409b0b
GM
1214(defcustom gnus-treat-strip-list-identifiers 'head
1215 "Strip list identifiers from `gnus-list-identifiers`.
01c52d31
MB
1216Valid values are nil, t, `head', `first', `last', an integer or a
1217predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1218 :version "21.1"
16409b0b 1219 :group 'gnus-article-treat
23f87bed 1220 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1221 :type gnus-article-treat-custom)
1222
265ac10b
SM
1223(make-obsolete-variable 'gnus-treat-strip-pgp nil
1224 "Gnus 5.10 (Emacs 22.1)")
16409b0b
GM
1225
1226(defcustom gnus-treat-strip-pem nil
1227 "Strip PEM signatures.
01c52d31
MB
1228Valid values are nil, t, `head', `first', `last', an integer or a
1229predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1230 :group 'gnus-article-treat
23f87bed 1231 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1232 :type gnus-article-treat-custom)
1233
1234(defcustom gnus-treat-strip-banner t
1235 "Strip banners from articles.
1236The banner to be stripped is specified in the `banner' group parameter.
01c52d31
MB
1237Valid values are nil, t, `head', `first', `last', an integer or a
1238predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1239 :group 'gnus-article-treat
23f87bed 1240 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1241 :type gnus-article-treat-custom)
1242
1243(defcustom gnus-treat-highlight-headers 'head
1244 "Highlight the headers.
01c52d31
MB
1245Valid values are nil, t, `head', `first', `last', an integer or a
1246predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1247 :group 'gnus-article-treat
23f87bed 1248 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1249 :type gnus-article-treat-head-custom)
1250(put 'gnus-treat-highlight-headers 'highlight t)
1251
1252(defcustom gnus-treat-highlight-citation t
1253 "Highlight cited text.
01c52d31
MB
1254Valid values are nil, t, `head', `first', `last', an integer or a
1255predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1256 :group 'gnus-article-treat
23f87bed 1257 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1258 :type gnus-article-treat-custom)
1259(put 'gnus-treat-highlight-citation 'highlight t)
1260
1261(defcustom gnus-treat-date-ut nil
1262 "Display the Date in UT (GMT).
01c52d31
MB
1263Valid values are nil, t, `head', `first', `last', an integer or a
1264predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1265 :group 'gnus-article-treat
23f87bed 1266 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1267 :type gnus-article-treat-head-custom)
1268
1269(defcustom gnus-treat-date-local nil
1270 "Display the Date in the local timezone.
01c52d31
MB
1271Valid values are nil, t, `head', `first', `last', an integer or a
1272predicate. See Info node `(gnus)Customizing Articles'."
23f87bed
MB
1273 :group 'gnus-article-treat
1274 :link '(custom-manual "(gnus)Customizing Articles")
1275 :type gnus-article-treat-head-custom)
1276
1277(defcustom gnus-treat-date-english nil
1278 "Display the Date in a format that can be read aloud in English.
01c52d31
MB
1279Valid values are nil, t, `head', `first', `last', an integer or a
1280predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1281 :version "22.1"
16409b0b 1282 :group 'gnus-article-treat
23f87bed 1283 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1284 :type gnus-article-treat-head-custom)
1285
1286(defcustom gnus-treat-date-lapsed nil
1287 "Display the Date header in a way that says how much time has elapsed.
01c52d31
MB
1288Valid values are nil, t, `head', `first', `last', an integer or a
1289predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1290 :group 'gnus-article-treat
23f87bed 1291 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1292 :type gnus-article-treat-head-custom)
1293
1294(defcustom gnus-treat-date-original nil
1295 "Display the date in the original timezone.
01c52d31
MB
1296Valid values are nil, t, `head', `first', `last', an integer or a
1297predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1298 :group 'gnus-article-treat
23f87bed 1299 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1300 :type gnus-article-treat-head-custom)
1301
1302(defcustom gnus-treat-date-iso8601 nil
1303 "Display the date in the ISO8601 format.
01c52d31
MB
1304Valid values are nil, t, `head', `first', `last', an integer or a
1305predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1306 :version "21.1"
16409b0b 1307 :group 'gnus-article-treat
23f87bed 1308 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1309 :type gnus-article-treat-head-custom)
1310
1311(defcustom gnus-treat-date-user-defined nil
1312 "Display the date in a user-defined format.
1313The format is defined by the `gnus-article-time-format' variable.
01c52d31
MB
1314Valid values are nil, t, `head', `first', `last', an integer or a
1315predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1316 :group 'gnus-article-treat
23f87bed 1317 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1318 :type gnus-article-treat-head-custom)
1319
1320(defcustom gnus-treat-strip-headers-in-body t
1321 "Strip the X-No-Archive header line from the beginning of the body.
01c52d31
MB
1322Valid values are nil, t, `head', `first', `last', an integer or a
1323predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1324 :version "21.1"
16409b0b 1325 :group 'gnus-article-treat
23f87bed 1326 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1327 :type gnus-article-treat-custom)
1328
1329(defcustom gnus-treat-strip-trailing-blank-lines nil
1330 "Strip trailing blank lines.
01c52d31
MB
1331Valid values are nil, t, `head', `first', `last', an integer or a
1332predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1333
1334When set to t, it also strips trailing blanks in all MIME parts.
1335Consider to use `last' instead."
16409b0b 1336 :group 'gnus-article-treat
23f87bed 1337 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1338 :type gnus-article-treat-custom)
1339
1340(defcustom gnus-treat-strip-leading-blank-lines nil
1341 "Strip leading blank lines.
01c52d31
MB
1342Valid values are nil, t, `head', `first', `last', an integer or a
1343predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1344
1345When set to t, it also strips trailing blanks in all MIME parts."
16409b0b 1346 :group 'gnus-article-treat
23f87bed 1347 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1348 :type gnus-article-treat-custom)
1349
1350(defcustom gnus-treat-strip-multiple-blank-lines nil
1351 "Strip multiple blank lines.
01c52d31
MB
1352Valid values are nil, t, `head', `first', `last', an integer or a
1353predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1354 :group 'gnus-article-treat
23f87bed
MB
1355 :link '(custom-manual "(gnus)Customizing Articles")
1356 :type gnus-article-treat-custom)
1357
1358(defcustom gnus-treat-unfold-headers 'head
1359 "Unfold folded header lines.
01c52d31
MB
1360Valid values are nil, t, `head', `first', `last', an integer or a
1361predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1362 :version "22.1"
23f87bed
MB
1363 :group 'gnus-article-treat
1364 :link '(custom-manual "(gnus)Customizing Articles")
1365 :type gnus-article-treat-custom)
1366
01c52d31
MB
1367(defcustom gnus-article-unfold-long-headers nil
1368 "If non-nil, allow unfolding headers even if the header is long.
1369If it is a regexp, only long headers matching this regexp are unfolded.
1370If it is t, all long headers are unfolded.
1371
1372This variable has no effect if `gnus-treat-unfold-headers' is nil."
330f707b 1373 :version "23.1" ;; No Gnus
01c52d31
MB
1374 :group 'gnus-article-treat
1375 :type '(choice (const nil)
1376 (const :tag "all" t)
1377 (regexp)))
1378
23f87bed
MB
1379(defcustom gnus-treat-fold-headers nil
1380 "Fold headers.
01c52d31
MB
1381Valid values are nil, t, `head', `first', `last', an integer or a
1382predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1383 :version "22.1"
23f87bed
MB
1384 :group 'gnus-article-treat
1385 :link '(custom-manual "(gnus)Customizing Articles")
1386 :type gnus-article-treat-custom)
1387
1388(defcustom gnus-treat-fold-newsgroups 'head
1389 "Fold the Newsgroups and Followup-To headers.
01c52d31
MB
1390Valid values are nil, t, `head', `first', `last', an integer or a
1391predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1392 :version "22.1"
23f87bed
MB
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1395 :type gnus-article-treat-custom)
1396
1397(defcustom gnus-treat-overstrike t
1398 "Treat overstrike highlighting.
01c52d31
MB
1399Valid values are nil, t, `head', `first', `last', an integer or a
1400predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1401 :group 'gnus-article-treat
23f87bed 1402 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1403 :type gnus-article-treat-custom)
1404(put 'gnus-treat-overstrike 'highlight t)
1405
01c52d31
MB
1406(defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1407 "Treat ANSI SGR control sequences.
1408Valid values are nil, t, `head', `first', `last', an integer or a
1409predicate. See Info node `(gnus)Customizing Articles'."
1410 :group 'gnus-article-treat
1411 :link '(custom-manual "(gnus)Customizing Articles")
1412 :type gnus-article-treat-custom)
1413
23f87bed 1414(make-obsolete-variable 'gnus-treat-display-xface
6b958814 1415 'gnus-treat-display-x-face "Emacs 22.1")
23f87bed
MB
1416
1417(defcustom gnus-treat-display-x-face
1418 (and (not noninteractive)
11e95b02
MB
1419 (gnus-image-type-available-p 'xbm)
1420 (if (featurep 'xemacs)
1421 (featurep 'xface)
86f5c034
SM
1422 (condition-case nil
1423 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1424 (executable-find "icontopbm"))
1425 ;; shell-command-to-string may signal an error, e.g. if
1426 ;; shell-file-name is not found.
1427 (error nil)))
8b93df01 1428 'head)
16409b0b 1429 "Display X-Face headers.
87ba2830 1430Valid values are nil and `head'.
23f87bed
MB
1431See Info node `(gnus)Customizing Articles' and Info node
1432`(gnus)X-Face' for details."
1433 :group 'gnus-article-treat
1434 :version "21.1"
1435 :link '(custom-manual "(gnus)Customizing Articles")
1436 :link '(custom-manual "(gnus)X-Face")
1437 :type gnus-article-treat-head-custom
1438 :set (lambda (symbol value)
1439 (set-default
1440 symbol
1441 (cond ((or (boundp symbol) (get symbol 'saved-value))
1442 value)
1443 ((boundp 'gnus-treat-display-xface)
1444 (message "\
1445** gnus-treat-display-xface is an obsolete variable;\
1446 use gnus-treat-display-x-face instead")
1447 (default-value 'gnus-treat-display-xface))
1448 ((get 'gnus-treat-display-xface 'saved-value)
1449 (message "\
1450** gnus-treat-display-xface is an obsolete variable;\
1451 use gnus-treat-display-x-face instead")
1452 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1453 (t
1454 value)))))
1455(put 'gnus-treat-display-x-face 'highlight t)
1456
1457(defcustom gnus-treat-display-face
1458 (and (not noninteractive)
11e95b02 1459 (gnus-image-type-available-p 'png)
23f87bed
MB
1460 'head)
1461 "Display Face headers.
01c52d31
MB
1462Valid values are nil, t, `head', `first', `last', an integer or a
1463predicate. See Info node `(gnus)Customizing Articles' and Info
41ec3f54 1464node `(gnus)Face' for details."
16409b0b 1465 :group 'gnus-article-treat
bf247b6e 1466 :version "22.1"
23f87bed
MB
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)X-Face")
16409b0b 1469 :type gnus-article-treat-head-custom)
23f87bed 1470(put 'gnus-treat-display-face 'highlight t)
16409b0b 1471
11e95b02 1472(defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
16409b0b 1473 "Display smileys.
01c52d31
MB
1474Valid values are nil, t, `head', `first', `last', an integer or a
1475predicate. See Info node `(gnus)Customizing Articles' and Info
1476node `(gnus)Smileys' for details."
16409b0b 1477 :group 'gnus-article-treat
b5a206e7 1478 :version "21.1"
23f87bed
MB
1479 :link '(custom-manual "(gnus)Customizing Articles")
1480 :link '(custom-manual "(gnus)Smileys")
16409b0b
GM
1481 :type gnus-article-treat-custom)
1482(put 'gnus-treat-display-smileys 'highlight t)
1483
23f87bed
MB
1484(defcustom gnus-treat-from-picon
1485 (if (and (gnus-image-type-available-p 'xpm)
1486 (gnus-picons-installed-p))
1487 'head nil)
1488 "Display picons in the From header.
01c52d31
MB
1489Valid values are nil, t, `head', `first', `last', an integer or a
1490predicate. See Info node `(gnus)Customizing Articles' and Info
1491node `(gnus)Picons' for details."
bf247b6e 1492 :version "22.1"
16409b0b 1493 :group 'gnus-article-treat
23f87bed
MB
1494 :group 'gnus-picon
1495 :link '(custom-manual "(gnus)Customizing Articles")
1496 :link '(custom-manual "(gnus)Picons")
1497 :type gnus-article-treat-head-custom)
1498(put 'gnus-treat-from-picon 'highlight t)
1499
1500(defcustom gnus-treat-mail-picon
1501 (if (and (gnus-image-type-available-p 'xpm)
1502 (gnus-picons-installed-p))
1503 'head nil)
1504 "Display picons in To and Cc headers.
01c52d31
MB
1505Valid values are nil, t, `head', `first', `last', an integer or a
1506predicate. See Info node `(gnus)Customizing Articles' and Info
1507node `(gnus)Picons' for details."
bf247b6e 1508 :version "22.1"
23f87bed
MB
1509 :group 'gnus-article-treat
1510 :group 'gnus-picon
1511 :link '(custom-manual "(gnus)Customizing Articles")
1512 :link '(custom-manual "(gnus)Picons")
1513 :type gnus-article-treat-head-custom)
1514(put 'gnus-treat-mail-picon 'highlight t)
1515
1516(defcustom gnus-treat-newsgroups-picon
1517 (if (and (gnus-image-type-available-p 'xpm)
1518 (gnus-picons-installed-p))
1519 'head nil)
1520 "Display picons in the Newsgroups and Followup-To headers.
01c52d31
MB
1521Valid values are nil, t, `head', `first', `last', an integer or a
1522predicate. See Info node `(gnus)Customizing Articles' and Info
1523node `(gnus)Picons' for details."
bf247b6e 1524 :version "22.1"
23f87bed
MB
1525 :group 'gnus-article-treat
1526 :group 'gnus-picon
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :link '(custom-manual "(gnus)Picons")
1529 :type gnus-article-treat-head-custom)
1530(put 'gnus-treat-newsgroups-picon 'highlight t)
1531
6688abe0 1532(defcustom gnus-treat-from-gravatar nil
61b1af82
G
1533 "Display gravatars in the From header.
1534Valid values are nil, t, `head', `first', `last', an integer or a
1535predicate. See Info node `(gnus)Customizing Articles' and Info
1536node `(gnus)Gravatars' for details."
1537 :version "24.1"
1538 :group 'gnus-article-treat
1539 :group 'gnus-gravatar
1540 :link '(custom-manual "(gnus)Customizing Articles")
1541 :link '(custom-manual "(gnus)Gravatars")
1542 :type gnus-article-treat-head-custom)
1543(put 'gnus-treat-from-gravatar 'highlight t)
1544
6688abe0 1545(defcustom gnus-treat-mail-gravatar nil
61b1af82
G
1546 "Display gravatars in To and Cc headers.
1547Valid values are nil, t, `head', `first', `last', an integer or a
1548predicate. See Info node `(gnus)Customizing Articles' and Info
1549node `(gnus)Gravatars' for details."
1550 :version "24.1"
1551 :group 'gnus-article-treat
1552 :group 'gnus-gravatar
1553 :link '(custom-manual "(gnus)Customizing Articles")
1554 :link '(custom-manual "(gnus)Gravatars")
1555 :type gnus-article-treat-head-custom)
1556(put 'gnus-treat-mail-gravatar 'highlight t)
1557
23f87bed 1558(defcustom gnus-treat-body-boundary
437ce4be
MB
1559 (if (or gnus-treat-newsgroups-picon
1560 gnus-treat-mail-picon
61b1af82
G
1561 gnus-treat-from-picon
1562 gnus-treat-from-gravatar
1563 gnus-treat-mail-gravatar)
437ce4be
MB
1564 ;; If there's much decoration, the user might prefer a boundery.
1565 'head
1566 nil)
23f87bed
MB
1567 "Draw a boundary at the end of the headers.
1568Valid values are nil and `head'.
1569See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1570 :version "22.1"
23f87bed
MB
1571 :group 'gnus-article-treat
1572 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b 1573 :type gnus-article-treat-head-custom)
16409b0b
GM
1574
1575(defcustom gnus-treat-capitalize-sentences nil
1576 "Capitalize sentence-starting words.
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
MB
1581 :link '(custom-manual "(gnus)Customizing Articles")
1582 :type gnus-article-treat-custom)
1583
1584(defcustom gnus-treat-wash-html nil
1585 "Format as HTML.
01c52d31
MB
1586Valid values are nil, t, `head', `first', `last', an integer or a
1587predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1588 :version "22.1"
23f87bed
MB
1589 :group 'gnus-article-treat
1590 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1591 :type gnus-article-treat-custom)
1592
1593(defcustom gnus-treat-fill-long-lines nil
1594 "Fill long lines.
01c52d31
MB
1595Valid values are nil, t, `head', `first', `last', an integer or a
1596predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1597 :group 'gnus-article-treat
23f87bed 1598 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1599 :type gnus-article-treat-custom)
1600
23f87bed
MB
1601(defcustom gnus-treat-x-pgp-sig nil
1602 "Verify X-PGP-Sig.
1603To automatically treat X-PGP-Sig, set it to head.
01c52d31
MB
1604Valid values are nil, t, `head', `first', `last', an integer or a
1605predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1606 :version "22.1"
23f87bed
MB
1607 :group 'gnus-article-treat
1608 :group 'mime-security
1609 :link '(custom-manual "(gnus)Customizing Articles")
1610 :type gnus-article-treat-custom)
1611
1612(defvar gnus-article-encrypt-protocol-alist
1613 '(("PGP" . mml2015-self-encrypt)))
1614
1615;; Set to nil if more than one protocol added to
1616;; gnus-article-encrypt-protocol-alist.
1617(defcustom gnus-article-encrypt-protocol "PGP"
1618 "The protocol used for encrypt articles.
1619It is a string, such as \"PGP\". If nil, ask user."
bf247b6e 1620 :version "22.1"
23f87bed
MB
1621 :type 'string
1622 :group 'mime-security)
1623
1624(defvar gnus-article-wash-function nil
1625 "Function used for converting HTML into text.")
1626
1627(defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1628 (mm-coding-system-p 'utf-8)
1629 (executable-find idna-program))
1630 "Whether IDNA decoding of headers is used when viewing messages.
1631This requires GNU Libidn, and by default only enabled if it is found."
bf247b6e 1632 :version "22.1"
23f87bed
MB
1633 :group 'gnus-article-headers
1634 :type 'boolean)
1635
1636(defcustom gnus-article-over-scroll nil
1637 "If non-nil, allow scrolling the article buffer even when there no more text."
bf247b6e 1638 :version "22.1"
23f87bed
MB
1639 :group 'gnus-article
1640 :type 'boolean)
1641
130e977f
LMI
1642(defcustom gnus-blocked-images "."
1643 "Images that have URLs matching this regexp will be blocked."
1644 :version "24.1"
1645 :group 'gnus-art
1646 :type 'regexp)
1647
eec82323
LMI
1648;;; Internal variables
1649
23f87bed
MB
1650(defvar gnus-english-month-names
1651 '("January" "February" "March" "April" "May" "June" "July" "August"
1652 "September" "October" "November" "December"))
1653
16409b0b
GM
1654(defvar article-goto-body-goes-to-point-min-p nil)
1655(defvar gnus-article-wash-types nil)
1656(defvar gnus-article-emphasis-alist nil)
23f87bed 1657(defvar gnus-article-image-alist nil)
16409b0b
GM
1658
1659(defvar gnus-article-mime-handle-alist-1 nil)
1660(defvar gnus-treatment-function-alist
23f87bed
MB
1661 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1662 (gnus-treat-strip-banner gnus-article-strip-banner)
16409b0b
GM
1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1665 (gnus-treat-buttonize gnus-article-add-buttons)
1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1667 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1668 (gnus-treat-strip-cr gnus-article-remove-cr)
23f87bed
MB
1669 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1670 (gnus-treat-date-ut gnus-article-date-ut)
1671 (gnus-treat-date-local gnus-article-date-local)
1672 (gnus-treat-date-english gnus-article-date-english)
23f87bed
MB
1673 (gnus-treat-date-original gnus-article-date-original)
1674 (gnus-treat-date-user-defined gnus-article-date-user)
1675 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
f3f01d5d 1676 (gnus-treat-date-lapsed gnus-article-date-lapsed)
23f87bed
MB
1677 (gnus-treat-display-x-face gnus-article-display-x-face)
1678 (gnus-treat-display-face gnus-article-display-face)
16409b0b
GM
1679 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1680 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1681 (gnus-treat-hide-signature gnus-article-hide-signature)
16409b0b 1682 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
23f87bed 1683 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
2696d88f
G
1684 (gnus-treat-from-picon gnus-treat-from-picon)
1685 (gnus-treat-mail-picon gnus-treat-mail-picon)
1686 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
16409b0b 1687 (gnus-treat-strip-pem gnus-article-hide-pem)
61b1af82
G
1688 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1689 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
16409b0b 1690 (gnus-treat-highlight-headers gnus-article-highlight-headers)
16409b0b 1691 (gnus-treat-highlight-signature gnus-article-highlight-signature)
16409b0b
GM
1692 (gnus-treat-strip-trailing-blank-lines
1693 gnus-article-remove-trailing-blank-lines)
1694 (gnus-treat-strip-leading-blank-lines
1695 gnus-article-strip-leading-blank-lines)
1696 (gnus-treat-strip-multiple-blank-lines
1697 gnus-article-strip-multiple-blank-lines)
1698 (gnus-treat-overstrike gnus-article-treat-overstrike)
01c52d31 1699 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
23f87bed 1700 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
23f87bed 1701 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
01c52d31 1702 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
16409b0b 1703 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
23f87bed 1704 (gnus-treat-display-smileys gnus-treat-smiley)
16409b0b 1705 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
23f87bed
MB
1706 (gnus-treat-wash-html gnus-article-wash-html)
1707 (gnus-treat-emphasize gnus-article-emphasize)
1708 (gnus-treat-hide-citation gnus-article-hide-citation)
1709 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1710 (gnus-treat-highlight-citation gnus-article-highlight-citation)
8ccbef23 1711 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
16409b0b
GM
1712
1713(defvar gnus-article-mime-handle-alist nil)
6748645f
LMI
1714(defvar article-lapsed-timer nil)
1715(defvar gnus-article-current-summary nil)
1716
eec82323
LMI
1717(defvar gnus-article-mode-syntax-table
1718 (let ((table (copy-syntax-table text-mode-syntax-table)))
23f87bed
MB
1719 ;; This causes the citation match run O(2^n).
1720 ;; (modify-syntax-entry ?- "w" table)
1721 (modify-syntax-entry ?> ")<" table)
1722 (modify-syntax-entry ?< "(>" table)
1723 ;; make M-. in article buffers work for `foo' strings
1724 (modify-syntax-entry ?' " " table)
1725 (modify-syntax-entry ?` " " table)
eec82323
LMI
1726 table)
1727 "Syntax table used in article mode buffers.
1728Initialized from `text-mode-syntax-table.")
1729
1730(defvar gnus-save-article-buffer nil)
1731
eec82323
LMI
1732(defvar gnus-number-of-articles-to-be-saved nil)
1733
1734(defvar gnus-inhibit-hiding nil)
1735
c1d7d285
MB
1736(defvar gnus-article-edit-mode nil)
1737
23f87bed
MB
1738;;; Macros for dealing with the article buffer.
1739
1740(defmacro gnus-with-article-headers (&rest forms)
80de1778 1741 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1742 (save-restriction
1743 (let ((inhibit-read-only t)
1744 (inhibit-point-motion-hooks t)
1745 (case-fold-search t))
1746 (article-narrow-to-head)
1747 ,@forms))))
1748
1749(put 'gnus-with-article-headers 'lisp-indent-function 0)
1750(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1751
1752(defmacro gnus-with-article-buffer (&rest forms)
80de1778 1753 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1754 (let ((inhibit-read-only t))
1755 ,@forms)))
1756
1757(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1759
1760(defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1763
eec82323
LMI
1764(defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1766 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1767 (when (memq 'intangible props)
1768 (put-text-property
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1771
eec82323
LMI
1772(defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1778
1779(defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
23f87bed 1781 (gnus-add-wash-type type)
eec82323
LMI
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1784
1785(defun gnus-article-unhide-text-type (b e type)
6748645f 1786 "Unhide text of TYPE between B and E."
23f87bed 1787 (gnus-delete-wash-type type)
eec82323
LMI
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1793
1794(defun gnus-article-hide-text-of-type (type)
1795 "Hide text of TYPE in the current buffer."
1796 (save-excursion
1797 (let ((b (point-min))
1798 (e (point-max)))
1799 (while (setq b (text-property-any b e 'article-type type))
1800 (add-text-properties b (incf b) gnus-hidden-properties)))))
1801
1802(defun gnus-article-delete-text-of-type (type)
1803 "Delete text of TYPE in the current buffer."
1804 (save-excursion
a8151ef7 1805 (let ((b (point-min)))
7dafe00b
MB
1806 (if (eq type 'multipart)
1807 ;; Remove MIME buttons associated with multipart/alternative parts.
1808 (progn
1809 (goto-char b)
1810 (while (if (get-text-property (point) 'gnus-part)
1811 (setq b (point))
1812 (when (setq b (next-single-property-change (point)
1813 'gnus-part))
1814 (goto-char b)
1815 t))
1816 (end-of-line)
1817 (skip-chars-forward "\n")
1818 (when (eq (get-text-property b 'article-type) 'multipart)
1819 (delete-region b (point)))))
1820 (while (setq b (text-property-any b (point-max) 'article-type type))
1821 (delete-region
1822 b (or (text-property-not-all b (point-max) 'article-type type)
1823 (point-max))))))))
eec82323
LMI
1824
1825(defun gnus-article-delete-invisible-text ()
1826 "Delete all invisible text in the current buffer."
1827 (save-excursion
a8151ef7
LMI
1828 (let ((b (point-min)))
1829 (while (setq b (text-property-any b (point-max) 'invisible t))
1830 (delete-region
1831 b (or (text-property-not-all b (point-max) 'invisible t)
1832 (point-max)))))))
eec82323
LMI
1833
1834(defun gnus-article-text-type-exists-p (type)
1835 "Say whether any text of type TYPE exists in the buffer."
1836 (text-property-any (point-min) (point-max) 'article-type type))
1837
1838(defsubst gnus-article-header-rank ()
1839 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1840 (let ((list gnus-sorted-header-list)
23f87bed 1841 (i 1))
eec82323 1842 (while list
23f87bed
MB
1843 (if (looking-at (car list))
1844 (setq list nil)
1845 (setq list (cdr list))
1846 (incf i)))
1847 i))
eec82323
LMI
1848
1849(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1850 "Hide unwanted headers and possibly sort them as well."
1851 (interactive)
1852 ;; This function might be inhibited.
1853 (unless gnus-inhibit-hiding
37cc095b 1854 (let ((inhibit-read-only t)
23f87bed
MB
1855 (case-fold-search t)
1856 (max (1+ (length gnus-sorted-header-list)))
1857 (inhibit-point-motion-hooks t)
1858 (cur (current-buffer))
1859 ignored visible beg)
1860 (save-excursion
1861 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1862 ;; group parameters, so we should go to the summary buffer.
1863 (when (prog1
1864 (condition-case nil
1865 (progn (set-buffer gnus-summary-buffer) t)
1866 (error nil))
1867 (setq ignored (when (not gnus-visible-headers)
1868 (cond ((stringp gnus-ignored-headers)
1869 gnus-ignored-headers)
1870 ((listp gnus-ignored-headers)
1871 (mapconcat 'identity
1872 gnus-ignored-headers
1873 "\\|"))))
1874 visible (cond ((stringp gnus-visible-headers)
1875 gnus-visible-headers)
1876 ((and gnus-visible-headers
1877 (listp gnus-visible-headers))
1878 (mapconcat 'identity
1879 gnus-visible-headers
1880 "\\|")))))
1881 (set-buffer cur))
1882 (save-restriction
16409b0b
GM
1883 ;; First we narrow to just the headers.
1884 (article-narrow-to-head)
1885 ;; Hide any "From " lines at the beginning of (mail) articles.
1886 (while (looking-at "From ")
1887 (forward-line 1))
1888 (unless (bobp)
1889 (delete-region (point-min) (point)))
1890 ;; Then treat the rest of the header lines.
1891 ;; Then we use the two regular expressions
1892 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1893 ;; select which header lines is to remain visible in the
1894 ;; article buffer.
23f87bed 1895 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
1896 (beginning-of-line)
1897 ;; Mark the rank of the header.
1898 (put-text-property
1899 (point) (1+ (point)) 'message-rank
1900 (if (or (and visible (looking-at visible))
1901 (and ignored
1902 (not (looking-at ignored))))
1903 (gnus-article-header-rank)
1904 (+ 2 max)))
1905 (forward-line 1))
1906 (message-sort-headers-1)
1907 (when (setq beg (text-property-any
1908 (point-min) (point-max) 'message-rank (+ 2 max)))
1909 ;; We delete the unwanted headers.
23f87bed 1910 (gnus-add-wash-type 'headers)
16409b0b
GM
1911 (add-text-properties (point-min) (+ 5 (point-min))
1912 '(article-type headers dummy-invisible t))
1913 (delete-region beg (point-max))))))))
eec82323
LMI
1914
1915(defun article-hide-boring-headers (&optional arg)
1916 "Toggle hiding of headers that aren't very interesting.
1917If given a negative prefix, always show; if given a positive prefix,
1918always hide."
1919 (interactive (gnus-article-hidden-arg))
1920 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1921 (not gnus-show-all-headers))
1922 (save-excursion
1923 (save-restriction
4e7d0221 1924 (let ((inhibit-read-only t)
01c52d31 1925 (inhibit-point-motion-hooks t))
16409b0b 1926 (article-narrow-to-head)
01c52d31 1927 (dolist (elem gnus-boring-article-headers)
eec82323
LMI
1928 (goto-char (point-min))
1929 (cond
1930 ;; Hide empty headers.
1931 ((eq elem 'empty)
16409b0b 1932 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1933 (forward-line -1)
1934 (gnus-article-hide-text-type
01c52d31 1935 (point-at-bol)
eec82323
LMI
1936 (progn
1937 (end-of-line)
1938 (if (re-search-forward "^[^ \t]" nil t)
1939 (match-beginning 0)
1940 (point-max)))
1941 'boring-headers)))
1942 ;; Hide boring Newsgroups header.
1943 ((eq elem 'newsgroups)
23f87bed
MB
1944 (when (gnus-string-equal
1945 (gnus-fetch-field "newsgroups")
1946 (gnus-group-real-name
1947 (if (boundp 'gnus-newsgroup-name)
1948 gnus-newsgroup-name
1949 "")))
eec82323 1950 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
1951 ((eq elem 'to-address)
1952 (let ((to (message-fetch-field "to"))
1953 (to-address
1954 (gnus-parameter-to-address
1955 (if (boundp 'gnus-newsgroup-name)
1956 gnus-newsgroup-name ""))))
1957 (when (and to to-address
1958 (ignore-errors
1959 (gnus-string-equal
1960 ;; only one address in To
1961 (nth 1 (mail-extract-address-components to))
1962 to-address)))
1963 (gnus-article-hide-header "to"))))
1964 ((eq elem 'to-list)
1965 (let ((to (message-fetch-field "to"))
1966 (to-list
1967 (gnus-parameter-to-list
1968 (if (boundp 'gnus-newsgroup-name)
1969 gnus-newsgroup-name ""))))
1970 (when (and to to-list
1971 (ignore-errors
1972 (gnus-string-equal
1973 ;; only one address in To
1974 (nth 1 (mail-extract-address-components to))
1975 to-list)))
1976 (gnus-article-hide-header "to"))))
1977 ((eq elem 'cc-list)
1978 (let ((cc (message-fetch-field "cc"))
1979 (to-list
1980 (gnus-parameter-to-list
1981 (if (boundp 'gnus-newsgroup-name)
1982 gnus-newsgroup-name ""))))
1983 (when (and cc to-list
1984 (ignore-errors
1985 (gnus-string-equal
1986 ;; only one address in CC
1987 (nth 1 (mail-extract-address-components cc))
1988 to-list)))
1989 (gnus-article-hide-header "cc"))))
eec82323 1990 ((eq elem 'followup-to)
23f87bed
MB
1991 (when (gnus-string-equal
1992 (message-fetch-field "followup-to")
1993 (message-fetch-field "newsgroups"))
eec82323
LMI
1994 (gnus-article-hide-header "followup-to")))
1995 ((eq elem 'reply-to)
23f87bed
MB
1996 (if (gnus-group-find-parameter
1997 gnus-newsgroup-name 'broken-reply-to)
1998 (gnus-article-hide-header "reply-to")
1999 (let ((from (message-fetch-field "from"))
2000 (reply-to (message-fetch-field "reply-to")))
2001 (when
2002 (and
eec82323
LMI
2003 from reply-to
2004 (ignore-errors
2005 (equal
23f87bed
MB
2006 (sort (mapcar
2007 (lambda (x) (downcase (cadr x)))
2008 (mail-extract-address-components from t))
2009 'string<)
2010 (sort (mapcar
2011 (lambda (x) (downcase (cadr x)))
2012 (mail-extract-address-components reply-to t))
2013 'string<))))
2014 (gnus-article-hide-header "reply-to")))))
eec82323 2015 ((eq elem 'date)
b193caa3
MB
2016 (let ((date (with-current-buffer gnus-original-article-buffer
2017 ;; If date in `gnus-article-buffer' is localized
2018 ;; (`gnus-treat-date-user-defined'),
2019 ;; `days-between' might fail.
2020 (message-fetch-field "date"))))
eec82323 2021 (when (and date
16409b0b 2022 (< (days-between (current-time-string) date)
eec82323 2023 4))
6748645f
LMI
2024 (gnus-article-hide-header "date"))))
2025 ((eq elem 'long-to)
16409b0b
GM
2026 (let ((to (message-fetch-field "to"))
2027 (cc (message-fetch-field "cc")))
6748645f 2028 (when (> (length to) 1024)
16409b0b
GM
2029 (gnus-article-hide-header "to"))
2030 (when (> (length cc) 1024)
2031 (gnus-article-hide-header "cc"))))
6748645f 2032 ((eq elem 'many-to)
16409b0b
GM
2033 (let ((to-count 0)
2034 (cc-count 0))
6748645f
LMI
2035 (goto-char (point-min))
2036 (while (re-search-forward "^to:" nil t)
2037 (setq to-count (1+ to-count)))
2038 (when (> to-count 1)
2039 (while (> to-count 0)
2040 (goto-char (point-min))
2041 (save-restriction
2042 (re-search-forward "^to:" nil nil to-count)
2043 (forward-line -1)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "to"))
16409b0b
GM
2046 (setq to-count (1- to-count))))
2047 (goto-char (point-min))
2048 (while (re-search-forward "^cc:" nil t)
2049 (setq cc-count (1+ cc-count)))
2050 (when (> cc-count 1)
2051 (while (> cc-count 0)
2052 (goto-char (point-min))
2053 (save-restriction
2054 (re-search-forward "^cc:" nil nil cc-count)
2055 (forward-line -1)
2056 (narrow-to-region (point) (point-max))
2057 (gnus-article-hide-header "cc"))
2058 (setq cc-count (1- cc-count)))))))))))))
eec82323
LMI
2059
2060(defun gnus-article-hide-header (header)
2061 (save-excursion
2062 (goto-char (point-min))
2063 (when (re-search-forward (concat "^" header ":") nil t)
2064 (gnus-article-hide-text-type
01c52d31 2065 (point-at-bol)
eec82323
LMI
2066 (progn
2067 (end-of-line)
2068 (if (re-search-forward "^[^ \t]" nil t)
2069 (match-beginning 0)
2070 (point-max)))
2071 'boring-headers))))
2072
16409b0b
GM
2073(defvar gnus-article-normalized-header-length 40
2074 "Length of normalized headers.")
2075
2076(defun article-normalize-headers ()
2077 "Make all header lines 40 characters long."
2078 (interactive)
4e7d0221 2079 (let ((inhibit-read-only t)
16409b0b
GM
2080 column)
2081 (save-excursion
2082 (save-restriction
2083 (article-narrow-to-head)
2084 (while (not (eobp))
2085 (cond
01c52d31 2086 ((< (setq column (- (point-at-eol) (point)))
16409b0b
GM
2087 gnus-article-normalized-header-length)
2088 (end-of-line)
2089 (insert (make-string
2090 (- gnus-article-normalized-header-length column)
2091 ? )))
2092 ((> column gnus-article-normalized-header-length)
2093 (gnus-put-text-property
2094 (progn
2095 (forward-char gnus-article-normalized-header-length)
2096 (point))
01c52d31 2097 (point-at-eol)
16409b0b
GM
2098 'invisible t))
2099 (t
2100 ;; Do nothing.
2101 ))
2102 (forward-line 1))))))
2103
6748645f 2104(defun article-treat-dumbquotes ()
23f87bed 2105 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 2106Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
2107not, so it should only be used interactively.
2108
23f87bed
MB
2109Sm*rtq**t*s are M****s***'s unilateral extension to the
2110iso-8859-1 character map in an attempt to provide more quoting
2111characters. If you see something like \\222 or \\264 where
2112you're expecting some kind of apostrophe or quotation mark, then
2113try this wash."
6748645f 2114 (interactive)
16409b0b 2115 (article-translate-strings gnus-article-dumbquotes-map))
6748645f
LMI
2116
2117(defun article-translate-characters (from to)
2118 "Translate all characters in the body of the article according to FROM and TO.
2119FROM is a string of characters to translate from; to is a string of
2120characters to translate to."
2121 (save-excursion
16409b0b 2122 (when (article-goto-body)
4e7d0221 2123 (let ((inhibit-read-only t)
6748645f
LMI
2124 (x (make-string 225 ?x))
2125 (i -1))
2126 (while (< (incf i) (length x))
2127 (aset x i i))
2128 (setq i 0)
2129 (while (< i (length from))
2130 (aset x (aref from i) (aref to i))
2131 (incf i))
2132 (translate-region (point) (point-max) x)))))
2133
16409b0b
GM
2134(defun article-translate-strings (map)
2135 "Translate all string in the body of the article according to MAP.
2136MAP is an alist where the elements are on the form (\"from\" \"to\")."
2137 (save-excursion
2138 (when (article-goto-body)
01c52d31
MB
2139 (let ((inhibit-read-only t))
2140 (dolist (elem map)
16409b0b
GM
2141 (save-excursion
2142 (while (search-forward (car elem) nil t)
2143 (replace-match (cadr elem)))))))))
2144
eec82323
LMI
2145(defun article-treat-overstrike ()
2146 "Translate overstrikes into bold text."
2147 (interactive)
2148 (save-excursion
16409b0b 2149 (when (article-goto-body)
4e7d0221 2150 (let ((inhibit-read-only t))
eec82323 2151 (while (search-forward "\b" nil t)
16409b0b 2152 (let ((next (char-after))
eec82323
LMI
2153 (previous (char-after (- (point) 2))))
2154 ;; We do the boldification/underlining by hiding the
2155 ;; overstrikes and putting the proper text property
2156 ;; on the letters.
2157 (cond
2158 ((eq next previous)
2159 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2160 (put-text-property (point) (1+ (point)) 'face 'bold))
2161 ((eq next ?_)
2162 (gnus-article-hide-text-type
2163 (1- (point)) (1+ (point)) 'overstrike)
2164 (put-text-property
2165 (- (point) 2) (1- (point)) 'face 'underline))
2166 ((eq previous ?_)
2167 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2168 (put-text-property
2169 (point) (1+ (point)) 'face 'underline)))))))))
2170
01c52d31
MB
2171(defun article-treat-ansi-sequences ()
2172 "Translate ANSI SGR control sequences into overlays or extents."
2173 (interactive)
2174 (save-excursion
2175 (when (article-goto-body)
2176 (let ((inhibit-read-only t))
2177 (ansi-color-apply-on-region (point) (point-max))))))
2178
23f87bed
MB
2179(defun gnus-article-treat-unfold-headers ()
2180 "Unfold folded message headers.
2181Only the headers that fit into the current window width will be
2182unfolded."
2183 (interactive)
2184 (gnus-with-article-headers
2185 (let (length)
2186 (while (not (eobp))
2187 (save-restriction
2188 (mail-header-narrow-to-field)
01c52d31
MB
2189 (let* ((header (buffer-string))
2190 (unfoldable
2191 (or (equal gnus-article-unfold-long-headers t)
2192 (and (stringp gnus-article-unfold-long-headers)
2193 (string-match gnus-article-unfold-long-headers header)))))
23f87bed
MB
2194 (with-temp-buffer
2195 (insert header)
2196 (goto-char (point-min))
2197 (while (re-search-forward "\n[\t ]" nil t)
2198 (replace-match " " t t)))
01c52d31
MB
2199 (setq length (- (point-max) (point-min) 1))
2200 (when (or unfoldable
2201 (< length (window-width)))
2202 (while (re-search-forward "\n[\t ]" nil t)
2203 (replace-match " " t t))))
23f87bed
MB
2204 (goto-char (point-max)))))))
2205
2206(defun gnus-article-treat-fold-headers ()
2207 "Fold message headers."
2208 (interactive)
2209 (gnus-with-article-headers
2210 (while (not (eobp))
2211 (save-restriction
2212 (mail-header-narrow-to-field)
2213 (mail-header-fold-field)
2214 (goto-char (point-max))))))
2215
2216(defun gnus-treat-smiley ()
2217 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2218 (interactive)
2219 (gnus-with-article-buffer
2220 (if (memq 'smiley gnus-article-wash-types)
2221 (gnus-delete-images 'smiley)
2222 (article-goto-body)
2223 (let ((images (smiley-region (point) (point-max))))
2224 (when images
2225 (gnus-add-wash-type 'smiley)
2226 (dolist (image images)
2227 (gnus-add-image 'smiley image)))))))
2228
2229(defun gnus-article-remove-images ()
2230 "Remove all images from the article buffer."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (dolist (elem gnus-article-image-alist)
2234 (gnus-delete-images (car elem)))))
2235
2236(defun gnus-article-treat-fold-newsgroups ()
2237 "Unfold folded message headers.
2238Only the headers that fit into the current window width will be
2239unfolded."
2240 (interactive)
2241 (gnus-with-article-headers
2242 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2243 (save-restriction
2244 (mail-header-narrow-to-field)
2245 (while (re-search-forward ", *" nil t)
2246 (replace-match ", " t t))
2247 (mail-header-fold-field)
2248 (goto-char (point-max))))))
2249
b7b80032 2250(defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
01c52d31
MB
2251 "Value of `truncate-lines' in Gnus Article buffer.
2252Valid values are nil, t, `head', `first', `last', an integer or a
2253predicate. See Info node `(gnus)Customizing Articles'."
330f707b 2254 :version "23.1" ;; No Gnus
01c52d31
MB
2255 :group 'gnus-article
2256 ;; :link '(custom-manual "(gnus)Customizing Articles")
2257 :type 'boolean)
2258
2259(defun gnus-article-toggle-truncate-lines (&optional arg)
2260 "Toggle whether to fold or truncate long lines in article the buffer.
2261If ARG is non-nil and not a number, toggle
2262`gnus-article-truncate-lines' too. If ARG is a number, truncate
5229211e 2263long lines if and only if arg is positive."
01c52d31
MB
2264 (interactive "P")
2265 (cond
2266 ((and (numberp arg) (> arg 0))
2267 (setq gnus-article-truncate-lines t))
2268 ((numberp arg)
2269 (setq gnus-article-truncate-lines nil))
2270 (arg
2271 (setq gnus-article-truncate-lines
2272 (not gnus-article-truncate-lines))))
2273 (gnus-with-article-buffer
2274 (cond
2275 ((and (numberp arg) (> arg 0))
2276 (setq truncate-lines nil))
2277 ((numberp arg)
2278 (setq truncate-lines t)))
2279 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2280 ;; `toggle-truncate-lines' needs an argument.
2281 (toggle-truncate-lines)))
2282
23f87bed
MB
2283(defun gnus-article-treat-body-boundary ()
2284 "Place a boundary line at the end of the headers."
2285 (interactive)
2286 (when (and gnus-body-boundary-delimiter
2287 (> (length gnus-body-boundary-delimiter) 0))
2288 (gnus-with-article-headers
2289 (goto-char (point-max))
2290 (let ((start (point)))
2291 (insert "X-Boundary: ")
2292 (gnus-add-text-properties start (point) '(invisible t intangible t))
2293 (insert (let (str)
4478e074 2294 (while (>= (window-width) (length str))
23f87bed 2295 (setq str (concat str gnus-body-boundary-delimiter)))
4478e074 2296 (substring str 0 (window-width)))
23f87bed
MB
2297 "\n")
2298 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2299
16409b0b
GM
2300(defun article-fill-long-lines ()
2301 "Fill lines that are wider than the window width."
eec82323
LMI
2302 (interactive)
2303 (save-excursion
4e7d0221 2304 (let ((inhibit-read-only t)
16409b0b
GM
2305 (width (window-width (get-buffer-window (current-buffer)))))
2306 (save-restriction
2307 (article-goto-body)
80b47379 2308 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2309 (while (not (eobp))
2310 (end-of-line)
2311 (when (>= (current-column) (min fill-column width))
23f87bed 2312 (narrow-to-region (min (1+ (point)) (point-max))
01c52d31 2313 (point-at-bol))
23f87bed
MB
2314 (let ((goback (point-marker)))
2315 (fill-paragraph nil)
2316 (goto-char (marker-position goback)))
16409b0b
GM
2317 (widen))
2318 (forward-line 1)))))))
2319
2320(defun article-capitalize-sentences ()
2321 "Capitalize the first word in each sentence."
2322 (interactive)
2323 (save-excursion
4e7d0221 2324 (let ((inhibit-read-only t)
16409b0b
GM
2325 (paragraph-start "^[\n\^L]"))
2326 (article-goto-body)
2327 (while (not (eobp))
2328 (capitalize-word 1)
2329 (forward-sentence)))))
eec82323
LMI
2330
2331(defun article-remove-cr ()
16409b0b 2332 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2333 (interactive)
2334 (save-excursion
4e7d0221 2335 (let ((inhibit-read-only t))
eec82323 2336 (goto-char (point-min))
16409b0b
GM
2337 (while (re-search-forward "\r+$" nil t)
2338 (replace-match "" t t))
2339 (goto-char (point-min))
eec82323 2340 (while (search-forward "\r" nil t)
16409b0b 2341 (replace-match "\n" t t)))))
eec82323
LMI
2342
2343(defun article-remove-trailing-blank-lines ()
2344 "Remove all trailing blank lines from the article."
2345 (interactive)
2346 (save-excursion
4e7d0221 2347 (let ((inhibit-read-only t))
eec82323
LMI
2348 (goto-char (point-max))
2349 (delete-region
2350 (point)
2351 (progn
2352 (while (and (not (bobp))
16409b0b
GM
2353 (looking-at "^[ \t]*$")
2354 (not (gnus-annotation-in-region-p
01c52d31 2355 (point) (point-at-eol))))
eec82323
LMI
2356 (forward-line -1))
2357 (forward-line 1)
2358 (point))))))
2359
9efa445f 2360(defvar gnus-face-properties-alist)
01c52d31 2361
b890d447 2362(defun article-display-face (&optional force)
23f87bed 2363 "Display any Face headers in the header."
b890d447 2364 (interactive (list 'force))
23f87bed
MB
2365 (let ((wash-face-p buffer-read-only))
2366 (gnus-with-article-headers
2367 ;; When displaying parts, this function can be called several times on
2368 ;; the same article, without any intended toggle semantic (as typing `W
2369 ;; D d' would have). So face deletion must occur only when we come from
2370 ;; an interactive command, that is when the *Article* buffer is
2371 ;; read-only.
2372 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2373 (gnus-delete-images 'face)
b890d447
MB
2374 (let ((from (message-fetch-field "from"))
2375 face faces)
7d0c69be 2376 (save-current-buffer
23f87bed 2377 (when (and wash-face-p
7d0c69be
MB
2378 (gnus-buffer-live-p gnus-original-article-buffer)
2379 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2380 (set-buffer gnus-original-article-buffer))
2381 (save-restriction
2382 (mail-narrow-to-head)
b890d447
MB
2383 (when (or force
2384 ;; Check whether this face is censored.
2385 (not (and gnus-article-x-face-too-ugly
2386 (or from
2387 (setq from (message-fetch-field "from")))
2388 (string-match gnus-article-x-face-too-ugly
2389 from))))
2390 (while (gnus-article-goto-header "Face")
2391 (push (mail-header-field-value) faces)))))
d6697c02 2392 (when faces
7d0c69be 2393 (goto-char (point-min))
b890d447
MB
2394 (let (png image)
2395 (unless (setq from (gnus-article-goto-header "from"))
7d0c69be
MB
2396 (insert "From:")
2397 (setq from (point))
b890d447 2398 (insert " [no `from' set]\n"))
7d0c69be
MB
2399 (while faces
2400 (when (setq png (gnus-convert-face-to-png (pop faces)))
01c52d31
MB
2401 (setq image
2402 (apply 'gnus-create-image png 'png t
2403 (cdr (assq 'png gnus-face-properties-alist))))
d6697c02
MB
2404 (goto-char from)
2405 (gnus-add-wash-type 'face)
2406 (gnus-add-image 'face image)
2407 (gnus-put-image image nil 'face))))))))))
23f87bed 2408
eec82323
LMI
2409(defun article-display-x-face (&optional force)
2410 "Look for an X-Face header and display it if present."
2411 (interactive (list 'force))
23f87bed
MB
2412 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2413 (gnus-with-article-headers
2414 ;; Delete the old process, if any.
2415 (when (process-status "article-x-face")
2416 (delete-process "article-x-face"))
2417 ;; See the comment in `article-display-face'.
2418 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2419 ;; We have already displayed X-Faces, so we remove them
2420 ;; instead.
2421 (gnus-delete-images 'xface)
2422 ;; Display X-Faces.
b890d447
MB
2423 (let ((from (message-fetch-field "from"))
2424 x-faces face)
7d0c69be 2425 (save-current-buffer
23f87bed 2426 (when (and wash-face-p
7d0c69be
MB
2427 (gnus-buffer-live-p gnus-original-article-buffer)
2428 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2429 ;; If type `W f', use gnus-original-article-buffer,
2430 ;; otherwise use the current buffer because displaying
2431 ;; RFC822 parts calls this function too.
2432 (set-buffer gnus-original-article-buffer))
2433 (save-restriction
2434 (mail-narrow-to-head)
b890d447
MB
2435 (and gnus-article-x-face-command
2436 (or force
2437 ;; Check whether this face is censored.
2438 (not (and gnus-article-x-face-too-ugly
2439 (or from
2440 (setq from (message-fetch-field "from")))
2441 (string-match gnus-article-x-face-too-ugly
2442 from))))
2443 (while (gnus-article-goto-header "X-Face")
2444 (push (mail-header-field-value) x-faces)))))
2445 (when x-faces
2446 ;; We display the face.
2447 (cond ((functionp gnus-article-x-face-command)
2448 ;; The command is a lisp function, so we call it.
2449 (mapc gnus-article-x-face-command x-faces))
2450 ((stringp gnus-article-x-face-command)
2451 ;; The command is a string, so we interpret the command
2452 ;; as a, well, command, and fork it off.
2453 (let ((process-connection-type nil))
2454 (gnus-set-process-query-on-exit-flag
2455 (start-process
2456 "article-x-face" nil shell-file-name
2457 shell-command-switch gnus-article-x-face-command)
2458 nil)
2459 ;; Sending multiple EOFs to xv doesn't work,
2460 ;; so we only do a single external face.
2461 (with-temp-buffer
2462 (insert (car x-faces))
2463 (process-send-region "article-x-face"
2464 (point-min) (point-max)))
2465 (process-send-eof "article-x-face")))
2466 (t
2467 (error "`%s' set to `%s' is not a function"
2468 gnus-article-x-face-command
2469 'gnus-article-x-face-command)))))))))
a8151ef7 2470
16409b0b
GM
2471(defun article-decode-mime-words ()
2472 "Decode all MIME-encoded words in the article."
2473 (interactive)
01c52d31 2474 (gnus-with-article-buffer
16409b0b 2475 (let ((inhibit-point-motion-hooks t)
16409b0b 2476 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2477 (mail-parse-ignored-charsets
01c52d31
MB
2478 (with-current-buffer gnus-summary-buffer
2479 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
2480 (mail-decode-encoded-word-region (point-min) (point-max)))))
2481
2482(defun article-decode-charset (&optional prompt)
2483 "Decode charset-encoded text in the article.
2484If PROMPT (the prefix), prompt for a coding system to use."
2485 (interactive "P")
2486 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2487 (inhibit-read-only t)
16409b0b 2488 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2489 (mail-parse-ignored-charsets
16409b0b
GM
2490 (save-excursion (condition-case nil
2491 (set-buffer gnus-summary-buffer)
2492 (error))
2493 gnus-newsgroup-ignored-charsets))
2494 ct cte ctl charset format)
c96ec15a
MB
2495 (save-excursion
2496 (save-restriction
2497 (article-narrow-to-head)
2498 (setq ct (message-fetch-field "Content-Type" t)
2499 cte (message-fetch-field "Content-Transfer-Encoding" t)
2500 ctl (and ct (mail-header-parse-content-type ct))
2501 charset (cond
2502 (prompt
2503 (mm-read-coding-system "Charset to decode: "))
2504 (ctl
2505 (mail-content-type-get ctl 'charset)))
2506 format (and ctl (mail-content-type-get ctl 'format)))
2507 (when cte
2508 (setq cte (mail-header-strip cte)))
2509 (if (and ctl (not (string-match "/" (car ctl))))
2510 (setq ctl nil))
2511 (goto-char (point-max)))
2512 (forward-line 1)
2513 (save-restriction
2514 (narrow-to-region (point) (point-max))
2515 (when (and (eq mail-parse-charset 'gnus-decoded)
2516 (eq (mm-body-7-or-8) '8bit))
2517 ;; The text code could have been decoded.
2518 (setq charset mail-parse-charset))
2519 (when (and (or (not ctl)
2520 (equal (car ctl) "text/plain"))
2521 (not format)) ;; article with format will decode later.
2522 (mm-decode-body
2523 charset (and cte (intern (downcase
2524 (gnus-strip-whitespace cte))))
2525 (car ctl)))))))
16409b0b
GM
2526
2527(defun article-decode-encoded-words ()
2528 "Remove encoded-word encoding from headers."
2529 (let ((inhibit-point-motion-hooks t)
2530 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2531 (mail-parse-ignored-charsets
16409b0b
GM
2532 (save-excursion (condition-case nil
2533 (set-buffer gnus-summary-buffer)
2534 (error))
2535 gnus-newsgroup-ignored-charsets))
343d6628 2536 (inhibit-read-only t)
8fbdffe5
MB
2537 end start)
2538 (goto-char (point-min))
2539 (when (search-forward "\n\n" nil 'move)
2540 (forward-line -1))
2541 (setq end (point))
2542 (while (not (bobp))
2543 (while (progn
2544 (forward-line -1)
2545 (and (not (bobp))
2546 (memq (char-after) '(?\t ? )))))
2547 (setq start (point))
2548 (if (looking-at "\
343d6628
MB
2549\\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2550\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
8fbdffe5
MB
2551 (funcall gnus-decode-address-function start end)
2552 (funcall gnus-decode-header-function start end))
2553 (goto-char (setq end start)))))
eec82323 2554
23f87bed 2555(defun article-decode-group-name ()
01c52d31 2556 "Decode group names in Newsgroups, Followup-To and Xref headers."
23f87bed
MB
2557 (let ((inhibit-point-motion-hooks t)
2558 (inhibit-read-only t)
01c52d31
MB
2559 (method (gnus-find-method-for-group gnus-newsgroup-name))
2560 regexp)
23f87bed
MB
2561 (when (and (or gnus-group-name-charset-method-alist
2562 gnus-group-name-charset-group-alist)
2563 (gnus-buffer-live-p gnus-original-article-buffer))
2564 (save-restriction
2565 (article-narrow-to-head)
01c52d31
MB
2566 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2567 (with-current-buffer gnus-original-article-buffer
2568 (goto-char (point-min)))
2569 (setq regexp (concat "^" header
2570 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2571 (while (re-search-forward regexp nil t)
2572 (replace-match (save-match-data
2573 (gnus-decode-newsgroups
2574 ;; XXX how to use data in article buffer?
2575 (with-current-buffer gnus-original-article-buffer
2576 (re-search-forward regexp nil t)
2577 (match-string 1))
2578 gnus-newsgroup-name method))
2579 t t nil 1))
2580 (goto-char (point-min)))))))
23f87bed
MB
2581
2582(autoload 'idna-to-unicode "idna")
2583
2584(defun article-decode-idna-rhs ()
53cfefc8
MB
2585 "Decode IDNA strings in RHS in various headers in current buffer.
2586The following headers are decoded: From:, To:, Cc:, Reply-To:,
2587Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2588 (when gnus-use-idna
2589 (save-restriction
2590 (let ((inhibit-point-motion-hooks t)
2591 (inhibit-read-only t))
2592 (article-narrow-to-head)
2593 (goto-char (point-min))
53cfefc8 2594 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2595 (let (ace unicode)
2596 (when (save-match-data
2597 (and (setq ace (match-string 1))
2598 (save-excursion
2599 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2600 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2601 (setq unicode (idna-to-unicode ace))))
2602 (unless (string= ace unicode)
2603 (replace-match unicode nil nil nil 1)))))))))
2604
2605(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2606 "Translate a quoted-printable-encoded article.
eec82323 2607If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2608or not.
2609If READ-CHARSET, ask for a coding system."
2610 (interactive (list 'force current-prefix-arg))
eec82323 2611 (save-excursion
4e7d0221 2612 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2613 (if (gnus-buffer-live-p gnus-original-article-buffer)
2614 (with-current-buffer gnus-original-article-buffer
2615 (setq type
2616 (gnus-fetch-field "content-transfer-encoding"))
2617 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2618 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2619 (setq charset (and ctl
2620 (mail-content-type-get ctl 'charset)))
2621 (if (stringp charset)
2622 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2623 (if read-charset
2624 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2625 (unless charset
8b93df01 2626 (setq charset gnus-newsgroup-charset))
eec82323 2627 (when (or force
eb806ef3
DL
2628 (and type (let ((case-fold-search t))
2629 (string-match "quoted-printable" type))))
16409b0b 2630 (article-goto-body)
eb806ef3
DL
2631 (quoted-printable-decode-region
2632 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2633
23f87bed 2634(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2635 "Translate a base64 article.
23f87bed
MB
2636If FORCE, decode the article whether it is marked as base64 not.
2637If READ-CHARSET, ask for a coding system."
2638 (interactive (list 'force current-prefix-arg))
16409b0b 2639 (save-excursion
4e7d0221 2640 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2641 (if (gnus-buffer-live-p gnus-original-article-buffer)
2642 (with-current-buffer gnus-original-article-buffer
2643 (setq type
2644 (gnus-fetch-field "content-transfer-encoding"))
2645 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2646 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2647 (setq charset (and ctl
2648 (mail-content-type-get ctl 'charset)))
2649 (if (stringp charset)
2650 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2651 (if read-charset
2652 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2653 (unless charset
8b93df01 2654 (setq charset gnus-newsgroup-charset))
16409b0b 2655 (when (or force
eb806ef3
DL
2656 (and type (let ((case-fold-search t))
2657 (string-match "base64" type))))
16409b0b
GM
2658 (article-goto-body)
2659 (save-restriction
2660 (narrow-to-region (point) (point-max))
2661 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2662 (mm-decode-coding-region
2663 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2664
2665(eval-when-compile
2666 (require 'rfc1843))
2667
2668(defun article-decode-HZ ()
2669 "Translate a HZ-encoded article."
2670 (interactive)
2671 (require 'rfc1843)
2672 (save-excursion
4e7d0221 2673 (let ((inhibit-read-only t))
16409b0b
GM
2674 (rfc1843-decode-region (point-min) (point-max)))))
2675
23f87bed
MB
2676(defun article-unsplit-urls ()
2677 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2678 (interactive)
23f87bed
MB
2679 (save-excursion
2680 (let ((inhibit-read-only t))
2681 (goto-char (point-min))
2682 (while (re-search-forward
97f78c9b 2683 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2684 (replace-match "\\1\\3" t)))
2685 (when (interactive-p)
2686 (gnus-treat-article nil))))
2687
2688
2689(defun article-wash-html (&optional read-charset)
2690 "Format an HTML article.
73043f7d
MB
2691If READ-CHARSET, ask for a coding system. If it is a number, the
2692charset defined in `gnus-summary-show-article-charset-alist' is used."
23f87bed 2693 (interactive "P")
16409b0b 2694 (save-excursion
4e7d0221 2695 (let ((inhibit-read-only t)
8b93df01 2696 charset)
73043f7d
MB
2697 (if read-charset
2698 (if (or (and (numberp read-charset)
2699 (setq charset
2700 (cdr
2701 (assq read-charset
2702 gnus-summary-show-article-charset-alist))))
2703 (setq charset (mm-read-coding-system "Charset: ")))
2704 (let ((gnus-summary-show-article-charset-alist
2705 (list (cons 1 charset))))
2706 (with-current-buffer gnus-summary-buffer
2707 (gnus-summary-show-article 1)))
2708 (error "No charset is given"))
2709 (when (gnus-buffer-live-p gnus-original-article-buffer)
2710 (with-current-buffer gnus-original-article-buffer
2711 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2712 (ctl (and ct (mail-header-parse-content-type ct))))
73043f7d
MB
2713 (setq charset (and ctl
2714 (mail-content-type-get ctl 'charset)))
2715 (when (stringp charset)
2716 (setq charset (intern (downcase charset)))))))
2717 (unless charset
2718 (setq charset gnus-newsgroup-charset)))
16409b0b
GM
2719 (article-goto-body)
2720 (save-window-excursion
2721 (save-restriction
2722 (narrow-to-region (point) (point-max))
23f87bed
MB
2723 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2724 (entry (assq func mm-text-html-washer-alist)))
2725 (when entry
2726 (setq func (cdr entry)))
2727 (cond
2728 ((functionp func)
2729 (funcall func))
2730 (t
2731 (apply (car func) (cdr func))))))))))
2732
9640c3bc
GM
2733;; External.
2734(declare-function w3-region "ext:w3-display" (st nd))
2735
23f87bed
MB
2736(defun gnus-article-wash-html-with-w3 ()
2737 "Wash the current buffer with w3."
2738 (mm-setup-w3)
2739 (let ((w3-strict-width (window-width))
2740 (url-standalone-mode t)
2741 (url-gateway-unplugged t)
2742 (w3-honor-stylesheets nil))
2743 (condition-case ()
2744 (w3-region (point-min) (point-max))
2745 (error))))
2746
9640c3bc
GM
2747;; External.
2748(declare-function w3m-region "ext:w3m" (start end &optional url charset))
2749
23f87bed
MB
2750(defun gnus-article-wash-html-with-w3m ()
2751 "Wash the current buffer with emacs-w3m."
2752 (mm-setup-w3m)
7dafe00b
MB
2753 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2754 w3m-force-redisplay)
2755 (w3m-region (point-min) (point-max)))
1250af7b
KY
2756 ;; Put the mark meaning this part was rendered by emacs-w3m.
2757 (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
7dafe00b
MB
2758 (when (and mm-inline-text-html-with-w3m-keymap
2759 (boundp 'w3m-minor-mode-map)
2760 w3m-minor-mode-map)
886367d8
KY
2761 (if (and (boundp 'w3m-link-map)
2762 w3m-link-map)
1250af7b
KY
2763 (let* ((start (point-min))
2764 (end (point-max))
2765 (on (get-text-property start 'w3m-href-anchor))
2766 (map (copy-keymap w3m-link-map))
2767 next)
886367d8 2768 (set-keymap-parent map w3m-minor-mode-map)
1250af7b
KY
2769 (while (< start end)
2770 (if on
2771 (progn
2772 (setq next (or (text-property-any start end
2773 'w3m-href-anchor nil)
2774 end))
2775 (put-text-property start next 'keymap map))
2776 (setq next (or (text-property-not-all start end
2777 'w3m-href-anchor nil)
2778 end))
2779 (put-text-property start next 'keymap w3m-minor-mode-map))
2780 (setq start next
2781 on (not on))))
2782 (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
16409b0b 2783
9efa445f 2784(defvar charset) ;; Bound by `article-wash-html'.
73043f7d
MB
2785
2786(defun gnus-article-wash-html-with-w3m-standalone ()
2787 "Wash the current buffer with w3m."
7347faa8
MB
2788 (if (mm-w3m-standalone-supports-m17n-p)
2789 (progn
2790 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2791 ;; The default.
2792 (setq charset 'iso-8859-1))
2793 (let ((coding-system-for-write charset)
2794 (coding-system-for-read charset))
2795 (call-process-region
2796 (point-min) (point-max)
2797 "w3m" t t nil "-dump" "-T" "text/html"
2798 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2799 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
73043f7d 2800
01c52d31
MB
2801(defvar gnus-article-browse-html-temp-list nil
2802 "List of temporary files created by `gnus-article-browse-html-parts'.
2803Internal variable.")
2804
2805(defcustom gnus-article-browse-delete-temp 'ask
2806 "What to do with temporary files from `gnus-article-browse-html-parts'.
2807If nil, don't delete temporary files. If it is t, delete them on
2808exit from the summary buffer. If it is the symbol `file', query
2809on each file, if it is `ask' ask once when exiting from the
2810summary buffer."
2811 :group 'gnus-article
330f707b 2812 :version "23.1" ;; No Gnus
01c52d31
MB
2813 :type '(choice (const :tag "Don't delete" nil)
2814 (const :tag "Don't ask" t)
2815 (const :tag "Ask" ask)
2816 (const :tag "Ask for each file" file)))
2817
2818;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2819
2820(defun gnus-article-browse-delete-temp-files (&optional how)
2821 "Delete temp-files created by `gnus-article-browse-html-parts'."
2822 (when (and gnus-article-browse-html-temp-list
3aeb9402
KY
2823 (progn
2824 (or how (setq how gnus-article-browse-delete-temp))
2825 (if (eq how 'ask)
2826 (let ((files (length gnus-article-browse-html-temp-list)))
2827 (gnus-y-or-n-p (format
2828 "Delete all %s temporary HTML file%s? "
2829 files
2830 (if (> files 1) "s" ""))))
2831 how)))
01c52d31 2832 (dolist (file gnus-article-browse-html-temp-list)
3aeb9402
KY
2833 (cond ((file-directory-p file)
2834 (when (or (not (eq how 'file))
2835 (gnus-y-or-n-p
2836 (format
2837 "Delete temporary HTML file(s) in directory `%s'? "
2838 (file-name-as-directory file))))
2839 (gnus-delete-directory file)))
2840 ((file-exists-p file)
2841 (when (or (not (eq how 'file))
2842 (gnus-y-or-n-p
2843 (format "Delete temporary HTML file `%s'? " file)))
2844 (delete-file file)))))
01c52d31
MB
2845 ;; Also remove file from the list when not deleted or if file doesn't
2846 ;; exist anymore.
2847 (setq gnus-article-browse-html-temp-list nil))
2848 gnus-article-browse-html-temp-list)
2849
d40d713a
KY
2850(defun gnus-article-browse-html-save-cid-content (cid handles directory)
2851 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2852Return file name."
20c0b2ce 2853 (save-match-data
d40d713a
KY
2854 (let (file type)
2855 (catch 'found
2856 (dolist (handle handles)
2857 (cond
2858 ((not (listp handle)))
2859 ((equal (mm-handle-media-supertype handle) "multipart")
2860 (when (setq file (gnus-article-browse-html-save-cid-content
2861 cid handle directory))
2862 (throw 'found file)))
2863 ((equal (concat "<" cid ">") (mm-handle-id handle))
2864 (setq file
2865 (expand-file-name
2866 (or (mail-content-type-get
2867 (mm-handle-disposition handle) 'filename)
2868 (mail-content-type-get
2869 (setq type (mm-handle-type handle)) 'name)
2870 (concat
2871 (make-temp-name "cid")
2872 (car (rassoc (car type) mailcap-mime-extensions))))
2873 directory))
2874 (mm-save-part-to-file handle file)
2875 (throw 'found file))))))))
20c0b2ce 2876
87035689 2877(defun gnus-article-browse-html-parts (list &optional header)
01c52d31 2878 "View all \"text/html\" parts from LIST.
87035689
MB
2879Recurse into multiparts. The optional HEADER that should be a decoded
2880message header will be added to the bodies of the \"text/html\" parts."
01c52d31 2881 ;; Internal function used by `gnus-article-browse-html-article'.
d40d713a 2882 (let (type file charset content cid-dir tmp-file showed)
01c52d31
MB
2883 ;; Find and show the html-parts.
2884 (dolist (handle list)
2885 ;; If HTML, show it:
bbbe940b
MB
2886 (cond ((not (listp handle)))
2887 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2888 (and (equal (car type) "message/external-body")
87035689
MB
2889 (or header
2890 (setq file (or (mail-content-type-get type 'name)
2891 (mail-content-type-get
2892 (mm-handle-disposition handle)
2893 'filename))))
bbbe940b
MB
2894 (or (mm-handle-cache handle)
2895 (condition-case code
2896 (progn (mm-extern-cache-contents handle) t)
2897 (error
2898 (gnus-message 3 "%s" (error-message-string code))
2899 (when (>= gnus-verbose 3) (sit-for 2))
2900 nil)))
2901 (progn
2902 (setq handle (mm-handle-cache handle)
2903 type (mm-handle-type handle))
2904 (equal (car type) "text/html"))))
d40d713a
KY
2905 (setq charset (mail-content-type-get type 'charset)
2906 content (mm-get-part handle))
2907 (with-temp-buffer
2908 (if (eq charset 'gnus-decoded)
2909 (mm-enable-multibyte)
2910 (mm-disable-multibyte))
2911 (insert content)
2912 ;; resolve cid contents
2913 (let ((case-fold-search t)
2914 cid-file)
2915 (goto-char (point-min))
2916 (while (re-search-forward "\
2917<img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2918 nil t)
2919 (unless cid-dir
765d4319 2920 (setq cid-dir (mm-make-temp-file "cid" t))
d40d713a
KY
2921 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2922 (setq file nil
2923 content nil)
2924 (when (setq cid-file
2925 (gnus-article-browse-html-save-cid-content
2926 (match-string 2)
2927 (with-current-buffer gnus-article-buffer
2928 gnus-article-mime-handles)
2929 cid-dir))
2930 (replace-match (concat "file://" cid-file)
2931 nil nil nil 1))))
2932 (unless content (setq content (buffer-string))))
2933 (when (or charset header (not file))
bbbe940b
MB
2934 (setq tmp-file (mm-make-temp-file
2935 ;; Do we need to care for 8.3 filenames?
2936 "mm-" nil ".html")))
87035689
MB
2937 ;; Add a meta html tag to specify charset and a header.
2938 (cond
2939 (header
d40d713a 2940 (let (title eheader body hcharset coding force-charset)
87035689
MB
2941 (with-temp-buffer
2942 (mm-enable-multibyte)
2943 (setq case-fold-search t)
2944 (insert header "\n")
2945 (setq title (message-fetch-field "subject"))
2946 (goto-char (point-min))
2947 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2948 (replace-match (cond ((match-beginning 1) "&lt;")
2949 ((match-beginning 2) "&gt;")
2950 (t "&amp;"))))
2951 (goto-char (point-min))
2952 (insert "<pre>\n")
2953 (goto-char (point-max))
2954 (insert "</pre>\n<hr>\n")
2955 ;; We have to examine charset one by one since
2956 ;; charset specified in parts might be different.
2957 (if (eq charset 'gnus-decoded)
2958 (setq charset 'utf-8
2959 eheader (mm-encode-coding-string (buffer-string)
2960 charset)
2961 title (when title
2962 (mm-encode-coding-string title charset))
d40d713a 2963 body (mm-encode-coding-string content charset)
82fc7980 2964 force-charset t)
87035689
MB
2965 (setq hcharset (mm-find-mime-charset-region (point-min)
2966 (point-max)))
2967 (cond ((= (length hcharset) 1)
2968 (setq hcharset (car hcharset)
2969 coding (mm-charset-to-coding-system
2970 hcharset)))
2971 ((> (length hcharset) 1)
2972 (setq hcharset 'utf-8
2973 coding hcharset)))
2974 (if coding
2975 (if charset
2976 (progn
2977 (setq body
2978 (mm-charset-to-coding-system charset))
2979 (if (eq coding body)
2980 (setq eheader (mm-encode-coding-string
2981 (buffer-string) coding)
2982 title (when title
2983 (mm-encode-coding-string
2984 title coding))
d40d713a 2985 body content)
87035689
MB
2986 (setq charset 'utf-8
2987 eheader (mm-encode-coding-string
2988 (buffer-string) charset)
2989 title (when title
2990 (mm-encode-coding-string
2991 title charset))
2992 body (mm-encode-coding-string
2993 (mm-decode-coding-string
d40d713a 2994 content body)
82fc7980
KY
2995 charset)
2996 force-charset t)))
87035689
MB
2997 (setq charset hcharset
2998 eheader (mm-encode-coding-string
2999 (buffer-string) coding)
3000 title (when title
3001 (mm-encode-coding-string
3002 title coding))
d40d713a 3003 body content))
87035689 3004 (setq eheader (mm-string-as-unibyte (buffer-string))
d40d713a 3005 body content)))
87035689
MB
3006 (erase-buffer)
3007 (mm-disable-multibyte)
3008 (insert body)
3009 (when charset
82fc7980 3010 (mm-add-meta-html-tag handle charset force-charset))
87035689
MB
3011 (when title
3012 (goto-char (point-min))
3013 (unless (search-forward "<title>" nil t)
3014 (re-search-forward "<head>\\s-*" nil t)
3015 (insert "<title>" title "</title>\n")))
3016 (goto-char (point-min))
3017 (or (re-search-forward
3018 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
3019 (re-search-forward
3020 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
3021 (insert eheader)
3022 (mm-write-region (point-min) (point-max)
3023 tmp-file nil nil nil 'binary t))))
3024 (charset
3025 (mm-with-unibyte-buffer
3026 (insert (if (eq charset 'gnus-decoded)
d40d713a
KY
3027 (mm-encode-coding-string content
3028 (setq charset 'utf-8))
3029 content))
87035689
MB
3030 (if (or (mm-add-meta-html-tag handle charset)
3031 (not file))
3032 (mm-write-region (point-min) (point-max)
3033 tmp-file nil nil nil 'binary t)
3034 (setq tmp-file nil))))
3035 (tmp-file
3036 (mm-save-part-to-file handle tmp-file)))
bbbe940b
MB
3037 (when tmp-file
3038 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3039 (add-hook 'gnus-summary-prepare-exit-hook
3040 'gnus-article-browse-delete-temp-files)
3041 (add-hook 'gnus-exit-gnus-hook
3042 (lambda ()
3043 (gnus-article-browse-delete-temp-files t)))
3044 ;; FIXME: Warn if there's an <img> tag?
3045 (browse-url-of-file (or tmp-file (expand-file-name file)))
3046 (setq showed t))
3047 ;; If multipart, recurse
87035689
MB
3048 ((equal (mm-handle-media-supertype handle) "multipart")
3049 (when (gnus-article-browse-html-parts handle header)
3050 (setq showed t)))
3051 ((equal (mm-handle-media-type handle) "message/rfc822")
3052 (mm-with-multibyte-buffer
3053 (mm-insert-part handle)
3054 (setq handle (mm-dissect-buffer t t))
3055 (when (and (bufferp (car handle))
3056 (stringp (car (mm-handle-type handle))))
3057 (setq handle (list handle)))
3058 (when header
3059 (article-decode-encoded-words)
3060 (let ((gnus-visible-headers
3061 (or (get 'gnus-visible-headers 'standard-value)
3062 gnus-visible-headers)))
3063 (article-hide-headers))
3064 (goto-char (point-min))
3065 (search-forward "\n\n" nil 'move)
3066 (skip-chars-backward "\t\n ")
3067 (setq header (buffer-substring (point-min) (point)))))
3068 (when (prog1
3069 (gnus-article-browse-html-parts handle header)
3070 (mm-destroy-parts handle))
3071 (setq showed t)))))
01c52d31
MB
3072 showed))
3073
87035689 3074(defun gnus-article-browse-html-article (&optional arg)
01c52d31 3075 "View \"text/html\" parts of the current article with a WWW browser.
d40d713a
KY
3076Inline images embedded in a message using the cid scheme, as they are
3077generally considered to be safe, will be processed properly.
87035689
MB
3078The message header is added to the beginning of every html part unless
3079the prefix argument ARG is given.
01c52d31 3080
d40d713a
KY
3081Warning: Spammers use links to images (using the http scheme) in HTML
3082articles to verify whether you have read the message. As
9b3ebcb6
MB
3083`gnus-article-browse-html-article' passes the HTML content to the
3084browser without eliminating these \"web bugs\" you should only
3085use it for mails from trusted senders.
b890d447 3086
9b3ebcb6 3087If you always want to display HTML parts in the browser, set
d40d713a
KY
3088`mm-text-html-renderer' to nil.
3089
3090This command creates temporary files to pass HTML contents including
3091images if any to the browser, and deletes them when exiting the group
3092\(if you want)."
01c52d31 3093 ;; Cf. `mm-w3m-safe-url-regexp'
87035689
MB
3094 (interactive "P")
3095 (if arg
3096 (gnus-summary-show-article)
3097 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
9b3ebcb6
MB
3098 gnus-visible-headers))
3099 ;; As we insert a <hr>, there's no need for the body boundary.
3100 (gnus-treat-body-boundary nil))
87035689
MB
3101 (gnus-summary-show-article)))
3102 (with-current-buffer gnus-article-buffer
3103 (let ((header (unless arg
3104 (save-restriction
3105 (widen)
3106 (buffer-substring-no-properties
3107 (goto-char (point-min))
3108 (if (search-forward "\n\n" nil t)
3109 (match-beginning 0)
3110 (goto-char (point-max))
3111 (skip-chars-backward "\t\n ")
3112 (point))))))
3113 parts)
3114 (set-buffer gnus-original-article-buffer)
3115 (setq parts (mm-dissect-buffer t t))
01c52d31
MB
3116 ;; If singlepart, enforce a list.
3117 (when (and (bufferp (car parts))
3118 (stringp (car (mm-handle-type parts))))
3119 (setq parts (list parts)))
3120 ;; Process the list
87035689 3121 (unless (gnus-article-browse-html-parts parts header)
01c52d31 3122 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
87035689
MB
3123 (mm-destroy-parts parts)
3124 (unless arg
3125 (gnus-summary-show-article)))))
01c52d31 3126
16409b0b
GM
3127(defun article-hide-list-identifiers ()
3128 "Remove list identifies from the Subject header.
3129The `gnus-list-identifiers' variable specifies what to do."
3130 (interactive)
23f87bed
MB
3131 (let ((inhibit-point-motion-hooks t)
3132 (regexp (if (consp gnus-list-identifiers)
3133 (mapconcat 'identity gnus-list-identifiers " *\\|")
3134 gnus-list-identifiers))
3135 (inhibit-read-only t))
3136 (when regexp
3137 (save-excursion
3138 (save-restriction
3139 (article-narrow-to-head)
3140 (goto-char (point-min))
3141 (while (re-search-forward
3142 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3143 nil t)
3144 (delete-region (match-beginning 2) (match-end 0))
3145 (beginning-of-line))
3146 (when (re-search-forward
3147 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3148 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
3149
3150(defun article-hide-pem (&optional arg)
3151 "Toggle hiding of any PEM headers and signatures in the current article.
3152If given a negative prefix, always show; if given a positive prefix,
3153always hide."
3154 (interactive (gnus-article-hidden-arg))
3155 (unless (gnus-article-check-hidden-text 'pem arg)
3156 (save-excursion
23f87bed 3157 (let ((inhibit-read-only t) end)
eec82323 3158 (goto-char (point-min))
16409b0b
GM
3159 ;; Hide the horrendously ugly "header".
3160 (when (and (search-forward
3161 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3162 nil t)
3163 (setq end (1+ (match-beginning 0))))
23f87bed 3164 (gnus-add-wash-type 'pem)
16409b0b
GM
3165 (gnus-article-hide-text-type
3166 end
3167 (if (search-forward "\n\n" nil t)
3168 (match-end 0)
3169 (point-max))
3170 'pem)
3171 ;; Hide the trailer as well
3172 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3173 nil t)
3174 (gnus-article-hide-text-type
3175 (match-beginning 0) (match-end 0) 'pem)))))))
3176
3177(defun article-strip-banner ()
23f87bed
MB
3178 "Strip the banners specified by the `banner' group parameter and by
3179`gnus-article-address-banner-alist'."
16409b0b 3180 (interactive)
23f87bed
MB
3181 (save-excursion
3182 (save-restriction
3183 (let ((inhibit-point-motion-hooks t))
3184 (when (gnus-parameter-banner gnus-newsgroup-name)
3185 (article-really-strip-banner
3186 (gnus-parameter-banner gnus-newsgroup-name)))
3187 (when gnus-article-address-banner-alist
cf5a5c38
MB
3188 ;; Note that the From header is decoded here, so it is
3189 ;; required that the *-extract-address-components function
3190 ;; supports non-ASCII text.
d71c0855
MB
3191 (let ((from (save-restriction
3192 (widen)
3193 (article-narrow-to-head)
3194 (mail-fetch-field "from"))))
3195 (when (and from
3196 (setq from
3197 (cadr (funcall gnus-extract-address-components
3198 from))))
3199 (catch 'found
3200 (dolist (pair gnus-article-address-banner-alist)
3201 (when (string-match (car pair) from)
3202 (throw 'found
3203 (article-really-strip-banner (cdr pair)))))))))))))
23f87bed
MB
3204
3205(defun article-really-strip-banner (banner)
3206 "Strip the banner specified by the argument."
16409b0b
GM
3207 (save-excursion
3208 (save-restriction
3209 (let ((inhibit-point-motion-hooks t)
16409b0b 3210 (gnus-signature-limit nil)
23f87bed
MB
3211 (inhibit-read-only t))
3212 (article-goto-body)
3213 (cond
3214 ((eq banner 'signature)
3215 (when (gnus-article-narrow-to-signature)
3216 (widen)
3217 (forward-line -1)
3218 (delete-region (point) (point-max))))
3219 ((symbolp banner)
3220 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3221 (while (re-search-forward banner nil t)
3222 (delete-region (match-beginning 0) (match-end 0)))))
3223 ((stringp banner)
3224 (while (re-search-forward banner nil t)
3225 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
3226
3227(defun article-babel ()
3228 "Translate article using an online translation service."
3229 (interactive)
3230 (require 'babel)
01c52d31 3231 (gnus-with-article-buffer
16409b0b 3232 (when (article-goto-body)
01c52d31 3233 (let* ((start (point))
16409b0b
GM
3234 (end (point-max))
3235 (orig (buffer-substring start end))
23f87bed 3236 (trans (babel-as-string orig)))
16409b0b
GM
3237 (save-restriction
3238 (narrow-to-region start end)
3239 (delete-region start end)
23f87bed 3240 (insert trans))))))
eec82323
LMI
3241
3242(defun article-hide-signature (&optional arg)
3243 "Hide the signature in the current article.
3244If given a negative prefix, always show; if given a positive prefix,
3245always hide."
3246 (interactive (gnus-article-hidden-arg))
3247 (unless (gnus-article-check-hidden-text 'signature arg)
3248 (save-excursion
3249 (save-restriction
4e7d0221 3250 (let ((inhibit-read-only t))
eec82323
LMI
3251 (when (gnus-article-narrow-to-signature)
3252 (gnus-article-hide-text-type
23f87bed
MB
3253 (point-min) (point-max) 'signature))))))
3254 (gnus-set-mode-line 'article))
eec82323 3255
16409b0b
GM
3256(defun article-strip-headers-in-body ()
3257 "Strip offensive headers from bodies."
3258 (interactive)
3259 (save-excursion
3260 (article-goto-body)
3261 (let ((case-fold-search t))
3262 (when (looking-at "x-no-archive:")
3263 (gnus-delete-line)))))
3264
eec82323
LMI
3265(defun article-strip-leading-blank-lines ()
3266 "Remove all blank lines from the beginning of the article."
3267 (interactive)
3268 (save-excursion
3269 (let ((inhibit-point-motion-hooks t)
23f87bed 3270 (inhibit-read-only t))
16409b0b 3271 (when (article-goto-body)
eec82323
LMI
3272 (while (and (not (eobp))
3273 (looking-at "[ \t]*$"))
3274 (gnus-delete-line))))))
3275
16409b0b
GM
3276(defun article-narrow-to-head ()
3277 "Narrow the buffer to the head of the message.
3278Point is left at the beginning of the narrowed-to region."
3279 (narrow-to-region
3280 (goto-char (point-min))
3281 (if (search-forward "\n\n" nil 1)
3282 (1- (point))
3283 (point-max)))
3284 (goto-char (point-min)))
3285
3286(defun article-goto-body ()
3287 "Place point at the start of the body."
3288 (goto-char (point-min))
3289 (cond
3290 ;; This variable is only bound when dealing with separate
3291 ;; MIME body parts.
3292 (article-goto-body-goes-to-point-min-p
3293 t)
3294 ((search-forward "\n\n" nil t)
3295 t)
3296 (t
3297 (goto-char (point-max))
3298 nil)))
3299
eec82323
LMI
3300(defun article-strip-multiple-blank-lines ()
3301 "Replace consecutive blank lines with one empty line."
3302 (interactive)
3303 (save-excursion
3304 (let ((inhibit-point-motion-hooks t)
23f87bed 3305 (inhibit-read-only t))
eec82323 3306 ;; First make all blank lines empty.
16409b0b 3307 (article-goto-body)
eec82323 3308 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
3309 (unless (gnus-annotation-in-region-p
3310 (match-beginning 0) (match-end 0))
3311 (replace-match "" nil t)))
eec82323 3312 ;; Then replace multiple empty lines with a single empty line.
16409b0b 3313 (article-goto-body)
23f87bed 3314 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
3315 (unless (gnus-annotation-in-region-p
3316 (match-beginning 0) (match-end 0))
23f87bed 3317 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3318
3319(defun article-strip-leading-space ()
3320 "Remove all white space from the beginning of the lines in the article."
3321 (interactive)
3322 (save-excursion
3323 (let ((inhibit-point-motion-hooks t)
23f87bed 3324 (inhibit-read-only t))
16409b0b 3325 (article-goto-body)
eec82323
LMI
3326 (while (re-search-forward "^[ \t]+" nil t)
3327 (replace-match "" t t)))))
3328
16409b0b
GM
3329(defun article-strip-trailing-space ()
3330 "Remove all white space from the end of the lines in the article."
3331 (interactive)
3332 (save-excursion
3333 (let ((inhibit-point-motion-hooks t)
23f87bed 3334 (inhibit-read-only t))
16409b0b
GM
3335 (article-goto-body)
3336 (while (re-search-forward "[ \t]+$" nil t)
3337 (replace-match "" t t)))))
3338
eec82323
LMI
3339(defun article-strip-blank-lines ()
3340 "Strip leading, trailing and multiple blank lines."
3341 (interactive)
3342 (article-strip-leading-blank-lines)
3343 (article-remove-trailing-blank-lines)
3344 (article-strip-multiple-blank-lines))
3345
6748645f
LMI
3346(defun article-strip-all-blank-lines ()
3347 "Strip all blank lines."
3348 (interactive)
3349 (save-excursion
3350 (let ((inhibit-point-motion-hooks t)
23f87bed 3351 (inhibit-read-only t))
16409b0b 3352 (article-goto-body)
6748645f
LMI
3353 (while (re-search-forward "^[ \t]*\n" nil t)
3354 (replace-match "" t t)))))
3355
eec82323
LMI
3356(defun gnus-article-narrow-to-signature ()
3357 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 3358 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
3359 (when (gnus-article-search-signature)
3360 (forward-line 1)
3361 ;; Check whether we have some limits to what we consider
3362 ;; to be a signature.
3363 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3364 (list gnus-signature-limit)))
3365 limit limited)
3366 (while (setq limit (pop limits))
3367 (if (or (and (integerp limit)
3368 (< (- (point-max) (point)) limit))
3369 (and (floatp limit)
3370 (< (count-lines (point) (point-max)) limit))
23f87bed 3371 (and (functionp limit)
6748645f
LMI
3372 (funcall limit))
3373 (and (stringp limit)
3374 (not (re-search-forward limit nil t))))
3375 () ; This limit did not succeed.
3376 (setq limited t
3377 limits nil)))
3378 (unless limited
3379 (narrow-to-region (point) (point-max))
3380 t)))))
eec82323
LMI
3381
3382(defun gnus-article-search-signature ()
3383 "Search the current buffer for the signature separator.
3384Put point at the beginning of the signature separator."
3385 (let ((cur (point)))
3386 (goto-char (point-max))
3387 (if (if (stringp gnus-signature-separator)
3388 (re-search-backward gnus-signature-separator nil t)
3389 (let ((seps gnus-signature-separator))
3390 (while (and seps
3391 (not (re-search-backward (car seps) nil t)))
3392 (pop seps))
3393 seps))
3394 t
3395 (goto-char cur)
3396 nil)))
3397
eec82323
LMI
3398(defun gnus-article-hidden-arg ()
3399 "Return the current prefix arg as a number, or 0 if no prefix."
3400 (list (if current-prefix-arg
3401 (prefix-numeric-value current-prefix-arg)
3402 0)))
3403
3404(defun gnus-article-check-hidden-text (type arg)
3405 "Return nil if hiding is necessary.
f0529b5b 3406Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
3407means show, 0 means toggle."
3408 (save-excursion
3409 (save-restriction
eec82323
LMI
3410 (let ((hide (gnus-article-hidden-text-p type)))
3411 (cond
3412 ((or (null arg)
3413 (> arg 0))
3414 nil)
3415 ((< arg 0)
4481aa98
SZ
3416 (gnus-article-show-hidden-text type)
3417 t)
eec82323
LMI
3418 (t
3419 (if (eq hide 'hidden)
4481aa98
SZ
3420 (progn
3421 (gnus-article-show-hidden-text type)
3422 t)
eec82323
LMI
3423 nil)))))))
3424
3425(defun gnus-article-hidden-text-p (type)
3426 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 3427 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 3428 (while (and pos
16409b0b
GM
3429 (not (get-text-property pos 'invisible))
3430 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
3431 (setq pos
3432 (text-property-any (1+ pos) (point-max) 'article-type type)))
3433 (if pos
3434 'hidden
16409b0b 3435 nil)))
eec82323 3436
520aa572 3437(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 3438 "Show all hidden text of type TYPE.
520aa572 3439Originally it is hide instead of DUMMY."
4e7d0221 3440 (let ((inhibit-read-only t)
520aa572 3441 (inhibit-point-motion-hooks t))
a1506d29 3442 (gnus-remove-text-properties-when
520aa572 3443 'article-type type
a1506d29 3444 (point-min) (point-max)
520aa572 3445 (cons 'article-type (cons type
23f87bed
MB
3446 gnus-hidden-properties)))
3447 (gnus-delete-wash-type type)))
eec82323
LMI
3448
3449(defconst article-time-units
3450 `((year . ,(* 365.25 24 60 60))
3451 (week . ,(* 7 24 60 60))
3452 (day . ,(* 24 60 60))
3453 (hour . ,(* 60 60))
3454 (minute . 60)
3455 (second . 1))
3456 "Mapping from time units to seconds.")
3457
23f87bed
MB
3458(defun gnus-article-forward-header ()
3459 "Move point to the start of the next header.
3460If the current header is a continuation header, this can be several
3461lines forward."
3462 (let ((ended nil))
3463 (while (not ended)
3464 (forward-line 1)
3465 (if (looking-at "[ \t]+[^ \t]")
3466 (forward-line 1)
3467 (setq ended t)))))
3468
31640842 3469(defun article-date-ut (&optional type highlight)
eec82323
LMI
3470 "Convert DATE date to universal time in the current article.
3471If TYPE is `local', convert to local time; if it is `lapsed', output
16409b0b
GM
3472how much time has lapsed since DATE. For `lapsed', the value of
3473`gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3474should replace the \"Date:\" one, or should be added below it."
eec82323 3475 (interactive (list 'ut t))
31640842
MB
3476 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3477 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3478 tdate-regexp)
3479 ((eq type 'lapsed)
3480 "^X-Sent:[ \t]")
3481 (article-lapsed-timer
3482 "^Date:[ \t]")
3483 (t
3484 tdate-regexp)))
3485 (case-fold-search t)
3486 (inhibit-read-only t)
eec82323 3487 (inhibit-point-motion-hooks t)
31640842 3488 pos date bface eface)
16409b0b
GM
3489 (save-excursion
3490 (save-restriction
31640842
MB
3491 (widen)
3492 (goto-char (point-min))
3493 (while (or (setq date (get-text-property (setq pos (point))
3494 'original-date))
3495 (when (setq pos (next-single-property-change
3496 (point) 'original-date))
3497 (setq date (get-text-property pos 'original-date))
3498 t))
548f737d
MB
3499 (narrow-to-region
3500 pos (if (setq pos (text-property-any pos (point-max)
3501 'original-date nil))
3502 (progn
3503 (goto-char pos)
3504 (if (or (bolp) (eobp))
3505 (point)
3506 (1+ (point))))
3507 (point-max)))
16409b0b 3508 (goto-char (point-min))
31640842 3509 (when (re-search-forward tdate-regexp nil t)
01c52d31
MB
3510 (setq bface (get-text-property (point-at-bol) 'face)
3511 eface (get-text-property (1- (point-at-eol)) 'face)))
31640842
MB
3512 (goto-char (point-min))
3513 (setq pos nil)
3514 ;; Delete any old Date headers.
3515 (while (re-search-forward date-regexp nil t)
3516 (if pos
01c52d31
MB
3517 (delete-region (point-at-bol) (progn
3518 (gnus-article-forward-header)
3519 (point)))
3520 (delete-region (point-at-bol) (progn
3521 (gnus-article-forward-header)
3522 (forward-char -1)
3523 (point)))
31640842
MB
3524 (setq pos (point))))
3525 (when (and (not pos)
3526 (re-search-forward tdate-regexp nil t))
3527 (forward-line 1))
3528 (gnus-goto-char pos)
3529 (insert (article-make-date-line date (or type 'ut)))
3530 (unless pos
3531 (insert "\n")
3532 (forward-line -1))
3533 ;; Do highlighting.
3534 (beginning-of-line)
3535 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3536 (put-text-property (match-beginning 1) (1+ (match-end 1))
3537 'face bface)
3538 (put-text-property (match-beginning 2) (match-end 2)
3539 'face eface))
3540 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3541 (goto-char (point-max))
3542 (widen))))))
eec82323
LMI
3543
3544(defun article-make-date-line (date type)
3545 "Return a DATE line of TYPE."
23f87bed
MB
3546 (unless (memq type '(local ut original user iso8601 lapsed english))
3547 (error "Unknown conversion type: %s" type))
3548 (condition-case ()
3549 (let ((time (date-to-time date)))
16409b0b 3550 (cond
23f87bed
MB
3551 ;; Convert to the local timezone.
3552 ((eq type 'local)
01c52d31 3553 (concat "Date: " (message-make-date time)))
23f87bed
MB
3554 ;; Convert to Universal Time.
3555 ((eq type 'ut)
3556 (concat "Date: "
01c52d31
MB
3557 (substring
3558 (message-make-date
3559 (let* ((e (parse-time-string date))
3560 (tm (apply 'encode-time e))
3561 (ms (car tm))
3562 (ls (- (cadr tm) (car (current-time-zone time)))))
3563 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3564 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3565 (t (list ms ls)))))
3566 0 -5)
3567 "UT"))
23f87bed
MB
3568 ;; Get the original date from the article.
3569 ((eq type 'original)
3570 (concat "Date: " (if (string-match "\n+$" date)
3571 (substring date 0 (match-beginning 0))
3572 date)))
3573 ;; Let the user define the format.
3574 ((eq type 'user)
3575 (let ((format (or (condition-case nil
3576 (with-current-buffer gnus-summary-buffer
3577 gnus-article-time-format)
3578 (error nil))
3579 gnus-article-time-format)))
3580 (if (functionp format)
3581 (funcall format time)
3582 (concat "Date: " (format-time-string format time)))))
3583 ;; ISO 8601.
3584 ((eq type 'iso8601)
3585 (let ((tz (car (current-time-zone time))))
3586 (concat
3587 "Date: "
3588 (format-time-string "%Y%m%dT%H%M%S" time)
3589 (format "%s%02d%02d"
3590 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3591 (/ (% (abs tz) 3600) 60)))))
3592 ;; Do an X-Sent lapsed format.
3593 ((eq type 'lapsed)
3594 ;; If the date is seriously mangled, the timezone functions are
3595 ;; liable to bug out, so we ignore all errors.
3596 (let* ((now (current-time))
3597 (real-time (subtract-time now time))
3598 (real-sec (and real-time
3599 (+ (* (float (car real-time)) 65536)
3600 (cadr real-time))))
3601 (sec (and real-time (abs real-sec)))
3602 num prev)
3603 (cond
3604 ((null real-time)
3605 "X-Sent: Unknown")
3606 ((zerop sec)
3607 "X-Sent: Now")
3608 (t
3609 (concat
3610 "X-Sent: "
3611 ;; This is a bit convoluted, but basically we go
3612 ;; through the time units for years, weeks, etc,
3613 ;; and divide things to see whether that results
3614 ;; in positive answers.
3615 (mapconcat
3616 (lambda (unit)
3617 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3618 ;; The (remaining) seconds are too few to
3619 ;; be divided into this time unit.
3620 ""
3621 ;; It's big enough, so we output it.
3622 (setq sec (- sec (* num (cdr unit))))
3623 (prog1
3624 (concat (if prev ", " "") (int-to-string
3625 (floor num))
3626 " " (symbol-name (car unit))
3627 (if (> num 1) "s" ""))
3628 (setq prev t))))
3629 article-time-units "")
3630 ;; If dates are odd, then it might appear like the
3631 ;; article was sent in the future.
3632 (if (> real-sec 0)
3633 " ago"
3634 " in the future"))))))
3635 ;; Display the date in proper English
3636 ((eq type 'english)
3637 (let ((dtime (decode-time time)))
3638 (concat
3639 "Date: the "
3640 (number-to-string (nth 3 dtime))
3641 (let ((digit (% (nth 3 dtime) 10)))
3642 (cond
3643 ((memq (nth 3 dtime) '(11 12 13)) "th")
3644 ((= digit 1) "st")
3645 ((= digit 2) "nd")
3646 ((= digit 3) "rd")
3647 (t "th")))
3648 " of "
3649 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3650 " "
3651 (number-to-string (nth 5 dtime))
3652 " at "
3653 (format "%02d" (nth 2 dtime))
3654 ":"
3655 (format "%02d" (nth 1 dtime)))))))
3656 (error
a601fb74 3657 (format "Date: %s (from Gnus)" date))))
eec82323
LMI
3658
3659(defun article-date-local (&optional highlight)
3660 "Convert the current article date to the local timezone."
3661 (interactive (list t))
3662 (article-date-ut 'local highlight))
3663
23f87bed
MB
3664(defun article-date-english (&optional highlight)
3665 "Convert the current article date to something that is proper English."
3666 (interactive (list t))
3667 (article-date-ut 'english highlight))
3668
eec82323
LMI
3669(defun article-date-original (&optional highlight)
3670 "Convert the current article date to what it was originally.
3671This is only useful if you have used some other date conversion
3672function and want to see what the date was before converting."
3673 (interactive (list t))
3674 (article-date-ut 'original highlight))
3675
3676(defun article-date-lapsed (&optional highlight)
3677 "Convert the current article date to time lapsed since it was sent."
3678 (interactive (list t))
3679 (article-date-ut 'lapsed highlight))
3680
6748645f
LMI
3681(defun article-update-date-lapsed ()
3682 "Function to be run from a timer to update the lapsed time line."
e0a8aa09
LT
3683 (save-match-data
3684 (let (deactivate-mark)
3685 (save-excursion
3686 (ignore-errors
3687 (walk-windows
3688 (lambda (w)
3689 (set-buffer (window-buffer w))
3690 (when (eq major-mode 'gnus-article-mode)
3691 (let ((mark (point-marker)))
3692 (goto-char (point-min))
3693 (when (re-search-forward "^X-Sent:" nil t)
3694 (article-date-lapsed t))
3695 (goto-char (marker-position mark))
3696 (move-marker mark nil))))
3697 nil 'visible))))))
6748645f
LMI
3698
3699(defun gnus-start-date-timer (&optional n)
3700 "Start a timer to update the X-Sent header in the article buffers.
3701The numerical prefix says how frequently (in seconds) the function
3702is to run."
3703 (interactive "p")
3704 (unless n
3705 (setq n 1))
3706 (gnus-stop-date-timer)
3707 (setq article-lapsed-timer
01c52d31 3708 (run-at-time 1 n 'article-update-date-lapsed)))
6748645f
LMI
3709
3710(defun gnus-stop-date-timer ()
3711 "Stop the X-Sent timer."
3712 (interactive)
3713 (when article-lapsed-timer
3714 (nnheader-cancel-timer article-lapsed-timer)
3715 (setq article-lapsed-timer nil)))
3716
eec82323
LMI
3717(defun article-date-user (&optional highlight)
3718 "Convert the current article date to the user-defined format.
3719This format is defined by the `gnus-article-time-format' variable."
3720 (interactive (list t))
3721 (article-date-ut 'user highlight))
3722
6748645f
LMI
3723(defun article-date-iso8601 (&optional highlight)
3724 "Convert the current article date to ISO8601."
3725 (interactive (list t))
3726 (article-date-ut 'iso8601 highlight))
3727
31640842
MB
3728(defmacro gnus-article-save-original-date (&rest forms)
3729 "Save the original date as a text property and evaluate FORMS."
3730 `(let* ((case-fold-search t)
3731 (start (progn
3732 (goto-char (point-min))
3733 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3734 (not (bolp)))
3735 (match-end 0))))
3736 (date (when (and start
01c52d31 3737 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
31640842
MB
3738 nil t))
3739 (buffer-substring-no-properties start
3740 (match-beginning 0)))))
3741 (goto-char (point-max))
3742 (skip-chars-backward "\n")
3743 (put-text-property (point-min) (point) 'original-date date)
3744 ,@forms
3745 (goto-char (point-max))
3746 (skip-chars-backward "\n")
3747 (put-text-property (point-min) (point) 'original-date date)))
3748
23f87bed
MB
3749;; (defun article-show-all ()
3750;; "Show all hidden text in the article buffer."
3751;; (interactive)
3752;; (save-excursion
3753;; (let ((inhibit-read-only t))
3754;; (gnus-article-unhide-text (point-min) (point-max)))))
3755
3756(defun article-remove-leading-whitespace ()
3757 "Remove excessive whitespace from all headers."
eec82323
LMI
3758 (interactive)
3759 (save-excursion
23f87bed
MB
3760 (save-restriction
3761 (let ((inhibit-read-only t))
3762 (article-narrow-to-head)
3763 (goto-char (point-min))
3764 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3765 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3766
3767(defun article-emphasize (&optional arg)
3768 "Emphasize text according to `gnus-emphasis-alist'."
3769 (interactive (gnus-article-hidden-arg))
3770 (unless (gnus-article-check-hidden-text 'emphasis arg)
3771 (save-excursion
a1506d29 3772 (let ((alist (or
16409b0b 3773 (condition-case nil
a1506d29
JB
3774 (with-current-buffer gnus-summary-buffer
3775 gnus-article-emphasis-alist)
16409b0b
GM
3776 (error))
3777 gnus-emphasis-alist))
4e7d0221 3778 (inhibit-read-only t)
eec82323
LMI
3779 (props (append '(article-type emphasis)
3780 gnus-hidden-properties))
3781 regexp elem beg invisible visible face)
16409b0b 3782 (article-goto-body)
eec82323
LMI
3783 (setq beg (point))
3784 (while (setq elem (pop alist))
3785 (goto-char beg)
3786 (setq regexp (car elem)
3787 invisible (nth 1 elem)
3788 visible (nth 2 elem)
3789 face (nth 3 elem))
3790 (while (re-search-forward regexp nil t)
23f87bed
MB
3791 (when (and (match-beginning visible) (match-beginning invisible))
3792 (gnus-article-hide-text
3793 (match-beginning invisible) (match-end invisible) props)
3794 (gnus-article-unhide-text-type
3795 (match-beginning visible) (match-end visible) 'emphasis)
3796 (gnus-put-overlay-excluding-newlines
3797 (match-beginning visible) (match-end visible) 'face face)
3798 (gnus-add-wash-type 'emphasis)
3799 (goto-char (match-end invisible)))))))))
eec82323 3800
16409b0b
GM
3801(defun gnus-article-setup-highlight-words (&optional highlight-words)
3802 "Setup newsgroup emphasis alist."
3803 (unless gnus-article-emphasis-alist
3804 (let ((name (and gnus-newsgroup-name
3805 (gnus-group-real-name gnus-newsgroup-name))))
3806 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3807 (setq gnus-article-emphasis-alist
3808 (nconc
16409b0b
GM
3809 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3810 (while (setq elem (pop alist))
3811 (when (and name (string-match (car elem) name))
3812 (setq alist nil
3813 highlight (copy-sequence (cdr elem)))))
3814 highlight)
3815 (copy-sequence highlight-words)
3816 (if gnus-newsgroup-name
a1506d29 3817 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3818 gnus-newsgroup-name 'highlight-words t)))
3819 gnus-emphasis-alist)))))
3820
9efa445f
DN
3821(defvar gnus-summary-article-menu)
3822(defvar gnus-summary-post-menu)
eec82323
LMI
3823
3824;;; Saving functions.
3825
3826(defun gnus-article-save (save-buffer file &optional num)
3827 "Save the currently selected article."
26c9afc3
MB
3828 (when (or (get gnus-default-article-saver :headers)
3829 (not gnus-save-all-headers))
3830 ;; Remove headers according to `gnus-saved-headers' or the value
3831 ;; of the `:headers' property that the saver function might have.
eec82323 3832 (let ((gnus-visible-headers
26c9afc3
MB
3833 (or (symbol-value (get gnus-default-article-saver :headers))
3834 gnus-saved-headers gnus-visible-headers))
16c85f26
MB
3835 ;; Ignore group parameter. See `article-hide-headers'.
3836 (gnus-summary-buffer nil))
80de1778 3837 (with-current-buffer save-buffer
6748645f 3838 (article-hide-headers 1 t))))
eec82323
LMI
3839 (save-window-excursion
3840 (if (not gnus-default-article-saver)
a8151ef7 3841 (error "No default saver is defined")
eec82323 3842 ;; !!! Magic! The saving functions all save
16409b0b 3843 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3844 ;; bind that variable to our save-buffer.
3845 (set-buffer gnus-article-buffer)
3846 (let* ((gnus-save-article-buffer save-buffer)
3847 (filename
3848 (cond
3849 ((not gnus-prompt-before-saving) 'default)
3850 ((eq gnus-prompt-before-saving 'always) nil)
3851 (t file)))
3852 (gnus-number-of-articles-to-be-saved
3853 (when (eq gnus-prompt-before-saving t)
3854 num))) ; Magic
6748645f 3855 (set-buffer gnus-article-current-summary)
eec82323
LMI
3856 (funcall gnus-default-article-saver filename)))))
3857
3858(defun gnus-read-save-file-name (prompt &optional filename
26c9afc3
MB
3859 function group headers variable
3860 dir-var)
eec82323
LMI
3861 (let ((default-name
3862 (funcall function group headers (symbol-value variable)))
3863 result)
4325195c 3864 (setq result
a1506d29 3865 (expand-file-name
4325195c
DL
3866 (cond
3867 ((eq filename 'default)
3868 default-name)
3869 ((eq filename t)
3870 default-name)
3871 (filename filename)
3872 (t
26c9afc3
MB
3873 (when (symbol-value dir-var)
3874 (setq default-name (expand-file-name
3875 (file-name-nondirectory default-name)
3876 (symbol-value dir-var))))
4325195c
DL
3877 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3878 (prompt
3879 (format prompt
3880 (if (and gnus-number-of-articles-to-be-saved
3881 (> gnus-number-of-articles-to-be-saved 1))
3882 (format "these %d articles"
3883 gnus-number-of-articles-to-be-saved)
3884 "this article")))
3885 (file
3886 ;; Let the split methods have their say.
3887 (cond
3888 ;; No split name was found.
3889 ((null split-name)
3890 (read-file-name
3891 (concat prompt " (default "
81df110a 3892 (file-name-nondirectory default-name) "): ")
4325195c
DL
3893 (file-name-directory default-name)
3894 default-name))
3895 ;; A single group name is returned.
3896 ((stringp split-name)
3897 (setq default-name
3898 (funcall function split-name headers
3899 (symbol-value variable)))
3900 (read-file-name
3901 (concat prompt " (default "
81df110a 3902 (file-name-nondirectory default-name) "): ")
4325195c
DL
3903 (file-name-directory default-name)
3904 default-name))
3905 ;; A single split name was found
3906 ((= 1 (length split-name))
3907 (let* ((name (expand-file-name
23f87bed
MB
3908 (car split-name)
3909 gnus-article-save-directory))
4325195c
DL
3910 (dir (cond ((file-directory-p name)
3911 (file-name-as-directory name))
3912 ((file-exists-p name) name)
3913 (t gnus-article-save-directory))))
3914 (read-file-name
81df110a 3915 (concat prompt " (default " name "): ")
4325195c
DL
3916 dir name)))
3917 ;; A list of splits was found.
3918 (t
3919 (setq split-name (nreverse split-name))
3920 (let (result)
3921 (let ((file-name-history
3922 (nconc split-name file-name-history)))
3923 (setq result
3924 (expand-file-name
3925 (read-file-name
81df110a 3926 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3927 gnus-article-save-directory
3928 (car split-name))
3929 gnus-article-save-directory)))
3930 (car (push result file-name-history)))))))
3931 ;; Create the directory.
3932 (gnus-make-directory (file-name-directory file))
23f87bed 3933 ;; If we have read a directory, we append the default file name.
4325195c 3934 (when (file-directory-p file)
23f87bed
MB
3935 (setq file (expand-file-name (file-name-nondirectory
3936 default-name)
4325195c
DL
3937 (file-name-as-directory file))))
3938 ;; Possibly translate some characters.
3939 (nnheader-translate-file-chars file))))))
eec82323 3940 (gnus-make-directory (file-name-directory result))
26c9afc3
MB
3941 (when variable
3942 (set variable result))
3943 (when dir-var
3944 (set dir-var (file-name-directory result)))
3945 result))
eec82323
LMI
3946
3947(defun gnus-article-archive-name (group)
3948 "Return the first instance of an \"Archive-name\" in the current buffer."
3949 (let ((case-fold-search t))
3950 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3951 (nnheader-concat gnus-article-save-directory
3952 (match-string 1)))))
3953
3954(defun gnus-article-nndoc-name (group)
3955 "If GROUP is an nndoc group, return the name of the parent group."
3956 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3957 (gnus-group-get-parameter group 'save-article-group)))
3958
3959(defun gnus-summary-save-in-rmail (&optional filename)
3960 "Append this article to Rmail file.
3961Optional argument FILENAME specifies file name.
3962Directory to save to is default to `gnus-article-save-directory'."
eec82323 3963 (setq filename (gnus-read-save-file-name
81df110a 3964 "Save %s in rmail file" filename
eec82323
LMI
3965 gnus-rmail-save-name gnus-newsgroup-name
3966 gnus-current-headers 'gnus-newsgroup-last-rmail))
a3f57c41 3967 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
3968 (save-excursion
3969 (save-restriction
3970 (widen)
fef8d38e
GM
3971 ;; Note that unlike gnus-summary-save-in-mail, there is no
3972 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3973 ;; not use Babyl.
6748645f
LMI
3974 (gnus-output-to-rmail filename))))
3975 filename)
eec82323
LMI
3976
3977(defun gnus-summary-save-in-mail (&optional filename)
3978 "Append this article to Unix mail file.
3979Optional argument FILENAME specifies file name.
3980Directory to save to is default to `gnus-article-save-directory'."
eec82323 3981 (setq filename (gnus-read-save-file-name
81df110a 3982 "Save %s in Unix mail file" filename
eec82323
LMI
3983 gnus-mail-save-name gnus-newsgroup-name
3984 gnus-current-headers 'gnus-newsgroup-last-mail))
a3f57c41 3985 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
3986 (save-excursion
3987 (save-restriction
3988 (widen)
3989 (if (and (file-readable-p filename)
23f87bed 3990 (file-regular-p filename)
eec82323 3991 (mail-file-babyl-p filename))
fef8d38e 3992 (gnus-output-to-rmail filename)
6748645f
LMI
3993 (gnus-output-to-mail filename)))))
3994 filename)
eec82323 3995
26c9afc3
MB
3996(put 'gnus-summary-save-in-file :decode t)
3997(put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
eec82323
LMI
3998(defun gnus-summary-save-in-file (&optional filename overwrite)
3999 "Append this article to file.
4000Optional argument FILENAME specifies file name.
4001Directory to save to is default to `gnus-article-save-directory'."
eec82323 4002 (setq filename (gnus-read-save-file-name
81df110a 4003 "Save %s in file" filename
eec82323
LMI
4004 gnus-file-save-name gnus-newsgroup-name
4005 gnus-current-headers 'gnus-newsgroup-last-file))
a3f57c41 4006 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
4007 (save-excursion
4008 (save-restriction
4009 (widen)
4010 (when (and overwrite
4011 (file-exists-p filename))
4012 (delete-file filename))
6748645f
LMI
4013 (gnus-output-to-file filename))))
4014 filename)
eec82323 4015
26c9afc3
MB
4016(put 'gnus-summary-write-to-file :decode t)
4017(put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4018(put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
eec82323 4019(defun gnus-summary-write-to-file (&optional filename)
23f87bed 4020 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
4021Optional argument FILENAME specifies file name.
4022The directory to save in defaults to `gnus-article-save-directory'."
26c9afc3
MB
4023 (setq filename (gnus-read-save-file-name
4024 "Save %s in file" filename
4025 gnus-file-save-name gnus-newsgroup-name
4026 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4027 (gnus-summary-save-in-file filename t))
eec82323 4028
26c9afc3
MB
4029(put 'gnus-summary-save-body-in-file :decode t)
4030(defun gnus-summary-save-body-in-file (&optional filename overwrite)
eec82323
LMI
4031 "Append this article body to a file.
4032Optional argument FILENAME specifies file name.
4033The directory to save in defaults to `gnus-article-save-directory'."
eec82323 4034 (setq filename (gnus-read-save-file-name
81df110a 4035 "Save %s body in file" filename
eec82323
LMI
4036 gnus-file-save-name gnus-newsgroup-name
4037 gnus-current-headers 'gnus-newsgroup-last-file))
a3f57c41 4038 (with-current-buffer gnus-save-article-buffer
eec82323
LMI
4039 (save-excursion
4040 (save-restriction
4041 (widen)
16409b0b 4042 (when (article-goto-body)
eec82323 4043 (narrow-to-region (point) (point-max)))
26c9afc3
MB
4044 (when (and overwrite
4045 (file-exists-p filename))
4046 (delete-file filename))
6748645f
LMI
4047 (gnus-output-to-file filename))))
4048 filename)
eec82323 4049
26c9afc3
MB
4050(put 'gnus-summary-write-body-to-file :decode t)
4051(put 'gnus-summary-write-body-to-file
4052 :function 'gnus-summary-save-body-in-file)
4053(defun gnus-summary-write-body-to-file (&optional filename)
4054 "Write this article body to a file, overwriting it if the file exists.
4055Optional argument FILENAME specifies file name.
4056The directory to save in defaults to `gnus-article-save-directory'."
4057 (setq filename (gnus-read-save-file-name
4058 "Save %s body in file" filename
4059 gnus-file-save-name gnus-newsgroup-name
4060 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4061 (gnus-summary-save-body-in-file filename t))
4062
89167438
MB
4063(put 'gnus-summary-save-in-pipe :decode t)
4064(put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
d62672f3
MB
4065(defun gnus-summary-save-in-pipe (&optional command raw)
4066 "Pipe this article to subprocess COMMAND.
4067Valid values for COMMAND include:
4068 a string
4069 The executable command name and possibly arguments.
4070 nil
4071 You will be prompted for the command in the minibuffer.
4072 the symbol `default'
4073 It will be replaced with the command which the variable
4074 `gnus-summary-pipe-output-default-command' holds or the command
4075 last used for saving.
4076Non-nil value for RAW overrides `:decode' and `:headers' properties
4077and the raw article including all headers will be piped."
6ecfe5c2
MB
4078 (let ((article (gnus-summary-article-number))
4079 (decode (unless raw
4080 (get 'gnus-summary-save-in-pipe :decode)))
4081 save-buffer default)
4082 (if article
4083 (if (vectorp (gnus-summary-article-header article))
4084 (save-current-buffer
4085 (gnus-summary-select-article decode decode nil article)
4086 (insert-buffer-substring
4087 (prog1
4088 (if decode
4089 gnus-article-buffer
4090 gnus-original-article-buffer)
4091 (setq save-buffer
4092 (nnheader-set-temp-buffer " *Gnus Save*"))))
4093 ;; Remove unwanted headers.
4094 (when (and (not raw)
4095 (or (get 'gnus-summary-save-in-pipe :headers)
4096 (not gnus-save-all-headers)))
4097 (let ((gnus-visible-headers
4098 (or (symbol-value (get 'gnus-summary-save-in-pipe
4099 :headers))
4100 gnus-saved-headers gnus-visible-headers))
4101 (gnus-summary-buffer nil))
4102 (article-hide-headers 1 t))))
4103 (error "%d is not a real article" article))
4104 (error "No article to pipe"))
4105 (setq default (or gnus-summary-pipe-output-default-command
4106 gnus-last-shell-command))
89167438
MB
4107 (unless (stringp command)
4108 (setq command
4109 (if (and (eq command 'default) default)
4110 default
6ecfe5c2
MB
4111 (gnus-read-shell-command "Shell command on this article: "
4112 default))))
89167438
MB
4113 (when (string-equal command "")
4114 (if default
4115 (setq command default)
16c85f26 4116 (error "A command is required")))
a3f57c41 4117 (with-current-buffer save-buffer
16c85f26
MB
4118 (save-restriction
4119 (widen)
4120 (shell-command-on-region (point-min) (point-max) command nil)))
4121 (gnus-kill-buffer save-buffer))
89167438 4122 (setq gnus-summary-pipe-output-default-command command))
eec82323 4123
23f87bed
MB
4124(defun gnus-summary-pipe-to-muttprint (&optional command)
4125 "Pipe this article to muttprint."
16c85f26
MB
4126 (unless (stringp command)
4127 (setq command (read-string
4128 "Print using command: " gnus-summary-muttprint-program
4129 nil gnus-summary-muttprint-program)))
4130 (let ((gnus-summary-pipe-output-default-command
4131 gnus-summary-pipe-output-default-command))
4132 (gnus-summary-save-in-pipe command))
4133 (setq gnus-summary-muttprint-program command))
23f87bed 4134
eec82323
LMI
4135;;; Article file names when saving.
4136
4137(defun gnus-capitalize-newsgroup (newsgroup)
4138 "Capitalize NEWSGROUP name."
4139 (when (not (zerop (length newsgroup)))
4140 (concat (char-to-string (upcase (aref newsgroup 0)))
4141 (substring newsgroup 1))))
4142
4143(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4144 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4145If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4146Otherwise, it is like ~/News/news/group/num."
4147 (let ((default
4148 (expand-file-name
4149 (concat (if (gnus-use-long-file-name 'not-save)
4150 (gnus-capitalize-newsgroup newsgroup)
4151 (gnus-newsgroup-directory-form newsgroup))
4152 "/" (int-to-string (mail-header-number headers)))
4153 gnus-article-save-directory)))
4154 (if (and last-file
4155 (string-equal (file-name-directory default)
4156 (file-name-directory last-file))
4157 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4158 default
4159 (or last-file default))))
4160
4161(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4162 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4163If variable `gnus-use-long-file-name' is non-nil, it is
2ff9f5b4 4164~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
eec82323
LMI
4165 (let ((default
4166 (expand-file-name
4167 (concat (if (gnus-use-long-file-name 'not-save)
4168 newsgroup
4169 (gnus-newsgroup-directory-form newsgroup))
4170 "/" (int-to-string (mail-header-number headers)))
4171 gnus-article-save-directory)))
4172 (if (and last-file
4173 (string-equal (file-name-directory default)
4174 (file-name-directory last-file))
4175 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4176 default
4177 (or last-file default))))
4178
eec82323
LMI
4179(defun gnus-plain-save-name (newsgroup headers &optional last-file)
4180 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4181If variable `gnus-use-long-file-name' is non-nil, it is
4182~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4183 (or last-file
4184 (expand-file-name
4185 (if (gnus-use-long-file-name 'not-save)
4186 newsgroup
23f87bed
MB
4187 (file-relative-name
4188 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4189 default-directory))
eec82323
LMI
4190 gnus-article-save-directory)))
4191
23f87bed
MB
4192(defun gnus-sender-save-name (newsgroup headers &optional last-file)
4193 "Generate file name from sender."
4194 (let ((from (mail-header-from headers)))
4195 (expand-file-name
4196 (if (and from (string-match "\\([^ <]+\\)@" from))
4197 (match-string 1 from)
4198 "nobody")
4199 gnus-article-save-directory)))
4200
4201(defun article-verify-x-pgp-sig ()
4202 "Verify X-PGP-Sig."
bbbe940b 4203 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
23f87bed
MB
4204 (interactive)
4205 (if (gnus-buffer-live-p gnus-original-article-buffer)
4206 (let ((sig (with-current-buffer gnus-original-article-buffer
4207 (gnus-fetch-field "X-PGP-Sig")))
4208 items info headers)
4209 (when (and sig
4210 mml2015-use
4211 (mml2015-clear-verify-function))
4212 (with-temp-buffer
4213 (insert-buffer-substring gnus-original-article-buffer)
4214 (setq items (split-string sig))
4215 (message-narrow-to-head)
4216 (let ((inhibit-point-motion-hooks t)
4217 (case-fold-search t))
4218 ;; Don't verify multiple headers.
4219 (setq headers (mapconcat (lambda (header)
4220 (concat header ": "
4221 (mail-fetch-field header)
4222 "\n"))
4223 (split-string (nth 1 items) ",") "")))
4224 (delete-region (point-min) (point-max))
4225 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4226 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4227 (insert headers)
4228 (widen)
4229 (forward-line)
4230 (while (not (eobp))
4231 (if (looking-at "^-")
4232 (insert "- "))
4233 (forward-line))
4234 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4235 (insert "Version: " (car items) "\n\n")
4236 (insert (mapconcat 'identity (cddr items) "\n"))
4237 (insert "\n-----END PGP SIGNATURE-----\n")
4238 (let ((mm-security-handle (list (format "multipart/signed"))))
4239 (mml2015-clean-buffer)
4240 (let ((coding-system-for-write (or gnus-newsgroup-charset
4241 'iso-8859-1)))
4242 (funcall (mml2015-clear-verify-function)))
4243 (setq info
4244 (or (mm-handle-multipart-ctl-parameter
4245 mm-security-handle 'gnus-details)
4246 (mm-handle-multipart-ctl-parameter
4247 mm-security-handle 'gnus-info)))))
4248 (when info
4249 (let ((inhibit-read-only t) bface eface)
4250 (save-restriction
4251 (message-narrow-to-head)
4252 (goto-char (point-max))
4253 (forward-line -1)
01c52d31
MB
4254 (setq bface (get-text-property (point-at-bol) 'face)
4255 eface (get-text-property (1- (point-at-eol)) 'face))
23f87bed
MB
4256 (message-remove-header "X-Gnus-PGP-Verify")
4257 (if (re-search-forward "^X-PGP-Sig:" nil t)
4258 (forward-line)
4259 (goto-char (point-max)))
4260 (narrow-to-region (point) (point))
4261 (insert "X-Gnus-PGP-Verify: " info "\n")
4262 (goto-char (point-min))
4263 (forward-line)
4264 (while (not (eobp))
4265 (if (not (looking-at "^[ \t]"))
4266 (insert " "))
4267 (forward-line))
4268 ;; Do highlighting.
4269 (goto-char (point-min))
4270 (when (looking-at "\\([^:]+\\): *")
4271 (put-text-property (match-beginning 1) (1+ (match-end 1))
4272 'face bface)
4273 (put-text-property (match-end 0) (point-max)
4274 'face eface)))))))))
4275
5843126b 4276(autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
ec7995fa 4277
23f87bed
MB
4278(defun article-verify-cancel-lock ()
4279 "Verify Cancel-Lock header."
4280 (interactive)
4281 (if (gnus-buffer-live-p gnus-original-article-buffer)
4282 (canlock-verify gnus-original-article-buffer)))
4283
eec82323 4284(eval-and-compile
01c52d31 4285 (mapc
eec82323
LMI
4286 (lambda (func)
4287 (let (afunc gfunc)
4288 (if (consp func)
4289 (setq afunc (car func)
4290 gfunc (cdr func))
4291 (setq afunc func
4292 gfunc (intern (format "gnus-%s" func))))
16409b0b 4293 (defalias gfunc
23f87bed 4294 (when (fboundp afunc)
16409b0b
GM
4295 `(lambda (&optional interactive &rest args)
4296 ,(documentation afunc t)
4297 (interactive (list t))
80de1778 4298 (with-current-buffer gnus-article-buffer
16409b0b
GM
4299 (if interactive
4300 (call-interactively ',afunc)
4301 (apply ',afunc args))))))))
eec82323 4302 '(article-hide-headers
23f87bed
MB
4303 article-verify-x-pgp-sig
4304 article-verify-cancel-lock
eec82323
LMI
4305 article-hide-boring-headers
4306 article-treat-overstrike
01c52d31 4307 article-treat-ansi-sequences
16409b0b
GM
4308 article-fill-long-lines
4309 article-capitalize-sentences
eec82323 4310 article-remove-cr
23f87bed 4311 article-remove-leading-whitespace
eec82323 4312 article-display-x-face
23f87bed 4313 article-display-face
eec82323 4314 article-de-quoted-unreadable
16409b0b
GM
4315 article-de-base64-unreadable
4316 article-decode-HZ
4317 article-wash-html
23f87bed 4318 article-unsplit-urls
16409b0b 4319 article-hide-list-identifiers
16409b0b
GM
4320 article-strip-banner
4321 article-babel
eec82323
LMI
4322 article-hide-pem
4323 article-hide-signature
16409b0b 4324 article-strip-headers-in-body
eec82323
LMI
4325 article-remove-trailing-blank-lines
4326 article-strip-leading-blank-lines
4327 article-strip-multiple-blank-lines
4328 article-strip-leading-space
16409b0b 4329 article-strip-trailing-space
eec82323 4330 article-strip-blank-lines
6748645f 4331 article-strip-all-blank-lines
eec82323 4332 article-date-local
23f87bed 4333 article-date-english
6748645f 4334 article-date-iso8601
eec82323
LMI
4335 article-date-original
4336 article-date-ut
16409b0b
GM
4337 article-decode-mime-words
4338 article-decode-charset
4339 article-decode-encoded-words
eec82323
LMI
4340 article-date-user
4341 article-date-lapsed
4342 article-emphasize
6748645f 4343 article-treat-dumbquotes
16409b0b 4344 article-normalize-headers
01c52d31 4345 ;;(article-show-all . gnus-article-show-all-headers)
23f87bed 4346 )))
eec82323
LMI
4347\f
4348;;;
4349;;; Gnus article mode
4350;;;
4351
4352(put 'gnus-article-mode 'mode-class 'special)
4353
16409b0b
GM
4354(set-keymap-parent gnus-article-mode-map widget-keymap)
4355
a8151ef7
LMI
4356(gnus-define-keys gnus-article-mode-map
4357 " " gnus-article-goto-next-page
4358 "\177" gnus-article-goto-prev-page
4359 [delete] gnus-article-goto-prev-page
16409b0b 4360 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
4361 "\C-c^" gnus-article-refer-article
4362 "h" gnus-article-show-summary
4363 "s" gnus-article-show-summary
4364 "\C-c\C-m" gnus-article-mail
4365 "?" gnus-article-describe-briefly
a8151ef7
LMI
4366 "<" beginning-of-buffer
4367 ">" end-of-buffer
4368 "\C-c\C-i" gnus-info-find-node
4369 "\C-c\C-b" gnus-bug
23f87bed
MB
4370 "R" gnus-article-reply-with-original
4371 "F" gnus-article-followup-with-original
520aa572
SZ
4372 "\C-hk" gnus-article-describe-key
4373 "\C-hc" gnus-article-describe-key-briefly
0b6799c3 4374 "\C-hb" gnus-article-describe-bindings
a8151ef7 4375
6ab2c7a8 4376 "e" gnus-article-read-summary-keys
a8151ef7
LMI
4377 "\C-d" gnus-article-read-summary-keys
4378 "\M-*" gnus-article-read-summary-keys
4379 "\M-#" gnus-article-read-summary-keys
4380 "\M-^" gnus-article-read-summary-keys
4381 "\M-g" gnus-article-read-summary-keys)
4382
4383(substitute-key-definition
4384 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323 4385
95838435
MB
4386(gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4387 "W" gnus-article-wide-reply-with-original)
4388(if (featurep 'xemacs)
4389 (set-keymap-default-binding gnus-article-send-map
4390 'gnus-article-read-summary-send-keys)
4391 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4392
eec82323 4393(defun gnus-article-make-menu-bar ()
23f87bed
MB
4394 (unless (boundp 'gnus-article-commands-menu)
4395 (gnus-summary-make-menu-bar))
eec82323
LMI
4396 (gnus-turn-off-edit-menu 'article)
4397 (unless (boundp 'gnus-article-article-menu)
4398 (easy-menu-define
4399 gnus-article-article-menu gnus-article-mode-map ""
4400 '("Article"
4401 ["Scroll forwards" gnus-article-goto-next-page t]
4402 ["Scroll backwards" gnus-article-goto-prev-page t]
4403 ["Show summary" gnus-article-show-summary t]
4404 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
4405 ["Mail to address at point" gnus-article-mail t]
4406 ["Send a bug report" gnus-bug t]))
eec82323
LMI
4407
4408 (easy-menu-define
4409 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 4410 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
4411 '("Treatment"
4412 ["Hide headers" gnus-article-hide-headers t]
4413 ["Hide signature" gnus-article-hide-signature t]
4414 ["Hide citation" gnus-article-hide-citation t]
4415 ["Treat overstrike" gnus-article-treat-overstrike t]
01c52d31 4416 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
eec82323 4417 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 4418 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
4419 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4420 ["Remove base64" gnus-article-de-base64-unreadable t]
4421 ["Treat html" gnus-article-wash-html t]
23f87bed 4422 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 4423 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 4424
6748645f 4425 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 4426
23f87bed 4427 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 4428
6748645f 4429 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323 4430
8e7d4ca1
GM
4431(defvar bookmark-make-record-function)
4432
eec82323
LMI
4433(defun gnus-article-mode ()
4434 "Major mode for displaying an article.
4435
4436All normal editing commands are switched off.
4437
4438The following commands are available in addition to all summary mode
4439commands:
4440\\<gnus-article-mode-map>
4441\\[gnus-article-next-page]\t Scroll the article one page forwards
4442\\[gnus-article-prev-page]\t Scroll the article one page backwards
4443\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4444\\[gnus-article-show-summary]\t Display the summary buffer
4445\\[gnus-article-mail]\t Send a reply to the address near point
4446\\[gnus-article-describe-briefly]\t Describe the current mode briefly
4447\\[gnus-info-find-node]\t Go to the Gnus info node"
4448 (interactive)
0eb586fc 4449 (kill-all-local-variables)
eec82323
LMI
4450 (gnus-simplify-mode-line)
4451 (setq mode-name "Article")
4452 (setq major-mode 'gnus-article-mode)
4453 (make-local-variable 'minor-mode-alist)
eec82323 4454 (use-local-map gnus-article-mode-map)
1653df0f 4455 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
4456 (gnus-article-make-menu-bar)
4457 (when gnus-summary-tool-bar-map
4458 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
4459 (gnus-update-format-specifications nil 'article-mode)
4460 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 4461 (set (make-local-variable 'gnus-page-broken) nil)
6748645f
LMI
4462 (make-local-variable 'gnus-button-marker-list)
4463 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
4464 (make-local-variable 'gnus-article-mime-handles)
4465 (make-local-variable 'gnus-article-decoded-p)
4466 (make-local-variable 'gnus-article-mime-handle-alist)
4467 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
4468 (make-local-variable 'gnus-article-image-alist)
4469 (make-local-variable 'gnus-article-charset)
4470 (make-local-variable 'gnus-article-ignored-charsets)
33b48483
KF
4471 (set (make-local-variable 'bookmark-make-record-function)
4472 'gnus-summary-bookmark-make-record)
524705ae
MB
4473 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4474 ;; face.
fc1c32c1 4475 (set (make-local-variable 'nobreak-char-display) nil)
e4a89ccf 4476 (setq cursor-in-non-selected-windows nil)
01c52d31 4477 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4478 (gnus-set-default-directory)
16409b0b 4479 (buffer-disable-undo)
01c52d31
MB
4480 (setq buffer-read-only t
4481 show-trailing-whitespace nil)
eec82323 4482 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 4483 (mm-enable-multibyte)
cfcd5c91 4484 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323 4485
676c1893 4486(defvar gnus-button-marker-list nil
01c52d31
MB
4487 "Regexp matching any of the regexps from `gnus-button-alist'.
4488Internal variable.")
676c1893 4489
eec82323
LMI
4490(defun gnus-article-setup-buffer ()
4491 "Initialize the article buffer."
4492 (let* ((name (if gnus-single-article-buffer "*Article*"
4493 (concat "*Article " gnus-newsgroup-name "*")))
4494 (original
4495 (progn (string-match "\\*Article" name)
4496 (concat " *Original Article"
4497 (substring name (match-end 0))))))
4498 (setq gnus-article-buffer name)
4499 (setq gnus-original-article-buffer original)
16409b0b 4500 (setq gnus-article-mime-handle-alist nil)
01c52d31
MB
4501 (with-current-buffer gnus-summary-buffer
4502 ;; This might be a variable local to the summary buffer.
4503 (unless gnus-single-article-buffer
eec82323
LMI
4504 (setq gnus-article-buffer name)
4505 (setq gnus-original-article-buffer original)
4506 (gnus-set-global-variables)))
16409b0b 4507 (gnus-article-setup-highlight-words)
eec82323 4508 ;; Init original article buffer.
80de1778 4509 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
16409b0b 4510 (mm-enable-multibyte)
eec82323 4511 (setq major-mode 'gnus-original-article-mode)
eec82323 4512 (make-local-variable 'gnus-original-article))
aba1948a
MB
4513 (if (and (get-buffer name)
4514 (with-current-buffer name
4515 (if gnus-article-edit-mode
4516 (if (y-or-n-p "Article mode edit in progress; discard? ")
4517 (progn
4518 (set-buffer-modified-p nil)
4519 (gnus-kill-buffer name)
4520 (message "")
4521 nil)
4522 (error "Action aborted"))
4523 t)))
80de1778 4524 (with-current-buffer name
23f87bed 4525 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
4526 (when gnus-article-mime-handles
4527 (mm-destroy-parts gnus-article-mime-handles)
4528 (setq gnus-article-mime-handles nil))
4529 ;; Set it to nil in article-buffer!
a1506d29 4530 (setq gnus-article-mime-handle-alist nil)
16409b0b 4531 (buffer-disable-undo)
eec82323 4532 (setq buffer-read-only t)
23f87bed
MB
4533 ;; This list just keeps growing if we don't reset it.
4534 (setq gnus-button-marker-list nil)
eec82323
LMI
4535 (unless (eq major-mode 'gnus-article-mode)
4536 (gnus-article-mode))
4537 (current-buffer))
80de1778 4538 (with-current-buffer (gnus-get-buffer-create name)
eec82323
LMI
4539 (gnus-article-mode)
4540 (make-local-variable 'gnus-summary-buffer)
01c52d31
MB
4541 (setq gnus-summary-buffer
4542 (gnus-summary-buffer-name gnus-newsgroup-name))
16409b0b 4543 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
4544 (current-buffer)))))
4545
4546;; Set article window start at LINE, where LINE is the number of lines
4547;; from the head of the article.
4548(defun gnus-article-set-window-start (&optional line)
01c52d31
MB
4549 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4550 (when article-window
4551 (set-window-start
4552 article-window
80de1778 4553 (with-current-buffer gnus-article-buffer
01c52d31
MB
4554 (goto-char (point-min))
4555 (if (not line)
4556 (point-min)
4557 (gnus-message 6 "Moved to bookmark")
4558 (search-forward "\n\n" nil t)
4559 (forward-line line)
4560 (point)))))))
eec82323
LMI
4561
4562(defun gnus-article-prepare (article &optional all-headers header)
4563 "Prepare ARTICLE in article mode buffer.
4564ARTICLE should either be an article number or a Message-ID.
4565If ARTICLE is an id, HEADER should be the article headers.
4566If ALL-HEADERS is non-nil, no headers are hidden."
4567 (save-excursion
4568 ;; Make sure we start in a summary buffer.
4569 (unless (eq major-mode 'gnus-summary-mode)
4570 (set-buffer gnus-summary-buffer))
4571 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
4572 (let* ((gnus-article (if header (mail-header-number header) article))
4573 (summary-buffer (current-buffer))
6748645f 4574 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
4575 (group gnus-newsgroup-name)
4576 result)
4577 (save-excursion
4578 (gnus-article-setup-buffer)
4579 (set-buffer gnus-article-buffer)
4580 ;; Deactivate active regions.
4581 (when (and (boundp 'transient-mark-mode)
4582 transient-mark-mode)
4583 (setq mark-active nil))
4e7d0221 4584 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
4585 (gnus-request-article-this-buffer
4586 article group))))
4587 ;; There is no such article.
4588 (save-excursion
4589 (when (and (numberp article)
4590 (not (memq article gnus-newsgroup-sparse)))
4591 (setq gnus-article-current
4592 (cons gnus-newsgroup-name article))
4593 (set-buffer gnus-summary-buffer)
4594 (setq gnus-current-article article)
23f87bed
MB
4595 (if (and (memq article gnus-newsgroup-undownloaded)
4596 (not (gnus-online (gnus-find-method-for-group
4597 gnus-newsgroup-name))))
6748645f
LMI
4598 (progn
4599 (gnus-summary-set-agent-mark article)
4600 (message "Message marked for downloading"))
4601 (gnus-summary-mark-article article gnus-canceled-mark)
4602 (unless (memq article gnus-newsgroup-sparse)
16409b0b 4603 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
4604 (if (or (eq result 'pseudo)
4605 (eq result 'nneething))
eec82323 4606 (progn
80de1778 4607 (with-current-buffer summary-buffer
6748645f 4608 (push article gnus-newsgroup-history)
eec82323 4609 (setq gnus-last-article gnus-current-article
eec82323
LMI
4610 gnus-current-article 0
4611 gnus-current-headers nil
4612 gnus-article-current nil)
4613 (if (eq result 'nneething)
4614 (gnus-configure-windows 'summary)
4615 (gnus-configure-windows 'article))
4616 (gnus-set-global-variables))
16409b0b
GM
4617 (let ((gnus-article-mime-handle-alist-1
4618 gnus-article-mime-handle-alist))
4619 (gnus-set-mode-line 'article)))
eec82323
LMI
4620 ;; The result from the `request' was an actual article -
4621 ;; or at least some text that is now displayed in the
4622 ;; article buffer.
4623 (when (and (numberp article)
4624 (not (eq article gnus-current-article)))
4625 ;; Seems like a new article has been selected.
4626 ;; `gnus-current-article' must be an article number.
80de1778 4627 (with-current-buffer summary-buffer
6748645f 4628 (push article gnus-newsgroup-history)
eec82323 4629 (setq gnus-last-article gnus-current-article
eec82323
LMI
4630 gnus-current-article article
4631 gnus-current-headers
4632 (gnus-summary-article-header gnus-current-article)
4633 gnus-article-current
4634 (cons gnus-newsgroup-name gnus-current-article))
4635 (unless (vectorp gnus-current-headers)
4636 (setq gnus-current-headers nil))
6748645f
LMI
4637 (gnus-summary-goto-subject gnus-current-article)
4638 (when (gnus-summary-show-thread)
4639 ;; If the summary buffer really was folded, the
4640 ;; previous goto may not actually have gone to
4641 ;; the right article, but the thread root instead.
4642 ;; So we go again.
4643 (gnus-summary-goto-subject gnus-current-article))
4644 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
4645 (gnus-set-mode-line 'summary)
4646 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 4647 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 4648 ;; Set the global newsgroup variables here.
eec82323
LMI
4649 (gnus-set-global-variables)
4650 (setq gnus-have-all-headers
6748645f 4651 (or all-headers gnus-show-all-headers))))
e0bad764
DL
4652 (save-excursion
4653 (gnus-configure-windows 'article))
eec82323
LMI
4654 (when (or (numberp article)
4655 (stringp article))
16409b0b 4656 (gnus-article-prepare-display)
eec82323
LMI
4657 ;; Do page break.
4658 (goto-char (point-min))
23f87bed
MB
4659 (when gnus-break-pages
4660 (gnus-narrow-to-page)))
16409b0b
GM
4661 (let ((gnus-article-mime-handle-alist-1
4662 gnus-article-mime-handle-alist))
4663 (gnus-set-mode-line 'article))
4664 (article-goto-body)
23f87bed
MB
4665 (unless (bobp)
4666 (forward-line -1))
6748645f 4667 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 4668 (gnus-configure-windows 'article)
eec82323
LMI
4669 t))))))
4670
16409b0b
GM
4671;;;###autoload
4672(defun gnus-article-prepare-display ()
4673 "Make the current buffer look like a nice article."
4674 ;; Hooks for getting information from the article.
4675 ;; This hook must be called before being narrowed.
4676 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
4677 buffer-read-only
4678 (inhibit-read-only t))
16409b0b
GM
4679 (unless (eq major-mode 'gnus-article-mode)
4680 (gnus-article-mode))
4681 (setq buffer-read-only nil
23f87bed
MB
4682 gnus-article-wash-types nil
4683 gnus-article-image-alist nil)
16409b0b
GM
4684 (gnus-run-hooks 'gnus-tmp-internal-hook)
4685 (when gnus-display-mime-function
4686 (funcall gnus-display-mime-function))
4687 (gnus-run-hooks 'gnus-article-prepare-hook)))
4688
01c52d31
MB
4689;;;
4690;;; Gnus Sticky Article Mode
4691;;;
4692
4693(define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4694 "Mode for sticky articles."
4695 ;; Release bindings that won't work.
4696 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4697 gnus-sticky-article-mode-map)
4698 (substitute-key-definition 'gnus-article-refer-article 'undefined
4699 gnus-sticky-article-mode-map)
4700 (dolist (k '("e" "h" "s" "F" "R"))
4701 (define-key gnus-sticky-article-mode-map k nil))
4702 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4703 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4704 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4705 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4706
4707(defun gnus-sticky-article (arg)
4708 "Make the current article sticky.
4709If a prefix ARG is given, ask for a name for this sticky article buffer."
4710 (interactive "P")
4711 (gnus-summary-show-thread)
4712 (gnus-summary-select-article nil nil 'pseudo)
4713 (let (new-art-buf-name)
4714 (gnus-eval-in-buffer-window gnus-article-buffer
4715 (setq new-art-buf-name
4716 (concat
4717 "*Sticky Article: "
4718 (if arg
4719 (read-from-minibuffer "Sticky article buffer name: ")
4720 (gnus-with-article-headers
4721 (gnus-article-goto-header "subject")
4722 (setq new-art-buf-name
4723 (buffer-substring-no-properties
4724 (line-beginning-position) (line-end-position)))
4725 (goto-char (point-min))
4726 (gnus-article-goto-header "from")
4727 (setq new-art-buf-name
4728 (concat
4729 new-art-buf-name ", "
4730 (buffer-substring-no-properties
4731 (line-beginning-position) (line-end-position))))
4732 (goto-char (point-min))
4733 (gnus-article-goto-header "date")
4734 (setq new-art-buf-name
4735 (concat
4736 new-art-buf-name ", "
4737 (buffer-substring-no-properties
4738 (line-beginning-position) (line-end-position))))))
4739 "*"))
4740 (if (and (gnus-buffer-live-p new-art-buf-name)
4741 (with-current-buffer new-art-buf-name
4742 (eq major-mode 'gnus-sticky-article-mode)))
4743 (switch-to-buffer new-art-buf-name)
4744 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4745 (gnus-sticky-article-mode))
4746 (setq gnus-article-buffer new-art-buf-name))
4747 (gnus-summary-recenter)
4748 (gnus-summary-position-point))
4749
4750(defun gnus-kill-sticky-article-buffer (&optional buffer)
4751 "Kill the given sticky article BUFFER.
4752If none is given, assume the current buffer and kill it if it has
4753`gnus-sticky-article-mode'."
4754 (interactive)
4755 (unless buffer
4756 (setq buffer (current-buffer)))
4757 (with-current-buffer buffer
4758 (when (eq major-mode 'gnus-sticky-article-mode)
4759 (gnus-kill-buffer buffer))))
4760
4761(defun gnus-kill-sticky-article-buffers (arg)
4762 "Kill all sticky article buffers.
4763If a prefix ARG is given, ask for confirmation."
4764 (interactive "P")
4765 (dolist (buf (gnus-buffers))
4766 (with-current-buffer buf
4767 (when (eq major-mode 'gnus-sticky-article-mode)
4768 (if (not arg)
4769 (gnus-kill-buffer buf)
4770 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4771 (gnus-kill-buffer buf)))))))
4772
16409b0b
GM
4773;;;
4774;;; Gnus MIME viewing functions
4775;;;
4776
4777(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
4778 "Format of the MIME buttons.
4779
4780Valid specifiers include:
16409b0b
GM
4781%t The MIME type
4782%T MIME type, along with additional info
4783%n The `name' parameter
4784%d The description, if any
4785%l The length of the encoded part
4786%p The part identifier number
23f87bed
MB
4787%e Dots if the part isn't displayed
4788
4789General format specifiers can also be used. See Info node
4790`(gnus)Formatting Variables'.")
16409b0b
GM
4791
4792(defvar gnus-mime-button-line-format-alist
4793 '((?t gnus-tmp-type ?s)
4794 (?T gnus-tmp-type-long ?s)
4795 (?n gnus-tmp-name ?s)
4796 (?d gnus-tmp-description ?s)
4797 (?p gnus-tmp-id ?s)
4798 (?l gnus-tmp-length ?d)
4799 (?e gnus-tmp-dots ?s)))
4800
4801(defvar gnus-mime-button-commands
4802 '((gnus-article-press-button "\r" "Toggle Display")
4803 (gnus-mime-view-part "v" "View Interactively...")
4804 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4805 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4806 (gnus-mime-save-part "o" "Save...")
23f87bed 4807 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
01c52d31 4808 (gnus-mime-replace-part "r" "Replace part")
23f87bed 4809 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4810 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4811 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
01c52d31 4812 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
23f87bed
MB
4813 (gnus-mime-view-part-externally "e" "View Externally")
4814 (gnus-mime-print-part "p" "Print")
e0bad764 4815 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4816 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4817
4818(defun gnus-article-mime-part-status ()
4819 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4820 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4821 " (1 part)"
4822 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4823 ""))
4824
4825(defvar gnus-mime-button-map
4826 (let ((map (make-sparse-keymap)))
16409b0b
GM
4827 (define-key map gnus-mouse-2 'gnus-article-push-button)
4828 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4829 (dolist (c gnus-mime-button-commands)
4830 (define-key map (cadr c) (car c)))
4831 map))
4832
23f87bed
MB
4833(easy-menu-define
4834 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4835 `("MIME Part"
4836 ,@(mapcar (lambda (c)
01c52d31 4837 (vector (caddr c) (car c) :active t))
23f87bed
MB
4838 gnus-mime-button-commands)))
4839
7426b4f7
LMI
4840(defvar gnus-url-button-commands
4841 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4842
4843(defvar gnus-url-button-map
4844 (let ((map (make-sparse-keymap)))
4845 (dolist (c gnus-url-button-commands)
4846 (define-key map (cadr c) (car c)))
4847 map))
4848
4849(easy-menu-define
4850 gnus-url-button-menu gnus-url-button-map "URL button menu."
4851 `("Url Button"
4852 ,@(mapcar (lambda (c)
4853 (vector (caddr c) (car c) :active t))
4854 gnus-url-button-commands)))
4855
b0b63450
MB
4856(defmacro gnus-bind-safe-url-regexp (&rest body)
4857 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4858 `(let ((mm-w3m-safe-url-regexp
4859 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4860 (gnus-buffer-live-p
4861 gnus-article-current-summary))
4862 (with-current-buffer gnus-article-current-summary
4863 gnus-newsgroup-name)
4864 gnus-newsgroup-name)))
7cab80f9
KY
4865 (if (cond ((not group)
4866 ;; Maybe we're in a mml-preview buffer
4867 ;; and no group is selected.
4868 t)
4869 ((stringp gnus-safe-html-newsgroups)
b0b63450
MB
4870 (string-match gnus-safe-html-newsgroups group))
4871 ((consp gnus-safe-html-newsgroups)
4872 (member group gnus-safe-html-newsgroups)))
4873 nil
4874 mm-w3m-safe-url-regexp))))
4875 ,@body))
4876
23f87bed
MB
4877(defun gnus-mime-button-menu (event prefix)
4878 "Construct a context-sensitive menu of MIME commands."
4879 (interactive "e\nP")
4880 (save-window-excursion
4881 (let ((pos (event-start event)))
4882 (select-window (posn-window pos))
4883 (goto-char (posn-point pos))
4884 (gnus-article-check-buffer)
4885 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4886
4887(defun gnus-mime-view-all-parts (&optional handles)
4888 "View all the MIME parts."
4889 (interactive)
01c52d31 4890 (with-current-buffer gnus-article-buffer
16409b0b
GM
4891 (let ((handles (or handles gnus-article-mime-handles))
4892 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4893 (mail-parse-ignored-charsets
23f87bed
MB
4894 (with-current-buffer gnus-summary-buffer
4895 gnus-newsgroup-ignored-charsets)))
4896 (when handles
4897 (mm-remove-parts handles)
4898 (goto-char (point-min))
4899 (or (search-forward "\n\n") (goto-char (point-max)))
4900 (let ((inhibit-read-only t))
4901 (delete-region (point) (point-max))
b0b63450 4902 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
23f87bed 4903
01c52d31
MB
4904(defun gnus-article-jump-to-part (n)
4905 "Jump to MIME part N."
4906 (interactive "P")
4907 (pop-to-buffer gnus-article-buffer)
4908 ;; FIXME: why is it necessary?
4909 (sit-for 0)
4910 (let ((parts (length gnus-article-mime-handle-alist)))
5843126b 4911 (or n (setq n (read-number (format "Jump to part (2..%s): " parts))))
01c52d31
MB
4912 (unless (and (integerp n) (<= n parts) (>= n 1))
4913 (setq n
4914 (progn
4915 (gnus-message 7 "Invalid part `%s', using %s instead."
4916 n parts)
4917 parts)))
4918 (gnus-message 9 "Jumping to part %s." n)
4919 (cond ((>= gnus-auto-select-part 1)
4920 (while (and (<= n parts)
4921 (not (gnus-article-goto-part n)))
4922 (setq n (1+ n))))
4923 ((< gnus-auto-select-part 0)
4924 (while (and (>= n 1)
4925 (not (gnus-article-goto-part n)))
4926 (setq n (1- n))))
4927 (t
4928 (gnus-article-goto-part n)))))
4929
3e3ab3ab
KY
4930(defvar gnus-mime-buttonized-part-id nil
4931 "ID of a mime part that should be buttonized.
4932`gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4933
01c52d31
MB
4934(eval-when-compile
4935 (defsubst gnus-article-edit-part (handles &optional current-id)
4936 "Edit an article in order to delete a mime part.
4937This function is exclusively used by `gnus-mime-save-part-and-strip'
4938and `gnus-mime-delete-part', and not provided at run-time normally."
4939 (gnus-article-edit-article
4940 `(lambda ()
4941 (buffer-disable-undo)
4942 (erase-buffer)
4943 (let ((mail-parse-charset (or gnus-article-charset
4944 ',gnus-newsgroup-charset))
4945 (mail-parse-ignored-charsets
4946 (or gnus-article-ignored-charsets
4947 ',gnus-newsgroup-ignored-charsets))
4948 (mbl mml-buffer-list))
4949 (setq mml-buffer-list nil)
4950 (insert-buffer-substring gnus-original-article-buffer)
4951 (mime-to-mml ',handles)
4952 (setq gnus-article-mime-handles nil)
4953 (let ((mbl1 mml-buffer-list))
4954 (setq mml-buffer-list mbl)
4955 (set (make-local-variable 'mml-buffer-list) mbl1))
4956 (gnus-make-local-hook 'kill-buffer-hook)
4957 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4958 `(lambda (no-highlight)
4959 (let ((mail-parse-charset (or gnus-article-charset
4960 ',gnus-newsgroup-charset))
4961 (message-options message-options)
4962 (message-options-set-recipient)
4963 (mail-parse-ignored-charsets
4964 (or gnus-article-ignored-charsets
4965 ',gnus-newsgroup-ignored-charsets)))
4966 (mml-to-mime)
4967 (mml-destroy-buffers)
4968 (remove-hook 'kill-buffer-hook
4969 'mml-destroy-buffers t)
4970 (kill-local-variable 'mml-buffer-list))
4971 (gnus-summary-edit-article-done
4972 ,(or (mail-header-references gnus-current-headers) "")
4973 ,(gnus-group-read-only-p)
4974 ,gnus-summary-buffer no-highlight))
4975 t)
3e3ab3ab
KY
4976 ;; Force buttonizing this part.
4977 (let ((gnus-mime-buttonized-part-id current-id))
4978 (gnus-article-edit-done))
54c72c31 4979 (gnus-configure-windows 'article)
01c52d31 4980 (when (and current-id (integerp gnus-auto-select-part))
3e3ab3ab
KY
4981 (gnus-article-jump-to-part
4982 (min (max (+ current-id gnus-auto-select-part) 1)
4983 (with-current-buffer gnus-article-buffer
4984 (length gnus-article-mime-handle-alist)))))))
01c52d31
MB
4985
4986(defun gnus-mime-replace-part (file)
4987 "Replace MIME part under point with an external body."
4988 ;; Useful if file has already been saved to disk
4989 (interactive
4990 (list
75eda25b
SM
4991 (read-file-name "Replace MIME part with file: "
4992 (or mm-default-directory default-directory)
4993 nil nil)))
01c52d31
MB
4994 (gnus-mime-save-part-and-strip file))
4995
4996(defun gnus-mime-save-part-and-strip (&optional file)
4997 "Save the MIME part under point then replace it with an external body.
4998If FILE is given, use it for the external part."
23f87bed
MB
4999 (interactive)
5000 (gnus-article-check-buffer)
5001 (when (gnus-group-read-only-p)
5002 (error "The current group does not support deleting of parts"))
5003 (when (mm-complicated-handles gnus-article-mime-handles)
5004 (error "\
5005The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
5006 (let* ((data (get-text-property (point) 'gnus-data))
5007 (id (get-text-property (point) 'gnus-part))
5008 param
5009 (handles gnus-article-mime-handles))
5010 (unless file
5011 (setq file
5012 (and data (mm-save-part data "Delete MIME part and save to: "))))
5013 (when file
5014 (with-current-buffer (mm-handle-buffer data)
5015 (erase-buffer)
5016 (insert "Content-Type: " (mm-handle-media-type data))
5017 (mml-insert-parameter-string (cdr (mm-handle-type data))
5018 '(charset))
5019 ;; Add a filename for the sake of saving the part again.
5020 (mml-insert-parameter
5021 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5022 (insert "\n")
5023 (insert "Content-ID: " (message-make-message-id) "\n")
5024 (insert "Content-Transfer-Encoding: binary\n")
5025 (insert "\n"))
5026 (setcdr data
5027 (cdr (mm-make-handle nil
5028 `("message/external-body"
5029 (access-type . "LOCAL-FILE")
5030 (name . ,file)))))
5031 ;; (set-buffer gnus-summary-buffer)
5032 (gnus-article-edit-part handles id))))
5033
5034;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5035;; parts...>') but with stripping would be nice.
23f87bed
MB
5036
5037(defun gnus-mime-delete-part ()
5038 "Delete the MIME part under point.
5039Replace it with some information about the removed part."
5040 (interactive)
5041 (gnus-article-check-buffer)
5042 (when (gnus-group-read-only-p)
5043 (error "The current group does not support deleting of parts"))
5044 (when (mm-complicated-handles gnus-article-mime-handles)
5045 (error "\
5046The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
5047 (when (or gnus-expert-user
5048 (gnus-yes-or-no-p "\
5049Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 5050 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 5051 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
5052 (handles gnus-article-mime-handles)
5053 (none "(none)")
5054 (description
bbbe940b
MB
5055 (let ((desc (mm-handle-description data)))
5056 (when desc
5057 (mail-decode-encoded-word-string desc))))
23f87bed
MB
5058 (filename
5059 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5060 none))
5061 (type (mm-handle-media-type data)))
5062 (unless data
5063 (error "No MIME part under point"))
5064 (with-current-buffer (mm-handle-buffer data)
e5fa3899 5065 (let ((bsize (buffer-size)))
23f87bed
MB
5066 (erase-buffer)
5067 (insert
5068 (concat
5069 ",----\n"
5070 "| The following attachment has been deleted:\n"
5071 "|\n"
5072 "| Type: " type "\n"
5073 "| Filename: " filename "\n"
e5fa3899
KY
5074 "| Size (encoded): " (format "%s byte%s\n"
5075 bsize (if (= bsize 1)
8ccbef23
G
5076 ""
5077 "s"))
bbbe940b
MB
5078 (when description
5079 (concat "| Description: " description "\n"))
23f87bed
MB
5080 "`----\n"))
5081 (setcdr data
5082 (cdr (mm-make-handle
0cf681b6 5083 nil `("text/plain" (charset . gnus-decoded)) nil nil
23f87bed
MB
5084 (list "attachment")
5085 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
5086 ;; (set-buffer gnus-summary-buffer)
5087 (gnus-article-edit-part handles id))))
16409b0b
GM
5088
5089(defun gnus-mime-save-part ()
5090 "Save the MIME part under point."
5091 (interactive)
5092 (gnus-article-check-buffer)
5093 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5094 (when data
5095 (mm-save-part data))))
16409b0b 5096
9581ba4d
KY
5097(defun gnus-mime-pipe-part (&optional cmd)
5098 "Pipe the MIME part under point to a process.
5099Use CMD as the process."
16409b0b
GM
5100 (interactive)
5101 (gnus-article-check-buffer)
5102 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed 5103 (when data
9581ba4d 5104 (mm-pipe-part data cmd))))
16409b0b
GM
5105
5106(defun gnus-mime-view-part ()
5107 "Interactively choose a viewing method for the MIME part under point."
5108 (interactive)
5109 (gnus-article-check-buffer)
5110 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
5111 (when data
5112 (setq gnus-article-mime-handles
5113 (mm-merge-handles
5114 gnus-article-mime-handles (setq data (copy-sequence data))))
5115 (mm-interactively-view-part data))))
16409b0b
GM
5116
5117(defun gnus-mime-view-part-as-type-internal ()
5118 (gnus-article-check-buffer)
54e573e6
MB
5119 (let* ((handle (get-text-property (point) 'gnus-data))
5120 (name (or
5121 ;; Content-Type: foo/bar; name=...
5122 (mail-content-type-get (mm-handle-type handle) 'name)
5123 ;; Content-Disposition: attachment; filename=...
5124 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 5125 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
5126 (or (and def-type (cons def-type 0))
5127 (and handle
5128 (equal (mm-handle-media-supertype handle) "text")
5129 '("text/plain" . 0))
5130 '("application/octet-stream" . 0))))
16409b0b 5131
54e573e6
MB
5132(defun gnus-mime-view-part-as-type (&optional mime-type pred)
5133 "Choose a MIME media type, and view the part as such.
5134If non-nil, PRED is a predicate to use during completion to limit the
5135available media-types."
23f87bed
MB
5136 (interactive)
5137 (unless mime-type
54e573e6
MB
5138 (setq mime-type
5139 (let ((default (gnus-mime-view-part-as-type-internal)))
229b59da
G
5140 (gnus-completing-read
5141 "View as MIME type"
568f71a8
KY
5142 (if pred
5143 (gnus-remove-if-not pred (mailcap-mime-types))
5144 (mailcap-mime-types))
229b59da 5145 nil nil nil
54e573e6 5146 (car default)))))
16409b0b
GM
5147 (gnus-article-check-buffer)
5148 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 5149 (when handle
531bedc3
MB
5150 (when (equal (mm-handle-media-type handle) "message/external-body")
5151 (unless (mm-handle-cache handle)
5152 (mm-extern-cache-contents handle))
5153 (setq handle (mm-handle-cache handle)))
23f87bed
MB
5154 (setq handle
5155 (mm-make-handle (mm-handle-buffer handle)
5156 (cons mime-type (cdr (mm-handle-type handle)))
5157 (mm-handle-encoding handle)
5158 (mm-handle-undisplayer handle)
5159 (mm-handle-disposition handle)
5160 (mm-handle-description handle)
5161 nil
5162 (mm-handle-id handle)))
5163 (setq gnus-article-mime-handles
5164 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
5165 (when (mm-handle-displayed-p handle)
5166 (mm-remove-part handle))
23f87bed
MB
5167 (gnus-mm-display-part handle))))
5168
01c52d31 5169(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
5170 "Put the MIME part under point into a new buffer.
5171If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5172are decompressed."
01c52d31 5173 (interactive (list nil current-prefix-arg))
16409b0b 5174 (gnus-article-check-buffer)
01c52d31
MB
5175 (unless handle
5176 (setq handle (get-text-property (point) 'gnus-data)))
5177 (when handle
5178 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5179 'name)
5180 (mail-content-type-get (mm-handle-disposition handle)
5181 'filename)))
5182 contents dont-decode charset coding-system)
5183 (mm-with-unibyte-buffer
5184 (mm-insert-part handle)
5185 (setq contents (or (condition-case nil
5186 (mm-decompress-buffer filename nil 'sig)
5187 (error
5188 (setq dont-decode t)
5189 nil))
5190 (buffer-string))))
5191 (setq filename (cond (filename (file-name-nondirectory filename))
5192 (dont-decode "*raw data*")
5193 (t "*decoded*")))
5194 (cond
5195 (dont-decode)
5196 ((not arg)
5197 (unless (setq charset (mail-content-type-get
5198 (mm-handle-type handle) 'charset))
5199 (unless (setq coding-system (mm-with-unibyte-buffer
5200 (insert contents)
5201 (mm-find-buffer-file-coding-system)))
5202 (setq charset gnus-newsgroup-charset))))
5203 ((numberp arg)
5204 (setq charset (or (cdr (assq arg
5205 gnus-summary-show-article-charset-alist))
5206 (mm-read-coding-system "Charset: ")))))
5207 (switch-to-buffer (generate-new-buffer filename))
5208 (if (or coding-system
5209 (and charset
5210 (setq coding-system (mm-charset-to-coding-system charset))
5211 (not (eq charset 'ascii))))
5212 (progn
5213 (mm-enable-multibyte)
5214 (insert (mm-decode-coding-string contents coding-system))
5215 (setq buffer-file-coding-system
5216 (if (boundp 'last-coding-system-used)
5217 (symbol-value 'last-coding-system-used)
5218 coding-system)))
5219 (mm-disable-multibyte)
5220 (insert contents)
5221 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5222 ;; We do it this way to make `normal-mode' set the appropriate mode.
5223 (unwind-protect
5224 (progn
01c52d31 5225 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5226 (normal-mode))
5227 (setq buffer-file-name nil))
5228 (goto-char (point-min)))))
5229
5230(defun gnus-mime-print-part (&optional handle filename)
5231 "Print the MIME part under point."
5232 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5233 (gnus-article-check-buffer)
5234 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5235 (contents (and handle (mm-get-part handle)))
5236 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5237 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5238 (when contents
5239 (if printer
5240 (unwind-protect
5241 (progn
5242 (mm-save-part-to-file handle file)
5243 (call-process shell-file-name nil
5244 (generate-new-buffer " *mm*")
5245 nil
5246 shell-command-switch
5247 (mm-mailcap-command
5248 printer file (mm-handle-type handle))))
5249 (delete-file file))
5250 (with-temp-buffer
5251 (insert contents)
5252 (gnus-print-buffer))
5253 (ps-despool filename)))))
16409b0b 5254
e0bad764 5255(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5256 "Insert the MIME part under point into the current buffer.
5257Compressed files like .gz and .bz2 are decompressed."
e0bad764 5258 (interactive (list nil current-prefix-arg))
16409b0b 5259 (gnus-article-check-buffer)
01c52d31
MB
5260 (unless handle
5261 (setq handle (get-text-property (point) 'gnus-data)))
5262 (when handle
5263 (let ((b (point))
5264 (inhibit-read-only t)
5265 contents charset coding-system)
23f87bed
MB
5266 (if (and (not arg) (mm-handle-undisplayer handle))
5267 (mm-remove-part handle)
01c52d31
MB
5268 (mm-with-unibyte-buffer
5269 (mm-insert-part handle)
5270 (setq contents
5271 (or (mm-decompress-buffer
5272 (or (mail-content-type-get (mm-handle-type handle)
5273 'name)
5274 (mail-content-type-get (mm-handle-disposition handle)
5275 'filename))
5276 nil t)
5277 (buffer-string))))
23f87bed
MB
5278 (cond
5279 ((not arg)
01c52d31
MB
5280 (unless (setq charset (mail-content-type-get
5281 (mm-handle-type handle) 'charset))
5282 (unless (setq coding-system
5283 (mm-with-unibyte-buffer
5284 (insert contents)
5285 (mm-find-buffer-file-coding-system)))
5286 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5287 ((numberp arg)
5288 (if (mm-handle-undisplayer handle)
5289 (mm-remove-part handle))
5290 (setq charset
5291 (or (cdr (assq arg
5292 gnus-summary-show-article-charset-alist))
56c30d72
MB
5293 (mm-read-coding-system "Charset: "))))
5294 (t
5295 (if (mm-handle-undisplayer handle)
850c333d 5296 (mm-remove-part handle))))
23f87bed 5297 (forward-line 2)
850c333d
MB
5298 (mm-insert-inline
5299 handle
01c52d31
MB
5300 (if (or coding-system
5301 (and charset
5302 (setq coding-system
5303 (mm-charset-to-coding-system charset))
5304 (not (eq coding-system 'ascii))))
5305 (mm-decode-coding-string contents coding-system)
850c333d 5306 (mm-string-to-multibyte contents)))
23f87bed
MB
5307 (goto-char b)))))
5308
c0ccb0d6
KY
5309(defun gnus-mime-set-charset-parameters (handle charset)
5310 "Set CHARSET to parameters in HANDLE.
5311CHARSET may either be a string or a symbol."
5312 (unless (stringp charset)
5313 (setq charset (symbol-name charset)))
6b554e88 5314 (if (stringp (car handle))
c0ccb0d6
KY
5315 (dolist (h (cdr handle))
5316 (gnus-mime-set-charset-parameters h charset))
6b554e88
MB
5317 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5318 "message/external-body")
5319 (progn
5320 (unless (mm-handle-cache handle)
5321 (mm-extern-cache-contents handle))
5322 (mm-handle-cache handle))
5323 handle)))
c0ccb0d6
KY
5324 (param (assq 'charset (cdr type))))
5325 (if param
5326 (setcdr param charset)
5327 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
6b554e88 5328
23f87bed
MB
5329(defun gnus-mime-view-part-as-charset (&optional handle arg)
5330 "Insert the MIME part under point into the current buffer using the
5331specified charset."
5332 (interactive (list nil current-prefix-arg))
5333 (gnus-article-check-buffer)
163cb72d
MB
5334 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5335 (fun (get-text-property (point) 'gnus-callback))
5336 (gnus-newsgroup-ignored-charsets 'gnus-all)
c0ccb0d6 5337 charset form preferred parts)
23f87bed 5338 (when handle
01c52d31
MB
5339 (when (prog1
5340 (and fun
c0ccb0d6 5341 (setq charset
01c52d31
MB
5342 (or (cdr (assq
5343 arg
5344 gnus-summary-show-article-charset-alist))
5345 (mm-read-coding-system "Charset: "))))
5346 (if (mm-handle-undisplayer handle)
5347 (mm-remove-part handle)))
c0ccb0d6 5348 (gnus-mime-set-charset-parameters handle charset)
6b554e88
MB
5349 (when (and (consp (setq form (cdr-safe fun)))
5350 (setq form (ignore-errors
5351 (assq 'gnus-mime-display-alternative form)))
5352 (setq preferred (caddr form))
5353 (progn
5354 (when (eq (car preferred) 'quote)
5355 (setq preferred (cadr preferred)))
5356 (not (equal preferred
5357 (get-text-property (point) 'gnus-data))))
5358 (setq parts (get-text-property (point) 'gnus-part))
5359 (setq parts (cdr (assq parts
5360 gnus-article-mime-handle-alist)))
5361 (equal (mm-handle-media-type parts) "multipart/alternative")
5362 (setq parts (reverse (cdr parts))))
5363 (setcar (cddr form)
5364 (list 'quote (or (cadr (member preferred parts))
5365 (car parts)))))
163cb72d 5366 (funcall fun handle)))))
23f87bed
MB
5367
5368(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5369 "View the MIME part under point with an external viewer."
5370 (interactive)
5371 (gnus-article-check-buffer)
5372 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5373 (mm-user-display-methods nil)
5374 (mm-inlined-types nil)
5375 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5376 (mail-parse-ignored-charsets
54e573e6
MB
5377 (with-current-buffer gnus-summary-buffer
5378 gnus-newsgroup-ignored-charsets))
5379 (type (mm-handle-media-type handle))
5380 (method (mailcap-mime-info type))
5381 (mm-enable-external t))
5382 (if (not (stringp method))
5383 (gnus-mime-view-part-as-type
f7aa0b8f 5384 nil (lambda (type) (stringp (mailcap-mime-info type))))
54e573e6
MB
5385 (when handle
5386 (if (mm-handle-undisplayer handle)
5387 (mm-remove-part handle)
5388 (mm-display-part handle))))))
16409b0b 5389
23f87bed 5390(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5391 "View the MIME part under point with an internal viewer.
23f87bed 5392If no internal viewer is available, use an external viewer."
16409b0b
GM
5393 (interactive)
5394 (gnus-article-check-buffer)
5395 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5396 (mm-inlined-types '(".*"))
5397 (mm-inline-large-images t)
5398 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5399 (mail-parse-ignored-charsets
54e573e6
MB
5400 (with-current-buffer gnus-summary-buffer
5401 gnus-newsgroup-ignored-charsets))
23f87bed 5402 (inhibit-read-only t))
54e573e6
MB
5403 (if (not (mm-inlinable-p handle))
5404 (gnus-mime-view-part-as-type
f7aa0b8f 5405 nil (lambda (type) (mm-inlinable-p handle type)))
54e573e6
MB
5406 (when handle
5407 (if (mm-handle-undisplayer handle)
5408 (mm-remove-part handle)
b0b63450 5409 (gnus-bind-safe-url-regexp (mm-display-part handle)))))))
16409b0b 5410
e0bad764
DL
5411(defun gnus-mime-action-on-part (&optional action)
5412 "Do something with the MIME attachment at \(point\)."
5413 (interactive
229b59da 5414 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
e0bad764
DL
5415 (gnus-article-check-buffer)
5416 (let ((action-pair (assoc action gnus-mime-action-alist)))
5417 (if action-pair
5418 (funcall (cdr action-pair)))))
5419
01c52d31
MB
5420(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5421 "Call FUNCTION on MIME part N.
5422Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5423If INTERACTIVE, call FUNCTION interactivly."
5424 (let (window frame)
5425 ;; Check whether the article is displayed.
5426 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5427 (setq window (get-buffer-window gnus-article-buffer t))
5428 (frame-visible-p (setq frame (window-frame window))))
5429 (error "No article is displayed"))
5430 (with-current-buffer gnus-article-buffer
5431 ;; Check whether the article displays the right contents.
5432 (unless (with-current-buffer gnus-summary-buffer
5433 (eq gnus-current-article (gnus-summary-article-number)))
5434 (error "You should select the right article first"))
5435 (if n
5436 (setq n (prefix-numeric-value n))
5437 (let ((pt (point)))
5438 (setq n (or (get-text-property pt 'gnus-part)
5439 (and (not (bobp))
5440 (get-text-property (1- pt) 'gnus-part))
5441 (get-text-property (prog2
5442 (forward-line 1)
5443 (point)
5444 (goto-char pt))
5445 'gnus-part)
5446 (get-text-property
5447 (or (and (setq pt (previous-single-property-change
5448 pt 'gnus-part))
5449 (1- pt))
5450 (next-single-property-change (point) 'gnus-part)
5451 (point))
5452 'gnus-part)
5453 1))))
5454 ;; Check whether the specified part exists.
5455 (when (> n (length gnus-article-mime-handle-alist))
5456 (error "No such part")))
5457 (unless
5458 (progn
5459 ;; To select the window is needed so that the cursor
5460 ;; might be visible on the MIME button.
5461 (select-window (prog1
5462 window
5463 (setq window (selected-window))
5464 ;; Article may be displayed in the other frame.
5465 (gnus-select-frame-set-input-focus
5466 (prog1
5467 frame
5468 (setq frame (selected-frame))))))
5469 (when (gnus-article-goto-part n)
5470 ;; We point the cursor and the arrow at the MIME button
5471 ;; when the `function' prompt the user for something.
5472 (let ((cursor-in-non-selected-windows t)
5473 (overlay-arrow-string "=>")
5474 (overlay-arrow-position (point-marker)))
5475 (unwind-protect
5476 (cond
5477 ((and no-handle interactive)
5478 (call-interactively function))
5479 (no-handle
5480 (funcall function))
5481 (interactive
5482 (call-interactively
5483 function
5484 (cdr (assq n gnus-article-mime-handle-alist))))
5485 (t
5486 (funcall function
5487 (cdr (assq n gnus-article-mime-handle-alist)))))
5488 (set-marker overlay-arrow-position nil)
5489 (unless gnus-auto-select-part
5490 (gnus-select-frame-set-input-focus frame)
5491 (select-window window))))
5492 t))
5493 (if gnus-inhibit-mime-unbuttonizing
5494 ;; This is the default though the program shouldn't reach here.
5495 (error "No such part")
5496 ;; The part which doesn't have the MIME button is selected.
5497 ;; So, we display all the buttons and redo it.
5498 (let ((gnus-inhibit-mime-unbuttonizing t))
5499 (gnus-summary-show-article)
5500 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5501
5502(defun gnus-article-pipe-part (n)
5503 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5504 (interactive "P")
16409b0b
GM
5505 (gnus-article-part-wrapper n 'mm-pipe-part))
5506
5507(defun gnus-article-save-part (n)
5508 "Save MIME part N, which is the numerical prefix."
01c52d31 5509 (interactive "P")
16409b0b
GM
5510 (gnus-article-part-wrapper n 'mm-save-part))
5511
5512(defun gnus-article-interactively-view-part (n)
5513 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5514 (interactive "P")
16409b0b
GM
5515 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5516
5517(defun gnus-article-copy-part (n)
5518 "Copy MIME part N, which is the numerical prefix."
01c52d31 5519 (interactive "P")
16409b0b
GM
5520 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5521
23f87bed
MB
5522(defun gnus-article-view-part-as-charset (n)
5523 "View MIME part N using a specified charset.
5524N is the numerical prefix."
01c52d31 5525 (interactive "P")
23f87bed
MB
5526 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5527
5528(defun gnus-article-view-part-externally (n)
16409b0b 5529 "View MIME part N externally, which is the numerical prefix."
01c52d31 5530 (interactive "P")
23f87bed 5531 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5532
5533(defun gnus-article-inline-part (n)
5534 "Inline MIME part N, which is the numerical prefix."
01c52d31 5535 (interactive "P")
16409b0b
GM
5536 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5537
01c52d31
MB
5538(defun gnus-article-save-part-and-strip (n)
5539 "Save MIME part N and replace it with an external body.
5540N is the numerical prefix."
5541 (interactive "P")
5542 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5543
5544(defun gnus-article-replace-part (n)
5545 "Replace MIME part N with an external body.
5546N is the numerical prefix."
5547 (interactive "P")
5548 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5549
5550(defun gnus-article-delete-part (n)
5551 "Delete MIME part N and add some information about the removed part.
5552N is the numerical prefix."
5553 (interactive "P")
5554 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5555
5556(defun gnus-article-view-part-as-type (n)
5557 "Choose a MIME media type, and view part N as such.
5558N is the numerical prefix."
5559 (interactive "P")
5560 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5561
16409b0b
GM
5562(defun gnus-article-mime-match-handle-first (condition)
5563 (if condition
01c52d31
MB
5564 (let (n)
5565 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5566 (if (and (cond
16409b0b
GM
5567 ((functionp condition)
5568 (funcall condition (cdr ihandle)))
a1506d29 5569 ((eq condition 'undisplayed)
16409b0b
GM
5570 (not (or (mm-handle-undisplayer (cdr ihandle))
5571 (equal (mm-handle-media-type (cdr ihandle))
5572 "multipart/alternative"))))
5573 ((eq condition 'undisplayed-alternative)
5574 (not (mm-handle-undisplayer (cdr ihandle))))
5575 (t t))
5576 (gnus-article-goto-part (car ihandle))
5577 (or (not n) (< (car ihandle) n)))
5578 (setq n (car ihandle))))
5579 (or n 1))
5580 1))
5581
5582(defun gnus-article-view-part (&optional n)
47fe149b
KY
5583 "View MIME part N, which is the numerical prefix.
5584If the part is already shown, hide the part. If N is nil, view
5585all parts."
16409b0b 5586 (interactive "P")
01c52d31 5587 (with-current-buffer gnus-article-buffer
a1506d29 5588 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5589 gnus-article-mime-match-handle-function)))
5590 (when (> n (length gnus-article-mime-handle-alist))
5591 (error "No such part"))
5592 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5593 (when (gnus-article-goto-part n)
5594 (if (equal (car handle) "multipart/alternative")
5595 (gnus-article-press-button)
5596 (when (eq (gnus-mm-display-part handle) 'internal)
5597 (gnus-set-window-start)))))))
5598
e0bad764
DL
5599(defsubst gnus-article-mime-total-parts ()
5600 (if (bufferp (car gnus-article-mime-handles))
5601 1 ;; single part
5602 (1- (length gnus-article-mime-handles))))
5603
16409b0b
GM
5604(defun gnus-mm-display-part (handle)
5605 "Display HANDLE and fix MIME button."
5606 (let ((id (get-text-property (point) 'gnus-part))
5607 (point (point))
23f87bed 5608 (inhibit-read-only t))
16409b0b
GM
5609 (forward-line 1)
5610 (prog1
5611 (let ((window (selected-window))
5612 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5613 (mail-parse-ignored-charsets
23f87bed 5614 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5615 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5616 gnus-newsgroup-ignored-charsets)
5617 nil)))
16409b0b
GM
5618 (save-excursion
5619 (unwind-protect
23f87bed 5620 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5621 (beg (point)))
5622 (when win
5623 (select-window win))
5624 (goto-char point)
5625 (forward-line)
5626 (if (mm-handle-displayed-p handle)
5627 ;; This will remove the part.
5628 (mm-display-part handle)
5629 (save-restriction
23f87bed
MB
5630 (narrow-to-region (point)
5631 (if (eobp) (point) (1+ (point))))
b0b63450 5632 (gnus-bind-safe-url-regexp (mm-display-part handle))
16409b0b
GM
5633 ;; We narrow to the part itself and
5634 ;; then call the treatment functions.
5635 (goto-char (point-min))
5636 (forward-line 1)
5637 (narrow-to-region (point) (point-max))
5638 (gnus-treat-article
5639 nil id
e0bad764 5640 (gnus-article-mime-total-parts)
16409b0b 5641 (mm-handle-media-type handle)))))
23f87bed
MB
5642 (if (window-live-p window)
5643 (select-window window)))))
16409b0b 5644 (goto-char point)
23f87bed 5645 (gnus-delete-line)
16409b0b
GM
5646 (gnus-insert-mime-button
5647 handle id (list (mm-handle-displayed-p handle)))
5648 (goto-char point))))
5649
5650(defun gnus-article-goto-part (n)
5651 "Go to MIME part N."
23f87bed 5652 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
5653
5654(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5655 (let ((gnus-tmp-name
23f87bed
MB
5656 (or (mail-content-type-get (mm-handle-type handle) 'name)
5657 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5658 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5659 ""))
5660 (gnus-tmp-type (mm-handle-media-type handle))
4599d0ec 5661 (gnus-tmp-description (or (mm-handle-description handle) ""))
16409b0b
GM
5662 (gnus-tmp-dots
5663 (if (if displayed (car displayed)
5664 (mm-handle-displayed-p handle))
5665 "" "..."))
5666 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5667 (buffer-size)))
5668 gnus-tmp-type-long b e)
5669 (when (string-match ".*/" gnus-tmp-name)
5670 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5671 (setq gnus-tmp-type-long (concat gnus-tmp-type
5672 (and (not (equal gnus-tmp-name ""))
5673 (concat "; " gnus-tmp-name))))
23f87bed
MB
5674 (unless (equal gnus-tmp-description "")
5675 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5676 (unless (bolp)
5677 (insert "\n"))
5678 (setq b (point))
5679 (gnus-eval-format
5680 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5681 `(keymap ,gnus-mime-button-map
5682 gnus-callback gnus-mm-display-part
5683 gnus-part ,gnus-tmp-id
5684 article-type annotation
5685 gnus-data ,handle))
23f87bed
MB
5686 (setq e (if (bolp)
5687 ;; Exclude a newline.
5688 (1- (point))
5689 (point)))
01c52d31
MB
5690 (when gnus-article-button-face
5691 (gnus-overlay-put (gnus-make-overlay b e nil t)
5692 'face gnus-article-button-face))
16409b0b
GM
5693 (widget-convert-button
5694 'link b e
5695 :mime-handle handle
5696 :action 'gnus-widget-press-button
5697 :button-keymap gnus-mime-button-map
5698 :help-echo
5843126b 5699 (lambda (widget)
16409b0b
GM
5700 ;; Needed to properly clear the message due to a bug in
5701 ;; wid-edit (XEmacs only).
5702 (if (boundp 'help-echo-owns-message)
5703 (setq help-echo-owns-message t))
5704 (format
5705 "%S: %s the MIME part; %S: more options"
5706 (aref gnus-mouse-2 0)
5843126b 5707 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
16409b0b
GM
5708 "hide" "show")
5709 (aref gnus-down-mouse-3 0))))))
5710
5711(defun gnus-widget-press-button (elems el)
5712 (goto-char (widget-get elems :from))
5713 (gnus-article-press-button))
5714
5715(defvar gnus-displaying-mime nil)
5716
5717(defun gnus-display-mime (&optional ihandles)
5718 "Display the MIME parts."
5719 (save-excursion
5720 (save-selected-window
5721 (let ((window (get-buffer-window gnus-article-buffer))
5722 (point (point)))
5723 (when window
5724 (select-window window)
5725 ;; We have to do this since selecting the window
5726 ;; may change the point. So we set the window point.
5727 (set-window-point window point)))
73043f7d
MB
5728 (let ((handles ihandles)
5729 (inhibit-read-only t)
5730 handle)
5731 (cond (handles)
5732 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5733 (when gnus-article-emulate-mime
5734 (mm-uu-dissect-text-parts handles)))
5735 (gnus-article-emulate-mime
5736 (setq handles (mm-uu-dissect))))
16409b0b
GM
5737 (when (and (not ihandles)
5738 (not gnus-displaying-mime))
5739 ;; Top-level call; we clean up.
5740 (when gnus-article-mime-handles
5741 (mm-destroy-parts gnus-article-mime-handles)
5742 (setq gnus-article-mime-handle-alist nil));; A trick.
5743 (setq gnus-article-mime-handles handles)
5744 ;; We allow users to glean info from the handles.
5745 (when gnus-article-mime-part-function
5746 (gnus-mime-part-function handles)))
5747 (if (and handles
5748 (or (not (stringp (car handles)))
5749 (cdr handles)))
5750 (progn
5751 (when (and (not ihandles)
5752 (not gnus-displaying-mime))
5753 ;; Clean up for mime parts.
5754 (article-goto-body)
5755 (delete-region (point) (point-max)))
5756 (let ((gnus-displaying-mime t))
5757 (gnus-mime-display-part handles)))
5758 (save-restriction
5759 (article-goto-body)
5760 (narrow-to-region (point) (point-max))
5761 (gnus-treat-article nil 1 1)
5762 (widen)))
5763 (unless ihandles
5764 ;; Highlight the headers.
5765 (save-excursion
5766 (save-restriction
5767 (article-goto-body)
5768 (narrow-to-region (point-min) (point))
31640842 5769 (gnus-article-save-original-date
f362b760
MB
5770 (gnus-treat-article 'head)))))))
5771 ;; Cope with broken MIME messages.
5772 (goto-char (point-max))
5773 (unless (bolp)
5774 (insert "\n"))))
16409b0b 5775
23f87bed
MB
5776(defcustom gnus-mime-display-multipart-as-mixed nil
5777 "Display \"multipart\" parts as \"multipart/mixed\".
5778
5779If t, it overrides nil values of
5780`gnus-mime-display-multipart-alternative-as-mixed' and
5781`gnus-mime-display-multipart-related-as-mixed'."
5782 :group 'gnus-article-mime
5783 :type 'boolean)
5784
5785(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5786 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5787 :version "22.1"
23f87bed
MB
5788 :group 'gnus-article-mime
5789 :type 'boolean)
5790
5791(defcustom gnus-mime-display-multipart-related-as-mixed nil
5792 "Display \"multipart/related\" parts as \"multipart/mixed\".
5793
5794If displaying \"text/html\" is discouraged \(see
5795`mm-discouraged-alternatives'\) images or other material inside a
5796\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5797 :version "22.1"
23f87bed
MB
5798 :group 'gnus-article-mime
5799 :type 'boolean)
16409b0b
GM
5800
5801(defun gnus-mime-display-part (handle)
5802 (cond
430d3ed7
MB
5803 ;; Maybe a broken MIME message.
5804 ((null handle))
16409b0b
GM
5805 ;; Single part.
5806 ((not (stringp (car handle)))
5807 (gnus-mime-display-single handle))
5808 ;; User-defined multipart
5809 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5810 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5811 handle))
5812 ;; multipart/alternative
5813 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5814 (not (or gnus-mime-display-multipart-as-mixed
5815 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5816 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5817 (push (cons id handle) gnus-article-mime-handle-alist)
5818 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5819 ;; multipart/related
5820 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5821 (not (or gnus-mime-display-multipart-as-mixed
5822 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5823 ;;;!!!We should find the start part, but we just default
5824 ;;;!!!to the first part.
23f87bed
MB
5825 ;;(gnus-mime-display-part (cadr handle))
5826 ;;;!!! Most multipart/related is an HTML message plus images.
5827 ;;;!!! Unfortunately we are unable to let W3 display those
5828 ;;;!!! included images, so we just display it as a mixed multipart.
5829 ;;(gnus-mime-display-mixed (cdr handle))
5830 ;;;!!! No, w3 can display everything just fine.
16409b0b 5831 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5832 ((equal (car handle) "multipart/signed")
5833 (gnus-add-wash-type 'signed)
5834 (gnus-mime-display-security handle))
5835 ((equal (car handle) "multipart/encrypted")
5836 (gnus-add-wash-type 'encrypted)
5837 (gnus-mime-display-security handle))
16409b0b
GM
5838 ;; Other multiparts are handled like multipart/mixed.
5839 (t
5840 (gnus-mime-display-mixed (cdr handle)))))
5841
5842(defun gnus-mime-part-function (handles)
5843 (if (stringp (car handles))
5844 (mapcar 'gnus-mime-part-function (cdr handles))
5845 (funcall gnus-article-mime-part-function handles)))
5846
5847(defun gnus-mime-display-mixed (handles)
5848 (mapcar 'gnus-mime-display-part handles))
5849
5850(defun gnus-mime-display-single (handle)
5851 (let ((type (mm-handle-media-type handle))
5852 (ignored gnus-ignored-mime-types)
5853 (not-attachment t)
5854 (move nil)
5855 display text)
5856 (catch 'ignored
5857 (progn
5858 (while ignored
5859 (when (string-match (pop ignored) type)
5860 (throw 'ignored nil)))
5861 (if (and (setq not-attachment
5862 (and (not (mm-inline-override-p handle))
5863 (or (not (mm-handle-disposition handle))
5864 (equal (car (mm-handle-disposition handle))
5865 "inline")
5866 (mm-attachment-override-p handle))))
5867 (mm-automatic-display-p handle)
23f87bed
MB
5868 (or (and
5869 (mm-inlinable-p handle)
5870 (mm-inlined-p handle))
16409b0b
GM
5871 (mm-automatic-external-display-p type)))
5872 (setq display t)
5873 (when (equal (mm-handle-media-supertype handle) "text")
5874 (setq text t)))
e0bad764
DL
5875 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5876 beg)
16409b0b 5877 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5878 (when (and display
5879 (equal (mm-handle-media-supertype handle) "message"))
5880 (insert-char
5881 ?\n
5882 (cond ((not (bolp)) 2)
5883 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5884 (t 1))))
16409b0b 5885 (when (or (not display)
3e3ab3ab
KY
5886 (not (gnus-unbuttonized-mime-type-p type))
5887 (eq id gnus-mime-buttonized-part-id))
16409b0b
GM
5888 (gnus-insert-mime-button
5889 handle id (list (or display (and not-attachment text))))
5890 (gnus-article-insert-newline)
23f87bed 5891 ;; Remember modify the number of forward lines.
e0bad764
DL
5892 (setq move t))
5893 (setq beg (point))
16409b0b
GM
5894 (cond
5895 (display
5896 (when move
23f87bed 5897 (forward-line -1)
16409b0b
GM
5898 (setq beg (point)))
5899 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5900 (mail-parse-ignored-charsets
16409b0b
GM
5901 (save-excursion (condition-case ()
5902 (set-buffer gnus-summary-buffer)
5903 (error))
5904 gnus-newsgroup-ignored-charsets)))
b0b63450 5905 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
16409b0b
GM
5906 (goto-char (point-max)))
5907 ((and text not-attachment)
5908 (when move
23f87bed 5909 (forward-line -1)
16409b0b
GM
5910 (setq beg (point)))
5911 (gnus-article-insert-newline)
53cfefc8
MB
5912 (mm-insert-inline
5913 handle
01c52d31
MB
5914 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5915 'charset)
5916 (and (equal type "text/calendar") 'utf-8))))
53cfefc8
MB
5917 (cond ((not charset)
5918 (mm-string-as-multibyte (mm-get-part handle)))
5919 ((eq charset 'gnus-decoded)
5920 (with-current-buffer (mm-handle-buffer handle)
5921 (buffer-string)))
5922 (t
5923 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
5924 (goto-char (point-max))))
5925 ;; Do highlighting.
5926 (save-excursion
5927 (save-restriction
5928 (narrow-to-region beg (point))
01c52d31
MB
5929 (if (eq handle gnus-article-mime-handles)
5930 ;; The format=flowed case.
5931 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5932 ;; Don't count signature parts that are never displayed.
5933 ;; The part number should be re-calculated supposing this
5934 ;; might be a message/rfc822 part.
5935 (let (handles)
5936 (dolist (part gnus-article-mime-handles)
5937 (unless (or (stringp part)
5938 (equal (car (mm-handle-type part))
5939 "application/pgp-signature"))
5940 (push part handles)))
5941 (gnus-treat-article
5942 nil (length (memq handle handles)) (length handles)
5943 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5944
5945(defun gnus-unbuttonized-mime-type-p (type)
5946 "Say whether TYPE is to be unbuttonized."
5947 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5948 (when (catch 'found
5949 (let ((types gnus-unbuttonized-mime-types))
5950 (while types
5951 (when (string-match (pop types) type)
5952 (throw 'found t)))))
5953 (not (catch 'found
5954 (let ((types gnus-buttonized-mime-types))
5955 (while types
5956 (when (string-match (pop types) type)
5957 (throw 'found t)))))))))
16409b0b
GM
5958
5959(defun gnus-article-insert-newline ()
5960 "Insert a newline, but mark it as undeletable."
5961 (gnus-put-text-property
5962 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5963
5964(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5965 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5966 (ihandles handles)
5967 (point (point))
23f87bed 5968 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5969 (save-window-excursion
5970 (save-restriction
5971 (when ibegend
5972 (narrow-to-region (car ibegend)
5973 (or (cdr ibegend)
5974 (progn
5975 (goto-char (car ibegend))
5976 (forward-line 2)
5977 (point))))
5978 (delete-region (point-min) (point-max))
5979 (mm-remove-parts handles))
5980 (setq begend (list (point-marker)))
5981 ;; Do the toggle.
5982 (unless (setq not-pref (cadr (member preferred ihandles)))
5983 (setq not-pref (car ihandles)))
5984 (when (or ibegend
23f87bed 5985 (not preferred)
16409b0b
GM
5986 (not (gnus-unbuttonized-mime-type-p
5987 "multipart/alternative")))
5988 (gnus-add-text-properties
5989 (setq from (point))
5990 (progn
5991 (insert (format "%d. " id))
5992 (point))
5993 `(gnus-callback
5994 (lambda (handles)
5995 (unless ,(not ibegend)
5996 (setq gnus-article-mime-handle-alist
5997 ',gnus-article-mime-handle-alist))
5998 (gnus-mime-display-alternative
5999 ',ihandles ',not-pref ',begend ,id))
01c52d31 6000 keymap ,gnus-mime-button-map
16409b0b
GM
6001 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6002 face ,gnus-article-button-face
16409b0b 6003 gnus-part ,id
7dafe00b 6004 article-type multipart))
16409b0b
GM
6005 (widget-convert-button 'link from (point)
6006 :action 'gnus-widget-press-button
6007 :button-keymap gnus-widget-button-keymap)
6008 ;; Do the handles
6009 (while (setq handle (pop handles))
6010 (gnus-add-text-properties
6011 (setq from (point))
6012 (progn
6013 (insert (format "(%c) %-18s"
6014 (if (equal handle preferred) ?* ? )
6015 (mm-handle-media-type handle)))
6016 (point))
6017 `(gnus-callback
6018 (lambda (handles)
6019 (unless ,(not ibegend)
6020 (setq gnus-article-mime-handle-alist
6021 ',gnus-article-mime-handle-alist))
6022 (gnus-mime-display-alternative
6023 ',ihandles ',handle ',begend ,id))
01c52d31 6024 keymap ,gnus-mime-button-map
16409b0b
GM
6025 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6026 face ,gnus-article-button-face
16409b0b
GM
6027 gnus-part ,id
6028 gnus-data ,handle))
6029 (widget-convert-button 'link from (point)
6030 :action 'gnus-widget-press-button
6031 :button-keymap gnus-widget-button-keymap)
6032 (insert " "))
6033 (insert "\n\n"))
6034 (when preferred
6035 (if (stringp (car preferred))
6036 (gnus-display-mime preferred)
6037 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 6038 (mail-parse-ignored-charsets
01c52d31
MB
6039 (with-current-buffer gnus-summary-buffer
6040 gnus-newsgroup-ignored-charsets)))
b0b63450 6041 (gnus-bind-safe-url-regexp (mm-display-part preferred))
16409b0b
GM
6042 ;; Do highlighting.
6043 (save-excursion
6044 (save-restriction
6045 (narrow-to-region (car begend) (point-max))
6046 (gnus-treat-article
6047 nil (length gnus-article-mime-handle-alist)
e0bad764 6048 (gnus-article-mime-total-parts)
16409b0b
GM
6049 (mm-handle-media-type handle))))))
6050 (goto-char (point-max))
6051 (setcdr begend (point-marker)))))
6052 (when ibegend
6053 (goto-char point))))
6054
23f87bed
MB
6055(defconst gnus-article-wash-status-strings
6056 (let ((alist '((cite "c" "Possible hidden citation text"
6057 " " "All citation text visible")
6058 (headers "h" "Hidden headers"
6059 " " "All headers visible.")
6060 (pgp "p" "Encrypted or signed message status hidden"
6061 " " "No hidden encryption nor digital signature status")
6062 (signature "s" "Signature has been hidden"
6063 " " "Signature is visible")
6064 (overstrike "o" "Overstrike (^H) characters applied"
6065 " " "No overstrike characters applied")
6066 (emphasis "e" "/*_Emphasis_*/ characters applied"
6067 " " "No /*_emphasis_*/ characters applied")))
6068 result)
6069 (dolist (entry alist result)
6070 (let ((key (nth 0 entry))
6071 (on (copy-sequence (nth 1 entry)))
6072 (on-help (nth 2 entry))
6073 (off (copy-sequence (nth 3 entry)))
6074 (off-help (nth 4 entry)))
6075 (put-text-property 0 1 'help-echo on-help on)
6076 (put-text-property 0 1 'help-echo off-help off)
6077 (push (list key on off) result))))
6078 "Alist of strings describing wash status in the mode line.
6079Each entry has the form (KEY ON OF), where the KEY is a symbol
6080representing the particular washing function, ON is the string to use
6081in the article mode line when the washing function is active, and OFF
6082is the string to use when it is inactive.")
6083
6084(defun gnus-article-wash-status-entry (key value)
6085 (let ((entry (assoc key gnus-article-wash-status-strings)))
6086 (if value (nth 1 entry) (nth 2 entry))))
6087
eec82323
LMI
6088(defun gnus-article-wash-status ()
6089 "Return a string which display status of article washing."
01c52d31 6090 (with-current-buffer gnus-article-buffer
16409b0b
GM
6091 (let ((cite (memq 'cite gnus-article-wash-types))
6092 (headers (memq 'headers gnus-article-wash-types))
6093 (boring (memq 'boring-headers gnus-article-wash-types))
6094 (pgp (memq 'pgp gnus-article-wash-types))
6095 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
6096 (signed (memq 'signed gnus-article-wash-types))
6097 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
6098 (signature (memq 'signature gnus-article-wash-types))
6099 (overstrike (memq 'overstrike gnus-article-wash-types))
6100 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
6101 (concat
6102 (gnus-article-wash-status-entry 'cite cite)
6103 (gnus-article-wash-status-entry 'headers (or headers boring))
6104 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6105 (gnus-article-wash-status-entry 'signature signature)
6106 (gnus-article-wash-status-entry 'overstrike overstrike)
6107 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6108
6109(defun gnus-add-wash-type (type)
6110 "Add a washing of TYPE to the current status."
6111 (add-to-list 'gnus-article-wash-types type))
6112
6113(defun gnus-delete-wash-type (type)
6114 "Add a washing of TYPE to the current status."
6115 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6116
6117(defun gnus-add-image (category image)
6118 "Add IMAGE of CATEGORY to the list of displayed images."
6119 (let ((entry (assq category gnus-article-image-alist)))
6120 (unless entry
6121 (setq entry (list category))
6122 (push entry gnus-article-image-alist))
6123 (nconc entry (list image))))
6124
6125(defun gnus-delete-images (category)
6126 "Delete all images in CATEGORY."
6127 (let ((entry (assq category gnus-article-image-alist)))
6128 (dolist (image (cdr entry))
6129 (gnus-remove-image image category))
6130 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6131 (gnus-delete-wash-type category)))
eec82323 6132
16409b0b 6133(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
6134
6135(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
6136 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6137Provided for backwards compatibility."
16409b0b 6138 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
6139 (not (with-current-buffer gnus-summary-buffer
6140 gnus-have-all-headers)))
16409b0b
GM
6141 (not gnus-inhibit-hiding))
6142 (gnus-article-hide-headers)))
eec82323
LMI
6143
6144;;; Article savers.
6145
6146(defun gnus-output-to-file (file-name)
26c9afc3
MB
6147 "Append the current article to a file named FILE-NAME.
6148If `gnus-article-save-coding-system' is non-nil, it is used to encode
6149text and used as the value of the coding cookie which is added to the
6150top of a file. Otherwise, this function saves a raw article without
6151the coding cookie."
6152 (let* ((artbuf (current-buffer))
6153 (file-name-coding-system nnmail-pathname-coding-system)
6154 (coding gnus-article-save-coding-system)
6155 (coding-system-for-read (if coding
6156 nil ;; Rely on the coding cookie.
6157 mm-text-coding-system))
6158 (coding-system-for-write (or coding
6159 mm-text-coding-system-for-write
6160 mm-text-coding-system))
6161 (exists (file-exists-p file-name)))
16409b0b 6162 (with-temp-buffer
26c9afc3
MB
6163 (when exists
6164 (insert-file-contents file-name)
6165 (goto-char (point-min))
6166 ;; Remove the existing coding cookie.
6167 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6168 (delete-region (match-beginning 0) (match-end 0))))
6169 (goto-char (point-max))
eec82323
LMI
6170 (insert-buffer-substring artbuf)
6171 ;; Append newline at end of the buffer as separator, and then
6172 ;; save it to file.
6173 (goto-char (point-max))
6174 (insert "\n")
26c9afc3
MB
6175 (when coding
6176 ;; If the coding system is not suitable to encode the text,
6177 ;; ask a user for a proper one.
6178 (when (fboundp 'select-safe-coding-system)
6179 (setq coding (coding-system-base
6180 (save-window-excursion
6181 (select-safe-coding-system (point-min) (point-max)
6182 coding))))
6183 (setq coding-system-for-write
6184 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6185 coding)))
6186 (goto-char (point-min))
6187 ;; Add the coding cookie.
6188 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6189 coding-system-for-write)))
6190 (if exists
6191 (progn
6192 (write-region (point-min) (point-max) file-name nil 'no-message)
6193 (message "Appended to %s" file-name))
6194 (write-region (point-min) (point-max) file-name))))
6195 t)
eec82323
LMI
6196
6197(defun gnus-narrow-to-page (&optional arg)
6198 "Narrow the article buffer to a page.
6199If given a numerical ARG, move forward ARG pages."
6200 (interactive "P")
6201 (setq arg (if arg (prefix-numeric-value arg) 0))
80de1778 6202 (with-current-buffer gnus-article-buffer
eec82323
LMI
6203 (widen)
6204 ;; Remove any old next/prev buttons.
6205 (when (gnus-visual-p 'page-marker)
4e7d0221 6206 (let ((inhibit-read-only t))
eec82323
LMI
6207 (gnus-remove-text-with-property 'gnus-prev)
6208 (gnus-remove-text-with-property 'gnus-next)))
8f7abae3
MB
6209 (let (st nd pt)
6210 (when (save-excursion
6211 (cond ((< arg 0)
6212 (if (re-search-backward page-delimiter nil 'move (abs arg))
6213 (prog1
6214 (setq nd (match-beginning 0)
6215 pt nd)
6216 (when (re-search-backward page-delimiter nil t)
6217 (setq st (match-end 0))))
6218 (when (re-search-forward page-delimiter nil t)
6219 (setq nd (match-beginning 0)
6220 pt (point-min)))))
6221 ((> arg 0)
6222 (if (re-search-forward page-delimiter nil 'move arg)
6223 (prog1
6224 (setq st (match-end 0)
6225 pt st)
6226 (when (re-search-forward page-delimiter nil t)
6227 (setq nd (match-beginning 0))))
6228 (when (re-search-backward page-delimiter nil t)
6229 (setq st (match-end 0)
6230 pt (point-max)))))
6231 (t
6232 (when (re-search-backward page-delimiter nil t)
6233 (goto-char (setq st (match-end 0))))
6234 (when (re-search-forward page-delimiter nil t)
6235 (setq nd (match-beginning 0)))
6236 (or st nd))))
6237 (setq gnus-page-broken t)
6238 (when pt (goto-char pt))
6239 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6240 (when (gnus-visual-p 'page-marker)
6241 (save-excursion
6242 (when nd
6243 (goto-char nd)
6244 (gnus-insert-next-page-button))
6245 (when st
6246 (goto-char st)
6247 (gnus-insert-prev-page-button))))))))
eec82323
LMI
6248
6249;; Article mode commands
6250
6251(defun gnus-article-goto-next-page ()
6252 "Show the next page of the article."
6253 (interactive)
6254 (when (gnus-article-next-page)
6255 (goto-char (point-min))
6256 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6257
23f87bed 6258
eec82323 6259(defun gnus-article-goto-prev-page ()
23f87bed 6260 "Show the previous page of the article."
eec82323 6261 (interactive)
8f7abae3 6262 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
23f87bed 6263 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6264 (gnus-article-prev-page nil)))
6265
23f87bed
MB
6266;; This is cleaner but currently breaks `gnus-pick-mode':
6267;;
6268;; (defun gnus-article-goto-next-page ()
6269;; "Show the next page of the article."
6270;; (interactive)
6271;; (gnus-eval-in-buffer-window gnus-summary-buffer
6272;; (gnus-summary-next-page)))
6273;;
6274;; (defun gnus-article-goto-prev-page ()
6275;; "Show the next page of the article."
6276;; (interactive)
6277;; (gnus-eval-in-buffer-window gnus-summary-buffer
6278;; (gnus-summary-prev-page)))
6279
eec82323
LMI
6280(defun gnus-article-next-page (&optional lines)
6281 "Show the next page of the current article.
6282If end of article, return non-nil. Otherwise return nil.
6283Argument LINES specifies lines to be scrolled up."
6284 (interactive "p")
9153f10d 6285 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
60ece9b0
MB
6286 (if (and (not (and gnus-article-over-scroll
6287 (> (count-lines (window-start) (point-max))
9153f10d
MB
6288 (if (featurep 'xemacs)
6289 (or lines (1- (window-height)))
6290 (+ (or lines (1- (window-height))) scroll-margin)))))
60ece9b0
MB
6291 (save-excursion
6292 (end-of-line)
6293 (and (pos-visible-in-window-p) ;Not continuation line.
6294 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
eec82323
LMI
6295 ;; Nothing in this page.
6296 (if (or (not gnus-page-broken)
6297 (save-excursion
6298 (save-restriction
23f87bed
MB
6299 (widen)
6300 (forward-line)
6301 (eobp)))) ;Real end-of-buffer?
6302 (progn
6303 (when gnus-article-over-scroll
6304 (gnus-article-next-page-1 lines))
6305 t) ;Nothing more.
eec82323
LMI
6306 (gnus-narrow-to-page 1) ;Go to next page.
6307 nil)
6308 ;; More in this page.
23f87bed 6309 (gnus-article-next-page-1 lines)
eec82323
LMI
6310 nil))
6311
b1992461 6312(defun gnus-article-beginning-of-window ()
d8a88581
MB
6313 "Move point to the beginning of the window.
6314In Emacs, the point is placed at the line number which `scroll-margin'
6315specifies."
6316 (if (featurep 'xemacs)
b1992461
KY
6317 (move-to-window-line 0)
6318 ;; There is an obscure bug in Emacs that makes it impossible to
6319 ;; scroll past big pictures in the article buffer. Try to fix
6320 ;; this by adding a sanity check by counting the lines visible.
6321 (when (> (count-lines (window-start) (window-end)) 30)
6322 (move-to-window-line
6323 (min (max 0 scroll-margin)
6324 (max 1 (- (window-height)
6325 (if mode-line-format 1 0)
6326 (if header-line-format 1 0)
6327 2)))))))
d8a88581 6328
23f87bed 6329(defun gnus-article-next-page-1 (lines)
4b91459a
MB
6330 (condition-case ()
6331 (let ((scroll-in-place nil))
6332 (scroll-up lines))
6333 (end-of-buffer
6334 ;; Long lines may cause an end-of-buffer error.
6335 (goto-char (point-max))))
6336 (gnus-article-beginning-of-window))
23f87bed 6337
eec82323
LMI
6338(defun gnus-article-prev-page (&optional lines)
6339 "Show previous page of current article.
6340Argument LINES specifies lines to be scrolled down."
6341 (interactive "p")
d8a88581 6342 (move-to-window-line 0)
eec82323
LMI
6343 (if (and gnus-page-broken
6344 (bobp)
6345 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6346 (progn
6347 (gnus-narrow-to-page -1) ;Go to previous page.
6348 (goto-char (point-max))
60ece9b0
MB
6349 (recenter (if gnus-article-over-scroll
6350 (if lines
9153f10d
MB
6351 (max (if (featurep 'xemacs)
6352 lines
6353 (+ lines scroll-margin))
60ece9b0
MB
6354 3)
6355 (- (window-height) 2))
6356 -1)))
c03ac728
MB
6357 (prog1
6358 (condition-case ()
6359 (let ((scroll-in-place nil))
6360 (scroll-down lines))
6361 (beginning-of-buffer
6362 (goto-char (point-min))))
6363 (gnus-article-beginning-of-window))))
eec82323 6364
23f87bed
MB
6365(defun gnus-article-only-boring-p ()
6366 "Decide whether there is only boring text remaining in the article.
6367Something \"interesting\" is a word of at least two letters that does
6368not have a face in `gnus-article-boring-faces'."
6369 (when (and gnus-article-skip-boring
6370 (boundp 'gnus-article-boring-faces)
6371 (symbol-value 'gnus-article-boring-faces))
6372 (save-excursion
531bedc3
MB
6373 (let ((inhibit-point-motion-hooks t))
6374 (catch 'only-boring
6375 (while (re-search-forward "\\b\\w\\w" nil t)
6376 (forward-char -1)
6377 (when (not (gnus-intersection
6378 (gnus-faces-at (point))
6379 (symbol-value 'gnus-article-boring-faces)))
6380 (throw 'only-boring nil)))
6381 (throw 'only-boring t))))))
23f87bed 6382
eec82323
LMI
6383(defun gnus-article-refer-article ()
6384 "Read article specified by message-id around point."
6385 (interactive)
23f87bed 6386 (save-excursion
01c52d31
MB
6387 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6388 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6389 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6390 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6391 (set-buffer gnus-summary-buffer)
23f87bed 6392 (gnus-summary-refer-article msg-id))
eec82323
LMI
6393 (error "No references around point"))))
6394
6395(defun gnus-article-show-summary ()
6396 "Reconfigure windows to show summary buffer."
6397 (interactive)
6398 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6399 (error "There is no summary buffer for this article buffer")
a8151ef7 6400 (gnus-article-set-globals)
eec82323 6401 (gnus-configure-windows 'article)
6748645f
LMI
6402 (gnus-summary-goto-subject gnus-current-article)
6403 (gnus-summary-position-point)))
eec82323
LMI
6404
6405(defun gnus-article-describe-briefly ()
6406 "Describe article mode commands briefly."
6407 (interactive)
bdaa75c7 6408 (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
eec82323 6409
16409b0b
GM
6410(defun gnus-article-check-buffer ()
6411 "Beep if not in an article buffer."
6412 (unless (equal major-mode 'gnus-article-mode)
6413 (error "Command invoked outside of a Gnus article buffer")))
6414
eec82323
LMI
6415(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6416 "Read a summary buffer key sequence and execute it from the article buffer."
6417 (interactive "P")
16409b0b 6418 (gnus-article-check-buffer)
eec82323 6419 (let ((nosaves
23f87bed
MB
6420 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6421 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6422 "=" "^" "\M-^" "|"))
6423 (nosave-but-article
0b6799c3
MB
6424 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6425 "An" "Ap" [?A (meta return)] [?A delete]))
23f87bed 6426 (nosave-in-article
0b6799c3 6427 '("AS" "\C-d"))
23f87bed
MB
6428 (up-to-top
6429 '("n" "Gn" "p" "Gp"))
6430 keys new-sum-point)
80de1778 6431 (with-current-buffer gnus-article-current-summary
eec82323 6432 (let (gnus-pick-mode)
95838435
MB
6433 (setq unread-command-events (nconc unread-command-events
6434 (list (or key last-command-event)))
6435 keys (if (featurep 'xemacs)
6436 (events-to-keys (read-key-sequence nil t))
6437 (read-key-sequence nil t)))))
a1506d29 6438
eec82323
LMI
6439 (message "")
6440
01c52d31
MB
6441 (cond
6442 ((eq (aref keys (1- (length keys))) ?\C-h)
0b6799c3 6443 (gnus-article-describe-bindings (substring keys 0 -1)))
01c52d31
MB
6444 ((or (member keys nosaves)
6445 (member keys nosave-but-article)
6446 (member keys nosave-in-article))
6447 (let (func)
6448 (save-window-excursion
6449 (pop-to-buffer gnus-article-current-summary)
6450 ;; We disable the pick minor mode commands.
6451 (let (gnus-pick-mode)
6ab2c7a8 6452 (setq func (key-binding keys t))))
01c52d31
MB
6453 (if (or (not func)
6454 (numberp func))
6455 (ding)
6456 (unless (member keys nosave-in-article)
6457 (set-buffer gnus-article-current-summary))
6458 (call-interactively func)
6459 (setq new-sum-point (point)))
6460 (when (member keys nosave-but-article)
6461 (pop-to-buffer gnus-article-buffer))))
6462 (t
eec82323
LMI
6463 ;; These commands should restore window configuration.
6464 (let ((obuf (current-buffer))
23f87bed 6465 (owin (current-window-configuration))
01c52d31 6466 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6467 (cond (not-restore-window
01c52d31
MB
6468 (pop-to-buffer gnus-article-current-summary)
6469 (setq win (selected-window)))
23f87bed
MB
6470 ((setq win (get-buffer-window gnus-article-current-summary))
6471 (select-window win))
6472 (t
01c52d31
MB
6473 (let ((summary-buffer gnus-article-current-summary))
6474 (gnus-configure-windows 'article)
6475 (unless (setq win (get-buffer-window summary-buffer 'visible))
6476 (let ((gnus-buffer-configuration
de0bdfe7
KY
6477 '((article ((vertical 1.0
6478 (summary 0.25 point)
6479 (article 1.0)))))))
01c52d31
MB
6480 (gnus-configure-windows 'article))
6481 (setq win (get-buffer-window summary-buffer 'visible)))
6482 (gnus-select-frame-set-input-focus (window-frame win))
6483 (select-window win))))
23f87bed
MB
6484 (setq in-buffer (current-buffer))
6485 ;; We disable the pick minor mode commands.
6486 (if (and (setq func (let (gnus-pick-mode)
6ab2c7a8 6487 (key-binding keys t)))
01c52d31
MB
6488 (functionp func)
6489 (condition-case code
6490 (progn
6491 (call-interactively func)
6492 t)
6493 (error
6494 (setq err code)
6495 nil)))
23f87bed 6496 (progn
23f87bed
MB
6497 (when (eq win (selected-window))
6498 (setq new-sum-point (point)
6499 new-sum-start (window-start win)
9a89f5b0 6500 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6501 (when (or (eq in-buffer (current-buffer))
6502 (when (eq obuf (current-buffer))
6503 (set-buffer in-buffer)
6504 t))
520aa572
SZ
6505 (setq selected (gnus-summary-select-article))
6506 (set-buffer obuf)
6507 (unless not-restore-window
6508 (set-window-configuration owin))
01c52d31
MB
6509 (when (and (eq selected 'old)
6510 new-sum-point)
520aa572
SZ
6511 (set-window-start (get-buffer-window (current-buffer))
6512 1)
6513 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6514 (if (article-goto-body)
6515 (1- (point))
6516 (point))))
23f87bed 6517 (when (and (not not-restore-window)
01c52d31 6518 new-sum-point
4520e527 6519 (window-live-p win)
01c52d31
MB
6520 (with-current-buffer (window-buffer win)
6521 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6522 (set-window-point win new-sum-point)
6523 (set-window-start win new-sum-start)
9a89f5b0 6524 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6525 (set-window-configuration owin)
01c52d31
MB
6526 (if err
6527 (signal (car err) (cdr err))
6528 (ding))))))))
520aa572 6529
95838435
MB
6530(defun gnus-article-read-summary-send-keys ()
6531 (interactive)
0b6799c3 6532 (let ((unread-command-events (list (gnus-character-to-event ?S))))
95838435
MB
6533 (gnus-article-read-summary-keys)))
6534
520aa572 6535(defun gnus-article-describe-key (key)
95838435
MB
6536 "Display documentation of the function invoked by KEY.
6537KEY is a string or a vector."
6538 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6539 (read-key-sequence "Describe key: "))))
520aa572 6540 (gnus-article-check-buffer)
95838435
MB
6541 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6542 gnus-article-read-summary-send-keys))
80de1778 6543 (with-current-buffer gnus-article-current-summary
95838435
MB
6544 (setq unread-command-events
6545 (if (featurep 'xemacs)
6546 (append key nil)
6547 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6548 (list 'meta (- x 128))
6549 x))
6550 key)))
6551 (let ((cursor-in-echo-area t)
6552 gnus-pick-mode)
6553 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6554 (describe-key key)))
6555
6556(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6557 "Display documentation of the function invoked by KEY.
6558KEY is a string or a vector."
6559 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6560 (read-key-sequence "Describe key: "))
6561 current-prefix-arg))
520aa572 6562 (gnus-article-check-buffer)
95838435
MB
6563 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6564 gnus-article-read-summary-send-keys))
80de1778 6565 (with-current-buffer gnus-article-current-summary
95838435
MB
6566 (setq unread-command-events
6567 (if (featurep 'xemacs)
6568 (append key nil)
6569 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6570 (list 'meta (- x 128))
6571 x))
6572 key)))
6573 (let ((cursor-in-echo-area t)
6574 gnus-pick-mode)
6575 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6576 (describe-key-briefly key insert)))
eec82323 6577
0b6799c3
MB
6578;;`gnus-agent-mode' in gnus-agent.el will define it.
6579(defvar gnus-agent-summary-mode)
e9198520 6580(defvar gnus-draft-mode)
12ea3d65
GM
6581;; Calling help-buffer will autoload help-mode.
6582(defvar help-xref-stack-item)
5843126b
KY
6583;; Emacs 22 doesn't load it in the batch mode.
6584(eval-when-compile
6585 (autoload 'help-buffer "help-mode"))
0b6799c3
MB
6586
6587(defun gnus-article-describe-bindings (&optional prefix)
6588 "Show a list of all defined keys, and their definitions.
6589The optional argument PREFIX, if non-nil, should be a key sequence;
6590then we display only bindings that start with that prefix."
6591 (interactive)
6592 (gnus-article-check-buffer)
6593 (let ((keymap (copy-keymap gnus-article-mode-map))
6594 (map (copy-keymap gnus-article-send-map))
6595 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
8a908224 6596 parent agent draft)
0b6799c3
MB
6597 (define-key keymap "S" map)
6598 (define-key map [t] nil)
6599 (with-current-buffer gnus-article-current-summary
8a908224
KY
6600 (set-keymap-parent
6601 keymap
6602 (if (setq parent (keymap-parent gnus-article-mode-map))
6603 (prog1
6604 (setq parent (copy-keymap parent))
6605 (set-keymap-parent parent (current-local-map)))
6606 (current-local-map)))
0b6799c3 6607 (set-keymap-parent map (key-binding "S"))
8f7abae3
MB
6608 (let (key def gnus-pick-mode)
6609 (while sumkeys
6610 (setq key (pop sumkeys))
6611 (cond ((and (vectorp key) (= (length key) 1)
6612 (consp (setq def (aref key 0)))
6613 (numberp (car def)) (numberp (cdr def)))
6614 (when (< (max (car def) (cdr def)) 128)
6615 (setq sumkeys
6616 (append (mapcar
6617 #'vector
6618 (nreverse (gnus-uncompress-range def)))
6619 sumkeys))))
6620 ((setq def (key-binding key))
6621 (unless (eq def 'undefined)
6622 (define-key keymap key def))))))
0b6799c3 6623 (when (boundp 'gnus-agent-summary-mode)
e9198520
MB
6624 (setq agent gnus-agent-summary-mode))
6625 (when (boundp 'gnus-draft-mode)
6626 (setq draft gnus-draft-mode)))
0b6799c3
MB
6627 (with-temp-buffer
6628 (use-local-map keymap)
6629 (set (make-local-variable 'gnus-agent-summary-mode) agent)
e9198520 6630 (set (make-local-variable 'gnus-draft-mode) draft)
0b6799c3
MB
6631 (describe-bindings prefix))
6632 (let ((item `((lambda (prefix)
80de1778 6633 (with-current-buffer ,(current-buffer)
0b6799c3
MB
6634 (gnus-article-describe-bindings prefix)))
6635 ,prefix)))
5843126b 6636 (with-current-buffer (let (help-xref-following) (help-buffer))
0b6799c3
MB
6637 (setq help-xref-stack-item item)))))
6638
23f87bed
MB
6639(defun gnus-article-reply-with-original (&optional wide)
6640 "Start composing a reply mail to the current message.
6641The text in the region will be yanked. If the region isn't active,
6642the entire article will be yanked."
95838435 6643 (interactive)
23f87bed
MB
6644 (let ((article (cdr gnus-article-current))
6645 contents)
1d0df8af 6646 (if (not (gnus-region-active-p))
23f87bed
MB
6647 (with-current-buffer gnus-summary-buffer
6648 (gnus-summary-reply (list (list article)) wide))
6649 (setq contents (buffer-substring (point) (mark t)))
6650 ;; Deactivate active regions.
6651 (when (and (boundp 'transient-mark-mode)
6652 transient-mark-mode)
6653 (setq mark-active nil))
6654 (with-current-buffer gnus-summary-buffer
6655 (gnus-summary-reply
6656 (list (list article contents)) wide)))))
6657
95838435
MB
6658(defun gnus-article-wide-reply-with-original ()
6659 "Start composing a wide reply mail to the current message.
6660The text in the region will be yanked. If the region isn't active,
6661the entire article will be yanked."
6662 (interactive)
6663 (gnus-article-reply-with-original t))
6664
23f87bed
MB
6665(defun gnus-article-followup-with-original ()
6666 "Compose a followup to the current article.
6667The text in the region will be yanked. If the region isn't active,
6668the entire article will be yanked."
6669 (interactive)
6670 (let ((article (cdr gnus-article-current))
6671 contents)
1d0df8af 6672 (if (not (gnus-region-active-p))
23f87bed
MB
6673 (with-current-buffer gnus-summary-buffer
6674 (gnus-summary-followup (list (list article))))
6675 (setq contents (buffer-substring (point) (mark t)))
6676 ;; Deactivate active regions.
6677 (when (and (boundp 'transient-mark-mode)
6678 transient-mark-mode)
6679 (setq mark-active nil))
6680 (with-current-buffer gnus-summary-buffer
6681 (gnus-summary-followup
6682 (list (list article contents)))))))
6683
eec82323
LMI
6684(defun gnus-article-hide (&optional arg force)
6685 "Hide all the gruft in the current article.
23f87bed
MB
6686This means that signatures, cited text and (some) headers will be
6687hidden.
eec82323 6688If given a prefix, show the hidden text instead."
6748645f 6689 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6690 (gnus-article-hide-headers arg)
16409b0b 6691 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6692 (gnus-article-hide-citation-maybe arg force)
6693 (gnus-article-hide-signature arg))
6694
6695(defun gnus-article-maybe-highlight ()
6748645f 6696 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6697 (when (gnus-visual-p 'article-highlight 'highlight)
6698 (gnus-article-highlight-some)))
6699
6748645f
LMI
6700(defun gnus-check-group-server ()
6701 ;; Make sure the connection to the server is alive.
6702 (unless (gnus-server-opened
6703 (gnus-find-method-for-group gnus-newsgroup-name))
6704 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6705 (gnus-request-group gnus-newsgroup-name t)))
6706
23f87bed
MB
6707(eval-when-compile
6708 (autoload 'nneething-get-file-name "nneething"))
6709
eec82323
LMI
6710(defun gnus-request-article-this-buffer (article group)
6711 "Get an article and insert it into this buffer."
6748645f 6712 (let (do-update-line sparse-header)
eec82323
LMI
6713 (prog1
6714 (save-excursion
6715 (erase-buffer)
6716 (gnus-kill-all-overlays)
6717 (setq group (or group gnus-newsgroup-name))
6718
eec82323
LMI
6719 ;; Using `gnus-request-article' directly will insert the article into
6720 ;; `nntp-server-buffer' - so we'll save some time by not having to
6721 ;; copy it from the server buffer into the article buffer.
6722
6723 ;; We only request an article by message-id when we do not have the
6724 ;; headers for it, so we'll have to get those.
6725 (when (stringp article)
16409b0b 6726 (gnus-read-header article))
eec82323
LMI
6727
6728 ;; If the article number is negative, that means that this article
6729 ;; doesn't belong in this newsgroup (possibly), so we find its
6730 ;; message-id and request it by id instead of number.
6731 (when (and (numberp article)
6732 gnus-summary-buffer
6733 (get-buffer gnus-summary-buffer)
6748645f 6734 (gnus-buffer-exists-p gnus-summary-buffer))
80de1778 6735 (with-current-buffer gnus-summary-buffer
eec82323
LMI
6736 (let ((header (gnus-summary-article-header article)))
6737 (when (< article 0)
6738 (cond
6739 ((memq article gnus-newsgroup-sparse)
6740 ;; This is a sparse gap article.
6741 (setq do-update-line article)
6742 (setq article (mail-header-id header))
16409b0b 6743 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6744 (setq gnus-newsgroup-sparse
6745 (delq article gnus-newsgroup-sparse)))
6746 ((vectorp header)
6747 ;; It's a real article.
6748 (setq article (mail-header-id header)))
6749 (t
6750 ;; It is an extracted pseudo-article.
6751 (setq article 'pseudo)
6752 (gnus-request-pseudo-article header))))
6753
6754 (let ((method (gnus-find-method-for-group
6755 gnus-newsgroup-name)))
6748645f
LMI
6756 (when (and (eq (car method) 'nneething)
6757 (vectorp header))
23f87bed
MB
6758 (let ((dir (nneething-get-file-name
6759 (mail-header-id header))))
6760 (when (and (stringp dir)
6761 (file-directory-p dir))
eec82323
LMI
6762 (setq article 'nneething)
6763 (gnus-group-enter-directory dir))))))))
6764
6765 (cond
6766 ;; Refuse to select canceled articles.
6767 ((and (numberp article)
6768 gnus-summary-buffer
6769 (get-buffer gnus-summary-buffer)
6748645f 6770 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6771 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6772 (assq article gnus-newsgroup-reads)))
6773 gnus-canceled-mark))
6774 nil)
6775 ;; We first check `gnus-original-article-buffer'.
6776 ((and (get-buffer gnus-original-article-buffer)
6777 (numberp article)
01c52d31 6778 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6779 (and (equal (car gnus-original-article) group)
6780 (eq (cdr gnus-original-article) article))))
75eda25b
SM
6781 ;; `insert-buffer-substring' would incorrectly use the
6782 ;; equivalent of string-make-multibyte which amount to decoding
6783 ;; with locale-coding-system, causing failure of
6784 ;; subsequent decoding.
6785 (insert (mm-string-to-multibyte
6786 (with-current-buffer gnus-original-article-buffer
6787 (buffer-substring (point-min) (point-max)))))
eec82323
LMI
6788 'article)
6789 ;; Check the backlog.
6790 ((and gnus-keep-backlog
6791 (gnus-backlog-request-article group article (current-buffer)))
6792 'article)
6793 ;; Check asynchronous pre-fetch.
6794 ((gnus-async-request-fetched-article group article (current-buffer))
6795 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6796 (when (and (numberp article) gnus-keep-backlog)
6797 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6798 'article)
6799 ;; Check the cache.
6800 ((and gnus-use-cache
6801 (numberp article)
6802 (gnus-cache-request-article article group))
6803 'article)
23f87bed
MB
6804 ;; Check the agent cache.
6805 ((gnus-agent-request-article article group)
6806 'article)
eec82323 6807 ;; Get the article and put into the article buffer.
16409b0b
GM
6808 ((or (stringp article)
6809 (numberp article))
6810 (let ((gnus-override-method gnus-override-method)
a1506d29 6811 (methods (and (stringp article)
16409b0b 6812 gnus-refer-article-method))
23f87bed
MB
6813 (backend (car (gnus-find-method-for-group
6814 gnus-newsgroup-name)))
16409b0b 6815 result
4e7d0221 6816 (inhibit-read-only t))
e0bad764
DL
6817 (if (or (not (listp methods))
6818 (and (symbolp (car methods))
6819 (assq (car methods) nnoo-definition-alist)))
6820 (setq methods (list methods)))
16409b0b
GM
6821 (when (and (null gnus-override-method)
6822 methods)
6823 (setq gnus-override-method (pop methods)))
6824 (while (not result)
6825 (when (eq gnus-override-method 'current)
c55f89a5
GM
6826 (setq gnus-override-method
6827 (with-current-buffer gnus-summary-buffer
6828 gnus-current-select-method)))
16409b0b
GM
6829 (erase-buffer)
6830 (gnus-kill-all-overlays)
6831 (let ((gnus-newsgroup-name group))
6832 (gnus-check-group-server))
23f87bed
MB
6833 (cond
6834 ((gnus-request-article article group (current-buffer))
16409b0b 6835 (when (numberp article)
a1506d29 6836 (gnus-async-prefetch-next group article
16409b0b
GM
6837 gnus-summary-buffer)
6838 (when gnus-keep-backlog
6839 (gnus-backlog-enter-article
6840 group article (current-buffer))))
6841 (setq result 'article))
23f87bed
MB
6842 (methods
6843 (setq gnus-override-method (pop methods)))
6844 ((not (string-match "^400 "
6845 (nnheader-get-report backend)))
6846 ;; If we get 400 server disconnect, reconnect and
6847 ;; retry; otherwise, assume the article has expired.
6848 (setq result 'done))))
16409b0b 6849 (and (eq result 'article) 'article)))
eec82323
LMI
6850 ;; It was a pseudo.
6851 (t article)))
6852
6748645f
LMI
6853 ;; Associate this article with the current summary buffer.
6854 (setq gnus-article-current-summary gnus-summary-buffer)
6855
eec82323
LMI
6856 ;; Take the article from the original article buffer
6857 ;; and place it in the buffer it's supposed to be in.
6858 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6859 (equal (buffer-name (current-buffer))
6860 (buffer-name (get-buffer gnus-article-buffer))))
6861 (save-excursion
6862 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6863 (set-buffer gnus-original-article-buffer)
6864 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6865 (buffer-disable-undo)
eec82323 6866 (setq major-mode 'gnus-original-article-mode)
6748645f 6867 (setq buffer-read-only t))
23f87bed 6868 (let ((inhibit-read-only t))
eec82323
LMI
6869 (erase-buffer)
6870 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6871 (setq gnus-original-article (cons group article)))
6872
6873 ;; Decode charsets.
6874 (run-hooks 'gnus-article-decode-hook)
6875 ;; Mark article as decoded or not.
6876 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6877
6878 ;; Update sparse articles.
6879 (when (and do-update-line
6880 (or (numberp article)
6881 (stringp article)))
6882 (let ((buf (current-buffer)))
6883 (set-buffer gnus-summary-buffer)
6748645f 6884 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6885 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6886 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6887 (point))
6888 (set-buffer buf))))))
6889
6890;;;
6891;;; Article editing
6892;;;
6893
6894(defcustom gnus-article-edit-mode-hook nil
6895 "Hook run in article edit mode buffers."
6896 :group 'gnus-article-various
6897 :type 'hook)
6898
6899(defvar gnus-article-edit-done-function nil)
6900
6901(defvar gnus-article-edit-mode-map nil)
6902
16409b0b 6903;; Should we be using derived.el for this?
eec82323 6904(unless gnus-article-edit-mode-map
23f87bed 6905 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6906 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6907
6908 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6909 "\C-c?" describe-mode
eec82323 6910 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6911 "\C-c\C-k" gnus-article-edit-exit
6912 "\C-c\C-f\C-t" message-goto-to
6913 "\C-c\C-f\C-o" message-goto-from
6914 "\C-c\C-f\C-b" message-goto-bcc
6915 ;;"\C-c\C-f\C-w" message-goto-fcc
6916 "\C-c\C-f\C-c" message-goto-cc
6917 "\C-c\C-f\C-s" message-goto-subject
6918 "\C-c\C-f\C-r" message-goto-reply-to
6919 "\C-c\C-f\C-n" message-goto-newsgroups
6920 "\C-c\C-f\C-d" message-goto-distribution
6921 "\C-c\C-f\C-f" message-goto-followup-to
6922 "\C-c\C-f\C-m" message-goto-mail-followup-to
6923 "\C-c\C-f\C-k" message-goto-keywords
6924 "\C-c\C-f\C-u" message-goto-summary
6925 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6926 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6927 "\C-c\C-b" message-goto-body
6928 "\C-c\C-i" message-goto-signature
6929
6930 "\C-c\C-t" message-insert-to
6931 "\C-c\C-n" message-insert-newsgroups
6932 "\C-c\C-o" message-sort-headers
6933 "\C-c\C-e" message-elide-region
6934 "\C-c\C-v" message-delete-not-region
6935 "\C-c\C-z" message-kill-to-signature
6936 "\M-\r" message-newline-and-reformat
6937 "\C-c\C-a" mml-attach-file
6938 "\C-a" message-beginning-of-line
6939 "\t" message-tab
6940 "\M-;" comment-region)
eec82323
LMI
6941
6942 (gnus-define-keys (gnus-article-edit-wash-map
6943 "\C-c\C-w" gnus-article-edit-mode-map)
6944 "f" gnus-article-edit-full-stops))
6945
23f87bed
MB
6946(easy-menu-define
6947 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6948 '("Field"
6949 ["Fetch To" message-insert-to t]
6950 ["Fetch Newsgroups" message-insert-newsgroups t]
6951 "----"
6952 ["To" message-goto-to t]
6953 ["From" message-goto-from t]
6954 ["Subject" message-goto-subject t]
6955 ["Cc" message-goto-cc t]
6956 ["Reply-To" message-goto-reply-to t]
6957 ["Summary" message-goto-summary t]
6958 ["Keywords" message-goto-keywords t]
6959 ["Newsgroups" message-goto-newsgroups t]
6960 ["Followup-To" message-goto-followup-to t]
6961 ["Mail-Followup-To" message-goto-mail-followup-to t]
6962 ["Distribution" message-goto-distribution t]
6963 ["Body" message-goto-body t]
6964 ["Signature" message-goto-signature t]))
6965
4e7d0221 6966(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6967 "Major mode for editing articles.
6968This is an extended text-mode.
6969
6970\\{gnus-article-edit-mode-map}"
eec82323
LMI
6971 (make-local-variable 'gnus-article-edit-done-function)
6972 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6973 (set (make-local-variable 'font-lock-defaults)
6974 '(message-font-lock-keywords t))
23f87bed
MB
6975 (set (make-local-variable 'mail-header-separator) "")
6976 (set (make-local-variable 'gnus-article-edit-mode) t)
6977 (easy-menu-add message-mode-field-menu message-mode-map)
6978 (mml-mode)
eec82323
LMI
6979 (setq buffer-read-only nil)
6980 (buffer-enable-undo)
80b47379 6981 (widen))
eec82323
LMI
6982
6983(defun gnus-article-edit (&optional force)
6984 "Edit the current article.
6985This will have permanent effect only in mail groups.
6986If FORCE is non-nil, allow editing of articles even in read-only
6987groups."
6988 (interactive "P")
6989 (when (and (not force)
6990 (gnus-group-read-only-p))
a8151ef7 6991 (error "The current newsgroup does not support article editing"))
6748645f 6992 (gnus-article-date-original)
eec82323 6993 (gnus-article-edit-article
16409b0b 6994 'ignore
6748645f 6995 `(lambda (no-highlight)
16409b0b 6996 'ignore
eec82323
LMI
6997 (gnus-summary-edit-article-done
6998 ,(or (mail-header-references gnus-current-headers) "")
6748645f 6999 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 7000
01c52d31 7001(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
7002 "Start editing the contents of the current article buffer."
7003 (let ((winconf (current-window-configuration)))
7004 (set-buffer gnus-article-buffer)
0683d241
MB
7005 (let ((message-auto-save-directory
7006 ;; Don't associate the article buffer with a draft file.
7007 nil))
7008 (gnus-article-edit-mode))
16409b0b 7009 (funcall start-func)
23f87bed 7010 (set-buffer-modified-p nil)
eec82323
LMI
7011 (gnus-configure-windows 'edit-article)
7012 (setq gnus-article-edit-done-function exit-func)
7013 (setq gnus-prev-winconf winconf)
01c52d31
MB
7014 (unless quiet
7015 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 7016
6748645f 7017(defun gnus-article-edit-done (&optional arg)
eec82323 7018 "Update the article edits and exit."
6748645f 7019 (interactive "P")
eec82323
LMI
7020 (let ((func gnus-article-edit-done-function)
7021 (buf (current-buffer))
23f87bed
MB
7022 (start (window-start))
7023 (p (point))
7024 (winconf gnus-prev-winconf))
7025 (widen) ;; Widen it in case that users narrowed the buffer.
7026 (funcall func arg)
7027 (set-buffer buf)
7028 ;; The cache and backlog have to be flushed somewhat.
7029 (when gnus-keep-backlog
7030 (gnus-backlog-remove-article
7031 (car gnus-article-current) (cdr gnus-article-current)))
7032 ;; Flush original article as well.
8ccbef23 7033 (gnus-flush-original-article-buffer)
23f87bed
MB
7034 (when gnus-use-cache
7035 (gnus-cache-update-article
7036 (car gnus-article-current) (cdr gnus-article-current)))
7037 ;; We remove all text props from the article buffer.
7038 (kill-all-local-variables)
01c52d31 7039 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
7040 (gnus-article-mode)
7041 (set-window-configuration winconf)
eec82323
LMI
7042 (set-buffer buf)
7043 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
7044 (set-window-point (get-buffer-window buf) (point)))
7045 (gnus-summary-show-article))
eec82323 7046
8ccbef23
G
7047(defun gnus-flush-original-article-buffer ()
7048 (when (get-buffer gnus-original-article-buffer)
7049 (with-current-buffer gnus-original-article-buffer
7050 (setq gnus-original-article nil))))
7051
eec82323
LMI
7052(defun gnus-article-edit-exit ()
7053 "Exit the article editing without updating."
7054 (interactive)
23f87bed
MB
7055 (when (or (not (buffer-modified-p))
7056 (yes-or-no-p "Article modified; kill anyway? "))
7057 (let ((curbuf (current-buffer))
7058 (p (point))
7059 (window-start (window-start)))
7060 (erase-buffer)
7061 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 7062 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
7063 (let ((winconf gnus-prev-winconf))
7064 (kill-all-local-variables)
7065 (gnus-article-mode)
7066 (set-window-configuration winconf)
7067 ;; Tippy-toe some to make sure that point remains where it was.
7068 (save-current-buffer
7069 (set-buffer curbuf)
7070 (set-window-start (get-buffer-window (current-buffer)) window-start)
7071 (goto-char p))))
7072 (gnus-summary-show-article)))
eec82323
LMI
7073
7074(defun gnus-article-edit-full-stops ()
7075 "Interactively repair spacing at end of sentences."
7076 (interactive)
7077 (save-excursion
7078 (goto-char (point-min))
7079 (search-forward-regexp "^$" nil t)
7080 (let ((case-fold-search nil))
7081 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7082
7083;;;
7084;;; Article highlights
7085;;;
7086
7087;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7088
7089;;; Internal Variables:
7090
a1506d29 7091(defcustom gnus-button-url-regexp
01c52d31
MB
7092 (concat
7093 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7094 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7095 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7096 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7097 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7098 (punct "!?:;.,"))
7099 (concat
7100 "\\(?:"
7101 ;; Match paired parentheses, e.g. in Wikipedia URLs:
9b3ebcb6
MB
7102 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7103 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
01c52d31
MB
7104 "\\|"
7105 "[" chars punct "]+" "[" chars "]"
7106 "\\)"))
7107 (concat ;; XEmacs 21.4 doesn't support POSIX.
7108 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7109 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7110 "\\)")
eec82323
LMI
7111 "Regular expression that matches URLs."
7112 :group 'gnus-article-buttons
7113 :type 'regexp)
7114
23f87bed
MB
7115(defcustom gnus-button-valid-fqdn-regexp
7116 message-valid-fqdn-regexp
7117 "Regular expression that matches a valid FQDN."
bf247b6e 7118 :version "22.1"
23f87bed
MB
7119 :group 'gnus-article-buttons
7120 :type 'regexp)
7121
97f78c9b
MB
7122;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7123(defcustom gnus-button-valid-localpart-regexp
14e6dc54 7124 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
7125 "Regular expression that matches a localpart of mail addresses or MIDs."
7126 :version "22.1"
7127 :group 'gnus-article-buttons
7128 :type 'regexp)
7129
23f87bed
MB
7130(defcustom gnus-button-man-handler 'manual-entry
7131 "Function to use for displaying man pages.
7132The function must take at least one argument with a string naming the
7133man page."
bf247b6e 7134 :version "22.1"
23f87bed
MB
7135 :type '(choice (function-item :tag "Man" manual-entry)
7136 (function-item :tag "Woman" woman)
7137 (function :tag "Other"))
7138 :group 'gnus-article-buttons)
7139
23f87bed 7140(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 7141 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
7142 gnus-button-valid-fqdn-regexp
7143 ">?\\)\\b")
7144 "Regular expression that matches a message ID or a mail address."
bf247b6e 7145 :version "22.1"
23f87bed
MB
7146 :group 'gnus-article-buttons
7147 :type 'regexp)
7148
7149(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7150 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7151Strings like this can be either a message ID or a mail address. If it is one
7152of the symbols `mid' or `mail', Gnus will always assume that the string is a
7153message ID or a mail address, respectively. If this variable is set to the
7154symbol `ask', always query the user what do do. If it is a function, this
aa819354 7155function will be called with the string as its only argument. The function
23f87bed 7156must return `mid', `mail', `invalid' or `ask'."
bf247b6e 7157 :version "22.1"
23f87bed
MB
7158 :group 'gnus-article-buttons
7159 :type '(choice (function-item :tag "Heuristic function"
7160 gnus-button-mid-or-mail-heuristic)
7161 (const ask)
7162 (const mid)
7163 (const mail)))
7164
7165(defcustom gnus-button-mid-or-mail-heuristic-alist
7166 '((-10.0 . ".+\\$.+@")
7167 (-10.0 . "#")
7168 (-10.0 . "\\*")
7169 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7170 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7171 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7172 (-1.0 . "^[^a-z]+@")
7173 ;;
7174 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7175 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7176 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7177 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7178 ;;
7179 (-2.0 . "^[0-9]")
7180 (-1.0 . "^[0-9][0-9]")
7181 ;;
7182 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7183 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7184 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7185 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7186 ;;
7187 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7188 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7189 ;; "[0-9]{8,}.*\@"
7190 (-3.0
7191 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7192 ;; "[0-9]{12,}.*\@"
7193 ;; compensation for TDMA dated mail addresses:
7194 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7195 ;;
7196 (-20.0 . "\\.fsf@") ;; Gnus
7197 (-20.0 . "^slrn")
7198 (-20.0 . "^Pine")
437ce4be 7199 (-20.0 . "^alpine\\.")
23f87bed
MB
7200 (-20.0 . "_-_") ;; Subject change in thread
7201 ;;
7202 (-20.0 . "\\.ln@") ;; leafnode
7203 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7204 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7205 ;;
7206 ;; (5.0 . "") ;; $local_part_len <= 7
7207 (10.0 . "^[^0-9]+@")
7208 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7209 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7210 (3.0 . "\@stud")
7211 ;;
7212 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7213 ;;
7214 (0.5 . "^[A-Z][a-z]")
7215 (0.5 . "^[A-Z][a-z][a-z]")
7216 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7217 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7218 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7219
7220A negative RATE indicates a message IDs, whereas a positive indicates a mail
7221address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7222 :version "22.1"
23f87bed
MB
7223 :group 'gnus-article-buttons
7224 :type '(repeat (cons (number :tag "Rate")
7225 (regexp :tag "Regexp"))))
7226
7227(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7228 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7229Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7230address, `ask' if unsure and `invalid' if the string is invalid."
7231 (let ((case-fold-search nil)
7232 (list gnus-button-mid-or-mail-heuristic-alist)
7233 (result 0) rate regexp lpartlen elem)
7234 (setq lpartlen
7235 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7236 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7237 ;; Certain special cases...
7238 (when (string-match
7239 (concat
7240 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7241 "^[0-9]+\\.[0-9]+@compuserve\\|"
7242 "@public\\.gmane\\.org")
7243 mid-or-mail)
7244 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7245 (setq result 'mail))
7246 (when (string-match "@.*@\\| " mid-or-mail)
7247 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7248 (setq result 'invalid))
7249 ;; Nothing more to do, if result is not a number here...
7250 (when (numberp result)
7251 (while list
7252 (setq elem (car list)
7253 rate (car elem)
7254 regexp (cdr elem)
7255 list (cdr list))
7256 (when (string-match regexp mid-or-mail)
7257 (setq result (+ result rate))
7258 (gnus-message
7259 9 "`%s' matched `%s', rate `%s', result `%s'."
7260 mid-or-mail regexp rate result)))
7261 (when (<= lpartlen 7)
7262 (setq result (+ result 5.0))
7263 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7264 mid-or-mail result))
7265 (when (>= lpartlen 12)
7266 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7267 (cond
7268 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7269 ;; Long local part should contain realname if e-mail address,
7270 ;; too many digits: message-id.
7271 ;; $score -= 5.0 + 0.1 * $local_part_len;
7272 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7273 (setq result (+ result rate))
7274 (gnus-message
7275 9 "Many digits in `%s', rate `%s', result `%s'."
7276 mid-or-mail rate result))
7277 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7278 mid-or-mail)
7279 ;; Too few vowels [^aeiouy]{4,}.*\@
7280 (setq result (+ result -5.0))
7281 (gnus-message
7282 9 "Few vowels in `%s', rate `%s', result `%s'."
7283 mid-or-mail -5.0 result))
7284 (t
7285 (setq result (+ result 5.0))
7286 (gnus-message
7287 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7288 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7289 ;; Maybe we should make this a customizable alist: (condition . 'result)
7290 (cond
7291 ((symbolp result) result)
7292 ;; Now convert number into proper results:
7293 ((< result -10.0) 'mid)
7294 ((> result 10.0) 'mail)
7295 (t 'ask))))
7296
7297(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7298 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7299 (url-mid (concat "news" ":" mid-or-mail))
7300 (url-mailto (concat "mailto" ":" mid-or-mail)))
7301 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7302 (when (fboundp pref)
7303 (setq guessed
7304 ;; get rid of surrounding angles...
7305 (funcall pref
7306 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7307 (if (or (eq 'mid guessed) (eq 'mail guessed))
7308 (setq pref guessed)
7309 (setq pref 'ask)))
7310 (if (eq pref 'ask)
7311 (save-window-excursion
7312 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7313 (setq pref 'mail)
7314 (setq pref 'mid))))
7315 (cond ((eq pref 'mid)
7316 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7317 (gnus-button-handle-news url-mid))
7318 ((eq pref 'mail)
7319 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7320 (gnus-url-mailto url-mailto))
7321 (t (gnus-message 3 "Invalid string.")))))
7322
01c52d31
MB
7323(defun gnus-button-handle-custom (fun arg)
7324 "Call function FUN on argument ARG.
7325Both FUN and ARG are supposed to be strings. ARG will be passed
7326as a symbol to FUN."
7327 (funcall (intern fun)
7328 (if (string-match "^customize-apropos" fun)
7329 arg
7330 (intern arg))))
23f87bed
MB
7331
7332(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7333
7334;; FIXME: Maybe we should merge some of the functions that do quite similar
7335;; stuff?
7336
7337(defun gnus-button-handle-describe-function (url)
7338 "Call `describe-function' when pushing the corresponding URL button."
7339 (describe-function
7340 (intern
7341 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7342
7343(defun gnus-button-handle-describe-variable (url)
7344 "Call `describe-variable' when pushing the corresponding URL button."
7345 (describe-variable
7346 (intern
7347 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7348
7349(defun gnus-button-handle-symbol (url)
7350"Display help on variable or function.
7351Calls `describe-variable' or `describe-function'."
7352 (let ((sym (intern url)))
7353 (cond
7354 ((fboundp sym) (describe-function sym))
7355 ((boundp sym) (describe-variable sym))
7356 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7357
7358(defun gnus-button-handle-describe-key (url)
7359 "Call `describe-key' when pushing the corresponding URL button."
7360 (let* ((key-string
7361 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7362 (keys (ignore-errors (eval `(kbd ,key-string)))))
7363 (if keys
7364 (describe-key keys)
7365 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7366
7367(defun gnus-button-handle-apropos (url)
7368 "Call `apropos' when pushing the corresponding URL button."
7369 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7370
7371(defun gnus-button-handle-apropos-command (url)
7372 "Call `apropos' when pushing the corresponding URL button."
7373 (apropos-command
7374 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7375
7376(defun gnus-button-handle-apropos-variable (url)
7377 "Call `apropos' when pushing the corresponding URL button."
7378 (funcall
7379 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7380 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7381
7382(defun gnus-button-handle-apropos-documentation (url)
7383 "Call `apropos' when pushing the corresponding URL button."
7384 (funcall
7385 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7386 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7387
7388(defun gnus-button-handle-library (url)
7389 "Call `locate-library' when pushing the corresponding URL button."
7390 (gnus-message 9 "url=`%s'" url)
7391 (let* ((lib (locate-library url))
7392 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7393 (if (not lib)
7394 (gnus-message 1 "Cannot locale library `%s'." url)
7395 (find-file-read-only file))))
7396
23f87bed
MB
7397(defcustom gnus-button-man-level 5
7398 "*Integer that says how many man-related buttons Gnus will show.
7399The higher the number, the more buttons will appear and the more false
7400positives are possible. Note that you can set this variable local to
7401specific groups. Setting it higher in Unix groups is probably a good idea.
7402See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7403how to set variables in specific groups."
bf247b6e 7404 :version "22.1"
23f87bed
MB
7405 :group 'gnus-article-buttons
7406 :link '(custom-manual "(gnus)Group Parameters")
7407 :type 'integer)
7408
7409(defcustom gnus-button-emacs-level 5
7410 "*Integer that says how many emacs-related buttons Gnus will show.
7411The higher the number, the more buttons will appear and the more false
7412positives are possible. Note that you can set this variable local to
7413specific groups. Setting it higher in Emacs or Gnus related groups is
7414probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7415`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7416 :version "22.1"
23f87bed
MB
7417 :group 'gnus-article-buttons
7418 :link '(custom-manual "(gnus)Group Parameters")
7419 :type 'integer)
7420
7421(defcustom gnus-button-message-level 5
7422 "*Integer that says how many buttons for news or mail messages will appear.
7423The higher the number, the more buttons will appear and the more false
7424positives are possible."
7425 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7426 :version "22.1"
23f87bed
MB
7427 :group 'gnus-article-buttons
7428 :type 'integer)
7429
7430(defcustom gnus-button-browse-level 5
7431 "*Integer that says how many buttons for browsing will appear.
7432The higher the number, the more buttons will appear and the more false
7433positives are possible."
7434 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7435 :version "22.1"
23f87bed
MB
7436 :group 'gnus-article-buttons
7437 :type 'integer)
7438
eec82323 7439(defcustom gnus-button-alist
23f87bed
MB
7440 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7441 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7442 ((concat "\\b\\(nntp\\|news\\):\\("
7443 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7444 0 t gnus-button-handle-news 2)
23f87bed
MB
7445 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7446 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7447 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7448 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7449 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7450 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7451 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7452 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7453 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7454 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7455 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7456 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7457 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7458 ;; RFC 2368 (The mailto URL scheme)
531e5812 7459 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7460 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7461 ("\\bmailto:\\([^ \n\t]+\\)"
7462 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
9eb59592
MB
7463 ;; Info Konqueror style <info:/foo/bar baz>.
7464 ;; Must come before " Gnus home-grown style".
7465 ("\\binfo://?\\([^'\">\n\t]+\\)"
7466 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7467 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
23f87bed
MB
7468 ("\\binfo://\\([^'\">\n\t ]+\\)"
7469 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7470 ;; Info GNOME style <info:foo#bar_baz>
7471 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7472 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7473 ;; Info KDE style <info:(foo)bar baz>
7474 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7475 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7476 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7477 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
9b3ebcb6
MB
7478 ("\\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,]*\\)\\)?"
7479 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7480 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
23f87bed 7481 ;; This is custom
01c52d31
MB
7482 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7483 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed
MB
7484 ;; Emacs help commands
7485 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7486 ;; regexp doesn't match arguments containing ` '.
7487 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7488 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7489 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7490 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7491 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7492 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7493 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7494 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7495 ;; them by default (use a high button level).
7496 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7497 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7498 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7499 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7500 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7501 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7502 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7503 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7504 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7505 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7506 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7507 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7508 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7509 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7510 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7511 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7512 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7513 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7514 ;; Unlike the other regexps we really have to require quoting
7515 ;; here to determine where it ends.
7516 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7517 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7518 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7519 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7520 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7521 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7522 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7523 ;; Raw URLs.
23f87bed
MB
7524 (gnus-button-url-regexp
7525 0 (>= gnus-button-browse-level 0) browse-url 0)
7526 ;; man pages
531e5812 7527 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7528 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7529 gnus-button-handle-man 1)
7530 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7531 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7532 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7533 gnus-button-handle-man 1)
7534 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7535 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7536 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7537 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7538 ;; Recognizing patches to .el files. This is somewhat obscure,
7539 ;; but considering the percentage of Gnus users who hack Emacs
7540 ;; Lisp files...
7541 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7542 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7543 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7544 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7545 ;; MID or mail: To avoid too many false positives we don't try to catch
7546 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7547 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7548 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7549 ;; so that non-ambiguous entries (see above) match first.
7550 (gnus-button-mid-or-mail-regexp
7551 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7552 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7553
7554Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7555REGEXP: is the string (case insensitive) matching text around the button (can
7556also be Lisp expression evaluating to a string),
eec82323 7557BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7558FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7559be added,
7560CALLBACK: is the function to call when the user push this button, and each
7561PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7562
7563CALLBACK can also be a variable, in that case the value of that
7564variable it the real callback function."
7565 :group 'gnus-article-buttons
23f87bed 7566 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7567 (integer :tag "Button")
7568 (sexp :tag "Form")
7569 (function :tag "Callback")
7570 (repeat :tag "Par"
7571 :inline t
7572 (integer :tag "Regexp group")))))
60ece9b0 7573(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7574
7575(defcustom gnus-header-button-alist
23f87bed
MB
7576 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7577 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7578 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7579 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7580 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7581 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7582 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7583 0 (>= gnus-button-browse-level 0) browse-url 0)
7584 ("^Subject:" gnus-button-url-regexp
7585 0 (>= gnus-button-browse-level 0) browse-url 0)
7586 ("^[^:]+:" gnus-button-url-regexp
7587 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7588 ("^OpenPGP:.*url=" gnus-button-url-regexp
7589 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7590 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7591 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7592 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7593 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7594 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7595
7596This alist is very similar to `gnus-button-alist', except that each
7597alist has an additional HEADER element first in each entry:
7598
7599\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7600
7601HEADER is a regexp to match a header. For a fuller explanation, see
7602`gnus-button-alist'."
7603 :group 'gnus-article-buttons
7604 :group 'gnus-article-headers
7605 :type '(repeat (list (regexp :tag "Header")
23f87bed 7606 (choice regexp variable)
eec82323
LMI
7607 (integer :tag "Button")
7608 (sexp :tag "Form")
7609 (function :tag "Callback")
7610 (repeat :tag "Par"
7611 :inline t
7612 (integer :tag "Regexp group")))))
60ece9b0 7613(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7614
eec82323
LMI
7615;;; Commands:
7616
7617(defun gnus-article-push-button (event)
7618 "Check text under the mouse pointer for a callback function.
7619If the text under the mouse pointer has a `gnus-callback' property,
7620call it with the value of the `gnus-data' text property."
7621 (interactive "e")
7622 (set-buffer (window-buffer (posn-window (event-start event))))
7623 (let* ((pos (posn-point (event-start event)))
23f87bed 7624 (data (get-text-property pos 'gnus-data))
eec82323 7625 (fun (get-text-property pos 'gnus-callback)))
6748645f 7626 (goto-char pos)
eec82323
LMI
7627 (when fun
7628 (funcall fun data))))
7629
7630(defun gnus-article-press-button ()
7631 "Check text at point for a callback function.
7632If the text at point has a `gnus-callback' property,
7633call it with the value of the `gnus-data' text property."
7634 (interactive)
23f87bed
MB
7635 (let ((data (get-text-property (point) 'gnus-data))
7636 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7637 (when fun
7638 (funcall fun data))))
7639
eec82323
LMI
7640(defun gnus-article-highlight (&optional force)
7641 "Highlight current article.
7642This function calls `gnus-article-highlight-headers',
7643`gnus-article-highlight-citation',
7644`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7645do the highlighting. See the documentation for those functions."
7646 (interactive (list 'force))
7647 (gnus-article-highlight-headers)
7648 (gnus-article-highlight-citation force)
7649 (gnus-article-highlight-signature)
7650 (gnus-article-add-buttons force)
7651 (gnus-article-add-buttons-to-head))
7652
7653(defun gnus-article-highlight-some (&optional force)
7654 "Highlight current article.
7655This function calls `gnus-article-highlight-headers',
7656`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7657do the highlighting. See the documentation for those functions."
7658 (interactive (list 'force))
7659 (gnus-article-highlight-headers)
7660 (gnus-article-highlight-signature)
7661 (gnus-article-add-buttons))
7662
7663(defun gnus-article-highlight-headers ()
7664 "Highlight article headers as specified by `gnus-header-face-alist'."
7665 (interactive)
01c52d31
MB
7666 (gnus-with-article-headers
7667 (let (regexp header-face field-face from hpoints fpoints)
7668 (dolist (entry gnus-header-face-alist)
7669 (goto-char (point-min))
7670 (setq regexp (concat "^\\("
7671 (if (string-equal "" (nth 0 entry))
7672 "[^\t ]"
7673 (nth 0 entry))
7674 "\\)")
7675 header-face (nth 1 entry)
7676 field-face (nth 2 entry))
7677 (while (and (re-search-forward regexp nil t)
7678 (not (eobp)))
7679 (beginning-of-line)
7680 (setq from (point))
7681 (unless (search-forward ":" nil t)
7682 (forward-char 1))
7683 (when (and header-face
7684 (not (memq (point) hpoints)))
7685 (push (point) hpoints)
7686 (gnus-put-text-property from (point) 'face header-face))
7687 (when (and field-face
7688 (not (memq (setq from (point)) fpoints)))
7689 (push from fpoints)
7690 (if (re-search-forward "^[^ \t]" nil t)
7691 (forward-char -2)
7692 (goto-char (point-max)))
7693 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7694
7695(defun gnus-article-highlight-signature ()
7696 "Highlight the signature in an article.
7697It does this by highlighting everything after
0f49874b 7698`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7699 (interactive)
01c52d31
MB
7700 (gnus-with-article-buffer
7701 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7702 (save-restriction
7703 (when (and gnus-signature-face
7704 (gnus-article-narrow-to-signature))
01c52d31 7705 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7706 'face gnus-signature-face)
7707 (widen)
7708 (gnus-article-search-signature)
7709 (let ((start (match-beginning 0))
7710 (end (set-marker (make-marker) (1+ (match-end 0)))))
7711 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7712 end)))))))
7713
7714(defun gnus-button-in-region-p (b e prop)
7715 "Say whether PROP exists in the region."
7716 (text-property-not-all b e prop nil))
7717
7718(defun gnus-article-add-buttons (&optional force)
7719 "Find external references in the article and make buttons of them.
7720\"External references\" are things like Message-IDs and URLs, as
7721specified by `gnus-button-alist'."
7722 (interactive (list 'force))
01c52d31
MB
7723 (gnus-with-article-buffer
7724 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7725 (case-fold-search t)
7726 (alist gnus-button-alist)
7727 beg entry regexp)
7728 ;; Remove all old markers.
16409b0b 7729 (let (marker entry new-list)
eec82323 7730 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
7731 (if (or (< marker (point-min)) (>= marker (point-max)))
7732 (push marker new-list)
7733 (goto-char marker)
7734 (when (setq entry (gnus-button-entry))
7735 (put-text-property (match-beginning (nth 1 entry))
7736 (match-end (nth 1 entry))
7737 'gnus-callback nil))
7738 (set-marker marker nil)))
7739 (setq gnus-button-marker-list new-list))
eec82323 7740 ;; We skip the headers.
16409b0b 7741 (article-goto-body)
eec82323
LMI
7742 (setq beg (point))
7743 (while (setq entry (pop alist))
23f87bed 7744 (setq regexp (eval (car entry)))
eec82323
LMI
7745 (goto-char beg)
7746 (while (re-search-forward regexp nil t)
01c52d31
MB
7747 (let ((start (match-beginning (nth 1 entry)))
7748 (end (match-end (nth 1 entry)))
7749 (from (match-beginning 0)))
eec82323
LMI
7750 (when (and (or (eq t (nth 2 entry))
7751 (eval (nth 2 entry)))
7752 (not (gnus-button-in-region-p
7753 start end 'gnus-callback)))
7754 ;; That optional form returned non-nil, so we add the
7755 ;; button.
01c52d31
MB
7756 (setq from (set-marker (make-marker) from))
7757 (push from gnus-button-marker-list)
7758 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7759 (gnus-article-extend-url-button from start end))
7760 (gnus-article-add-button start end
7426b4f7
LMI
7761 'gnus-button-push from)
7762 (gnus-put-text-property
7763 start end
10e91ca9
LMI
7764 'gnus-string (buffer-substring-no-properties
7765 start end))))))))))
01c52d31
MB
7766
7767(defun gnus-article-extend-url-button (beg start end)
7768 "Extend url button if url is folded into two or more lines.
7769Return non-nil if button is extended. BEG is a marker that points to
7770the beginning position of a text containing url. START and END are
7771the endpoints of a url button before it is extended. The concatenated
7772url is put as the `gnus-button-url' overlay property on the button."
7773 (let ((opoint (point))
7774 (points (list start end))
7775 url delim regexp)
7776 (prog1
7777 (when (and (progn
7778 (goto-char end)
7779 (not (looking-at "[\t ]*[\">]")))
7780 (progn
7781 (goto-char start)
7782 (string-match
7783 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7784 (buffer-substring (point-at-bol) start)))
7785 (progn
7786 (setq url (list (buffer-substring start end))
7787 delim (if (match-beginning 1) ">" "\""))
7788 (beginning-of-line)
7789 (setq regexp (concat
7790 (when (and (looking-at
7791 message-cite-prefix-regexp)
7792 (< (match-end 0) start))
7793 (regexp-quote (match-string 0)))
7794 "\
7795\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7796 delim "\\)"))
7797 (while (progn
7798 (forward-line 1)
7799 (and (looking-at regexp)
7800 (prog1
7801 (match-beginning 1)
7802 (push (or (match-string 2)
7803 (match-string 1))
7804 url)
7805 (push (setq end (or (match-end 2)
7806 (match-end 1)))
7807 points)
7808 (push (or (match-beginning 2)
7809 (match-beginning 1))
7810 points)))))
7811 (match-beginning 2)))
7812 (let (gnus-article-mouse-face widget-mouse-face)
7813 (while points
7814 (gnus-article-add-button (pop points) (pop points)
7815 'gnus-button-push beg)))
7816 (let ((overlay (gnus-make-overlay start end)))
7817 (gnus-overlay-put overlay 'evaporate t)
7818 (gnus-overlay-put overlay 'gnus-button-url
7819 (list (mapconcat 'identity (nreverse url) "")))
7820 (when gnus-article-mouse-face
7821 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7822 t)
7823 (goto-char opoint))))
eec82323
LMI
7824
7825;; Add buttons to the head of an article.
7826(defun gnus-article-add-buttons-to-head ()
7827 "Add buttons to the head of the article."
7828 (interactive)
01c52d31
MB
7829 (gnus-with-article-headers
7830 (let (beg end)
7831 (dolist (entry gnus-header-button-alist)
7832 ;; Each alist entry.
7833 (goto-char (point-min))
7834 (while (re-search-forward (car entry) nil t)
7835 ;; Each header matching the entry.
7836 (setq beg (match-beginning 0))
7837 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7838 (match-beginning 0))
7839 (point-max)))
7840 (goto-char beg)
7841 (while (re-search-forward (eval (nth 1 entry)) end t)
7842 ;; Each match within a header.
7843 (let* ((entry (cdr entry))
7844 (start (match-beginning (nth 1 entry)))
7845 (end (match-end (nth 1 entry)))
7846 (form (nth 2 entry)))
7847 (goto-char (match-end 0))
7848 (when (eval form)
7849 (gnus-article-add-button
7850 start end (nth 3 entry)
7851 (buffer-substring (match-beginning (nth 4 entry))
7852 (match-end (nth 4 entry)))))))
7853 (goto-char end))))))
eec82323
LMI
7854
7855;;; External functions:
7856
b1992461 7857(defun gnus-article-add-button (from to fun &optional data text)
eec82323
LMI
7858 "Create a button between FROM and TO with callback FUN and data DATA."
7859 (when gnus-article-button-face
01c52d31 7860 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7861 'face gnus-article-button-face))
7862 (gnus-add-text-properties
7863 from to
7864 (nconc (and gnus-article-mouse-face
7865 (list gnus-mouse-face-prop gnus-article-mouse-face))
7866 (list 'gnus-callback fun)
16409b0b
GM
7867 (and data (list 'gnus-data data))))
7868 (widget-convert-button 'link from to :action 'gnus-widget-press-button
b1992461 7869 :help-echo (or text "Follow the link")
7426b4f7 7870 :keymap gnus-url-button-map
16409b0b 7871 :button-keymap gnus-widget-button-keymap))
eec82323 7872
7426b4f7
LMI
7873(defun gnus-article-copy-string ()
7874 "Copy the string in the button to the kill ring."
7875 (interactive)
7876 (gnus-article-check-buffer)
10e91ca9 7877 (let ((data (get-text-property (point) 'gnus-string)))
7426b4f7
LMI
7878 (when data
7879 (with-temp-buffer
7880 (insert data)
c25d60ab
LMI
7881 (copy-region-as-kill (point-min) (point-max))
7882 (message "Copied %s" data)))))
7426b4f7 7883
eec82323
LMI
7884;;; Internal functions:
7885
a8151ef7 7886(defun gnus-article-set-globals ()
01c52d31 7887 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7888 (gnus-set-global-variables)))
7889
eec82323 7890(defun gnus-signature-toggle (end)
01c52d31
MB
7891 (gnus-with-article-buffer
7892 (let ((inhibit-point-motion-hooks t))
520aa572 7893 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7894 (progn
7895 (gnus-delete-wash-type 'signature)
7896 (gnus-remove-text-properties-when
7897 'article-type 'signature end (point-max)
7898 (cons 'article-type (cons 'signature
7899 gnus-hidden-properties))))
7900 (gnus-add-wash-type 'signature)
520aa572
SZ
7901 (gnus-add-text-properties-when
7902 'article-type nil end (point-max)
7903 (cons 'article-type (cons 'signature
23f87bed
MB
7904 gnus-hidden-properties)))))
7905 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7906 (gnus-set-mode-line 'article))))
eec82323
LMI
7907
7908(defun gnus-button-entry ()
7909 ;; Return the first entry in `gnus-button-alist' matching this place.
7910 (let ((alist gnus-button-alist)
7911 (entry nil))
7912 (while alist
7913 (setq entry (pop alist))
23f87bed 7914 (if (looking-at (eval (car entry)))
eec82323
LMI
7915 (setq alist nil)
7916 (setq entry nil)))
7917 entry))
7918
7919(defun gnus-button-push (marker)
7920 ;; Push button starting at MARKER.
7921 (save-excursion
eec82323
LMI
7922 (goto-char marker)
7923 (let* ((entry (gnus-button-entry))
7924 (inhibit-point-motion-hooks t)
7925 (fun (nth 3 entry))
01c52d31
MB
7926 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7927 (get-char-property marker 'gnus-button-url))
7928 (mapcar (lambda (group)
7929 (let ((string (match-string group)))
7930 (set-text-properties
7931 0 (length string) nil string)
7932 string))
7933 (nthcdr 4 entry)))))
eec82323
LMI
7934 (cond
7935 ((fboundp fun)
7936 (apply fun args))
7937 ((and (boundp fun)
7938 (fboundp (symbol-value fun)))
7939 (apply (symbol-value fun) args))
7940 (t
7941 (gnus-message 1 "You must define `%S' to use this button"
7942 (cons fun args)))))))
7943
23f87bed 7944(defun gnus-parse-news-url (url)
82a8ad04 7945 (let (scheme server port group message-id articles)
23f87bed
MB
7946 (with-temp-buffer
7947 (insert url)
7948 (goto-char (point-min))
7949 (when (looking-at "\\([A-Za-z]+\\):")
7950 (setq scheme (match-string 1))
7951 (goto-char (match-end 0)))
82a8ad04 7952 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7953 (setq server (match-string 1))
82a8ad04
MB
7954 (setq port (if (stringp (match-string 3))
7955 (string-to-number (match-string 3))
7956 (match-string 3)))
23f87bed
MB
7957 (goto-char (match-end 0)))
7958
7959 (cond
7960 ((looking-at "\\(.*@.*\\)")
7961 (setq message-id (match-string 1)))
7962 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7963 (setq group (match-string 1)
7964 articles (split-string (match-string 2) "-")))
7965 ((looking-at "\\([^/]+\\)/?")
7966 (setq group (match-string 1)))
7967 (t
7968 (error "Unknown news URL syntax"))))
82a8ad04 7969 (list scheme server port group message-id articles)))
23f87bed
MB
7970
7971(defun gnus-button-handle-news (url)
7972 "Fetch a news URL."
82a8ad04 7973 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7974 (gnus-parse-news-url url)
7975 (cond
7976 (message-id
80de1778 7977 (with-current-buffer gnus-summary-buffer
23f87bed 7978 (if server
ff4d3926
MB
7979 (let ((gnus-refer-article-method
7980 (nconc (list (list 'nntp server))
7981 gnus-refer-article-method))
82a8ad04 7982 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7983 (gnus-message 7 "Fetching %s with %s"
7984 message-id gnus-refer-article-method)
23f87bed
MB
7985 (gnus-summary-refer-article message-id))
7986 (gnus-summary-refer-article message-id))))
7987 (group
7988 (gnus-button-fetch-group url)))))
7989
01c52d31
MB
7990(defun gnus-button-patch (library line)
7991 "Visit an Emacs Lisp library LIBRARY on line LINE."
7992 (interactive)
7993 (let ((file (locate-library (file-name-nondirectory library))))
7994 (unless file
7995 (error "Couldn't find library %s" library))
7996 (find-file file)
5dcc825f
GM
7997 (goto-char (point-min))
7998 (forward-line (1- (string-to-number line)))))
01c52d31 7999
23f87bed
MB
8000(defun gnus-button-handle-man (url)
8001 "Fetch a man page."
531e5812
MB
8002 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8003 (when (eq gnus-button-man-handler 'woman)
8004 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8005 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
8006 (funcall gnus-button-man-handler url))
8007
8008(defun gnus-button-handle-info-url (url)
8009 "Fetch an info URL."
8010 (setq url (mm-subst-char-in-string ?+ ?\ url))
8011 (cond
8012 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8013 (gnus-info-find-node
8014 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8015 "Gnus")
8016 ")" (gnus-url-unhex-string (match-string 2 url)))))
8017 ((string-match "([^)\"]+)[^\"]+" url)
8018 (setq url
8019 (gnus-replace-in-string
8020 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8021 (gnus-info-find-node url))
8022 (t (error "Can't parse %s" url))))
8023
8024(defun gnus-button-handle-info-url-gnome (url)
8025 "Fetch GNOME style info URL."
8026 (setq url (mm-subst-char-in-string ?_ ?\ url))
8027 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8028 (gnus-info-find-node
8029 (concat "("
bf247b6e 8030 (gnus-url-unhex-string
23f87bed
MB
8031 (match-string 1 url))
8032 ")"
bf247b6e 8033 (or (gnus-url-unhex-string
23f87bed
MB
8034 (match-string 2 url))
8035 "Top")))
8036 (error "Can't parse %s" url)))
8037
8038(defun gnus-button-handle-info-url-kde (url)
8039 "Fetch KDE style info URL."
8040 (gnus-info-find-node (gnus-url-unhex-string url)))
8041
9640c3bc
GM
8042;; (info) will autoload info.el
8043(declare-function Info-menu "info" (menu-item &optional fork))
9b3ebcb6 8044(declare-function Info-index-next "info" (num))
9640c3bc 8045
23f87bed
MB
8046(defun gnus-button-handle-info-keystrokes (url)
8047 "Call `info' when pushing the corresponding URL button."
9b3ebcb6
MB
8048 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8049 (let (node indx comma)
8050 (if (string-match
8051 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8052 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8053 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
8054 "\\(?:[ \t\n,]*\\)\\)?")
8055 url)
8056 (setq node (match-string 2 url)
8057 indx (match-string 3 url))
8058 (error "Can't parse %s" url))
8059 (info)
8060 (Info-directory)
8061 (Info-menu node)
8062 (when (> (length indx) 0)
8063 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8064 "\\([ \t\n,]*\\)")
8065 indx)
8066 (setq comma (match-string 2 indx))
8067 (setq indx (match-string 1 indx))
8068 (Info-index indx)
8069 (when comma
8070 (dotimes (i (with-temp-buffer
8071 (insert comma)
8072 ;; Note: the XEmacs version of `how-many' takes
8073 ;; no optional argument.
8074 (goto-char (point-min))
8075 (how-many ",")))
8076 (Info-index-next 1)))
8077 nil)))
1888e568
GM
8078
8079;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8080(declare-function pgg-display-output-buffer "pgg" (start end status))
23f87bed 8081
01c52d31
MB
8082(defun gnus-button-openpgp (url)
8083 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8084 (with-temp-buffer
8085 (mm-url-insert-file-contents-external url)
8086 (pgg-snarf-keys-region (point-min) (point-max))
8087 (pgg-display-output-buffer nil nil nil)))
8088
eec82323
LMI
8089(defun gnus-button-message-id (message-id)
8090 "Fetch MESSAGE-ID."
01c52d31 8091 (with-current-buffer gnus-summary-buffer
eec82323
LMI
8092 (gnus-summary-refer-article message-id)))
8093
01c52d31 8094(defun gnus-button-fetch-group (address &rest ignore)
eec82323 8095 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
8096 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8097 address)
8098 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8099 ;; for nntp:// and news://
8100 (setq address (match-string 3 address)))
eec82323
LMI
8101 (if (not (string-match "[:/]" address))
8102 ;; This is just a simple group url.
8103 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
8104 (if (not
8105 (string-match
8106 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8107 address))
eec82323
LMI
8108 (error "Can't parse %s" address)
8109 (gnus-group-read-ephemeral-group
8110 (match-string 4 address)
8111 `(nntp ,(match-string 1 address)
8112 (nntp-address ,(match-string 1 address))
8113 (nntp-port-number ,(if (match-end 3)
8114 (match-string 3 address)
23f87bed
MB
8115 "nntp")))
8116 nil nil nil
e9bd5782 8117 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 8118
eec82323
LMI
8119(defun gnus-url-parse-query-string (query &optional downcase)
8120 (let (retval pairs cur key val)
16409b0b 8121 (setq pairs (split-string query "&"))
eec82323
LMI
8122 (while pairs
8123 (setq cur (car pairs)
23f87bed 8124 pairs (cdr pairs))
eec82323 8125 (if (not (string-match "=" cur))
23f87bed
MB
8126 nil ; Grace
8127 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8128 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8129 (if downcase
8130 (setq key (downcase key)))
8131 (setq cur (assoc key retval))
8132 (if cur
8133 (setcdr cur (cons val (cdr cur)))
8134 (setq retval (cons (list key val) retval)))))
eec82323
LMI
8135 retval))
8136
eec82323
LMI
8137(defun gnus-url-mailto (url)
8138 ;; Send mail to someone
8139 (when (string-match "mailto:/*\\(.*\\)" url)
8140 (setq url (substring url (match-beginning 1) nil)))
6748645f 8141 (let (to args subject func)
23f87bed
MB
8142 (setq args (gnus-url-parse-query-string
8143 (if (string-match "^\\?" url)
8144 (substring url 1)
8145 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8146 (concat "to=" (match-string 1 url) "&"
8147 (match-string 2 url))
8148 (concat "to=" url)))
8149 t)
8150 subject (cdr-safe (assoc "subject" args)))
8151 (gnus-msg-mail)
eec82323
LMI
8152 (while args
8153 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8154 (if (fboundp func)
23f87bed
MB
8155 (funcall func)
8156 (message-position-on-field (caar args)))
8157 (insert (gnus-replace-in-string
8158 (mapconcat 'identity (reverse (cdar args)) ", ")
8159 "\r\n" "\n" t))
eec82323
LMI
8160 (setq args (cdr args)))
8161 (if subject
23f87bed 8162 (message-goto-body)
eec82323
LMI
8163 (message-goto-subject))))
8164
eec82323 8165(defun gnus-button-embedded-url (address)
e0bad764 8166 "Activate ADDRESS with `browse-url'."
1b978bfc 8167 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
8168
8169;;; Next/prev buttons in the article buffer.
8170
8171(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8172(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8173
23f87bed
MB
8174(defvar gnus-prev-page-map
8175 (let ((map (make-sparse-keymap)))
23f87bed
MB
8176 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8177 (define-key map "\r" 'gnus-button-prev-page)
8178 map))
8179
8180(defvar gnus-next-page-map
8181 (let ((map (make-sparse-keymap)))
23f87bed
MB
8182 (define-key map gnus-mouse-2 'gnus-button-next-page)
8183 (define-key map "\r" 'gnus-button-next-page)
8184 map))
eec82323
LMI
8185
8186(defun gnus-insert-prev-page-button ()
01c52d31 8187 (let ((b (point)) e
23f87bed 8188 (inhibit-read-only t))
eec82323
LMI
8189 (gnus-eval-format
8190 gnus-prev-page-line-format nil
01c52d31
MB
8191 `(keymap ,gnus-prev-page-map
8192 gnus-prev t
8193 gnus-callback gnus-article-button-prev-page
8194 article-type annotation))
8195 (setq e (if (bolp)
8196 ;; Exclude a newline.
8197 (1- (point))
8198 (point)))
8199 (when gnus-article-button-face
8200 (gnus-overlay-put (gnus-make-overlay b e nil t)
8201 'face gnus-article-button-face))
23f87bed 8202 (widget-convert-button
01c52d31 8203 'link b e
23f87bed
MB
8204 :action 'gnus-button-prev-page
8205 :button-keymap gnus-prev-page-map)))
8206
8207(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8208 "Go to the next page."
8209 (interactive)
8210 (let ((win (selected-window)))
23f87bed 8211 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8212 (gnus-article-next-page)
8213 (select-window win)))
8214
23f87bed 8215(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8216 "Go to the prev page."
8217 (interactive)
8218 (let ((win (selected-window)))
23f87bed 8219 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8220 (gnus-article-prev-page)
8221 (select-window win)))
8222
8223(defun gnus-insert-next-page-button ()
01c52d31 8224 (let ((b (point)) e
23f87bed 8225 (inhibit-read-only t))
eec82323 8226 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8227 `(keymap ,gnus-next-page-map
8228 gnus-next t
8229 gnus-callback gnus-article-button-next-page
8230 article-type annotation))
8231 (setq e (if (bolp)
8232 ;; Exclude a newline.
8233 (1- (point))
8234 (point)))
8235 (when gnus-article-button-face
8236 (gnus-overlay-put (gnus-make-overlay b e nil t)
8237 'face gnus-article-button-face))
23f87bed 8238 (widget-convert-button
01c52d31 8239 'link b e
23f87bed
MB
8240 :action 'gnus-button-next-page
8241 :button-keymap gnus-next-page-map)))
eec82323
LMI
8242
8243(defun gnus-article-button-next-page (arg)
8244 "Go to the next page."
8245 (interactive "P")
8246 (let ((win (selected-window)))
23f87bed 8247 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8248 (gnus-article-next-page)
8249 (select-window win)))
8250
8251(defun gnus-article-button-prev-page (arg)
8252 "Go to the prev page."
8253 (interactive "P")
8254 (let ((win (selected-window)))
23f87bed 8255 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8256 (gnus-article-prev-page)
8257 (select-window win)))
8258
16409b0b
GM
8259(defvar gnus-decode-header-methods
8260 '(mail-decode-encoded-word-region)
8261 "List of methods used to decode headers.
8262
8263This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8264is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8265\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8266whose names match REGEXP.
8267
8268For example:
8f688cb0 8269\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8270 mail-decode-encoded-word-region
8271 (\"chinese\" . rfc1843-decode-region))
8272")
8273
8274(defvar gnus-decode-header-methods-cache nil)
8275
8276(defun gnus-multi-decode-header (start end)
8277 "Apply the functions from `gnus-encoded-word-methods' that match."
8278 (unless (and gnus-decode-header-methods-cache
8279 (eq gnus-newsgroup-name
8280 (car gnus-decode-header-methods-cache)))
8281 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8282 (dolist (x gnus-decode-header-methods)
8283 (if (symbolp x)
8284 (nconc gnus-decode-header-methods-cache (list x))
8285 (if (and gnus-newsgroup-name
8286 (string-match (car x) gnus-newsgroup-name))
8287 (nconc gnus-decode-header-methods-cache
8288 (list (cdr x)))))))
16409b0b
GM
8289 (let ((xlist gnus-decode-header-methods-cache))
8290 (pop xlist)
8291 (save-restriction
8292 (narrow-to-region start end)
8293 (while xlist
8294 (funcall (pop xlist) (point-min) (point-max))))))
8295
8296;;;
8297;;; Treatment top-level handling.
8298;;;
8299
8300(defun gnus-treat-article (condition &optional part-number total-parts type)
8301 (let ((length (- (point-max) (point-min)))
8302 (alist gnus-treatment-function-alist)
8303 (article-goto-body-goes-to-point-min-p t)
8304 (treated-type
8305 (or (not type)
8306 (catch 'found
8307 (let ((list gnus-article-treat-types))
8308 (while list
8309 (when (string-match (pop list) type)
8310 (throw 'found t)))))))
8311 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8312 val elem)
8313 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8314 (dolist (elem alist)
16409b0b
GM
8315 (setq val
8316 (save-excursion
23f87bed
MB
8317 (when (gnus-buffer-live-p gnus-summary-buffer)
8318 (set-buffer gnus-summary-buffer))
16409b0b
GM
8319 (symbol-value (car elem))))
8320 (when (and (or (consp val)
8321 treated-type)
8322 (gnus-treat-predicate val)
8323 (or (not (get (car elem) 'highlight))
8324 highlightp))
8325 (save-restriction
8326 (funcall (cadr elem)))))))
8327
8328;; Dynamic variables.
9efa445f
DN
8329(defvar part-number)
8330(defvar total-parts)
8331(defvar type)
8332(defvar condition)
8333(defvar length)
e0bad764 8334
16409b0b
GM
8335(defun gnus-treat-predicate (val)
8336 (cond
8337 ((null val)
8338 nil)
23f87bed
MB
8339 (condition
8340 (eq condition val))
16409b0b
GM
8341 ((and (listp val)
8342 (stringp (car val)))
8343 (apply 'gnus-or (mapcar `(lambda (s)
8344 (string-match s ,(or gnus-newsgroup-name "")))
8345 val)))
8346 ((listp val)
8347 (let ((pred (pop val)))
8348 (cond
8349 ((eq pred 'or)
8350 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8351 ((eq pred 'and)
8352 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8353 ((eq pred 'not)
8354 (not (gnus-treat-predicate (car val))))
8355 ((eq pred 'typep)
8356 (equal (car val) type))
8357 (t
8358 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8359 ((eq val t)
8360 t)
8361 ((eq val 'head)
8362 nil)
01c52d31
MB
8363 ((eq val 'first)
8364 (eq part-number 1))
16409b0b
GM
8365 ((eq val 'last)
8366 (eq part-number total-parts))
8367 ((numberp val)
8368 (< length val))
8369 (t
8370 (error "%S is not a valid value" val))))
8371
23f87bed
MB
8372(defun gnus-article-encrypt-body (protocol &optional n)
8373 "Encrypt the article body."
8374 (interactive
8375 (list
8376 (or gnus-article-encrypt-protocol
229b59da
G
8377 (gnus-completing-read "Encrypt protocol"
8378 (mapcar 'car gnus-article-encrypt-protocol-alist)
8379 t))
23f87bed 8380 current-prefix-arg))
bbbe940b
MB
8381 ;; User might hit `K E' instead of `K e', so prompt once.
8382 (when (and gnus-article-encrypt-protocol
8383 gnus-novice-user)
8384 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
d93ec753 8385 (error "Encrypt aborted")))
23f87bed
MB
8386 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8387 (unless func
998a5a95 8388 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8389 (if (member gnus-newsgroup-name '("nndraft:delayed"
8390 "nndraft:drafts"
8391 "nndraft:queue"))
8392 (error "Can't encrypt the article in group %s"
8393 gnus-newsgroup-name))
8394 (gnus-summary-iterate n
80de1778 8395 (with-current-buffer gnus-summary-buffer
23f87bed
MB
8396 (let ((mail-parse-charset gnus-newsgroup-charset)
8397 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8398 (summary-buffer gnus-summary-buffer)
8399 references point)
8400 (gnus-set-global-variables)
8401 (when (gnus-group-read-only-p)
8402 (error "The current newsgroup does not support article encrypt"))
8403 (gnus-summary-show-article t)
8404 (setq references
8405 (or (mail-header-references gnus-current-headers) ""))
8406 (set-buffer gnus-article-buffer)
8407 (let* ((inhibit-read-only t)
8408 (headers
8409 (mapcar (lambda (field)
8410 (and (save-restriction
8411 (message-narrow-to-head)
8412 (goto-char (point-min))
8413 (search-forward field nil t))
8414 (prog2
8415 (message-narrow-to-field)
8416 (buffer-string)
8417 (delete-region (point-min) (point-max))
8418 (widen))))
8419 '("Content-Type:" "Content-Transfer-Encoding:"
8420 "Content-Disposition:"))))
8421 (message-narrow-to-head)
8422 (message-remove-header "MIME-Version")
8423 (goto-char (point-max))
8424 (setq point (point))
8425 (insert (apply 'concat headers))
8426 (widen)
8427 (narrow-to-region point (point-max))
8428 (let ((message-options message-options))
8429 (message-options-set 'message-sender user-mail-address)
8430 (message-options-set 'message-recipients user-mail-address)
8431 (message-options-set 'message-sign-encrypt 'not)
8432 (funcall func))
8433 (goto-char (point-min))
8434 (insert "MIME-Version: 1.0\n")
8435 (widen)
8436 (gnus-summary-edit-article-done
8437 references nil summary-buffer t))
8438 (when gnus-keep-backlog
8439 (gnus-backlog-remove-article
8440 (car gnus-article-current) (cdr gnus-article-current)))
8ccbef23 8441 (gnus-flush-original-article-buffer)
23f87bed
MB
8442 (when gnus-use-cache
8443 (gnus-cache-update-article
8444 (car gnus-article-current) (cdr gnus-article-current))))))))
8445
8446(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8447 "The following specs can be used:
8448%t The security MIME type
8449%i Additional info
8450%d Details
8451%D Details if button is pressed")
8452
8453(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8454 "The following specs can be used:
8455%t The security MIME type
8456%i Additional info
8457%d Details
8458%D Details if button is pressed")
8459
8460(defvar gnus-mime-security-button-line-format-alist
8461 '((?t gnus-tmp-type ?s)
8462 (?i gnus-tmp-info ?s)
8463 (?d gnus-tmp-details ?s)
8464 (?D gnus-tmp-pressed-details ?s)))
8465
01c52d31
MB
8466(defvar gnus-mime-security-button-commands
8467 '((gnus-article-press-button "\r" "Show Detail")
8468 (undefined "v")
8469 (undefined "t")
8470 (undefined "C")
8471 (gnus-mime-security-save-part "o" "Save...")
8472 (undefined "\C-o")
8473 (undefined "r")
8474 (undefined "d")
8475 (undefined "c")
8476 (undefined "i")
8477 (undefined "E")
8478 (undefined "e")
8479 (undefined "p")
8480 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8481 (undefined ".")))
8482
23f87bed
MB
8483(defvar gnus-mime-security-button-map
8484 (let ((map (make-sparse-keymap)))
23f87bed 8485 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8486 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8487 (dolist (c gnus-mime-security-button-commands)
8488 (define-key map (cadr c) (car c)))
23f87bed
MB
8489 map))
8490
01c52d31
MB
8491(easy-menu-define
8492 gnus-mime-security-button-menu gnus-mime-security-button-map
8493 "Security button menu."
8494 `("Security Part"
8495 ,@(delq nil
8496 (mapcar (lambda (c)
8497 (unless (eq (car c) 'undefined)
8498 (vector (caddr c) (car c) :active t)))
8499 gnus-mime-security-button-commands))))
8500
8501(defun gnus-mime-security-button-menu (event prefix)
8502 "Construct a context-sensitive menu of security commands."
8503 (interactive "e\nP")
8504 (save-window-excursion
8505 (let ((pos (event-start event)))
8506 (select-window (posn-window pos))
8507 (goto-char (posn-point pos))
8508 (gnus-article-check-buffer)
8509 (popup-menu gnus-mime-security-button-menu nil prefix))))
8510
23f87bed
MB
8511(defvar gnus-mime-security-details-buffer nil)
8512
8513(defvar gnus-mime-security-button-pressed nil)
8514
8515(defvar gnus-mime-security-show-details-inline t
8516 "If non-nil, show details in the article buffer.")
8517
8518(defun gnus-mime-security-verify-or-decrypt (handle)
8519 (mm-remove-parts (cdr handle))
8520 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8521 point (inhibit-read-only t))
8522 (if region
8523 (goto-char (car region)))
01c52d31
MB
8524 (setq point (point))
8525 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8526 (let* ((mm-verify-option 'known)
8527 (mm-decrypt-option 'known)
8528 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8529 (unless (eq nparts (cdr handle))
8530 (mm-destroy-parts (cdr handle))
8531 (setcdr handle nparts))))
8532 (gnus-mime-display-security handle)
23f87bed
MB
8533 (when region
8534 (delete-region (point) (cdr region))
8535 (set-marker (car region) nil)
8536 (set-marker (cdr region) nil))
8537 (goto-char point)))
8538
8539(defun gnus-mime-security-show-details (handle)
8540 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8541 (if (not details)
8542 (gnus-message 5 "No details.")
8543 (if gnus-mime-security-show-details-inline
8544 (let ((gnus-mime-security-button-pressed
8545 (not (get-text-property (point) 'gnus-mime-details)))
8546 (gnus-mime-security-button-line-format
8547 (get-text-property (point) 'gnus-line-format))
8548 (inhibit-read-only t))
8549 (forward-char -1)
8550 (while (eq (get-text-property (point) 'gnus-line-format)
8551 gnus-mime-security-button-line-format)
8552 (forward-char -1))
8553 (forward-char)
8554 (save-restriction
8555 (narrow-to-region (point) (point))
8556 (gnus-insert-mime-security-button handle))
8557 (delete-region (point)
8558 (or (text-property-not-all
8559 (point) (point-max)
8560 'gnus-line-format
8561 gnus-mime-security-button-line-format)
8562 (point-max))))
8563 ;; Not inlined.
8564 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8565 (with-current-buffer gnus-mime-security-details-buffer
8566 (erase-buffer)
8567 t)
8568 (setq gnus-mime-security-details-buffer
8569 (gnus-get-buffer-create "*MIME Security Details*")))
8570 (with-current-buffer gnus-mime-security-details-buffer
8571 (insert details)
8572 (goto-char (point-min)))
8573 (pop-to-buffer gnus-mime-security-details-buffer)))))
8574
8575(defun gnus-mime-security-press-button (handle)
8576 (save-excursion
8577 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8578 (gnus-mime-security-show-details handle)
8579 (gnus-mime-security-verify-or-decrypt handle))))
8580
8581(defun gnus-insert-mime-security-button (handle &optional displayed)
8582 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8583 (gnus-tmp-type
8584 (concat
8585 (or (nth 2 (assoc protocol mm-verify-function-alist))
8586 (nth 2 (assoc protocol mm-decrypt-function-alist))
8587 "Unknown")
8588 (if (equal (car handle) "multipart/signed")
8589 " Signed" " Encrypted")
8590 " Part"))
8591 (gnus-tmp-info
8592 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8593 "Undecided"))
8594 (gnus-tmp-details
8595 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8596 gnus-tmp-pressed-details
8597 b e)
8598 (setq gnus-tmp-details
8599 (if gnus-tmp-details
8600 (concat "\n" gnus-tmp-details)
8601 ""))
8602 (setq gnus-tmp-pressed-details
8603 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8604 (unless (bolp)
8605 (insert "\n"))
8606 (setq b (point))
8607 (gnus-eval-format
8608 gnus-mime-security-button-line-format
8609 gnus-mime-security-button-line-format-alist
01c52d31 8610 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8611 gnus-callback gnus-mime-security-press-button
8612 gnus-line-format ,gnus-mime-security-button-line-format
8613 gnus-mime-details ,gnus-mime-security-button-pressed
8614 article-type annotation
8615 gnus-data ,handle))
8616 (setq e (if (bolp)
8617 ;; Exclude a newline.
8618 (1- (point))
8619 (point)))
01c52d31
MB
8620 (when gnus-article-button-face
8621 (gnus-overlay-put (gnus-make-overlay b e nil t)
8622 'face gnus-article-button-face))
23f87bed
MB
8623 (widget-convert-button
8624 'link b e
8625 :mime-handle handle
8626 :action 'gnus-widget-press-button
8627 :button-keymap gnus-mime-security-button-map
8628 :help-echo
5843126b 8629 (lambda (widget)
23f87bed
MB
8630 ;; Needed to properly clear the message due to a bug in
8631 ;; wid-edit (XEmacs only).
8632 (when (boundp 'help-echo-owns-message)
8633 (setq help-echo-owns-message t))
8634 (format
01c52d31
MB
8635 "%S: show detail; %S: more options"
8636 (aref gnus-mouse-2 0)
8637 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8638
8639(defun gnus-mime-display-security (handle)
8640 (save-restriction
8641 (narrow-to-region (point) (point))
8642 (unless (gnus-unbuttonized-mime-type-p (car handle))
8643 (gnus-insert-mime-security-button handle))
01c52d31 8644 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8645 (unless (bolp)
8646 (insert "\n"))
8647 (unless (gnus-unbuttonized-mime-type-p (car handle))
8648 (let ((gnus-mime-security-button-line-format
8649 gnus-mime-security-button-end-line-format))
8650 (gnus-insert-mime-security-button handle)))
8651 (mm-set-handle-multipart-parameter
8652 handle 'gnus-region
8653 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8654 (set-marker (make-marker) (point-max))))
8655 (goto-char (point-max))))
8656
8657(defun gnus-mime-security-run-function (function)
8658 "Run FUNCTION with the security part under point."
8659 (gnus-article-check-buffer)
8660 (let ((data (get-text-property (point) 'gnus-data))
8661 buffer handle)
8662 (when (and (stringp (car-safe data))
8663 (setq buffer (mm-handle-multipart-original-buffer data))
8664 (setq handle (cadr data)))
8665 (if (bufferp (mm-handle-buffer handle))
8666 (progn
8667 (setq handle (cons buffer (copy-sequence (cdr handle))))
8668 (mm-handle-set-undisplayer handle nil))
8669 (setq handle (mm-make-handle
8670 buffer
8671 (mm-handle-multipart-ctl-parameter handle 'protocol)
8672 nil nil nil nil nil nil)))
8673 (funcall function handle))))
8674
8675(defun gnus-mime-security-save-part ()
8676 "Save the security part under point."
8677 (interactive)
8678 (gnus-mime-security-run-function 'mm-save-part))
8679
8680(defun gnus-mime-security-pipe-part ()
8681 "Pipe the security part under point to a process."
8682 (interactive)
8683 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8684
eec82323
LMI
8685(gnus-ems-redefine)
8686
8687(provide 'gnus-art)
8688
8689(run-hooks 'gnus-art-load-hook)
8690
8691;;; gnus-art.el ends here