(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / gnus / gnus-art.el
blob4af363c6b2e9d62d2a2d64d17a247c3b46e533df
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;;; Code:
29 (eval-when-compile
30 (require 'cl)
31 (defvar tool-bar-map))
33 (require 'gnus)
34 (require 'gnus-sum)
35 (require 'gnus-spec)
36 (require 'gnus-int)
37 (require 'gnus-win)
38 (require 'mm-bodies)
39 (require 'mail-parse)
40 (require 'mm-decode)
41 (require 'mm-view)
42 (require 'wid-edit)
43 (require 'mm-uu)
44 (require 'message)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
51 (defgroup gnus-article nil
52 "Article display."
53 :link '(custom-manual "(gnus)Article Buffer")
54 :group 'gnus)
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
59 :group 'gnus-article)
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
64 :group 'gnus-article)
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
69 :group 'gnus-article
70 :group 'gnus-visual)
72 (defgroup gnus-article-signature nil
73 "Article signatures."
74 :link '(custom-manual "(gnus)Article Signature")
75 :group 'gnus-article)
77 (defgroup gnus-article-headers nil
78 "Article headers."
79 :link '(custom-manual "(gnus)Hiding Headers")
80 :group 'gnus-article)
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
85 :group 'gnus-article)
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
90 :group 'gnus-article)
92 (defgroup gnus-article-saving nil
93 "Saving articles."
94 :link '(custom-manual "(gnus)Saving Articles")
95 :group 'gnus-article)
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 (mapcar
114 (lambda (header)
115 (concat "^" header ":"))
116 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
117 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
118 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
119 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
120 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
121 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
122 "X-Attribution" "X-Originating-IP" "Delivered-To"
123 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
124 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
125 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
126 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
127 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
128 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
129 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
130 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
131 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
132 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
133 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
134 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
135 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
136 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
137 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
138 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
139 "List-[A-Za-z]+" "X-Listprocessor-Version"
140 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
141 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
142 "X-Received" "Content-length" "X-precedence"
143 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
144 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
145 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
146 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
147 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
148 "X-Content-length" "X-Posting-Agent" "Original-Received"
149 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
150 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
151 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
152 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
153 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
154 "*All headers that start with this regexp will be hidden.
155 This variable can also be a list of regexps of headers to be ignored.
156 If `gnus-visible-headers' is non-nil, this variable will be ignored."
157 :type '(choice :custom-show nil
158 regexp
159 (repeat regexp))
160 :group 'gnus-article-hiding)
162 (defcustom gnus-visible-headers
163 "^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:"
164 "*All headers that do not match this regexp will be hidden.
165 This variable can also be a list of regexp of headers to remain visible.
166 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
167 :type '(repeat :value-to-internal (lambda (widget value)
168 (custom-split-regexp-maybe value))
169 :match (lambda (widget value)
170 (or (stringp value)
171 (widget-editable-list-match widget value)))
172 regexp)
173 :group 'gnus-article-hiding)
175 (defcustom gnus-sorted-header-list
176 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
177 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
178 "*This variable is a list of regular expressions.
179 If it is non-nil, headers that match the regular expressions will
180 be placed first in the article buffer in the sequence specified by
181 this list."
182 :type '(repeat regexp)
183 :group 'gnus-article-hiding)
185 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
186 "Headers that are only to be displayed if they have interesting data.
187 Possible values in this list are:
189 'empty Headers with no content.
190 'newsgroups Newsgroup identical to Gnus group.
191 'to-address To identical to To-address.
192 'to-list To identical to To-list.
193 'cc-list CC identical to To-list.
194 'followup-to Followup-to identical to Newsgroups.
195 'reply-to Reply-to identical to From.
196 'date Date less than four days old.
197 'long-to To and/or Cc longer than 1024 characters.
198 'many-to Multiple To and/or Cc."
199 :type '(set (const :tag "Headers with no content." empty)
200 (const :tag "Newsgroups identical to Gnus group." newsgroups)
201 (const :tag "To identical to To-address." to-address)
202 (const :tag "To identical to To-list." to-list)
203 (const :tag "CC identical to To-list." cc-list)
204 (const :tag "Followup-to identical to Newsgroups." followup-to)
205 (const :tag "Reply-to identical to From." reply-to)
206 (const :tag "Date less than four days old." date)
207 (const :tag "To and/or Cc longer than 1024 characters." long-to)
208 (const :tag "Multiple To and/or Cc headers." many-to))
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-skip-boring nil
212 "Skip over text that is not worth reading.
213 By default, if you set this t, then Gnus will display citations and
214 signatures, but will never scroll down to show you a page consisting
215 only of boring text. Boring text is controlled by
216 `gnus-article-boring-faces'."
217 :version "22.1"
218 :type 'boolean
219 :group 'gnus-article-hiding)
221 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
222 "Regexp matching signature separator.
223 This can also be a list of regexps. In that case, it will be checked
224 from head to tail looking for a separator. Searches will be done from
225 the end of the buffer."
226 :type '(repeat string)
227 :group 'gnus-article-signature)
229 (defcustom gnus-signature-limit nil
230 "Provide a limit to what is considered a signature.
231 If it is a number, no signature may not be longer (in characters) than
232 that number. If it is a floating point number, no signature may be
233 longer (in lines) than that number. If it is a function, the function
234 will be called without any parameters, and if it returns nil, there is
235 no signature in the buffer. If it is a string, it will be used as a
236 regexp. If it matches, the text in question is not a signature."
237 :type '(choice (integer :value 200)
238 (number :value 4.0)
239 (function :value fun)
240 (regexp :value ".*"))
241 :group 'gnus-article-signature)
243 (defcustom gnus-hidden-properties '(invisible t intangible t)
244 "Property list to use for hiding text."
245 :type 'sexp
246 :group 'gnus-article-hiding)
248 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
249 ;; frames in a session.
250 (defcustom gnus-article-x-face-command
251 (if (featurep 'xemacs)
252 (if (or (gnus-image-type-available-p 'xface)
253 (gnus-image-type-available-p 'pbm))
254 'gnus-display-x-face-in-from
255 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
256 (if (gnus-image-type-available-p 'pbm)
257 'gnus-display-x-face-in-from
258 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
259 display -"))
260 "*String or function to be executed to display an X-Face header.
261 If it is a string, the command will be executed in a sub-shell
262 asynchronously. The compressed face will be piped to this command."
263 :type `(choice string
264 (function-item gnus-display-x-face-in-from)
265 function)
266 :version "21.1"
267 :group 'gnus-picon
268 :group 'gnus-article-washing)
270 (defcustom gnus-article-x-face-too-ugly nil
271 "Regexp matching posters whose face shouldn't be shown automatically."
272 :type '(choice regexp (const nil))
273 :group 'gnus-article-washing)
275 (defcustom gnus-article-banner-alist nil
276 "Banner alist for stripping.
277 For example,
278 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
279 :version "21.1"
280 :type '(repeat (cons symbol regexp))
281 :group 'gnus-article-washing)
283 (gnus-define-group-parameter
284 banner
285 :variable-document
286 "Alist of regexps (to match group names) and banner."
287 :variable-group gnus-article-washing
288 :parameter-type
289 '(choice :tag "Banner"
290 :value nil
291 (const :tag "Remove signature" signature)
292 (symbol :tag "Item in `gnus-article-banner-alist'" none)
293 regexp
294 (const :tag "None" nil))
295 :parameter-document
296 "If non-nil, specify how to remove `banners' from articles.
298 Symbol `signature' means to remove signatures delimited by
299 `gnus-signature-separator'. Any other symbol is used to look up a
300 regular expression to match the banner in `gnus-article-banner-alist'.
301 A string is used as a regular expression to match the banner
302 directly.")
304 (defcustom gnus-article-address-banner-alist nil
305 "Alist of mail addresses and banners.
306 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
307 to match a mail address in the From: header, BANNER is one of a symbol
308 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
309 If ADDRESS matches author's mail address, it will remove things like
310 advertisements. For example:
312 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
314 :type '(repeat
315 (cons
316 (regexp :tag "Address")
317 (choice :tag "Banner" :value nil
318 (const :tag "Remove signature" signature)
319 (symbol :tag "Item in `gnus-article-banner-alist'" none)
320 regexp
321 (const :tag "None" nil))))
322 :version "22.1"
323 :group 'gnus-article-washing)
325 (defmacro gnus-emphasis-custom-with-format (&rest body)
326 `(let ((format "\
327 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
328 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
329 ,@body))
331 (defun gnus-emphasis-custom-value-to-external (value)
332 (gnus-emphasis-custom-with-format
333 (if (consp (car value))
334 (list (format format (car (car value)) (cdr (car value)))
336 (if (nth 1 value) 2 3)
337 (nth 2 value))
338 value)))
340 (defun gnus-emphasis-custom-value-to-internal (value)
341 (gnus-emphasis-custom-with-format
342 (let ((regexp (concat "\\`"
343 (format (regexp-quote format)
344 "\\([^()]+\\)" "\\([^()]+\\)")
345 "\\'"))
346 pattern)
347 (if (string-match regexp (setq pattern (car value)))
348 (list (cons (match-string 1 pattern) (match-string 2 pattern))
349 (= (nth 2 value) 2)
350 (nth 3 value))
351 value))))
353 (defcustom gnus-emphasis-alist
354 (let ((types
355 '(("\\*" "\\*" bold nil 2)
356 ("_" "_" underline)
357 ("/" "/" italic)
358 ("_/" "/_" underline-italic)
359 ("_\\*" "\\*_" underline-bold)
360 ("\\*/" "/\\*" bold-italic)
361 ("_\\*/" "/\\*_" underline-bold-italic))))
362 (nconc
363 (gnus-emphasis-custom-with-format
364 (mapcar (lambda (spec)
365 (list (format format (car spec) (cadr spec))
366 (or (nth 3 spec) 2)
367 (or (nth 4 spec) 3)
368 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
369 types))
370 '(("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
371 2 3 gnus-emphasis-strikethru)
372 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
373 2 3 gnus-emphasis-underline))))
374 "*Alist that says how to fontify certain phrases.
375 Each item looks like this:
377 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
379 The first element is a regular expression to be matched. The second
380 is a number that says what regular expression grouping used to find
381 the entire emphasized word. The third is a number that says what
382 regexp grouping should be displayed and highlighted. The fourth
383 is the face used for highlighting."
384 :type
385 '(repeat
386 (menu-choice
387 :format "%[Customizing Style%]\n%v"
388 :indent 2
389 (group :tag "Default"
390 :value ("" 0 0 default)
391 :value-create
392 (lambda (widget)
393 (let ((value (widget-get
394 (cadr (widget-get (widget-get widget :parent)
395 :args))
396 :value)))
397 (if (not (eq (nth 2 value) 'default))
398 (widget-put
399 widget
400 :value
401 (gnus-emphasis-custom-value-to-external value))))
402 (widget-group-value-create widget))
403 regexp
404 (integer :format "Match group: %v")
405 (integer :format "Emphasize group: %v")
406 face)
407 (group :tag "Simple"
408 :value (("_" . "_") nil default)
409 (cons :format "%v"
410 (regexp :format "Start regexp: %v")
411 (regexp :format "End regexp: %v"))
412 (boolean :format "Show start and end patterns: %[%v%]\n"
413 :on " On " :off " Off ")
414 face)))
415 :get (lambda (symbol)
416 (mapcar 'gnus-emphasis-custom-value-to-internal
417 (default-value symbol)))
418 :set (lambda (symbol value)
419 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
420 value)))
421 :group 'gnus-article-emphasis)
423 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
424 "A regexp to describe whitespace which should not be emphasized.
425 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
426 The former avoids underlining of leading and trailing whitespace,
427 and the latter avoids underlining any whitespace at all."
428 :version "21.1"
429 :group 'gnus-article-emphasis
430 :type 'regexp)
432 (defface gnus-emphasis-bold '((t (:bold t)))
433 "Face used for displaying strong emphasized text (*word*)."
434 :group 'gnus-article-emphasis)
436 (defface gnus-emphasis-italic '((t (:italic t)))
437 "Face used for displaying italic emphasized text (/word/)."
438 :group 'gnus-article-emphasis)
440 (defface gnus-emphasis-underline '((t (:underline t)))
441 "Face used for displaying underlined emphasized text (_word_)."
442 :group 'gnus-article-emphasis)
444 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
445 "Face used for displaying underlined bold emphasized text (_*word*_)."
446 :group 'gnus-article-emphasis)
448 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
449 "Face used for displaying underlined italic emphasized text (_/word/_)."
450 :group 'gnus-article-emphasis)
452 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
453 "Face used for displaying bold italic emphasized text (/*word*/)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-underline-bold-italic
457 '((t (:bold t :italic t :underline t)))
458 "Face used for displaying underlined bold italic emphasized text.
459 Example: (_/*word*/_)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
463 '((t (:strikethru t)))
464 '((t (:strike-through t))))
465 "Face used for displaying strike-through text (-word-)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-highlight-words
469 '((t (:background "black" :foreground "yellow")))
470 "Face used for displaying highlighted words."
471 :group 'gnus-article-emphasis)
473 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
474 "Format for display of Date headers in article bodies.
475 See `format-time-string' for the possible values.
477 The variable can also be function, which should return a complete Date
478 header. The function is called with one argument, the time, which can
479 be fed to `format-time-string'."
480 :type '(choice string symbol)
481 :link '(custom-manual "(gnus)Article Date")
482 :group 'gnus-article-washing)
484 (defcustom gnus-save-all-headers t
485 "*If non-nil, don't remove any headers before saving."
486 :group 'gnus-article-saving
487 :type 'boolean)
489 (defcustom gnus-prompt-before-saving 'always
490 "*This variable says how much prompting is to be done when saving articles.
491 If it is nil, no prompting will be done, and the articles will be
492 saved to the default files. If this variable is `always', each and
493 every article that is saved will be preceded by a prompt, even when
494 saving large batches of articles. If this variable is neither nil not
495 `always', there the user will be prompted once for a file name for
496 each invocation of the saving commands."
497 :group 'gnus-article-saving
498 :type '(choice (item always)
499 (item :tag "never" nil)
500 (sexp :tag "once" :format "%t\n" :value t)))
502 (defcustom gnus-saved-headers gnus-visible-headers
503 "Headers to keep if `gnus-save-all-headers' is nil.
504 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
505 If that variable is nil, however, all headers that match this regexp
506 will be kept while the rest will be deleted before saving."
507 :group 'gnus-article-saving
508 :type 'regexp)
510 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
511 "A function to save articles in your favourite format.
512 The function must be interactively callable (in other words, it must
513 be an Emacs command).
515 Gnus provides the following functions:
517 * gnus-summary-save-in-rmail (Rmail format)
518 * gnus-summary-save-in-mail (Unix mail format)
519 * gnus-summary-save-in-folder (MH folder)
520 * gnus-summary-save-in-file (article format)
521 * gnus-summary-save-body-in-file (article body)
522 * gnus-summary-save-in-vm (use VM's folder format)
523 * gnus-summary-write-to-file (article format -- overwrite)."
524 :group 'gnus-article-saving
525 :type '(radio (function-item gnus-summary-save-in-rmail)
526 (function-item gnus-summary-save-in-mail)
527 (function-item gnus-summary-save-in-folder)
528 (function-item gnus-summary-save-in-file)
529 (function-item gnus-summary-save-body-in-file)
530 (function-item gnus-summary-save-in-vm)
531 (function-item gnus-summary-write-to-file)))
533 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
534 "A function generating a file name to save articles in Rmail format.
535 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
536 :group 'gnus-article-saving
537 :type 'function)
539 (defcustom gnus-mail-save-name 'gnus-plain-save-name
540 "A function generating a file name to save articles in Unix mail format.
541 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
542 :group 'gnus-article-saving
543 :type 'function)
545 (defcustom gnus-folder-save-name 'gnus-folder-save-name
546 "A function generating a file name to save articles in MH folder.
547 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
548 :group 'gnus-article-saving
549 :type 'function)
551 (defcustom gnus-file-save-name 'gnus-numeric-save-name
552 "A function generating a file name to save articles in article format.
553 The function is called with NEWSGROUP, HEADERS, and optional
554 LAST-FILE."
555 :group 'gnus-article-saving
556 :type 'function)
558 (defcustom gnus-split-methods
559 '((gnus-article-archive-name)
560 (gnus-article-nndoc-name))
561 "*Variable used to suggest where articles are to be saved.
562 For instance, if you would like to save articles related to Gnus in
563 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
564 you could set this variable to something like:
566 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
567 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
569 This variable is an alist where the where the key is the match and the
570 value is a list of possible files to save in if the match is non-nil.
572 If the match is a string, it is used as a regexp match on the
573 article. If the match is a symbol, that symbol will be funcalled
574 from the buffer of the article to be saved with the newsgroup as the
575 parameter. If it is a list, it will be evaled in the same buffer.
577 If this form or function returns a string, this string will be used as
578 a possible file name; and if it returns a non-nil list, that list will
579 be used as possible file names."
580 :group 'gnus-article-saving
581 :type '(repeat (choice (list :value (fun) function)
582 (cons :value ("" "") regexp (repeat string))
583 (sexp :value nil))))
585 (defcustom gnus-page-delimiter "^\^L"
586 "*Regexp describing what to use as article page delimiters.
587 The default value is \"^\^L\", which is a form linefeed at the
588 beginning of a line."
589 :type 'regexp
590 :group 'gnus-article-various)
592 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
593 "*The format specification for the article mode line.
594 See `gnus-summary-mode-line-format' for a closer description.
596 The following additional specs are available:
598 %w The article washing status.
599 %m The number of MIME parts in the article."
600 :type 'string
601 :group 'gnus-article-various)
603 (defcustom gnus-article-mode-hook nil
604 "*A hook for Gnus article mode."
605 :type 'hook
606 :group 'gnus-article-various)
608 (when (featurep 'xemacs)
609 ;; Extracted from gnus-xmas-define in order to preserve user settings
610 (when (fboundp 'turn-off-scroll-in-place)
611 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
612 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
613 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
615 (defcustom gnus-article-menu-hook nil
616 "*Hook run after the creation of the article mode menu."
617 :type 'hook
618 :group 'gnus-article-various)
620 (defcustom gnus-article-prepare-hook nil
621 "*A hook called after an article has been prepared in the article buffer."
622 :type 'hook
623 :group 'gnus-article-various)
625 (make-obsolete-variable 'gnus-article-hide-pgp-hook
626 "This variable is obsolete in Gnus 5.10.")
628 (defcustom gnus-article-button-face 'bold
629 "Face used for highlighting buttons in the article buffer.
631 An article button is a piece of text that you can activate by pressing
632 `RET' or `mouse-2' above it."
633 :type 'face
634 :group 'gnus-article-buttons)
636 (defcustom gnus-article-mouse-face 'highlight
637 "Face used for mouse highlighting in the article buffer.
639 Article buttons will be displayed in this face when the cursor is
640 above them."
641 :type 'face
642 :group 'gnus-article-buttons)
644 (defcustom gnus-signature-face 'gnus-signature-face
645 "Face used for highlighting a signature in the article buffer.
646 Obsolete; use the face `gnus-signature-face' for customizations instead."
647 :type 'face
648 :group 'gnus-article-highlight
649 :group 'gnus-article-signature)
651 (defface gnus-signature-face
652 '((t
653 (:italic t)))
654 "Face used for highlighting a signature in the article buffer."
655 :group 'gnus-article-highlight
656 :group 'gnus-article-signature)
658 (defface gnus-header-from-face
659 '((((class color)
660 (background dark))
661 (:foreground "spring green"))
662 (((class color)
663 (background light))
664 (:foreground "red3"))
666 (:italic t)))
667 "Face used for displaying from headers."
668 :group 'gnus-article-headers
669 :group 'gnus-article-highlight)
671 (defface gnus-header-subject-face
672 '((((class color)
673 (background dark))
674 (:foreground "SeaGreen3"))
675 (((class color)
676 (background light))
677 (:foreground "red4"))
679 (:bold t :italic t)))
680 "Face used for displaying subject headers."
681 :group 'gnus-article-headers
682 :group 'gnus-article-highlight)
684 (defface gnus-header-newsgroups-face
685 '((((class color)
686 (background dark))
687 (:foreground "yellow" :italic t))
688 (((class color)
689 (background light))
690 (:foreground "MidnightBlue" :italic t))
692 (:italic t)))
693 "Face used for displaying newsgroups headers.
694 In the default setup this face is only used for crossposted
695 articles."
696 :group 'gnus-article-headers
697 :group 'gnus-article-highlight)
699 (defface gnus-header-name-face
700 '((((class color)
701 (background dark))
702 (:foreground "SeaGreen"))
703 (((class color)
704 (background light))
705 (:foreground "maroon"))
707 (:bold t)))
708 "Face used for displaying header names."
709 :group 'gnus-article-headers
710 :group 'gnus-article-highlight)
712 (defface gnus-header-content-face
713 '((((class color)
714 (background dark))
715 (:foreground "forest green" :italic t))
716 (((class color)
717 (background light))
718 (:foreground "indianred4" :italic t))
720 (:italic t))) "Face used for displaying header content."
721 :group 'gnus-article-headers
722 :group 'gnus-article-highlight)
724 (defcustom gnus-header-face-alist
725 '(("From" nil gnus-header-from-face)
726 ("Subject" nil gnus-header-subject-face)
727 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
728 ("" gnus-header-name-face gnus-header-content-face))
729 "*Controls highlighting of article headers.
731 An alist of the form (HEADER NAME CONTENT).
733 HEADER is a regular expression which should match the name of a
734 header and NAME and CONTENT are either face names or nil.
736 The name of each header field will be displayed using the face
737 specified by the first element in the list where HEADER matches
738 the header name and NAME is non-nil. Similarly, the content will
739 be displayed by the first non-nil matching CONTENT face."
740 :group 'gnus-article-headers
741 :group 'gnus-article-highlight
742 :type '(repeat (list (regexp :tag "Header")
743 (choice :tag "Name"
744 (item :tag "skip" nil)
745 (face :value default))
746 (choice :tag "Content"
747 (item :tag "skip" nil)
748 (face :value default)))))
750 (defcustom gnus-article-decode-hook
751 '(article-decode-charset article-decode-encoded-words
752 article-decode-group-name article-decode-idna-rhs)
753 "*Hook run to decode charsets in articles."
754 :group 'gnus-article-headers
755 :type 'hook)
757 (defcustom gnus-display-mime-function 'gnus-display-mime
758 "Function to display MIME articles."
759 :group 'gnus-article-mime
760 :type 'function)
762 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
763 "Function used to decode headers.")
765 (defvar gnus-article-dumbquotes-map
766 '(("\200" "EUR")
767 ("\202" ",")
768 ("\203" "f")
769 ("\204" ",,")
770 ("\205" "...")
771 ("\213" "<")
772 ("\214" "OE")
773 ("\221" "`")
774 ("\222" "'")
775 ("\223" "``")
776 ("\224" "\"")
777 ("\225" "*")
778 ("\226" "-")
779 ("\227" "--")
780 ("\230" "~")
781 ("\231" "(TM)")
782 ("\233" ">")
783 ("\234" "oe")
784 ("\264" "'"))
785 "Table for MS-to-Latin1 translation.")
787 (defcustom gnus-ignored-mime-types nil
788 "List of MIME types that should be ignored by Gnus."
789 :version "21.1"
790 :group 'gnus-article-mime
791 :type '(repeat regexp))
793 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
794 "List of MIME types that should not be given buttons when rendered inline.
795 See also `gnus-buttonized-mime-types' which may override this variable.
796 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
797 :version "21.1"
798 :group 'gnus-article-mime
799 :type '(repeat regexp))
801 (defcustom gnus-buttonized-mime-types nil
802 "List of MIME types that should be given buttons when rendered inline.
803 If set, this variable overrides `gnus-unbuttonized-mime-types'.
804 To see e.g. security buttons you could set this to
805 `(\"multipart/signed\")'.
806 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
807 :version "22.1"
808 :group 'gnus-article-mime
809 :type '(repeat regexp))
811 (defcustom gnus-inhibit-mime-unbuttonizing nil
812 "If non-nil, all MIME parts get buttons.
813 When nil (the default value), then some MIME parts do not get buttons,
814 as described by the variables `gnus-buttonized-mime-types' and
815 `gnus-unbuttonized-mime-types'."
816 :version "22.1"
817 :group 'gnus-article-mime
818 :type 'boolean)
820 (defcustom gnus-body-boundary-delimiter "_"
821 "String used to delimit header and body.
822 This variable is used by `gnus-article-treat-body-boundary' which can
823 be controlled by `gnus-treat-body-boundary'."
824 :version "22.1"
825 :group 'gnus-article-various
826 :type '(choice (item :tag "None" :value nil)
827 string))
829 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
830 "Defines the location of the faces database.
831 For information on obtaining this database of pretty pictures, please
832 see http://www.cs.indiana.edu/picons/ftp/index.html"
833 :version "22.1"
834 :type '(repeat directory)
835 :link '(url-link :tag "download"
836 "http://www.cs.indiana.edu/picons/ftp/index.html")
837 :link '(custom-manual "(gnus)Picons")
838 :group 'gnus-picon)
840 (defun gnus-picons-installed-p ()
841 "Say whether picons are installed on your machine."
842 (let ((installed nil))
843 (dolist (database gnus-picon-databases)
844 (when (file-exists-p database)
845 (setq installed t)))
846 installed))
848 (defcustom gnus-article-mime-part-function nil
849 "Function called with a MIME handle as the argument.
850 This is meant for people who want to do something automatic based
851 on parts -- for instance, adding Vcard info to a database."
852 :group 'gnus-article-mime
853 :type 'function)
855 (defcustom gnus-mime-multipart-functions nil
856 "An alist of MIME types to functions to display them."
857 :version "21.1"
858 :group 'gnus-article-mime
859 :type 'alist)
861 (defcustom gnus-article-date-lapsed-new-header nil
862 "Whether the X-Sent and Date headers can coexist.
863 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
864 either replace the old \"Date:\" header (if this variable is nil), or
865 be added below it (otherwise)."
866 :version "21.1"
867 :group 'gnus-article-headers
868 :type 'boolean)
870 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
871 "Function called with a MIME handle as the argument.
872 This is meant for people who want to view first matched part.
873 For `undisplayed-alternative' (default), the first undisplayed
874 part or alternative part is used. For `undisplayed', the first
875 undisplayed part is used. For a function, the first part which
876 the function return t is used. For nil, the first part is
877 used."
878 :version "21.1"
879 :group 'gnus-article-mime
880 :type '(choice
881 (item :tag "first" :value nil)
882 (item :tag "undisplayed" :value undisplayed)
883 (item :tag "undisplayed or alternative"
884 :value undisplayed-alternative)
885 (function)))
887 (defcustom gnus-mime-action-alist
888 '(("save to file" . gnus-mime-save-part)
889 ("save and strip" . gnus-mime-save-part-and-strip)
890 ("delete part" . gnus-mime-delete-part)
891 ("display as text" . gnus-mime-inline-part)
892 ("view the part" . gnus-mime-view-part)
893 ("pipe to command" . gnus-mime-pipe-part)
894 ("toggle display" . gnus-article-press-button)
895 ("toggle display" . gnus-article-view-part-as-charset)
896 ("view as type" . gnus-mime-view-part-as-type)
897 ("view internally" . gnus-mime-view-part-internally)
898 ("view externally" . gnus-mime-view-part-externally))
899 "An alist of actions that run on the MIME attachment."
900 :group 'gnus-article-mime
901 :type '(repeat (cons (string :tag "name")
902 (function))))
905 ;;; The treatment variables
908 (defvar gnus-part-display-hook nil
909 "Hook called on parts that are to receive treatment.")
911 (defvar gnus-article-treat-custom
912 '(choice (const :tag "Off" nil)
913 (const :tag "On" t)
914 (const :tag "Header" head)
915 (const :tag "Last" last)
916 (integer :tag "Less")
917 (repeat :tag "Groups" regexp)
918 (sexp :tag "Predicate")))
920 (defvar gnus-article-treat-head-custom
921 '(choice (const :tag "Off" nil)
922 (const :tag "Header" head)))
924 (defvar gnus-article-treat-types '("text/plain")
925 "Parts to treat.")
927 (defvar gnus-inhibit-treatment nil
928 "Whether to inhibit treatment.")
930 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
931 "Highlight the signature.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See Info node `(gnus)Customizing Articles'."
934 :group 'gnus-article-treat
935 :link '(custom-manual "(gnus)Customizing Articles")
936 :type gnus-article-treat-custom)
937 (put 'gnus-treat-highlight-signature 'highlight t)
939 (defcustom gnus-treat-buttonize 100000
940 "Add buttons.
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See Info node `(gnus)Customizing Articles'."
943 :group 'gnus-article-treat
944 :link '(custom-manual "(gnus)Customizing Articles")
945 :type gnus-article-treat-custom)
946 (put 'gnus-treat-buttonize 'highlight t)
948 (defcustom gnus-treat-buttonize-head 'head
949 "Add buttons to the head.
950 Valid values are nil, t, `head', `last', an integer or a predicate.
951 See Info node `(gnus)Customizing Articles' for details."
952 :group 'gnus-article-treat
953 :link '(custom-manual "(gnus)Customizing Articles")
954 :type gnus-article-treat-head-custom)
955 (put 'gnus-treat-buttonize-head 'highlight t)
957 (defcustom gnus-treat-emphasize
958 (and (or window-system
959 (featurep 'xemacs)
960 (>= (string-to-number emacs-version) 21))
961 50000)
962 "Emphasize text.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See Info node `(gnus)Customizing Articles' for details."
965 :group 'gnus-article-treat
966 :link '(custom-manual "(gnus)Customizing Articles")
967 :type gnus-article-treat-custom)
968 (put 'gnus-treat-emphasize 'highlight t)
970 (defcustom gnus-treat-strip-cr nil
971 "Remove carriage returns.
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See Info node `(gnus)Customizing Articles' for details."
974 :version "22.1"
975 :group 'gnus-article-treat
976 :link '(custom-manual "(gnus)Customizing Articles")
977 :type gnus-article-treat-custom)
979 (defcustom gnus-treat-unsplit-urls nil
980 "Remove newlines from within URLs.
981 Valid values are nil, t, `head', `last', an integer or a predicate.
982 See Info node `(gnus)Customizing Articles' for details."
983 :version "22.1"
984 :group 'gnus-article-treat
985 :link '(custom-manual "(gnus)Customizing Articles")
986 :type gnus-article-treat-custom)
988 (defcustom gnus-treat-leading-whitespace nil
989 "Remove leading whitespace in headers.
990 Valid values are nil, t, `head', `last', an integer or a predicate.
991 See Info node `(gnus)Customizing Articles' for details."
992 :version "22.1"
993 :group 'gnus-article-treat
994 :link '(custom-manual "(gnus)Customizing Articles")
995 :type gnus-article-treat-custom)
997 (defcustom gnus-treat-hide-headers 'head
998 "Hide headers.
999 Valid values are nil, t, `head', `last', an integer or a predicate.
1000 See Info node `(gnus)Customizing Articles' for details."
1001 :group 'gnus-article-treat
1002 :link '(custom-manual "(gnus)Customizing Articles")
1003 :type gnus-article-treat-head-custom)
1005 (defcustom gnus-treat-hide-boring-headers nil
1006 "Hide boring headers.
1007 Valid values are nil, t, `head', `last', an integer or a predicate.
1008 See Info node `(gnus)Customizing Articles' for details."
1009 :group 'gnus-article-treat
1010 :link '(custom-manual "(gnus)Customizing Articles")
1011 :type gnus-article-treat-head-custom)
1013 (defcustom gnus-treat-hide-signature nil
1014 "Hide the signature.
1015 Valid values are nil, t, `head', `last', an integer or a predicate.
1016 See Info node `(gnus)Customizing Articles' for details."
1017 :group 'gnus-article-treat
1018 :link '(custom-manual "(gnus)Customizing Articles")
1019 :type gnus-article-treat-custom)
1021 (defcustom gnus-treat-fill-article nil
1022 "Fill the article.
1023 Valid values are nil, t, `head', `last', an integer or a predicate.
1024 See Info node `(gnus)Customizing Articles' for details."
1025 :group 'gnus-article-treat
1026 :link '(custom-manual "(gnus)Customizing Articles")
1027 :type gnus-article-treat-custom)
1029 (defcustom gnus-treat-hide-citation nil
1030 "Hide cited text.
1031 Valid values are nil, t, `head', `last', an integer or a predicate.
1032 See Info node `(gnus)Customizing Articles' for details."
1033 :group 'gnus-article-treat
1034 :link '(custom-manual "(gnus)Customizing Articles")
1035 :type gnus-article-treat-custom)
1037 (defcustom gnus-treat-hide-citation-maybe nil
1038 "Hide cited text.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See Info node `(gnus)Customizing Articles' for details."
1041 :group 'gnus-article-treat
1042 :link '(custom-manual "(gnus)Customizing Articles")
1043 :type gnus-article-treat-custom)
1045 (defcustom gnus-treat-strip-list-identifiers 'head
1046 "Strip list identifiers from `gnus-list-identifiers`.
1047 Valid values are nil, t, `head', `last', an integer or a predicate.
1048 See Info node `(gnus)Customizing Articles' for details."
1049 :version "21.1"
1050 :group 'gnus-article-treat
1051 :link '(custom-manual "(gnus)Customizing Articles")
1052 :type gnus-article-treat-custom)
1054 (make-obsolete-variable 'gnus-treat-strip-pgp
1055 "This option is obsolete in Gnus 5.10.")
1057 (defcustom gnus-treat-strip-pem nil
1058 "Strip PEM signatures.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See Info node `(gnus)Customizing Articles' for details."
1061 :group 'gnus-article-treat
1062 :link '(custom-manual "(gnus)Customizing Articles")
1063 :type gnus-article-treat-custom)
1065 (defcustom gnus-treat-strip-banner t
1066 "Strip banners from articles.
1067 The banner to be stripped is specified in the `banner' group parameter.
1068 Valid values are nil, t, `head', `last', an integer or a predicate.
1069 See Info node `(gnus)Customizing Articles' for details."
1070 :group 'gnus-article-treat
1071 :link '(custom-manual "(gnus)Customizing Articles")
1072 :type gnus-article-treat-custom)
1074 (defcustom gnus-treat-highlight-headers 'head
1075 "Highlight the headers.
1076 Valid values are nil, t, `head', `last', an integer or a predicate.
1077 See Info node `(gnus)Customizing Articles' for details."
1078 :group 'gnus-article-treat
1079 :link '(custom-manual "(gnus)Customizing Articles")
1080 :type gnus-article-treat-head-custom)
1081 (put 'gnus-treat-highlight-headers 'highlight t)
1083 (defcustom gnus-treat-highlight-citation t
1084 "Highlight cited text.
1085 Valid values are nil, t, `head', `last', an integer or a predicate.
1086 See Info node `(gnus)Customizing Articles' for details."
1087 :group 'gnus-article-treat
1088 :link '(custom-manual "(gnus)Customizing Articles")
1089 :type gnus-article-treat-custom)
1090 (put 'gnus-treat-highlight-citation 'highlight t)
1092 (defcustom gnus-treat-date-ut nil
1093 "Display the Date in UT (GMT).
1094 Valid values are nil, t, `head', `last', an integer or a predicate.
1095 See Info node `(gnus)Customizing Articles' for details."
1096 :group 'gnus-article-treat
1097 :link '(custom-manual "(gnus)Customizing Articles")
1098 :type gnus-article-treat-head-custom)
1100 (defcustom gnus-treat-date-local nil
1101 "Display the Date in the local timezone.
1102 Valid values are nil, t, `head', `last', an integer or a predicate.
1103 See Info node `(gnus)Customizing Articles' for details."
1104 :group 'gnus-article-treat
1105 :link '(custom-manual "(gnus)Customizing Articles")
1106 :type gnus-article-treat-head-custom)
1108 (defcustom gnus-treat-date-english nil
1109 "Display the Date in a format that can be read aloud in English.
1110 Valid values are nil, t, `head', `last', an integer or a predicate.
1111 See Info node `(gnus)Customizing Articles' for details."
1112 :version "22.1"
1113 :group 'gnus-article-treat
1114 :link '(custom-manual "(gnus)Customizing Articles")
1115 :type gnus-article-treat-head-custom)
1117 (defcustom gnus-treat-date-lapsed nil
1118 "Display the Date header in a way that says how much time has elapsed.
1119 Valid values are nil, t, `head', `last', an integer or a predicate.
1120 See Info node `(gnus)Customizing Articles' for details."
1121 :group 'gnus-article-treat
1122 :link '(custom-manual "(gnus)Customizing Articles")
1123 :type gnus-article-treat-head-custom)
1125 (defcustom gnus-treat-date-original nil
1126 "Display the date in the original timezone.
1127 Valid values are nil, t, `head', `last', an integer or a predicate.
1128 See Info node `(gnus)Customizing Articles' for details."
1129 :group 'gnus-article-treat
1130 :link '(custom-manual "(gnus)Customizing Articles")
1131 :type gnus-article-treat-head-custom)
1133 (defcustom gnus-treat-date-iso8601 nil
1134 "Display the date in the ISO8601 format.
1135 Valid values are nil, t, `head', `last', an integer or a predicate.
1136 See Info node `(gnus)Customizing Articles' for details."
1137 :version "21.1"
1138 :group 'gnus-article-treat
1139 :link '(custom-manual "(gnus)Customizing Articles")
1140 :type gnus-article-treat-head-custom)
1142 (defcustom gnus-treat-date-user-defined nil
1143 "Display the date in a user-defined format.
1144 The format is defined by the `gnus-article-time-format' variable.
1145 Valid values are nil, t, `head', `last', an integer or a predicate.
1146 See Info node `(gnus)Customizing Articles' for details."
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-head-custom)
1151 (defcustom gnus-treat-strip-headers-in-body t
1152 "Strip the X-No-Archive header line from the beginning of the body.
1153 Valid values are nil, t, `head', `last', an integer or a predicate.
1154 See Info node `(gnus)Customizing Articles' for details."
1155 :version "21.1"
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-custom)
1160 (defcustom gnus-treat-strip-trailing-blank-lines nil
1161 "Strip trailing blank lines.
1162 Valid values are nil, t, `head', `last', an integer or a predicate.
1163 See Info node `(gnus)Customizing Articles' for details."
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-custom)
1168 (defcustom gnus-treat-strip-leading-blank-lines nil
1169 "Strip leading blank lines.
1170 Valid values are nil, t, `head', `last', an integer or a predicate.
1171 See Info node `(gnus)Customizing Articles' for details."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1176 (defcustom gnus-treat-strip-multiple-blank-lines nil
1177 "Strip multiple blank lines.
1178 Valid values are nil, t, `head', `last', an integer or a predicate.
1179 See Info node `(gnus)Customizing Articles' for details."
1180 :group 'gnus-article-treat
1181 :link '(custom-manual "(gnus)Customizing Articles")
1182 :type gnus-article-treat-custom)
1184 (defcustom gnus-treat-unfold-headers 'head
1185 "Unfold folded header lines.
1186 Valid values are nil, t, `head', `last', an integer or a predicate.
1187 See Info node `(gnus)Customizing Articles' for details."
1188 :version "22.1"
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-custom)
1193 (defcustom gnus-treat-fold-headers nil
1194 "Fold headers.
1195 Valid values are nil, t, `head', `last', an integer or a predicate.
1196 See Info node `(gnus)Customizing Articles' for details."
1197 :version "22.1"
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1202 (defcustom gnus-treat-fold-newsgroups 'head
1203 "Fold the Newsgroups and Followup-To headers.
1204 Valid values are nil, t, `head', `last', an integer or a predicate.
1205 See Info node `(gnus)Customizing Articles' for details."
1206 :version "22.1"
1207 :group 'gnus-article-treat
1208 :link '(custom-manual "(gnus)Customizing Articles")
1209 :type gnus-article-treat-custom)
1211 (defcustom gnus-treat-overstrike t
1212 "Treat overstrike highlighting.
1213 Valid values are nil, t, `head', `last', an integer or a predicate.
1214 See Info node `(gnus)Customizing Articles' for details."
1215 :group 'gnus-article-treat
1216 :link '(custom-manual "(gnus)Customizing Articles")
1217 :type gnus-article-treat-custom)
1218 (put 'gnus-treat-overstrike 'highlight t)
1220 (make-obsolete-variable 'gnus-treat-display-xface
1221 'gnus-treat-display-x-face)
1223 (defcustom gnus-treat-display-x-face
1224 (and (not noninteractive)
1225 (or (and (fboundp 'image-type-available-p)
1226 (image-type-available-p 'xbm)
1227 (string-match "^0x" (shell-command-to-string "uncompface"))
1228 (executable-find "icontopbm"))
1229 (and (featurep 'xemacs)
1230 (featurep 'xface)))
1231 'head)
1232 "Display X-Face headers.
1233 Valid values are nil, t, `head', `last', an integer or a predicate.
1234 See Info node `(gnus)Customizing Articles' and Info node
1235 `(gnus)X-Face' for details."
1236 :group 'gnus-article-treat
1237 :version "21.1"
1238 :link '(custom-manual "(gnus)Customizing Articles")
1239 :link '(custom-manual "(gnus)X-Face")
1240 :type gnus-article-treat-head-custom
1241 :set (lambda (symbol value)
1242 (set-default
1243 symbol
1244 (cond ((or (boundp symbol) (get symbol 'saved-value))
1245 value)
1246 ((boundp 'gnus-treat-display-xface)
1247 (message "\
1248 ** gnus-treat-display-xface is an obsolete variable;\
1249 use gnus-treat-display-x-face instead")
1250 (default-value 'gnus-treat-display-xface))
1251 ((get 'gnus-treat-display-xface 'saved-value)
1252 (message "\
1253 ** gnus-treat-display-xface is an obsolete variable;\
1254 use gnus-treat-display-x-face instead")
1255 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1257 value)))))
1258 (put 'gnus-treat-display-x-face 'highlight t)
1260 (defcustom gnus-treat-display-face
1261 (and (not noninteractive)
1262 (or (and (fboundp 'image-type-available-p)
1263 (image-type-available-p 'png))
1264 (and (featurep 'xemacs)
1265 (featurep 'png)))
1266 'head)
1267 "Display Face headers.
1268 Valid values are nil, t, `head', `last', an integer or a predicate.
1269 See Info node `(gnus)Customizing Articles' and Info node
1270 `(gnus)X-Face' for details."
1271 :group 'gnus-article-treat
1272 :version "22.1"
1273 :link '(custom-manual "(gnus)Customizing Articles")
1274 :link '(custom-manual "(gnus)X-Face")
1275 :type gnus-article-treat-head-custom)
1276 (put 'gnus-treat-display-face 'highlight t)
1278 (defcustom gnus-treat-display-smileys
1279 (if (or (and (featurep 'xemacs)
1280 (featurep 'xpm))
1281 (and (fboundp 'image-type-available-p)
1282 (image-type-available-p 'pbm)))
1283 t nil)
1284 "Display smileys.
1285 Valid values are nil, t, `head', `last', an integer or a predicate.
1286 See Info node `(gnus)Customizing Articles' and Info node
1287 `(gnus)Smileys' for details."
1288 :group 'gnus-article-treat
1289 :version "21.1"
1290 :link '(custom-manual "(gnus)Customizing Articles")
1291 :link '(custom-manual "(gnus)Smileys")
1292 :type gnus-article-treat-custom)
1293 (put 'gnus-treat-display-smileys 'highlight t)
1295 (defcustom gnus-treat-from-picon
1296 (if (and (gnus-image-type-available-p 'xpm)
1297 (gnus-picons-installed-p))
1298 'head nil)
1299 "Display picons in the From header.
1300 Valid values are nil, t, `head', `last', an integer or a predicate.
1301 See Info node `(gnus)Customizing Articles' and Info node
1302 `(gnus)Picons' for details."
1303 :version "22.1"
1304 :group 'gnus-article-treat
1305 :group 'gnus-picon
1306 :link '(custom-manual "(gnus)Customizing Articles")
1307 :link '(custom-manual "(gnus)Picons")
1308 :type gnus-article-treat-head-custom)
1309 (put 'gnus-treat-from-picon 'highlight t)
1311 (defcustom gnus-treat-mail-picon
1312 (if (and (gnus-image-type-available-p 'xpm)
1313 (gnus-picons-installed-p))
1314 'head nil)
1315 "Display picons in To and Cc headers.
1316 Valid values are nil, t, `head', `last', an integer or a predicate.
1317 See Info node `(gnus)Customizing Articles' and Info node
1318 `(gnus)Picons' for details."
1319 :version "22.1"
1320 :group 'gnus-article-treat
1321 :group 'gnus-picon
1322 :link '(custom-manual "(gnus)Customizing Articles")
1323 :link '(custom-manual "(gnus)Picons")
1324 :type gnus-article-treat-head-custom)
1325 (put 'gnus-treat-mail-picon 'highlight t)
1327 (defcustom gnus-treat-newsgroups-picon
1328 (if (and (gnus-image-type-available-p 'xpm)
1329 (gnus-picons-installed-p))
1330 'head nil)
1331 "Display picons in the Newsgroups and Followup-To headers.
1332 Valid values are nil, t, `head', `last', an integer or a predicate.
1333 See Info node `(gnus)Customizing Articles' and Info node
1334 `(gnus)Picons' for details."
1335 :version "22.1"
1336 :group 'gnus-article-treat
1337 :group 'gnus-picon
1338 :link '(custom-manual "(gnus)Customizing Articles")
1339 :link '(custom-manual "(gnus)Picons")
1340 :type gnus-article-treat-head-custom)
1341 (put 'gnus-treat-newsgroups-picon 'highlight t)
1343 (defcustom gnus-treat-body-boundary
1344 (if (or gnus-treat-newsgroups-picon
1345 gnus-treat-mail-picon
1346 gnus-treat-from-picon)
1347 'head nil)
1348 "Draw a boundary at the end of the headers.
1349 Valid values are nil and `head'.
1350 See Info node `(gnus)Customizing Articles' for details."
1351 :version "22.1"
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-head-custom)
1356 (defcustom gnus-treat-capitalize-sentences nil
1357 "Capitalize sentence-starting words.
1358 Valid values are nil, t, `head', `last', an integer or a predicate.
1359 See Info node `(gnus)Customizing Articles' for details."
1360 :version "21.1"
1361 :group 'gnus-article-treat
1362 :link '(custom-manual "(gnus)Customizing Articles")
1363 :type gnus-article-treat-custom)
1365 (defcustom gnus-treat-wash-html nil
1366 "Format as HTML.
1367 Valid values are nil, t, `head', `last', an integer or a predicate.
1368 See Info node `(gnus)Customizing Articles' for details."
1369 :version "22.1"
1370 :group 'gnus-article-treat
1371 :link '(custom-manual "(gnus)Customizing Articles")
1372 :type gnus-article-treat-custom)
1374 (defcustom gnus-treat-fill-long-lines nil
1375 "Fill long lines.
1376 Valid values are nil, t, `head', `last', an integer or a predicate.
1377 See Info node `(gnus)Customizing Articles' for details."
1378 :group 'gnus-article-treat
1379 :link '(custom-manual "(gnus)Customizing Articles")
1380 :type gnus-article-treat-custom)
1382 (defcustom gnus-treat-play-sounds nil
1383 "Play sounds.
1384 Valid values are nil, t, `head', `last', an integer or a predicate.
1385 See Info node `(gnus)Customizing Articles' for details."
1386 :version "21.1"
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1391 (defcustom gnus-treat-translate nil
1392 "Translate articles from one language to another.
1393 Valid values are nil, t, `head', `last', an integer or a predicate.
1394 See Info node `(gnus)Customizing Articles' for details."
1395 :version "21.1"
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1400 (defcustom gnus-treat-x-pgp-sig nil
1401 "Verify X-PGP-Sig.
1402 To automatically treat X-PGP-Sig, set it to head.
1403 Valid values are nil, t, `head', `last', an integer or a predicate.
1404 See Info node `(gnus)Customizing Articles' for details."
1405 :version "22.1"
1406 :group 'gnus-article-treat
1407 :group 'mime-security
1408 :link '(custom-manual "(gnus)Customizing Articles")
1409 :type gnus-article-treat-custom)
1411 (defvar gnus-article-encrypt-protocol-alist
1412 '(("PGP" . mml2015-self-encrypt)))
1414 ;; Set to nil if more than one protocol added to
1415 ;; gnus-article-encrypt-protocol-alist.
1416 (defcustom gnus-article-encrypt-protocol "PGP"
1417 "The protocol used for encrypt articles.
1418 It is a string, such as \"PGP\". If nil, ask user."
1419 :version "22.1"
1420 :type 'string
1421 :group 'mime-security)
1423 (defvar gnus-article-wash-function nil
1424 "Function used for converting HTML into text.")
1426 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1427 (mm-coding-system-p 'utf-8)
1428 (executable-find idna-program))
1429 "Whether IDNA decoding of headers is used when viewing messages.
1430 This requires GNU Libidn, and by default only enabled if it is found."
1431 :version "22.1"
1432 :group 'gnus-article-headers
1433 :type 'boolean)
1435 (defcustom gnus-article-over-scroll nil
1436 "If non-nil, allow scrolling the article buffer even when there no more text."
1437 :version "22.1"
1438 :group 'gnus-article
1439 :type 'boolean)
1441 ;;; Internal variables
1443 (defvar gnus-english-month-names
1444 '("January" "February" "March" "April" "May" "June" "July" "August"
1445 "September" "October" "November" "December"))
1447 (defvar article-goto-body-goes-to-point-min-p nil)
1448 (defvar gnus-article-wash-types nil)
1449 (defvar gnus-article-emphasis-alist nil)
1450 (defvar gnus-article-image-alist nil)
1452 (defvar gnus-article-mime-handle-alist-1 nil)
1453 (defvar gnus-treatment-function-alist
1454 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1455 (gnus-treat-strip-banner gnus-article-strip-banner)
1456 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1457 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1458 (gnus-treat-buttonize gnus-article-add-buttons)
1459 (gnus-treat-fill-article gnus-article-fill-cited-article)
1460 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1461 (gnus-treat-strip-cr gnus-article-remove-cr)
1462 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1463 (gnus-treat-date-ut gnus-article-date-ut)
1464 (gnus-treat-date-local gnus-article-date-local)
1465 (gnus-treat-date-english gnus-article-date-english)
1466 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1467 (gnus-treat-date-original gnus-article-date-original)
1468 (gnus-treat-date-user-defined gnus-article-date-user)
1469 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1470 (gnus-treat-display-x-face gnus-article-display-x-face)
1471 (gnus-treat-display-face gnus-article-display-face)
1472 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1473 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1474 (gnus-treat-hide-signature gnus-article-hide-signature)
1475 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1476 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1477 (gnus-treat-strip-pem gnus-article-hide-pem)
1478 (gnus-treat-from-picon gnus-treat-from-picon)
1479 (gnus-treat-mail-picon gnus-treat-mail-picon)
1480 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1481 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1482 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1483 (gnus-treat-strip-trailing-blank-lines
1484 gnus-article-remove-trailing-blank-lines)
1485 (gnus-treat-strip-leading-blank-lines
1486 gnus-article-strip-leading-blank-lines)
1487 (gnus-treat-strip-multiple-blank-lines
1488 gnus-article-strip-multiple-blank-lines)
1489 (gnus-treat-overstrike gnus-article-treat-overstrike)
1490 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1491 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1492 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1493 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1494 (gnus-treat-display-smileys gnus-treat-smiley)
1495 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1496 (gnus-treat-wash-html gnus-article-wash-html)
1497 (gnus-treat-emphasize gnus-article-emphasize)
1498 (gnus-treat-hide-citation gnus-article-hide-citation)
1499 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1500 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1501 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1502 (gnus-treat-play-sounds gnus-earcon-display)))
1504 (defvar gnus-article-mime-handle-alist nil)
1505 (defvar article-lapsed-timer nil)
1506 (defvar gnus-article-current-summary nil)
1508 (defvar gnus-article-mode-syntax-table
1509 (let ((table (copy-syntax-table text-mode-syntax-table)))
1510 ;; This causes the citation match run O(2^n).
1511 ;; (modify-syntax-entry ?- "w" table)
1512 (modify-syntax-entry ?> ")<" table)
1513 (modify-syntax-entry ?< "(>" table)
1514 ;; make M-. in article buffers work for `foo' strings
1515 (modify-syntax-entry ?' " " table)
1516 (modify-syntax-entry ?` " " table)
1517 table)
1518 "Syntax table used in article mode buffers.
1519 Initialized from `text-mode-syntax-table.")
1521 (defvar gnus-save-article-buffer nil)
1523 (defvar gnus-article-mode-line-format-alist
1524 (nconc '((?w (gnus-article-wash-status) ?s)
1525 (?m (gnus-article-mime-part-status) ?s))
1526 gnus-summary-mode-line-format-alist))
1528 (defvar gnus-number-of-articles-to-be-saved nil)
1530 (defvar gnus-inhibit-hiding nil)
1532 (defvar gnus-article-edit-mode nil)
1534 ;;; Macros for dealing with the article buffer.
1536 (defmacro gnus-with-article-headers (&rest forms)
1537 `(save-excursion
1538 (set-buffer gnus-article-buffer)
1539 (save-restriction
1540 (let ((inhibit-read-only t)
1541 (inhibit-point-motion-hooks t)
1542 (case-fold-search t))
1543 (article-narrow-to-head)
1544 ,@forms))))
1546 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1547 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1549 (defmacro gnus-with-article-buffer (&rest forms)
1550 `(save-excursion
1551 (set-buffer gnus-article-buffer)
1552 (let ((inhibit-read-only t))
1553 ,@forms)))
1555 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1556 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1558 (defun gnus-article-goto-header (header)
1559 "Go to HEADER, which is a regular expression."
1560 (re-search-forward (concat "^\\(" header "\\):") nil t))
1562 (defsubst gnus-article-hide-text (b e props)
1563 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1564 (gnus-add-text-properties-when 'article-type nil b e props)
1565 (when (memq 'intangible props)
1566 (put-text-property
1567 (max (1- b) (point-min))
1568 b 'intangible (cddr (memq 'intangible props)))))
1570 (defsubst gnus-article-unhide-text (b e)
1571 "Remove hidden text properties from region between B and E."
1572 (remove-text-properties b e gnus-hidden-properties)
1573 (when (memq 'intangible gnus-hidden-properties)
1574 (put-text-property (max (1- b) (point-min))
1575 b 'intangible nil)))
1577 (defun gnus-article-hide-text-type (b e type)
1578 "Hide text of TYPE between B and E."
1579 (gnus-add-wash-type type)
1580 (gnus-article-hide-text
1581 b e (cons 'article-type (cons type gnus-hidden-properties))))
1583 (defun gnus-article-unhide-text-type (b e type)
1584 "Unhide text of TYPE between B and E."
1585 (gnus-delete-wash-type type)
1586 (remove-text-properties
1587 b e (cons 'article-type (cons type gnus-hidden-properties)))
1588 (when (memq 'intangible gnus-hidden-properties)
1589 (put-text-property (max (1- b) (point-min))
1590 b 'intangible nil)))
1592 (defun gnus-article-hide-text-of-type (type)
1593 "Hide text of TYPE in the current buffer."
1594 (save-excursion
1595 (let ((b (point-min))
1596 (e (point-max)))
1597 (while (setq b (text-property-any b e 'article-type type))
1598 (add-text-properties b (incf b) gnus-hidden-properties)))))
1600 (defun gnus-article-delete-text-of-type (type)
1601 "Delete text of TYPE in the current buffer."
1602 (save-excursion
1603 (let ((b (point-min)))
1604 (while (setq b (text-property-any b (point-max) 'article-type type))
1605 (delete-region
1606 b (or (text-property-not-all b (point-max) 'article-type type)
1607 (point-max)))))))
1609 (defun gnus-article-delete-invisible-text ()
1610 "Delete all invisible text in the current buffer."
1611 (save-excursion
1612 (let ((b (point-min)))
1613 (while (setq b (text-property-any b (point-max) 'invisible t))
1614 (delete-region
1615 b (or (text-property-not-all b (point-max) 'invisible t)
1616 (point-max)))))))
1618 (defun gnus-article-text-type-exists-p (type)
1619 "Say whether any text of type TYPE exists in the buffer."
1620 (text-property-any (point-min) (point-max) 'article-type type))
1622 (defsubst gnus-article-header-rank ()
1623 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1624 (let ((list gnus-sorted-header-list)
1625 (i 1))
1626 (while list
1627 (if (looking-at (car list))
1628 (setq list nil)
1629 (setq list (cdr list))
1630 (incf i)))
1633 (defun article-hide-headers (&optional arg delete)
1634 "Hide unwanted headers and possibly sort them as well."
1635 (interactive)
1636 ;; This function might be inhibited.
1637 (unless gnus-inhibit-hiding
1638 (let ((inhibit-read-only nil)
1639 (case-fold-search t)
1640 (max (1+ (length gnus-sorted-header-list)))
1641 (inhibit-point-motion-hooks t)
1642 (cur (current-buffer))
1643 ignored visible beg)
1644 (save-excursion
1645 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1646 ;; group parameters, so we should go to the summary buffer.
1647 (when (prog1
1648 (condition-case nil
1649 (progn (set-buffer gnus-summary-buffer) t)
1650 (error nil))
1651 (setq ignored (when (not gnus-visible-headers)
1652 (cond ((stringp gnus-ignored-headers)
1653 gnus-ignored-headers)
1654 ((listp gnus-ignored-headers)
1655 (mapconcat 'identity
1656 gnus-ignored-headers
1657 "\\|"))))
1658 visible (cond ((stringp gnus-visible-headers)
1659 gnus-visible-headers)
1660 ((and gnus-visible-headers
1661 (listp gnus-visible-headers))
1662 (mapconcat 'identity
1663 gnus-visible-headers
1664 "\\|")))))
1665 (set-buffer cur))
1666 (save-restriction
1667 ;; First we narrow to just the headers.
1668 (article-narrow-to-head)
1669 ;; Hide any "From " lines at the beginning of (mail) articles.
1670 (while (looking-at "From ")
1671 (forward-line 1))
1672 (unless (bobp)
1673 (delete-region (point-min) (point)))
1674 ;; Then treat the rest of the header lines.
1675 ;; Then we use the two regular expressions
1676 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1677 ;; select which header lines is to remain visible in the
1678 ;; article buffer.
1679 (while (re-search-forward "^[^ \t:]*:" nil t)
1680 (beginning-of-line)
1681 ;; Mark the rank of the header.
1682 (put-text-property
1683 (point) (1+ (point)) 'message-rank
1684 (if (or (and visible (looking-at visible))
1685 (and ignored
1686 (not (looking-at ignored))))
1687 (gnus-article-header-rank)
1688 (+ 2 max)))
1689 (forward-line 1))
1690 (message-sort-headers-1)
1691 (when (setq beg (text-property-any
1692 (point-min) (point-max) 'message-rank (+ 2 max)))
1693 ;; We delete the unwanted headers.
1694 (gnus-add-wash-type 'headers)
1695 (add-text-properties (point-min) (+ 5 (point-min))
1696 '(article-type headers dummy-invisible t))
1697 (delete-region beg (point-max))))))))
1699 (defun article-hide-boring-headers (&optional arg)
1700 "Toggle hiding of headers that aren't very interesting.
1701 If given a negative prefix, always show; if given a positive prefix,
1702 always hide."
1703 (interactive (gnus-article-hidden-arg))
1704 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1705 (not gnus-show-all-headers))
1706 (save-excursion
1707 (save-restriction
1708 (let ((inhibit-read-only t)
1709 (list gnus-boring-article-headers)
1710 (inhibit-point-motion-hooks t)
1711 elem)
1712 (article-narrow-to-head)
1713 (while list
1714 (setq elem (pop list))
1715 (goto-char (point-min))
1716 (cond
1717 ;; Hide empty headers.
1718 ((eq elem 'empty)
1719 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1720 (forward-line -1)
1721 (gnus-article-hide-text-type
1722 (gnus-point-at-bol)
1723 (progn
1724 (end-of-line)
1725 (if (re-search-forward "^[^ \t]" nil t)
1726 (match-beginning 0)
1727 (point-max)))
1728 'boring-headers)))
1729 ;; Hide boring Newsgroups header.
1730 ((eq elem 'newsgroups)
1731 (when (gnus-string-equal
1732 (gnus-fetch-field "newsgroups")
1733 (gnus-group-real-name
1734 (if (boundp 'gnus-newsgroup-name)
1735 gnus-newsgroup-name
1736 "")))
1737 (gnus-article-hide-header "newsgroups")))
1738 ((eq elem 'to-address)
1739 (let ((to (message-fetch-field "to"))
1740 (to-address
1741 (gnus-parameter-to-address
1742 (if (boundp 'gnus-newsgroup-name)
1743 gnus-newsgroup-name ""))))
1744 (when (and to to-address
1745 (ignore-errors
1746 (gnus-string-equal
1747 ;; only one address in To
1748 (nth 1 (mail-extract-address-components to))
1749 to-address)))
1750 (gnus-article-hide-header "to"))))
1751 ((eq elem 'to-list)
1752 (let ((to (message-fetch-field "to"))
1753 (to-list
1754 (gnus-parameter-to-list
1755 (if (boundp 'gnus-newsgroup-name)
1756 gnus-newsgroup-name ""))))
1757 (when (and to to-list
1758 (ignore-errors
1759 (gnus-string-equal
1760 ;; only one address in To
1761 (nth 1 (mail-extract-address-components to))
1762 to-list)))
1763 (gnus-article-hide-header "to"))))
1764 ((eq elem 'cc-list)
1765 (let ((cc (message-fetch-field "cc"))
1766 (to-list
1767 (gnus-parameter-to-list
1768 (if (boundp 'gnus-newsgroup-name)
1769 gnus-newsgroup-name ""))))
1770 (when (and cc to-list
1771 (ignore-errors
1772 (gnus-string-equal
1773 ;; only one address in CC
1774 (nth 1 (mail-extract-address-components cc))
1775 to-list)))
1776 (gnus-article-hide-header "cc"))))
1777 ((eq elem 'followup-to)
1778 (when (gnus-string-equal
1779 (message-fetch-field "followup-to")
1780 (message-fetch-field "newsgroups"))
1781 (gnus-article-hide-header "followup-to")))
1782 ((eq elem 'reply-to)
1783 (if (gnus-group-find-parameter
1784 gnus-newsgroup-name 'broken-reply-to)
1785 (gnus-article-hide-header "reply-to")
1786 (let ((from (message-fetch-field "from"))
1787 (reply-to (message-fetch-field "reply-to")))
1788 (when
1789 (and
1790 from reply-to
1791 (ignore-errors
1792 (equal
1793 (sort (mapcar
1794 (lambda (x) (downcase (cadr x)))
1795 (mail-extract-address-components from t))
1796 'string<)
1797 (sort (mapcar
1798 (lambda (x) (downcase (cadr x)))
1799 (mail-extract-address-components reply-to t))
1800 'string<))))
1801 (gnus-article-hide-header "reply-to")))))
1802 ((eq elem 'date)
1803 (let ((date (message-fetch-field "date")))
1804 (when (and date
1805 (< (days-between (current-time-string) date)
1807 (gnus-article-hide-header "date"))))
1808 ((eq elem 'long-to)
1809 (let ((to (message-fetch-field "to"))
1810 (cc (message-fetch-field "cc")))
1811 (when (> (length to) 1024)
1812 (gnus-article-hide-header "to"))
1813 (when (> (length cc) 1024)
1814 (gnus-article-hide-header "cc"))))
1815 ((eq elem 'many-to)
1816 (let ((to-count 0)
1817 (cc-count 0))
1818 (goto-char (point-min))
1819 (while (re-search-forward "^to:" nil t)
1820 (setq to-count (1+ to-count)))
1821 (when (> to-count 1)
1822 (while (> to-count 0)
1823 (goto-char (point-min))
1824 (save-restriction
1825 (re-search-forward "^to:" nil nil to-count)
1826 (forward-line -1)
1827 (narrow-to-region (point) (point-max))
1828 (gnus-article-hide-header "to"))
1829 (setq to-count (1- to-count))))
1830 (goto-char (point-min))
1831 (while (re-search-forward "^cc:" nil t)
1832 (setq cc-count (1+ cc-count)))
1833 (when (> cc-count 1)
1834 (while (> cc-count 0)
1835 (goto-char (point-min))
1836 (save-restriction
1837 (re-search-forward "^cc:" nil nil cc-count)
1838 (forward-line -1)
1839 (narrow-to-region (point) (point-max))
1840 (gnus-article-hide-header "cc"))
1841 (setq cc-count (1- cc-count)))))))))))))
1843 (defun gnus-article-hide-header (header)
1844 (save-excursion
1845 (goto-char (point-min))
1846 (when (re-search-forward (concat "^" header ":") nil t)
1847 (gnus-article-hide-text-type
1848 (gnus-point-at-bol)
1849 (progn
1850 (end-of-line)
1851 (if (re-search-forward "^[^ \t]" nil t)
1852 (match-beginning 0)
1853 (point-max)))
1854 'boring-headers))))
1856 (defvar gnus-article-normalized-header-length 40
1857 "Length of normalized headers.")
1859 (defun article-normalize-headers ()
1860 "Make all header lines 40 characters long."
1861 (interactive)
1862 (let ((inhibit-read-only t)
1863 column)
1864 (save-excursion
1865 (save-restriction
1866 (article-narrow-to-head)
1867 (while (not (eobp))
1868 (cond
1869 ((< (setq column (- (gnus-point-at-eol) (point)))
1870 gnus-article-normalized-header-length)
1871 (end-of-line)
1872 (insert (make-string
1873 (- gnus-article-normalized-header-length column)
1874 ? )))
1875 ((> column gnus-article-normalized-header-length)
1876 (gnus-put-text-property
1877 (progn
1878 (forward-char gnus-article-normalized-header-length)
1879 (point))
1880 (gnus-point-at-eol)
1881 'invisible t))
1883 ;; Do nothing.
1885 (forward-line 1))))))
1887 (defun article-treat-dumbquotes ()
1888 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1889 Note that this function guesses whether a character is a sm*rtq**t* or
1890 not, so it should only be used interactively.
1892 Sm*rtq**t*s are M****s***'s unilateral extension to the
1893 iso-8859-1 character map in an attempt to provide more quoting
1894 characters. If you see something like \\222 or \\264 where
1895 you're expecting some kind of apostrophe or quotation mark, then
1896 try this wash."
1897 (interactive)
1898 (article-translate-strings gnus-article-dumbquotes-map))
1900 (defun article-translate-characters (from to)
1901 "Translate all characters in the body of the article according to FROM and TO.
1902 FROM is a string of characters to translate from; to is a string of
1903 characters to translate to."
1904 (save-excursion
1905 (when (article-goto-body)
1906 (let ((inhibit-read-only t)
1907 (x (make-string 225 ?x))
1908 (i -1))
1909 (while (< (incf i) (length x))
1910 (aset x i i))
1911 (setq i 0)
1912 (while (< i (length from))
1913 (aset x (aref from i) (aref to i))
1914 (incf i))
1915 (translate-region (point) (point-max) x)))))
1917 (defun article-translate-strings (map)
1918 "Translate all string in the body of the article according to MAP.
1919 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1920 (save-excursion
1921 (when (article-goto-body)
1922 (let ((inhibit-read-only t)
1923 elem)
1924 (while (setq elem (pop map))
1925 (save-excursion
1926 (while (search-forward (car elem) nil t)
1927 (replace-match (cadr elem)))))))))
1929 (defun article-treat-overstrike ()
1930 "Translate overstrikes into bold text."
1931 (interactive)
1932 (save-excursion
1933 (when (article-goto-body)
1934 (let ((inhibit-read-only t))
1935 (while (search-forward "\b" nil t)
1936 (let ((next (char-after))
1937 (previous (char-after (- (point) 2))))
1938 ;; We do the boldification/underlining by hiding the
1939 ;; overstrikes and putting the proper text property
1940 ;; on the letters.
1941 (cond
1942 ((eq next previous)
1943 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1944 (put-text-property (point) (1+ (point)) 'face 'bold))
1945 ((eq next ?_)
1946 (gnus-article-hide-text-type
1947 (1- (point)) (1+ (point)) 'overstrike)
1948 (put-text-property
1949 (- (point) 2) (1- (point)) 'face 'underline))
1950 ((eq previous ?_)
1951 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1952 (put-text-property
1953 (point) (1+ (point)) 'face 'underline)))))))))
1955 (defun gnus-article-treat-unfold-headers ()
1956 "Unfold folded message headers.
1957 Only the headers that fit into the current window width will be
1958 unfolded."
1959 (interactive)
1960 (gnus-with-article-headers
1961 (let (length)
1962 (while (not (eobp))
1963 (save-restriction
1964 (mail-header-narrow-to-field)
1965 (let ((header (buffer-string)))
1966 (with-temp-buffer
1967 (insert header)
1968 (goto-char (point-min))
1969 (while (re-search-forward "\n[\t ]" nil t)
1970 (replace-match " " t t)))
1971 (setq length (- (point-max) (point-min) 1)))
1972 (when (< length (window-width))
1973 (while (re-search-forward "\n[\t ]" nil t)
1974 (replace-match " " t t)))
1975 (goto-char (point-max)))))))
1977 (defun gnus-article-treat-fold-headers ()
1978 "Fold message headers."
1979 (interactive)
1980 (gnus-with-article-headers
1981 (while (not (eobp))
1982 (save-restriction
1983 (mail-header-narrow-to-field)
1984 (mail-header-fold-field)
1985 (goto-char (point-max))))))
1987 (defun gnus-treat-smiley ()
1988 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1989 (interactive)
1990 (gnus-with-article-buffer
1991 (if (memq 'smiley gnus-article-wash-types)
1992 (gnus-delete-images 'smiley)
1993 (article-goto-body)
1994 (let ((images (smiley-region (point) (point-max))))
1995 (when images
1996 (gnus-add-wash-type 'smiley)
1997 (dolist (image images)
1998 (gnus-add-image 'smiley image)))))))
2000 (defun gnus-article-remove-images ()
2001 "Remove all images from the article buffer."
2002 (interactive)
2003 (gnus-with-article-buffer
2004 (dolist (elem gnus-article-image-alist)
2005 (gnus-delete-images (car elem)))))
2007 (defun gnus-article-treat-fold-newsgroups ()
2008 "Unfold folded message headers.
2009 Only the headers that fit into the current window width will be
2010 unfolded."
2011 (interactive)
2012 (gnus-with-article-headers
2013 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2014 (save-restriction
2015 (mail-header-narrow-to-field)
2016 (while (re-search-forward ", *" nil t)
2017 (replace-match ", " t t))
2018 (mail-header-fold-field)
2019 (goto-char (point-max))))))
2021 (defun gnus-article-treat-body-boundary ()
2022 "Place a boundary line at the end of the headers."
2023 (interactive)
2024 (when (and gnus-body-boundary-delimiter
2025 (> (length gnus-body-boundary-delimiter) 0))
2026 (gnus-with-article-headers
2027 (goto-char (point-max))
2028 (let ((start (point)))
2029 (insert "X-Boundary: ")
2030 (gnus-add-text-properties start (point) '(invisible t intangible t))
2031 (insert (let (str)
2032 (while (>= (1- (window-width)) (length str))
2033 (setq str (concat str gnus-body-boundary-delimiter)))
2034 (substring str 0 (1- (window-width))))
2035 "\n")
2036 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2038 (defun article-fill-long-lines ()
2039 "Fill lines that are wider than the window width."
2040 (interactive)
2041 (save-excursion
2042 (let ((inhibit-read-only t)
2043 (width (window-width (get-buffer-window (current-buffer)))))
2044 (save-restriction
2045 (article-goto-body)
2046 (let ((adaptive-fill-mode nil)) ;Why? -sm
2047 (while (not (eobp))
2048 (end-of-line)
2049 (when (>= (current-column) (min fill-column width))
2050 (narrow-to-region (min (1+ (point)) (point-max))
2051 (gnus-point-at-bol))
2052 (let ((goback (point-marker)))
2053 (fill-paragraph nil)
2054 (goto-char (marker-position goback)))
2055 (widen))
2056 (forward-line 1)))))))
2058 (defun article-capitalize-sentences ()
2059 "Capitalize the first word in each sentence."
2060 (interactive)
2061 (save-excursion
2062 (let ((inhibit-read-only t)
2063 (paragraph-start "^[\n\^L]"))
2064 (article-goto-body)
2065 (while (not (eobp))
2066 (capitalize-word 1)
2067 (forward-sentence)))))
2069 (defun article-remove-cr ()
2070 "Remove trailing CRs and then translate remaining CRs into LFs."
2071 (interactive)
2072 (save-excursion
2073 (let ((inhibit-read-only t))
2074 (goto-char (point-min))
2075 (while (re-search-forward "\r+$" nil t)
2076 (replace-match "" t t))
2077 (goto-char (point-min))
2078 (while (search-forward "\r" nil t)
2079 (replace-match "\n" t t)))))
2081 (defun article-remove-trailing-blank-lines ()
2082 "Remove all trailing blank lines from the article."
2083 (interactive)
2084 (save-excursion
2085 (let ((inhibit-read-only t))
2086 (goto-char (point-max))
2087 (delete-region
2088 (point)
2089 (progn
2090 (while (and (not (bobp))
2091 (looking-at "^[ \t]*$")
2092 (not (gnus-annotation-in-region-p
2093 (point) (gnus-point-at-eol))))
2094 (forward-line -1))
2095 (forward-line 1)
2096 (point))))))
2098 (defun article-display-face ()
2099 "Display any Face headers in the header."
2100 (interactive)
2101 (let ((wash-face-p buffer-read-only))
2102 (gnus-with-article-headers
2103 ;; When displaying parts, this function can be called several times on
2104 ;; the same article, without any intended toggle semantic (as typing `W
2105 ;; D d' would have). So face deletion must occur only when we come from
2106 ;; an interactive command, that is when the *Article* buffer is
2107 ;; read-only.
2108 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2109 (gnus-delete-images 'face)
2110 (let (face faces)
2111 (save-excursion
2112 (when (and wash-face-p
2113 (progn
2114 (goto-char (point-min))
2115 (not (re-search-forward "^Face:[\t ]*" nil t)))
2116 (gnus-buffer-live-p gnus-original-article-buffer))
2117 (set-buffer gnus-original-article-buffer))
2118 (save-restriction
2119 (mail-narrow-to-head)
2120 (while (gnus-article-goto-header "Face")
2121 (push (mail-header-field-value) faces))))
2122 (while (setq face (pop faces))
2123 (let ((png (gnus-convert-face-to-png face))
2124 image)
2125 (when png
2126 (setq image (gnus-create-image png 'png t))
2127 (gnus-article-goto-header "from")
2128 (when (bobp)
2129 (insert "From: [no `from' set]\n")
2130 (forward-char -17))
2131 (gnus-add-wash-type 'face)
2132 (gnus-add-image 'face image)
2133 (gnus-put-image image nil 'face))))))
2136 (defun article-display-x-face (&optional force)
2137 "Look for an X-Face header and display it if present."
2138 (interactive (list 'force))
2139 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2140 (gnus-with-article-headers
2141 ;; Delete the old process, if any.
2142 (when (process-status "article-x-face")
2143 (delete-process "article-x-face"))
2144 ;; See the comment in `article-display-face'.
2145 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2146 ;; We have already displayed X-Faces, so we remove them
2147 ;; instead.
2148 (gnus-delete-images 'xface)
2149 ;; Display X-Faces.
2150 (let (x-faces from face)
2151 (save-excursion
2152 (when (and wash-face-p
2153 (progn
2154 (goto-char (point-min))
2155 (not (re-search-forward
2156 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2157 (gnus-buffer-live-p gnus-original-article-buffer))
2158 ;; If type `W f', use gnus-original-article-buffer,
2159 ;; otherwise use the current buffer because displaying
2160 ;; RFC822 parts calls this function too.
2161 (set-buffer gnus-original-article-buffer))
2162 (save-restriction
2163 (mail-narrow-to-head)
2164 (while (gnus-article-goto-header "X-Face")
2165 (push (mail-header-field-value) x-faces))
2166 (setq from (message-fetch-field "from"))))
2167 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2168 ;; single external face.
2169 (when (stringp gnus-article-x-face-command)
2170 (setq x-faces (list (car x-faces))))
2171 (while (and (setq face (pop x-faces))
2172 gnus-article-x-face-command
2173 (or force
2174 ;; Check whether this face is censored.
2175 (not gnus-article-x-face-too-ugly)
2176 (and gnus-article-x-face-too-ugly from
2177 (not (string-match gnus-article-x-face-too-ugly
2178 from)))))
2179 ;; We display the face.
2180 (cond ((stringp gnus-article-x-face-command)
2181 ;; The command is a string, so we interpret the command
2182 ;; as a, well, command, and fork it off.
2183 (let ((process-connection-type nil))
2184 (gnus-set-process-query-on-exit-flag
2185 (start-process
2186 "article-x-face" nil shell-file-name
2187 shell-command-switch gnus-article-x-face-command)
2188 nil)
2189 (with-temp-buffer
2190 (insert face)
2191 (process-send-region "article-x-face"
2192 (point-min) (point-max)))
2193 (process-send-eof "article-x-face")))
2194 ((functionp gnus-article-x-face-command)
2195 ;; The command is a lisp function, so we call it.
2196 (funcall gnus-article-x-face-command face))
2198 (error "%s is not a function"
2199 gnus-article-x-face-command)))))))))
2201 (defun article-decode-mime-words ()
2202 "Decode all MIME-encoded words in the article."
2203 (interactive)
2204 (save-excursion
2205 (set-buffer gnus-article-buffer)
2206 (let ((inhibit-point-motion-hooks t)
2207 (inhibit-read-only t)
2208 (mail-parse-charset gnus-newsgroup-charset)
2209 (mail-parse-ignored-charsets
2210 (save-excursion (set-buffer gnus-summary-buffer)
2211 gnus-newsgroup-ignored-charsets)))
2212 (mail-decode-encoded-word-region (point-min) (point-max)))))
2214 (defun article-decode-charset (&optional prompt)
2215 "Decode charset-encoded text in the article.
2216 If PROMPT (the prefix), prompt for a coding system to use."
2217 (interactive "P")
2218 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2219 (inhibit-read-only t)
2220 (mail-parse-charset gnus-newsgroup-charset)
2221 (mail-parse-ignored-charsets
2222 (save-excursion (condition-case nil
2223 (set-buffer gnus-summary-buffer)
2224 (error))
2225 gnus-newsgroup-ignored-charsets))
2226 ct cte ctl charset format)
2227 (save-excursion
2228 (save-restriction
2229 (article-narrow-to-head)
2230 (setq ct (message-fetch-field "Content-Type" t)
2231 cte (message-fetch-field "Content-Transfer-Encoding" t)
2232 ctl (and ct (ignore-errors
2233 (mail-header-parse-content-type ct)))
2234 charset (cond
2235 (prompt
2236 (mm-read-coding-system "Charset to decode: "))
2237 (ctl
2238 (mail-content-type-get ctl 'charset)))
2239 format (and ctl (mail-content-type-get ctl 'format)))
2240 (when cte
2241 (setq cte (mail-header-strip cte)))
2242 (if (and ctl (not (string-match "/" (car ctl))))
2243 (setq ctl nil))
2244 (goto-char (point-max)))
2245 (forward-line 1)
2246 (save-restriction
2247 (narrow-to-region (point) (point-max))
2248 (when (and (eq mail-parse-charset 'gnus-decoded)
2249 (eq (mm-body-7-or-8) '8bit))
2250 ;; The text code could have been decoded.
2251 (setq charset mail-parse-charset))
2252 (when (and (or (not ctl)
2253 (equal (car ctl) "text/plain"))
2254 (not format)) ;; article with format will decode later.
2255 (mm-decode-body
2256 charset (and cte (intern (downcase
2257 (gnus-strip-whitespace cte))))
2258 (car ctl)))))))
2260 (defun article-decode-encoded-words ()
2261 "Remove encoded-word encoding from headers."
2262 (let ((inhibit-point-motion-hooks t)
2263 (mail-parse-charset gnus-newsgroup-charset)
2264 (mail-parse-ignored-charsets
2265 (save-excursion (condition-case nil
2266 (set-buffer gnus-summary-buffer)
2267 (error))
2268 gnus-newsgroup-ignored-charsets))
2269 (inhibit-read-only t))
2270 (save-restriction
2271 (article-narrow-to-head)
2272 (funcall gnus-decode-header-function (point-min) (point-max)))))
2274 (defun article-decode-group-name ()
2275 "Decode group names in `Newsgroups:'."
2276 (let ((inhibit-point-motion-hooks t)
2277 (inhibit-read-only t)
2278 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2279 (when (and (or gnus-group-name-charset-method-alist
2280 gnus-group-name-charset-group-alist)
2281 (gnus-buffer-live-p gnus-original-article-buffer))
2282 (save-restriction
2283 (article-narrow-to-head)
2284 (with-current-buffer gnus-original-article-buffer
2285 (goto-char (point-min)))
2286 (while (re-search-forward
2287 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2288 (replace-match (save-match-data
2289 (gnus-decode-newsgroups
2290 ;; XXX how to use data in article buffer?
2291 (with-current-buffer gnus-original-article-buffer
2292 (re-search-forward
2293 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2294 nil t)
2295 (match-string 1))
2296 gnus-newsgroup-name method))
2297 t t nil 1))
2298 (goto-char (point-min))
2299 (with-current-buffer gnus-original-article-buffer
2300 (goto-char (point-min)))
2301 (while (re-search-forward
2302 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2303 (replace-match (save-match-data
2304 (gnus-decode-newsgroups
2305 ;; XXX how to use data in article buffer?
2306 (with-current-buffer gnus-original-article-buffer
2307 (re-search-forward
2308 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2309 nil t)
2310 (match-string 1))
2311 gnus-newsgroup-name method))
2312 t t nil 1))))))
2314 (autoload 'idna-to-unicode "idna")
2316 (defun article-decode-idna-rhs ()
2317 "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2318 (when gnus-use-idna
2319 (save-restriction
2320 (let ((inhibit-point-motion-hooks t)
2321 (inhibit-read-only t))
2322 (article-narrow-to-head)
2323 (goto-char (point-min))
2324 (while (re-search-forward "@.*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2325 (let (ace unicode)
2326 (when (save-match-data
2327 (and (setq ace (match-string 1))
2328 (save-excursion
2329 (and (re-search-backward "^[^ \t]" nil t)
2330 (looking-at "From\\|To\\|Cc")))
2331 (setq unicode (idna-to-unicode ace))))
2332 (unless (string= ace unicode)
2333 (replace-match unicode nil nil nil 1)))))))))
2335 (defun article-de-quoted-unreadable (&optional force read-charset)
2336 "Translate a quoted-printable-encoded article.
2337 If FORCE, decode the article whether it is marked as quoted-printable
2338 or not.
2339 If READ-CHARSET, ask for a coding system."
2340 (interactive (list 'force current-prefix-arg))
2341 (save-excursion
2342 (let ((inhibit-read-only t) type charset)
2343 (if (gnus-buffer-live-p gnus-original-article-buffer)
2344 (with-current-buffer gnus-original-article-buffer
2345 (setq type
2346 (gnus-fetch-field "content-transfer-encoding"))
2347 (let* ((ct (gnus-fetch-field "content-type"))
2348 (ctl (and ct
2349 (ignore-errors
2350 (mail-header-parse-content-type ct)))))
2351 (setq charset (and ctl
2352 (mail-content-type-get ctl 'charset)))
2353 (if (stringp charset)
2354 (setq charset (intern (downcase charset)))))))
2355 (if read-charset
2356 (setq charset (mm-read-coding-system "Charset: " charset)))
2357 (unless charset
2358 (setq charset gnus-newsgroup-charset))
2359 (when (or force
2360 (and type (let ((case-fold-search t))
2361 (string-match "quoted-printable" type))))
2362 (article-goto-body)
2363 (quoted-printable-decode-region
2364 (point) (point-max) (mm-charset-to-coding-system charset))))))
2366 (defun article-de-base64-unreadable (&optional force read-charset)
2367 "Translate a base64 article.
2368 If FORCE, decode the article whether it is marked as base64 not.
2369 If READ-CHARSET, ask for a coding system."
2370 (interactive (list 'force current-prefix-arg))
2371 (save-excursion
2372 (let ((inhibit-read-only t) type charset)
2373 (if (gnus-buffer-live-p gnus-original-article-buffer)
2374 (with-current-buffer gnus-original-article-buffer
2375 (setq type
2376 (gnus-fetch-field "content-transfer-encoding"))
2377 (let* ((ct (gnus-fetch-field "content-type"))
2378 (ctl (and ct
2379 (ignore-errors
2380 (mail-header-parse-content-type ct)))))
2381 (setq charset (and ctl
2382 (mail-content-type-get ctl 'charset)))
2383 (if (stringp charset)
2384 (setq charset (intern (downcase charset)))))))
2385 (if read-charset
2386 (setq charset (mm-read-coding-system "Charset: " charset)))
2387 (unless charset
2388 (setq charset gnus-newsgroup-charset))
2389 (when (or force
2390 (and type (let ((case-fold-search t))
2391 (string-match "base64" type))))
2392 (article-goto-body)
2393 (save-restriction
2394 (narrow-to-region (point) (point-max))
2395 (base64-decode-region (point-min) (point-max))
2396 (mm-decode-coding-region
2397 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2399 (eval-when-compile
2400 (require 'rfc1843))
2402 (defun article-decode-HZ ()
2403 "Translate a HZ-encoded article."
2404 (interactive)
2405 (require 'rfc1843)
2406 (save-excursion
2407 (let ((inhibit-read-only t))
2408 (rfc1843-decode-region (point-min) (point-max)))))
2410 (defun article-unsplit-urls ()
2411 "Remove the newlines that some other mailers insert into URLs."
2412 (interactive)
2413 (save-excursion
2414 (let ((inhibit-read-only t))
2415 (goto-char (point-min))
2416 (while (re-search-forward
2417 "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2418 (replace-match "\\1\\3" t)))
2419 (when (interactive-p)
2420 (gnus-treat-article nil))))
2423 (defun article-wash-html (&optional read-charset)
2424 "Format an HTML article.
2425 If READ-CHARSET, ask for a coding system."
2426 (interactive "P")
2427 (save-excursion
2428 (let ((inhibit-read-only t)
2429 charset)
2430 (when (gnus-buffer-live-p gnus-original-article-buffer)
2431 (with-current-buffer gnus-original-article-buffer
2432 (let* ((ct (gnus-fetch-field "content-type"))
2433 (ctl (and ct
2434 (ignore-errors
2435 (mail-header-parse-content-type ct)))))
2436 (setq charset (and ctl
2437 (mail-content-type-get ctl 'charset)))
2438 (when (stringp charset)
2439 (setq charset (intern (downcase charset)))))))
2440 (when read-charset
2441 (setq charset (mm-read-coding-system "Charset: " charset)))
2442 (unless charset
2443 (setq charset gnus-newsgroup-charset))
2444 (article-goto-body)
2445 (save-window-excursion
2446 (save-restriction
2447 (narrow-to-region (point) (point-max))
2448 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2449 (entry (assq func mm-text-html-washer-alist)))
2450 (when entry
2451 (setq func (cdr entry)))
2452 (cond
2453 ((functionp func)
2454 (funcall func))
2456 (apply (car func) (cdr func))))))))))
2458 (defun gnus-article-wash-html-with-w3 ()
2459 "Wash the current buffer with w3."
2460 (mm-setup-w3)
2461 (let ((w3-strict-width (window-width))
2462 (url-standalone-mode t)
2463 (url-gateway-unplugged t)
2464 (w3-honor-stylesheets nil))
2465 (condition-case ()
2466 (w3-region (point-min) (point-max))
2467 (error))))
2469 (defun gnus-article-wash-html-with-w3m ()
2470 "Wash the current buffer with emacs-w3m."
2471 (mm-setup-w3m)
2472 (save-restriction
2473 (narrow-to-region (point) (point-max))
2474 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2475 w3m-force-redisplay)
2476 (w3m-region (point-min) (point-max)))
2477 (when (and mm-inline-text-html-with-w3m-keymap
2478 (boundp 'w3m-minor-mode-map)
2479 w3m-minor-mode-map)
2480 (add-text-properties
2481 (point-min) (point-max)
2482 (list 'keymap w3m-minor-mode-map
2483 ;; Put the mark meaning this part was rendered by emacs-w3m.
2484 'mm-inline-text-html-with-w3m t)))))
2486 (defun article-hide-list-identifiers ()
2487 "Remove list identifies from the Subject header.
2488 The `gnus-list-identifiers' variable specifies what to do."
2489 (interactive)
2490 (let ((inhibit-point-motion-hooks t)
2491 (regexp (if (consp gnus-list-identifiers)
2492 (mapconcat 'identity gnus-list-identifiers " *\\|")
2493 gnus-list-identifiers))
2494 (inhibit-read-only t))
2495 (when regexp
2496 (save-excursion
2497 (save-restriction
2498 (article-narrow-to-head)
2499 (goto-char (point-min))
2500 (while (re-search-forward
2501 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2502 nil t)
2503 (delete-region (match-beginning 2) (match-end 0))
2504 (beginning-of-line))
2505 (when (re-search-forward
2506 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2507 (delete-region (match-beginning 1) (match-end 1))))))))
2509 (defun article-hide-pem (&optional arg)
2510 "Toggle hiding of any PEM headers and signatures in the current article.
2511 If given a negative prefix, always show; if given a positive prefix,
2512 always hide."
2513 (interactive (gnus-article-hidden-arg))
2514 (unless (gnus-article-check-hidden-text 'pem arg)
2515 (save-excursion
2516 (let ((inhibit-read-only t) end)
2517 (goto-char (point-min))
2518 ;; Hide the horrendously ugly "header".
2519 (when (and (search-forward
2520 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2521 nil t)
2522 (setq end (1+ (match-beginning 0))))
2523 (gnus-add-wash-type 'pem)
2524 (gnus-article-hide-text-type
2526 (if (search-forward "\n\n" nil t)
2527 (match-end 0)
2528 (point-max))
2529 'pem)
2530 ;; Hide the trailer as well
2531 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2532 nil t)
2533 (gnus-article-hide-text-type
2534 (match-beginning 0) (match-end 0) 'pem)))))))
2536 (defun article-strip-banner ()
2537 "Strip the banners specified by the `banner' group parameter and by
2538 `gnus-article-address-banner-alist'."
2539 (interactive)
2540 (save-excursion
2541 (save-restriction
2542 (let ((inhibit-point-motion-hooks t))
2543 (when (gnus-parameter-banner gnus-newsgroup-name)
2544 (article-really-strip-banner
2545 (gnus-parameter-banner gnus-newsgroup-name)))
2546 (when gnus-article-address-banner-alist
2547 (article-really-strip-banner
2548 (let ((from (save-restriction
2549 (widen)
2550 (article-narrow-to-head)
2551 (mail-fetch-field "from"))))
2552 (when (and from
2553 (setq from
2554 (caar (mail-header-parse-addresses from))))
2555 (catch 'found
2556 (dolist (pair gnus-article-address-banner-alist)
2557 (when (string-match (car pair) from)
2558 (throw 'found (cdr pair)))))))))))))
2560 (defun article-really-strip-banner (banner)
2561 "Strip the banner specified by the argument."
2562 (save-excursion
2563 (save-restriction
2564 (let ((inhibit-point-motion-hooks t)
2565 (gnus-signature-limit nil)
2566 (inhibit-read-only t))
2567 (article-goto-body)
2568 (cond
2569 ((eq banner 'signature)
2570 (when (gnus-article-narrow-to-signature)
2571 (widen)
2572 (forward-line -1)
2573 (delete-region (point) (point-max))))
2574 ((symbolp banner)
2575 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2576 (while (re-search-forward banner nil t)
2577 (delete-region (match-beginning 0) (match-end 0)))))
2578 ((stringp banner)
2579 (while (re-search-forward banner nil t)
2580 (delete-region (match-beginning 0) (match-end 0)))))))))
2582 (defun article-babel ()
2583 "Translate article using an online translation service."
2584 (interactive)
2585 (require 'babel)
2586 (save-excursion
2587 (set-buffer gnus-article-buffer)
2588 (when (article-goto-body)
2589 (let* ((inhibit-read-only t)
2590 (start (point))
2591 (end (point-max))
2592 (orig (buffer-substring start end))
2593 (trans (babel-as-string orig)))
2594 (save-restriction
2595 (narrow-to-region start end)
2596 (delete-region start end)
2597 (insert trans))))))
2599 (defun article-hide-signature (&optional arg)
2600 "Hide the signature in the current article.
2601 If given a negative prefix, always show; if given a positive prefix,
2602 always hide."
2603 (interactive (gnus-article-hidden-arg))
2604 (unless (gnus-article-check-hidden-text 'signature arg)
2605 (save-excursion
2606 (save-restriction
2607 (let ((inhibit-read-only t))
2608 (when (gnus-article-narrow-to-signature)
2609 (gnus-article-hide-text-type
2610 (point-min) (point-max) 'signature))))))
2611 (gnus-set-mode-line 'article))
2613 (defun article-strip-headers-in-body ()
2614 "Strip offensive headers from bodies."
2615 (interactive)
2616 (save-excursion
2617 (article-goto-body)
2618 (let ((case-fold-search t))
2619 (when (looking-at "x-no-archive:")
2620 (gnus-delete-line)))))
2622 (defun article-strip-leading-blank-lines ()
2623 "Remove all blank lines from the beginning of the article."
2624 (interactive)
2625 (save-excursion
2626 (let ((inhibit-point-motion-hooks t)
2627 (inhibit-read-only t))
2628 (when (article-goto-body)
2629 (while (and (not (eobp))
2630 (looking-at "[ \t]*$"))
2631 (gnus-delete-line))))))
2633 (defun article-narrow-to-head ()
2634 "Narrow the buffer to the head of the message.
2635 Point is left at the beginning of the narrowed-to region."
2636 (narrow-to-region
2637 (goto-char (point-min))
2638 (if (search-forward "\n\n" nil 1)
2639 (1- (point))
2640 (point-max)))
2641 (goto-char (point-min)))
2643 (defun article-goto-body ()
2644 "Place point at the start of the body."
2645 (goto-char (point-min))
2646 (cond
2647 ;; This variable is only bound when dealing with separate
2648 ;; MIME body parts.
2649 (article-goto-body-goes-to-point-min-p
2651 ((search-forward "\n\n" nil t)
2654 (goto-char (point-max))
2655 nil)))
2657 (defun article-strip-multiple-blank-lines ()
2658 "Replace consecutive blank lines with one empty line."
2659 (interactive)
2660 (save-excursion
2661 (let ((inhibit-point-motion-hooks t)
2662 (inhibit-read-only t))
2663 ;; First make all blank lines empty.
2664 (article-goto-body)
2665 (while (re-search-forward "^[ \t]+$" nil t)
2666 (unless (gnus-annotation-in-region-p
2667 (match-beginning 0) (match-end 0))
2668 (replace-match "" nil t)))
2669 ;; Then replace multiple empty lines with a single empty line.
2670 (article-goto-body)
2671 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2672 (unless (gnus-annotation-in-region-p
2673 (match-beginning 0) (match-end 0))
2674 (delete-region (match-beginning 1) (match-end 1)))))))
2676 (defun article-strip-leading-space ()
2677 "Remove all white space from the beginning of the lines in the article."
2678 (interactive)
2679 (save-excursion
2680 (let ((inhibit-point-motion-hooks t)
2681 (inhibit-read-only t))
2682 (article-goto-body)
2683 (while (re-search-forward "^[ \t]+" nil t)
2684 (replace-match "" t t)))))
2686 (defun article-strip-trailing-space ()
2687 "Remove all white space from the end of the lines in the article."
2688 (interactive)
2689 (save-excursion
2690 (let ((inhibit-point-motion-hooks t)
2691 (inhibit-read-only t))
2692 (article-goto-body)
2693 (while (re-search-forward "[ \t]+$" nil t)
2694 (replace-match "" t t)))))
2696 (defun article-strip-blank-lines ()
2697 "Strip leading, trailing and multiple blank lines."
2698 (interactive)
2699 (article-strip-leading-blank-lines)
2700 (article-remove-trailing-blank-lines)
2701 (article-strip-multiple-blank-lines))
2703 (defun article-strip-all-blank-lines ()
2704 "Strip all blank lines."
2705 (interactive)
2706 (save-excursion
2707 (let ((inhibit-point-motion-hooks t)
2708 (inhibit-read-only t))
2709 (article-goto-body)
2710 (while (re-search-forward "^[ \t]*\n" nil t)
2711 (replace-match "" t t)))))
2713 (defun gnus-article-narrow-to-signature ()
2714 "Narrow to the signature; return t if a signature is found, else nil."
2715 (let ((inhibit-point-motion-hooks t))
2716 (when (gnus-article-search-signature)
2717 (forward-line 1)
2718 ;; Check whether we have some limits to what we consider
2719 ;; to be a signature.
2720 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2721 (list gnus-signature-limit)))
2722 limit limited)
2723 (while (setq limit (pop limits))
2724 (if (or (and (integerp limit)
2725 (< (- (point-max) (point)) limit))
2726 (and (floatp limit)
2727 (< (count-lines (point) (point-max)) limit))
2728 (and (functionp limit)
2729 (funcall limit))
2730 (and (stringp limit)
2731 (not (re-search-forward limit nil t))))
2732 () ; This limit did not succeed.
2733 (setq limited t
2734 limits nil)))
2735 (unless limited
2736 (narrow-to-region (point) (point-max))
2737 t)))))
2739 (defun gnus-article-search-signature ()
2740 "Search the current buffer for the signature separator.
2741 Put point at the beginning of the signature separator."
2742 (let ((cur (point)))
2743 (goto-char (point-max))
2744 (if (if (stringp gnus-signature-separator)
2745 (re-search-backward gnus-signature-separator nil t)
2746 (let ((seps gnus-signature-separator))
2747 (while (and seps
2748 (not (re-search-backward (car seps) nil t)))
2749 (pop seps))
2750 seps))
2752 (goto-char cur)
2753 nil)))
2755 (defun gnus-article-hidden-arg ()
2756 "Return the current prefix arg as a number, or 0 if no prefix."
2757 (list (if current-prefix-arg
2758 (prefix-numeric-value current-prefix-arg)
2759 0)))
2761 (defun gnus-article-check-hidden-text (type arg)
2762 "Return nil if hiding is necessary.
2763 Arg can be nil or a number. nil and positive means hide, negative
2764 means show, 0 means toggle."
2765 (save-excursion
2766 (save-restriction
2767 (let ((hide (gnus-article-hidden-text-p type)))
2768 (cond
2769 ((or (null arg)
2770 (> arg 0))
2771 nil)
2772 ((< arg 0)
2773 (gnus-article-show-hidden-text type)
2776 (if (eq hide 'hidden)
2777 (progn
2778 (gnus-article-show-hidden-text type)
2780 nil)))))))
2782 (defun gnus-article-hidden-text-p (type)
2783 "Say whether the current buffer contains hidden text of type TYPE."
2784 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2785 (while (and pos
2786 (not (get-text-property pos 'invisible))
2787 (not (get-text-property pos 'dummy-invisible)))
2788 (setq pos
2789 (text-property-any (1+ pos) (point-max) 'article-type type)))
2790 (if pos
2791 'hidden
2792 nil)))
2794 (defun gnus-article-show-hidden-text (type &optional dummy)
2795 "Show all hidden text of type TYPE.
2796 Originally it is hide instead of DUMMY."
2797 (let ((inhibit-read-only t)
2798 (inhibit-point-motion-hooks t))
2799 (gnus-remove-text-properties-when
2800 'article-type type
2801 (point-min) (point-max)
2802 (cons 'article-type (cons type
2803 gnus-hidden-properties)))
2804 (gnus-delete-wash-type type)))
2806 (defconst article-time-units
2807 `((year . ,(* 365.25 24 60 60))
2808 (week . ,(* 7 24 60 60))
2809 (day . ,(* 24 60 60))
2810 (hour . ,(* 60 60))
2811 (minute . 60)
2812 (second . 1))
2813 "Mapping from time units to seconds.")
2815 (defun gnus-article-forward-header ()
2816 "Move point to the start of the next header.
2817 If the current header is a continuation header, this can be several
2818 lines forward."
2819 (let ((ended nil))
2820 (while (not ended)
2821 (forward-line 1)
2822 (if (looking-at "[ \t]+[^ \t]")
2823 (forward-line 1)
2824 (setq ended t)))))
2826 (defun article-date-ut (&optional type highlight)
2827 "Convert DATE date to universal time in the current article.
2828 If TYPE is `local', convert to local time; if it is `lapsed', output
2829 how much time has lapsed since DATE. For `lapsed', the value of
2830 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2831 should replace the \"Date:\" one, or should be added below it."
2832 (interactive (list 'ut t))
2833 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2834 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2835 tdate-regexp)
2836 ((eq type 'lapsed)
2837 "^X-Sent:[ \t]")
2838 (article-lapsed-timer
2839 "^Date:[ \t]")
2841 tdate-regexp)))
2842 (case-fold-search t)
2843 (inhibit-read-only t)
2844 (inhibit-point-motion-hooks t)
2845 pos date bface eface)
2846 (save-excursion
2847 (save-restriction
2848 (widen)
2849 (goto-char (point-min))
2850 (while (or (setq date (get-text-property (setq pos (point))
2851 'original-date))
2852 (when (setq pos (next-single-property-change
2853 (point) 'original-date))
2854 (setq date (get-text-property pos 'original-date))
2856 (narrow-to-region pos (or (text-property-any pos (point-max)
2857 'original-date nil)
2858 (point-max)))
2859 (goto-char (point-min))
2860 (when (re-search-forward tdate-regexp nil t)
2861 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2862 eface (get-text-property (1- (gnus-point-at-eol)) 'face)))
2863 (goto-char (point-min))
2864 (setq pos nil)
2865 ;; Delete any old Date headers.
2866 (while (re-search-forward date-regexp nil t)
2867 (if pos
2868 (delete-region (gnus-point-at-bol)
2869 (progn
2870 (gnus-article-forward-header)
2871 (point)))
2872 (delete-region (gnus-point-at-bol)
2873 (progn
2874 (gnus-article-forward-header)
2875 (forward-char -1)
2876 (point)))
2877 (setq pos (point))))
2878 (when (and (not pos)
2879 (re-search-forward tdate-regexp nil t))
2880 (forward-line 1))
2881 (gnus-goto-char pos)
2882 (insert (article-make-date-line date (or type 'ut)))
2883 (unless pos
2884 (insert "\n")
2885 (forward-line -1))
2886 ;; Do highlighting.
2887 (beginning-of-line)
2888 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2889 (put-text-property (match-beginning 1) (1+ (match-end 1))
2890 'face bface)
2891 (put-text-property (match-beginning 2) (match-end 2)
2892 'face eface))
2893 (put-text-property (point-min) (1- (point-max)) 'original-date date)
2894 (goto-char (point-max))
2895 (widen))))))
2897 (defun article-make-date-line (date type)
2898 "Return a DATE line of TYPE."
2899 (unless (memq type '(local ut original user iso8601 lapsed english))
2900 (error "Unknown conversion type: %s" type))
2901 (condition-case ()
2902 (let ((time (date-to-time date)))
2903 (cond
2904 ;; Convert to the local timezone.
2905 ((eq type 'local)
2906 (let ((tz (car (current-time-zone time))))
2907 (format "Date: %s %s%02d%02d" (current-time-string time)
2908 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2909 (/ (% (abs tz) 3600) 60))))
2910 ;; Convert to Universal Time.
2911 ((eq type 'ut)
2912 (concat "Date: "
2913 (current-time-string
2914 (let* ((e (parse-time-string date))
2915 (tm (apply 'encode-time e))
2916 (ms (car tm))
2917 (ls (- (cadr tm) (car (current-time-zone time)))))
2918 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2919 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2920 (t (list ms ls)))))
2921 " UT"))
2922 ;; Get the original date from the article.
2923 ((eq type 'original)
2924 (concat "Date: " (if (string-match "\n+$" date)
2925 (substring date 0 (match-beginning 0))
2926 date)))
2927 ;; Let the user define the format.
2928 ((eq type 'user)
2929 (let ((format (or (condition-case nil
2930 (with-current-buffer gnus-summary-buffer
2931 gnus-article-time-format)
2932 (error nil))
2933 gnus-article-time-format)))
2934 (if (functionp format)
2935 (funcall format time)
2936 (concat "Date: " (format-time-string format time)))))
2937 ;; ISO 8601.
2938 ((eq type 'iso8601)
2939 (let ((tz (car (current-time-zone time))))
2940 (concat
2941 "Date: "
2942 (format-time-string "%Y%m%dT%H%M%S" time)
2943 (format "%s%02d%02d"
2944 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2945 (/ (% (abs tz) 3600) 60)))))
2946 ;; Do an X-Sent lapsed format.
2947 ((eq type 'lapsed)
2948 ;; If the date is seriously mangled, the timezone functions are
2949 ;; liable to bug out, so we ignore all errors.
2950 (let* ((now (current-time))
2951 (real-time (subtract-time now time))
2952 (real-sec (and real-time
2953 (+ (* (float (car real-time)) 65536)
2954 (cadr real-time))))
2955 (sec (and real-time (abs real-sec)))
2956 num prev)
2957 (cond
2958 ((null real-time)
2959 "X-Sent: Unknown")
2960 ((zerop sec)
2961 "X-Sent: Now")
2963 (concat
2964 "X-Sent: "
2965 ;; This is a bit convoluted, but basically we go
2966 ;; through the time units for years, weeks, etc,
2967 ;; and divide things to see whether that results
2968 ;; in positive answers.
2969 (mapconcat
2970 (lambda (unit)
2971 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2972 ;; The (remaining) seconds are too few to
2973 ;; be divided into this time unit.
2975 ;; It's big enough, so we output it.
2976 (setq sec (- sec (* num (cdr unit))))
2977 (prog1
2978 (concat (if prev ", " "") (int-to-string
2979 (floor num))
2980 " " (symbol-name (car unit))
2981 (if (> num 1) "s" ""))
2982 (setq prev t))))
2983 article-time-units "")
2984 ;; If dates are odd, then it might appear like the
2985 ;; article was sent in the future.
2986 (if (> real-sec 0)
2987 " ago"
2988 " in the future"))))))
2989 ;; Display the date in proper English
2990 ((eq type 'english)
2991 (let ((dtime (decode-time time)))
2992 (concat
2993 "Date: the "
2994 (number-to-string (nth 3 dtime))
2995 (let ((digit (% (nth 3 dtime) 10)))
2996 (cond
2997 ((memq (nth 3 dtime) '(11 12 13)) "th")
2998 ((= digit 1) "st")
2999 ((= digit 2) "nd")
3000 ((= digit 3) "rd")
3001 (t "th")))
3002 " of "
3003 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3005 (number-to-string (nth 5 dtime))
3006 " at "
3007 (format "%02d" (nth 2 dtime))
3009 (format "%02d" (nth 1 dtime)))))))
3010 (error
3011 (format "Date: %s (from Gnus)" date))))
3013 (defun article-date-local (&optional highlight)
3014 "Convert the current article date to the local timezone."
3015 (interactive (list t))
3016 (article-date-ut 'local highlight))
3018 (defun article-date-english (&optional highlight)
3019 "Convert the current article date to something that is proper English."
3020 (interactive (list t))
3021 (article-date-ut 'english highlight))
3023 (defun article-date-original (&optional highlight)
3024 "Convert the current article date to what it was originally.
3025 This is only useful if you have used some other date conversion
3026 function and want to see what the date was before converting."
3027 (interactive (list t))
3028 (article-date-ut 'original highlight))
3030 (defun article-date-lapsed (&optional highlight)
3031 "Convert the current article date to time lapsed since it was sent."
3032 (interactive (list t))
3033 (article-date-ut 'lapsed highlight))
3035 (defun article-update-date-lapsed ()
3036 "Function to be run from a timer to update the lapsed time line."
3037 (let (deactivate-mark)
3038 (save-excursion
3039 (ignore-errors
3040 (walk-windows
3041 (lambda (w)
3042 (set-buffer (window-buffer w))
3043 (when (eq major-mode 'gnus-article-mode)
3044 (let ((mark (point-marker)))
3045 (goto-char (point-min))
3046 (when (re-search-forward "^X-Sent:" nil t)
3047 (article-date-lapsed t))
3048 (goto-char (marker-position mark))
3049 (move-marker mark nil))))
3050 nil 'visible)))))
3052 (defun gnus-start-date-timer (&optional n)
3053 "Start a timer to update the X-Sent header in the article buffers.
3054 The numerical prefix says how frequently (in seconds) the function
3055 is to run."
3056 (interactive "p")
3057 (unless n
3058 (setq n 1))
3059 (gnus-stop-date-timer)
3060 (setq article-lapsed-timer
3061 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
3063 (defun gnus-stop-date-timer ()
3064 "Stop the X-Sent timer."
3065 (interactive)
3066 (when article-lapsed-timer
3067 (nnheader-cancel-timer article-lapsed-timer)
3068 (setq article-lapsed-timer nil)))
3070 (defun article-date-user (&optional highlight)
3071 "Convert the current article date to the user-defined format.
3072 This format is defined by the `gnus-article-time-format' variable."
3073 (interactive (list t))
3074 (article-date-ut 'user highlight))
3076 (defun article-date-iso8601 (&optional highlight)
3077 "Convert the current article date to ISO8601."
3078 (interactive (list t))
3079 (article-date-ut 'iso8601 highlight))
3081 (defmacro gnus-article-save-original-date (&rest forms)
3082 "Save the original date as a text property and evaluate FORMS."
3083 `(let* ((case-fold-search t)
3084 (start (progn
3085 (goto-char (point-min))
3086 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3087 (not (bolp)))
3088 (match-end 0))))
3089 (date (when (and start
3090 (re-search-forward "[\t ]*\n\\([^\t ]\\|\\'\\)"
3091 nil t))
3092 (buffer-substring-no-properties start
3093 (match-beginning 0)))))
3094 (goto-char (point-max))
3095 (skip-chars-backward "\n")
3096 (put-text-property (point-min) (point) 'original-date date)
3097 ,@forms
3098 (goto-char (point-max))
3099 (skip-chars-backward "\n")
3100 (put-text-property (point-min) (point) 'original-date date)))
3102 ;; (defun article-show-all ()
3103 ;; "Show all hidden text in the article buffer."
3104 ;; (interactive)
3105 ;; (save-excursion
3106 ;; (let ((inhibit-read-only t))
3107 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3109 (defun article-remove-leading-whitespace ()
3110 "Remove excessive whitespace from all headers."
3111 (interactive)
3112 (save-excursion
3113 (save-restriction
3114 (let ((inhibit-read-only t))
3115 (article-narrow-to-head)
3116 (goto-char (point-min))
3117 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3118 (delete-region (match-beginning 1) (match-end 1)))))))
3120 (defun article-emphasize (&optional arg)
3121 "Emphasize text according to `gnus-emphasis-alist'."
3122 (interactive (gnus-article-hidden-arg))
3123 (unless (gnus-article-check-hidden-text 'emphasis arg)
3124 (save-excursion
3125 (let ((alist (or
3126 (condition-case nil
3127 (with-current-buffer gnus-summary-buffer
3128 gnus-article-emphasis-alist)
3129 (error))
3130 gnus-emphasis-alist))
3131 (inhibit-read-only t)
3132 (props (append '(article-type emphasis)
3133 gnus-hidden-properties))
3134 regexp elem beg invisible visible face)
3135 (article-goto-body)
3136 (setq beg (point))
3137 (while (setq elem (pop alist))
3138 (goto-char beg)
3139 (setq regexp (car elem)
3140 invisible (nth 1 elem)
3141 visible (nth 2 elem)
3142 face (nth 3 elem))
3143 (while (re-search-forward regexp nil t)
3144 (when (and (match-beginning visible) (match-beginning invisible))
3145 (gnus-article-hide-text
3146 (match-beginning invisible) (match-end invisible) props)
3147 (gnus-article-unhide-text-type
3148 (match-beginning visible) (match-end visible) 'emphasis)
3149 (gnus-put-overlay-excluding-newlines
3150 (match-beginning visible) (match-end visible) 'face face)
3151 (gnus-add-wash-type 'emphasis)
3152 (goto-char (match-end invisible)))))))))
3154 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3155 "Setup newsgroup emphasis alist."
3156 (unless gnus-article-emphasis-alist
3157 (let ((name (and gnus-newsgroup-name
3158 (gnus-group-real-name gnus-newsgroup-name))))
3159 (make-local-variable 'gnus-article-emphasis-alist)
3160 (setq gnus-article-emphasis-alist
3161 (nconc
3162 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3163 (while (setq elem (pop alist))
3164 (when (and name (string-match (car elem) name))
3165 (setq alist nil
3166 highlight (copy-sequence (cdr elem)))))
3167 highlight)
3168 (copy-sequence highlight-words)
3169 (if gnus-newsgroup-name
3170 (copy-sequence (gnus-group-find-parameter
3171 gnus-newsgroup-name 'highlight-words t)))
3172 gnus-emphasis-alist)))))
3174 (eval-when-compile
3175 (defvar gnus-summary-article-menu)
3176 (defvar gnus-summary-post-menu))
3178 ;;; Saving functions.
3180 (defun gnus-article-save (save-buffer file &optional num)
3181 "Save the currently selected article."
3182 (unless gnus-save-all-headers
3183 ;; Remove headers according to `gnus-saved-headers'.
3184 (let ((gnus-visible-headers
3185 (or gnus-saved-headers gnus-visible-headers))
3186 (gnus-article-buffer save-buffer))
3187 (save-excursion
3188 (set-buffer save-buffer)
3189 (article-hide-headers 1 t))))
3190 (save-window-excursion
3191 (if (not gnus-default-article-saver)
3192 (error "No default saver is defined")
3193 ;; !!! Magic! The saving functions all save
3194 ;; `gnus-save-article-buffer' (or so they think), but we
3195 ;; bind that variable to our save-buffer.
3196 (set-buffer gnus-article-buffer)
3197 (let* ((gnus-save-article-buffer save-buffer)
3198 (filename
3199 (cond
3200 ((not gnus-prompt-before-saving) 'default)
3201 ((eq gnus-prompt-before-saving 'always) nil)
3202 (t file)))
3203 (gnus-number-of-articles-to-be-saved
3204 (when (eq gnus-prompt-before-saving t)
3205 num))) ; Magic
3206 (set-buffer gnus-article-current-summary)
3207 (funcall gnus-default-article-saver filename)))))
3209 (defun gnus-read-save-file-name (prompt &optional filename
3210 function group headers variable)
3211 (let ((default-name
3212 (funcall function group headers (symbol-value variable)))
3213 result)
3214 (setq result
3215 (expand-file-name
3216 (cond
3217 ((eq filename 'default)
3218 default-name)
3219 ((eq filename t)
3220 default-name)
3221 (filename filename)
3223 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3224 (prompt
3225 (format prompt
3226 (if (and gnus-number-of-articles-to-be-saved
3227 (> gnus-number-of-articles-to-be-saved 1))
3228 (format "these %d articles"
3229 gnus-number-of-articles-to-be-saved)
3230 "this article")))
3231 (file
3232 ;; Let the split methods have their say.
3233 (cond
3234 ;; No split name was found.
3235 ((null split-name)
3236 (read-file-name
3237 (concat prompt " (default "
3238 (file-name-nondirectory default-name) ") ")
3239 (file-name-directory default-name)
3240 default-name))
3241 ;; A single group name is returned.
3242 ((stringp split-name)
3243 (setq default-name
3244 (funcall function split-name headers
3245 (symbol-value variable)))
3246 (read-file-name
3247 (concat prompt " (default "
3248 (file-name-nondirectory default-name) ") ")
3249 (file-name-directory default-name)
3250 default-name))
3251 ;; A single split name was found
3252 ((= 1 (length split-name))
3253 (let* ((name (expand-file-name
3254 (car split-name)
3255 gnus-article-save-directory))
3256 (dir (cond ((file-directory-p name)
3257 (file-name-as-directory name))
3258 ((file-exists-p name) name)
3259 (t gnus-article-save-directory))))
3260 (read-file-name
3261 (concat prompt " (default " name ") ")
3262 dir name)))
3263 ;; A list of splits was found.
3265 (setq split-name (nreverse split-name))
3266 (let (result)
3267 (let ((file-name-history
3268 (nconc split-name file-name-history)))
3269 (setq result
3270 (expand-file-name
3271 (read-file-name
3272 (concat prompt " (`M-p' for defaults) ")
3273 gnus-article-save-directory
3274 (car split-name))
3275 gnus-article-save-directory)))
3276 (car (push result file-name-history)))))))
3277 ;; Create the directory.
3278 (gnus-make-directory (file-name-directory file))
3279 ;; If we have read a directory, we append the default file name.
3280 (when (file-directory-p file)
3281 (setq file (expand-file-name (file-name-nondirectory
3282 default-name)
3283 (file-name-as-directory file))))
3284 ;; Possibly translate some characters.
3285 (nnheader-translate-file-chars file))))))
3286 (gnus-make-directory (file-name-directory result))
3287 (set variable result)))
3289 (defun gnus-article-archive-name (group)
3290 "Return the first instance of an \"Archive-name\" in the current buffer."
3291 (let ((case-fold-search t))
3292 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3293 (nnheader-concat gnus-article-save-directory
3294 (match-string 1)))))
3296 (defun gnus-article-nndoc-name (group)
3297 "If GROUP is an nndoc group, return the name of the parent group."
3298 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3299 (gnus-group-get-parameter group 'save-article-group)))
3301 (defun gnus-summary-save-in-rmail (&optional filename)
3302 "Append this article to Rmail file.
3303 Optional argument FILENAME specifies file name.
3304 Directory to save to is default to `gnus-article-save-directory'."
3305 (setq filename (gnus-read-save-file-name
3306 "Save %s in rmail file:" filename
3307 gnus-rmail-save-name gnus-newsgroup-name
3308 gnus-current-headers 'gnus-newsgroup-last-rmail))
3309 (gnus-eval-in-buffer-window gnus-save-article-buffer
3310 (save-excursion
3311 (save-restriction
3312 (widen)
3313 (gnus-output-to-rmail filename))))
3314 filename)
3316 (defun gnus-summary-save-in-mail (&optional filename)
3317 "Append this article to Unix mail file.
3318 Optional argument FILENAME specifies file name.
3319 Directory to save to is default to `gnus-article-save-directory'."
3320 (setq filename (gnus-read-save-file-name
3321 "Save %s in Unix mail file:" filename
3322 gnus-mail-save-name gnus-newsgroup-name
3323 gnus-current-headers 'gnus-newsgroup-last-mail))
3324 (gnus-eval-in-buffer-window gnus-save-article-buffer
3325 (save-excursion
3326 (save-restriction
3327 (widen)
3328 (if (and (file-readable-p filename)
3329 (file-regular-p filename)
3330 (mail-file-babyl-p filename))
3331 (rmail-output-to-rmail-file filename t)
3332 (gnus-output-to-mail filename)))))
3333 filename)
3335 (defun gnus-summary-save-in-file (&optional filename overwrite)
3336 "Append this article to file.
3337 Optional argument FILENAME specifies file name.
3338 Directory to save to is default to `gnus-article-save-directory'."
3339 (setq filename (gnus-read-save-file-name
3340 "Save %s in file:" filename
3341 gnus-file-save-name gnus-newsgroup-name
3342 gnus-current-headers 'gnus-newsgroup-last-file))
3343 (gnus-eval-in-buffer-window gnus-save-article-buffer
3344 (save-excursion
3345 (save-restriction
3346 (widen)
3347 (when (and overwrite
3348 (file-exists-p filename))
3349 (delete-file filename))
3350 (gnus-output-to-file filename))))
3351 filename)
3353 (defun gnus-summary-write-to-file (&optional filename)
3354 "Write this article to a file, overwriting it if the file exists.
3355 Optional argument FILENAME specifies file name.
3356 The directory to save in defaults to `gnus-article-save-directory'."
3357 (gnus-summary-save-in-file nil t))
3359 (defun gnus-summary-save-body-in-file (&optional filename)
3360 "Append this article body to a file.
3361 Optional argument FILENAME specifies file name.
3362 The directory to save in defaults to `gnus-article-save-directory'."
3363 (setq filename (gnus-read-save-file-name
3364 "Save %s body in file:" filename
3365 gnus-file-save-name gnus-newsgroup-name
3366 gnus-current-headers 'gnus-newsgroup-last-file))
3367 (gnus-eval-in-buffer-window gnus-save-article-buffer
3368 (save-excursion
3369 (save-restriction
3370 (widen)
3371 (when (article-goto-body)
3372 (narrow-to-region (point) (point-max)))
3373 (gnus-output-to-file filename))))
3374 filename)
3376 (defun gnus-summary-save-in-pipe (&optional command)
3377 "Pipe this article to subprocess."
3378 (setq command
3379 (cond ((and (eq command 'default)
3380 gnus-last-shell-command)
3381 gnus-last-shell-command)
3382 ((stringp command)
3383 command)
3384 (t (read-string
3385 (format
3386 "Shell command on %s: "
3387 (if (and gnus-number-of-articles-to-be-saved
3388 (> gnus-number-of-articles-to-be-saved 1))
3389 (format "these %d articles"
3390 gnus-number-of-articles-to-be-saved)
3391 "this article"))
3392 gnus-last-shell-command))))
3393 (when (string-equal command "")
3394 (if gnus-last-shell-command
3395 (setq command gnus-last-shell-command)
3396 (error "A command is required")))
3397 (gnus-eval-in-buffer-window gnus-article-buffer
3398 (save-restriction
3399 (widen)
3400 (shell-command-on-region (point-min) (point-max) command nil)))
3401 (setq gnus-last-shell-command command))
3403 (defmacro gnus-read-string (prompt &optional initial-contents history
3404 default-value)
3405 "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3406 (if (and (featurep 'xemacs)
3407 (< emacs-minor-version 2))
3408 `(read-string ,prompt ,initial-contents ,history)
3409 `(read-string ,prompt ,initial-contents ,history ,default-value)))
3411 (defun gnus-summary-pipe-to-muttprint (&optional command)
3412 "Pipe this article to muttprint."
3413 (setq command (gnus-read-string
3414 "Print using command: " gnus-summary-muttprint-program
3415 nil gnus-summary-muttprint-program))
3416 (gnus-summary-save-in-pipe command))
3418 ;;; Article file names when saving.
3420 (defun gnus-capitalize-newsgroup (newsgroup)
3421 "Capitalize NEWSGROUP name."
3422 (when (not (zerop (length newsgroup)))
3423 (concat (char-to-string (upcase (aref newsgroup 0)))
3424 (substring newsgroup 1))))
3426 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3427 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3428 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3429 Otherwise, it is like ~/News/news/group/num."
3430 (let ((default
3431 (expand-file-name
3432 (concat (if (gnus-use-long-file-name 'not-save)
3433 (gnus-capitalize-newsgroup newsgroup)
3434 (gnus-newsgroup-directory-form newsgroup))
3435 "/" (int-to-string (mail-header-number headers)))
3436 gnus-article-save-directory)))
3437 (if (and last-file
3438 (string-equal (file-name-directory default)
3439 (file-name-directory last-file))
3440 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3441 default
3442 (or last-file default))))
3444 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3445 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3446 If variable `gnus-use-long-file-name' is non-nil, it is
3447 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3448 (let ((default
3449 (expand-file-name
3450 (concat (if (gnus-use-long-file-name 'not-save)
3451 newsgroup
3452 (gnus-newsgroup-directory-form newsgroup))
3453 "/" (int-to-string (mail-header-number headers)))
3454 gnus-article-save-directory)))
3455 (if (and last-file
3456 (string-equal (file-name-directory default)
3457 (file-name-directory last-file))
3458 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3459 default
3460 (or last-file default))))
3462 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3463 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3464 If variable `gnus-use-long-file-name' is non-nil, it is
3465 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3466 (or last-file
3467 (expand-file-name
3468 (if (gnus-use-long-file-name 'not-save)
3469 newsgroup
3470 (file-relative-name
3471 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3472 default-directory))
3473 gnus-article-save-directory)))
3475 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3476 "Generate file name from sender."
3477 (let ((from (mail-header-from headers)))
3478 (expand-file-name
3479 (if (and from (string-match "\\([^ <]+\\)@" from))
3480 (match-string 1 from)
3481 "nobody")
3482 gnus-article-save-directory)))
3484 (defun article-verify-x-pgp-sig ()
3485 "Verify X-PGP-Sig."
3486 (interactive)
3487 (if (gnus-buffer-live-p gnus-original-article-buffer)
3488 (let ((sig (with-current-buffer gnus-original-article-buffer
3489 (gnus-fetch-field "X-PGP-Sig")))
3490 items info headers)
3491 (when (and sig
3492 mml2015-use
3493 (mml2015-clear-verify-function))
3494 (with-temp-buffer
3495 (insert-buffer-substring gnus-original-article-buffer)
3496 (setq items (split-string sig))
3497 (message-narrow-to-head)
3498 (let ((inhibit-point-motion-hooks t)
3499 (case-fold-search t))
3500 ;; Don't verify multiple headers.
3501 (setq headers (mapconcat (lambda (header)
3502 (concat header ": "
3503 (mail-fetch-field header)
3504 "\n"))
3505 (split-string (nth 1 items) ",") "")))
3506 (delete-region (point-min) (point-max))
3507 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3508 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3509 (insert headers)
3510 (widen)
3511 (forward-line)
3512 (while (not (eobp))
3513 (if (looking-at "^-")
3514 (insert "- "))
3515 (forward-line))
3516 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3517 (insert "Version: " (car items) "\n\n")
3518 (insert (mapconcat 'identity (cddr items) "\n"))
3519 (insert "\n-----END PGP SIGNATURE-----\n")
3520 (let ((mm-security-handle (list (format "multipart/signed"))))
3521 (mml2015-clean-buffer)
3522 (let ((coding-system-for-write (or gnus-newsgroup-charset
3523 'iso-8859-1)))
3524 (funcall (mml2015-clear-verify-function)))
3525 (setq info
3526 (or (mm-handle-multipart-ctl-parameter
3527 mm-security-handle 'gnus-details)
3528 (mm-handle-multipart-ctl-parameter
3529 mm-security-handle 'gnus-info)))))
3530 (when info
3531 (let ((inhibit-read-only t) bface eface)
3532 (save-restriction
3533 (message-narrow-to-head)
3534 (goto-char (point-max))
3535 (forward-line -1)
3536 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3537 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3538 (message-remove-header "X-Gnus-PGP-Verify")
3539 (if (re-search-forward "^X-PGP-Sig:" nil t)
3540 (forward-line)
3541 (goto-char (point-max)))
3542 (narrow-to-region (point) (point))
3543 (insert "X-Gnus-PGP-Verify: " info "\n")
3544 (goto-char (point-min))
3545 (forward-line)
3546 (while (not (eobp))
3547 (if (not (looking-at "^[ \t]"))
3548 (insert " "))
3549 (forward-line))
3550 ;; Do highlighting.
3551 (goto-char (point-min))
3552 (when (looking-at "\\([^:]+\\): *")
3553 (put-text-property (match-beginning 1) (1+ (match-end 1))
3554 'face bface)
3555 (put-text-property (match-end 0) (point-max)
3556 'face eface)))))))))
3558 (defun article-verify-cancel-lock ()
3559 "Verify Cancel-Lock header."
3560 (interactive)
3561 (if (gnus-buffer-live-p gnus-original-article-buffer)
3562 (canlock-verify gnus-original-article-buffer)))
3564 (eval-and-compile
3565 (mapcar
3566 (lambda (func)
3567 (let (afunc gfunc)
3568 (if (consp func)
3569 (setq afunc (car func)
3570 gfunc (cdr func))
3571 (setq afunc func
3572 gfunc (intern (format "gnus-%s" func))))
3573 (defalias gfunc
3574 (when (fboundp afunc)
3575 `(lambda (&optional interactive &rest args)
3576 ,(documentation afunc t)
3577 (interactive (list t))
3578 (save-excursion
3579 (set-buffer gnus-article-buffer)
3580 (if interactive
3581 (call-interactively ',afunc)
3582 (apply ',afunc args))))))))
3583 '(article-hide-headers
3584 article-verify-x-pgp-sig
3585 article-verify-cancel-lock
3586 article-hide-boring-headers
3587 article-treat-overstrike
3588 article-fill-long-lines
3589 article-capitalize-sentences
3590 article-remove-cr
3591 article-remove-leading-whitespace
3592 article-display-x-face
3593 article-display-face
3594 article-de-quoted-unreadable
3595 article-de-base64-unreadable
3596 article-decode-HZ
3597 article-wash-html
3598 article-unsplit-urls
3599 article-hide-list-identifiers
3600 article-strip-banner
3601 article-babel
3602 article-hide-pem
3603 article-hide-signature
3604 article-strip-headers-in-body
3605 article-remove-trailing-blank-lines
3606 article-strip-leading-blank-lines
3607 article-strip-multiple-blank-lines
3608 article-strip-leading-space
3609 article-strip-trailing-space
3610 article-strip-blank-lines
3611 article-strip-all-blank-lines
3612 article-date-local
3613 article-date-english
3614 article-date-iso8601
3615 article-date-original
3616 article-date-ut
3617 article-decode-mime-words
3618 article-decode-charset
3619 article-decode-encoded-words
3620 article-date-user
3621 article-date-lapsed
3622 article-emphasize
3623 article-treat-dumbquotes
3624 article-normalize-headers
3625 ;; (article-show-all . gnus-article-show-all-headers)
3629 ;;; Gnus article mode
3632 (put 'gnus-article-mode 'mode-class 'special)
3634 (set-keymap-parent gnus-article-mode-map widget-keymap)
3636 (gnus-define-keys gnus-article-mode-map
3637 " " gnus-article-goto-next-page
3638 "\177" gnus-article-goto-prev-page
3639 [delete] gnus-article-goto-prev-page
3640 [backspace] gnus-article-goto-prev-page
3641 "\C-c^" gnus-article-refer-article
3642 "h" gnus-article-show-summary
3643 "s" gnus-article-show-summary
3644 "\C-c\C-m" gnus-article-mail
3645 "?" gnus-article-describe-briefly
3646 "e" gnus-summary-edit-article
3647 "<" beginning-of-buffer
3648 ">" end-of-buffer
3649 "\C-c\C-i" gnus-info-find-node
3650 "\C-c\C-b" gnus-bug
3651 "R" gnus-article-reply-with-original
3652 "F" gnus-article-followup-with-original
3653 "\C-hk" gnus-article-describe-key
3654 "\C-hc" gnus-article-describe-key-briefly
3656 "\C-d" gnus-article-read-summary-keys
3657 "\M-*" gnus-article-read-summary-keys
3658 "\M-#" gnus-article-read-summary-keys
3659 "\M-^" gnus-article-read-summary-keys
3660 "\M-g" gnus-article-read-summary-keys)
3662 (substitute-key-definition
3663 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3665 (defun gnus-article-make-menu-bar ()
3666 (unless (boundp 'gnus-article-commands-menu)
3667 (gnus-summary-make-menu-bar))
3668 (gnus-turn-off-edit-menu 'article)
3669 (unless (boundp 'gnus-article-article-menu)
3670 (easy-menu-define
3671 gnus-article-article-menu gnus-article-mode-map ""
3672 '("Article"
3673 ["Scroll forwards" gnus-article-goto-next-page t]
3674 ["Scroll backwards" gnus-article-goto-prev-page t]
3675 ["Show summary" gnus-article-show-summary t]
3676 ["Fetch Message-ID at point" gnus-article-refer-article t]
3677 ["Mail to address at point" gnus-article-mail t]
3678 ["Send a bug report" gnus-bug t]))
3680 (easy-menu-define
3681 gnus-article-treatment-menu gnus-article-mode-map ""
3682 ;; Fixme: this should use :active (and maybe :visible).
3683 '("Treatment"
3684 ["Hide headers" gnus-article-hide-headers t]
3685 ["Hide signature" gnus-article-hide-signature t]
3686 ["Hide citation" gnus-article-hide-citation t]
3687 ["Treat overstrike" gnus-article-treat-overstrike t]
3688 ["Remove carriage return" gnus-article-remove-cr t]
3689 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3690 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3691 ["Remove base64" gnus-article-de-base64-unreadable t]
3692 ["Treat html" gnus-article-wash-html t]
3693 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3694 ["Decode HZ" gnus-article-decode-HZ t]))
3696 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3698 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3700 (gnus-run-hooks 'gnus-article-menu-hook)))
3702 (defun gnus-article-mode ()
3703 "Major mode for displaying an article.
3705 All normal editing commands are switched off.
3707 The following commands are available in addition to all summary mode
3708 commands:
3709 \\<gnus-article-mode-map>
3710 \\[gnus-article-next-page]\t Scroll the article one page forwards
3711 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3712 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3713 \\[gnus-article-show-summary]\t Display the summary buffer
3714 \\[gnus-article-mail]\t Send a reply to the address near point
3715 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3716 \\[gnus-info-find-node]\t Go to the Gnus info node"
3717 (interactive)
3718 (gnus-simplify-mode-line)
3719 (setq mode-name "Article")
3720 (setq major-mode 'gnus-article-mode)
3721 (make-local-variable 'minor-mode-alist)
3722 (use-local-map gnus-article-mode-map)
3723 (when (gnus-visual-p 'article-menu 'menu)
3724 (gnus-article-make-menu-bar)
3725 (when gnus-summary-tool-bar-map
3726 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3727 (gnus-update-format-specifications nil 'article-mode)
3728 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3729 (set (make-local-variable 'gnus-page-broken) nil)
3730 (make-local-variable 'gnus-button-marker-list)
3731 (make-local-variable 'gnus-article-current-summary)
3732 (make-local-variable 'gnus-article-mime-handles)
3733 (make-local-variable 'gnus-article-decoded-p)
3734 (make-local-variable 'gnus-article-mime-handle-alist)
3735 (make-local-variable 'gnus-article-wash-types)
3736 (make-local-variable 'gnus-article-image-alist)
3737 (make-local-variable 'gnus-article-charset)
3738 (make-local-variable 'gnus-article-ignored-charsets)
3739 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3740 (set (make-local-variable 'show-nonbreak-escape) nil)
3741 (gnus-set-default-directory)
3742 (buffer-disable-undo)
3743 (setq buffer-read-only t)
3744 (set-syntax-table gnus-article-mode-syntax-table)
3745 (mm-enable-multibyte)
3746 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3748 (defun gnus-article-setup-buffer ()
3749 "Initialize the article buffer."
3750 (let* ((name (if gnus-single-article-buffer "*Article*"
3751 (concat "*Article " gnus-newsgroup-name "*")))
3752 (original
3753 (progn (string-match "\\*Article" name)
3754 (concat " *Original Article"
3755 (substring name (match-end 0))))))
3756 (setq gnus-article-buffer name)
3757 (setq gnus-original-article-buffer original)
3758 (setq gnus-article-mime-handle-alist nil)
3759 ;; This might be a variable local to the summary buffer.
3760 (unless gnus-single-article-buffer
3761 (save-excursion
3762 (set-buffer gnus-summary-buffer)
3763 (setq gnus-article-buffer name)
3764 (setq gnus-original-article-buffer original)
3765 (gnus-set-global-variables)))
3766 (gnus-article-setup-highlight-words)
3767 ;; Init original article buffer.
3768 (save-excursion
3769 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3770 (mm-enable-multibyte)
3771 (setq major-mode 'gnus-original-article-mode)
3772 (make-local-variable 'gnus-original-article))
3773 (if (and (get-buffer name)
3774 (with-current-buffer name
3775 (if gnus-article-edit-mode
3776 (if (y-or-n-p "Article mode edit in progress; discard? ")
3777 (progn
3778 (set-buffer-modified-p nil)
3779 (gnus-kill-buffer name)
3780 (message "")
3781 nil)
3782 (error "Action aborted"))
3783 t)))
3784 (save-excursion
3785 (set-buffer name)
3786 (set (make-local-variable 'gnus-article-edit-mode) nil)
3787 (when gnus-article-mime-handles
3788 (mm-destroy-parts gnus-article-mime-handles)
3789 (setq gnus-article-mime-handles nil))
3790 ;; Set it to nil in article-buffer!
3791 (setq gnus-article-mime-handle-alist nil)
3792 (buffer-disable-undo)
3793 (setq buffer-read-only t)
3794 ;; This list just keeps growing if we don't reset it.
3795 (setq gnus-button-marker-list nil)
3796 (unless (eq major-mode 'gnus-article-mode)
3797 (gnus-article-mode))
3798 (current-buffer))
3799 (save-excursion
3800 (set-buffer (gnus-get-buffer-create name))
3801 (gnus-article-mode)
3802 (make-local-variable 'gnus-summary-buffer)
3803 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3804 (current-buffer)))))
3806 ;; Set article window start at LINE, where LINE is the number of lines
3807 ;; from the head of the article.
3808 (defun gnus-article-set-window-start (&optional line)
3809 (set-window-start
3810 (gnus-get-buffer-window gnus-article-buffer t)
3811 (save-excursion
3812 (set-buffer gnus-article-buffer)
3813 (goto-char (point-min))
3814 (if (not line)
3815 (point-min)
3816 (gnus-message 6 "Moved to bookmark")
3817 (search-forward "\n\n" nil t)
3818 (forward-line line)
3819 (point)))))
3821 (defun gnus-article-prepare (article &optional all-headers header)
3822 "Prepare ARTICLE in article mode buffer.
3823 ARTICLE should either be an article number or a Message-ID.
3824 If ARTICLE is an id, HEADER should be the article headers.
3825 If ALL-HEADERS is non-nil, no headers are hidden."
3826 (save-excursion
3827 ;; Make sure we start in a summary buffer.
3828 (unless (eq major-mode 'gnus-summary-mode)
3829 (set-buffer gnus-summary-buffer))
3830 (setq gnus-summary-buffer (current-buffer))
3831 (let* ((gnus-article (if header (mail-header-number header) article))
3832 (summary-buffer (current-buffer))
3833 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3834 (group gnus-newsgroup-name)
3835 result)
3836 (save-excursion
3837 (gnus-article-setup-buffer)
3838 (set-buffer gnus-article-buffer)
3839 ;; Deactivate active regions.
3840 (when (and (boundp 'transient-mark-mode)
3841 transient-mark-mode)
3842 (setq mark-active nil))
3843 (if (not (setq result (let ((inhibit-read-only t))
3844 (gnus-request-article-this-buffer
3845 article group))))
3846 ;; There is no such article.
3847 (save-excursion
3848 (when (and (numberp article)
3849 (not (memq article gnus-newsgroup-sparse)))
3850 (setq gnus-article-current
3851 (cons gnus-newsgroup-name article))
3852 (set-buffer gnus-summary-buffer)
3853 (setq gnus-current-article article)
3854 (if (and (memq article gnus-newsgroup-undownloaded)
3855 (not (gnus-online (gnus-find-method-for-group
3856 gnus-newsgroup-name))))
3857 (progn
3858 (gnus-summary-set-agent-mark article)
3859 (message "Message marked for downloading"))
3860 (gnus-summary-mark-article article gnus-canceled-mark)
3861 (unless (memq article gnus-newsgroup-sparse)
3862 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3863 (if (or (eq result 'pseudo)
3864 (eq result 'nneething))
3865 (progn
3866 (save-excursion
3867 (set-buffer summary-buffer)
3868 (push article gnus-newsgroup-history)
3869 (setq gnus-last-article gnus-current-article
3870 gnus-current-article 0
3871 gnus-current-headers nil
3872 gnus-article-current nil)
3873 (if (eq result 'nneething)
3874 (gnus-configure-windows 'summary)
3875 (gnus-configure-windows 'article))
3876 (gnus-set-global-variables))
3877 (let ((gnus-article-mime-handle-alist-1
3878 gnus-article-mime-handle-alist))
3879 (gnus-set-mode-line 'article)))
3880 ;; The result from the `request' was an actual article -
3881 ;; or at least some text that is now displayed in the
3882 ;; article buffer.
3883 (when (and (numberp article)
3884 (not (eq article gnus-current-article)))
3885 ;; Seems like a new article has been selected.
3886 ;; `gnus-current-article' must be an article number.
3887 (save-excursion
3888 (set-buffer summary-buffer)
3889 (push article gnus-newsgroup-history)
3890 (setq gnus-last-article gnus-current-article
3891 gnus-current-article article
3892 gnus-current-headers
3893 (gnus-summary-article-header gnus-current-article)
3894 gnus-article-current
3895 (cons gnus-newsgroup-name gnus-current-article))
3896 (unless (vectorp gnus-current-headers)
3897 (setq gnus-current-headers nil))
3898 (gnus-summary-goto-subject gnus-current-article)
3899 (when (gnus-summary-show-thread)
3900 ;; If the summary buffer really was folded, the
3901 ;; previous goto may not actually have gone to
3902 ;; the right article, but the thread root instead.
3903 ;; So we go again.
3904 (gnus-summary-goto-subject gnus-current-article))
3905 (gnus-run-hooks 'gnus-mark-article-hook)
3906 (gnus-set-mode-line 'summary)
3907 (when (gnus-visual-p 'article-highlight 'highlight)
3908 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3909 ;; Set the global newsgroup variables here.
3910 (gnus-set-global-variables)
3911 (setq gnus-have-all-headers
3912 (or all-headers gnus-show-all-headers))))
3913 (save-excursion
3914 (gnus-configure-windows 'article))
3915 (when (or (numberp article)
3916 (stringp article))
3917 (gnus-article-prepare-display)
3918 ;; Do page break.
3919 (goto-char (point-min))
3920 (when gnus-break-pages
3921 (gnus-narrow-to-page)))
3922 (let ((gnus-article-mime-handle-alist-1
3923 gnus-article-mime-handle-alist))
3924 (gnus-set-mode-line 'article))
3925 (article-goto-body)
3926 (unless (bobp)
3927 (forward-line -1))
3928 (set-window-point (get-buffer-window (current-buffer)) (point))
3929 (gnus-configure-windows 'article)
3930 t))))))
3932 ;;;###autoload
3933 (defun gnus-article-prepare-display ()
3934 "Make the current buffer look like a nice article."
3935 ;; Hooks for getting information from the article.
3936 ;; This hook must be called before being narrowed.
3937 (let ((gnus-article-buffer (current-buffer))
3938 buffer-read-only
3939 (inhibit-read-only t))
3940 (unless (eq major-mode 'gnus-article-mode)
3941 (gnus-article-mode))
3942 (setq buffer-read-only nil
3943 gnus-article-wash-types nil
3944 gnus-article-image-alist nil)
3945 (gnus-run-hooks 'gnus-tmp-internal-hook)
3946 (when gnus-display-mime-function
3947 (funcall gnus-display-mime-function))
3948 (gnus-run-hooks 'gnus-article-prepare-hook)))
3951 ;;; Gnus MIME viewing functions
3954 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3955 "Format of the MIME buttons.
3957 Valid specifiers include:
3958 %t The MIME type
3959 %T MIME type, along with additional info
3960 %n The `name' parameter
3961 %d The description, if any
3962 %l The length of the encoded part
3963 %p The part identifier number
3964 %e Dots if the part isn't displayed
3966 General format specifiers can also be used. See Info node
3967 `(gnus)Formatting Variables'.")
3969 (defvar gnus-mime-button-line-format-alist
3970 '((?t gnus-tmp-type ?s)
3971 (?T gnus-tmp-type-long ?s)
3972 (?n gnus-tmp-name ?s)
3973 (?d gnus-tmp-description ?s)
3974 (?p gnus-tmp-id ?s)
3975 (?l gnus-tmp-length ?d)
3976 (?e gnus-tmp-dots ?s)))
3978 (defvar gnus-mime-button-commands
3979 '((gnus-article-press-button "\r" "Toggle Display")
3980 (gnus-mime-view-part "v" "View Interactively...")
3981 (gnus-mime-view-part-as-type "t" "View As Type...")
3982 (gnus-mime-view-part-as-charset "C" "View As charset...")
3983 (gnus-mime-save-part "o" "Save...")
3984 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3985 (gnus-mime-delete-part "d" "Delete part")
3986 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3987 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3988 (gnus-mime-view-part-internally "E" "View Internally")
3989 (gnus-mime-view-part-externally "e" "View Externally")
3990 (gnus-mime-print-part "p" "Print")
3991 (gnus-mime-pipe-part "|" "Pipe To Command...")
3992 (gnus-mime-action-on-part "." "Take action on the part...")))
3994 (defun gnus-article-mime-part-status ()
3995 (if gnus-article-mime-handle-alist-1
3996 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3997 " (1 part)"
3998 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3999 ""))
4001 (defvar gnus-mime-button-map
4002 (let ((map (make-sparse-keymap)))
4003 (unless (>= (string-to-number emacs-version) 21)
4004 ;; XEmacs doesn't care.
4005 (set-keymap-parent map gnus-article-mode-map))
4006 (define-key map gnus-mouse-2 'gnus-article-push-button)
4007 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4008 (dolist (c gnus-mime-button-commands)
4009 (define-key map (cadr c) (car c)))
4010 map))
4012 (easy-menu-define
4013 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4014 `("MIME Part"
4015 ,@(mapcar (lambda (c)
4016 (vector (caddr c) (car c) :enable t))
4017 gnus-mime-button-commands)))
4019 (eval-when-compile
4020 (define-compiler-macro popup-menu (&whole form
4021 menu &optional position prefix)
4022 (if (and (fboundp 'popup-menu)
4023 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4024 form
4025 ;; Gnus is probably running under Emacs 20.
4026 `(let* ((menu (cdr ,menu))
4027 (response (x-popup-menu
4028 t (list (car menu)
4029 (cons "" (mapcar (lambda (c)
4030 (cons (caddr c) (car c)))
4031 (cdr menu)))))))
4032 (if response
4033 (call-interactively (nth 3 (assq response menu))))))))
4035 (defun gnus-mime-button-menu (event prefix)
4036 "Construct a context-sensitive menu of MIME commands."
4037 (interactive "e\nP")
4038 (save-window-excursion
4039 (let ((pos (event-start event)))
4040 (select-window (posn-window pos))
4041 (goto-char (posn-point pos))
4042 (gnus-article-check-buffer)
4043 (popup-menu gnus-mime-button-menu nil prefix))))
4045 (defun gnus-mime-view-all-parts (&optional handles)
4046 "View all the MIME parts."
4047 (interactive)
4048 (save-current-buffer
4049 (set-buffer gnus-article-buffer)
4050 (let ((handles (or handles gnus-article-mime-handles))
4051 (mail-parse-charset gnus-newsgroup-charset)
4052 (mail-parse-ignored-charsets
4053 (with-current-buffer gnus-summary-buffer
4054 gnus-newsgroup-ignored-charsets)))
4055 (when handles
4056 (mm-remove-parts handles)
4057 (goto-char (point-min))
4058 (or (search-forward "\n\n") (goto-char (point-max)))
4059 (let ((inhibit-read-only t))
4060 (delete-region (point) (point-max))
4061 (mm-display-parts handles))))))
4063 (defun gnus-mime-save-part-and-strip ()
4064 "Save the MIME part under point then replace it with an external body."
4065 (interactive)
4066 (gnus-article-check-buffer)
4067 (when (gnus-group-read-only-p)
4068 (error "The current group does not support deleting of parts"))
4069 (when (mm-complicated-handles gnus-article-mime-handles)
4070 (error "\
4071 The current article has a complicated MIME structure, giving up..."))
4072 (when (gnus-yes-or-no-p "\
4073 Deleting parts may malfunction or destroy the article; continue? ")
4074 (let* ((data (get-text-property (point) 'gnus-data))
4075 file param
4076 (handles gnus-article-mime-handles))
4077 (setq file (and data (mm-save-part data)))
4078 (when file
4079 (with-current-buffer (mm-handle-buffer data)
4080 (erase-buffer)
4081 (insert "Content-Type: " (mm-handle-media-type data))
4082 (mml-insert-parameter-string (cdr (mm-handle-type data))
4083 '(charset))
4084 (insert "\n")
4085 (insert "Content-ID: " (message-make-message-id) "\n")
4086 (insert "Content-Transfer-Encoding: binary\n")
4087 (insert "\n"))
4088 (setcdr data
4089 (cdr (mm-make-handle nil
4090 `("message/external-body"
4091 (access-type . "LOCAL-FILE")
4092 (name . ,file)))))
4093 (set-buffer gnus-summary-buffer)
4094 (gnus-article-edit-article
4095 `(lambda ()
4096 (erase-buffer)
4097 (let ((mail-parse-charset (or gnus-article-charset
4098 ',gnus-newsgroup-charset))
4099 (mail-parse-ignored-charsets
4100 (or gnus-article-ignored-charsets
4101 ',gnus-newsgroup-ignored-charsets))
4102 (mbl mml-buffer-list))
4103 (setq mml-buffer-list nil)
4104 (insert-buffer gnus-original-article-buffer)
4105 (mime-to-mml ',handles)
4106 (setq gnus-article-mime-handles nil)
4107 (let ((mbl1 mml-buffer-list))
4108 (setq mml-buffer-list mbl)
4109 (set (make-local-variable 'mml-buffer-list) mbl1))
4110 (gnus-make-local-hook 'kill-buffer-hook)
4111 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4112 `(lambda (no-highlight)
4113 (let ((mail-parse-charset (or gnus-article-charset
4114 ',gnus-newsgroup-charset))
4115 (message-options message-options)
4116 (message-options-set-recipient)
4117 (mail-parse-ignored-charsets
4118 (or gnus-article-ignored-charsets
4119 ',gnus-newsgroup-ignored-charsets)))
4120 (mml-to-mime)
4121 (mml-destroy-buffers)
4122 (remove-hook 'kill-buffer-hook
4123 'mml-destroy-buffers t)
4124 (kill-local-variable 'mml-buffer-list))
4125 (gnus-summary-edit-article-done
4126 ,(or (mail-header-references gnus-current-headers) "")
4127 ,(gnus-group-read-only-p)
4128 ,gnus-summary-buffer no-highlight)))))))
4130 (defun gnus-mime-delete-part ()
4131 "Delete the MIME part under point.
4132 Replace it with some information about the removed part."
4133 (interactive)
4134 (gnus-article-check-buffer)
4135 (when (gnus-group-read-only-p)
4136 (error "The current group does not support deleting of parts"))
4137 (when (mm-complicated-handles gnus-article-mime-handles)
4138 (error "\
4139 The current article has a complicated MIME structure, giving up..."))
4140 (when (gnus-yes-or-no-p "\
4141 Deleting parts may malfunction or destroy the article; continue? ")
4142 (let* ((data (get-text-property (point) 'gnus-data))
4143 (handles gnus-article-mime-handles)
4144 (none "(none)")
4145 (description
4147 (mail-decode-encoded-word-string (or (mm-handle-description data)
4148 none))))
4149 (filename
4150 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4151 none))
4152 (type (mm-handle-media-type data)))
4153 (unless data
4154 (error "No MIME part under point"))
4155 (with-current-buffer (mm-handle-buffer data)
4156 (let ((bsize (format "%s" (buffer-size))))
4157 (erase-buffer)
4158 (insert
4159 (concat
4160 ",----\n"
4161 "| The following attachment has been deleted:\n"
4162 "|\n"
4163 "| Type: " type "\n"
4164 "| Filename: " filename "\n"
4165 "| Size (encoded): " bsize " Byte\n"
4166 "| Description: " description "\n"
4167 "`----\n"))
4168 (setcdr data
4169 (cdr (mm-make-handle
4170 nil `("text/plain") nil nil
4171 (list "attachment")
4172 (format "Deleted attachment (%s bytes)" bsize))))))
4173 (set-buffer gnus-summary-buffer)
4174 ;; FIXME: maybe some of the following code (borrowed from
4175 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4176 (gnus-article-edit-article
4177 `(lambda ()
4178 (erase-buffer)
4179 (let ((mail-parse-charset (or gnus-article-charset
4180 ',gnus-newsgroup-charset))
4181 (mail-parse-ignored-charsets
4182 (or gnus-article-ignored-charsets
4183 ',gnus-newsgroup-ignored-charsets))
4184 (mbl mml-buffer-list))
4185 (setq mml-buffer-list nil)
4186 (insert-buffer gnus-original-article-buffer)
4187 (mime-to-mml ',handles)
4188 (setq gnus-article-mime-handles nil)
4189 (let ((mbl1 mml-buffer-list))
4190 (setq mml-buffer-list mbl)
4191 (set (make-local-variable 'mml-buffer-list) mbl1))
4192 (gnus-make-local-hook 'kill-buffer-hook)
4193 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4194 `(lambda (no-highlight)
4195 (let ((mail-parse-charset (or gnus-article-charset
4196 ',gnus-newsgroup-charset))
4197 (message-options message-options)
4198 (message-options-set-recipient)
4199 (mail-parse-ignored-charsets
4200 (or gnus-article-ignored-charsets
4201 ',gnus-newsgroup-ignored-charsets)))
4202 (mml-to-mime)
4203 (mml-destroy-buffers)
4204 (remove-hook 'kill-buffer-hook
4205 'mml-destroy-buffers t)
4206 (kill-local-variable 'mml-buffer-list))
4207 (gnus-summary-edit-article-done
4208 ,(or (mail-header-references gnus-current-headers) "")
4209 ,(gnus-group-read-only-p)
4210 ,gnus-summary-buffer no-highlight)))))
4211 ;; Not in `gnus-mime-save-part-and-strip':
4212 (gnus-article-edit-done)
4213 (gnus-summary-expand-window)
4214 (gnus-summary-show-article))
4216 (defun gnus-mime-save-part ()
4217 "Save the MIME part under point."
4218 (interactive)
4219 (gnus-article-check-buffer)
4220 (let ((data (get-text-property (point) 'gnus-data)))
4221 (when data
4222 (mm-save-part data))))
4224 (defun gnus-mime-pipe-part ()
4225 "Pipe the MIME part under point to a process."
4226 (interactive)
4227 (gnus-article-check-buffer)
4228 (let ((data (get-text-property (point) 'gnus-data)))
4229 (when data
4230 (mm-pipe-part data))))
4232 (defun gnus-mime-view-part ()
4233 "Interactively choose a viewing method for the MIME part under point."
4234 (interactive)
4235 (gnus-article-check-buffer)
4236 (let ((data (get-text-property (point) 'gnus-data)))
4237 (when data
4238 (setq gnus-article-mime-handles
4239 (mm-merge-handles
4240 gnus-article-mime-handles (setq data (copy-sequence data))))
4241 (mm-interactively-view-part data))))
4243 (defun gnus-mime-view-part-as-type-internal ()
4244 (gnus-article-check-buffer)
4245 (let* ((name (mail-content-type-get
4246 (mm-handle-type (get-text-property (point) 'gnus-data))
4247 'name))
4248 (def-type (and name (mm-default-file-encoding name))))
4249 (and def-type (cons def-type 0))))
4251 (defun gnus-mime-view-part-as-type (&optional mime-type)
4252 "Choose a MIME media type, and view the part as such."
4253 (interactive)
4254 (unless mime-type
4255 (setq mime-type (completing-read
4256 "View as MIME type: "
4257 (mapcar #'list (mailcap-mime-types))
4258 nil nil
4259 (gnus-mime-view-part-as-type-internal))))
4260 (gnus-article-check-buffer)
4261 (let ((handle (get-text-property (point) 'gnus-data)))
4262 (when handle
4263 (setq handle
4264 (mm-make-handle (mm-handle-buffer handle)
4265 (cons mime-type (cdr (mm-handle-type handle)))
4266 (mm-handle-encoding handle)
4267 (mm-handle-undisplayer handle)
4268 (mm-handle-disposition handle)
4269 (mm-handle-description handle)
4271 (mm-handle-id handle)))
4272 (setq gnus-article-mime-handles
4273 (mm-merge-handles gnus-article-mime-handles handle))
4274 (gnus-mm-display-part handle))))
4276 (eval-when-compile
4277 (require 'jka-compr))
4279 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4280 ;; emacs can do that itself.
4282 (defun gnus-mime-jka-compr-maybe-uncompress ()
4283 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4284 The uncompress method used is derived from `buffer-file-name'."
4285 (when (and (fboundp 'jka-compr-installed-p)
4286 (jka-compr-installed-p))
4287 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4288 (when info
4289 (let ((basename (file-name-nondirectory buffer-file-name))
4290 (args (jka-compr-info-uncompress-args info))
4291 (prog (jka-compr-info-uncompress-program info))
4292 (message (jka-compr-info-uncompress-message info))
4293 (err-file (jka-compr-make-temp-name)))
4294 (if message
4295 (message "%s %s..." message basename))
4296 (unwind-protect
4297 (unless (memq (apply 'call-process-region
4298 (point-min) (point-max)
4299 prog
4300 t (list t err-file) nil
4301 args)
4302 jka-compr-acceptable-retval-list)
4303 (jka-compr-error prog args basename message err-file))
4304 (jka-compr-delete-temp-file err-file)))))))
4306 (defun gnus-mime-copy-part (&optional handle)
4307 "Put the MIME part under point into a new buffer.
4308 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4309 are decompressed."
4310 (interactive)
4311 (gnus-article-check-buffer)
4312 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4313 (contents (and handle (mm-get-part handle)))
4314 (base (and handle
4315 (file-name-nondirectory
4317 (mail-content-type-get (mm-handle-type handle) 'name)
4318 (mail-content-type-get (mm-handle-disposition handle)
4319 'filename)
4320 "*decoded*"))))
4321 (buffer (and base (generate-new-buffer base))))
4322 (when contents
4323 (switch-to-buffer buffer)
4324 (insert contents)
4325 ;; We do it this way to make `normal-mode' set the appropriate mode.
4326 (unwind-protect
4327 (progn
4328 (setq buffer-file-name (expand-file-name base))
4329 (gnus-mime-jka-compr-maybe-uncompress)
4330 (normal-mode))
4331 (setq buffer-file-name nil))
4332 (goto-char (point-min)))))
4334 (defun gnus-mime-print-part (&optional handle filename)
4335 "Print the MIME part under point."
4336 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4337 (gnus-article-check-buffer)
4338 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4339 (contents (and handle (mm-get-part handle)))
4340 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4341 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4342 (when contents
4343 (if printer
4344 (unwind-protect
4345 (progn
4346 (mm-save-part-to-file handle file)
4347 (call-process shell-file-name nil
4348 (generate-new-buffer " *mm*")
4350 shell-command-switch
4351 (mm-mailcap-command
4352 printer file (mm-handle-type handle))))
4353 (delete-file file))
4354 (with-temp-buffer
4355 (insert contents)
4356 (gnus-print-buffer))
4357 (ps-despool filename)))))
4359 (defun gnus-mime-inline-part (&optional handle arg)
4360 "Insert the MIME part under point into the current buffer."
4361 (interactive (list nil current-prefix-arg))
4362 (gnus-article-check-buffer)
4363 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4364 contents charset
4365 (b (point))
4366 (inhibit-read-only t))
4367 (when handle
4368 (if (and (not arg) (mm-handle-undisplayer handle))
4369 (mm-remove-part handle)
4370 (setq contents (mm-get-part handle))
4371 (cond
4372 ((not arg)
4373 (setq charset (or (mail-content-type-get
4374 (mm-handle-type handle) 'charset)
4375 gnus-newsgroup-charset)))
4376 ((numberp arg)
4377 (if (mm-handle-undisplayer handle)
4378 (mm-remove-part handle))
4379 (setq charset
4380 (or (cdr (assq arg
4381 gnus-summary-show-article-charset-alist))
4382 (mm-read-coding-system "Charset: "))))
4384 (if (mm-handle-undisplayer handle)
4385 (mm-remove-part handle))))
4386 (forward-line 2)
4387 (mm-insert-inline
4388 handle
4389 (if (and charset
4390 (setq charset (mm-charset-to-coding-system
4391 charset))
4392 (not (eq charset 'ascii)))
4393 (mm-decode-coding-string contents charset)
4394 (mm-string-to-multibyte contents)))
4395 (goto-char b)))))
4397 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4398 "Insert the MIME part under point into the current buffer using the
4399 specified charset."
4400 (interactive (list nil current-prefix-arg))
4401 (gnus-article-check-buffer)
4402 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4403 contents charset
4404 (b (point))
4405 (inhibit-read-only t))
4406 (when handle
4407 (if (mm-handle-undisplayer handle)
4408 (mm-remove-part handle))
4409 (let ((gnus-newsgroup-charset
4410 (or (cdr (assq arg
4411 gnus-summary-show-article-charset-alist))
4412 (mm-read-coding-system "Charset: ")))
4413 (gnus-newsgroup-ignored-charsets 'gnus-all))
4414 (gnus-article-press-button)))))
4416 (defun gnus-mime-view-part-externally (&optional handle)
4417 "View the MIME part under point with an external viewer."
4418 (interactive)
4419 (gnus-article-check-buffer)
4420 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4421 (mm-user-display-methods nil)
4422 (mm-inlined-types nil)
4423 (mail-parse-charset gnus-newsgroup-charset)
4424 (mail-parse-ignored-charsets
4425 (save-excursion (set-buffer gnus-summary-buffer)
4426 gnus-newsgroup-ignored-charsets)))
4427 (when handle
4428 (if (mm-handle-undisplayer handle)
4429 (mm-remove-part handle)
4430 (mm-display-part handle)))))
4432 (defun gnus-mime-view-part-internally (&optional handle)
4433 "View the MIME part under point with an internal viewer.
4434 If no internal viewer is available, use an external viewer."
4435 (interactive)
4436 (gnus-article-check-buffer)
4437 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4438 (mm-inlined-types '(".*"))
4439 (mm-inline-large-images t)
4440 (mail-parse-charset gnus-newsgroup-charset)
4441 (mail-parse-ignored-charsets
4442 (save-excursion (set-buffer gnus-summary-buffer)
4443 gnus-newsgroup-ignored-charsets))
4444 (inhibit-read-only t))
4445 (when handle
4446 (if (mm-handle-undisplayer handle)
4447 (mm-remove-part handle)
4448 (mm-display-part handle)))))
4450 (defun gnus-mime-action-on-part (&optional action)
4451 "Do something with the MIME attachment at \(point\)."
4452 (interactive
4453 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4454 (gnus-article-check-buffer)
4455 (let ((action-pair (assoc action gnus-mime-action-alist)))
4456 (if action-pair
4457 (funcall (cdr action-pair)))))
4459 (defun gnus-article-part-wrapper (n function)
4460 (save-current-buffer
4461 (set-buffer gnus-article-buffer)
4462 (when (> n (length gnus-article-mime-handle-alist))
4463 (error "No such part"))
4464 (gnus-article-goto-part n)
4465 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4466 (funcall function handle))))
4468 (defun gnus-article-pipe-part (n)
4469 "Pipe MIME part N, which is the numerical prefix."
4470 (interactive "p")
4471 (gnus-article-part-wrapper n 'mm-pipe-part))
4473 (defun gnus-article-save-part (n)
4474 "Save MIME part N, which is the numerical prefix."
4475 (interactive "p")
4476 (gnus-article-part-wrapper n 'mm-save-part))
4478 (defun gnus-article-interactively-view-part (n)
4479 "View MIME part N interactively, which is the numerical prefix."
4480 (interactive "p")
4481 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4483 (defun gnus-article-copy-part (n)
4484 "Copy MIME part N, which is the numerical prefix."
4485 (interactive "p")
4486 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4488 (defun gnus-article-view-part-as-charset (n)
4489 "View MIME part N using a specified charset.
4490 N is the numerical prefix."
4491 (interactive "p")
4492 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4494 (defun gnus-article-view-part-externally (n)
4495 "View MIME part N externally, which is the numerical prefix."
4496 (interactive "p")
4497 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4499 (defun gnus-article-inline-part (n)
4500 "Inline MIME part N, which is the numerical prefix."
4501 (interactive "p")
4502 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4504 (defun gnus-article-mime-match-handle-first (condition)
4505 (if condition
4506 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4507 (while (setq ihandle (pop alist))
4508 (if (and (cond
4509 ((functionp condition)
4510 (funcall condition (cdr ihandle)))
4511 ((eq condition 'undisplayed)
4512 (not (or (mm-handle-undisplayer (cdr ihandle))
4513 (equal (mm-handle-media-type (cdr ihandle))
4514 "multipart/alternative"))))
4515 ((eq condition 'undisplayed-alternative)
4516 (not (mm-handle-undisplayer (cdr ihandle))))
4517 (t t))
4518 (gnus-article-goto-part (car ihandle))
4519 (or (not n) (< (car ihandle) n)))
4520 (setq n (car ihandle))))
4521 (or n 1))
4524 (defun gnus-article-view-part (&optional n)
4525 "View MIME part N, which is the numerical prefix."
4526 (interactive "P")
4527 (save-current-buffer
4528 (set-buffer gnus-article-buffer)
4529 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4530 gnus-article-mime-match-handle-function)))
4531 (when (> n (length gnus-article-mime-handle-alist))
4532 (error "No such part"))
4533 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4534 (when (gnus-article-goto-part n)
4535 (if (equal (car handle) "multipart/alternative")
4536 (gnus-article-press-button)
4537 (when (eq (gnus-mm-display-part handle) 'internal)
4538 (gnus-set-window-start)))))))
4540 (defsubst gnus-article-mime-total-parts ()
4541 (if (bufferp (car gnus-article-mime-handles))
4542 1 ;; single part
4543 (1- (length gnus-article-mime-handles))))
4545 (defun gnus-mm-display-part (handle)
4546 "Display HANDLE and fix MIME button."
4547 (let ((id (get-text-property (point) 'gnus-part))
4548 (point (point))
4549 (inhibit-read-only t))
4550 (forward-line 1)
4551 (prog1
4552 (let ((window (selected-window))
4553 (mail-parse-charset gnus-newsgroup-charset)
4554 (mail-parse-ignored-charsets
4555 (if (gnus-buffer-live-p gnus-summary-buffer)
4556 (save-excursion
4557 (set-buffer gnus-summary-buffer)
4558 gnus-newsgroup-ignored-charsets)
4559 nil)))
4560 (save-excursion
4561 (unwind-protect
4562 (let ((win (gnus-get-buffer-window (current-buffer) t))
4563 (beg (point)))
4564 (when win
4565 (select-window win))
4566 (goto-char point)
4567 (forward-line)
4568 (if (mm-handle-displayed-p handle)
4569 ;; This will remove the part.
4570 (mm-display-part handle)
4571 (save-restriction
4572 (narrow-to-region (point)
4573 (if (eobp) (point) (1+ (point))))
4574 (mm-display-part handle)
4575 ;; We narrow to the part itself and
4576 ;; then call the treatment functions.
4577 (goto-char (point-min))
4578 (forward-line 1)
4579 (narrow-to-region (point) (point-max))
4580 (gnus-treat-article
4581 nil id
4582 (gnus-article-mime-total-parts)
4583 (mm-handle-media-type handle)))))
4584 (if (window-live-p window)
4585 (select-window window)))))
4586 (goto-char point)
4587 (gnus-delete-line)
4588 (gnus-insert-mime-button
4589 handle id (list (mm-handle-displayed-p handle)))
4590 (goto-char point))))
4592 (defun gnus-article-goto-part (n)
4593 "Go to MIME part N."
4594 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4596 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4597 (let ((gnus-tmp-name
4598 (or (mail-content-type-get (mm-handle-type handle) 'name)
4599 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4600 (mail-content-type-get (mm-handle-type handle) 'url)
4601 ""))
4602 (gnus-tmp-type (mm-handle-media-type handle))
4603 (gnus-tmp-description
4604 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4605 "")))
4606 (gnus-tmp-dots
4607 (if (if displayed (car displayed)
4608 (mm-handle-displayed-p handle))
4609 "" "..."))
4610 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4611 (buffer-size)))
4612 gnus-tmp-type-long b e)
4613 (when (string-match ".*/" gnus-tmp-name)
4614 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4615 (setq gnus-tmp-type-long (concat gnus-tmp-type
4616 (and (not (equal gnus-tmp-name ""))
4617 (concat "; " gnus-tmp-name))))
4618 (unless (equal gnus-tmp-description "")
4619 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4620 (unless (bolp)
4621 (insert "\n"))
4622 (setq b (point))
4623 (gnus-eval-format
4624 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4625 `(,@(gnus-local-map-property gnus-mime-button-map)
4626 gnus-callback gnus-mm-display-part
4627 gnus-part ,gnus-tmp-id
4628 article-type annotation
4629 gnus-data ,handle))
4630 (setq e (if (bolp)
4631 ;; Exclude a newline.
4632 (1- (point))
4633 (point)))
4634 (widget-convert-button
4635 'link b e
4636 :mime-handle handle
4637 :action 'gnus-widget-press-button
4638 :button-keymap gnus-mime-button-map
4639 :help-echo
4640 (lambda (widget/window &optional overlay pos)
4641 ;; Needed to properly clear the message due to a bug in
4642 ;; wid-edit (XEmacs only).
4643 (if (boundp 'help-echo-owns-message)
4644 (setq help-echo-owns-message t))
4645 (format
4646 "%S: %s the MIME part; %S: more options"
4647 (aref gnus-mouse-2 0)
4648 ;; XEmacs will get a single widget arg; Emacs 21 will get
4649 ;; window, overlay, position.
4650 (if (mm-handle-displayed-p
4651 (if overlay
4652 (with-current-buffer (gnus-overlay-buffer overlay)
4653 (widget-get (widget-at (gnus-overlay-start overlay))
4654 :mime-handle))
4655 (widget-get widget/window :mime-handle)))
4656 "hide" "show")
4657 (aref gnus-down-mouse-3 0))))))
4659 (defun gnus-widget-press-button (elems el)
4660 (goto-char (widget-get elems :from))
4661 (gnus-article-press-button))
4663 (defvar gnus-displaying-mime nil)
4665 (defun gnus-display-mime (&optional ihandles)
4666 "Display the MIME parts."
4667 (save-excursion
4668 (save-selected-window
4669 (let ((window (get-buffer-window gnus-article-buffer))
4670 (point (point)))
4671 (when window
4672 (select-window window)
4673 ;; We have to do this since selecting the window
4674 ;; may change the point. So we set the window point.
4675 (set-window-point window point)))
4676 (let* ((handles (or ihandles
4677 (mm-dissect-buffer nil gnus-article-loose-mime)
4678 (and gnus-article-emulate-mime
4679 (mm-uu-dissect))))
4680 (inhibit-read-only t) handle name type b e display)
4681 (when (and (not ihandles)
4682 (not gnus-displaying-mime))
4683 ;; Top-level call; we clean up.
4684 (when gnus-article-mime-handles
4685 (mm-destroy-parts gnus-article-mime-handles)
4686 (setq gnus-article-mime-handle-alist nil));; A trick.
4687 (setq gnus-article-mime-handles handles)
4688 ;; We allow users to glean info from the handles.
4689 (when gnus-article-mime-part-function
4690 (gnus-mime-part-function handles)))
4691 (if (and handles
4692 (or (not (stringp (car handles)))
4693 (cdr handles)))
4694 (progn
4695 (when (and (not ihandles)
4696 (not gnus-displaying-mime))
4697 ;; Clean up for mime parts.
4698 (article-goto-body)
4699 (delete-region (point) (point-max)))
4700 (let ((gnus-displaying-mime t))
4701 (gnus-mime-display-part handles)))
4702 (save-restriction
4703 (article-goto-body)
4704 (narrow-to-region (point) (point-max))
4705 (gnus-treat-article nil 1 1)
4706 (widen)))
4707 (unless ihandles
4708 ;; Highlight the headers.
4709 (save-excursion
4710 (save-restriction
4711 (article-goto-body)
4712 (narrow-to-region (point-min) (point))
4713 (gnus-article-save-original-date
4714 (gnus-treat-article 'head)))))))))
4716 (defcustom gnus-mime-display-multipart-as-mixed nil
4717 "Display \"multipart\" parts as \"multipart/mixed\".
4719 If t, it overrides nil values of
4720 `gnus-mime-display-multipart-alternative-as-mixed' and
4721 `gnus-mime-display-multipart-related-as-mixed'."
4722 :group 'gnus-article-mime
4723 :type 'boolean)
4725 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4726 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4727 :version "22.1"
4728 :group 'gnus-article-mime
4729 :type 'boolean)
4731 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4732 "Display \"multipart/related\" parts as \"multipart/mixed\".
4734 If displaying \"text/html\" is discouraged \(see
4735 `mm-discouraged-alternatives'\) images or other material inside a
4736 \"multipart/related\" part might be overlooked when this variable is nil."
4737 :version "22.1"
4738 :group 'gnus-article-mime
4739 :type 'boolean)
4741 (defun gnus-mime-display-part (handle)
4742 (cond
4743 ;; Single part.
4744 ((not (stringp (car handle)))
4745 (gnus-mime-display-single handle))
4746 ;; User-defined multipart
4747 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4748 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4749 handle))
4750 ;; multipart/alternative
4751 ((and (equal (car handle) "multipart/alternative")
4752 (not (or gnus-mime-display-multipart-as-mixed
4753 gnus-mime-display-multipart-alternative-as-mixed)))
4754 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4755 (push (cons id handle) gnus-article-mime-handle-alist)
4756 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4757 ;; multipart/related
4758 ((and (equal (car handle) "multipart/related")
4759 (not (or gnus-mime-display-multipart-as-mixed
4760 gnus-mime-display-multipart-related-as-mixed)))
4761 ;;;!!!We should find the start part, but we just default
4762 ;;;!!!to the first part.
4763 ;;(gnus-mime-display-part (cadr handle))
4764 ;;;!!! Most multipart/related is an HTML message plus images.
4765 ;;;!!! Unfortunately we are unable to let W3 display those
4766 ;;;!!! included images, so we just display it as a mixed multipart.
4767 ;;(gnus-mime-display-mixed (cdr handle))
4768 ;;;!!! No, w3 can display everything just fine.
4769 (gnus-mime-display-part (cadr handle)))
4770 ((equal (car handle) "multipart/signed")
4771 (gnus-add-wash-type 'signed)
4772 (gnus-mime-display-security handle))
4773 ((equal (car handle) "multipart/encrypted")
4774 (gnus-add-wash-type 'encrypted)
4775 (gnus-mime-display-security handle))
4776 ;; Other multiparts are handled like multipart/mixed.
4778 (gnus-mime-display-mixed (cdr handle)))))
4780 (defun gnus-mime-part-function (handles)
4781 (if (stringp (car handles))
4782 (mapcar 'gnus-mime-part-function (cdr handles))
4783 (funcall gnus-article-mime-part-function handles)))
4785 (defun gnus-mime-display-mixed (handles)
4786 (mapcar 'gnus-mime-display-part handles))
4788 (defun gnus-mime-display-single (handle)
4789 (let ((type (mm-handle-media-type handle))
4790 (ignored gnus-ignored-mime-types)
4791 (not-attachment t)
4792 (move nil)
4793 display text)
4794 (catch 'ignored
4795 (progn
4796 (while ignored
4797 (when (string-match (pop ignored) type)
4798 (throw 'ignored nil)))
4799 (if (and (setq not-attachment
4800 (and (not (mm-inline-override-p handle))
4801 (or (not (mm-handle-disposition handle))
4802 (equal (car (mm-handle-disposition handle))
4803 "inline")
4804 (mm-attachment-override-p handle))))
4805 (mm-automatic-display-p handle)
4806 (or (and
4807 (mm-inlinable-p handle)
4808 (mm-inlined-p handle))
4809 (mm-automatic-external-display-p type)))
4810 (setq display t)
4811 (when (equal (mm-handle-media-supertype handle) "text")
4812 (setq text t)))
4813 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4814 beg)
4815 (push (cons id handle) gnus-article-mime-handle-alist)
4816 (when (or (not display)
4817 (not (gnus-unbuttonized-mime-type-p type)))
4818 ;(gnus-article-insert-newline)
4819 (gnus-insert-mime-button
4820 handle id (list (or display (and not-attachment text))))
4821 (gnus-article-insert-newline)
4822 ;(gnus-article-insert-newline)
4823 ;; Remember modify the number of forward lines.
4824 (setq move t))
4825 (setq beg (point))
4826 (cond
4827 (display
4828 (when move
4829 (forward-line -1)
4830 (setq beg (point)))
4831 (let ((mail-parse-charset gnus-newsgroup-charset)
4832 (mail-parse-ignored-charsets
4833 (save-excursion (condition-case ()
4834 (set-buffer gnus-summary-buffer)
4835 (error))
4836 gnus-newsgroup-ignored-charsets)))
4837 (mm-display-part handle t))
4838 (goto-char (point-max)))
4839 ((and text not-attachment)
4840 (when move
4841 (forward-line -1)
4842 (setq beg (point)))
4843 (gnus-article-insert-newline)
4844 (mm-insert-inline handle (mm-get-part handle))
4845 (goto-char (point-max))))
4846 ;; Do highlighting.
4847 (save-excursion
4848 (save-restriction
4849 (narrow-to-region beg (point))
4850 (gnus-treat-article
4851 nil id
4852 (gnus-article-mime-total-parts)
4853 (mm-handle-media-type handle)))))))))
4855 (defun gnus-unbuttonized-mime-type-p (type)
4856 "Say whether TYPE is to be unbuttonized."
4857 (unless gnus-inhibit-mime-unbuttonizing
4858 (when (catch 'found
4859 (let ((types gnus-unbuttonized-mime-types))
4860 (while types
4861 (when (string-match (pop types) type)
4862 (throw 'found t)))))
4863 (not (catch 'found
4864 (let ((types gnus-buttonized-mime-types))
4865 (while types
4866 (when (string-match (pop types) type)
4867 (throw 'found t)))))))))
4869 (defun gnus-article-insert-newline ()
4870 "Insert a newline, but mark it as undeletable."
4871 (gnus-put-text-property
4872 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4874 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4875 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4876 (ihandles handles)
4877 (point (point))
4878 handle (inhibit-read-only t) from props begend not-pref)
4879 (save-window-excursion
4880 (save-restriction
4881 (when ibegend
4882 (narrow-to-region (car ibegend)
4883 (or (cdr ibegend)
4884 (progn
4885 (goto-char (car ibegend))
4886 (forward-line 2)
4887 (point))))
4888 (delete-region (point-min) (point-max))
4889 (mm-remove-parts handles))
4890 (setq begend (list (point-marker)))
4891 ;; Do the toggle.
4892 (unless (setq not-pref (cadr (member preferred ihandles)))
4893 (setq not-pref (car ihandles)))
4894 (when (or ibegend
4895 (not preferred)
4896 (not (gnus-unbuttonized-mime-type-p
4897 "multipart/alternative")))
4898 (gnus-add-text-properties
4899 (setq from (point))
4900 (progn
4901 (insert (format "%d. " id))
4902 (point))
4903 `(gnus-callback
4904 (lambda (handles)
4905 (unless ,(not ibegend)
4906 (setq gnus-article-mime-handle-alist
4907 ',gnus-article-mime-handle-alist))
4908 (gnus-mime-display-alternative
4909 ',ihandles ',not-pref ',begend ,id))
4910 ,@(gnus-local-map-property gnus-mime-button-map)
4911 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4912 face ,gnus-article-button-face
4913 gnus-part ,id
4914 gnus-data ,handle))
4915 (widget-convert-button 'link from (point)
4916 :action 'gnus-widget-press-button
4917 :button-keymap gnus-widget-button-keymap)
4918 ;; Do the handles
4919 (while (setq handle (pop handles))
4920 (gnus-add-text-properties
4921 (setq from (point))
4922 (progn
4923 (insert (format "(%c) %-18s"
4924 (if (equal handle preferred) ?* ? )
4925 (mm-handle-media-type handle)))
4926 (point))
4927 `(gnus-callback
4928 (lambda (handles)
4929 (unless ,(not ibegend)
4930 (setq gnus-article-mime-handle-alist
4931 ',gnus-article-mime-handle-alist))
4932 (gnus-mime-display-alternative
4933 ',ihandles ',handle ',begend ,id))
4934 ,@(gnus-local-map-property gnus-mime-button-map)
4935 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4936 face ,gnus-article-button-face
4937 gnus-part ,id
4938 gnus-data ,handle))
4939 (widget-convert-button 'link from (point)
4940 :action 'gnus-widget-press-button
4941 :button-keymap gnus-widget-button-keymap)
4942 (insert " "))
4943 (insert "\n\n"))
4944 (when preferred
4945 (if (stringp (car preferred))
4946 (gnus-display-mime preferred)
4947 (let ((mail-parse-charset gnus-newsgroup-charset)
4948 (mail-parse-ignored-charsets
4949 (save-excursion (set-buffer gnus-summary-buffer)
4950 gnus-newsgroup-ignored-charsets)))
4951 (mm-display-part preferred)
4952 ;; Do highlighting.
4953 (save-excursion
4954 (save-restriction
4955 (narrow-to-region (car begend) (point-max))
4956 (gnus-treat-article
4957 nil (length gnus-article-mime-handle-alist)
4958 (gnus-article-mime-total-parts)
4959 (mm-handle-media-type handle))))))
4960 (goto-char (point-max))
4961 (setcdr begend (point-marker)))))
4962 (when ibegend
4963 (goto-char point))))
4965 (defconst gnus-article-wash-status-strings
4966 (let ((alist '((cite "c" "Possible hidden citation text"
4967 " " "All citation text visible")
4968 (headers "h" "Hidden headers"
4969 " " "All headers visible.")
4970 (pgp "p" "Encrypted or signed message status hidden"
4971 " " "No hidden encryption nor digital signature status")
4972 (signature "s" "Signature has been hidden"
4973 " " "Signature is visible")
4974 (overstrike "o" "Overstrike (^H) characters applied"
4975 " " "No overstrike characters applied")
4976 (emphasis "e" "/*_Emphasis_*/ characters applied"
4977 " " "No /*_emphasis_*/ characters applied")))
4978 result)
4979 (dolist (entry alist result)
4980 (let ((key (nth 0 entry))
4981 (on (copy-sequence (nth 1 entry)))
4982 (on-help (nth 2 entry))
4983 (off (copy-sequence (nth 3 entry)))
4984 (off-help (nth 4 entry)))
4985 (put-text-property 0 1 'help-echo on-help on)
4986 (put-text-property 0 1 'help-echo off-help off)
4987 (push (list key on off) result))))
4988 "Alist of strings describing wash status in the mode line.
4989 Each entry has the form (KEY ON OF), where the KEY is a symbol
4990 representing the particular washing function, ON is the string to use
4991 in the article mode line when the washing function is active, and OFF
4992 is the string to use when it is inactive.")
4994 (defun gnus-article-wash-status-entry (key value)
4995 (let ((entry (assoc key gnus-article-wash-status-strings)))
4996 (if value (nth 1 entry) (nth 2 entry))))
4998 (defun gnus-article-wash-status ()
4999 "Return a string which display status of article washing."
5000 (save-excursion
5001 (set-buffer gnus-article-buffer)
5002 (let ((cite (memq 'cite gnus-article-wash-types))
5003 (headers (memq 'headers gnus-article-wash-types))
5004 (boring (memq 'boring-headers gnus-article-wash-types))
5005 (pgp (memq 'pgp gnus-article-wash-types))
5006 (pem (memq 'pem gnus-article-wash-types))
5007 (signed (memq 'signed gnus-article-wash-types))
5008 (encrypted (memq 'encrypted gnus-article-wash-types))
5009 (signature (memq 'signature gnus-article-wash-types))
5010 (overstrike (memq 'overstrike gnus-article-wash-types))
5011 (emphasis (memq 'emphasis gnus-article-wash-types)))
5012 (concat
5013 (gnus-article-wash-status-entry 'cite cite)
5014 (gnus-article-wash-status-entry 'headers (or headers boring))
5015 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5016 (gnus-article-wash-status-entry 'signature signature)
5017 (gnus-article-wash-status-entry 'overstrike overstrike)
5018 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5020 (defun gnus-add-wash-type (type)
5021 "Add a washing of TYPE to the current status."
5022 (add-to-list 'gnus-article-wash-types type))
5024 (defun gnus-delete-wash-type (type)
5025 "Add a washing of TYPE to the current status."
5026 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5028 (defun gnus-add-image (category image)
5029 "Add IMAGE of CATEGORY to the list of displayed images."
5030 (let ((entry (assq category gnus-article-image-alist)))
5031 (unless entry
5032 (setq entry (list category))
5033 (push entry gnus-article-image-alist))
5034 (nconc entry (list image))))
5036 (defun gnus-delete-images (category)
5037 "Delete all images in CATEGORY."
5038 (let ((entry (assq category gnus-article-image-alist)))
5039 (dolist (image (cdr entry))
5040 (gnus-remove-image image category))
5041 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5042 (gnus-delete-wash-type category)))
5044 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5046 (defun gnus-article-maybe-hide-headers ()
5047 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5048 Provided for backwards compatibility."
5049 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5050 (not (save-excursion (set-buffer gnus-summary-buffer)
5051 gnus-have-all-headers)))
5052 (not gnus-inhibit-hiding))
5053 (gnus-article-hide-headers)))
5055 ;;; Article savers.
5057 (defun gnus-output-to-file (file-name)
5058 "Append the current article to a file named FILE-NAME."
5059 (let ((artbuf (current-buffer)))
5060 (with-temp-buffer
5061 (insert-buffer-substring artbuf)
5062 ;; Append newline at end of the buffer as separator, and then
5063 ;; save it to file.
5064 (goto-char (point-max))
5065 (insert "\n")
5066 (let ((file-name-coding-system nnmail-pathname-coding-system))
5067 (mm-append-to-file (point-min) (point-max) file-name))
5068 t)))
5070 (defun gnus-narrow-to-page (&optional arg)
5071 "Narrow the article buffer to a page.
5072 If given a numerical ARG, move forward ARG pages."
5073 (interactive "P")
5074 (setq arg (if arg (prefix-numeric-value arg) 0))
5075 (save-excursion
5076 (set-buffer gnus-article-buffer)
5077 (goto-char (point-min))
5078 (widen)
5079 ;; Remove any old next/prev buttons.
5080 (when (gnus-visual-p 'page-marker)
5081 (let ((inhibit-read-only t))
5082 (gnus-remove-text-with-property 'gnus-prev)
5083 (gnus-remove-text-with-property 'gnus-next)))
5085 (cond ((< arg 0)
5086 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5087 ((> arg 0)
5088 (re-search-forward page-delimiter nil 'move arg)))
5089 (goto-char (match-end 0))
5090 (save-excursion
5091 (goto-char (point-min))
5092 (setq gnus-page-broken
5093 (and (re-search-forward page-delimiter nil t) t))))
5094 (when gnus-page-broken
5095 (narrow-to-region
5096 (point)
5097 (if (re-search-forward page-delimiter nil 'move)
5098 (match-beginning 0)
5099 (point)))
5100 (when (and (gnus-visual-p 'page-marker)
5101 (> (point-min) (save-restriction (widen) (point-min))))
5102 (save-excursion
5103 (goto-char (point-min))
5104 (gnus-insert-prev-page-button)))
5105 (when (and (gnus-visual-p 'page-marker)
5106 (< (point-max) (save-restriction (widen) (point-max))))
5107 (save-excursion
5108 (goto-char (point-max))
5109 (gnus-insert-next-page-button))))))
5111 ;; Article mode commands
5113 (defun gnus-article-goto-next-page ()
5114 "Show the next page of the article."
5115 (interactive)
5116 (when (gnus-article-next-page)
5117 (goto-char (point-min))
5118 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5121 (defun gnus-article-goto-prev-page ()
5122 "Show the previous page of the article."
5123 (interactive)
5124 (if (bobp)
5125 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5126 (gnus-article-prev-page nil)))
5128 ;; This is cleaner but currently breaks `gnus-pick-mode':
5130 ;; (defun gnus-article-goto-next-page ()
5131 ;; "Show the next page of the article."
5132 ;; (interactive)
5133 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5134 ;; (gnus-summary-next-page)))
5136 ;; (defun gnus-article-goto-prev-page ()
5137 ;; "Show the next page of the article."
5138 ;; (interactive)
5139 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5140 ;; (gnus-summary-prev-page)))
5142 (defun gnus-article-next-page (&optional lines)
5143 "Show the next page of the current article.
5144 If end of article, return non-nil. Otherwise return nil.
5145 Argument LINES specifies lines to be scrolled up."
5146 (interactive "p")
5147 (move-to-window-line -1)
5148 (if (save-excursion
5149 (end-of-line)
5150 (and (pos-visible-in-window-p) ;Not continuation line.
5151 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5152 ;; Nothing in this page.
5153 (if (or (not gnus-page-broken)
5154 (save-excursion
5155 (save-restriction
5156 (widen)
5157 (forward-line)
5158 (eobp)))) ;Real end-of-buffer?
5159 (progn
5160 (when gnus-article-over-scroll
5161 (gnus-article-next-page-1 lines))
5162 t) ;Nothing more.
5163 (gnus-narrow-to-page 1) ;Go to next page.
5164 nil)
5165 ;; More in this page.
5166 (gnus-article-next-page-1 lines)
5167 nil))
5169 (defun gnus-article-next-page-1 (lines)
5170 (let ((scroll-in-place nil))
5171 (condition-case ()
5172 (scroll-up lines)
5173 (end-of-buffer
5174 ;; Long lines may cause an end-of-buffer error.
5175 (goto-char (point-max)))))
5176 (move-to-window-line 0))
5178 (defun gnus-article-prev-page (&optional lines)
5179 "Show previous page of current article.
5180 Argument LINES specifies lines to be scrolled down."
5181 (interactive "p")
5182 (move-to-window-line 0)
5183 (if (and gnus-page-broken
5184 (bobp)
5185 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5186 (progn
5187 (gnus-narrow-to-page -1) ;Go to previous page.
5188 (goto-char (point-max))
5189 (recenter -1))
5190 (let ((scroll-in-place nil))
5191 (prog1
5192 (condition-case ()
5193 (scroll-down lines)
5194 (beginning-of-buffer
5195 (goto-char (point-min))))
5196 (move-to-window-line 0)))))
5198 (defun gnus-article-only-boring-p ()
5199 "Decide whether there is only boring text remaining in the article.
5200 Something \"interesting\" is a word of at least two letters that does
5201 not have a face in `gnus-article-boring-faces'."
5202 (when (and gnus-article-skip-boring
5203 (boundp 'gnus-article-boring-faces)
5204 (symbol-value 'gnus-article-boring-faces))
5205 (save-excursion
5206 (catch 'only-boring
5207 (while (re-search-forward "\\b\\w\\w" nil t)
5208 (forward-char -1)
5209 (when (not (gnus-intersection
5210 (gnus-faces-at (point))
5211 (symbol-value 'gnus-article-boring-faces)))
5212 (throw 'only-boring nil)))
5213 (throw 'only-boring t)))))
5215 (defun gnus-article-refer-article ()
5216 "Read article specified by message-id around point."
5217 (interactive)
5218 (save-excursion
5219 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5220 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5221 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5222 (let ((msg-id (concat "<" (match-string 0) ">")))
5223 (set-buffer gnus-summary-buffer)
5224 (gnus-summary-refer-article msg-id))
5225 (error "No references around point"))))
5227 (defun gnus-article-show-summary ()
5228 "Reconfigure windows to show summary buffer."
5229 (interactive)
5230 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5231 (error "There is no summary buffer for this article buffer")
5232 (gnus-article-set-globals)
5233 (gnus-configure-windows 'article)
5234 (gnus-summary-goto-subject gnus-current-article)
5235 (gnus-summary-position-point)))
5237 (defun gnus-article-describe-briefly ()
5238 "Describe article mode commands briefly."
5239 (interactive)
5240 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
5242 (defun gnus-article-summary-command ()
5243 "Execute the last keystroke in the summary buffer."
5244 (interactive)
5245 (let ((obuf (current-buffer))
5246 (owin (current-window-configuration))
5247 func)
5248 (switch-to-buffer gnus-article-current-summary 'norecord)
5249 (setq func (lookup-key (current-local-map) (this-command-keys)))
5250 (call-interactively func)
5251 (set-buffer obuf)
5252 (set-window-configuration owin)
5253 (set-window-point (get-buffer-window (current-buffer)) (point))))
5255 (defun gnus-article-summary-command-nosave ()
5256 "Execute the last keystroke in the summary buffer."
5257 (interactive)
5258 (let (func)
5259 (pop-to-buffer gnus-article-current-summary 'norecord)
5260 (setq func (lookup-key (current-local-map) (this-command-keys)))
5261 (call-interactively func)))
5263 (defun gnus-article-check-buffer ()
5264 "Beep if not in an article buffer."
5265 (unless (equal major-mode 'gnus-article-mode)
5266 (error "Command invoked outside of a Gnus article buffer")))
5268 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5269 "Read a summary buffer key sequence and execute it from the article buffer."
5270 (interactive "P")
5271 (gnus-article-check-buffer)
5272 (let ((nosaves
5273 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5274 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5275 "=" "^" "\M-^" "|"))
5276 (nosave-but-article
5277 '("A\r"))
5278 (nosave-in-article
5279 '("\C-d"))
5280 (up-to-top
5281 '("n" "Gn" "p" "Gp"))
5282 keys new-sum-point)
5283 (save-excursion
5284 (set-buffer gnus-article-current-summary)
5285 (let (gnus-pick-mode)
5286 (push (or key last-command-event) unread-command-events)
5287 (setq keys (if (featurep 'xemacs)
5288 (events-to-keys (read-key-sequence nil))
5289 (read-key-sequence nil)))))
5291 (message "")
5293 (if (or (member keys nosaves)
5294 (member keys nosave-but-article)
5295 (member keys nosave-in-article))
5296 (let (func)
5297 (save-window-excursion
5298 (pop-to-buffer gnus-article-current-summary 'norecord)
5299 ;; We disable the pick minor mode commands.
5300 (let (gnus-pick-mode)
5301 (setq func (lookup-key (current-local-map) keys))))
5302 (if (or (not func)
5303 (numberp func))
5304 (ding)
5305 (unless (member keys nosave-in-article)
5306 (set-buffer gnus-article-current-summary))
5307 (call-interactively func)
5308 (setq new-sum-point (point)))
5309 (when (member keys nosave-but-article)
5310 (pop-to-buffer gnus-article-buffer 'norecord)))
5311 ;; These commands should restore window configuration.
5312 (let ((obuf (current-buffer))
5313 (owin (current-window-configuration))
5314 (opoint (point))
5315 win func in-buffer selected new-sum-start new-sum-hscroll)
5316 (cond (not-restore-window
5317 (pop-to-buffer gnus-article-current-summary 'norecord))
5318 ((setq win (get-buffer-window gnus-article-current-summary))
5319 (select-window win))
5321 (switch-to-buffer gnus-article-current-summary 'norecord)))
5322 (setq in-buffer (current-buffer))
5323 ;; We disable the pick minor mode commands.
5324 (if (and (setq func (let (gnus-pick-mode)
5325 (lookup-key (current-local-map) keys)))
5326 (functionp func))
5327 (progn
5328 (call-interactively func)
5329 (when (eq win (selected-window))
5330 (setq new-sum-point (point)
5331 new-sum-start (window-start win)
5332 new-sum-hscroll (window-hscroll win)))
5333 (when (eq in-buffer (current-buffer))
5334 (setq selected (gnus-summary-select-article))
5335 (set-buffer obuf)
5336 (unless not-restore-window
5337 (set-window-configuration owin))
5338 (when (eq selected 'old)
5339 (article-goto-body)
5340 (set-window-start (get-buffer-window (current-buffer))
5342 (set-window-point (get-buffer-window (current-buffer))
5343 (point)))
5344 (when (and (not not-restore-window)
5345 new-sum-point)
5346 (set-window-point win new-sum-point)
5347 (set-window-start win new-sum-start)
5348 (set-window-hscroll win new-sum-hscroll))))
5349 (set-window-configuration owin)
5350 (ding))))))
5352 (defun gnus-article-describe-key (key)
5353 "Display documentation of the function invoked by KEY. KEY is a string."
5354 (interactive "kDescribe key: ")
5355 (gnus-article-check-buffer)
5356 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5357 (save-excursion
5358 (set-buffer gnus-article-current-summary)
5359 (let (gnus-pick-mode)
5360 (if (featurep 'xemacs)
5361 (progn
5362 (push (elt key 0) unread-command-events)
5363 (setq key (events-to-keys
5364 (read-key-sequence "Describe key: "))))
5365 (setq unread-command-events
5366 (mapcar
5367 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5368 (string-to-list key)))
5369 (setq key (read-key-sequence "Describe key: "))))
5370 (describe-key key))
5371 (describe-key key)))
5373 (defun gnus-article-describe-key-briefly (key &optional insert)
5374 "Display documentation of the function invoked by KEY. KEY is a string."
5375 (interactive "kDescribe key: \nP")
5376 (gnus-article-check-buffer)
5377 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5378 (save-excursion
5379 (set-buffer gnus-article-current-summary)
5380 (let (gnus-pick-mode)
5381 (if (featurep 'xemacs)
5382 (progn
5383 (push (elt key 0) unread-command-events)
5384 (setq key (events-to-keys
5385 (read-key-sequence "Describe key: "))))
5386 (setq unread-command-events
5387 (mapcar
5388 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5389 (string-to-list key)))
5390 (setq key (read-key-sequence "Describe key: "))))
5391 (describe-key-briefly key insert))
5392 (describe-key-briefly key insert)))
5394 (defun gnus-article-reply-with-original (&optional wide)
5395 "Start composing a reply mail to the current message.
5396 The text in the region will be yanked. If the region isn't active,
5397 the entire article will be yanked."
5398 (interactive "P")
5399 (let ((article (cdr gnus-article-current))
5400 contents)
5401 (if (not (gnus-mark-active-p))
5402 (with-current-buffer gnus-summary-buffer
5403 (gnus-summary-reply (list (list article)) wide))
5404 (setq contents (buffer-substring (point) (mark t)))
5405 ;; Deactivate active regions.
5406 (when (and (boundp 'transient-mark-mode)
5407 transient-mark-mode)
5408 (setq mark-active nil))
5409 (with-current-buffer gnus-summary-buffer
5410 (gnus-summary-reply
5411 (list (list article contents)) wide)))))
5413 (defun gnus-article-followup-with-original ()
5414 "Compose a followup to the current article.
5415 The text in the region will be yanked. If the region isn't active,
5416 the entire article will be yanked."
5417 (interactive)
5418 (let ((article (cdr gnus-article-current))
5419 contents)
5420 (if (not (gnus-mark-active-p))
5421 (with-current-buffer gnus-summary-buffer
5422 (gnus-summary-followup (list (list article))))
5423 (setq contents (buffer-substring (point) (mark t)))
5424 ;; Deactivate active regions.
5425 (when (and (boundp 'transient-mark-mode)
5426 transient-mark-mode)
5427 (setq mark-active nil))
5428 (with-current-buffer gnus-summary-buffer
5429 (gnus-summary-followup
5430 (list (list article contents)))))))
5432 (defun gnus-article-hide (&optional arg force)
5433 "Hide all the gruft in the current article.
5434 This means that signatures, cited text and (some) headers will be
5435 hidden.
5436 If given a prefix, show the hidden text instead."
5437 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5438 (gnus-article-hide-headers arg)
5439 (gnus-article-hide-list-identifiers arg)
5440 (gnus-article-hide-citation-maybe arg force)
5441 (gnus-article-hide-signature arg))
5443 (defun gnus-article-maybe-highlight ()
5444 "Do some article highlighting if article highlighting is requested."
5445 (when (gnus-visual-p 'article-highlight 'highlight)
5446 (gnus-article-highlight-some)))
5448 (defun gnus-check-group-server ()
5449 ;; Make sure the connection to the server is alive.
5450 (unless (gnus-server-opened
5451 (gnus-find-method-for-group gnus-newsgroup-name))
5452 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5453 (gnus-request-group gnus-newsgroup-name t)))
5455 (eval-when-compile
5456 (autoload 'nneething-get-file-name "nneething"))
5458 (defun gnus-request-article-this-buffer (article group)
5459 "Get an article and insert it into this buffer."
5460 (let (do-update-line sparse-header)
5461 (prog1
5462 (save-excursion
5463 (erase-buffer)
5464 (gnus-kill-all-overlays)
5465 (setq group (or group gnus-newsgroup-name))
5467 ;; Using `gnus-request-article' directly will insert the article into
5468 ;; `nntp-server-buffer' - so we'll save some time by not having to
5469 ;; copy it from the server buffer into the article buffer.
5471 ;; We only request an article by message-id when we do not have the
5472 ;; headers for it, so we'll have to get those.
5473 (when (stringp article)
5474 (gnus-read-header article))
5476 ;; If the article number is negative, that means that this article
5477 ;; doesn't belong in this newsgroup (possibly), so we find its
5478 ;; message-id and request it by id instead of number.
5479 (when (and (numberp article)
5480 gnus-summary-buffer
5481 (get-buffer gnus-summary-buffer)
5482 (gnus-buffer-exists-p gnus-summary-buffer))
5483 (save-excursion
5484 (set-buffer gnus-summary-buffer)
5485 (let ((header (gnus-summary-article-header article)))
5486 (when (< article 0)
5487 (cond
5488 ((memq article gnus-newsgroup-sparse)
5489 ;; This is a sparse gap article.
5490 (setq do-update-line article)
5491 (setq article (mail-header-id header))
5492 (setq sparse-header (gnus-read-header article))
5493 (setq gnus-newsgroup-sparse
5494 (delq article gnus-newsgroup-sparse)))
5495 ((vectorp header)
5496 ;; It's a real article.
5497 (setq article (mail-header-id header)))
5499 ;; It is an extracted pseudo-article.
5500 (setq article 'pseudo)
5501 (gnus-request-pseudo-article header))))
5503 (let ((method (gnus-find-method-for-group
5504 gnus-newsgroup-name)))
5505 (when (and (eq (car method) 'nneething)
5506 (vectorp header))
5507 (let ((dir (nneething-get-file-name
5508 (mail-header-id header))))
5509 (when (and (stringp dir)
5510 (file-directory-p dir))
5511 (setq article 'nneething)
5512 (gnus-group-enter-directory dir))))))))
5514 (cond
5515 ;; Refuse to select canceled articles.
5516 ((and (numberp article)
5517 gnus-summary-buffer
5518 (get-buffer gnus-summary-buffer)
5519 (gnus-buffer-exists-p gnus-summary-buffer)
5520 (eq (cdr (save-excursion
5521 (set-buffer gnus-summary-buffer)
5522 (assq article gnus-newsgroup-reads)))
5523 gnus-canceled-mark))
5524 nil)
5525 ;; We first check `gnus-original-article-buffer'.
5526 ((and (get-buffer gnus-original-article-buffer)
5527 (numberp article)
5528 (save-excursion
5529 (set-buffer gnus-original-article-buffer)
5530 (and (equal (car gnus-original-article) group)
5531 (eq (cdr gnus-original-article) article))))
5532 (insert-buffer-substring gnus-original-article-buffer)
5533 'article)
5534 ;; Check the backlog.
5535 ((and gnus-keep-backlog
5536 (gnus-backlog-request-article group article (current-buffer)))
5537 'article)
5538 ;; Check asynchronous pre-fetch.
5539 ((gnus-async-request-fetched-article group article (current-buffer))
5540 (gnus-async-prefetch-next group article gnus-summary-buffer)
5541 (when (and (numberp article) gnus-keep-backlog)
5542 (gnus-backlog-enter-article group article (current-buffer)))
5543 'article)
5544 ;; Check the cache.
5545 ((and gnus-use-cache
5546 (numberp article)
5547 (gnus-cache-request-article article group))
5548 'article)
5549 ;; Check the agent cache.
5550 ((gnus-agent-request-article article group)
5551 'article)
5552 ;; Get the article and put into the article buffer.
5553 ((or (stringp article)
5554 (numberp article))
5555 (let ((gnus-override-method gnus-override-method)
5556 (methods (and (stringp article)
5557 gnus-refer-article-method))
5558 (backend (car (gnus-find-method-for-group
5559 gnus-newsgroup-name)))
5560 result
5561 (inhibit-read-only t))
5562 (if (or (not (listp methods))
5563 (and (symbolp (car methods))
5564 (assq (car methods) nnoo-definition-alist)))
5565 (setq methods (list methods)))
5566 (when (and (null gnus-override-method)
5567 methods)
5568 (setq gnus-override-method (pop methods)))
5569 (while (not result)
5570 (when (eq gnus-override-method 'current)
5571 (setq gnus-override-method
5572 (with-current-buffer gnus-summary-buffer
5573 gnus-current-select-method)))
5574 (erase-buffer)
5575 (gnus-kill-all-overlays)
5576 (let ((gnus-newsgroup-name group))
5577 (gnus-check-group-server))
5578 (cond
5579 ((gnus-request-article article group (current-buffer))
5580 (when (numberp article)
5581 (gnus-async-prefetch-next group article
5582 gnus-summary-buffer)
5583 (when gnus-keep-backlog
5584 (gnus-backlog-enter-article
5585 group article (current-buffer))))
5586 (setq result 'article))
5587 (methods
5588 (setq gnus-override-method (pop methods)))
5589 ((not (string-match "^400 "
5590 (nnheader-get-report backend)))
5591 ;; If we get 400 server disconnect, reconnect and
5592 ;; retry; otherwise, assume the article has expired.
5593 (setq result 'done))))
5594 (and (eq result 'article) 'article)))
5595 ;; It was a pseudo.
5596 (t article)))
5598 ;; Associate this article with the current summary buffer.
5599 (setq gnus-article-current-summary gnus-summary-buffer)
5601 ;; Take the article from the original article buffer
5602 ;; and place it in the buffer it's supposed to be in.
5603 (when (and (get-buffer gnus-article-buffer)
5604 (equal (buffer-name (current-buffer))
5605 (buffer-name (get-buffer gnus-article-buffer))))
5606 (save-excursion
5607 (if (get-buffer gnus-original-article-buffer)
5608 (set-buffer gnus-original-article-buffer)
5609 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5610 (buffer-disable-undo)
5611 (setq major-mode 'gnus-original-article-mode)
5612 (setq buffer-read-only t))
5613 (let ((inhibit-read-only t))
5614 (erase-buffer)
5615 (insert-buffer-substring gnus-article-buffer))
5616 (setq gnus-original-article (cons group article)))
5618 ;; Decode charsets.
5619 (run-hooks 'gnus-article-decode-hook)
5620 ;; Mark article as decoded or not.
5621 (setq gnus-article-decoded-p gnus-article-decode-hook))
5623 ;; Update sparse articles.
5624 (when (and do-update-line
5625 (or (numberp article)
5626 (stringp article)))
5627 (let ((buf (current-buffer)))
5628 (set-buffer gnus-summary-buffer)
5629 (gnus-summary-update-article do-update-line sparse-header)
5630 (gnus-summary-goto-subject do-update-line nil t)
5631 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5632 (point))
5633 (set-buffer buf))))))
5636 ;;; Article editing
5639 (defcustom gnus-article-edit-mode-hook nil
5640 "Hook run in article edit mode buffers."
5641 :group 'gnus-article-various
5642 :type 'hook)
5644 (defvar gnus-article-edit-done-function nil)
5646 (defvar gnus-article-edit-mode-map nil)
5647 (defvar gnus-article-edit-mode nil)
5649 ;; Should we be using derived.el for this?
5650 (unless gnus-article-edit-mode-map
5651 (setq gnus-article-edit-mode-map (make-keymap))
5652 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5654 (gnus-define-keys gnus-article-edit-mode-map
5655 "\C-c?" describe-mode
5656 "\C-c\C-c" gnus-article-edit-done
5657 "\C-c\C-k" gnus-article-edit-exit
5658 "\C-c\C-f\C-t" message-goto-to
5659 "\C-c\C-f\C-o" message-goto-from
5660 "\C-c\C-f\C-b" message-goto-bcc
5661 ;;"\C-c\C-f\C-w" message-goto-fcc
5662 "\C-c\C-f\C-c" message-goto-cc
5663 "\C-c\C-f\C-s" message-goto-subject
5664 "\C-c\C-f\C-r" message-goto-reply-to
5665 "\C-c\C-f\C-n" message-goto-newsgroups
5666 "\C-c\C-f\C-d" message-goto-distribution
5667 "\C-c\C-f\C-f" message-goto-followup-to
5668 "\C-c\C-f\C-m" message-goto-mail-followup-to
5669 "\C-c\C-f\C-k" message-goto-keywords
5670 "\C-c\C-f\C-u" message-goto-summary
5671 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5672 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5673 "\C-c\C-b" message-goto-body
5674 "\C-c\C-i" message-goto-signature
5676 "\C-c\C-t" message-insert-to
5677 "\C-c\C-n" message-insert-newsgroups
5678 "\C-c\C-o" message-sort-headers
5679 "\C-c\C-e" message-elide-region
5680 "\C-c\C-v" message-delete-not-region
5681 "\C-c\C-z" message-kill-to-signature
5682 "\M-\r" message-newline-and-reformat
5683 "\C-c\C-a" mml-attach-file
5684 "\C-a" message-beginning-of-line
5685 "\t" message-tab
5686 "\M-;" comment-region)
5688 (gnus-define-keys (gnus-article-edit-wash-map
5689 "\C-c\C-w" gnus-article-edit-mode-map)
5690 "f" gnus-article-edit-full-stops))
5692 (easy-menu-define
5693 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5694 '("Field"
5695 ["Fetch To" message-insert-to t]
5696 ["Fetch Newsgroups" message-insert-newsgroups t]
5697 "----"
5698 ["To" message-goto-to t]
5699 ["From" message-goto-from t]
5700 ["Subject" message-goto-subject t]
5701 ["Cc" message-goto-cc t]
5702 ["Reply-To" message-goto-reply-to t]
5703 ["Summary" message-goto-summary t]
5704 ["Keywords" message-goto-keywords t]
5705 ["Newsgroups" message-goto-newsgroups t]
5706 ["Followup-To" message-goto-followup-to t]
5707 ["Mail-Followup-To" message-goto-mail-followup-to t]
5708 ["Distribution" message-goto-distribution t]
5709 ["Body" message-goto-body t]
5710 ["Signature" message-goto-signature t]))
5712 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5713 "Major mode for editing articles.
5714 This is an extended text-mode.
5716 \\{gnus-article-edit-mode-map}"
5717 (make-local-variable 'gnus-article-edit-done-function)
5718 (make-local-variable 'gnus-prev-winconf)
5719 (set (make-local-variable 'font-lock-defaults)
5720 '(message-font-lock-keywords t))
5721 (set (make-local-variable 'mail-header-separator) "")
5722 (set (make-local-variable 'gnus-article-edit-mode) t)
5723 (easy-menu-add message-mode-field-menu message-mode-map)
5724 (mml-mode)
5725 (setq buffer-read-only nil)
5726 (buffer-enable-undo)
5727 (widen))
5729 (defun gnus-article-edit (&optional force)
5730 "Edit the current article.
5731 This will have permanent effect only in mail groups.
5732 If FORCE is non-nil, allow editing of articles even in read-only
5733 groups."
5734 (interactive "P")
5735 (when (and (not force)
5736 (gnus-group-read-only-p))
5737 (error "The current newsgroup does not support article editing"))
5738 (gnus-article-date-original)
5739 (gnus-article-edit-article
5740 'ignore
5741 `(lambda (no-highlight)
5742 'ignore
5743 (gnus-summary-edit-article-done
5744 ,(or (mail-header-references gnus-current-headers) "")
5745 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5747 (defun gnus-article-edit-article (start-func exit-func)
5748 "Start editing the contents of the current article buffer."
5749 (let ((winconf (current-window-configuration)))
5750 (set-buffer gnus-article-buffer)
5751 (let ((message-auto-save-directory
5752 ;; Don't associate the article buffer with a draft file.
5753 nil))
5754 (gnus-article-edit-mode))
5755 (funcall start-func)
5756 (set-buffer-modified-p nil)
5757 (gnus-configure-windows 'edit-article)
5758 (setq gnus-article-edit-done-function exit-func)
5759 (setq gnus-prev-winconf winconf)
5760 (gnus-message 6 "C-c C-c to end edits")))
5762 (defun gnus-article-edit-done (&optional arg)
5763 "Update the article edits and exit."
5764 (interactive "P")
5765 (let ((func gnus-article-edit-done-function)
5766 (buf (current-buffer))
5767 (start (window-start))
5768 (p (point))
5769 (winconf gnus-prev-winconf))
5770 (widen) ;; Widen it in case that users narrowed the buffer.
5771 (funcall func arg)
5772 (set-buffer buf)
5773 ;; The cache and backlog have to be flushed somewhat.
5774 (when gnus-keep-backlog
5775 (gnus-backlog-remove-article
5776 (car gnus-article-current) (cdr gnus-article-current)))
5777 ;; Flush original article as well.
5778 (save-excursion
5779 (when (get-buffer gnus-original-article-buffer)
5780 (set-buffer gnus-original-article-buffer)
5781 (setq gnus-original-article nil)))
5782 (when gnus-use-cache
5783 (gnus-cache-update-article
5784 (car gnus-article-current) (cdr gnus-article-current)))
5785 ;; We remove all text props from the article buffer.
5786 (kill-all-local-variables)
5787 (gnus-set-text-properties (point-min) (point-max) nil)
5788 (gnus-article-mode)
5789 (set-window-configuration winconf)
5790 (set-buffer buf)
5791 (set-window-start (get-buffer-window buf) start)
5792 (set-window-point (get-buffer-window buf) (point)))
5793 (gnus-summary-show-article))
5795 (defun gnus-article-edit-exit ()
5796 "Exit the article editing without updating."
5797 (interactive)
5798 (when (or (not (buffer-modified-p))
5799 (yes-or-no-p "Article modified; kill anyway? "))
5800 (let ((curbuf (current-buffer))
5801 (p (point))
5802 (window-start (window-start)))
5803 (erase-buffer)
5804 (if (gnus-buffer-live-p gnus-original-article-buffer)
5805 (insert-buffer gnus-original-article-buffer))
5806 (let ((winconf gnus-prev-winconf))
5807 (kill-all-local-variables)
5808 (gnus-article-mode)
5809 (set-window-configuration winconf)
5810 ;; Tippy-toe some to make sure that point remains where it was.
5811 (save-current-buffer
5812 (set-buffer curbuf)
5813 (set-window-start (get-buffer-window (current-buffer)) window-start)
5814 (goto-char p))))
5815 (gnus-summary-show-article)))
5817 (defun gnus-article-edit-full-stops ()
5818 "Interactively repair spacing at end of sentences."
5819 (interactive)
5820 (save-excursion
5821 (goto-char (point-min))
5822 (search-forward-regexp "^$" nil t)
5823 (let ((case-fold-search nil))
5824 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5827 ;;; Article highlights
5830 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5832 ;;; Internal Variables:
5834 (defcustom gnus-button-url-regexp
5835 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5836 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
5837 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
5838 "Regular expression that matches URLs."
5839 :group 'gnus-article-buttons
5840 :type 'regexp)
5842 (defcustom gnus-button-valid-fqdn-regexp
5843 message-valid-fqdn-regexp
5844 "Regular expression that matches a valid FQDN."
5845 :version "22.1"
5846 :group 'gnus-article-buttons
5847 :type 'regexp)
5849 (defcustom gnus-button-man-handler 'manual-entry
5850 "Function to use for displaying man pages.
5851 The function must take at least one argument with a string naming the
5852 man page."
5853 :version "22.1"
5854 :type '(choice (function-item :tag "Man" manual-entry)
5855 (function-item :tag "Woman" woman)
5856 (function :tag "Other"))
5857 :group 'gnus-article-buttons)
5859 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5860 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5861 If the default site is too slow, try to find a CTAN mirror, see
5862 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
5863 the variable `gnus-button-handle-ctan'."
5864 :version "22.1"
5865 :group 'gnus-article-buttons
5866 :link '(custom-manual "(gnus)Group Parameters")
5867 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5868 (const "http://tug.ctan.org/tex-archive/")
5869 (const "http://www.dante.de/CTAN/")
5870 (string :tag "Other")))
5872 (defcustom gnus-button-ctan-handler 'browse-url
5873 "Function to use for displaying CTAN links.
5874 The function must take one argument, the string naming the URL."
5875 :version "22.1"
5876 :type '(choice (function-item :tag "Browse Url" browse-url)
5877 (function :tag "Other"))
5878 :group 'gnus-article-buttons)
5880 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5881 "Bogus strings removed from CTAN URLs."
5882 :version "22.1"
5883 :group 'gnus-article-buttons
5884 :type '(choice (const "^/?tex-archive/\\|/")
5885 (regexp :tag "Other")))
5887 (defcustom gnus-button-ctan-directory-regexp
5888 (concat
5889 "\\("; Cannot use `\(?: ... \)' (compatibility with Emacs 20).
5890 "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
5891 "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
5892 "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
5893 "\\)")
5894 "Regular expression for ctan directories.
5895 It should match all directories in the top level of `gnus-ctan-url'."
5896 :version "22.1"
5897 :group 'gnus-article-buttons
5898 :type 'regexp)
5900 (defcustom gnus-button-mid-or-mail-regexp
5901 (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
5902 ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
5903 gnus-button-valid-fqdn-regexp
5904 ">?\\)\\b")
5905 "Regular expression that matches a message ID or a mail address."
5906 :version "22.1"
5907 :group 'gnus-article-buttons
5908 :type 'regexp)
5910 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5911 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5912 Strings like this can be either a message ID or a mail address. If it is one
5913 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5914 message ID or a mail address, respectively. If this variable is set to the
5915 symbol `ask', always query the user what do do. If it is a function, this
5916 function will be called with the string as it's only argument. The function
5917 must return `mid', `mail', `invalid' or `ask'."
5918 :version "22.1"
5919 :group 'gnus-article-buttons
5920 :type '(choice (function-item :tag "Heuristic function"
5921 gnus-button-mid-or-mail-heuristic)
5922 (const ask)
5923 (const mid)
5924 (const mail)))
5926 (defcustom gnus-button-mid-or-mail-heuristic-alist
5927 '((-10.0 . ".+\\$.+@")
5928 (-10.0 . "#")
5929 (-10.0 . "\\*")
5930 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
5931 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5932 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5933 (-1.0 . "^[^a-z]+@")
5935 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5936 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5937 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
5938 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5940 (-2.0 . "^[0-9]")
5941 (-1.0 . "^[0-9][0-9]")
5943 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5944 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5945 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5946 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5948 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5949 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5950 ;; "[0-9]{8,}.*\@"
5951 (-3.0
5952 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5953 ;; "[0-9]{12,}.*\@"
5954 ;; compensation for TDMA dated mail addresses:
5955 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5957 (-20.0 . "\\.fsf@") ;; Gnus
5958 (-20.0 . "^slrn")
5959 (-20.0 . "^Pine")
5960 (-20.0 . "_-_") ;; Subject change in thread
5962 (-20.0 . "\\.ln@") ;; leafnode
5963 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5964 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5966 ;; (5.0 . "") ;; $local_part_len <= 7
5967 (10.0 . "^[^0-9]+@")
5968 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5969 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5970 (3.0 . "\@stud")
5972 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
5974 (0.5 . "^[A-Z][a-z]")
5975 (0.5 . "^[A-Z][a-z][a-z]")
5976 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5977 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5978 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5980 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5981 address. The REGEXP is processed with `case-fold-search' set to nil."
5982 :version "22.1"
5983 :group 'gnus-article-buttons
5984 :type '(repeat (cons (number :tag "Rate")
5985 (regexp :tag "Regexp"))))
5987 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5988 "Guess whether MID-OR-MAIL is a message ID or a mail address.
5989 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5990 address, `ask' if unsure and `invalid' if the string is invalid."
5991 (let ((case-fold-search nil)
5992 (list gnus-button-mid-or-mail-heuristic-alist)
5993 (result 0) rate regexp lpartlen elem)
5994 (setq lpartlen
5995 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5996 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5997 ;; Certain special cases...
5998 (when (string-match
5999 (concat
6000 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6001 "^[0-9]+\\.[0-9]+@compuserve\\|"
6002 "@public\\.gmane\\.org")
6003 mid-or-mail)
6004 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6005 (setq result 'mail))
6006 (when (string-match "@.*@\\| " mid-or-mail)
6007 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6008 (setq result 'invalid))
6009 ;; Nothing more to do, if result is not a number here...
6010 (when (numberp result)
6011 (while list
6012 (setq elem (car list)
6013 rate (car elem)
6014 regexp (cdr elem)
6015 list (cdr list))
6016 (when (string-match regexp mid-or-mail)
6017 (setq result (+ result rate))
6018 (gnus-message
6019 9 "`%s' matched `%s', rate `%s', result `%s'."
6020 mid-or-mail regexp rate result)))
6021 (when (<= lpartlen 7)
6022 (setq result (+ result 5.0))
6023 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6024 mid-or-mail result))
6025 (when (>= lpartlen 12)
6026 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6027 (cond
6028 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6029 ;; Long local part should contain realname if e-mail address,
6030 ;; too many digits: message-id.
6031 ;; $score -= 5.0 + 0.1 * $local_part_len;
6032 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6033 (setq result (+ result rate))
6034 (gnus-message
6035 9 "Many digits in `%s', rate `%s', result `%s'."
6036 mid-or-mail rate result))
6037 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6038 mid-or-mail)
6039 ;; Too few vowels [^aeiouy]{4,}.*\@
6040 (setq result (+ result -5.0))
6041 (gnus-message
6042 9 "Few vowels in `%s', rate `%s', result `%s'."
6043 mid-or-mail -5.0 result))
6045 (setq result (+ result 5.0))
6046 (gnus-message
6047 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6048 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6049 ;; Maybe we should make this a customizable alist: (condition . 'result)
6050 (cond
6051 ((symbolp result) result)
6052 ;; Now convert number into proper results:
6053 ((< result -10.0) 'mid)
6054 ((> result 10.0) 'mail)
6055 (t 'ask))))
6057 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6058 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6059 (url-mid (concat "news" ":" mid-or-mail))
6060 (url-mailto (concat "mailto" ":" mid-or-mail)))
6061 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6062 (when (fboundp pref)
6063 (setq guessed
6064 ;; get rid of surrounding angles...
6065 (funcall pref
6066 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6067 (if (or (eq 'mid guessed) (eq 'mail guessed))
6068 (setq pref guessed)
6069 (setq pref 'ask)))
6070 (if (eq pref 'ask)
6071 (save-window-excursion
6072 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6073 (setq pref 'mail)
6074 (setq pref 'mid))))
6075 (cond ((eq pref 'mid)
6076 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6077 (gnus-button-handle-news url-mid))
6078 ((eq pref 'mail)
6079 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6080 (gnus-url-mailto url-mailto))
6081 (t (gnus-message 3 "Invalid string.")))))
6083 (defun gnus-button-handle-custom (url)
6084 "Follow a Custom URL."
6085 (customize-apropos (gnus-url-unhex-string url)))
6087 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6089 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6090 ;; stuff?
6092 (defun gnus-button-handle-describe-function (url)
6093 "Call `describe-function' when pushing the corresponding URL button."
6094 (describe-function
6095 (intern
6096 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6098 (defun gnus-button-handle-describe-variable (url)
6099 "Call `describe-variable' when pushing the corresponding URL button."
6100 (describe-variable
6101 (intern
6102 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6104 (defun gnus-button-handle-symbol (url)
6105 "Display help on variable or function.
6106 Calls `describe-variable' or `describe-function'."
6107 (let ((sym (intern url)))
6108 (cond
6109 ((fboundp sym) (describe-function sym))
6110 ((boundp sym) (describe-variable sym))
6111 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6113 (defun gnus-button-handle-describe-key (url)
6114 "Call `describe-key' when pushing the corresponding URL button."
6115 (let* ((key-string
6116 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6117 (keys (ignore-errors (eval `(kbd ,key-string)))))
6118 (if keys
6119 (describe-key keys)
6120 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6122 (defun gnus-button-handle-apropos (url)
6123 "Call `apropos' when pushing the corresponding URL button."
6124 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6126 (defun gnus-button-handle-apropos-command (url)
6127 "Call `apropos' when pushing the corresponding URL button."
6128 (apropos-command
6129 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6131 (defun gnus-button-handle-apropos-variable (url)
6132 "Call `apropos' when pushing the corresponding URL button."
6133 (funcall
6134 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6135 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6137 (defun gnus-button-handle-apropos-documentation (url)
6138 "Call `apropos' when pushing the corresponding URL button."
6139 (funcall
6140 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6141 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6143 (defun gnus-button-handle-library (url)
6144 "Call `locate-library' when pushing the corresponding URL button."
6145 (gnus-message 9 "url=`%s'" url)
6146 (let* ((lib (locate-library url))
6147 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6148 (if (not lib)
6149 (gnus-message 1 "Cannot locale library `%s'." url)
6150 (find-file-read-only file))))
6152 (defun gnus-button-handle-ctan (url)
6153 "Call `browse-url' when pushing a CTAN URL button."
6154 (funcall
6155 gnus-button-ctan-handler
6156 (concat
6157 gnus-ctan-url
6158 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6160 (defcustom gnus-button-tex-level 5
6161 "*Integer that says how many TeX-related buttons Gnus will show.
6162 The higher the number, the more buttons will appear and the more false
6163 positives are possible. Note that you can set this variable local to
6164 specific groups. Setting it higher in TeX groups is probably a good idea.
6165 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6166 how to set variables in specific groups."
6167 :version "22.1"
6168 :group 'gnus-article-buttons
6169 :link '(custom-manual "(gnus)Group Parameters")
6170 :type 'integer)
6172 (defcustom gnus-button-man-level 5
6173 "*Integer that says how many man-related buttons Gnus will show.
6174 The higher the number, the more buttons will appear and the more false
6175 positives are possible. Note that you can set this variable local to
6176 specific groups. Setting it higher in Unix groups is probably a good idea.
6177 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6178 how to set variables in specific groups."
6179 :version "22.1"
6180 :group 'gnus-article-buttons
6181 :link '(custom-manual "(gnus)Group Parameters")
6182 :type 'integer)
6184 (defcustom gnus-button-emacs-level 5
6185 "*Integer that says how many emacs-related buttons Gnus will show.
6186 The higher the number, the more buttons will appear and the more false
6187 positives are possible. Note that you can set this variable local to
6188 specific groups. Setting it higher in Emacs or Gnus related groups is
6189 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6190 `gnus-parameters' on how to set variables in specific groups."
6191 :version "22.1"
6192 :group 'gnus-article-buttons
6193 :link '(custom-manual "(gnus)Group Parameters")
6194 :type 'integer)
6196 (defcustom gnus-button-message-level 5
6197 "*Integer that says how many buttons for news or mail messages will appear.
6198 The higher the number, the more buttons will appear and the more false
6199 positives are possible."
6200 ;; mail addresses, MIDs, URLs for news, ...
6201 :version "22.1"
6202 :group 'gnus-article-buttons
6203 :type 'integer)
6205 (defcustom gnus-button-browse-level 5
6206 "*Integer that says how many buttons for browsing will appear.
6207 The higher the number, the more buttons will appear and the more false
6208 positives are possible."
6209 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6210 :version "22.1"
6211 :group 'gnus-article-buttons
6212 :type 'integer)
6214 (defcustom gnus-button-alist
6215 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6216 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6217 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6218 gnus-button-handle-news 2)
6219 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6220 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6221 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6222 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6223 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6224 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6225 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6226 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6227 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6228 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6229 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6230 ;; RFC 2368 (The mailto URL scheme)
6231 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6232 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6233 ("\\bmailto:\\([^ \n\t]+\\)"
6234 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6235 ;; CTAN
6236 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6237 gnus-button-ctan-directory-regexp
6238 "[^][>)!;:,'\n\t ]+\\)")
6239 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6240 ((concat "\\btex-archive/\\("
6241 gnus-button-ctan-directory-regexp
6242 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6243 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6244 ((concat
6245 "\\b\\("
6246 gnus-button-ctan-directory-regexp
6247 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6248 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6249 ;; This is info (home-grown style) <info://foo/bar+baz>
6250 ("\\binfo://\\([^'\">\n\t ]+\\)"
6251 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6252 ;; Info GNOME style <info:foo#bar_baz>
6253 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6254 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6255 ;; Info KDE style <info:(foo)bar baz>
6256 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6257 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6258 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6259 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6260 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6261 ;; Info links like `C-h i d m CC Mode RET'
6262 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6263 ;; This is custom
6264 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6265 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6266 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6267 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6268 ;; Emacs help commands
6269 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6270 ;; regexp doesn't match arguments containing ` '.
6271 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6272 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6273 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6274 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6275 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6276 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6277 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6278 ;; The following entries may lead to many false positives so don't enable
6279 ;; them by default (use a high button level).
6280 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6281 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6282 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6283 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6284 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6285 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6286 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6287 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6288 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6289 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6290 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6291 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6292 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6293 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6294 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6295 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6296 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6297 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6298 ;; Unlike the other regexps we really have to require quoting
6299 ;; here to determine where it ends.
6300 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6301 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6302 ("<URL: *\\([^<>]*\\)>"
6303 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6304 ;; RFC 2396 (2.4.3., delims) ...
6305 ("\"URL: *\\([^\"]*\\)\""
6306 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6307 ;; RFC 2396 (2.4.3., delims) ...
6308 ("\"URL: *\\([^\"]*\\)\""
6309 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6310 ;; Raw URLs.
6311 (gnus-button-url-regexp
6312 0 (>= gnus-button-browse-level 0) browse-url 0)
6313 ;; man pages
6314 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6315 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6316 gnus-button-handle-man 1)
6317 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6318 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6319 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6320 gnus-button-handle-man 1)
6321 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6322 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6323 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6324 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6325 ;; MID or mail: To avoid too many false positives we don't try to catch
6326 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6327 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6328 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6329 ;; so that non-ambiguous entries (see above) match first.
6330 (gnus-button-mid-or-mail-regexp
6331 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6332 "*Alist of regexps matching buttons in article bodies.
6334 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6335 REGEXP: is the string (case insensitive) matching text around the button (can
6336 also be Lisp expression evaluating to a string),
6337 BUTTON: is the number of the regexp grouping actually matching the button,
6338 FORM: is a Lisp expression which must eval to true for the button to
6339 be added,
6340 CALLBACK: is the function to call when the user push this button, and each
6341 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6343 CALLBACK can also be a variable, in that case the value of that
6344 variable it the real callback function."
6345 :group 'gnus-article-buttons
6346 :type '(repeat (list (choice regexp variable sexp)
6347 (integer :tag "Button")
6348 (sexp :tag "Form")
6349 (function :tag "Callback")
6350 (repeat :tag "Par"
6351 :inline t
6352 (integer :tag "Regexp group")))))
6354 (defcustom gnus-header-button-alist
6355 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6356 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6357 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6358 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6359 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6360 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6361 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6362 0 (>= gnus-button-browse-level 0) browse-url 0)
6363 ("^Subject:" gnus-button-url-regexp
6364 0 (>= gnus-button-browse-level 0) browse-url 0)
6365 ("^[^:]+:" gnus-button-url-regexp
6366 0 (>= gnus-button-browse-level 0) browse-url 0)
6367 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6368 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6369 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6370 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6371 "*Alist of headers and regexps to match buttons in article heads.
6373 This alist is very similar to `gnus-button-alist', except that each
6374 alist has an additional HEADER element first in each entry:
6376 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6378 HEADER is a regexp to match a header. For a fuller explanation, see
6379 `gnus-button-alist'."
6380 :group 'gnus-article-buttons
6381 :group 'gnus-article-headers
6382 :type '(repeat (list (regexp :tag "Header")
6383 (choice regexp variable)
6384 (integer :tag "Button")
6385 (sexp :tag "Form")
6386 (function :tag "Callback")
6387 (repeat :tag "Par"
6388 :inline t
6389 (integer :tag "Regexp group")))))
6391 (defvar gnus-button-regexp nil)
6392 (defvar gnus-button-marker-list nil)
6393 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6395 (defvar gnus-button-last nil)
6396 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6398 ;;; Commands:
6400 (defun gnus-article-push-button (event)
6401 "Check text under the mouse pointer for a callback function.
6402 If the text under the mouse pointer has a `gnus-callback' property,
6403 call it with the value of the `gnus-data' text property."
6404 (interactive "e")
6405 (set-buffer (window-buffer (posn-window (event-start event))))
6406 (let* ((pos (posn-point (event-start event)))
6407 (data (get-text-property pos 'gnus-data))
6408 (fun (get-text-property pos 'gnus-callback)))
6409 (goto-char pos)
6410 (when fun
6411 (funcall fun data))))
6413 (defun gnus-article-press-button ()
6414 "Check text at point for a callback function.
6415 If the text at point has a `gnus-callback' property,
6416 call it with the value of the `gnus-data' text property."
6417 (interactive)
6418 (let ((data (get-text-property (point) 'gnus-data))
6419 (fun (get-text-property (point) 'gnus-callback)))
6420 (when fun
6421 (funcall fun data))))
6423 (defun gnus-article-highlight (&optional force)
6424 "Highlight current article.
6425 This function calls `gnus-article-highlight-headers',
6426 `gnus-article-highlight-citation',
6427 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6428 do the highlighting. See the documentation for those functions."
6429 (interactive (list 'force))
6430 (gnus-article-highlight-headers)
6431 (gnus-article-highlight-citation force)
6432 (gnus-article-highlight-signature)
6433 (gnus-article-add-buttons force)
6434 (gnus-article-add-buttons-to-head))
6436 (defun gnus-article-highlight-some (&optional force)
6437 "Highlight current article.
6438 This function calls `gnus-article-highlight-headers',
6439 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6440 do the highlighting. See the documentation for those functions."
6441 (interactive (list 'force))
6442 (gnus-article-highlight-headers)
6443 (gnus-article-highlight-signature)
6444 (gnus-article-add-buttons))
6446 (defun gnus-article-highlight-headers ()
6447 "Highlight article headers as specified by `gnus-header-face-alist'."
6448 (interactive)
6449 (save-excursion
6450 (set-buffer gnus-article-buffer)
6451 (save-restriction
6452 (let ((alist gnus-header-face-alist)
6453 (inhibit-read-only t)
6454 (case-fold-search t)
6455 (inhibit-point-motion-hooks t)
6456 entry regexp header-face field-face from hpoints fpoints)
6457 (article-narrow-to-head)
6458 (while (setq entry (pop alist))
6459 (goto-char (point-min))
6460 (setq regexp (concat "^\\("
6461 (if (string-equal "" (nth 0 entry))
6462 "[^\t ]"
6463 (nth 0 entry))
6464 "\\)")
6465 header-face (nth 1 entry)
6466 field-face (nth 2 entry))
6467 (while (and (re-search-forward regexp nil t)
6468 (not (eobp)))
6469 (beginning-of-line)
6470 (setq from (point))
6471 (unless (search-forward ":" nil t)
6472 (forward-char 1))
6473 (when (and header-face
6474 (not (memq (point) hpoints)))
6475 (push (point) hpoints)
6476 (gnus-put-text-property from (point) 'face header-face))
6477 (when (and field-face
6478 (not (memq (setq from (point)) fpoints)))
6479 (push from fpoints)
6480 (if (re-search-forward "^[^ \t]" nil t)
6481 (forward-char -2)
6482 (goto-char (point-max)))
6483 (gnus-put-text-property from (point) 'face field-face))))))))
6485 (defun gnus-article-highlight-signature ()
6486 "Highlight the signature in an article.
6487 It does this by highlighting everything after
6488 `gnus-signature-separator' using `gnus-signature-face'."
6489 (interactive)
6490 (save-excursion
6491 (set-buffer gnus-article-buffer)
6492 (let ((inhibit-read-only t)
6493 (inhibit-point-motion-hooks t))
6494 (save-restriction
6495 (when (and gnus-signature-face
6496 (gnus-article-narrow-to-signature))
6497 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6498 'face gnus-signature-face)
6499 (widen)
6500 (gnus-article-search-signature)
6501 (let ((start (match-beginning 0))
6502 (end (set-marker (make-marker) (1+ (match-end 0)))))
6503 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6504 end)))))))
6506 (defun gnus-button-in-region-p (b e prop)
6507 "Say whether PROP exists in the region."
6508 (text-property-not-all b e prop nil))
6510 (defun gnus-article-add-buttons (&optional force)
6511 "Find external references in the article and make buttons of them.
6512 \"External references\" are things like Message-IDs and URLs, as
6513 specified by `gnus-button-alist'."
6514 (interactive (list 'force))
6515 (save-excursion
6516 (set-buffer gnus-article-buffer)
6517 (let ((inhibit-read-only t)
6518 (inhibit-point-motion-hooks t)
6519 (case-fold-search t)
6520 (alist gnus-button-alist)
6521 beg entry regexp)
6522 ;; Remove all old markers.
6523 (let (marker entry new-list)
6524 (while (setq marker (pop gnus-button-marker-list))
6525 (if (or (< marker (point-min)) (>= marker (point-max)))
6526 (push marker new-list)
6527 (goto-char marker)
6528 (when (setq entry (gnus-button-entry))
6529 (put-text-property (match-beginning (nth 1 entry))
6530 (match-end (nth 1 entry))
6531 'gnus-callback nil))
6532 (set-marker marker nil)))
6533 (setq gnus-button-marker-list new-list))
6534 ;; We skip the headers.
6535 (article-goto-body)
6536 (setq beg (point))
6537 (while (setq entry (pop alist))
6538 (setq regexp (eval (car entry)))
6539 (goto-char beg)
6540 (while (re-search-forward regexp nil t)
6541 (let* ((start (and entry (match-beginning (nth 1 entry))))
6542 (end (and entry (match-end (nth 1 entry))))
6543 (from (match-beginning 0)))
6544 (when (and (or (eq t (nth 2 entry))
6545 (eval (nth 2 entry)))
6546 (not (gnus-button-in-region-p
6547 start end 'gnus-callback)))
6548 ;; That optional form returned non-nil, so we add the
6549 ;; button.
6550 (gnus-article-add-button
6551 start end 'gnus-button-push
6552 (car (push (set-marker (make-marker) from)
6553 gnus-button-marker-list))))))))))
6555 ;; Add buttons to the head of an article.
6556 (defun gnus-article-add-buttons-to-head ()
6557 "Add buttons to the head of the article."
6558 (interactive)
6559 (save-excursion
6560 (set-buffer gnus-article-buffer)
6561 (save-restriction
6562 (let ((inhibit-read-only t)
6563 (inhibit-point-motion-hooks t)
6564 (case-fold-search t)
6565 (alist gnus-header-button-alist)
6566 entry beg end)
6567 (article-narrow-to-head)
6568 (while alist
6569 ;; Each alist entry.
6570 (setq entry (car alist)
6571 alist (cdr alist))
6572 (goto-char (point-min))
6573 (while (re-search-forward (car entry) nil t)
6574 ;; Each header matching the entry.
6575 (setq beg (match-beginning 0))
6576 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6577 (match-beginning 0))
6578 (point-max)))
6579 (goto-char beg)
6580 (while (re-search-forward (eval (nth 1 entry)) end t)
6581 ;; Each match within a header.
6582 (let* ((entry (cdr entry))
6583 (start (match-beginning (nth 1 entry)))
6584 (end (match-end (nth 1 entry)))
6585 (form (nth 2 entry)))
6586 (goto-char (match-end 0))
6587 (when (eval form)
6588 (gnus-article-add-button
6589 start end (nth 3 entry)
6590 (buffer-substring (match-beginning (nth 4 entry))
6591 (match-end (nth 4 entry)))))))
6592 (goto-char end)))))))
6594 ;;; External functions:
6596 (defun gnus-article-add-button (from to fun &optional data)
6597 "Create a button between FROM and TO with callback FUN and data DATA."
6598 (when gnus-article-button-face
6599 (gnus-overlay-put (gnus-make-overlay from to)
6600 'face gnus-article-button-face))
6601 (gnus-add-text-properties
6602 from to
6603 (nconc (and gnus-article-mouse-face
6604 (list gnus-mouse-face-prop gnus-article-mouse-face))
6605 (list 'gnus-callback fun)
6606 (and data (list 'gnus-data data))))
6607 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6608 :button-keymap gnus-widget-button-keymap))
6610 ;;; Internal functions:
6612 (defun gnus-article-set-globals ()
6613 (save-excursion
6614 (set-buffer gnus-summary-buffer)
6615 (gnus-set-global-variables)))
6617 (defun gnus-signature-toggle (end)
6618 (save-excursion
6619 (set-buffer gnus-article-buffer)
6620 (let ((inhibit-read-only t)
6621 (inhibit-point-motion-hooks t))
6622 (if (text-property-any end (point-max) 'article-type 'signature)
6623 (progn
6624 (gnus-delete-wash-type 'signature)
6625 (gnus-remove-text-properties-when
6626 'article-type 'signature end (point-max)
6627 (cons 'article-type (cons 'signature
6628 gnus-hidden-properties))))
6629 (gnus-add-wash-type 'signature)
6630 (gnus-add-text-properties-when
6631 'article-type nil end (point-max)
6632 (cons 'article-type (cons 'signature
6633 gnus-hidden-properties)))))
6634 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6635 (gnus-set-mode-line 'article))))
6637 (defun gnus-button-entry ()
6638 ;; Return the first entry in `gnus-button-alist' matching this place.
6639 (let ((alist gnus-button-alist)
6640 (entry nil))
6641 (while alist
6642 (setq entry (pop alist))
6643 (if (looking-at (eval (car entry)))
6644 (setq alist nil)
6645 (setq entry nil)))
6646 entry))
6648 (defun gnus-button-push (marker)
6649 ;; Push button starting at MARKER.
6650 (save-excursion
6651 (goto-char marker)
6652 (let* ((entry (gnus-button-entry))
6653 (inhibit-point-motion-hooks t)
6654 (fun (nth 3 entry))
6655 (args (mapcar (lambda (group)
6656 (let ((string (match-string group)))
6657 (gnus-set-text-properties
6658 0 (length string) nil string)
6659 string))
6660 (nthcdr 4 entry))))
6661 (cond
6662 ((fboundp fun)
6663 (apply fun args))
6664 ((and (boundp fun)
6665 (fboundp (symbol-value fun)))
6666 (apply (symbol-value fun) args))
6668 (gnus-message 1 "You must define `%S' to use this button"
6669 (cons fun args)))))))
6671 (defun gnus-parse-news-url (url)
6672 (let (scheme server port group message-id articles)
6673 (with-temp-buffer
6674 (insert url)
6675 (goto-char (point-min))
6676 (when (looking-at "\\([A-Za-z]+\\):")
6677 (setq scheme (match-string 1))
6678 (goto-char (match-end 0)))
6679 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
6680 (setq server (match-string 1))
6681 (setq port (if (stringp (match-string 3))
6682 (string-to-number (match-string 3))
6683 (match-string 3)))
6684 (goto-char (match-end 0)))
6686 (cond
6687 ((looking-at "\\(.*@.*\\)")
6688 (setq message-id (match-string 1)))
6689 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6690 (setq group (match-string 1)
6691 articles (split-string (match-string 2) "-")))
6692 ((looking-at "\\([^/]+\\)/?")
6693 (setq group (match-string 1)))
6695 (error "Unknown news URL syntax"))))
6696 (list scheme server port group message-id articles)))
6698 (defun gnus-button-handle-news (url)
6699 "Fetch a news URL."
6700 (destructuring-bind (scheme server port group message-id articles)
6701 (gnus-parse-news-url url)
6702 (cond
6703 (message-id
6704 (save-excursion
6705 (set-buffer gnus-summary-buffer)
6706 (if server
6707 (let ((gnus-refer-article-method
6708 (nconc (list (list 'nntp server))
6709 gnus-refer-article-method))
6710 (nntp-port-number (or port "nntp")))
6711 (gnus-message 7 "Fetching %s with %s"
6712 message-id gnus-refer-article-method)
6713 (gnus-summary-refer-article message-id))
6714 (gnus-summary-refer-article message-id))))
6715 (group
6716 (gnus-button-fetch-group url)))))
6718 (defun gnus-button-handle-man (url)
6719 "Fetch a man page."
6720 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6721 (when (eq gnus-button-man-handler 'woman)
6722 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6723 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6724 (funcall gnus-button-man-handler url))
6726 (defun gnus-button-handle-info-url (url)
6727 "Fetch an info URL."
6728 (setq url (mm-subst-char-in-string ?+ ?\ url))
6729 (cond
6730 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6731 (gnus-info-find-node
6732 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6733 "Gnus")
6734 ")" (gnus-url-unhex-string (match-string 2 url)))))
6735 ((string-match "([^)\"]+)[^\"]+" url)
6736 (setq url
6737 (gnus-replace-in-string
6738 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6739 (gnus-info-find-node url))
6740 (t (error "Can't parse %s" url))))
6742 (defun gnus-button-handle-info-url-gnome (url)
6743 "Fetch GNOME style info URL."
6744 (setq url (mm-subst-char-in-string ?_ ?\ url))
6745 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6746 (gnus-info-find-node
6747 (concat "("
6748 (gnus-url-unhex-string
6749 (match-string 1 url))
6751 (or (gnus-url-unhex-string
6752 (match-string 2 url))
6753 "Top")))
6754 (error "Can't parse %s" url)))
6756 (defun gnus-button-handle-info-url-kde (url)
6757 "Fetch KDE style info URL."
6758 (gnus-info-find-node (gnus-url-unhex-string url)))
6760 (defun gnus-button-handle-info-keystrokes (url)
6761 "Call `info' when pushing the corresponding URL button."
6762 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6763 (info)
6764 (Info-directory)
6765 (Info-menu url))
6767 (defun gnus-button-message-id (message-id)
6768 "Fetch MESSAGE-ID."
6769 (save-excursion
6770 (set-buffer gnus-summary-buffer)
6771 (gnus-summary-refer-article message-id)))
6773 (defun gnus-button-fetch-group (address)
6774 "Fetch GROUP specified by ADDRESS."
6775 (if (not (string-match "[:/]" address))
6776 ;; This is just a simple group url.
6777 (gnus-group-read-ephemeral-group address gnus-select-method)
6778 (if (not
6779 (string-match
6780 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6781 address))
6782 (error "Can't parse %s" address)
6783 (gnus-group-read-ephemeral-group
6784 (match-string 4 address)
6785 `(nntp ,(match-string 1 address)
6786 (nntp-address ,(match-string 1 address))
6787 (nntp-port-number ,(if (match-end 3)
6788 (match-string 3 address)
6789 "nntp")))
6790 nil nil nil
6791 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
6793 (defun gnus-url-parse-query-string (query &optional downcase)
6794 (let (retval pairs cur key val)
6795 (setq pairs (split-string query "&"))
6796 (while pairs
6797 (setq cur (car pairs)
6798 pairs (cdr pairs))
6799 (if (not (string-match "=" cur))
6800 nil ; Grace
6801 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6802 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6803 (if downcase
6804 (setq key (downcase key)))
6805 (setq cur (assoc key retval))
6806 (if cur
6807 (setcdr cur (cons val (cdr cur)))
6808 (setq retval (cons (list key val) retval)))))
6809 retval))
6811 (defun gnus-url-mailto (url)
6812 ;; Send mail to someone
6813 (when (string-match "mailto:/*\\(.*\\)" url)
6814 (setq url (substring url (match-beginning 1) nil)))
6815 (let (to args subject func)
6816 (setq args (gnus-url-parse-query-string
6817 (if (string-match "^\\?" url)
6818 (substring url 1)
6819 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
6820 (concat "to=" (match-string 1 url) "&"
6821 (match-string 2 url))
6822 (concat "to=" url)))
6824 subject (cdr-safe (assoc "subject" args)))
6825 (gnus-msg-mail)
6826 (while args
6827 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6828 (if (fboundp func)
6829 (funcall func)
6830 (message-position-on-field (caar args)))
6831 (insert (gnus-replace-in-string
6832 (mapconcat 'identity (reverse (cdar args)) ", ")
6833 "\r\n" "\n" t))
6834 (setq args (cdr args)))
6835 (if subject
6836 (message-goto-body)
6837 (message-goto-subject))))
6839 (defun gnus-button-embedded-url (address)
6840 "Activate ADDRESS with `browse-url'."
6841 (browse-url (gnus-strip-whitespace address)))
6843 ;;; Next/prev buttons in the article buffer.
6845 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6846 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6848 (defvar gnus-prev-page-map
6849 (let ((map (make-sparse-keymap)))
6850 (unless (>= emacs-major-version 21)
6851 ;; XEmacs doesn't care.
6852 (set-keymap-parent map gnus-article-mode-map))
6853 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6854 (define-key map "\r" 'gnus-button-prev-page)
6855 map))
6857 (defvar gnus-next-page-map
6858 (let ((map (make-sparse-keymap)))
6859 (unless (>= emacs-major-version 21)
6860 ;; XEmacs doesn't care.
6861 (set-keymap-parent map gnus-article-mode-map))
6862 (define-key map gnus-mouse-2 'gnus-button-next-page)
6863 (define-key map "\r" 'gnus-button-next-page)
6864 map))
6866 (defun gnus-insert-prev-page-button ()
6867 (let ((b (point))
6868 (inhibit-read-only t))
6869 (gnus-eval-format
6870 gnus-prev-page-line-format nil
6871 `(,@(gnus-local-map-property gnus-prev-page-map)
6872 gnus-prev t
6873 gnus-callback gnus-article-button-prev-page
6874 article-type annotation))
6875 (widget-convert-button
6876 'link b (if (bolp)
6877 ;; Exclude a newline.
6878 (1- (point))
6879 (point))
6880 :action 'gnus-button-prev-page
6881 :button-keymap gnus-prev-page-map)))
6883 (defun gnus-button-next-page (&optional args more-args)
6884 "Go to the next page."
6885 (interactive)
6886 (let ((win (selected-window)))
6887 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6888 (gnus-article-next-page)
6889 (select-window win)))
6891 (defun gnus-button-prev-page (&optional args more-args)
6892 "Go to the prev page."
6893 (interactive)
6894 (let ((win (selected-window)))
6895 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6896 (gnus-article-prev-page)
6897 (select-window win)))
6899 (defun gnus-insert-next-page-button ()
6900 (let ((b (point))
6901 (inhibit-read-only t))
6902 (gnus-eval-format gnus-next-page-line-format nil
6903 `(,@(gnus-local-map-property gnus-next-page-map)
6904 gnus-next t
6905 gnus-callback gnus-article-button-next-page
6906 article-type annotation))
6907 (widget-convert-button
6908 'link b (if (bolp)
6909 ;; Exclude a newline.
6910 (1- (point))
6911 (point))
6912 :action 'gnus-button-next-page
6913 :button-keymap gnus-next-page-map)))
6915 (defun gnus-article-button-next-page (arg)
6916 "Go to the next page."
6917 (interactive "P")
6918 (let ((win (selected-window)))
6919 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6920 (gnus-article-next-page)
6921 (select-window win)))
6923 (defun gnus-article-button-prev-page (arg)
6924 "Go to the prev page."
6925 (interactive "P")
6926 (let ((win (selected-window)))
6927 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6928 (gnus-article-prev-page)
6929 (select-window win)))
6931 (defvar gnus-decode-header-methods
6932 '(mail-decode-encoded-word-region)
6933 "List of methods used to decode headers.
6935 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6936 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
6937 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
6938 whose names match REGEXP.
6940 For example:
6941 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6942 mail-decode-encoded-word-region
6943 (\"chinese\" . rfc1843-decode-region))
6946 (defvar gnus-decode-header-methods-cache nil)
6948 (defun gnus-multi-decode-header (start end)
6949 "Apply the functions from `gnus-encoded-word-methods' that match."
6950 (unless (and gnus-decode-header-methods-cache
6951 (eq gnus-newsgroup-name
6952 (car gnus-decode-header-methods-cache)))
6953 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6954 (mapcar (lambda (x)
6955 (if (symbolp x)
6956 (nconc gnus-decode-header-methods-cache (list x))
6957 (if (and gnus-newsgroup-name
6958 (string-match (car x) gnus-newsgroup-name))
6959 (nconc gnus-decode-header-methods-cache
6960 (list (cdr x))))))
6961 gnus-decode-header-methods))
6962 (let ((xlist gnus-decode-header-methods-cache))
6963 (pop xlist)
6964 (save-restriction
6965 (narrow-to-region start end)
6966 (while xlist
6967 (funcall (pop xlist) (point-min) (point-max))))))
6970 ;;; Treatment top-level handling.
6973 (defun gnus-treat-article (condition &optional part-number total-parts type)
6974 (let ((length (- (point-max) (point-min)))
6975 (alist gnus-treatment-function-alist)
6976 (article-goto-body-goes-to-point-min-p t)
6977 (treated-type
6978 (or (not type)
6979 (catch 'found
6980 (let ((list gnus-article-treat-types))
6981 (while list
6982 (when (string-match (pop list) type)
6983 (throw 'found t)))))))
6984 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6985 val elem)
6986 (gnus-run-hooks 'gnus-part-display-hook)
6987 (dolist (elem alist)
6988 (setq val
6989 (save-excursion
6990 (when (gnus-buffer-live-p gnus-summary-buffer)
6991 (set-buffer gnus-summary-buffer))
6992 (symbol-value (car elem))))
6993 (when (and (or (consp val)
6994 treated-type)
6995 (gnus-treat-predicate val)
6996 (or (not (get (car elem) 'highlight))
6997 highlightp))
6998 (save-restriction
6999 (funcall (cadr elem)))))))
7001 ;; Dynamic variables.
7002 (eval-when-compile
7003 (defvar part-number)
7004 (defvar total-parts)
7005 (defvar type)
7006 (defvar condition)
7007 (defvar length))
7009 (defun gnus-treat-predicate (val)
7010 (cond
7011 ((null val)
7012 nil)
7013 (condition
7014 (eq condition val))
7015 ((and (listp val)
7016 (stringp (car val)))
7017 (apply 'gnus-or (mapcar `(lambda (s)
7018 (string-match s ,(or gnus-newsgroup-name "")))
7019 val)))
7020 ((listp val)
7021 (let ((pred (pop val)))
7022 (cond
7023 ((eq pred 'or)
7024 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7025 ((eq pred 'and)
7026 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7027 ((eq pred 'not)
7028 (not (gnus-treat-predicate (car val))))
7029 ((eq pred 'typep)
7030 (equal (car val) type))
7032 (error "%S is not a valid predicate" pred)))))
7033 ((eq val t)
7035 ((eq val 'head)
7036 nil)
7037 ((eq val 'last)
7038 (eq part-number total-parts))
7039 ((numberp val)
7040 (< length val))
7042 (error "%S is not a valid value" val))))
7044 (defun gnus-article-encrypt-body (protocol &optional n)
7045 "Encrypt the article body."
7046 (interactive
7047 (list
7048 (or gnus-article-encrypt-protocol
7049 (completing-read "Encrypt protocol: "
7050 gnus-article-encrypt-protocol-alist
7051 nil t))
7052 current-prefix-arg))
7053 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7054 (unless func
7055 (error (format "Can't find the encrypt protocol %s" protocol)))
7056 (if (member gnus-newsgroup-name '("nndraft:delayed"
7057 "nndraft:drafts"
7058 "nndraft:queue"))
7059 (error "Can't encrypt the article in group %s"
7060 gnus-newsgroup-name))
7061 (gnus-summary-iterate n
7062 (save-excursion
7063 (set-buffer gnus-summary-buffer)
7064 (let ((mail-parse-charset gnus-newsgroup-charset)
7065 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7066 (summary-buffer gnus-summary-buffer)
7067 references point)
7068 (gnus-set-global-variables)
7069 (when (gnus-group-read-only-p)
7070 (error "The current newsgroup does not support article encrypt"))
7071 (gnus-summary-show-article t)
7072 (setq references
7073 (or (mail-header-references gnus-current-headers) ""))
7074 (set-buffer gnus-article-buffer)
7075 (let* ((inhibit-read-only t)
7076 (headers
7077 (mapcar (lambda (field)
7078 (and (save-restriction
7079 (message-narrow-to-head)
7080 (goto-char (point-min))
7081 (search-forward field nil t))
7082 (prog2
7083 (message-narrow-to-field)
7084 (buffer-string)
7085 (delete-region (point-min) (point-max))
7086 (widen))))
7087 '("Content-Type:" "Content-Transfer-Encoding:"
7088 "Content-Disposition:"))))
7089 (message-narrow-to-head)
7090 (message-remove-header "MIME-Version")
7091 (goto-char (point-max))
7092 (setq point (point))
7093 (insert (apply 'concat headers))
7094 (widen)
7095 (narrow-to-region point (point-max))
7096 (let ((message-options message-options))
7097 (message-options-set 'message-sender user-mail-address)
7098 (message-options-set 'message-recipients user-mail-address)
7099 (message-options-set 'message-sign-encrypt 'not)
7100 (funcall func))
7101 (goto-char (point-min))
7102 (insert "MIME-Version: 1.0\n")
7103 (widen)
7104 (gnus-summary-edit-article-done
7105 references nil summary-buffer t))
7106 (when gnus-keep-backlog
7107 (gnus-backlog-remove-article
7108 (car gnus-article-current) (cdr gnus-article-current)))
7109 (save-excursion
7110 (when (get-buffer gnus-original-article-buffer)
7111 (set-buffer gnus-original-article-buffer)
7112 (setq gnus-original-article nil)))
7113 (when gnus-use-cache
7114 (gnus-cache-update-article
7115 (car gnus-article-current) (cdr gnus-article-current))))))))
7117 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7118 "The following specs can be used:
7119 %t The security MIME type
7120 %i Additional info
7121 %d Details
7122 %D Details if button is pressed")
7124 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7125 "The following specs can be used:
7126 %t The security MIME type
7127 %i Additional info
7128 %d Details
7129 %D Details if button is pressed")
7131 (defvar gnus-mime-security-button-line-format-alist
7132 '((?t gnus-tmp-type ?s)
7133 (?i gnus-tmp-info ?s)
7134 (?d gnus-tmp-details ?s)
7135 (?D gnus-tmp-pressed-details ?s)))
7137 (defvar gnus-mime-security-button-map
7138 (let ((map (make-sparse-keymap)))
7139 (unless (>= (string-to-number emacs-version) 21)
7140 (set-keymap-parent map gnus-article-mode-map))
7141 (define-key map gnus-mouse-2 'gnus-article-push-button)
7142 (define-key map "\r" 'gnus-article-press-button)
7143 map))
7145 (defvar gnus-mime-security-details-buffer nil)
7147 (defvar gnus-mime-security-button-pressed nil)
7149 (defvar gnus-mime-security-show-details-inline t
7150 "If non-nil, show details in the article buffer.")
7152 (defun gnus-mime-security-verify-or-decrypt (handle)
7153 (mm-remove-parts (cdr handle))
7154 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7155 point (inhibit-read-only t))
7156 (if region
7157 (goto-char (car region)))
7158 (save-restriction
7159 (narrow-to-region (point) (point))
7160 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7161 (let* ((mm-verify-option 'known)
7162 (mm-decrypt-option 'known)
7163 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7164 (unless (eq nparts (cdr handle))
7165 (mm-destroy-parts (cdr handle))
7166 (setcdr handle nparts))))
7167 (setq point (point))
7168 (gnus-mime-display-security handle)
7169 (goto-char (point-max)))
7170 (when region
7171 (delete-region (point) (cdr region))
7172 (set-marker (car region) nil)
7173 (set-marker (cdr region) nil))
7174 (goto-char point)))
7176 (defun gnus-mime-security-show-details (handle)
7177 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7178 (if (not details)
7179 (gnus-message 5 "No details.")
7180 (if gnus-mime-security-show-details-inline
7181 (let ((gnus-mime-security-button-pressed
7182 (not (get-text-property (point) 'gnus-mime-details)))
7183 (gnus-mime-security-button-line-format
7184 (get-text-property (point) 'gnus-line-format))
7185 (inhibit-read-only t))
7186 (forward-char -1)
7187 (while (eq (get-text-property (point) 'gnus-line-format)
7188 gnus-mime-security-button-line-format)
7189 (forward-char -1))
7190 (forward-char)
7191 (save-restriction
7192 (narrow-to-region (point) (point))
7193 (gnus-insert-mime-security-button handle))
7194 (delete-region (point)
7195 (or (text-property-not-all
7196 (point) (point-max)
7197 'gnus-line-format
7198 gnus-mime-security-button-line-format)
7199 (point-max))))
7200 ;; Not inlined.
7201 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7202 (with-current-buffer gnus-mime-security-details-buffer
7203 (erase-buffer)
7205 (setq gnus-mime-security-details-buffer
7206 (gnus-get-buffer-create "*MIME Security Details*")))
7207 (with-current-buffer gnus-mime-security-details-buffer
7208 (insert details)
7209 (goto-char (point-min)))
7210 (pop-to-buffer gnus-mime-security-details-buffer)))))
7212 (defun gnus-mime-security-press-button (handle)
7213 (save-excursion
7214 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7215 (gnus-mime-security-show-details handle)
7216 (gnus-mime-security-verify-or-decrypt handle))))
7218 (defun gnus-insert-mime-security-button (handle &optional displayed)
7219 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7220 (gnus-tmp-type
7221 (concat
7222 (or (nth 2 (assoc protocol mm-verify-function-alist))
7223 (nth 2 (assoc protocol mm-decrypt-function-alist))
7224 "Unknown")
7225 (if (equal (car handle) "multipart/signed")
7226 " Signed" " Encrypted")
7227 " Part"))
7228 (gnus-tmp-info
7229 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7230 "Undecided"))
7231 (gnus-tmp-details
7232 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7233 gnus-tmp-pressed-details
7234 b e)
7235 (setq gnus-tmp-details
7236 (if gnus-tmp-details
7237 (concat "\n" gnus-tmp-details)
7238 ""))
7239 (setq gnus-tmp-pressed-details
7240 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7241 (unless (bolp)
7242 (insert "\n"))
7243 (setq b (point))
7244 (gnus-eval-format
7245 gnus-mime-security-button-line-format
7246 gnus-mime-security-button-line-format-alist
7247 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7248 gnus-callback gnus-mime-security-press-button
7249 gnus-line-format ,gnus-mime-security-button-line-format
7250 gnus-mime-details ,gnus-mime-security-button-pressed
7251 article-type annotation
7252 gnus-data ,handle))
7253 (setq e (if (bolp)
7254 ;; Exclude a newline.
7255 (1- (point))
7256 (point)))
7257 (widget-convert-button
7258 'link b e
7259 :mime-handle handle
7260 :action 'gnus-widget-press-button
7261 :button-keymap gnus-mime-security-button-map
7262 :help-echo
7263 (lambda (widget/window &optional overlay pos)
7264 ;; Needed to properly clear the message due to a bug in
7265 ;; wid-edit (XEmacs only).
7266 (when (boundp 'help-echo-owns-message)
7267 (setq help-echo-owns-message t))
7268 (format
7269 "%S: show detail"
7270 (aref gnus-mouse-2 0))))))
7272 (defun gnus-mime-display-security (handle)
7273 (save-restriction
7274 (narrow-to-region (point) (point))
7275 (unless (gnus-unbuttonized-mime-type-p (car handle))
7276 (gnus-insert-mime-security-button handle))
7277 (gnus-mime-display-mixed (cdr handle))
7278 (unless (bolp)
7279 (insert "\n"))
7280 (unless (gnus-unbuttonized-mime-type-p (car handle))
7281 (let ((gnus-mime-security-button-line-format
7282 gnus-mime-security-button-end-line-format))
7283 (gnus-insert-mime-security-button handle)))
7284 (mm-set-handle-multipart-parameter
7285 handle 'gnus-region
7286 (cons (set-marker (make-marker) (point-min))
7287 (set-marker (make-marker) (point-max))))))
7289 (gnus-ems-redefine)
7291 (provide 'gnus-art)
7293 (run-hooks 'gnus-art-load-hook)
7295 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7296 ;;; gnus-art.el ends here