1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
34 (defvar tool-bar-map))
46 ;; Avoid byte-compile warnings.
56 (autoload 'gnus-msg-mail "gnus-msg" nil t)
57 (autoload 'gnus-button-mailto "gnus-msg")
58 (autoload 'gnus-button-reply "gnus-msg" nil t)
60 (defgroup gnus-article nil
62 :link '(custom-manual "(gnus)The Article Buffer")
65 (defgroup gnus-article-treat nil
66 "Treating article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
70 (defgroup gnus-article-hiding nil
71 "Hiding article parts."
72 :link '(custom-manual "(gnus)Article Hiding")
75 (defgroup gnus-article-highlight nil
76 "Article highlighting."
77 :link '(custom-manual "(gnus)Article Highlighting")
81 (defgroup gnus-article-signature nil
83 :link '(custom-manual "(gnus)Article Signature")
86 (defgroup gnus-article-headers nil
88 :link '(custom-manual "(gnus)Hiding Headers")
91 (defgroup gnus-article-washing nil
92 "Special commands on articles."
93 :link '(custom-manual "(gnus)Article Washing")
96 (defgroup gnus-article-emphasis nil
97 "Fontisizing articles."
98 :link '(custom-manual "(gnus)Article Fontisizing")
101 (defgroup gnus-article-saving nil
103 :link '(custom-manual "(gnus)Saving Articles")
104 :group 'gnus-article)
106 (defgroup gnus-article-mime nil
107 "Worshiping the MIME wonder."
108 :link '(custom-manual "(gnus)Using MIME")
109 :group 'gnus-article)
111 (defgroup gnus-article-buttons nil
112 "Pushable buttons in the article buffer."
113 :link '(custom-manual "(gnus)Article Buttons")
114 :group 'gnus-article)
116 (defgroup gnus-article-various nil
117 "Other article options."
118 :link '(custom-manual "(gnus)Misc Article")
119 :group 'gnus-article)
121 (defcustom gnus-ignored-headers
124 (concat "^" header ":"))
125 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
126 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
127 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
128 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
129 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
130 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
131 "X-Attribution" "X-Originating-IP" "Delivered-To"
132 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
133 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
134 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
135 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
136 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
137 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
138 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
139 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
140 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
141 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
142 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
143 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
144 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
145 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
146 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
147 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
148 "List-[A-Za-z]+" "X-Listprocessor-Version"
149 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
150 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
151 "X-Received" "Content-length" "X-precedence"
152 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
153 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
154 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
155 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
156 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
157 "X-Content-length" "X-Posting-Agent" "Original-Received"
158 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
159 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
160 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
161 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
162 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice :custom-show nil
169 :group 'gnus-article-hiding)
171 (defcustom gnus-visible-headers
172 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
173 "*All headers that do not match this regexp will be hidden.
174 This variable can also be a list of regexp of headers to remain visible.
175 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
176 :type '(repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
180 (widget-editable-list-match widget value)))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 'empty Headers with no content.
199 'newsgroups Newsgroup identical to Gnus group.
200 'to-address To identical to To-address.
201 'to-list To identical to To-list.
202 'cc-list CC identical to To-list.
203 'followup-to Followup-to identical to Newsgroups.
204 'reply-to Reply-to identical to From.
205 'date Date less than four days old.
206 'long-to To and/or Cc longer than 1024 characters.
207 'many-to Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(repeat string)
235 :group 'gnus-article-signature)
237 (defcustom gnus-signature-limit nil
238 "Provide a limit to what is considered a signature.
239 If it is a number, no signature may not be longer (in characters) than
240 that number. If it is a floating point number, no signature may be
241 longer (in lines) than that number. If it is a function, the function
242 will be called without any parameters, and if it returns nil, there is
243 no signature in the buffer. If it is a string, it will be used as a
244 regexp. If it matches, the text in question is not a signature."
245 :type '(choice (integer :value 200)
247 (function :value fun)
248 (regexp :value ".*"))
249 :group 'gnus-article-signature)
251 (defcustom gnus-hidden-properties '(invisible t intangible t)
252 "Property list to use for hiding text."
254 :group 'gnus-article-hiding)
256 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
257 ;; frames in a session.
258 (defcustom gnus-article-x-face-command
263 (if (or (gnus-image-type-available-p 'xface)
264 (gnus-image-type-available-p 'pbm))
265 'gnus-display-x-face-in-from
266 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
267 ((and (fboundp 'image-type-available-p)
268 (module-installed-p 'x-face-e21))
269 'x-face-decode-message-header)
270 ((gnus-image-type-available-p 'pbm)
271 'gnus-display-x-face-in-from)
273 (module-installed-p 'x-face-mule))
274 'x-face-mule-gnus-article-display-x-face)
276 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
278 "*String or function to be executed to display an X-Face header.
279 If it is a string, the command will be executed in a sub-shell
280 asynchronously. The compressed face will be piped to this command."
282 ,@(let (x-face-e21 x-face-mule)
283 (if (featurep 'xemacs)
285 (setq x-face-e21 (module-installed-p 'x-face-e21)
286 x-face-mule (module-installed-p 'x-face-mule)))
290 (if (or (gnus-image-type-available-p 'xface)
291 (gnus-image-type-available-p 'pbm))
292 '(function-item gnus-display-x-face-in-from))
294 (fboundp 'image-type-available-p))
296 :tag "x-face-decode-message-header (x-face-e21)"
297 x-face-decode-message-header))
300 x-face-mule-gnus-article-display-x-face))
304 :group 'gnus-article-washing)
306 (defcustom gnus-article-x-face-too-ugly nil
307 "Regexp matching posters whose face shouldn't be shown automatically."
308 :type '(choice regexp (const nil))
309 :group 'gnus-article-washing)
311 (defcustom gnus-article-banner-alist nil
312 "Banner alist for stripping.
314 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
316 :type '(repeat (cons symbol regexp))
317 :group 'gnus-article-washing)
319 (gnus-define-group-parameter
322 "Alist of regexps (to match group names) and banner."
323 :variable-group gnus-article-washing
325 '(choice :tag "Banner"
327 (const :tag "Remove signature" signature)
328 (symbol :tag "Item in `gnus-article-banner-alist'" none)
330 (const :tag "None" nil))
332 "If non-nil, specify how to remove `banners' from articles.
334 Symbol `signature' means to remove signatures delimited by
335 `gnus-signature-separator'. Any other symbol is used to look up a
336 regular expression to match the banner in `gnus-article-banner-alist'.
337 A string is used as a regular expression to match the banner
340 (defcustom gnus-article-address-banner-alist nil
341 "Alist of mail addresses and banners.
342 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
343 to match a mail address in the From: header, BANNER is one of a symbol
344 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
345 If ADDRESS matches author's mail address, it will remove things like
346 advertisements. For example:
348 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
352 (regexp :tag "Address")
353 (choice :tag "Banner" :value nil
354 (const :tag "Remove signature" signature)
355 (symbol :tag "Item in `gnus-article-banner-alist'" none)
357 (const :tag "None" nil))))
358 :group 'gnus-article-washing)
360 (defcustom gnus-emphasis-alist
362 "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
367 ("_/" "/_" underline-italic)
368 ("_\\*" "\\*_" underline-bold)
369 ("\\*/" "/\\*" bold-italic)
370 ("_\\*/" "/\\*_" underline-bold-italic))))
374 (format format (car spec) (car (cdr spec)))
375 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
377 ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
378 2 3 gnus-emphasis-strikethru)
379 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
380 2 3 gnus-emphasis-underline)))
381 "*Alist that says how to fontify certain phrases.
382 Each item looks like this:
384 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
386 The first element is a regular expression to be matched. The second
387 is a number that says what regular expression grouping used to find
388 the entire emphasized word. The third is a number that says what
389 regexp grouping should be displayed and highlighted. The fourth
390 is the face used for highlighting."
391 :type '(repeat (list :value ("" 0 0 default)
393 (integer :tag "Match group")
394 (integer :tag "Emphasize group")
396 :group 'gnus-article-emphasis)
398 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
399 "A regexp to describe whitespace which should not be emphasized.
400 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
401 The former avoids underlining of leading and trailing whitespace,
402 and the latter avoids underlining any whitespace at all."
404 :group 'gnus-article-emphasis
407 (defface gnus-emphasis-bold '((t (:bold t)))
408 "Face used for displaying strong emphasized text (*word*)."
409 :group 'gnus-article-emphasis)
411 (defface gnus-emphasis-italic '((t (:italic t)))
412 "Face used for displaying italic emphasized text (/word/)."
413 :group 'gnus-article-emphasis)
415 (defface gnus-emphasis-underline '((t (:underline t)))
416 "Face used for displaying underlined emphasized text (_word_)."
417 :group 'gnus-article-emphasis)
419 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
420 "Face used for displaying underlined bold emphasized text (_*word*_)."
421 :group 'gnus-article-emphasis)
423 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
424 "Face used for displaying underlined italic emphasized text (_/word/_)."
425 :group 'gnus-article-emphasis)
427 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
428 "Face used for displaying bold italic emphasized text (/*word*/)."
429 :group 'gnus-article-emphasis)
431 (defface gnus-emphasis-underline-bold-italic
432 '((t (:bold t :italic t :underline t)))
433 "Face used for displaying underlined bold italic emphasized text.
434 Example: (_/*word*/_)."
435 :group 'gnus-article-emphasis)
437 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
438 '((t (:strikethru t)))
439 '((t (:strike-through t))))
440 "Face used for displaying strike-through text (-word-)."
441 :group 'gnus-article-emphasis)
443 (defface gnus-emphasis-highlight-words
444 '((t (:background "black" :foreground "yellow")))
445 "Face used for displaying highlighted words."
446 :group 'gnus-article-emphasis)
448 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
449 "Format for display of Date headers in article bodies.
450 See `format-time-string' for the possible values.
452 The variable can also be function, which should return a complete Date
453 header. The function is called with one argument, the time, which can
454 be fed to `format-time-string'."
455 :type '(choice string symbol)
456 :link '(custom-manual "(gnus)Article Date")
457 :group 'gnus-article-washing)
460 (autoload 'mail-extract-address-components "mail-extr"))
462 (defcustom gnus-save-all-headers t
463 "*If non-nil, don't remove any headers before saving."
464 :group 'gnus-article-saving
467 (defcustom gnus-prompt-before-saving 'always
468 "*This variable says how much prompting is to be done when saving articles.
469 If it is nil, no prompting will be done, and the articles will be
470 saved to the default files. If this variable is `always', each and
471 every article that is saved will be preceded by a prompt, even when
472 saving large batches of articles. If this variable is neither nil not
473 `always', there the user will be prompted once for a file name for
474 each invocation of the saving commands."
475 :group 'gnus-article-saving
476 :type '(choice (item always)
477 (item :tag "never" nil)
478 (sexp :tag "once" :format "%t\n" :value t)))
480 (defcustom gnus-saved-headers gnus-visible-headers
481 "Headers to keep if `gnus-save-all-headers' is nil.
482 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
483 If that variable is nil, however, all headers that match this regexp
484 will be kept while the rest will be deleted before saving."
485 :group 'gnus-article-saving
488 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
489 "A function to save articles in your favourite format.
490 The function must be interactively callable (in other words, it must
491 be an Emacs command).
493 Gnus provides the following functions:
495 * gnus-summary-save-in-rmail (Rmail format)
496 * gnus-summary-save-in-mail (Unix mail format)
497 * gnus-summary-save-in-folder (MH folder)
498 * gnus-summary-save-in-file (article format)
499 * gnus-summary-save-body-in-file (article body)
500 * gnus-summary-save-in-vm (use VM's folder format)
501 * gnus-summary-write-to-file (article format -- overwrite)."
502 :group 'gnus-article-saving
503 :type '(radio (function-item gnus-summary-save-in-rmail)
504 (function-item gnus-summary-save-in-mail)
505 (function-item gnus-summary-save-in-folder)
506 (function-item gnus-summary-save-in-file)
507 (function-item gnus-summary-save-body-in-file)
508 (function-item gnus-summary-save-in-vm)
509 (function-item gnus-summary-write-to-file)))
511 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
512 "A function generating a file name to save articles in Rmail format.
513 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
514 :group 'gnus-article-saving
517 (defcustom gnus-mail-save-name 'gnus-plain-save-name
518 "A function generating a file name to save articles in Unix mail format.
519 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
520 :group 'gnus-article-saving
523 (defcustom gnus-folder-save-name 'gnus-folder-save-name
524 "A function generating a file name to save articles in MH folder.
525 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
526 :group 'gnus-article-saving
529 (defcustom gnus-file-save-name 'gnus-numeric-save-name
530 "A function generating a file name to save articles in article format.
531 The function is called with NEWSGROUP, HEADERS, and optional
533 :group 'gnus-article-saving
536 (defcustom gnus-split-methods
537 '((gnus-article-archive-name)
538 (gnus-article-nndoc-name))
539 "*Variable used to suggest where articles are to be saved.
540 For instance, if you would like to save articles related to Gnus in
541 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
542 you could set this variable to something like:
544 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
545 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
547 This variable is an alist where the where the key is the match and the
548 value is a list of possible files to save in if the match is non-nil.
550 If the match is a string, it is used as a regexp match on the
551 article. If the match is a symbol, that symbol will be funcalled
552 from the buffer of the article to be saved with the newsgroup as the
553 parameter. If it is a list, it will be evaled in the same buffer.
555 If this form or function returns a string, this string will be used as
556 a possible file name; and if it returns a non-nil list, that list will
557 be used as possible file names."
558 :group 'gnus-article-saving
559 :type '(repeat (choice (list :value (fun) function)
560 (cons :value ("" "") regexp (repeat string))
563 (defcustom gnus-article-display-method-for-mime
564 'gnus-article-display-mime-message
565 "Function to display a MIME message.
566 The function is called from the article buffer."
567 :group 'gnus-article-mime
570 (defcustom gnus-article-display-method-for-traditional
571 'gnus-article-display-traditional-message
572 "*Function to display a traditional message.
573 The function is called from the article buffer."
574 :group 'gnus-article-mime
577 (defcustom gnus-page-delimiter "^\^L"
578 "*Regexp describing what to use as article page delimiters.
579 The default value is \"^\^L\", which is a form linefeed at the
580 beginning of a line."
582 :group 'gnus-article-various)
584 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
585 "*The format specification for the article mode line.
586 See `gnus-summary-mode-line-format' for a closer description.
588 The following additional specs are available:
590 %w The article washing status.
591 %m The number of MIME parts in the article."
593 :group 'gnus-article-various)
595 (defcustom gnus-article-mode-hook nil
596 "*A hook for Gnus article mode."
598 :group 'gnus-article-various)
600 (when (featurep 'xemacs)
601 ;; Extracted from gnus-xmas-define in order to preserve user settings
602 (when (fboundp 'turn-off-scroll-in-place)
603 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
604 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
605 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
607 (defcustom gnus-article-menu-hook nil
608 "*Hook run after the creation of the article mode menu."
610 :group 'gnus-article-various)
612 (defcustom gnus-article-prepare-hook nil
613 "*A hook called after an article has been prepared in the article buffer."
615 :group 'gnus-article-various)
617 (make-obsolete-variable 'gnus-article-hide-pgp-hook
618 "This variable is obsolete in Gnus 5.10.")
620 (defcustom gnus-article-button-face 'bold
621 "Face used for highlighting buttons in the article buffer.
623 An article button is a piece of text that you can activate by pressing
624 `RET' or `mouse-2' above it."
626 :group 'gnus-article-buttons)
628 (defcustom gnus-article-mouse-face 'highlight
629 "Face used for mouse highlighting in the article buffer.
631 Article buttons will be displayed in this face when the cursor is
634 :group 'gnus-article-buttons)
636 (defcustom gnus-signature-face 'gnus-signature-face
637 "Face used for highlighting a signature in the article buffer.
638 Obsolete; use the face `gnus-signature-face' for customizations instead."
640 :group 'gnus-article-highlight
641 :group 'gnus-article-signature)
643 (defface gnus-signature-face
646 "Face used for highlighting a signature in the article buffer."
647 :group 'gnus-article-highlight
648 :group 'gnus-article-signature)
650 (defface gnus-header-from-face
653 (:foreground "spring green"))
656 (:foreground "red3"))
659 "Face used for displaying from headers."
660 :group 'gnus-article-headers
661 :group 'gnus-article-highlight)
663 (defface gnus-header-subject-face
666 (:foreground "SeaGreen3"))
669 (:foreground "red4"))
671 (:bold t :italic t)))
672 "Face used for displaying subject headers."
673 :group 'gnus-article-headers
674 :group 'gnus-article-highlight)
676 (defface gnus-header-newsgroups-face
679 (:foreground "yellow" :italic t))
682 (:foreground "MidnightBlue" :italic t))
685 "Face used for displaying newsgroups headers.
686 In the default setup this face is only used for crossposted
688 :group 'gnus-article-headers
689 :group 'gnus-article-highlight)
691 (defface gnus-header-name-face
694 (:foreground "SeaGreen"))
697 (:foreground "maroon"))
700 "Face used for displaying header names."
701 :group 'gnus-article-headers
702 :group 'gnus-article-highlight)
704 (defface gnus-header-content-face
707 (:foreground "forest green" :italic t))
710 (:foreground "indianred4" :italic t))
713 "Face used for displaying header content."
714 :group 'gnus-article-headers
715 :group 'gnus-article-highlight)
717 (defcustom gnus-header-face-alist
718 '(("From" nil gnus-header-from-face)
719 ("Subject" nil gnus-header-subject-face)
720 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
721 ("" gnus-header-name-face gnus-header-content-face))
722 "*Controls highlighting of article headers.
724 An alist of the form (HEADER NAME CONTENT).
726 HEADER is a regular expression which should match the name of a
727 header and NAME and CONTENT are either face names or nil.
729 The name of each header field will be displayed using the face
730 specified by the first element in the list where HEADER matches
731 the header name and NAME is non-nil. Similarly, the content will
732 be displayed by the first non-nil matching CONTENT face."
733 :group 'gnus-article-headers
734 :group 'gnus-article-highlight
735 :type '(repeat (list (regexp :tag "Header")
737 (item :tag "skip" nil)
738 (face :value default))
739 (choice :tag "Content"
740 (item :tag "skip" nil)
741 (face :value default)))))
743 (defcustom gnus-article-decode-hook
744 '(article-decode-group-name article-decode-idna-rhs)
745 "*Hook run to decode charsets in articles."
746 :group 'gnus-article-headers
749 (defcustom gnus-display-mime-function 'gnus-display-mime
750 "Function to display MIME articles."
751 :group 'gnus-article-mime
754 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
755 "Function used to decode headers.")
757 (defvar gnus-article-dumbquotes-map
777 "Table for MS-to-Latin1 translation.")
779 (defcustom gnus-ignored-mime-types nil
780 "List of MIME types that should be ignored by Gnus."
782 :group 'gnus-article-mime
783 :type '(repeat regexp))
785 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
786 "List of MIME types that should not be given buttons when rendered inline.
787 See also `gnus-buttonized-mime-types' which may override this variable.
788 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
790 :group 'gnus-article-mime
791 :type '(repeat regexp))
793 (defcustom gnus-buttonized-mime-types nil
794 "List of MIME types that should be given buttons when rendered inline.
795 If set, this variable overrides `gnus-unbuttonized-mime-types'.
796 To see e.g. security buttons you could set this to
797 `(\"multipart/signed\")'.
798 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
800 :group 'gnus-article-mime
801 :type '(repeat regexp))
803 (defcustom gnus-inhibit-mime-unbuttonizing nil
804 "If non-nil, all MIME parts get buttons.
805 When nil (the default value), then some MIME parts do not get buttons,
806 as described by the variables `gnus-buttonized-mime-types' and
807 `gnus-unbuttonized-mime-types'."
811 (defcustom gnus-body-boundary-delimiter "_"
812 "String used to delimit header and body.
813 This variable is used by `gnus-article-treat-body-boundary' which can
814 be controlled by `gnus-treat-body-boundary'."
815 :group 'gnus-article-various
816 :type '(choice (item :tag "None" :value nil)
819 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
820 "Defines the location of the faces database.
821 For information on obtaining this database of pretty pictures, please
822 see http://www.cs.indiana.edu/picons/ftp/index.html"
823 :type '(repeat directory)
824 :link '(url-link :tag "download"
825 "http://www.cs.indiana.edu/picons/ftp/index.html")
826 :link '(custom-manual "(gnus)Picons")
829 (defun gnus-picons-installed-p ()
830 "Say whether picons are installed on your machine."
831 (let ((installed nil))
832 (dolist (database gnus-picon-databases)
833 (when (file-exists-p database)
837 (defcustom gnus-article-mime-part-function nil
838 "Function called with a MIME handle as the argument.
839 This is meant for people who want to do something automatic based
840 on parts -- for instance, adding Vcard info to a database."
841 :group 'gnus-article-mime
844 (defcustom gnus-mime-multipart-functions nil
845 "An alist of MIME types to functions to display them."
847 :group 'gnus-article-mime
850 (defcustom gnus-article-date-lapsed-new-header nil
851 "Whether the X-Sent and Date headers can coexist.
852 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
853 either replace the old \"Date:\" header (if this variable is nil), or
854 be added below it (otherwise)."
856 :group 'gnus-article-headers
859 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
860 "Function called with a MIME handle as the argument.
861 This is meant for people who want to view first matched part.
862 For `undisplayed-alternative' (default), the first undisplayed
863 part or alternative part is used. For `undisplayed', the first
864 undisplayed part is used. For a function, the first part which
865 the function return t is used. For nil, the first part is
868 :group 'gnus-article-mime
870 (item :tag "first" :value nil)
871 (item :tag "undisplayed" :value undisplayed)
872 (item :tag "undisplayed or alternative"
873 :value undisplayed-alternative)
876 (defcustom gnus-mime-action-alist
877 '(("save to file" . gnus-mime-save-part)
878 ("save and strip" . gnus-mime-save-part-and-strip)
879 ("delete part" . gnus-mime-delete-part)
880 ("display as text" . gnus-mime-inline-part)
881 ("view the part" . gnus-mime-view-part)
882 ("pipe to command" . gnus-mime-pipe-part)
883 ("toggle display" . gnus-article-press-button)
884 ("toggle display" . gnus-article-view-part-as-charset)
885 ("view as type" . gnus-mime-view-part-as-type)
886 ("view internally" . gnus-mime-view-part-internally)
887 ("view externally" . gnus-mime-view-part-externally))
888 "An alist of actions that run on the MIME attachment."
889 :group 'gnus-article-mime
890 :type '(repeat (cons (string :tag "name")
894 ;;; The treatment variables
897 (defvar gnus-part-display-hook nil
898 "Hook called on parts that are to receive treatment.")
900 (defvar gnus-article-treat-custom
901 '(choice (const :tag "Off" nil)
903 (const :tag "Header" head)
904 (const :tag "Last" last)
905 (const :tag "Mime" mime)
906 (integer :tag "Less")
907 (repeat :tag "Groups" regexp)
908 (sexp :tag "Predicate")))
910 (defvar gnus-article-treat-head-custom
911 '(choice (const :tag "Off" nil)
912 (const :tag "Header" head)))
914 (defvar gnus-article-treat-types '("text/plain")
917 (defvar gnus-inhibit-treatment nil
918 "Whether to inhibit treatment.")
920 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
921 "Highlight the signature.
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See Info node `(gnus)Customizing Articles'."
924 :group 'gnus-article-treat
925 :link '(custom-manual "(gnus)Customizing Articles")
926 :type gnus-article-treat-custom)
927 (put 'gnus-treat-highlight-signature 'highlight t)
929 (defcustom gnus-treat-buttonize 100000
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See Info node `(gnus)Customizing Articles'."
933 :group 'gnus-article-treat
934 :link '(custom-manual "(gnus)Customizing Articles")
935 :type gnus-article-treat-custom)
936 (put 'gnus-treat-buttonize 'highlight t)
938 (defcustom gnus-treat-buttonize-head 'head
939 "Add buttons to the head.
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See Info node `(gnus)Customizing Articles' for details."
942 :group 'gnus-article-treat
943 :link '(custom-manual "(gnus)Customizing Articles")
944 :type gnus-article-treat-head-custom)
945 (put 'gnus-treat-buttonize-head 'highlight t)
947 (defcustom gnus-treat-emphasize
948 (and (or window-system
950 (>= (string-to-number emacs-version) 21))
953 Valid values are nil, t, `head', `last', an integer or a predicate.
954 See Info node `(gnus)Customizing Articles' for details."
955 :group 'gnus-article-treat
956 :link '(custom-manual "(gnus)Customizing Articles")
957 :type gnus-article-treat-custom)
958 (put 'gnus-treat-emphasize 'highlight t)
960 (defcustom gnus-treat-strip-cr nil
961 "Remove carriage returns.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See Info node `(gnus)Customizing Articles' for details."
964 :group 'gnus-article-treat
965 :link '(custom-manual "(gnus)Customizing Articles")
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-unsplit-urls nil
969 "Remove newlines from within URLs.
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See Info node `(gnus)Customizing Articles' for details."
972 :group 'gnus-article-treat
973 :link '(custom-manual "(gnus)Customizing Articles")
974 :type gnus-article-treat-custom)
976 (defcustom gnus-treat-leading-whitespace nil
977 "Remove leading whitespace in headers.
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See Info node `(gnus)Customizing Articles' for details."
980 :group 'gnus-article-treat
981 :link '(custom-manual "(gnus)Customizing Articles")
982 :type gnus-article-treat-custom)
984 (defcustom gnus-treat-hide-headers 'head
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See Info node `(gnus)Customizing Articles' for details."
988 :group 'gnus-article-treat
989 :link '(custom-manual "(gnus)Customizing Articles")
990 :type gnus-article-treat-head-custom)
992 (defcustom gnus-treat-hide-boring-headers nil
993 "Hide boring headers.
994 Valid values are nil, t, `head', `last', an integer or a predicate.
995 See Info node `(gnus)Customizing Articles' for details."
996 :group 'gnus-article-treat
997 :link '(custom-manual "(gnus)Customizing Articles")
998 :type gnus-article-treat-head-custom)
1000 (defcustom gnus-treat-hide-signature nil
1001 "Hide the signature.
1002 Valid values are nil, t, `head', `last', an integer or a predicate.
1003 See Info node `(gnus)Customizing Articles' for details."
1004 :group 'gnus-article-treat
1005 :link '(custom-manual "(gnus)Customizing Articles")
1006 :type gnus-article-treat-custom)
1008 (defcustom gnus-treat-fill-article nil
1010 Valid values are nil, t, `head', `last', an integer or a predicate.
1011 See Info node `(gnus)Customizing Articles' for details."
1012 :group 'gnus-article-treat
1013 :link '(custom-manual "(gnus)Customizing Articles")
1014 :type gnus-article-treat-custom)
1016 (defcustom gnus-treat-hide-citation nil
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See Info node `(gnus)Customizing Articles' for details."
1020 :group 'gnus-article-treat
1021 :link '(custom-manual "(gnus)Customizing Articles")
1022 :type gnus-article-treat-custom)
1024 (defcustom gnus-treat-hide-citation-maybe nil
1026 Valid values are nil, t, `head', `last', an integer or a predicate.
1027 See Info node `(gnus)Customizing Articles' for details."
1028 :group 'gnus-article-treat
1029 :link '(custom-manual "(gnus)Customizing Articles")
1030 :type gnus-article-treat-custom)
1032 (defcustom gnus-treat-strip-list-identifiers 'head
1033 "Strip list identifiers from `gnus-list-identifiers`.
1034 Valid values are nil, t, `head', `last', an integer or a predicate.
1035 See Info node `(gnus)Customizing Articles' for details."
1037 :group 'gnus-article-treat
1038 :link '(custom-manual "(gnus)Customizing Articles")
1039 :type gnus-article-treat-custom)
1041 (make-obsolete-variable 'gnus-treat-strip-pgp
1042 "This option is obsolete in Gnus 5.10.")
1044 (defcustom gnus-treat-strip-pem nil
1045 "Strip PEM signatures.
1046 Valid values are nil, t, `head', `last', an integer or a predicate.
1047 See Info node `(gnus)Customizing Articles' for details."
1048 :group 'gnus-article-treat
1049 :link '(custom-manual "(gnus)Customizing Articles")
1050 :type gnus-article-treat-custom)
1052 (defcustom gnus-treat-strip-banner t
1053 "Strip banners from articles.
1054 The banner to be stripped is specified in the `banner' group parameter.
1055 Valid values are nil, t, `head', `last', an integer or a predicate.
1056 See Info node `(gnus)Customizing Articles' for details."
1057 :group 'gnus-article-treat
1058 :link '(custom-manual "(gnus)Customizing Articles")
1059 :type gnus-article-treat-custom)
1061 (defcustom gnus-treat-highlight-headers 'head
1062 "Highlight the headers.
1063 Valid values are nil, t, `head', `last', an integer or a predicate.
1064 See Info node `(gnus)Customizing Articles' for details."
1065 :group 'gnus-article-treat
1066 :link '(custom-manual "(gnus)Customizing Articles")
1067 :type gnus-article-treat-head-custom)
1068 (put 'gnus-treat-highlight-headers 'highlight t)
1070 (defcustom gnus-treat-highlight-citation t
1071 "Highlight cited text.
1072 Valid values are nil, t, `head', `last', an integer or a predicate.
1073 See Info node `(gnus)Customizing Articles' for details."
1074 :group 'gnus-article-treat
1075 :link '(custom-manual "(gnus)Customizing Articles")
1076 :type gnus-article-treat-custom)
1077 (put 'gnus-treat-highlight-citation 'highlight t)
1079 (defcustom gnus-treat-date-ut nil
1080 "Display the Date in UT (GMT).
1081 Valid values are nil, t, `head', `last', an integer or a predicate.
1082 See Info node `(gnus)Customizing Articles' for details."
1083 :group 'gnus-article-treat
1084 :link '(custom-manual "(gnus)Customizing Articles")
1085 :type gnus-article-treat-head-custom)
1087 (defcustom gnus-treat-date-local nil
1088 "Display the Date in the local timezone.
1089 Valid values are nil, t, `head', `last', an integer or a predicate.
1090 See Info node `(gnus)Customizing Articles' for details."
1091 :group 'gnus-article-treat
1092 :link '(custom-manual "(gnus)Customizing Articles")
1093 :type gnus-article-treat-head-custom)
1095 (defcustom gnus-treat-date-english nil
1096 "Display the Date in a format that can be read aloud in English.
1097 Valid values are nil, t, `head', `last', an integer or a predicate.
1098 See Info node `(gnus)Customizing Articles' for details."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-head-custom)
1103 (defcustom gnus-treat-date-lapsed nil
1104 "Display the Date header in a way that says how much time has elapsed.
1105 Valid values are nil, t, `head', `last', an integer or a predicate.
1106 See Info node `(gnus)Customizing Articles' for details."
1107 :group 'gnus-article-treat
1108 :link '(custom-manual "(gnus)Customizing Articles")
1109 :type gnus-article-treat-head-custom)
1111 (defcustom gnus-treat-date-original nil
1112 "Display the date in the original timezone.
1113 Valid values are nil, t, `head', `last', an integer or a predicate.
1114 See Info node `(gnus)Customizing Articles' for details."
1115 :group 'gnus-article-treat
1116 :link '(custom-manual "(gnus)Customizing Articles")
1117 :type gnus-article-treat-head-custom)
1119 (defcustom gnus-treat-date-iso8601 nil
1120 "Display the date in the ISO8601 format.
1121 Valid values are nil, t, `head', `last', an integer or a predicate.
1122 See Info node `(gnus)Customizing Articles' for details."
1124 :group 'gnus-article-treat
1125 :link '(custom-manual "(gnus)Customizing Articles")
1126 :type gnus-article-treat-head-custom)
1128 (defcustom gnus-treat-date-user-defined nil
1129 "Display the date in a user-defined format.
1130 The format is defined by the `gnus-article-time-format' variable.
1131 Valid values are nil, t, `head', `last', an integer or a predicate.
1132 See Info node `(gnus)Customizing Articles' for details."
1133 :group 'gnus-article-treat
1134 :link '(custom-manual "(gnus)Customizing Articles")
1135 :type gnus-article-treat-head-custom)
1137 (defcustom gnus-treat-strip-headers-in-body t
1138 "Strip the X-No-Archive header line from the beginning of the body.
1139 Valid values are nil, t, `head', `last', an integer or a predicate.
1140 See Info node `(gnus)Customizing Articles' for details."
1142 :group 'gnus-article-treat
1143 :link '(custom-manual "(gnus)Customizing Articles")
1144 :type gnus-article-treat-custom)
1146 (defcustom gnus-treat-strip-trailing-blank-lines nil
1147 "Strip trailing blank lines.
1148 Valid values are nil, t, `head', `last', an integer or a predicate.
1149 See Info node `(gnus)Customizing Articles' for details."
1150 :group 'gnus-article-treat
1151 :link '(custom-manual "(gnus)Customizing Articles")
1152 :type gnus-article-treat-custom)
1154 (defcustom gnus-treat-strip-leading-blank-lines nil
1155 "Strip leading blank lines.
1156 Valid values are nil, t, `head', `last', an integer or a predicate.
1157 See Info node `(gnus)Customizing Articles' for details."
1158 :group 'gnus-article-treat
1159 :link '(custom-manual "(gnus)Customizing Articles")
1160 :type gnus-article-treat-custom)
1162 (defcustom gnus-treat-strip-multiple-blank-lines nil
1163 "Strip multiple blank lines.
1164 Valid values are nil, t, `head', `last', an integer or a predicate.
1165 See Info node `(gnus)Customizing Articles' for details."
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-custom)
1170 (defcustom gnus-treat-unfold-headers 'head
1171 "Unfold folded header lines.
1172 Valid values are nil, t, `head', `last', an integer or a predicate.
1173 See Info node `(gnus)Customizing Articles' for details."
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1178 (defcustom gnus-treat-fold-headers nil
1180 Valid values are nil, t, `head', `last', an integer or a predicate.
1181 See Info node `(gnus)Customizing Articles' for details."
1182 :group 'gnus-article-treat
1183 :link '(custom-manual "(gnus)Customizing Articles")
1184 :type gnus-article-treat-custom)
1186 (defcustom gnus-treat-fold-newsgroups 'head
1187 "Fold the Newsgroups and Followup-To headers.
1188 Valid values are nil, t, `head', `last', an integer or a predicate.
1189 See Info node `(gnus)Customizing Articles' for details."
1190 :group 'gnus-article-treat
1191 :link '(custom-manual "(gnus)Customizing Articles")
1192 :type gnus-article-treat-custom)
1194 (defcustom gnus-treat-overstrike t
1195 "Treat overstrike highlighting.
1196 Valid values are nil, t, `head', `last', an integer or a predicate.
1197 See Info node `(gnus)Customizing Articles' for details."
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1201 (put 'gnus-treat-overstrike 'highlight t)
1203 (make-obsolete-variable 'gnus-treat-display-xface
1204 'gnus-treat-display-x-face)
1206 (defcustom gnus-treat-display-x-face
1207 (and (not noninteractive)
1208 (or (memq gnus-article-x-face-command
1209 '(x-face-decode-message-header
1210 x-face-mule-gnus-article-display-x-face))
1211 (and (fboundp 'image-type-available-p)
1212 (image-type-available-p 'xbm)
1213 (string-match "^0x" (shell-command-to-string "uncompface"))
1214 (executable-find "icontopbm"))
1215 (and (featurep 'xemacs)
1218 "Display X-Face headers.
1219 Valid values are nil, t, `head', `last', an integer or a predicate.
1220 See Info node `(gnus)Customizing Articles' and Info node
1221 `(gnus)X-Face' for details."
1222 :group 'gnus-article-treat
1224 :link '(custom-manual "(gnus)Customizing Articles")
1225 :link '(custom-manual "(gnus)X-Face")
1226 :type gnus-article-treat-head-custom
1227 :set (lambda (symbol value)
1230 (cond ((or (boundp symbol) (get symbol 'saved-value))
1232 ((boundp 'gnus-treat-display-xface)
1234 ** gnus-treat-display-xface is an obsolete variable;\
1235 use gnus-treat-display-x-face instead")
1236 (default-value 'gnus-treat-display-xface))
1237 ((get 'gnus-treat-display-xface 'saved-value)
1239 ** gnus-treat-display-xface is an obsolete variable;\
1240 use gnus-treat-display-x-face instead")
1241 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1244 (put 'gnus-treat-display-x-face 'highlight t)
1246 (defcustom gnus-article-should-use-smiley-mule
1247 (not (or (featurep 'xemacs)
1248 (gnus-image-type-available-p 'xpm)
1249 (gnus-image-type-available-p 'pbm)))
1250 "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
1251 `smiley'. It defaults to t when Emacs 20 or earlier is running.
1252 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1253 even if you are using Emacs 21+. It has no effect on XEmacs."
1254 :group 'gnus-article-various
1256 :get (lambda (symbol)
1257 (and (not noninteractive)
1258 (default-value symbol)
1259 (not (featurep 'xemacs))
1260 (module-installed-p 'smiley-mule)
1262 :set (lambda (symbol value)
1263 (set-default symbol (and (not noninteractive)
1265 (not (featurep 'xemacs))
1266 (module-installed-p 'smiley-mule)
1269 (defvar gnus-article-smiley-mule-loaded-p nil
1270 "Internal variable used to say whether `smiley-mule' is loaded (whether
1271 smiley functions are not overridden by `smiley').")
1273 (defcustom gnus-treat-display-face
1274 (and (not noninteractive)
1275 ;; x-face-e21 handles both X-Face and Face headers.
1276 (not (and (eq gnus-article-x-face-command 'x-face-decode-message-header)
1277 (module-installed-p 'x-face-e21)))
1278 (or (and (fboundp 'image-type-available-p)
1279 (image-type-available-p 'png))
1280 (and (featurep 'xemacs)
1283 "Display Face headers.
1284 Valid values are nil, t, `head', `last', an integer or a predicate.
1285 See Info node `(gnus)Customizing Articles' and Info node
1286 `(gnus)X-Face' for details."
1287 :group 'gnus-article-treat
1289 :link '(custom-manual "(gnus)Customizing Articles")
1290 :link '(custom-manual "(gnus)X-Face")
1291 :type gnus-article-treat-head-custom)
1292 (put 'gnus-treat-display-face 'highlight t)
1294 (defcustom gnus-treat-display-smileys
1295 (if (and (not noninteractive)
1296 (or (and (featurep 'xemacs)
1298 (gnus-image-type-available-p 'xpm)
1299 (gnus-image-type-available-p 'pbm)
1300 (and (not (featurep 'xemacs))
1302 (module-installed-p 'smiley-mule))))
1306 Valid values are nil, t, `head', `last', an integer or a predicate.
1307 See Info node `(gnus)Customizing Articles' and Info node
1308 `(gnus)Smileys' for details."
1309 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :link '(custom-manual "(gnus)Smileys")
1313 :type gnus-article-treat-custom)
1314 (put 'gnus-treat-display-smileys 'highlight t)
1316 (defcustom gnus-treat-from-picon
1317 (if (and (gnus-image-type-available-p 'xpm)
1318 (gnus-picons-installed-p))
1320 "Display picons in the From header.
1321 Valid values are nil, t, `head', `last', an integer or a predicate.
1322 See Info node `(gnus)Customizing Articles' and Info node
1323 `(gnus)Picons' for details."
1324 :group 'gnus-article-treat
1326 :link '(custom-manual "(gnus)Customizing Articles")
1327 :link '(custom-manual "(gnus)Picons")
1328 :type gnus-article-treat-head-custom)
1329 (put 'gnus-treat-from-picon 'highlight t)
1331 (defcustom gnus-treat-mail-picon
1332 (if (and (gnus-image-type-available-p 'xpm)
1333 (gnus-picons-installed-p))
1335 "Display picons in To and Cc headers.
1336 Valid values are nil, t, `head', `last', an integer or a predicate.
1337 See Info node `(gnus)Customizing Articles' and Info node
1338 `(gnus)Picons' for details."
1339 :group 'gnus-article-treat
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :link '(custom-manual "(gnus)Picons")
1343 :type gnus-article-treat-head-custom)
1344 (put 'gnus-treat-mail-picon 'highlight t)
1346 (defcustom gnus-treat-newsgroups-picon
1347 (if (and (gnus-image-type-available-p 'xpm)
1348 (gnus-picons-installed-p))
1350 "Display picons in the Newsgroups and Followup-To headers.
1351 Valid values are nil, t, `head', `last', an integer or a predicate.
1352 See Info node `(gnus)Customizing Articles' and Info node
1353 `(gnus)Picons' for details."
1354 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :link '(custom-manual "(gnus)Picons")
1358 :type gnus-article-treat-head-custom)
1359 (put 'gnus-treat-newsgroups-picon 'highlight t)
1361 (defcustom gnus-treat-body-boundary
1362 (if (or gnus-treat-newsgroups-picon
1363 gnus-treat-mail-picon
1364 gnus-treat-from-picon)
1366 "Draw a boundary at the end of the headers.
1367 Valid values are nil, t, `head', `last', an integer or a predicate.
1368 See Info node `(gnus)Customizing Articles' for details."
1370 :group 'gnus-article-treat
1371 :link '(custom-manual "(gnus)Customizing Articles")
1372 :type gnus-article-treat-custom)
1374 (defcustom gnus-treat-capitalize-sentences nil
1375 "Capitalize sentence-starting words.
1376 Valid values are nil, t, `head', `last', an integer or a predicate.
1377 See Info node `(gnus)Customizing Articles' for details."
1379 :group 'gnus-article-treat
1380 :link '(custom-manual "(gnus)Customizing Articles")
1381 :type gnus-article-treat-custom)
1383 (defcustom gnus-treat-wash-html nil
1385 Valid values are nil, t, `head', `last', an integer or a predicate.
1386 See Info node `(gnus)Customizing Articles' for details."
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1391 (defcustom gnus-treat-fill-long-lines nil
1393 Valid values are nil, t, `head', `last', an integer or a predicate.
1394 See Info node `(gnus)Customizing Articles' for details."
1395 :group 'gnus-article-treat
1396 :link '(custom-manual "(gnus)Customizing Articles")
1397 :type gnus-article-treat-custom)
1399 (defcustom gnus-treat-play-sounds nil
1401 Valid values are nil, t, `head', `last', an integer or a predicate.
1402 See Info node `(gnus)Customizing Articles' for details."
1404 :group 'gnus-article-treat
1405 :link '(custom-manual "(gnus)Customizing Articles")
1406 :type gnus-article-treat-custom)
1408 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1409 "Decode an article as `default-mime-charset'. For instance, if you want to
1410 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1411 you could set this variable to something like: nil for don't decode, t for
1412 decode the body, '(or header t) for the whole article, etc."
1413 :group 'gnus-article-treat
1414 :type '(radio (const :tag "Off" nil)
1415 (const :tag "Decode body" t)
1416 (const :tag "Decode all" (or head t))))
1418 (defcustom gnus-treat-translate nil
1419 "Translate articles from one language to another.
1420 Valid values are nil, t, `head', `last', an integer or a predicate.
1421 See Info node `(gnus)Customizing Articles' for details."
1423 :group 'gnus-article-treat
1424 :link '(custom-manual "(gnus)Customizing Articles")
1425 :type gnus-article-treat-custom)
1427 (defcustom gnus-treat-x-pgp-sig nil
1429 To automatically treat X-PGP-Sig, set it to head.
1430 Valid values are nil, t, `head', `last', an integer or a predicate.
1431 See Info node `(gnus)Customizing Articles' for details."
1432 :group 'gnus-article-treat
1433 :group 'mime-security
1434 :type gnus-article-treat-custom)
1436 (defcustom gnus-treat-monafy nil
1437 "Display body part with mona font.
1438 Valid values are nil, t, `head', `last', an integer or a predicate.
1439 See Info node `(gnus)Customizing Articles' for details."
1440 :group 'gnus-article-treat
1441 :group 'mime-security
1442 :link '(custom-manual "(gnus)Customizing Articles")
1443 :type gnus-article-treat-custom)
1445 (defvar gnus-article-encrypt-protocol-alist
1446 '(("PGP" . mml2015-self-encrypt)))
1448 ;; Set to nil if more than one protocol added to
1449 ;; gnus-article-encrypt-protocol-alist.
1450 (defcustom gnus-article-encrypt-protocol "PGP"
1451 "The protocol used for encrypt articles.
1452 It is a string, such as \"PGP\". If nil, ask user."
1454 :group 'mime-security)
1456 (defvar gnus-article-wash-function nil
1457 "Function used for converting HTML into text.")
1459 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1460 (mm-coding-system-p 'utf-8)
1461 (executable-find idna-program))
1462 "Whether IDNA decoding of headers is used when viewing messages.
1463 This requires GNU Libidn, and by default only enabled if it is found."
1464 :group 'gnus-article-headers
1467 (defcustom gnus-article-over-scroll nil
1468 "If non-nil, allow scrolling the article buffer even when there no more text."
1469 :group 'gnus-article
1472 ;;; Internal variables
1474 (defvar gnus-english-month-names
1475 '("January" "February" "March" "April" "May" "June" "July" "August"
1476 "September" "October" "November" "December"))
1478 (defvar article-goto-body-goes-to-point-min-p nil)
1479 (defvar gnus-article-wash-types nil)
1480 (defvar gnus-article-emphasis-alist nil)
1481 (defvar gnus-article-image-alist nil)
1483 (defvar gnus-article-mime-handle-alist-1 nil)
1484 (defvar gnus-treatment-function-alist
1485 '((gnus-treat-decode-article-as-default-mime-charset
1486 gnus-article-decode-article-as-default-mime-charset)
1487 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1488 (gnus-treat-monafy gnus-article-monafy)
1489 (gnus-treat-strip-banner gnus-article-strip-banner)
1490 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1491 (gnus-treat-buttonize gnus-article-add-buttons)
1492 (gnus-treat-fill-article gnus-article-fill-cited-article)
1493 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1494 (gnus-treat-strip-cr gnus-article-remove-cr)
1495 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1496 (gnus-treat-date-ut gnus-article-date-ut)
1497 (gnus-treat-date-local gnus-article-date-local)
1498 (gnus-treat-date-english gnus-article-date-english)
1499 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1500 (gnus-treat-date-original gnus-article-date-original)
1501 (gnus-treat-date-user-defined gnus-article-date-user)
1502 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1503 (gnus-treat-display-face gnus-article-display-face)
1504 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1505 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1506 (gnus-treat-hide-signature gnus-article-hide-signature)
1507 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1508 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1509 (gnus-treat-strip-pem gnus-article-hide-pem)
1510 (gnus-treat-from-picon gnus-treat-from-picon)
1511 (gnus-treat-mail-picon gnus-treat-mail-picon)
1512 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1513 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1514 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1515 (gnus-treat-strip-trailing-blank-lines
1516 gnus-article-remove-trailing-blank-lines)
1517 (gnus-treat-strip-leading-blank-lines
1518 gnus-article-strip-leading-blank-lines)
1519 (gnus-treat-strip-multiple-blank-lines
1520 gnus-article-strip-multiple-blank-lines)
1521 (gnus-treat-overstrike gnus-article-treat-overstrike)
1522 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1523 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1524 ;; Displaying X-Face should be done after unfolding headers
1525 ;; to protect bitmap lines.
1526 (gnus-treat-display-x-face gnus-article-display-x-face)
1527 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1528 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1529 (gnus-treat-display-smileys gnus-treat-smiley)
1530 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1531 (gnus-treat-wash-html gnus-article-wash-html)
1532 (gnus-treat-emphasize gnus-article-emphasize)
1533 (gnus-treat-hide-citation gnus-article-hide-citation)
1534 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1535 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1536 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1537 (gnus-treat-play-sounds gnus-earcon-display)))
1539 (defvar gnus-article-mime-handle-alist nil)
1540 (defvar article-lapsed-timer nil)
1541 (defvar gnus-article-current-summary nil)
1543 (defvar gnus-article-mode-syntax-table
1544 (let ((table (copy-syntax-table text-mode-syntax-table)))
1545 ;; This causes the citation match run O(2^n).
1546 ;; (modify-syntax-entry ?- "w" table)
1547 (modify-syntax-entry ?> ")<" table)
1548 (modify-syntax-entry ?< "(>" table)
1549 ;; make M-. in article buffers work for `foo' strings
1550 (modify-syntax-entry ?' " " table)
1551 (modify-syntax-entry ?` " " table)
1553 "Syntax table used in article mode buffers.
1554 Initialized from `text-mode-syntax-table.")
1556 (defvar gnus-save-article-buffer nil)
1558 (defvar gnus-article-mode-line-format-alist
1559 (nconc '((?w (gnus-article-wash-status) ?s)
1560 (?m (gnus-article-mime-part-status) ?s))
1561 gnus-summary-mode-line-format-alist))
1563 (defvar gnus-number-of-articles-to-be-saved nil)
1565 (defvar gnus-inhibit-hiding nil)
1567 ;;; Macros for dealing with the article buffer.
1569 (defmacro gnus-with-article-headers (&rest forms)
1571 (set-buffer gnus-article-buffer)
1573 (let ((buffer-read-only nil)
1574 (inhibit-point-motion-hooks t)
1575 (case-fold-search t))
1576 (article-narrow-to-head)
1579 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1580 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1582 (defmacro gnus-with-article-buffer (&rest forms)
1584 (set-buffer gnus-article-buffer)
1585 (let ((buffer-read-only nil))
1588 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1589 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1591 (defun gnus-article-goto-header (header)
1592 "Go to HEADER, which is a regular expression."
1593 (re-search-forward (concat "^\\(" header "\\):") nil t))
1595 (defsubst gnus-article-hide-text (b e props)
1596 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1597 (gnus-add-text-properties-when 'article-type nil b e props)
1598 (when (memq 'intangible props)
1600 (max (1- b) (point-min))
1601 b 'intangible (cddr (memq 'intangible props)))))
1603 (defsubst gnus-article-unhide-text (b e)
1604 "Remove hidden text properties from region between B and E."
1605 (remove-text-properties b e gnus-hidden-properties)
1606 (when (memq 'intangible gnus-hidden-properties)
1607 (put-text-property (max (1- b) (point-min))
1608 b 'intangible nil)))
1610 (defun gnus-article-hide-text-type (b e type)
1611 "Hide text of TYPE between B and E."
1612 (gnus-add-wash-type type)
1613 (gnus-article-hide-text
1614 b e (cons 'article-type (cons type gnus-hidden-properties))))
1616 (defun gnus-article-unhide-text-type (b e type)
1617 "Unhide text of TYPE between B and E."
1618 (gnus-delete-wash-type type)
1619 (remove-text-properties
1620 b e (cons 'article-type (cons type gnus-hidden-properties)))
1621 (when (memq 'intangible gnus-hidden-properties)
1622 (put-text-property (max (1- b) (point-min))
1623 b 'intangible nil)))
1625 (defun gnus-article-hide-text-of-type (type)
1626 "Hide text of TYPE in the current buffer."
1628 (let ((b (point-min))
1630 (while (setq b (text-property-any b e 'article-type type))
1631 (add-text-properties b (incf b) gnus-hidden-properties)))))
1633 (defun gnus-article-delete-text-of-type (type)
1634 "Delete text of TYPE in the current buffer."
1636 (let ((b (point-min)))
1637 (while (setq b (text-property-any b (point-max) 'article-type type))
1639 b (or (text-property-not-all b (point-max) 'article-type type)
1642 (defun gnus-article-delete-invisible-text ()
1643 "Delete all invisible text in the current buffer."
1645 (let ((b (point-min)))
1646 (while (setq b (text-property-any b (point-max) 'invisible t))
1648 b (or (text-property-not-all b (point-max) 'invisible t)
1651 (defun gnus-article-text-type-exists-p (type)
1652 "Say whether any text of type TYPE exists in the buffer."
1653 (text-property-any (point-min) (point-max) 'article-type type))
1655 (defsubst gnus-article-header-rank ()
1656 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1657 (let ((list gnus-sorted-header-list)
1660 (if (looking-at (car list))
1662 (setq list (cdr list))
1666 (defun article-hide-headers (&optional arg delete)
1667 "Hide unwanted headers and possibly sort them as well."
1668 (interactive (gnus-article-hidden-arg))
1669 ;; Lars said that this function might be inhibited.
1670 (if (gnus-article-check-hidden-text 'headers arg)
1672 ;; Show boring headers as well.
1673 (gnus-article-show-hidden-text 'boring-headers)
1674 (when (eq 1 (point-min))
1675 (set-window-start (get-buffer-window (current-buffer)) 1)))
1676 (unless gnus-inhibit-hiding
1679 (let ((inhibit-read-only t)
1680 (case-fold-search t)
1681 (max (1+ (length gnus-sorted-header-list)))
1682 (ignored (when (not gnus-visible-headers)
1683 (cond ((stringp gnus-ignored-headers)
1684 gnus-ignored-headers)
1685 ((listp gnus-ignored-headers)
1686 (mapconcat 'identity gnus-ignored-headers
1689 (cond ((stringp gnus-visible-headers)
1690 gnus-visible-headers)
1691 ((and gnus-visible-headers
1692 (listp gnus-visible-headers))
1693 (mapconcat 'identity gnus-visible-headers "\\|"))))
1694 (inhibit-point-motion-hooks t)
1696 ;; First we narrow to just the headers.
1697 (article-narrow-to-head)
1698 ;; Hide any "From " lines at the beginning of (mail) articles.
1699 (while (looking-at "From ")
1703 (delete-region (point-min) (point))
1704 (gnus-article-hide-text (point-min) (point)
1705 (nconc (list 'article-type 'headers)
1706 gnus-hidden-properties))))
1707 ;; Then treat the rest of the header lines.
1708 ;; Then we use the two regular expressions
1709 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1710 ;; select which header lines is to remain visible in the
1712 (while (re-search-forward "^[^ \t:]*:" nil t)
1714 ;; Mark the rank of the header.
1716 (point) (1+ (point)) 'message-rank
1717 (if (or (and visible (looking-at visible))
1719 (not (looking-at ignored))))
1720 (gnus-article-header-rank)
1723 (message-sort-headers-1)
1724 (when (setq beg (text-property-any
1725 (point-min) (point-max) 'message-rank (+ 2 max)))
1726 ;; We delete or make invisible the unwanted headers.
1727 (gnus-add-wash-type 'headers)
1730 (add-text-properties
1731 (point-min) (+ 5 (point-min))
1732 '(article-type headers dummy-invisible t))
1733 (delete-region beg (point-max)))
1734 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1736 (defun article-hide-boring-headers (&optional arg)
1737 "Toggle hiding of headers that aren't very interesting.
1738 If given a negative prefix, always show; if given a positive prefix,
1740 (interactive (gnus-article-hidden-arg))
1741 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1742 (not gnus-show-all-headers))
1745 (let ((buffer-read-only nil)
1746 (list gnus-boring-article-headers)
1747 (inhibit-point-motion-hooks t)
1749 (article-narrow-to-head)
1751 (setq elem (pop list))
1752 (goto-char (point-min))
1754 ;; Hide empty headers.
1756 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1758 (gnus-article-hide-text-type
1762 (if (re-search-forward "^[^ \t]" nil t)
1766 ;; Hide boring Newsgroups header.
1767 ((eq elem 'newsgroups)
1768 (when (gnus-string-equal
1769 (gnus-fetch-field "newsgroups")
1770 (gnus-group-real-name
1771 (if (boundp 'gnus-newsgroup-name)
1774 (gnus-article-hide-header "newsgroups")))
1775 ((eq elem 'to-address)
1776 (let ((to (message-fetch-field "to"))
1778 (gnus-parameter-to-address
1779 (if (boundp 'gnus-newsgroup-name)
1780 gnus-newsgroup-name ""))))
1781 (when (and to to-address
1784 ;; only one address in To
1785 (nth 1 (mail-extract-address-components to))
1787 (gnus-article-hide-header "to"))))
1789 (let ((to (message-fetch-field "to"))
1791 (gnus-parameter-to-list
1792 (if (boundp 'gnus-newsgroup-name)
1793 gnus-newsgroup-name ""))))
1794 (when (and to to-list
1797 ;; only one address in To
1798 (nth 1 (mail-extract-address-components to))
1800 (gnus-article-hide-header "to"))))
1802 (let ((cc (message-fetch-field "cc"))
1804 (gnus-parameter-to-list
1805 (if (boundp 'gnus-newsgroup-name)
1806 gnus-newsgroup-name ""))))
1807 (when (and cc to-list
1810 ;; only one address in CC
1811 (nth 1 (mail-extract-address-components cc))
1813 (gnus-article-hide-header "cc"))))
1814 ((eq elem 'followup-to)
1815 (when (gnus-string-equal
1816 (message-fetch-field "followup-to")
1817 (message-fetch-field "newsgroups"))
1818 (gnus-article-hide-header "followup-to")))
1819 ((eq elem 'reply-to)
1820 (if (gnus-group-find-parameter
1821 gnus-newsgroup-name 'broken-reply-to)
1822 (gnus-article-hide-header "reply-to")
1823 (let ((from (message-fetch-field "from"))
1824 (reply-to (message-fetch-field "reply-to")))
1831 (lambda (x) (downcase (cadr x)))
1832 (mail-extract-address-components from t))
1835 (lambda (x) (downcase (cadr x)))
1836 (mail-extract-address-components reply-to t))
1838 (gnus-article-hide-header "reply-to")))))
1840 (let ((date (message-fetch-field "date")))
1842 (< (days-between (current-time-string) date)
1844 (gnus-article-hide-header "date"))))
1846 (let ((to (message-fetch-field "to"))
1847 (cc (message-fetch-field "cc")))
1848 (when (> (length to) 1024)
1849 (gnus-article-hide-header "to"))
1850 (when (> (length cc) 1024)
1851 (gnus-article-hide-header "cc"))))
1855 (goto-char (point-min))
1856 (while (re-search-forward "^to:" nil t)
1857 (setq to-count (1+ to-count)))
1858 (when (> to-count 1)
1859 (while (> to-count 0)
1860 (goto-char (point-min))
1862 (re-search-forward "^to:" nil nil to-count)
1864 (narrow-to-region (point) (point-max))
1865 (gnus-article-hide-header "to"))
1866 (setq to-count (1- to-count))))
1867 (goto-char (point-min))
1868 (while (re-search-forward "^cc:" nil t)
1869 (setq cc-count (1+ cc-count)))
1870 (when (> cc-count 1)
1871 (while (> cc-count 0)
1872 (goto-char (point-min))
1874 (re-search-forward "^cc:" nil nil cc-count)
1876 (narrow-to-region (point) (point-max))
1877 (gnus-article-hide-header "cc"))
1878 (setq cc-count (1- cc-count)))))))))))))
1880 (defun gnus-article-hide-header (header)
1882 (goto-char (point-min))
1883 (when (re-search-forward (concat "^" header ":") nil t)
1884 (gnus-article-hide-text-type
1888 (if (re-search-forward "^[^ \t]" nil t)
1893 (defvar gnus-article-normalized-header-length 40
1894 "Length of normalized headers.")
1896 (defun article-normalize-headers ()
1897 "Make all header lines 40 characters long."
1899 (let ((buffer-read-only nil)
1903 (article-narrow-to-head)
1906 ((< (setq column (- (gnus-point-at-eol) (point)))
1907 gnus-article-normalized-header-length)
1909 (insert (make-string
1910 (- gnus-article-normalized-header-length column)
1912 ((> column gnus-article-normalized-header-length)
1913 (gnus-put-text-property
1915 (forward-char gnus-article-normalized-header-length)
1922 (forward-line 1))))))
1924 (defun article-treat-dumbquotes ()
1925 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1926 Note that this function guesses whether a character is a sm*rtq**t* or
1927 not, so it should only be used interactively.
1929 Sm*rtq**t*s are M****s***'s unilateral extension to the
1930 iso-8859-1 character map in an attempt to provide more quoting
1931 characters. If you see something like \\222 or \\264 where
1932 you're expecting some kind of apostrophe or quotation mark, then
1935 (article-translate-strings gnus-article-dumbquotes-map))
1937 (defun article-translate-characters (from to)
1938 "Translate all characters in the body of the article according to FROM and TO.
1939 FROM is a string of characters to translate from; to is a string of
1940 characters to translate to."
1942 (when (article-goto-body)
1943 (let ((buffer-read-only nil)
1944 (x (make-string 225 ?x))
1946 (while (< (incf i) (length x))
1949 (while (< i (length from))
1950 (aset x (aref from i) (aref to i))
1952 (translate-region (point) (point-max) x)))))
1954 (defun article-translate-strings (map)
1955 "Translate all string in the body of the article according to MAP.
1956 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1958 (when (article-goto-body)
1959 (let ((buffer-read-only nil)
1961 (while (setq elem (pop map))
1963 (while (search-forward (car elem) nil t)
1964 (replace-match (cadr elem)))))))))
1966 (defun article-treat-overstrike ()
1967 "Translate overstrikes into bold text."
1970 (when (article-goto-body)
1971 (let ((buffer-read-only nil))
1972 (while (search-forward "\b" nil t)
1973 (let ((next (char-after))
1977 previous (char-after))
1981 ;; We do the boldification/underlining by hiding the
1982 ;; overstrikes and putting the proper text property
1986 (gnus-article-hide-text-type start (point) 'overstrike)
1987 (put-text-property (point) end 'face 'bold))
1989 (gnus-article-hide-text-type
1990 (1- (point)) (1+ (point)) 'overstrike)
1992 start (1- (point)) 'face 'underline))
1994 (gnus-article-hide-text-type start (point) 'overstrike)
1996 (point) end 'face 'underline)))))))))
1998 (defun gnus-article-treat-unfold-headers ()
1999 "Unfold folded message headers.
2000 Only the headers that fit into the current window width will be
2003 (gnus-with-article-headers
2007 (mail-header-narrow-to-field)
2008 (let ((header (buffer-string)))
2011 (goto-char (point-min))
2012 (while (re-search-forward "\n[\t ]" nil t)
2013 (replace-match " " t t)))
2014 (setq length (- (point-max) (point-min) 1)))
2015 (when (< length (window-width))
2016 (while (re-search-forward "\n[\t ]" nil t)
2017 (replace-match " " t t)))
2018 (goto-char (point-max)))))))
2020 (defun gnus-article-treat-fold-headers ()
2021 "Fold message headers."
2023 (gnus-with-article-headers
2026 (mail-header-narrow-to-field)
2027 (mail-header-fold-field)
2028 (goto-char (point-max))))))
2030 (defun gnus-treat-smiley ()
2031 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2033 (unless (featurep 'xemacs)
2034 (when (and (>= emacs-major-version 21)
2035 (not gnus-article-should-use-smiley-mule)
2036 gnus-article-smiley-mule-loaded-p)
2037 (load "smiley" nil t)
2038 (setq gnus-article-smiley-mule-loaded-p nil))
2039 (when (and gnus-article-should-use-smiley-mule
2040 (not gnus-article-smiley-mule-loaded-p))
2041 (load "smiley-mule" nil t)
2042 (setq gnus-article-smiley-mule-loaded-p t)))
2043 (gnus-with-article-buffer
2044 (if (memq 'smiley gnus-article-wash-types)
2045 (gnus-delete-images 'smiley)
2047 (let ((images (smiley-region (point) (point-max))))
2049 (gnus-add-wash-type 'smiley)
2050 (dolist (image images)
2051 (gnus-add-image 'smiley image)))))))
2053 (defun gnus-article-remove-images ()
2054 "Remove all images from the article buffer."
2056 (gnus-with-article-buffer
2057 (dolist (elem gnus-article-image-alist)
2058 (gnus-delete-images (car elem)))))
2060 (defun gnus-article-treat-fold-newsgroups ()
2061 "Unfold folded message headers.
2062 Only the headers that fit into the current window width will be
2065 (gnus-with-article-headers
2066 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2068 (mail-header-narrow-to-field)
2069 (while (re-search-forward ", *" nil t)
2070 (replace-match ", " t t))
2071 (mail-header-fold-field)
2072 (goto-char (point-max))))))
2074 (defun gnus-article-treat-body-boundary ()
2075 "Place a boundary line at the end of the headers."
2077 (when (and gnus-body-boundary-delimiter
2078 (> (length gnus-body-boundary-delimiter) 0))
2079 (gnus-with-article-headers
2080 (goto-char (point-max))
2081 (let ((start (point)))
2082 (insert "X-Boundary: ")
2083 (gnus-add-text-properties start (point) '(invisible t intangible t))
2085 (while (>= (1- (window-width)) (length str))
2086 (setq str (concat str gnus-body-boundary-delimiter)))
2087 (substring str 0 (1- (window-width))))
2089 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2091 (defun article-fill-long-lines ()
2092 "Fill lines that are wider than the window width."
2095 (let ((buffer-read-only nil)
2096 (width (window-width (get-buffer-window (current-buffer)))))
2099 (let ((adaptive-fill-mode nil)) ;Why? -sm
2102 (when (>= (current-column) (min fill-column width))
2103 (narrow-to-region (min (1+ (point)) (point-max))
2104 (gnus-point-at-bol))
2105 (let ((goback (point-marker)))
2106 (fill-paragraph nil)
2107 (goto-char (marker-position goback)))
2109 (forward-line 1)))))))
2111 (defun article-capitalize-sentences ()
2112 "Capitalize the first word in each sentence."
2115 (let ((buffer-read-only nil)
2116 (paragraph-start "^[\n\^L]"))
2120 (forward-sentence)))))
2122 (defun article-remove-cr ()
2123 "Remove trailing CRs and then translate remaining CRs into LFs."
2126 (let ((buffer-read-only nil))
2127 (goto-char (point-min))
2128 (while (re-search-forward "\r+$" nil t)
2129 (replace-match "" t t))
2130 (goto-char (point-min))
2131 (while (search-forward "\r" nil t)
2132 (replace-match "\n" t t)))))
2134 (defun article-remove-trailing-blank-lines ()
2135 "Remove all trailing blank lines from the article."
2138 (let ((buffer-read-only nil))
2139 (goto-char (point-max))
2143 (while (and (not (bobp))
2144 (looking-at "^[ \t]*$")
2145 (not (gnus-annotation-in-region-p
2146 (point) (gnus-point-at-eol))))
2151 (defun article-display-face ()
2152 "Display any Face headers in the header."
2154 (let ((wash-face-p buffer-read-only))
2155 (gnus-with-article-headers
2156 ;; When displaying parts, this function can be called several times on
2157 ;; the same article, without any intended toggle semantic (as typing `W
2158 ;; D d' would have). So face deletion must occur only when we come from
2159 ;; an interactive command, that is when the *Article* buffer is
2161 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2162 (gnus-delete-images 'face)
2165 (when (and wash-face-p
2167 (goto-char (point-min))
2168 (not (re-search-forward "^Face:[\t ]*" nil t)))
2169 (gnus-buffer-live-p gnus-original-article-buffer))
2170 (set-buffer gnus-original-article-buffer))
2172 (mail-narrow-to-head)
2173 (while (gnus-article-goto-header "Face")
2174 (push (mail-header-field-value) faces))))
2175 (while (setq face (pop faces))
2176 (let ((png (gnus-convert-face-to-png face))
2179 (setq image (gnus-create-image png 'png t))
2180 (gnus-article-goto-header "from")
2182 (insert "From: [no `from' set]\n")
2184 (gnus-add-wash-type 'face)
2185 (gnus-add-image 'face image)
2186 (gnus-put-image image nil 'face))))))
2189 (defun article-display-x-face (&optional force)
2190 "Look for an X-Face header and display it if present."
2191 (interactive (list 'force))
2192 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2193 (gnus-with-article-headers
2194 ;; Delete the old process, if any.
2195 (when (process-status "article-x-face")
2196 (delete-process "article-x-face"))
2197 ;; See the comment in `article-display-face'.
2198 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2199 ;; We have already displayed X-Faces, so we remove them
2201 (gnus-delete-images 'xface)
2203 (let (x-faces from face)
2205 (when (and wash-face-p
2207 (goto-char (point-min))
2208 (not (re-search-forward
2209 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2210 (gnus-buffer-live-p gnus-original-article-buffer))
2211 ;; If type `W f', use gnus-original-article-buffer,
2212 ;; otherwise use the current buffer because displaying
2213 ;; RFC822 parts calls this function too.
2214 (set-buffer gnus-original-article-buffer))
2216 (mail-narrow-to-head)
2217 (while (gnus-article-goto-header "X-Face")
2218 (push (mail-header-field-value) x-faces))
2219 (setq from (message-fetch-field "from"))))
2220 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2221 ;; single external face.
2222 (when (stringp gnus-article-x-face-command)
2223 (setq x-faces (list (car x-faces))))
2224 (while (and (setq face (pop x-faces))
2225 gnus-article-x-face-command
2227 ;; Check whether this face is censored.
2228 (not gnus-article-x-face-too-ugly)
2229 (and gnus-article-x-face-too-ugly from
2230 (not (string-match gnus-article-x-face-too-ugly
2232 ;; We display the face.
2233 (cond ((stringp gnus-article-x-face-command)
2234 ;; The command is a string, so we interpret the command
2235 ;; as a, well, command, and fork it off.
2236 (let ((process-connection-type nil))
2237 (process-kill-without-query
2239 "article-x-face" nil shell-file-name
2240 shell-command-switch gnus-article-x-face-command))
2243 (process-send-region "article-x-face"
2244 (point-min) (point-max)))
2245 (process-send-eof "article-x-face")))
2246 ((functionp gnus-article-x-face-command)
2247 ;; The command is a lisp function, so we call it.
2248 (funcall gnus-article-x-face-command face))
2250 (error "%s is not a function"
2251 gnus-article-x-face-command)))))))))
2253 (defun article-decode-mime-words ()
2254 "Decode all MIME-encoded words in the article."
2257 (set-buffer gnus-article-buffer)
2258 (let ((inhibit-point-motion-hooks t)
2260 (mail-parse-charset gnus-newsgroup-charset)
2261 (mail-parse-ignored-charsets
2262 (save-excursion (set-buffer gnus-summary-buffer)
2263 gnus-newsgroup-ignored-charsets)))
2264 (mail-decode-encoded-word-region (point-min) (point-max)))))
2266 (defun article-decode-charset (&optional prompt)
2267 "Decode charset-encoded text in the article.
2268 If PROMPT (the prefix), prompt for a coding system to use."
2270 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2272 (mail-parse-charset gnus-newsgroup-charset)
2273 (mail-parse-ignored-charsets
2274 (save-excursion (condition-case nil
2275 (set-buffer gnus-summary-buffer)
2277 gnus-newsgroup-ignored-charsets))
2278 ct cte ctl charset format)
2281 (article-narrow-to-head)
2282 (setq ct (message-fetch-field "Content-Type" t)
2283 cte (message-fetch-field "Content-Transfer-Encoding" t)
2284 ctl (and ct (ignore-errors
2285 (mail-header-parse-content-type ct)))
2288 (mm-read-coding-system "Charset to decode: "))
2290 (mail-content-type-get ctl 'charset)))
2291 format (and ctl (mail-content-type-get ctl 'format)))
2293 (setq cte (mail-header-strip cte)))
2294 (if (and ctl (not (string-match "/" (car ctl))))
2296 (goto-char (point-max)))
2299 (narrow-to-region (point) (point-max))
2300 (when (and (eq mail-parse-charset 'gnus-decoded)
2301 (eq (mm-body-7-or-8) '8bit))
2302 ;; The text code could have been decoded.
2303 (setq charset mail-parse-charset))
2304 (when (and (or (not ctl)
2305 (equal (car ctl) "text/plain"))
2306 (not format)) ;; article with format will decode later.
2308 charset (and cte (intern (downcase
2309 (gnus-strip-whitespace cte))))
2312 (defun article-decode-encoded-words ()
2313 "Remove encoded-word encoding from headers."
2314 (let (buffer-read-only)
2315 (let ((charset (save-excursion
2316 (set-buffer gnus-summary-buffer)
2317 default-mime-charset)))
2318 (mime-decode-header-in-buffer charset))))
2320 (defun article-decode-group-name ()
2321 "Decode group names in `Newsgroups:'."
2322 (let ((inhibit-point-motion-hooks t)
2324 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2325 (when (and (or gnus-group-name-charset-method-alist
2326 gnus-group-name-charset-group-alist)
2327 (gnus-buffer-live-p gnus-original-article-buffer))
2329 (article-narrow-to-head)
2330 (with-current-buffer gnus-original-article-buffer
2331 (goto-char (point-min)))
2332 (while (re-search-forward
2333 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2334 (replace-match (save-match-data
2335 (gnus-decode-newsgroups
2336 ;; XXX how to use data in article buffer?
2337 (with-current-buffer gnus-original-article-buffer
2339 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2342 gnus-newsgroup-name method))
2344 (goto-char (point-min))
2345 (with-current-buffer gnus-original-article-buffer
2346 (goto-char (point-min)))
2347 (while (re-search-forward
2348 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2349 (replace-match (save-match-data
2350 (gnus-decode-newsgroups
2351 ;; XXX how to use data in article buffer?
2352 (with-current-buffer gnus-original-article-buffer
2354 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2357 gnus-newsgroup-name method))
2360 (autoload 'idna-to-unicode "idna")
2362 (defun article-decode-idna-rhs ()
2363 "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2366 (let ((inhibit-point-motion-hooks t)
2368 (article-narrow-to-head)
2369 (goto-char (point-min))
2370 (while (re-search-forward "\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2372 (when (save-match-data
2373 (and (setq ace (match-string 1))
2375 (and (re-search-backward "^[^ \t]" nil t)
2376 (looking-at "From\\|To\\|Cc")))
2377 (save-excursion (backward-char)
2378 (message-idna-inside-rhs-p))
2379 (setq unicode (idna-to-unicode ace))))
2380 (unless (string= ace unicode)
2381 (replace-match unicode nil nil nil 1)))))))))
2383 (defun article-de-quoted-unreadable (&optional force read-charset)
2384 "Translate a quoted-printable-encoded article.
2385 If FORCE, decode the article whether it is marked as quoted-printable
2387 If READ-CHARSET, ask for a coding system."
2388 (interactive (list 'force current-prefix-arg))
2390 (let ((buffer-read-only nil) type charset)
2391 (if (gnus-buffer-live-p gnus-original-article-buffer)
2392 (with-current-buffer gnus-original-article-buffer
2394 (gnus-fetch-field "content-transfer-encoding"))
2395 (let* ((ct (gnus-fetch-field "content-type"))
2398 (mail-header-parse-content-type ct)))))
2399 (setq charset (and ctl
2400 (mail-content-type-get ctl 'charset)))
2401 (if (stringp charset)
2402 (setq charset (intern (downcase charset)))))))
2404 (setq charset (mm-read-coding-system "Charset: " charset)))
2406 (setq charset gnus-newsgroup-charset))
2408 (and type (let ((case-fold-search t))
2409 (string-match "quoted-printable" type))))
2411 (quoted-printable-decode-region
2412 (point) (point-max) (mm-charset-to-coding-system charset))))))
2414 (defun article-de-base64-unreadable (&optional force read-charset)
2415 "Translate a base64 article.
2416 If FORCE, decode the article whether it is marked as base64 not.
2417 If READ-CHARSET, ask for a coding system."
2418 (interactive (list 'force current-prefix-arg))
2420 (let ((buffer-read-only nil) type charset)
2421 (if (gnus-buffer-live-p gnus-original-article-buffer)
2422 (with-current-buffer gnus-original-article-buffer
2424 (gnus-fetch-field "content-transfer-encoding"))
2425 (let* ((ct (gnus-fetch-field "content-type"))
2428 (mail-header-parse-content-type ct)))))
2429 (setq charset (and ctl
2430 (mail-content-type-get ctl 'charset)))
2431 (if (stringp charset)
2432 (setq charset (intern (downcase charset)))))))
2434 (setq charset (mm-read-coding-system "Charset: " charset)))
2436 (setq charset gnus-newsgroup-charset))
2438 (and type (let ((case-fold-search t))
2439 (string-match "base64" type))))
2442 (narrow-to-region (point) (point-max))
2443 (base64-decode-region (point-min) (point-max))
2444 (mm-decode-coding-region
2445 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2450 (defun article-decode-HZ ()
2451 "Translate a HZ-encoded article."
2455 (let ((buffer-read-only nil))
2456 (rfc1843-decode-region (point-min) (point-max)))))
2458 (defun article-unsplit-urls ()
2459 "Remove the newlines that some other mailers insert into URLs."
2462 (let ((buffer-read-only nil))
2463 (goto-char (point-min))
2464 (while (re-search-forward
2465 "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2466 (replace-match "\\1\\3" t)))
2467 (when (interactive-p)
2468 (gnus-treat-article nil))))
2471 (defun article-wash-html (&optional read-charset)
2472 "Format an HTML article.
2473 If READ-CHARSET, ask for a coding system."
2476 (let ((buffer-read-only nil)
2478 (when (gnus-buffer-live-p gnus-original-article-buffer)
2479 (with-current-buffer gnus-original-article-buffer
2480 (let* ((ct (gnus-fetch-field "content-type"))
2483 (mail-header-parse-content-type ct)))))
2484 (setq charset (and ctl
2485 (mail-content-type-get ctl 'charset)))
2486 (when (stringp charset)
2487 (setq charset (intern (downcase charset)))))))
2489 (setq charset (mm-read-coding-system "Charset: " charset)))
2491 (setq charset gnus-newsgroup-charset))
2493 (save-window-excursion
2495 (narrow-to-region (point) (point-max))
2496 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2497 (entry (assq func mm-text-html-washer-alist)))
2499 (setq func (cdr entry)))
2504 (apply (car func) (cdr func))))))))))
2506 (defun gnus-article-wash-html-with-w3 ()
2507 "Wash the current buffer with w3."
2509 (let ((w3-strict-width (window-width))
2510 (url-standalone-mode t)
2511 (url-gateway-unplugged t)
2512 (w3-honor-stylesheets nil))
2514 (w3-region (point-min) (point-max))
2517 (defun gnus-article-wash-html-with-w3m ()
2518 "Wash the current buffer with emacs-w3m."
2521 (narrow-to-region (point) (point-max))
2522 (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2525 w3m-force-redisplay)
2526 (w3m-region (point-min) (point-max)))
2527 (when mm-inline-text-html-with-w3m-keymap
2528 (add-text-properties
2529 (point-min) (point-max)
2530 (nconc (mm-w3m-local-map-property)
2531 '(mm-inline-text-html-with-w3m t))))))
2533 (defun article-hide-list-identifiers ()
2534 "Remove list identifies from the Subject header.
2535 The `gnus-list-identifiers' variable specifies what to do."
2537 (let ((inhibit-point-motion-hooks t)
2538 (regexp (if (consp gnus-list-identifiers)
2539 (mapconcat 'identity gnus-list-identifiers " *\\|")
2540 gnus-list-identifiers))
2545 (article-narrow-to-head)
2546 (goto-char (point-min))
2547 (while (re-search-forward
2548 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2550 (delete-region (match-beginning 2) (match-end 0))
2551 (beginning-of-line))
2552 (when (re-search-forward
2553 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2554 (delete-region (match-beginning 1) (match-end 1))))))))
2556 (defun article-hide-pem (&optional arg)
2557 "Toggle hiding of any PEM headers and signatures in the current article.
2558 If given a negative prefix, always show; if given a positive prefix,
2560 (interactive (gnus-article-hidden-arg))
2561 (unless (gnus-article-check-hidden-text 'pem arg)
2563 (let (buffer-read-only end)
2564 (goto-char (point-min))
2565 ;; Hide the horrendously ugly "header".
2566 (when (and (search-forward
2567 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2569 (setq end (1+ (match-beginning 0))))
2570 (gnus-add-wash-type 'pem)
2571 (gnus-article-hide-text-type
2573 (if (search-forward "\n\n" nil t)
2577 ;; Hide the trailer as well
2578 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2580 (gnus-article-hide-text-type
2581 (match-beginning 0) (match-end 0) 'pem)))))))
2583 (defun article-strip-banner ()
2584 "Strip the banners specified by the `banner' group parameter and by
2585 `gnus-article-address-banner-alist'."
2589 (let ((inhibit-point-motion-hooks t))
2590 (when (gnus-parameter-banner gnus-newsgroup-name)
2591 (article-really-strip-banner
2592 (gnus-parameter-banner gnus-newsgroup-name)))
2593 (when gnus-article-address-banner-alist
2594 (article-really-strip-banner
2595 (let ((from (save-restriction
2597 (article-narrow-to-head)
2598 (mail-fetch-field "from"))))
2601 (caar (mail-header-parse-addresses from))))
2603 (dolist (pair gnus-article-address-banner-alist)
2604 (when (string-match (car pair) from)
2605 (throw 'found (cdr pair)))))))))))))
2607 (defun article-really-strip-banner (banner)
2608 "Strip the banner specified by the argument."
2611 (let ((inhibit-point-motion-hooks t)
2612 (gnus-signature-limit nil)
2616 ((eq banner 'signature)
2617 (when (gnus-article-narrow-to-signature)
2620 (delete-region (point) (point-max))))
2622 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2623 (while (re-search-forward banner nil t)
2624 (delete-region (match-beginning 0) (match-end 0)))))
2626 (while (re-search-forward banner nil t)
2627 (delete-region (match-beginning 0) (match-end 0)))))))))
2629 (defun article-babel ()
2630 "Translate article using an online translation service."
2634 (set-buffer gnus-article-buffer)
2635 (when (article-goto-body)
2636 (let* ((buffer-read-only nil)
2639 (orig (buffer-substring start end))
2640 (trans (babel-as-string orig)))
2642 (narrow-to-region start end)
2643 (delete-region start end)
2646 (defun article-hide-signature (&optional arg)
2647 "Hide the signature in the current article.
2648 If given a negative prefix, always show; if given a positive prefix,
2650 (interactive (gnus-article-hidden-arg))
2656 (article-goto-body))
2657 (goto-char (point-min)))
2658 (unless (gnus-article-check-hidden-text 'signature arg)
2659 (let ((buffer-read-only nil)
2661 (while (setq button (text-property-any button (point-max)
2663 'gnus-signature-toggle))
2664 (setq button (text-property-not-all button (point-max)
2666 'gnus-signature-toggle))
2667 (when (and button (not (eobp)))
2668 (gnus-article-hide-text-type
2670 (next-single-property-change (1+ button) 'mime-view-entity
2673 (gnus-set-mode-line 'article))
2675 (defun article-strip-headers-in-body ()
2676 "Strip offensive headers from bodies."
2680 (let ((case-fold-search t))
2681 (when (looking-at "x-no-archive:")
2682 (gnus-delete-line)))))
2684 (defun article-strip-leading-blank-lines ()
2685 "Remove all blank lines from the beginning of the article."
2688 (let ((inhibit-point-motion-hooks t)
2690 (when (article-goto-body)
2691 (while (and (not (eobp))
2692 (looking-at "[ \t]*$"))
2693 (gnus-delete-line))))))
2695 (defun article-narrow-to-head ()
2696 "Narrow the buffer to the head of the message.
2697 Point is left at the beginning of the narrowed-to region."
2699 (goto-char (point-min))
2700 (if (search-forward "\n\n" nil 1)
2703 (goto-char (point-min)))
2705 (defun article-goto-body ()
2706 "Place point at the start of the body."
2707 (goto-char (point-min))
2709 ;; This variable is only bound when dealing with separate
2711 (article-goto-body-goes-to-point-min-p
2713 ((search-forward "\n\n" nil t)
2716 (goto-char (point-max))
2719 (defun article-strip-multiple-blank-lines ()
2720 "Replace consecutive blank lines with one empty line."
2723 (let ((inhibit-point-motion-hooks t)
2725 ;; First make all blank lines empty.
2727 (while (re-search-forward "^[ \t]+$" nil t)
2728 (unless (gnus-annotation-in-region-p
2729 (match-beginning 0) (match-end 0))
2730 (replace-match "" nil t)))
2731 ;; Then replace multiple empty lines with a single empty line.
2733 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2734 (unless (gnus-annotation-in-region-p
2735 (match-beginning 0) (match-end 0))
2736 (delete-region (match-beginning 1) (match-end 1)))))))
2738 (defun article-strip-leading-space ()
2739 "Remove all white space from the beginning of the lines in the article."
2742 (let ((inhibit-point-motion-hooks t)
2745 (while (re-search-forward "^[ \t]+" nil t)
2746 (replace-match "" t t)))))
2748 (defun article-strip-trailing-space ()
2749 "Remove all white space from the end of the lines in the article."
2752 (let ((inhibit-point-motion-hooks t)
2755 (while (re-search-forward "[ \t]+$" nil t)
2756 (replace-match "" t t)))))
2758 (defun article-strip-blank-lines ()
2759 "Strip leading, trailing and multiple blank lines."
2761 (article-strip-leading-blank-lines)
2762 (article-remove-trailing-blank-lines)
2763 (article-strip-multiple-blank-lines))
2765 (defun article-strip-all-blank-lines ()
2766 "Strip all blank lines."
2769 (let ((inhibit-point-motion-hooks t)
2772 (while (re-search-forward "^[ \t]*\n" nil t)
2773 (replace-match "" t t)))))
2775 (defun gnus-article-narrow-to-signature ()
2776 "Narrow to the signature; return t if a signature is found, else nil."
2777 (let ((inhibit-point-motion-hooks t))
2778 (when (gnus-article-search-signature)
2780 ;; Check whether we have some limits to what we consider
2781 ;; to be a signature.
2782 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2783 (list gnus-signature-limit)))
2785 (while (setq limit (pop limits))
2786 (if (or (and (integerp limit)
2787 (< (- (point-max) (point)) limit))
2789 (< (count-lines (point) (point-max)) limit))
2790 (and (functionp limit)
2792 (and (stringp limit)
2793 (not (re-search-forward limit nil t))))
2794 () ; This limit did not succeed.
2798 (narrow-to-region (point) (point-max))
2801 (defun gnus-article-search-signature ()
2802 "Search the current buffer for the signature separator.
2803 Put point at the beginning of the signature separator."
2804 (let ((cur (point)))
2805 (goto-char (point-max))
2806 (if (if (stringp gnus-signature-separator)
2807 (re-search-backward gnus-signature-separator nil t)
2808 (let ((seps gnus-signature-separator))
2810 (not (re-search-backward (car seps) nil t)))
2817 (defun gnus-article-hidden-arg ()
2818 "Return the current prefix arg as a number, or 0 if no prefix."
2819 (list (if current-prefix-arg
2820 (prefix-numeric-value current-prefix-arg)
2823 (defun gnus-article-check-hidden-text (type arg)
2824 "Return nil if hiding is necessary.
2825 Arg can be nil or a number. nil and positive means hide, negative
2826 means show, 0 means toggle."
2829 (let ((hide (gnus-article-hidden-text-p type)))
2835 (gnus-article-show-hidden-text type)
2838 (if (eq hide 'hidden)
2840 (gnus-article-show-hidden-text type)
2844 (defun gnus-article-hidden-text-p (type)
2845 "Say whether the current buffer contains hidden text of type TYPE."
2846 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2848 (not (get-text-property pos 'invisible))
2849 (not (get-text-property pos 'dummy-invisible)))
2851 (text-property-any (1+ pos) (point-max) 'article-type type)))
2856 (defun gnus-article-show-hidden-text (type &optional dummy)
2857 "Show all hidden text of type TYPE.
2858 Originally it is hide instead of DUMMY."
2859 (let ((buffer-read-only nil)
2860 (inhibit-point-motion-hooks t))
2861 (gnus-remove-text-properties-when
2863 (point-min) (point-max)
2864 (cons 'article-type (cons type
2865 gnus-hidden-properties)))
2866 (gnus-delete-wash-type type)))
2868 (defconst article-time-units
2869 `((year . ,(* 365.25 24 60 60))
2870 (week . ,(* 7 24 60 60))
2871 (day . ,(* 24 60 60))
2875 "Mapping from time units to seconds.")
2877 (defun gnus-article-forward-header ()
2878 "Move point to the start of the next header.
2879 If the current header is a continuation header, this can be several
2884 (if (looking-at "[ \t]+[^ \t]")
2888 (defun article-date-ut (&optional type highlight header)
2889 "Convert DATE date to universal time in the current article.
2890 If TYPE is `local', convert to local time; if it is `lapsed', output
2891 how much time has lapsed since DATE. For `lapsed', the value of
2892 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2893 should replace the \"Date:\" one, or should be added below it."
2894 (interactive (list 'ut t))
2895 (let* ((header (or header
2896 (and (eq 1 (point-min))
2897 (mail-header-date (save-excursion
2898 (set-buffer gnus-summary-buffer)
2899 gnus-current-headers)))
2900 (message-fetch-field "date")
2902 (date (if (vectorp header) (mail-header-date header)
2904 (inhibit-point-motion-hooks t)
2905 bface eface date-pos)
2906 (when (and date (not (string= date "")))
2909 (article-narrow-to-head)
2910 (when (or (and (eq type 'lapsed)
2911 gnus-article-date-lapsed-new-header
2912 ;; Attempt to get the face of X-Sent first.
2913 (re-search-forward "^X-Sent:[ \t]" nil t))
2914 (re-search-forward "^Date:[ \t]" nil t)
2915 ;; If Date is missing, try again for X-Sent.
2916 (re-search-forward "^X-Sent:[ \t]" nil t))
2917 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2918 date (or (get-text-property (gnus-point-at-bol)
2921 eface (get-text-property (1- (gnus-point-at-eol))
2923 (let ((buffer-read-only nil))
2924 ;; Delete any old X-Sent headers.
2925 (when (setq date-pos
2926 (text-property-any (point-min) (point-max)
2927 'article-date-lapsed t))
2928 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2929 (delete-region (match-beginning 0)
2930 (progn (forward-line 1) (point))))
2931 (goto-char (point-min))
2932 ;; Delete any old Date headers.
2933 (while (re-search-forward "^Date:[ \t]" nil t)
2935 (setq date-pos (match-beginning 0)))
2936 (unless (and (eq type 'lapsed)
2937 gnus-article-date-lapsed-new-header)
2938 (delete-region (match-beginning 0)
2939 (progn (message-next-header) (point)))))
2942 (goto-char date-pos)
2944 ;; Possibly, Date has been deleted.
2946 (when (and (eq type 'lapsed)
2947 gnus-article-date-lapsed-new-header
2948 (looking-at "Date:"))
2950 (goto-char (point-min)))
2951 (insert (article-make-date-line date type))
2952 (when (eq type 'lapsed)
2953 (put-text-property (gnus-point-at-bol) (point)
2954 'article-date-lapsed t))
2958 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2959 (put-text-property (match-beginning 1) (1+ (match-end 1))
2960 'original-date date)
2961 (put-text-property (match-beginning 1) (1+ (match-end 1))
2963 (put-text-property (match-beginning 2) (match-end 2)
2966 (defun article-make-date-line (date type)
2967 "Return a DATE line of TYPE."
2968 (unless (memq type '(local ut original user iso8601 lapsed english))
2969 (error "Unknown conversion type: %s" type))
2971 (let ((time (date-to-time date)))
2973 ;; Convert to the local timezone.
2975 (let ((tz (car (current-time-zone time))))
2976 (format "Date: %s %s%02d%02d" (current-time-string time)
2977 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2978 (/ (% (abs tz) 3600) 60))))
2979 ;; Convert to Universal Time.
2982 (current-time-string
2983 (let* ((e (parse-time-string date))
2984 (tm (apply 'encode-time e))
2986 (ls (- (cadr tm) (car (current-time-zone time)))))
2987 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2988 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2991 ;; Get the original date from the article.
2992 ((eq type 'original)
2993 (concat "Date: " (if (string-match "\n+$" date)
2994 (substring date 0 (match-beginning 0))
2996 ;; Let the user define the format.
2998 (let ((format (or (condition-case nil
2999 (with-current-buffer gnus-summary-buffer
3000 gnus-article-time-format)
3002 gnus-article-time-format)))
3003 (if (functionp format)
3004 (funcall format time)
3005 (concat "Date: " (format-time-string format time)))))
3008 (let ((tz (car (current-time-zone time))))
3011 (format-time-string "%Y%m%dT%H%M%S" time)
3012 (format "%s%02d%02d"
3013 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3014 (/ (% (abs tz) 3600) 60)))))
3015 ;; Do an X-Sent lapsed format.
3017 ;; If the date is seriously mangled, the timezone functions are
3018 ;; liable to bug out, so we ignore all errors.
3019 (let* ((now (current-time))
3020 (real-time (subtract-time now time))
3021 (real-sec (and real-time
3022 (+ (* (float (car real-time)) 65536)
3024 (sec (and real-time (abs real-sec)))
3034 ;; This is a bit convoluted, but basically we go
3035 ;; through the time units for years, weeks, etc,
3036 ;; and divide things to see whether that results
3037 ;; in positive answers.
3040 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3041 ;; The (remaining) seconds are too few to
3042 ;; be divided into this time unit.
3044 ;; It's big enough, so we output it.
3045 (setq sec (- sec (* num (cdr unit))))
3047 (concat (if prev ", " "") (int-to-string
3049 " " (symbol-name (car unit))
3050 (if (> num 1) "s" ""))
3052 article-time-units "")
3053 ;; If dates are odd, then it might appear like the
3054 ;; article was sent in the future.
3057 " in the future"))))))
3058 ;; Display the date in proper English
3060 (let ((dtime (decode-time time)))
3063 (number-to-string (nth 3 dtime))
3064 (let ((digit (% (nth 3 dtime) 10)))
3066 ((memq (nth 3 dtime) '(11 12 13)) "th")
3072 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3074 (number-to-string (nth 5 dtime))
3076 (format "%02d" (nth 2 dtime))
3078 (format "%02d" (nth 1 dtime)))))))
3080 (format "Date: %s (from T-gnus)" date))))
3082 (defun article-date-local (&optional highlight)
3083 "Convert the current article date to the local timezone."
3084 (interactive (list t))
3085 (article-date-ut 'local highlight))
3087 (defun article-date-english (&optional highlight)
3088 "Convert the current article date to something that is proper English."
3089 (interactive (list t))
3090 (article-date-ut 'english highlight))
3092 (defun article-date-original (&optional highlight)
3093 "Convert the current article date to what it was originally.
3094 This is only useful if you have used some other date conversion
3095 function and want to see what the date was before converting."
3096 (interactive (list t))
3097 (article-date-ut 'original highlight))
3099 (defun article-date-lapsed (&optional highlight)
3100 "Convert the current article date to time lapsed since it was sent."
3101 (interactive (list t))
3102 (article-date-ut 'lapsed highlight))
3104 (defun article-update-date-lapsed ()
3105 "Function to be run from a timer to update the lapsed time line."
3106 (let (deactivate-mark)
3111 (set-buffer (window-buffer w))
3112 (when (eq major-mode 'gnus-article-mode)
3113 (let ((mark (point-marker)))
3114 (goto-char (point-min))
3115 (when (re-search-forward "^X-Sent:" nil t)
3116 (article-date-lapsed t))
3117 (goto-char (marker-position mark))
3118 (move-marker mark nil))))
3121 (defun gnus-start-date-timer (&optional n)
3122 "Start a timer to update the X-Sent header in the article buffers.
3123 The numerical prefix says how frequently (in seconds) the function
3128 (gnus-stop-date-timer)
3129 (setq article-lapsed-timer
3130 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
3132 (defun gnus-stop-date-timer ()
3133 "Stop the X-Sent timer."
3135 (when article-lapsed-timer
3136 (nnheader-cancel-timer article-lapsed-timer)
3137 (setq article-lapsed-timer nil)))
3139 (defun article-date-user (&optional highlight)
3140 "Convert the current article date to the user-defined format.
3141 This format is defined by the `gnus-article-time-format' variable."
3142 (interactive (list t))
3143 (article-date-ut 'user highlight))
3145 (defun article-date-iso8601 (&optional highlight)
3146 "Convert the current article date to ISO8601."
3147 (interactive (list t))
3148 (article-date-ut 'iso8601 highlight))
3150 ;; (defun article-show-all ()
3151 ;; "Show all hidden text in the article buffer."
3155 ;; (let ((buffer-read-only nil))
3156 ;; (gnus-article-unhide-text (point-min) (point-max))
3157 ;; (gnus-remove-text-with-property 'gnus-prev)
3158 ;; (gnus-remove-text-with-property 'gnus-next))))
3160 (defun article-show-all-headers ()
3161 "Show all hidden headers in the article buffer."
3166 (article-narrow-to-head)
3167 (let ((buffer-read-only nil))
3168 (gnus-article-unhide-text (point-min) (point-max))))))
3170 (defun article-remove-leading-whitespace ()
3171 "Remove excessive whitespace from all headers."
3175 (let ((buffer-read-only nil))
3176 (article-narrow-to-head)
3177 (goto-char (point-min))
3178 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3179 (delete-region (match-beginning 1) (match-end 1)))))))
3181 (defun article-emphasize (&optional arg)
3182 "Emphasize text according to `gnus-emphasis-alist'."
3183 (interactive (gnus-article-hidden-arg))
3184 (unless (gnus-article-check-hidden-text 'emphasis arg)
3188 (with-current-buffer gnus-summary-buffer
3189 gnus-article-emphasis-alist)
3191 gnus-emphasis-alist))
3192 (buffer-read-only nil)
3193 (props (append '(article-type emphasis)
3194 gnus-hidden-properties))
3195 regexp elem beg invisible visible face)
3198 (while (setq elem (pop alist))
3200 (setq regexp (car elem)
3201 invisible (nth 1 elem)
3202 visible (nth 2 elem)
3204 (while (re-search-forward regexp nil t)
3205 (when (and (match-beginning visible) (match-beginning invisible))
3206 (gnus-article-hide-text
3207 (match-beginning invisible) (match-end invisible) props)
3208 (gnus-article-unhide-text-type
3209 (match-beginning visible) (match-end visible) 'emphasis)
3210 (gnus-put-overlay-excluding-newlines
3211 (match-beginning visible) (match-end visible) 'face face)
3212 (gnus-add-wash-type 'emphasis)
3213 (goto-char (match-end invisible)))))))))
3215 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3216 "Setup newsgroup emphasis alist."
3217 (unless gnus-article-emphasis-alist
3218 (let ((name (and gnus-newsgroup-name
3219 (gnus-group-real-name gnus-newsgroup-name))))
3220 (make-local-variable 'gnus-article-emphasis-alist)
3221 (setq gnus-article-emphasis-alist
3223 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3224 (while (setq elem (pop alist))
3225 (when (and name (string-match (car elem) name))
3227 highlight (copy-sequence (cdr elem)))))
3229 (copy-sequence highlight-words)
3230 (if gnus-newsgroup-name
3231 (copy-sequence (gnus-group-find-parameter
3232 gnus-newsgroup-name 'highlight-words t)))
3233 gnus-emphasis-alist)))))
3236 (defvar gnus-summary-article-menu)
3237 (defvar gnus-summary-post-menu))
3239 ;;; Saving functions.
3241 (defun gnus-article-save (save-buffer file &optional num)
3242 "Save the currently selected article."
3243 (unless gnus-save-all-headers
3244 ;; Remove headers according to `gnus-saved-headers'.
3245 (let ((gnus-visible-headers
3246 (or gnus-saved-headers gnus-visible-headers))
3247 (gnus-article-buffer save-buffer))
3249 (set-buffer save-buffer)
3250 (article-hide-headers 1 t))))
3251 (save-window-excursion
3252 (if (not gnus-default-article-saver)
3253 (error "No default saver is defined")
3254 ;; !!! Magic! The saving functions all save
3255 ;; `gnus-save-article-buffer' (or so they think), but we
3256 ;; bind that variable to our save-buffer.
3257 (set-buffer gnus-article-buffer)
3258 (let* ((gnus-save-article-buffer save-buffer)
3261 ((not gnus-prompt-before-saving) 'default)
3262 ((eq gnus-prompt-before-saving 'always) nil)
3264 (gnus-number-of-articles-to-be-saved
3265 (when (eq gnus-prompt-before-saving t)
3267 (set-buffer gnus-article-current-summary)
3268 (funcall gnus-default-article-saver filename)))))
3270 (defun gnus-read-save-file-name (prompt &optional filename
3271 function group headers variable)
3273 (funcall function group headers (symbol-value variable)))
3278 ((eq filename 'default)
3284 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3287 (if (and gnus-number-of-articles-to-be-saved
3288 (> gnus-number-of-articles-to-be-saved 1))
3289 (format "these %d articles"
3290 gnus-number-of-articles-to-be-saved)
3293 ;; Let the split methods have their say.
3295 ;; No split name was found.
3298 (concat prompt " (default "
3299 (file-name-nondirectory default-name) ") ")
3300 (file-name-directory default-name)
3302 ;; A single group name is returned.
3303 ((stringp split-name)
3305 (funcall function split-name headers
3306 (symbol-value variable)))
3308 (concat prompt " (default "
3309 (file-name-nondirectory default-name) ") ")
3310 (file-name-directory default-name)
3312 ;; A single split name was found
3313 ((= 1 (length split-name))
3314 (let* ((name (expand-file-name
3316 gnus-article-save-directory))
3317 (dir (cond ((file-directory-p name)
3318 (file-name-as-directory name))
3319 ((file-exists-p name) name)
3320 (t gnus-article-save-directory))))
3322 (concat prompt " (default " name ") ")
3324 ;; A list of splits was found.
3326 (setq split-name (nreverse split-name))
3328 (let ((file-name-history
3329 (nconc split-name file-name-history)))
3333 (concat prompt " (`M-p' for defaults) ")
3334 gnus-article-save-directory
3336 gnus-article-save-directory)))
3337 (car (push result file-name-history)))))))
3338 ;; Create the directory.
3339 (gnus-make-directory (file-name-directory file))
3340 ;; If we have read a directory, we append the default file name.
3341 (when (file-directory-p file)
3342 (setq file (expand-file-name (file-name-nondirectory
3344 (file-name-as-directory file))))
3345 ;; Possibly translate some characters.
3346 (nnheader-translate-file-chars file))))))
3347 (gnus-make-directory (file-name-directory result))
3348 (set variable result)))
3350 (defun gnus-article-archive-name (group)
3351 "Return the first instance of an \"Archive-name\" in the current buffer."
3352 (let ((case-fold-search t))
3353 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3354 (nnheader-concat gnus-article-save-directory
3355 (match-string 1)))))
3357 (defun gnus-article-nndoc-name (group)
3358 "If GROUP is an nndoc group, return the name of the parent group."
3359 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3360 (gnus-group-get-parameter group 'save-article-group)))
3362 (defun gnus-summary-save-in-rmail (&optional filename)
3363 "Append this article to Rmail file.
3364 Optional argument FILENAME specifies file name.
3365 Directory to save to is default to `gnus-article-save-directory'."
3366 (setq filename (gnus-read-save-file-name
3367 "Save %s in rmail file:" filename
3368 gnus-rmail-save-name gnus-newsgroup-name
3369 gnus-current-headers 'gnus-newsgroup-last-rmail))
3370 (gnus-eval-in-buffer-window gnus-save-article-buffer
3374 (gnus-output-to-rmail filename))))
3377 (defun gnus-summary-save-in-mail (&optional filename)
3378 "Append this article to Unix mail file.
3379 Optional argument FILENAME specifies file name.
3380 Directory to save to is default to `gnus-article-save-directory'."
3381 (setq filename (gnus-read-save-file-name
3382 "Save %s in Unix mail file:" filename
3383 gnus-mail-save-name gnus-newsgroup-name
3384 gnus-current-headers 'gnus-newsgroup-last-mail))
3385 (gnus-eval-in-buffer-window gnus-save-article-buffer
3389 (if (and (file-readable-p filename)
3390 (file-regular-p filename)
3391 (mail-file-babyl-p filename))
3392 (rmail-output-to-rmail-file filename t)
3393 (gnus-output-to-mail filename)))))
3396 (defun gnus-summary-save-in-file (&optional filename overwrite)
3397 "Append this article to file.
3398 Optional argument FILENAME specifies file name.
3399 Directory to save to is default to `gnus-article-save-directory'."
3400 (setq filename (gnus-read-save-file-name
3401 "Save %s in file:" filename
3402 gnus-file-save-name gnus-newsgroup-name
3403 gnus-current-headers 'gnus-newsgroup-last-file))
3404 (gnus-eval-in-buffer-window gnus-save-article-buffer
3408 (when (and overwrite
3409 (file-exists-p filename))
3410 (delete-file filename))
3411 (gnus-output-to-file filename))))
3414 (defun gnus-summary-write-to-file (&optional filename)
3415 "Write this article to a file, overwriting it if the file exists.
3416 Optional argument FILENAME specifies file name.
3417 The directory to save in defaults to `gnus-article-save-directory'."
3418 (gnus-summary-save-in-file nil t))
3420 (defun gnus-summary-save-body-in-file (&optional filename)
3421 "Append this article body to a file.
3422 Optional argument FILENAME specifies file name.
3423 The directory to save in defaults to `gnus-article-save-directory'."
3424 (setq filename (gnus-read-save-file-name
3425 "Save %s body in file:" filename
3426 gnus-file-save-name gnus-newsgroup-name
3427 gnus-current-headers 'gnus-newsgroup-last-file))
3428 (gnus-eval-in-buffer-window gnus-save-article-buffer
3432 (when (article-goto-body)
3433 (narrow-to-region (point) (point-max)))
3434 (gnus-output-to-file filename))))
3437 (defun gnus-summary-save-in-pipe (&optional command)
3438 "Pipe this article to subprocess."
3440 (cond ((and (eq command 'default)
3441 gnus-last-shell-command)
3442 gnus-last-shell-command)
3447 "Shell command on %s: "
3448 (if (and gnus-number-of-articles-to-be-saved
3449 (> gnus-number-of-articles-to-be-saved 1))
3450 (format "these %d articles"
3451 gnus-number-of-articles-to-be-saved)
3453 gnus-last-shell-command))))
3454 (when (string-equal command "")
3455 (if gnus-last-shell-command
3456 (setq command gnus-last-shell-command)
3457 (error "A command is required")))
3458 (gnus-eval-in-buffer-window gnus-article-buffer
3461 (shell-command-on-region (point-min) (point-max) command nil)))
3462 (setq gnus-last-shell-command command))
3464 (defmacro gnus-read-string (prompt &optional initial-contents history
3466 "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3467 (if (and (featurep 'xemacs)
3468 (< emacs-minor-version 2))
3469 `(read-string ,prompt ,initial-contents ,history)
3470 `(read-string ,prompt ,initial-contents ,history ,default-value)))
3472 (defun gnus-summary-pipe-to-muttprint (&optional command)
3473 "Pipe this article to muttprint."
3474 (setq command (gnus-read-string
3475 "Print using command: " gnus-summary-muttprint-program
3476 nil gnus-summary-muttprint-program))
3477 (gnus-summary-save-in-pipe command))
3479 ;;; Article file names when saving.
3481 (defun gnus-capitalize-newsgroup (newsgroup)
3482 "Capitalize NEWSGROUP name."
3483 (when (not (zerop (length newsgroup)))
3484 (concat (char-to-string (upcase (aref newsgroup 0)))
3485 (substring newsgroup 1))))
3487 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3488 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3489 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3490 Otherwise, it is like ~/News/news/group/num."
3493 (concat (if (gnus-use-long-file-name 'not-save)
3494 (gnus-capitalize-newsgroup newsgroup)
3495 (gnus-newsgroup-directory-form newsgroup))
3496 "/" (int-to-string (mail-header-number headers)))
3497 gnus-article-save-directory)))
3499 (string-equal (file-name-directory default)
3500 (file-name-directory last-file))
3501 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3503 (or last-file default))))
3505 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3506 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3507 If variable `gnus-use-long-file-name' is non-nil, it is
3508 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3511 (concat (if (gnus-use-long-file-name 'not-save)
3513 (gnus-newsgroup-directory-form newsgroup))
3514 "/" (int-to-string (mail-header-number headers)))
3515 gnus-article-save-directory)))
3517 (string-equal (file-name-directory default)
3518 (file-name-directory last-file))
3519 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3521 (or last-file default))))
3523 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3524 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3525 If variable `gnus-use-long-file-name' is non-nil, it is
3526 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3529 (if (gnus-use-long-file-name 'not-save)
3532 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3534 gnus-article-save-directory)))
3536 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3537 "Generate file name from sender."
3538 (let ((from (mail-header-from headers)))
3540 (if (and from (string-match "\\([^ <]+\\)@" from))
3541 (match-string 1 from)
3543 gnus-article-save-directory)))
3545 (defun article-verify-x-pgp-sig ()
3548 (if (gnus-buffer-live-p gnus-original-article-buffer)
3549 (let ((sig (with-current-buffer gnus-original-article-buffer
3550 (gnus-fetch-field "X-PGP-Sig")))
3554 (mml2015-clear-verify-function))
3556 (insert-buffer-substring gnus-original-article-buffer)
3557 (setq items (split-string sig))
3558 (message-narrow-to-head)
3559 (let ((inhibit-point-motion-hooks t)
3560 (case-fold-search t))
3561 ;; Don't verify multiple headers.
3562 (setq headers (mapconcat (lambda (header)
3564 (mail-fetch-field header)
3566 (split-string (nth 1 items) ",") "")))
3567 (delete-region (point-min) (point-max))
3568 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3569 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3574 (if (looking-at "^-")
3577 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3578 (insert "Version: " (car items) "\n\n")
3579 (insert (mapconcat 'identity (cddr items) "\n"))
3580 (insert "\n-----END PGP SIGNATURE-----\n")
3581 (let ((mm-security-handle (list (format "multipart/signed"))))
3582 (mml2015-clean-buffer)
3583 (let ((coding-system-for-write (or gnus-newsgroup-charset
3585 (funcall (mml2015-clear-verify-function)))
3587 (or (mm-handle-multipart-ctl-parameter
3588 mm-security-handle 'gnus-details)
3589 (mm-handle-multipart-ctl-parameter
3590 mm-security-handle 'gnus-info)))))
3592 (let (buffer-read-only bface eface)
3594 (message-narrow-to-head)
3595 (goto-char (point-max))
3597 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3598 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3599 (message-remove-header "X-Gnus-PGP-Verify")
3600 (if (re-search-forward "^X-PGP-Sig:" nil t)
3602 (goto-char (point-max)))
3603 (narrow-to-region (point) (point))
3604 (insert "X-Gnus-PGP-Verify: " info "\n")
3605 (goto-char (point-min))
3608 (if (not (looking-at "^[ \t]"))
3612 (goto-char (point-min))
3613 (when (looking-at "\\([^:]+\\): *")
3614 (put-text-property (match-beginning 1) (1+ (match-end 1))
3616 (put-text-property (match-end 0) (point-max)
3617 'face eface)))))))))
3619 (defun article-verify-cancel-lock ()
3620 "Verify Cancel-Lock header."
3622 (if (gnus-buffer-live-p gnus-original-article-buffer)
3623 (canlock-verify gnus-original-article-buffer)))
3625 (defun article-monafy ()
3626 "Display body part with mona font."
3628 (unless (if (featurep 'xemacs)
3629 (find-face 'gnus-mona-face)
3630 (facep 'gnus-mona-face))
3631 (require 'navi2ch-mona)
3632 (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3634 (let ((buffer-read-only nil))
3637 (gnus-make-overlay (point) (point-max))
3638 'face 'gnus-mona-face))))
3645 (setq afunc (car func)
3648 gfunc (intern (format "gnus-%s" func))))
3650 (when (fboundp afunc)
3651 `(lambda (&optional interactive &rest args)
3652 ,(documentation afunc t)
3653 (interactive (list t))
3655 (set-buffer gnus-article-buffer)
3657 (call-interactively ',afunc)
3658 (apply ',afunc args))))))))
3659 '(article-hide-headers
3660 article-verify-x-pgp-sig
3661 article-verify-cancel-lock
3663 article-hide-boring-headers
3664 article-treat-overstrike
3665 article-fill-long-lines
3666 article-capitalize-sentences
3668 article-remove-leading-whitespace
3669 article-display-x-face
3670 article-display-face
3671 article-de-quoted-unreadable
3672 article-de-base64-unreadable
3675 article-unsplit-urls
3676 article-hide-list-identifiers
3677 article-strip-banner
3680 article-hide-signature
3681 article-strip-headers-in-body
3682 article-remove-trailing-blank-lines
3683 article-strip-leading-blank-lines
3684 article-strip-multiple-blank-lines
3685 article-strip-leading-space
3686 article-strip-trailing-space
3687 article-strip-blank-lines
3688 article-strip-all-blank-lines
3690 article-date-english
3691 article-date-iso8601
3692 article-date-original
3694 article-decode-mime-words
3695 article-decode-charset
3696 article-decode-encoded-words
3700 article-treat-dumbquotes
3701 article-normalize-headers
3702 (article-show-all-headers . gnus-article-show-all-headers)
3703 ;; (article-show-all . gnus-article-show-all)
3707 ;;; Gnus article mode
3710 (put 'gnus-article-mode 'mode-class 'special)
3712 (gnus-define-keys gnus-article-mode-map
3713 " " gnus-article-goto-next-page
3714 "\177" gnus-article-goto-prev-page
3715 [delete] gnus-article-goto-prev-page
3716 [backspace] gnus-article-goto-prev-page
3717 "\C-c^" gnus-article-refer-article
3718 "h" gnus-article-show-summary
3719 "s" gnus-article-show-summary
3720 "\C-c\C-m" gnus-article-mail
3721 "?" gnus-article-describe-briefly
3722 "e" gnus-summary-edit-article
3723 "<" beginning-of-buffer
3725 "\C-c\C-i" gnus-info-find-node
3727 "R" gnus-article-reply-with-original
3728 "F" gnus-article-followup-with-original
3729 "\C-hk" gnus-article-describe-key
3730 "\C-hc" gnus-article-describe-key-briefly
3732 "\C-d" gnus-article-read-summary-keys
3733 "\M-*" gnus-article-read-summary-keys
3734 "\M-#" gnus-article-read-summary-keys
3735 "\M-^" gnus-article-read-summary-keys
3736 "\M-g" gnus-article-read-summary-keys)
3738 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3742 (push (char-to-string key) keys)
3744 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3745 (setq key (car elem))
3746 (when (and (> (length key) 0)
3747 (not (eq 'menu-bar (aref key 0)))
3748 (symbolp (lookup-key gnus-summary-mode-map key)))
3751 (unless (lookup-key gnus-article-mode-map key)
3752 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3754 (defun gnus-article-make-menu-bar ()
3755 (unless (boundp 'gnus-article-commands-menu)
3756 (gnus-summary-make-menu-bar))
3757 (gnus-turn-off-edit-menu 'article)
3758 (unless (boundp 'gnus-article-article-menu)
3760 gnus-article-article-menu gnus-article-mode-map ""
3762 ["Scroll forwards" gnus-article-goto-next-page t]
3763 ["Scroll backwards" gnus-article-goto-prev-page t]
3764 ["Show summary" gnus-article-show-summary t]
3765 ["Fetch Message-ID at point" gnus-article-refer-article t]
3766 ["Mail to address at point" gnus-article-mail t]
3767 ["Send a bug report" gnus-bug t]))
3770 gnus-article-treatment-menu gnus-article-mode-map ""
3771 ;; Fixme: this should use :active (and maybe :visible).
3773 ["Hide headers" gnus-article-hide-headers t]
3774 ["Hide signature" gnus-article-hide-signature t]
3775 ["Hide citation" gnus-article-hide-citation t]
3776 ["Treat overstrike" gnus-article-treat-overstrike t]
3777 ["Remove carriage return" gnus-article-remove-cr t]
3778 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3779 ["Treat html" gnus-article-wash-html t]
3780 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3781 ["Decode HZ" gnus-article-decode-HZ t]))
3783 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3785 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3787 (gnus-run-hooks 'gnus-article-menu-hook)))
3789 (defun gnus-article-mode ()
3790 "Major mode for displaying an article.
3792 All normal editing commands are switched off.
3794 The following commands are available in addition to all summary mode
3796 \\<gnus-article-mode-map>
3797 \\[gnus-article-next-page]\t Scroll the article one page forwards
3798 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3799 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3800 \\[gnus-article-show-summary]\t Display the summary buffer
3801 \\[gnus-article-mail]\t Send a reply to the address near point
3802 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3803 \\[gnus-info-find-node]\t Go to the Gnus info node"
3805 (gnus-simplify-mode-line)
3806 (setq mode-name "Article")
3807 (setq major-mode 'gnus-article-mode)
3808 (make-local-variable 'minor-mode-alist)
3809 (unless (assq 'gnus-show-mime minor-mode-alist)
3810 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3811 (use-local-map gnus-article-mode-map)
3812 (when (gnus-visual-p 'article-menu 'menu)
3813 (gnus-article-make-menu-bar)
3814 (when gnus-summary-tool-bar-map
3815 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3816 (gnus-update-format-specifications nil 'article-mode)
3817 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3818 (set (make-local-variable 'gnus-page-broken) nil)
3819 (make-local-variable 'gnus-button-marker-list)
3820 (make-local-variable 'gnus-article-current-summary)
3821 (make-local-variable 'gnus-article-mime-handles)
3822 (make-local-variable 'gnus-article-decoded-p)
3823 (make-local-variable 'gnus-article-mime-handle-alist)
3824 (make-local-variable 'gnus-article-wash-types)
3825 (make-local-variable 'gnus-article-image-alist)
3826 (make-local-variable 'gnus-article-charset)
3827 (make-local-variable 'gnus-article-ignored-charsets)
3828 (gnus-set-default-directory)
3829 (buffer-disable-undo)
3830 (setq buffer-read-only t)
3831 (set-syntax-table gnus-article-mode-syntax-table)
3832 (gnus-run-hooks 'gnus-article-mode-hook))
3834 (defun gnus-article-setup-buffer ()
3835 "Initialize the article buffer."
3836 (let* ((name (if gnus-single-article-buffer "*Article*"
3837 (concat "*Article " gnus-newsgroup-name "*")))
3839 (progn (string-match "\\*Article" name)
3840 (concat " *Original Article"
3841 (substring name (match-end 0))))))
3842 (setq gnus-article-buffer name)
3843 (setq gnus-original-article-buffer original)
3844 (setq gnus-article-mime-handle-alist nil)
3845 ;; This might be a variable local to the summary buffer.
3846 (unless gnus-single-article-buffer
3848 (set-buffer gnus-summary-buffer)
3849 (setq gnus-article-buffer name)
3850 (setq gnus-original-article-buffer original)
3851 (gnus-set-global-variables)))
3852 (gnus-article-setup-highlight-words)
3853 ;; Init original article buffer.
3855 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3856 (set-buffer-multibyte t)
3857 (setq major-mode 'gnus-original-article-mode)
3858 (make-local-variable 'gnus-original-article))
3859 (if (get-buffer name)
3862 (when (and gnus-article-edit-mode
3865 (y-or-n-p "Article mode edit in progress; discard? ")))
3866 (error "Action aborted"))
3867 (set (make-local-variable 'gnus-article-edit-mode) nil)
3868 (buffer-disable-undo)
3869 (setq buffer-read-only t)
3870 ;; This list just keeps growing if we don't reset it.
3871 (setq gnus-button-marker-list nil)
3872 (unless (eq major-mode 'gnus-article-mode)
3873 (gnus-article-mode))
3876 (set-buffer (gnus-get-buffer-create name))
3878 (make-local-variable 'gnus-summary-buffer)
3879 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3880 (current-buffer)))))
3882 ;; Set article window start at LINE, where LINE is the number of lines
3883 ;; from the head of the article.
3884 (defun gnus-article-set-window-start (&optional line)
3886 (gnus-get-buffer-window gnus-article-buffer t)
3888 (set-buffer gnus-article-buffer)
3889 (goto-char (point-min))
3892 (gnus-message 6 "Moved to bookmark")
3893 (search-forward "\n\n" nil t)
3897 ;;; @@ article filters
3900 (defun gnus-article-display-mime-message ()
3901 "Article display method for MIME message."
3902 ;; called from `gnus-original-article-buffer'.
3903 (let (charset all-headers)
3904 (with-current-buffer gnus-summary-buffer
3905 (setq charset default-mime-charset
3906 all-headers gnus-have-all-headers))
3907 (make-local-variable 'default-mime-charset)
3908 (setq default-mime-charset charset)
3909 (with-current-buffer (get-buffer-create gnus-article-buffer)
3910 (make-local-variable 'default-mime-charset)
3911 (setq default-mime-charset charset))
3912 (mime-display-message mime-message-structure
3913 gnus-article-buffer nil gnus-article-mode-map)
3915 (gnus-article-hide-headers nil -1)))
3916 (run-hooks 'gnus-mime-article-prepare-hook))
3918 (defun gnus-article-display-traditional-message ()
3919 "Article display method for traditional message."
3920 (set-buffer gnus-article-buffer)
3921 (let (buffer-read-only)
3923 (insert-buffer-substring gnus-original-article-buffer)))
3925 (defun gnus-article-make-full-mail-header (&optional number charset)
3926 "Create a new mail header structure in a raw article buffer."
3927 (unless (and number charset)
3928 (save-current-buffer
3929 (set-buffer gnus-summary-buffer)
3931 (setq number (or (cdr gnus-article-current) 0)))
3933 (setq charset (or default-mime-charset 'x-ctext)))))
3934 (goto-char (point-min))
3935 (let ((header-end (if (search-forward "\n\n" nil t)
3937 (goto-char (point-max))))
3938 (chars (- (point-max) (point)))
3939 (lines (count-lines (point) (point-max)))
3940 (default-mime-charset charset)
3942 (narrow-to-region (point-min) header-end)
3943 (setq xref (std11-fetch-field "xref"))
3945 (make-full-mail-header
3947 (std11-fetch-field "subject")
3948 (std11-fetch-field "from")
3949 (std11-fetch-field "date")
3950 (std11-fetch-field "message-id")
3951 (std11-fetch-field "references")
3954 (when xref (concat "Xref: " xref)))
3957 (defun gnus-article-prepare (article &optional all-headers header)
3958 "Prepare ARTICLE in article mode buffer.
3959 ARTICLE should either be an article number or a Message-ID.
3960 If ARTICLE is an id, HEADER should be the article headers.
3961 If ALL-HEADERS is non-nil, no headers are hidden."
3963 ;; Make sure we start in a summary buffer.
3964 (unless (eq major-mode 'gnus-summary-mode)
3965 (set-buffer gnus-summary-buffer))
3966 (setq gnus-summary-buffer (current-buffer))
3967 (let* ((gnus-article (if header (mail-header-number header) article))
3968 (summary-buffer (current-buffer))
3969 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3970 (group gnus-newsgroup-name)
3973 (gnus-article-setup-buffer)
3974 (set-buffer gnus-article-buffer)
3975 ;; Deactivate active regions.
3976 (when (and (boundp 'transient-mark-mode)
3977 transient-mark-mode)
3978 (setq mark-active nil))
3979 (if (not (setq result (let ((buffer-read-only nil))
3980 (gnus-request-article-this-buffer
3982 ;; There is no such article.
3984 (when (and (numberp article)
3985 (not (memq article gnus-newsgroup-sparse)))
3986 (setq gnus-article-current
3987 (cons gnus-newsgroup-name article))
3988 (set-buffer gnus-summary-buffer)
3989 (setq gnus-current-article article)
3990 (if (and (memq article gnus-newsgroup-undownloaded)
3991 (not (gnus-online (gnus-find-method-for-group
3992 gnus-newsgroup-name))))
3994 (gnus-summary-set-agent-mark article)
3995 (message "Message marked for downloading"))
3996 (gnus-summary-mark-article article gnus-canceled-mark)
3997 (unless (memq article gnus-newsgroup-sparse)
3998 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3999 (if (or (eq result 'pseudo)
4000 (eq result 'nneething))
4003 (set-buffer summary-buffer)
4004 (push article gnus-newsgroup-history)
4005 (setq gnus-last-article gnus-current-article
4006 gnus-current-article 0
4007 gnus-current-headers nil
4008 gnus-article-current nil)
4009 (if (eq result 'nneething)
4010 (gnus-configure-windows 'summary)
4011 (gnus-configure-windows 'article))
4012 (gnus-set-global-variables))
4013 (let ((gnus-article-mime-handle-alist-1
4014 gnus-article-mime-handle-alist))
4015 (gnus-set-mode-line 'article)))
4016 ;; The result from the `request' was an actual article -
4017 ;; or at least some text that is now displayed in the
4019 (when (and (numberp article)
4020 (not (eq article gnus-current-article)))
4021 ;; Seems like a new article has been selected.
4022 ;; `gnus-current-article' must be an article number.
4024 (set-buffer summary-buffer)
4025 (push article gnus-newsgroup-history)
4026 (setq gnus-last-article gnus-current-article
4027 gnus-current-article article
4028 gnus-current-headers
4029 (gnus-summary-article-header gnus-current-article)
4030 gnus-article-current
4031 (cons gnus-newsgroup-name gnus-current-article))
4032 (unless (vectorp gnus-current-headers)
4033 (setq gnus-current-headers nil))
4034 (gnus-summary-goto-subject gnus-current-article)
4035 (when (gnus-summary-show-thread)
4036 ;; If the summary buffer really was folded, the
4037 ;; previous goto may not actually have gone to
4038 ;; the right article, but the thread root instead.
4040 (gnus-summary-goto-subject gnus-current-article))
4041 (gnus-run-hooks 'gnus-mark-article-hook)
4042 (gnus-set-mode-line 'summary)
4043 (when (gnus-visual-p 'article-highlight 'highlight)
4044 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4045 ;; Set the global newsgroup variables here.
4046 (gnus-set-global-variables)
4047 (setq gnus-have-all-headers
4048 (or all-headers gnus-show-all-headers))))
4050 (gnus-configure-windows 'article))
4051 (when (or (numberp article)
4053 (gnus-article-prepare-display)
4055 (goto-char (point-min))
4056 (when gnus-break-pages
4057 (gnus-narrow-to-page)))
4058 (let ((gnus-article-mime-handle-alist-1
4059 gnus-article-mime-handle-alist))
4060 (gnus-set-mode-line 'article))
4064 (set-window-point (get-buffer-window (current-buffer)) (point))
4065 (gnus-configure-windows 'article)
4068 (defun gnus-article-prepare-mime-display (&optional number)
4069 (goto-char (point-min))
4070 (when (re-search-forward "^[^\t ]+:" nil t)
4071 (goto-char (match-beginning 0)))
4072 (let ((entity (if (eq 1 (point-min))
4073 (get-text-property 1 'mime-view-entity)
4074 (get-text-property (point) 'mime-view-entity)))
4075 last-entity child-entity next type)
4076 (setq child-entity (mime-entity-children entity))
4078 (setq last-entity (nth (1- (length child-entity))
4080 (setq last-entity entity))
4082 (narrow-to-region (point)
4083 (if (search-forward "\n\n" nil t)
4086 (gnus-treat-article 'head)
4087 (put-text-property (point-min) (point-max) 'article-treated-header t)
4088 (goto-char (point-max)))
4089 (while (and (not (eobp)) entity)
4090 (setq next (set-marker
4092 (next-single-property-change (point) 'mime-view-entity
4094 (let ((types (mime-entity-content-type entity)))
4095 (while (eq 'multipart (mime-content-type-primary-type types))
4096 (setq entity (car (mime-entity-children entity))
4097 types (mime-entity-content-type entity)))
4099 (setq type (format "%s/%s"
4100 (mime-content-type-primary-type types)
4101 (mime-content-type-subtype types)))))
4102 (if (string-equal type "message/rfc822")
4105 (let ((children (mime-entity-children entity))
4108 (setq last-children (nth (1- (length children)) children))
4111 (not (eq last-children
4112 (get-text-property next 'mime-view-entity)))
4114 (next-single-property-change next
4116 nil (point-max)))))))
4117 (setq next (next-single-property-change next 'mime-view-entity
4120 (narrow-to-region (point) next)
4121 (gnus-article-prepare-mime-display)
4122 (goto-char (point-max)))
4123 (setq entity (get-text-property (point) 'mime-view-entity)))
4125 (narrow-to-region (point) next)
4126 ;; Kludge. We have to count true number, but for now,
4127 ;; part number is here only to achieve `last'.
4128 (gnus-treat-article nil 1
4129 (if (eq entity last-entity)
4132 (goto-char (point-max)))
4133 (setq entity (get-text-property next 'mime-view-entity))))))
4136 (defun gnus-article-prepare-display ()
4137 "Make the current buffer look like a nice article."
4138 (let ((gnus-article-buffer (current-buffer))
4140 (unless (eq major-mode 'gnus-article-mode)
4141 (gnus-article-mode))
4142 (setq buffer-read-only nil
4143 gnus-button-marker-list nil
4144 gnus-article-wash-types nil
4145 gnus-article-image-alist nil)
4148 (static-if (featurep 'xemacs)
4149 (map-extents (lambda (extent maparg) (delete-extent extent)))
4150 (let ((lists (overlay-lists)))
4151 (dolist (overlay (nconc (car lists) (cdr lists)))
4152 (delete-overlay overlay)))))
4153 (gnus-run-hooks 'gnus-tmp-internal-hook))
4154 (let ((show-mime (unless (member gnus-newsgroup-name '("nndraft:delayed"
4157 (inhibit-read-only t))
4158 (set-buffer gnus-original-article-buffer)
4160 (setq mime-message-structure gnus-current-headers)
4161 (mime-buffer-entity-set-buffer-internal mime-message-structure
4162 gnus-original-article-buffer)
4163 (mime-entity-set-representation-type-internal mime-message-structure
4164 'mime-buffer-entity)
4165 (luna-send mime-message-structure 'initialize-instance
4166 mime-message-structure)
4168 (let (mime-display-header-hook mime-display-text/plain-hook)
4169 (funcall gnus-article-display-method-for-mime))
4170 (funcall gnus-article-display-method-for-traditional))
4171 ;; Call the treatment functions.
4175 (gnus-article-prepare-mime-display)
4176 (narrow-to-region (goto-char (point-min))
4177 (if (search-forward "\n\n" nil t)
4180 (gnus-treat-article 'head)
4181 (put-text-property (point-min) (point-max) 'article-treated-header t)
4182 (goto-char (point-max))
4184 (narrow-to-region (point) (point-max))
4185 (gnus-treat-article nil))
4186 (put-text-property (point-min) (point-max) 'read-only nil)))
4187 (gnus-run-hooks 'gnus-article-prepare-hook))
4189 (defun gnus-article-decode-article-as-default-mime-charset ()
4190 "Decode an article as `default-mime-charset'. It won't work if the
4191 value of the variable `gnus-show-mime' is non-nil."
4192 (unless (or gnus-show-mime
4193 (member gnus-newsgroup-name '("nndraft:delayed"
4195 (set (make-local-variable 'default-mime-charset)
4196 (with-current-buffer gnus-summary-buffer
4197 default-mime-charset))
4198 (decode-mime-charset-region (point-min) (point-max)
4199 default-mime-charset)))
4202 ;;; Gnus MIME viewing functions
4205 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4206 "Format of the MIME buttons.
4208 Valid specifiers include:
4210 %T MIME type, along with additional info
4211 %n The `name' parameter
4212 %d The description, if any
4213 %l The length of the encoded part
4214 %p The part identifier number
4215 %e Dots if the part isn't displayed
4217 General format specifiers can also be used. See Info node
4218 `(gnus)Formatting Variables'.")
4220 (defvar gnus-mime-button-line-format-alist
4221 '((?t gnus-tmp-type ?s)
4222 (?T gnus-tmp-type-long ?s)
4223 (?n gnus-tmp-name ?s)
4224 (?d gnus-tmp-description ?s)
4226 (?l gnus-tmp-length ?d)
4227 (?e gnus-tmp-dots ?s)))
4229 (defvar gnus-mime-button-commands
4230 '((gnus-article-press-button "\r" "Toggle Display")
4231 (gnus-mime-view-part "v" "View Interactively...")
4232 (gnus-mime-view-part-as-type "t" "View As Type...")
4233 (gnus-mime-view-part-as-charset "C" "View As charset...")
4234 (gnus-mime-save-part "o" "Save...")
4235 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4236 (gnus-mime-delete-part "d" "Delete part")
4237 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4238 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4239 (gnus-mime-view-part-internally "E" "View Internally")
4240 (gnus-mime-view-part-externally "e" "View Externally")
4241 (gnus-mime-print-part "p" "Print")
4242 (gnus-mime-pipe-part "|" "Pipe To Command...")
4243 (gnus-mime-action-on-part "." "Take action on the part...")))
4245 (defun gnus-article-mime-part-status ()
4246 (with-current-buffer gnus-article-buffer
4247 (let ((entity (get-text-property (point-min) 'mime-view-entity))
4250 (setq children (mime-entity-children entity))
4251 (setq children (length children)))
4254 (format " (%d parts)" children))
4257 (defvar gnus-mime-button-map
4258 (let ((map (make-sparse-keymap)))
4259 (unless (>= (string-to-number emacs-version) 21)
4260 ;; XEmacs doesn't care.
4261 (set-keymap-parent map gnus-article-mode-map))
4262 (define-key map gnus-mouse-2 'gnus-article-push-button)
4263 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4264 (dolist (c gnus-mime-button-commands)
4265 (define-key map (cadr c) (car c)))
4269 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4271 ,@(mapcar (lambda (c)
4272 (vector (caddr c) (car c) :enable t))
4273 gnus-mime-button-commands)))
4276 (define-compiler-macro popup-menu (&whole form
4277 menu &optional position prefix)
4278 (if (and (fboundp 'popup-menu)
4279 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4281 ;; Gnus is probably running under Emacs 20.
4282 `(let* ((menu (cdr ,menu))
4283 (response (x-popup-menu
4285 (cons "" (mapcar (lambda (c)
4286 (cons (caddr c) (car c)))
4289 (call-interactively (nth 3 (assq response menu))))))))
4291 (defun gnus-mime-button-menu (event prefix)
4292 "Construct a context-sensitive menu of MIME commands."
4293 (interactive "e\nP")
4294 (save-window-excursion
4295 (let ((pos (event-start event)))
4296 (select-window (posn-window pos))
4297 (goto-char (posn-point pos))
4298 (gnus-article-check-buffer)
4299 (popup-menu gnus-mime-button-menu nil prefix))))
4301 (defun gnus-mime-view-all-parts (&optional handles)
4302 "View all the MIME parts."
4304 (save-current-buffer
4305 (set-buffer gnus-article-buffer)
4306 (let ((handles (or handles gnus-article-mime-handles))
4307 (mail-parse-charset gnus-newsgroup-charset)
4308 (mail-parse-ignored-charsets
4309 (with-current-buffer gnus-summary-buffer
4310 gnus-newsgroup-ignored-charsets)))
4312 (mm-remove-parts handles)
4313 (goto-char (point-min))
4314 (or (search-forward "\n\n") (goto-char (point-max)))
4315 (let (buffer-read-only)
4316 (delete-region (point) (point-max))
4317 (mm-display-parts handles))))))
4319 (defun gnus-mime-save-part-and-strip ()
4320 "Save the MIME part under point then replace it with an external body."
4322 (gnus-article-check-buffer)
4323 (let* ((data (get-text-property (point) 'gnus-data))
4325 (handles gnus-article-mime-handles))
4326 (if (mm-multiple-handles gnus-article-mime-handles)
4327 (error "This function is not implemented"))
4328 (setq file (and data (mm-save-part data)))
4330 (with-current-buffer (mm-handle-buffer data)
4332 (insert "Content-Type: " (mm-handle-media-type data))
4333 (mml-insert-parameter-string (cdr (mm-handle-type data))
4336 (insert "Content-ID: " (message-make-message-id) "\n")
4337 (insert "Content-Transfer-Encoding: binary\n")
4340 (cdr (mm-make-handle nil
4341 `("message/external-body"
4342 (access-type . "LOCAL-FILE")
4344 (set-buffer gnus-summary-buffer)
4345 (gnus-article-edit-article
4348 (let ((mail-parse-charset (or gnus-article-charset
4349 ',gnus-newsgroup-charset))
4350 (mail-parse-ignored-charsets
4351 (or gnus-article-ignored-charsets
4352 ',gnus-newsgroup-ignored-charsets))
4353 (mbl mml-buffer-list))
4354 (setq mml-buffer-list nil)
4355 (insert-buffer gnus-original-article-buffer)
4356 (mime-to-mml ',handles)
4357 (setq gnus-article-mime-handles nil)
4358 (let ((mbl1 mml-buffer-list))
4359 (setq mml-buffer-list mbl)
4360 (set (make-local-variable 'mml-buffer-list) mbl1))
4361 (gnus-make-local-hook 'kill-buffer-hook)
4362 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4363 `(lambda (no-highlight)
4364 (let ((mail-parse-charset (or gnus-article-charset
4365 ',gnus-newsgroup-charset))
4366 (message-options message-options)
4367 (message-options-set-recipient)
4368 (mail-parse-ignored-charsets
4369 (or gnus-article-ignored-charsets
4370 ',gnus-newsgroup-ignored-charsets)))
4372 (mml-destroy-buffers)
4373 (remove-hook 'kill-buffer-hook
4374 'mml-destroy-buffers t)
4375 (kill-local-variable 'mml-buffer-list))
4376 (gnus-summary-edit-article-done
4377 ,(or (mail-header-references gnus-current-headers) "")
4378 ,(gnus-group-read-only-p)
4379 ,gnus-summary-buffer no-highlight))))))
4381 (defun gnus-mime-delete-part ()
4382 "Delete the MIME part under point.
4383 Replace it with some information about the removed part."
4385 (gnus-article-check-buffer)
4386 (unless (and gnus-novice-user
4387 (not (gnus-yes-or-no-p
4388 "Really delete attachment forever? ")))
4389 (let* ((data (get-text-property (point) 'gnus-data))
4390 (handles gnus-article-mime-handles)
4394 (mail-decode-encoded-word-string (or (mm-handle-description data)
4397 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4399 (type (mm-handle-media-type data)))
4400 (if (mm-multiple-handles gnus-article-mime-handles)
4401 (error "This function is not implemented"))
4402 (with-current-buffer (mm-handle-buffer data)
4403 (let ((bsize (format "%s" (buffer-size))))
4408 "| The following attachment has been deleted:\n"
4410 "| Type: " type "\n"
4411 "| Filename: " filename "\n"
4412 "| Size (encoded): " bsize " Byte\n"
4413 "| Description: " description "\n"
4416 (cdr (mm-make-handle
4417 nil `("text/plain") nil nil
4419 (format "Deleted attachment (%s bytes)" bsize))))))
4420 (set-buffer gnus-summary-buffer)
4421 ;; FIXME: maybe some of the following code (borrowed from
4422 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4423 (gnus-article-edit-article
4426 (let ((mail-parse-charset (or gnus-article-charset
4427 ',gnus-newsgroup-charset))
4428 (mail-parse-ignored-charsets
4429 (or gnus-article-ignored-charsets
4430 ',gnus-newsgroup-ignored-charsets))
4431 (mbl mml-buffer-list))
4432 (setq mml-buffer-list nil)
4433 (insert-buffer gnus-original-article-buffer)
4434 (mime-to-mml ',handles)
4435 (setq gnus-article-mime-handles nil)
4436 (let ((mbl1 mml-buffer-list))
4437 (setq mml-buffer-list mbl)
4438 (set (make-local-variable 'mml-buffer-list) mbl1))
4439 (gnus-make-local-hook 'kill-buffer-hook)
4440 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4441 `(lambda (no-highlight)
4442 (let ((mail-parse-charset (or gnus-article-charset
4443 ',gnus-newsgroup-charset))
4444 (message-options message-options)
4445 (message-options-set-recipient)
4446 (mail-parse-ignored-charsets
4447 (or gnus-article-ignored-charsets
4448 ',gnus-newsgroup-ignored-charsets)))
4450 (mml-destroy-buffers)
4451 (remove-hook 'kill-buffer-hook
4452 'mml-destroy-buffers t)
4453 (kill-local-variable 'mml-buffer-list))
4454 (gnus-summary-edit-article-done
4455 ,(or (mail-header-references gnus-current-headers) "")
4456 ,(gnus-group-read-only-p)
4457 ,gnus-summary-buffer no-highlight)))))
4458 ;; Not in `gnus-mime-save-part-and-strip':
4459 (gnus-article-edit-done)
4460 (gnus-summary-expand-window)
4461 (gnus-summary-show-article))
4463 (defun gnus-mime-save-part ()
4464 "Save the MIME part under point."
4466 (gnus-article-check-buffer)
4467 (let ((data (get-text-property (point) 'gnus-data)))
4469 (mm-save-part data))))
4471 (defun gnus-mime-pipe-part ()
4472 "Pipe the MIME part under point to a process."
4474 (gnus-article-check-buffer)
4475 (let ((data (get-text-property (point) 'gnus-data)))
4477 (mm-pipe-part data))))
4479 (defun gnus-mime-view-part ()
4480 "Interactively choose a viewing method for the MIME part under point."
4482 (gnus-article-check-buffer)
4483 (let ((data (get-text-property (point) 'gnus-data)))
4485 (setq gnus-article-mime-handles
4487 gnus-article-mime-handles (setq data (copy-sequence data))))
4488 (mm-interactively-view-part data))))
4490 (defun gnus-mime-view-part-as-type-internal ()
4491 (gnus-article-check-buffer)
4492 (let* ((name (mail-content-type-get
4493 (mm-handle-type (get-text-property (point) 'gnus-data))
4495 (def-type (and name (mm-default-file-encoding name))))
4496 (and def-type (cons def-type 0))))
4498 (defun gnus-mime-view-part-as-type (&optional mime-type)
4499 "Choose a MIME media type, and view the part as such."
4502 (setq mime-type (completing-read
4503 "View as MIME type: "
4504 (mapcar #'list (mailcap-mime-types))
4506 (gnus-mime-view-part-as-type-internal))))
4507 (gnus-article-check-buffer)
4508 (let ((handle (get-text-property (point) 'gnus-data)))
4511 (mm-make-handle (mm-handle-buffer handle)
4512 (cons mime-type (cdr (mm-handle-type handle)))
4513 (mm-handle-encoding handle)
4514 (mm-handle-undisplayer handle)
4515 (mm-handle-disposition handle)
4516 (mm-handle-description handle)
4518 (mm-handle-id handle)))
4519 (setq gnus-article-mime-handles
4520 (mm-merge-handles gnus-article-mime-handles handle))
4521 (gnus-mm-display-part handle))))
4524 (require 'jka-compr))
4526 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4527 ;; emacs can do that itself.
4529 (defun gnus-mime-jka-compr-maybe-uncompress ()
4530 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4531 The uncompress method used is derived from `buffer-file-name'."
4532 (when (and (fboundp 'jka-compr-installed-p)
4533 (jka-compr-installed-p))
4534 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4536 (let ((basename (file-name-nondirectory buffer-file-name))
4537 (args (jka-compr-info-uncompress-args info))
4538 (prog (jka-compr-info-uncompress-program info))
4539 (message (jka-compr-info-uncompress-message info))
4540 (err-file (jka-compr-make-temp-name)))
4542 (message "%s %s..." message basename))
4544 (unless (memq (apply 'call-process-region
4545 (point-min) (point-max)
4547 t (list t err-file) nil
4549 jka-compr-acceptable-retval-list)
4550 (jka-compr-error prog args basename message err-file))
4551 (jka-compr-delete-temp-file err-file)))))))
4553 (defun gnus-mime-copy-part (&optional handle)
4554 "Put the MIME part under point into a new buffer.
4555 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4558 (gnus-article-check-buffer)
4559 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4560 (contents (and handle (mm-get-part handle)))
4562 (file-name-nondirectory
4564 (mail-content-type-get (mm-handle-type handle) 'name)
4565 (mail-content-type-get (mm-handle-disposition handle)
4568 (buffer (and base (generate-new-buffer base))))
4570 (switch-to-buffer buffer)
4572 ;; We do it this way to make `normal-mode' set the appropriate mode.
4575 (setq buffer-file-name (expand-file-name base))
4576 (gnus-mime-jka-compr-maybe-uncompress)
4578 (setq buffer-file-name nil))
4579 (goto-char (point-min)))))
4581 (defun gnus-mime-print-part (&optional handle filename)
4582 "Print the MIME part under point."
4583 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4584 (gnus-article-check-buffer)
4585 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4586 (contents (and handle (mm-get-part handle)))
4587 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4588 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4593 (mm-save-part-to-file handle file)
4594 (call-process shell-file-name nil
4595 (generate-new-buffer " *mm*")
4597 shell-command-switch
4599 printer file (mm-handle-type handle))))
4603 (gnus-print-buffer))
4604 (ps-despool filename)))))
4606 (defun gnus-mime-inline-part (&optional handle arg)
4607 "Insert the MIME part under point into the current buffer."
4608 (interactive (list nil current-prefix-arg))
4609 (gnus-article-check-buffer)
4610 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4615 (if (and (not arg) (mm-handle-undisplayer handle))
4616 (mm-remove-part handle)
4617 (setq contents (mm-get-part handle))
4620 (setq charset (or (mail-content-type-get
4621 (mm-handle-type handle) 'charset)
4622 gnus-newsgroup-charset)))
4624 (if (mm-handle-undisplayer handle)
4625 (mm-remove-part handle))
4628 gnus-summary-show-article-charset-alist))
4629 (mm-read-coding-system "Charset: ")))))
4631 (mm-insert-inline handle
4633 (setq charset (mm-charset-to-coding-system
4635 (not (eq charset 'ascii)))
4636 (mm-decode-coding-string contents charset)
4640 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4641 "Insert the MIME part under point into the current buffer using the
4643 (interactive (list nil current-prefix-arg))
4644 (gnus-article-check-buffer)
4645 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4650 (if (mm-handle-undisplayer handle)
4651 (mm-remove-part handle))
4652 (let ((gnus-newsgroup-charset
4654 gnus-summary-show-article-charset-alist))
4655 (mm-read-coding-system "Charset: ")))
4656 (gnus-newsgroup-ignored-charsets 'gnus-all))
4657 (gnus-article-press-button)))))
4659 (defun gnus-mime-view-part-externally (&optional handle)
4660 "View the MIME part under point with an external viewer."
4662 (gnus-article-check-buffer)
4663 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4664 (mm-user-display-methods nil)
4665 (mm-inlined-types nil)
4666 (mail-parse-charset gnus-newsgroup-charset)
4667 (mail-parse-ignored-charsets
4668 (save-excursion (set-buffer gnus-summary-buffer)
4669 gnus-newsgroup-ignored-charsets)))
4671 (if (mm-handle-undisplayer handle)
4672 (mm-remove-part handle)
4673 (mm-display-part handle)))))
4675 (defun gnus-mime-view-part-internally (&optional handle)
4676 "View the MIME part under point with an internal viewer.
4677 If no internal viewer is available, use an external viewer."
4679 (gnus-article-check-buffer)
4680 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4681 (mm-inlined-types '(".*"))
4682 (mm-inline-large-images t)
4683 (mail-parse-charset gnus-newsgroup-charset)
4684 (mail-parse-ignored-charsets
4685 (save-excursion (set-buffer gnus-summary-buffer)
4686 gnus-newsgroup-ignored-charsets))
4689 (if (mm-handle-undisplayer handle)
4690 (mm-remove-part handle)
4691 (mm-display-part handle)))))
4693 (defun gnus-mime-action-on-part (&optional action)
4694 "Do something with the MIME attachment at \(point\)."
4696 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4697 (gnus-article-check-buffer)
4698 (let ((action-pair (assoc action gnus-mime-action-alist)))
4700 (funcall (cdr action-pair)))))
4702 (defun gnus-article-part-wrapper (n function)
4703 (save-current-buffer
4704 (set-buffer gnus-article-buffer)
4705 (when (> n (length gnus-article-mime-handle-alist))
4706 (error "No such part"))
4707 (gnus-article-goto-part n)
4708 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4709 (funcall function handle))))
4711 (defun gnus-article-pipe-part (n)
4712 "Pipe MIME part N, which is the numerical prefix."
4714 (gnus-article-part-wrapper n 'mm-pipe-part))
4716 (defun gnus-article-save-part (n)
4717 "Save MIME part N, which is the numerical prefix."
4719 (gnus-article-part-wrapper n 'mm-save-part))
4721 (defun gnus-article-interactively-view-part (n)
4722 "View MIME part N interactively, which is the numerical prefix."
4724 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4726 (defun gnus-article-copy-part (n)
4727 "Copy MIME part N, which is the numerical prefix."
4729 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4731 (defun gnus-article-view-part-as-charset (n)
4732 "View MIME part N using a specified charset.
4733 N is the numerical prefix."
4735 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4737 (defun gnus-article-view-part-externally (n)
4738 "View MIME part N externally, which is the numerical prefix."
4740 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4742 (defun gnus-article-inline-part (n)
4743 "Inline MIME part N, which is the numerical prefix."
4745 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4747 (defun gnus-article-mime-match-handle-first (condition)
4749 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4750 (while (setq ihandle (pop alist))
4752 ((functionp condition)
4753 (funcall condition (cdr ihandle)))
4754 ((eq condition 'undisplayed)
4755 (not (or (mm-handle-undisplayer (cdr ihandle))
4756 (equal (mm-handle-media-type (cdr ihandle))
4757 "multipart/alternative"))))
4758 ((eq condition 'undisplayed-alternative)
4759 (not (mm-handle-undisplayer (cdr ihandle))))
4761 (gnus-article-goto-part (car ihandle))
4762 (or (not n) (< (car ihandle) n)))
4763 (setq n (car ihandle))))
4767 (defun gnus-article-view-part (&optional n)
4768 "View MIME part N, which is the numerical prefix."
4770 (save-current-buffer
4771 (set-buffer gnus-article-buffer)
4772 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4773 gnus-article-mime-match-handle-function)))
4774 (when (> n (length gnus-article-mime-handle-alist))
4775 (error "No such part"))
4776 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4777 (when (gnus-article-goto-part n)
4778 (if (equal (car handle) "multipart/alternative")
4779 (gnus-article-press-button)
4780 (when (eq (gnus-mm-display-part handle) 'internal)
4781 (gnus-set-window-start)))))))
4783 (defsubst gnus-article-mime-total-parts ()
4784 (if (bufferp (car gnus-article-mime-handles))
4786 (1- (length gnus-article-mime-handles))))
4788 (defun gnus-mm-display-part (handle)
4789 "Display HANDLE and fix MIME button."
4790 (let ((id (get-text-property (point) 'gnus-part))
4795 (let ((window (selected-window))
4796 (mail-parse-charset gnus-newsgroup-charset)
4797 (mail-parse-ignored-charsets
4798 (if (gnus-buffer-live-p gnus-summary-buffer)
4800 (set-buffer gnus-summary-buffer)
4801 gnus-newsgroup-ignored-charsets)
4805 (let ((win (gnus-get-buffer-window (current-buffer) t))
4808 (select-window win))
4811 (if (mm-handle-displayed-p handle)
4812 ;; This will remove the part.
4813 (mm-display-part handle)
4815 (narrow-to-region (point)
4816 (if (eobp) (point) (1+ (point))))
4817 (mm-display-part handle)
4818 ;; We narrow to the part itself and
4819 ;; then call the treatment functions.
4820 (goto-char (point-min))
4822 (narrow-to-region (point) (point-max))
4825 (gnus-article-mime-total-parts)
4826 (mm-handle-media-type handle)))))
4827 (if (window-live-p window)
4828 (select-window window)))))
4831 (gnus-insert-mime-button
4832 handle id (list (mm-handle-displayed-p handle)))
4833 (goto-char point))))
4835 (defun gnus-article-goto-part (n)
4836 "Go to MIME part N."
4837 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4839 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4840 (let ((gnus-tmp-name
4841 (or (mail-content-type-get (mm-handle-type handle) 'name)
4842 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4843 (mail-content-type-get (mm-handle-type handle) 'url)
4845 (gnus-tmp-type (mm-handle-media-type handle))
4846 (gnus-tmp-description
4847 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4850 (if (if displayed (car displayed)
4851 (mm-handle-displayed-p handle))
4853 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4855 gnus-tmp-type-long b e)
4856 (when (string-match ".*/" gnus-tmp-name)
4857 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4858 (setq gnus-tmp-type-long (concat gnus-tmp-type
4859 (and (not (equal gnus-tmp-name ""))
4860 (concat "; " gnus-tmp-name))))
4861 (unless (equal gnus-tmp-description "")
4862 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4867 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4868 `(,@(gnus-local-map-property gnus-mime-button-map)
4869 gnus-callback gnus-mm-display-part
4870 gnus-part ,gnus-tmp-id
4871 article-type annotation
4874 ;; Exclude a newline.
4877 (widget-convert-button
4880 :action 'gnus-widget-press-button
4881 :button-keymap gnus-mime-button-map
4883 (lambda (widget/window &optional overlay pos)
4884 ;; Needed to properly clear the message due to a bug in
4885 ;; wid-edit (XEmacs only).
4886 (if (boundp 'help-echo-owns-message)
4887 (setq help-echo-owns-message t))
4889 "%S: %s the MIME part; %S: more options"
4890 (aref gnus-mouse-2 0)
4891 ;; XEmacs will get a single widget arg; Emacs 21 will get
4892 ;; window, overlay, position.
4893 (if (mm-handle-displayed-p
4895 (with-current-buffer (gnus-overlay-buffer overlay)
4896 (widget-get (widget-at (gnus-overlay-start overlay))
4898 (widget-get widget/window :mime-handle)))
4900 (aref gnus-down-mouse-3 0))))))
4902 (defun gnus-widget-press-button (elems el)
4903 (goto-char (widget-get elems :from))
4904 (gnus-article-press-button))
4906 (defvar gnus-displaying-mime nil)
4908 (defun gnus-display-mime (&optional ihandles)
4909 "Display the MIME parts."
4911 (save-selected-window
4912 (let ((window (get-buffer-window gnus-article-buffer))
4915 (select-window window)
4916 ;; We have to do this since selecting the window
4917 ;; may change the point. So we set the window point.
4918 (set-window-point window point)))
4919 (let* ((handles (or ihandles
4920 (mm-dissect-buffer nil gnus-article-loose-mime)
4921 (and gnus-article-emulate-mime
4923 buffer-read-only handle name type b e display)
4924 (when (and (not ihandles)
4925 (not gnus-displaying-mime))
4926 ;; Top-level call; we clean up.
4927 (when gnus-article-mime-handles
4928 (mm-destroy-parts gnus-article-mime-handles)
4929 (setq gnus-article-mime-handle-alist nil));; A trick.
4930 (setq gnus-article-mime-handles handles)
4931 ;; We allow users to glean info from the handles.
4932 (when gnus-article-mime-part-function
4933 (gnus-mime-part-function handles)))
4935 (or (not (stringp (car handles)))
4938 (when (and (not ihandles)
4939 (not gnus-displaying-mime))
4940 ;; Clean up for mime parts.
4942 (delete-region (point) (point-max)))
4943 (let ((gnus-displaying-mime t))
4944 (gnus-mime-display-part handles)))
4947 (narrow-to-region (point) (point-max))
4948 (gnus-treat-article nil 1 1)
4951 ;; Highlight the headers.
4955 (narrow-to-region (point-min) (point))
4956 (gnus-treat-article 'head))))))))
4958 (defcustom gnus-mime-display-multipart-as-mixed nil
4959 "Display \"multipart\" parts as \"multipart/mixed\".
4961 If t, it overrides nil values of
4962 `gnus-mime-display-multipart-alternative-as-mixed' and
4963 `gnus-mime-display-multipart-related-as-mixed'."
4964 :group 'gnus-article-mime
4967 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4968 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4969 :group 'gnus-article-mime
4972 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4973 "Display \"multipart/related\" parts as \"multipart/mixed\".
4975 If displaying \"text/html\" is discouraged \(see
4976 `mm-discouraged-alternatives'\) images or other material inside a
4977 \"multipart/related\" part might be overlooked when this variable is nil."
4978 :group 'gnus-article-mime
4981 (defun gnus-mime-display-part (handle)
4984 ((not (stringp (car handle)))
4985 (gnus-mime-display-single handle))
4986 ;; User-defined multipart
4987 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4988 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4990 ;; multipart/alternative
4991 ((and (equal (car handle) "multipart/alternative")
4992 (not (or gnus-mime-display-multipart-as-mixed
4993 gnus-mime-display-multipart-alternative-as-mixed)))
4994 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4995 (push (cons id handle) gnus-article-mime-handle-alist)
4996 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4997 ;; multipart/related
4998 ((and (equal (car handle) "multipart/related")
4999 (not (or gnus-mime-display-multipart-as-mixed
5000 gnus-mime-display-multipart-related-as-mixed)))
5001 ;;;!!!We should find the start part, but we just default
5002 ;;;!!!to the first part.
5003 ;;(gnus-mime-display-part (cadr handle))
5004 ;;;!!! Most multipart/related is an HTML message plus images.
5005 ;;;!!! Unfortunately we are unable to let W3 display those
5006 ;;;!!! included images, so we just display it as a mixed multipart.
5007 ;;(gnus-mime-display-mixed (cdr handle))
5008 ;;;!!! No, w3 can display everything just fine.
5009 (gnus-mime-display-part (cadr handle)))
5010 ((equal (car handle) "multipart/signed")
5011 (gnus-add-wash-type 'signed)
5012 (gnus-mime-display-security handle))
5013 ((equal (car handle) "multipart/encrypted")
5014 (gnus-add-wash-type 'encrypted)
5015 (gnus-mime-display-security handle))
5016 ;; Other multiparts are handled like multipart/mixed.
5018 (gnus-mime-display-mixed (cdr handle)))))
5020 (defun gnus-mime-part-function (handles)
5021 (if (stringp (car handles))
5022 (mapcar 'gnus-mime-part-function (cdr handles))
5023 (funcall gnus-article-mime-part-function handles)))
5025 (defun gnus-mime-display-mixed (handles)
5026 (mapcar 'gnus-mime-display-part handles))
5028 (defun gnus-mime-display-single (handle)
5029 (let ((type (mm-handle-media-type handle))
5030 (ignored gnus-ignored-mime-types)
5037 (when (string-match (pop ignored) type)
5038 (throw 'ignored nil)))
5039 (if (and (setq not-attachment
5040 (and (not (mm-inline-override-p handle))
5041 (or (not (mm-handle-disposition handle))
5042 (equal (car (mm-handle-disposition handle))
5044 (mm-attachment-override-p handle))))
5045 (mm-automatic-display-p handle)
5047 (mm-inlinable-p handle)
5048 (mm-inlined-p handle))
5049 (mm-automatic-external-display-p type)))
5051 (when (equal (mm-handle-media-supertype handle) "text")
5053 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5055 (push (cons id handle) gnus-article-mime-handle-alist)
5056 (when (or (not display)
5057 (not (gnus-unbuttonized-mime-type-p type)))
5058 ;(gnus-article-insert-newline)
5059 (gnus-insert-mime-button
5060 handle id (list (or display (and not-attachment text))))
5061 (gnus-article-insert-newline)
5062 ;(gnus-article-insert-newline)
5063 ;; Remember modify the number of forward lines.
5071 (let ((mail-parse-charset gnus-newsgroup-charset)
5072 (mail-parse-ignored-charsets
5073 (save-excursion (condition-case ()
5074 (set-buffer gnus-summary-buffer)
5076 gnus-newsgroup-ignored-charsets)))
5077 (mm-display-part handle t))
5078 (goto-char (point-max)))
5079 ((and text not-attachment)
5083 (gnus-article-insert-newline)
5084 (mm-insert-inline handle (mm-get-part handle))
5085 (goto-char (point-max))))
5089 (narrow-to-region beg (point))
5092 (gnus-article-mime-total-parts)
5093 (mm-handle-media-type handle)))))))))
5095 (defun gnus-unbuttonized-mime-type-p (type)
5096 "Say whether TYPE is to be unbuttonized."
5097 (unless gnus-inhibit-mime-unbuttonizing
5099 (let ((types gnus-unbuttonized-mime-types))
5101 (when (string-match (pop types) type)
5102 (throw 'found t)))))
5104 (let ((types gnus-buttonized-mime-types))
5106 (when (string-match (pop types) type)
5107 (throw 'found t)))))))))
5109 (defun gnus-article-insert-newline ()
5110 "Insert a newline, but mark it as undeletable."
5111 (gnus-put-text-property
5112 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5114 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5115 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5118 handle buffer-read-only from props begend not-pref)
5119 (save-window-excursion
5122 (narrow-to-region (car ibegend)
5125 (goto-char (car ibegend))
5128 (delete-region (point-min) (point-max))
5129 (mm-remove-parts handles))
5130 (setq begend (list (point-marker)))
5132 (unless (setq not-pref (cadr (member preferred ihandles)))
5133 (setq not-pref (car ihandles)))
5136 (not (gnus-unbuttonized-mime-type-p
5137 "multipart/alternative")))
5138 (gnus-add-text-properties
5141 (insert (format "%d. " id))
5145 (unless ,(not ibegend)
5146 (setq gnus-article-mime-handle-alist
5147 ',gnus-article-mime-handle-alist))
5148 (gnus-mime-display-alternative
5149 ',ihandles ',not-pref ',begend ,id))
5150 ,@(gnus-local-map-property gnus-mime-button-map)
5151 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5152 face ,gnus-article-button-face
5155 (widget-convert-button 'link from (point)
5156 :action 'gnus-widget-press-button
5157 :button-keymap gnus-widget-button-keymap)
5159 (while (setq handle (pop handles))
5160 (gnus-add-text-properties
5163 (insert (format "(%c) %-18s"
5164 (if (equal handle preferred) ?* ? )
5165 (mm-handle-media-type handle)))
5169 (unless ,(not ibegend)
5170 (setq gnus-article-mime-handle-alist
5171 ',gnus-article-mime-handle-alist))
5172 (gnus-mime-display-alternative
5173 ',ihandles ',handle ',begend ,id))
5174 ,@(gnus-local-map-property gnus-mime-button-map)
5175 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5176 face ,gnus-article-button-face
5179 (widget-convert-button 'link from (point)
5180 :action 'gnus-widget-press-button
5181 :button-keymap gnus-widget-button-keymap)
5185 (if (stringp (car preferred))
5186 (gnus-display-mime preferred)
5187 (let ((mail-parse-charset gnus-newsgroup-charset)
5188 (mail-parse-ignored-charsets
5189 (save-excursion (set-buffer gnus-summary-buffer)
5190 gnus-newsgroup-ignored-charsets)))
5191 (mm-display-part preferred)
5195 (narrow-to-region (car begend) (point-max))
5197 nil (length gnus-article-mime-handle-alist)
5198 (gnus-article-mime-total-parts)
5199 (mm-handle-media-type handle))))))
5200 (goto-char (point-max))
5201 (setcdr begend (point-marker)))))
5203 (goto-char point))))
5205 (defconst gnus-article-wash-status-strings
5206 (let ((alist '((cite "c" "Possible hidden citation text"
5207 " " "All citation text visible")
5208 (headers "h" "Hidden headers"
5209 " " "All headers visible.")
5210 (pgp "p" "Encrypted or signed message status hidden"
5211 " " "No hidden encryption nor digital signature status")
5212 (signature "s" "Signature has been hidden"
5213 " " "Signature is visible")
5214 (overstrike "o" "Overstrike (^H) characters applied"
5215 " " "No overstrike characters applied")
5216 (gnus-show-mime "m" "Mime processing is activated"
5217 " " "Mime processing is not activated")
5218 (emphasis "e" "/*_Emphasis_*/ characters applied"
5219 " " "No /*_emphasis_*/ characters applied")))
5221 (dolist (entry alist result)
5222 (let ((key (nth 0 entry))
5223 (on (copy-sequence (nth 1 entry)))
5224 (on-help (nth 2 entry))
5225 (off (copy-sequence (nth 3 entry)))
5226 (off-help (nth 4 entry)))
5227 (put-text-property 0 1 'help-echo on-help on)
5228 (put-text-property 0 1 'help-echo off-help off)
5229 (push (list key on off) result))))
5230 "Alist of strings describing wash status in the mode line.
5231 Each entry has the form (KEY ON OF), where the KEY is a symbol
5232 representing the particular washing function, ON is the string to use
5233 in the article mode line when the washing function is active, and OFF
5234 is the string to use when it is inactive.")
5236 (defun gnus-article-wash-status-entry (key value)
5237 (let ((entry (assoc key gnus-article-wash-status-strings)))
5238 (if value (nth 1 entry) (nth 2 entry))))
5240 (defun gnus-article-wash-status ()
5241 "Return a string which display status of article washing."
5243 (set-buffer gnus-article-buffer)
5244 (let ((cite (memq 'cite gnus-article-wash-types))
5245 (headers (memq 'headers gnus-article-wash-types))
5246 (boring (memq 'boring-headers gnus-article-wash-types))
5247 (pgp (memq 'pgp gnus-article-wash-types))
5248 (pem (memq 'pem gnus-article-wash-types))
5249 (signed (memq 'signed gnus-article-wash-types))
5250 (encrypted (memq 'encrypted gnus-article-wash-types))
5251 (signature (memq 'signature gnus-article-wash-types))
5252 (overstrike (memq 'overstrike gnus-article-wash-types))
5253 (emphasis (memq 'emphasis gnus-article-wash-types)))
5255 (gnus-article-wash-status-entry 'cite cite)
5256 (gnus-article-wash-status-entry 'headers (or headers boring))
5257 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5258 (gnus-article-wash-status-entry 'signature signature)
5259 (gnus-article-wash-status-entry 'overstrike overstrike)
5260 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
5261 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5263 (defun gnus-add-wash-type (type)
5264 "Add a washing of TYPE to the current status."
5265 (add-to-list 'gnus-article-wash-types type))
5267 (defun gnus-delete-wash-type (type)
5268 "Add a washing of TYPE to the current status."
5269 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5271 (defun gnus-add-image (category image)
5272 "Add IMAGE of CATEGORY to the list of displayed images."
5273 (let ((entry (assq category gnus-article-image-alist)))
5275 (setq entry (list category))
5276 (push entry gnus-article-image-alist))
5277 (nconc entry (list image))))
5279 (defun gnus-delete-images (category)
5280 "Delete all images in CATEGORY."
5281 (let ((entry (assq category gnus-article-image-alist)))
5282 (dolist (image (cdr entry))
5283 (gnus-remove-image image category))
5284 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5285 (gnus-delete-wash-type category)))
5287 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5289 (defun gnus-article-maybe-hide-headers ()
5290 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5291 Provided for backwards compatibility."
5292 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5293 (not (save-excursion (set-buffer gnus-summary-buffer)
5294 gnus-have-all-headers)))
5295 (not gnus-inhibit-hiding))
5296 (gnus-article-hide-headers)))
5300 (defun gnus-output-to-file (file-name)
5301 "Append the current article to a file named FILE-NAME."
5302 (let ((artbuf (current-buffer)))
5304 (insert-buffer-substring artbuf)
5305 ;; Append newline at end of the buffer as separator, and then
5307 (goto-char (point-max))
5309 (let ((file-name-coding-system nnmail-pathname-coding-system)
5310 (pathname-coding-system nnmail-pathname-coding-system))
5311 (write-region-as-binary (point-min) (point-max) file-name 'append))
5314 (defun gnus-narrow-to-page (&optional arg)
5315 "Narrow the article buffer to a page.
5316 If given a numerical ARG, move forward ARG pages."
5318 (setq arg (if arg (prefix-numeric-value arg) 0))
5320 (set-buffer gnus-article-buffer)
5321 (goto-char (point-min))
5323 ;; Remove any old next/prev buttons.
5324 (when (gnus-visual-p 'page-marker)
5325 (let ((buffer-read-only nil))
5326 (gnus-remove-text-with-property 'gnus-prev)
5327 (gnus-remove-text-with-property 'gnus-next)))
5330 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5332 (re-search-forward page-delimiter nil 'move arg)))
5333 (goto-char (match-end 0))
5335 (goto-char (point-min))
5336 (setq gnus-page-broken
5337 (and (re-search-forward page-delimiter nil t) t))))
5338 (when gnus-page-broken
5341 (if (re-search-forward page-delimiter nil 'move)
5344 (when (and (gnus-visual-p 'page-marker)
5345 (not (= (point-min) 1)))
5347 (goto-char (point-min))
5348 (gnus-insert-prev-page-button)))
5349 (when (and (gnus-visual-p 'page-marker)
5350 (< (+ (point-max) 2) (buffer-size)))
5352 (goto-char (point-max))
5353 (gnus-insert-next-page-button))))))
5355 ;; Article mode commands
5357 (defun gnus-article-goto-next-page ()
5358 "Show the next page of the article."
5360 (when (gnus-article-next-page)
5361 (goto-char (point-min))
5362 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5365 (defun gnus-article-goto-prev-page ()
5366 "Show the previous page of the article."
5369 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5370 (gnus-article-prev-page nil)))
5372 ;; This is cleaner but currently breaks `gnus-pick-mode':
5374 ;; (defun gnus-article-goto-next-page ()
5375 ;; "Show the next page of the article."
5377 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5378 ;; (gnus-summary-next-page)))
5380 ;; (defun gnus-article-goto-prev-page ()
5381 ;; "Show the next page of the article."
5383 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5384 ;; (gnus-summary-prev-page)))
5386 (defun gnus-article-next-page (&optional lines)
5387 "Show the next page of the current article.
5388 If end of article, return non-nil. Otherwise return nil.
5389 Argument LINES specifies lines to be scrolled up."
5391 (move-to-window-line -1)
5394 (and (pos-visible-in-window-p) ;Not continuation line.
5395 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5396 ;; Nothing in this page.
5397 (if (or (not gnus-page-broken)
5401 (eobp)))) ;Real end-of-buffer?
5403 (when gnus-article-over-scroll
5404 (gnus-article-next-page-1 lines))
5406 (gnus-narrow-to-page 1) ;Go to next page.
5408 ;; More in this page.
5409 (gnus-article-next-page-1 lines)
5412 (defun gnus-article-next-page-1 (lines)
5413 (let ((scroll-in-place nil))
5417 ;; Long lines may cause an end-of-buffer error.
5418 (goto-char (point-max)))))
5419 (move-to-window-line 0))
5421 (defun gnus-article-prev-page (&optional lines)
5422 "Show previous page of current article.
5423 Argument LINES specifies lines to be scrolled down."
5425 (move-to-window-line 0)
5426 (if (and gnus-page-broken
5428 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5430 (gnus-narrow-to-page -1) ;Go to previous page.
5431 (goto-char (point-max))
5433 (let ((scroll-in-place nil))
5437 (beginning-of-buffer
5438 (goto-char (point-min))))
5439 (move-to-window-line 0)))))
5441 (defun gnus-article-only-boring-p ()
5442 "Decide whether there is only boring text remaining in the article.
5443 Something \"interesting\" is a word of at least two letters that does
5444 not have a face in `gnus-article-boring-faces'."
5445 (when (and gnus-article-skip-boring
5446 (boundp 'gnus-article-boring-faces)
5447 (symbol-value 'gnus-article-boring-faces))
5450 (while (re-search-forward "\\b\\w\\w" nil t)
5452 (when (not (gnus-intersection
5453 (gnus-faces-at (point))
5454 (symbol-value 'gnus-article-boring-faces)))
5455 (throw 'only-boring nil)))
5456 (throw 'only-boring t)))))
5458 (defun gnus-article-refer-article ()
5459 "Read article specified by message-id around point."
5462 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5463 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5464 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5465 (let ((msg-id (concat "<" (match-string 0) ">")))
5466 (set-buffer gnus-summary-buffer)
5467 (gnus-summary-refer-article msg-id))
5468 (error "No references around point"))))
5470 (defun gnus-article-show-summary ()
5471 "Reconfigure windows to show summary buffer."
5473 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5474 (error "There is no summary buffer for this article buffer")
5475 (gnus-article-set-globals)
5476 (gnus-configure-windows 'article)
5477 (gnus-summary-goto-subject gnus-current-article)
5478 (gnus-summary-position-point)))
5480 (defun gnus-article-describe-briefly ()
5481 "Describe article mode commands briefly."
5483 (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")))
5485 (defun gnus-article-summary-command ()
5486 "Execute the last keystroke in the summary buffer."
5488 (let ((obuf (current-buffer))
5489 (owin (current-window-configuration))
5491 (switch-to-buffer gnus-article-current-summary 'norecord)
5492 (setq func (lookup-key (current-local-map) (this-command-keys)))
5493 (call-interactively func)
5495 (set-window-configuration owin)
5496 (set-window-point (get-buffer-window (current-buffer)) (point))))
5498 (defun gnus-article-summary-command-nosave ()
5499 "Execute the last keystroke in the summary buffer."
5502 (pop-to-buffer gnus-article-current-summary 'norecord)
5503 (setq func (lookup-key (current-local-map) (this-command-keys)))
5504 (call-interactively func)))
5506 (defun gnus-article-check-buffer ()
5507 "Beep if not in an article buffer."
5508 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5509 (error "Command invoked outside of a Gnus article buffer")))
5511 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5512 "Read a summary buffer key sequence and execute it from the article buffer."
5514 (gnus-article-check-buffer)
5516 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5517 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5518 "=" "^" "\M-^" "|"))
5524 '("n" "Gn" "p" "Gp"))
5527 (set-buffer gnus-article-current-summary)
5528 (let (gnus-pick-mode)
5529 (push (or key last-command-event) unread-command-events)
5530 (setq keys (static-if (featurep 'xemacs)
5531 (events-to-keys (read-key-sequence nil))
5532 (read-key-sequence nil)))))
5535 (if (or (member keys nosaves)
5536 (member keys nosave-but-article)
5537 (member keys nosave-in-article))
5539 (save-window-excursion
5540 (pop-to-buffer gnus-article-current-summary 'norecord)
5541 ;; We disable the pick minor mode commands.
5542 (let (gnus-pick-mode)
5543 (setq func (lookup-key (current-local-map) keys))))
5547 (unless (member keys nosave-in-article)
5548 (set-buffer gnus-article-current-summary))
5549 (call-interactively func)
5550 (setq new-sum-point (point)))
5551 (when (member keys nosave-but-article)
5552 (pop-to-buffer gnus-article-buffer 'norecord)))
5553 ;; These commands should restore window configuration.
5554 (let ((obuf (current-buffer))
5555 (owin (current-window-configuration))
5557 (summary gnus-article-current-summary)
5558 func in-buffer selected)
5559 (if not-restore-window
5560 (pop-to-buffer summary 'norecord)
5561 (switch-to-buffer summary 'norecord))
5562 (setq in-buffer (current-buffer))
5563 ;; We disable the pick minor mode commands.
5564 (if (and (setq func (let (gnus-pick-mode)
5565 (lookup-key (current-local-map) keys)))
5568 (call-interactively func)
5569 (setq new-sum-point (point))
5570 (when (eq in-buffer (current-buffer))
5571 (setq selected (gnus-summary-select-article))
5573 (unless not-restore-window
5574 (set-window-configuration owin))
5575 (when (eq selected 'old)
5577 (set-window-start (get-buffer-window (current-buffer))
5579 (set-window-point (get-buffer-window (current-buffer))
5581 (let ((win (get-buffer-window gnus-article-current-summary)))
5583 (set-window-point win new-sum-point)))) )
5584 (switch-to-buffer gnus-article-buffer)
5587 (defun gnus-article-describe-key (key)
5588 "Display documentation of the function invoked by KEY. KEY is a string."
5589 (interactive "kDescribe key: ")
5590 (gnus-article-check-buffer)
5591 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5593 (set-buffer gnus-article-current-summary)
5594 (let (gnus-pick-mode)
5595 (if (featurep 'xemacs)
5597 (push (elt key 0) unread-command-events)
5598 (setq key (events-to-keys
5599 (read-key-sequence "Describe key: "))))
5600 (setq unread-command-events
5602 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5604 (setq key (read-key-sequence "Describe key: "))))
5606 (describe-key key)))
5608 (defun gnus-article-describe-key-briefly (key &optional insert)
5609 "Display documentation of the function invoked by KEY. KEY is a string."
5610 (interactive "kDescribe key: \nP")
5611 (gnus-article-check-buffer)
5612 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5614 (set-buffer gnus-article-current-summary)
5615 (let (gnus-pick-mode)
5616 (if (featurep 'xemacs)
5618 (push (elt key 0) unread-command-events)
5619 (setq key (events-to-keys
5620 (read-key-sequence "Describe key: "))))
5621 (setq unread-command-events
5623 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5625 (setq key (read-key-sequence "Describe key: "))))
5626 (describe-key-briefly key insert))
5627 (describe-key-briefly key insert)))
5629 (defun gnus-article-reply-with-original (&optional wide)
5630 "Start composing a reply mail to the current message.
5631 The text in the region will be yanked. If the region isn't active,
5632 the entire article will be yanked."
5634 (let ((article (cdr gnus-article-current))
5636 (if (not (gnus-mark-active-p))
5637 (with-current-buffer gnus-summary-buffer
5638 (gnus-summary-reply (list (list article)) wide))
5639 (setq contents (buffer-substring (point) (mark t)))
5640 ;; Deactivate active regions.
5641 (when (and (boundp 'transient-mark-mode)
5642 transient-mark-mode)
5643 (setq mark-active nil))
5644 (with-current-buffer gnus-summary-buffer
5646 (list (list article contents)) wide)))))
5648 (defun gnus-article-followup-with-original ()
5649 "Compose a followup to the current article.
5650 The text in the region will be yanked. If the region isn't active,
5651 the entire article will be yanked."
5653 (let ((article (cdr gnus-article-current))
5655 (if (not (gnus-mark-active-p))
5656 (with-current-buffer gnus-summary-buffer
5657 (gnus-summary-followup (list (list article))))
5658 (setq contents (buffer-substring (point) (mark t)))
5659 ;; Deactivate active regions.
5660 (when (and (boundp 'transient-mark-mode)
5661 transient-mark-mode)
5662 (setq mark-active nil))
5663 (with-current-buffer gnus-summary-buffer
5664 (gnus-summary-followup
5665 (list (list article contents)))))))
5667 (defun gnus-article-hide (&optional arg force)
5668 "Hide all the gruft in the current article.
5669 This means that signatures, cited text and (some) headers will be
5671 If given a prefix, show the hidden text instead."
5672 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5673 (gnus-article-hide-headers arg)
5674 (gnus-article-hide-list-identifiers arg)
5675 (gnus-article-hide-citation-maybe arg force)
5676 (gnus-article-hide-signature arg))
5678 (defun gnus-article-maybe-highlight ()
5679 "Do some article highlighting if article highlighting is requested."
5680 (when (gnus-visual-p 'article-highlight 'highlight)
5681 (gnus-article-highlight-some)))
5683 (defun gnus-check-group-server ()
5684 ;; Make sure the connection to the server is alive.
5685 (unless (gnus-server-opened
5686 (gnus-find-method-for-group gnus-newsgroup-name))
5687 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5688 (gnus-request-group gnus-newsgroup-name t)))
5691 (autoload 'nneething-get-file-name "nneething"))
5693 (defun gnus-request-article-this-buffer (article group)
5694 "Get an article and insert it into this buffer."
5695 (let (do-update-line sparse-header)
5699 (gnus-kill-all-overlays)
5700 (setq group (or group gnus-newsgroup-name))
5702 ;; Using `gnus-request-article' directly will insert the article into
5703 ;; `nntp-server-buffer' - so we'll save some time by not having to
5704 ;; copy it from the server buffer into the article buffer.
5706 ;; We only request an article by message-id when we do not have the
5707 ;; headers for it, so we'll have to get those.
5708 (when (stringp article)
5709 (gnus-read-header article))
5711 ;; If the article number is negative, that means that this article
5712 ;; doesn't belong in this newsgroup (possibly), so we find its
5713 ;; message-id and request it by id instead of number.
5714 (when (and (numberp article)
5716 (get-buffer gnus-summary-buffer)
5717 (gnus-buffer-exists-p gnus-summary-buffer))
5719 (set-buffer gnus-summary-buffer)
5720 (let ((header (gnus-summary-article-header article)))
5723 ((memq article gnus-newsgroup-sparse)
5724 ;; This is a sparse gap article.
5725 (setq do-update-line article)
5726 (setq article (mail-header-id header))
5727 (setq sparse-header (gnus-read-header article))
5728 (setq gnus-newsgroup-sparse
5729 (delq article gnus-newsgroup-sparse)))
5731 ;; It's a real article.
5732 (setq article (mail-header-id header)))
5734 ;; It is an extracted pseudo-article.
5735 (setq article 'pseudo)
5736 (gnus-request-pseudo-article header))))
5738 (let ((method (gnus-find-method-for-group
5739 gnus-newsgroup-name)))
5740 (when (and (eq (car method) 'nneething)
5742 (let ((dir (nneething-get-file-name
5743 (mail-header-id header))))
5744 (when (and (stringp dir)
5745 (file-directory-p dir))
5746 (setq article 'nneething)
5747 (gnus-group-enter-directory dir))))))))
5750 ;; Refuse to select canceled articles.
5751 ((and (numberp article)
5753 (get-buffer gnus-summary-buffer)
5754 (gnus-buffer-exists-p gnus-summary-buffer)
5755 (eq (cdr (save-excursion
5756 (set-buffer gnus-summary-buffer)
5757 (assq article gnus-newsgroup-reads)))
5758 gnus-canceled-mark))
5760 ;; We first check `gnus-original-article-buffer'.
5761 ((and (get-buffer gnus-original-article-buffer)
5764 (set-buffer gnus-original-article-buffer)
5765 (and (equal (car gnus-original-article) group)
5766 (eq (cdr gnus-original-article) article))))
5767 (insert-buffer-substring gnus-original-article-buffer)
5769 ;; Check the backlog.
5770 ((and gnus-keep-backlog
5771 (gnus-backlog-request-article group article (current-buffer)))
5773 ;; Check asynchronous pre-fetch.
5774 ((gnus-async-request-fetched-article group article (current-buffer))
5775 (gnus-async-prefetch-next group article gnus-summary-buffer)
5776 (when (and (numberp article) gnus-keep-backlog)
5777 (gnus-backlog-enter-article group article (current-buffer)))
5780 ((and gnus-use-cache
5782 (gnus-cache-request-article article group))
5784 ;; Check the agent cache.
5785 ((gnus-agent-request-article article group)
5787 ;; Get the article and put into the article buffer.
5788 ((or (stringp article)
5790 (let ((gnus-override-method gnus-override-method)
5791 (methods (and (stringp article)
5792 gnus-refer-article-method))
5793 (backend (car (gnus-find-method-for-group
5794 gnus-newsgroup-name)))
5796 (buffer-read-only nil))
5797 (if (or (not (listp methods))
5798 (and (symbolp (car methods))
5799 (assq (car methods) nnoo-definition-alist)))
5800 (setq methods (list methods)))
5801 (when (and (null gnus-override-method)
5803 (setq gnus-override-method (pop methods)))
5805 (when (eq gnus-override-method 'current)
5806 (setq gnus-override-method
5807 (with-current-buffer gnus-summary-buffer
5808 gnus-current-select-method)))
5810 (gnus-kill-all-overlays)
5811 (let ((gnus-newsgroup-name group))
5812 (gnus-check-group-server))
5814 ((gnus-request-article article group (current-buffer))
5815 (when (numberp article)
5816 (gnus-async-prefetch-next group article
5817 gnus-summary-buffer)
5818 (when gnus-keep-backlog
5819 (gnus-backlog-enter-article
5820 group article (current-buffer))))
5821 (setq result 'article))
5823 (setq gnus-override-method (pop methods)))
5824 ((not (string-match "^400 "
5825 (nnheader-get-report backend)))
5826 ;; If we get 400 server disconnect, reconnect and
5827 ;; retry; otherwise, assume the article has expired.
5828 (setq result 'done))))
5829 (and (eq result 'article) 'article)))
5833 ;; Associate this article with the current summary buffer.
5834 (setq gnus-article-current-summary gnus-summary-buffer)
5836 ;; Take the article from the original article buffer
5837 ;; and place it in the buffer it's supposed to be in.
5838 (when (and (get-buffer gnus-article-buffer)
5839 (equal (buffer-name (current-buffer))
5840 (buffer-name (get-buffer gnus-article-buffer))))
5842 (if (get-buffer gnus-original-article-buffer)
5843 (set-buffer gnus-original-article-buffer)
5844 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5845 (buffer-disable-undo)
5846 (setq major-mode 'gnus-original-article-mode)
5847 (setq buffer-read-only t))
5848 (let (buffer-read-only)
5850 (insert-buffer-substring gnus-article-buffer))
5851 (setq gnus-original-article (cons group article)))
5854 (run-hooks 'gnus-article-decode-hook)
5855 ;; Mark article as decoded or not.
5856 (setq gnus-article-decoded-p gnus-article-decode-hook))
5858 ;; Update sparse articles.
5859 (when (and do-update-line
5860 (or (numberp article)
5862 (let ((buf (current-buffer)))
5863 (set-buffer gnus-summary-buffer)
5864 (gnus-summary-update-article do-update-line sparse-header)
5865 (gnus-summary-goto-subject do-update-line nil t)
5866 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5868 (set-buffer buf))))))
5874 (defcustom gnus-article-edit-mode-hook nil
5875 "Hook run in article edit mode buffers."
5876 :group 'gnus-article-various
5879 (defcustom gnus-article-edit-article-setup-function
5880 'gnus-article-mime-edit-article-setup
5881 "Function called to setup an editing article buffer."
5882 :group 'gnus-article-various
5885 (defvar gnus-article-edit-done-function nil)
5887 (defvar gnus-article-edit-mode-map nil)
5888 (defvar gnus-article-edit-mode nil)
5890 ;; Should we be using derived.el for this?
5891 (unless gnus-article-edit-mode-map
5892 (setq gnus-article-edit-mode-map (make-keymap))
5893 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5895 (gnus-define-keys gnus-article-edit-mode-map
5896 "\C-c?" describe-mode
5897 "\C-c\C-c" gnus-article-edit-done
5898 "\C-c\C-k" gnus-article-edit-exit
5899 "\C-c\C-f\C-t" message-goto-to
5900 "\C-c\C-f\C-o" message-goto-from
5901 "\C-c\C-f\C-b" message-goto-bcc
5902 ;;"\C-c\C-f\C-w" message-goto-fcc
5903 "\C-c\C-f\C-c" message-goto-cc
5904 "\C-c\C-f\C-s" message-goto-subject
5905 "\C-c\C-f\C-r" message-goto-reply-to
5906 "\C-c\C-f\C-n" message-goto-newsgroups
5907 "\C-c\C-f\C-d" message-goto-distribution
5908 "\C-c\C-f\C-f" message-goto-followup-to
5909 "\C-c\C-f\C-m" message-goto-mail-followup-to
5910 "\C-c\C-f\C-k" message-goto-keywords
5911 "\C-c\C-f\C-u" message-goto-summary
5912 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5913 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5914 "\C-c\C-b" message-goto-body
5915 "\C-c\C-i" message-goto-signature
5917 "\C-c\C-t" message-insert-to
5918 "\C-c\C-n" message-insert-newsgroups
5919 "\C-c\C-o" message-sort-headers
5920 "\C-c\C-e" message-elide-region
5921 "\C-c\C-v" message-delete-not-region
5922 "\C-c\C-z" message-kill-to-signature
5923 "\M-\r" message-newline-and-reformat
5924 "\C-c\C-a" mml-attach-file
5925 "\C-a" message-beginning-of-line
5927 "\M-;" comment-region)
5929 (gnus-define-keys (gnus-article-edit-wash-map
5930 "\C-c\C-w" gnus-article-edit-mode-map)
5931 "f" gnus-article-edit-full-stops))
5934 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5936 ["Fetch To" message-insert-to t]
5937 ["Fetch Newsgroups" message-insert-newsgroups t]
5939 ["To" message-goto-to t]
5940 ["From" message-goto-from t]
5941 ["Subject" message-goto-subject t]
5942 ["Cc" message-goto-cc t]
5943 ["Reply-To" message-goto-reply-to t]
5944 ["Summary" message-goto-summary t]
5945 ["Keywords" message-goto-keywords t]
5946 ["Newsgroups" message-goto-newsgroups t]
5947 ["Followup-To" message-goto-followup-to t]
5948 ["Mail-Followup-To" message-goto-mail-followup-to t]
5949 ["Distribution" message-goto-distribution t]
5950 ["Body" message-goto-body t]
5951 ["Signature" message-goto-signature t]))
5953 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5954 "Major mode for editing articles.
5955 This is an extended text-mode.
5957 \\{gnus-article-edit-mode-map}"
5958 (make-local-variable 'gnus-article-edit-done-function)
5959 (make-local-variable 'gnus-prev-winconf)
5960 (set (make-local-variable 'font-lock-defaults)
5961 '(message-font-lock-keywords t))
5962 (set (make-local-variable 'mail-header-separator) "")
5963 (set (make-local-variable 'gnus-article-edit-mode) t)
5964 (easy-menu-add message-mode-field-menu message-mode-map)
5965 (setq buffer-read-only nil)
5966 (buffer-enable-undo)
5969 (defun gnus-article-edit (&optional force)
5970 "Edit the current article.
5971 This will have permanent effect only in mail groups.
5972 If FORCE is non-nil, allow editing of articles even in read-only
5975 (when (and (not force)
5976 (gnus-group-read-only-p))
5977 (error "The current newsgroup does not support article editing"))
5978 (gnus-article-date-original)
5979 (gnus-article-edit-article
5981 `(lambda (no-highlight)
5983 (gnus-summary-edit-article-done
5984 ,(or (mail-header-references gnus-current-headers) "")
5985 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5987 (defun gnus-article-edit-article (start-func exit-func)
5988 "Start editing the contents of the current article buffer."
5989 (let ((winconf (current-window-configuration)))
5990 (set-buffer gnus-article-buffer)
5991 (gnus-article-edit-mode)
5992 (funcall start-func)
5993 (set-buffer-modified-p nil)
5994 (gnus-configure-windows 'edit-article)
5995 (setq gnus-article-edit-done-function exit-func)
5996 (setq gnus-prev-winconf winconf)
5997 (when gnus-article-edit-article-setup-function
5998 (funcall gnus-article-edit-article-setup-function))
5999 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
6001 (defun gnus-article-edit-done (&optional arg)
6002 "Update the article edits and exit."
6004 (let ((func gnus-article-edit-done-function)
6005 (buf (current-buffer))
6006 (start (window-start))
6008 (winconf gnus-prev-winconf))
6009 (remove-hook 'gnus-article-mode-hook
6010 'gnus-article-mime-edit-article-unwind)
6011 (widen) ;; Widen it in case that users narrowed the buffer.
6014 ;; The cache and backlog have to be flushed somewhat.
6015 (when gnus-keep-backlog
6016 (gnus-backlog-remove-article
6017 (car gnus-article-current) (cdr gnus-article-current)))
6018 ;; Flush original article as well.
6020 (when (get-buffer gnus-original-article-buffer)
6021 (set-buffer gnus-original-article-buffer)
6022 (setq gnus-original-article nil)))
6023 (when gnus-use-cache
6024 (gnus-cache-update-article
6025 (car gnus-article-current) (cdr gnus-article-current)))
6026 ;; We remove all text props from the article buffer.
6027 (kill-all-local-variables)
6028 (gnus-set-text-properties (point-min) (point-max) nil)
6030 (set-window-configuration winconf)
6032 (set-window-start (get-buffer-window buf) start)
6033 (set-window-point (get-buffer-window buf) (point)))
6034 (gnus-summary-show-article))
6036 (defun gnus-article-edit-exit ()
6037 "Exit the article editing without updating."
6039 (when (or (not (buffer-modified-p))
6040 (yes-or-no-p "Article modified; kill anyway? "))
6041 (let ((curbuf (current-buffer))
6043 (window-start (window-start)))
6045 (if (gnus-buffer-live-p gnus-original-article-buffer)
6046 (insert-buffer-substring gnus-original-article-buffer))
6047 (let ((winconf gnus-prev-winconf))
6048 (kill-all-local-variables)
6050 (set-window-configuration winconf)
6051 ;; Tippy-toe some to make sure that point remains where it was.
6052 (save-current-buffer
6054 (set-window-start (get-buffer-window (current-buffer)) window-start)
6056 (gnus-summary-show-article)))
6058 (defun gnus-article-edit-full-stops ()
6059 "Interactively repair spacing at end of sentences."
6062 (goto-char (point-min))
6063 (search-forward-regexp "^$" nil t)
6064 (let ((case-fold-search nil))
6065 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6068 ;;; Article editing with MIME-Edit
6071 (defcustom gnus-article-mime-edit-article-setup-hook nil
6072 "Hook run after setting up a MIME editing article buffer."
6073 :group 'gnus-article-various
6076 (defun gnus-article-mime-edit-article-unwind ()
6077 "Unwind `gnus-article-buffer' if article editing was given up."
6078 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6079 (when (featurep 'font-lock)
6080 (setq font-lock-defaults nil)
6081 (font-lock-mode -1))
6082 (when mime-edit-mode-flag
6083 (mime-edit-exit 'nomime 'no-error)
6086 (defun gnus-article-mime-edit-article-setup ()
6087 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
6088 after replacing with the original article."
6089 (setq gnus-show-mime t)
6090 (setq gnus-article-edit-done-function
6091 `(lambda (&rest args)
6092 (when mime-edit-mode-flag
6093 (let (mime-edit-insert-user-agent-field)
6096 (goto-char (point-min))
6097 (let (case-fold-search)
6098 (when (re-search-forward
6099 (format "^%s$" (regexp-quote mail-header-separator))
6101 (replace-match "")))
6102 (apply ,gnus-article-edit-done-function args)
6105 (buffer-substring-no-properties (point-min) (point-max))
6106 (set-buffer (get-buffer-create gnus-original-article-buffer))
6108 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6109 (set-buffer gnus-article-buffer)
6110 (gnus-article-prepare-display)))
6111 (substitute-key-definition 'gnus-article-edit-done
6112 'gnus-article-mime-edit-done
6113 gnus-article-edit-mode-map)
6114 (substitute-key-definition 'gnus-article-edit-exit
6115 'gnus-article-mime-edit-exit
6116 gnus-article-edit-mode-map)
6118 (insert-buffer-substring gnus-original-article-buffer)
6119 (unless (member (with-current-buffer gnus-summary-buffer
6120 gnus-newsgroup-name)
6121 '("nndraft:delayed" "nndraft:drafts"))
6122 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
6123 (fset 'mime-edit-decode-single-part-in-buffer
6124 (lambda (&rest args)
6125 (if (let ((content-type (car args)))
6126 (and (eq 'message (mime-content-type-primary-type
6128 (eq 'rfc822 (mime-content-type-subtype
6130 (setcar (cdr args) 'not-decode-text))
6134 (fset 'mime-edit-decode-single-part-in-buffer ofn))))
6135 (when (featurep 'font-lock)
6136 (set (make-local-variable 'font-lock-defaults)
6137 '(message-font-lock-keywords t))
6138 (font-lock-set-defaults)
6139 (turn-on-font-lock))
6140 (set-buffer-modified-p nil)
6141 (delete-other-windows)
6142 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6143 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
6145 (defun gnus-article-mime-edit-done (&optional arg)
6146 "Update the article MIME edits and exit."
6148 (when (featurep 'font-lock)
6149 (setq font-lock-defaults nil)
6150 (font-lock-mode -1))
6151 (let ((inhibit-read-only t))
6152 (gnus-article-edit-done arg)))
6154 (defun gnus-article-mime-edit-exit ()
6155 "Exit the article MIME editing without updating."
6157 (when (or (not (buffer-modified-p))
6158 (yes-or-no-p "Article modified; kill anyway? "))
6159 (when (featurep 'font-lock)
6160 (setq font-lock-defaults nil)
6161 (font-lock-mode -1))
6162 (when mime-edit-mode-flag
6163 (let (mime-edit-insert-user-agent-field)
6166 (goto-char (point-min))
6167 (let (case-fold-search)
6168 (when (re-search-forward
6169 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
6170 (replace-match "")))
6171 (let ((winconf gnus-prev-winconf))
6173 (buffer-substring-no-properties (point-min) (point-max))
6174 (set-buffer (get-buffer-create gnus-original-article-buffer))
6176 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6177 (set-buffer gnus-article-buffer)
6178 (gnus-article-prepare-display)
6179 (set-window-configuration winconf))))
6182 ;;; Article highlights
6185 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6187 ;;; Internal Variables:
6189 (defcustom gnus-button-url-regexp
6190 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6191 "\\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:]]\\)"
6192 "\\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\\)\\)")
6193 "Regular expression that matches URLs."
6194 :group 'gnus-article-buttons
6197 (defcustom gnus-button-valid-fqdn-regexp
6198 message-valid-fqdn-regexp
6199 "Regular expression that matches a valid FQDN."
6200 :group 'gnus-article-buttons
6203 (defcustom gnus-button-man-handler 'manual-entry
6204 "Function to use for displaying man pages.
6205 The function must take at least one argument with a string naming the
6207 :type '(choice (function-item :tag "Man" manual-entry)
6208 (function-item :tag "Woman" woman)
6209 (function :tag "Other"))
6210 :group 'gnus-article-buttons)
6212 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6213 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6214 If the default site is too slow, try to find a CTAN mirror, see
6215 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6216 the variable `gnus-button-handle-ctan'."
6217 :group 'gnus-article-buttons
6218 :link '(custom-manual "(gnus)Group Parameters")
6219 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6220 (const "http://tug.ctan.org/tex-archive/")
6221 (const "http://www.dante.de/CTAN/")
6222 (string :tag "Other")))
6224 (defcustom gnus-button-ctan-handler 'browse-url
6225 "Function to use for displaying CTAN links.
6226 The function must take one argument, the string naming the URL."
6227 :type '(choice (function-item :tag "Browse Url" browse-url)
6228 (function :tag "Other"))
6229 :group 'gnus-article-buttons)
6231 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6232 "Bogus strings removed from CTAN URLs."
6233 :group 'gnus-article-buttons
6234 :type '(choice (const "^/?tex-archive/\\|/")
6235 (regexp :tag "Other")))
6237 (defcustom gnus-button-ctan-directory-regexp
6239 "\\("; Cannot use `\(?: ... \)' (compatibility with Emacs 20).
6240 "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
6241 "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
6242 "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
6244 "Regular expression for ctan directories.
6245 It should match all directories in the top level of `gnus-ctan-url'."
6246 :group 'gnus-article-buttons
6249 (defcustom gnus-button-mid-or-mail-regexp
6250 (concat "\\b\\(<?[a-z0-9][^<>\")!;:,{}\n\t ]*@"
6251 gnus-button-valid-fqdn-regexp
6253 "Regular expression that matches a message ID or a mail address."
6254 :group 'gnus-article-buttons
6257 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6258 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6259 Strings like this can be either a message ID or a mail address. If it is one
6260 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6261 message ID or a mail address, respectively. If this variable is set to the
6262 symbol `ask', always query the user what do do. If it is a function, this
6263 function will be called with the string as it's only argument. The function
6264 must return `mid', `mail', `invalid' or `ask'."
6265 :group 'gnus-article-buttons
6266 :type '(choice (function-item :tag "Heuristic function"
6267 gnus-button-mid-or-mail-heuristic)
6272 (defcustom gnus-button-mid-or-mail-heuristic-alist
6273 '((-10.0 . ".+\\$.+@")
6276 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6277 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6278 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6279 (-1.0 . "^[^a-z]+@")
6281 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6282 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6283 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6284 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6287 (-1.0 . "^[0-9][0-9]")
6289 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6290 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6291 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6292 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6294 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6295 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6298 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6300 ;; compensation for TDMA dated mail addresses:
6301 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6303 (-20.0 . "\\.fsf@") ;; Gnus
6306 (-20.0 . "_-_") ;; Subject change in thread
6308 (-20.0 . "\\.ln@") ;; leafnode
6309 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6310 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6312 ;; (5.0 . "") ;; $local_part_len <= 7
6313 (10.0 . "^[^0-9]+@")
6314 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6315 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6318 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6320 (0.5 . "^[A-Z][a-z]")
6321 (0.5 . "^[A-Z][a-z][a-z]")
6322 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6323 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6324 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6326 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6327 address. The REGEXP is processed with `case-fold-search' set to nil."
6328 :group 'gnus-article-buttons
6329 :type '(repeat (cons (number :tag "Rate")
6330 (regexp :tag "Regexp"))))
6332 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6333 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6334 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6335 address, `ask' if unsure and `invalid' if the string is invalid."
6336 (let ((case-fold-search nil)
6337 (list gnus-button-mid-or-mail-heuristic-alist)
6338 (result 0) rate regexp lpartlen elem)
6340 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6341 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6342 ;; Certain special cases...
6345 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$" "\\|"
6346 "^[0-9]+\.[0-9]+\@compuserve")
6348 (gnus-message 8 "`%s' is a known mail address.")
6349 (setq result 'mail))
6350 (when (string-match "@.*@\\| " mid-or-mail)
6351 (gnus-message 8 "`%s' is invalid.")
6352 (setq result 'invalid))
6353 ;; Nothing more to do, if result is not a number here...
6354 (when (numberp result)
6356 (setq elem (car list)
6360 (when (string-match regexp mid-or-mail)
6361 (setq result (+ result rate))
6363 9 "`%s' matched `%s', rate `%s', result `%s'."
6364 mid-or-mail regexp rate result)))
6365 (when (<= lpartlen 7)
6366 (setq result (+ result 5.0))
6367 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6368 mid-or-mail result))
6369 (when (>= lpartlen 12)
6370 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6372 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6373 ;; Long local part should contain realname if e-mail address,
6374 ;; too many digits: message-id.
6375 ;; $score -= 5.0 + 0.1 * $local_part_len;
6376 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6377 (setq result (+ result rate))
6379 9 "Many digits in `%s', rate `%s', result `%s'."
6380 mid-or-mail rate result))
6381 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6383 ;; Too few vowels [^aeiouy]{4,}.*\@
6384 (setq result (+ result -5.0))
6386 9 "Few vowels in `%s', rate `%s', result `%s'."
6387 mid-or-mail -5.0 result))
6389 (setq result (+ result 5.0))
6391 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6392 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6394 ;; Maybe we should make this a customizable alist: (condition . 'result)
6395 ((< result -10.0) 'mid)
6396 ((> result 10.0) 'mail)
6399 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6400 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6401 (url-mid (concat "news" ":" mid-or-mail))
6402 (url-mailto (concat "mailto" ":" mid-or-mail)))
6403 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6404 (when (fboundp pref)
6406 ;; get rid of surrounding angles...
6408 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6409 (if (or (eq 'mid guessed) (eq 'mail guessed))
6413 (save-window-excursion
6414 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6417 (cond ((eq pref 'mid)
6418 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6419 (gnus-button-handle-news url-mid))
6421 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6422 (gnus-url-mailto url-mailto))
6423 (t (gnus-message 3 "Invalid string.")))))
6425 (defun gnus-button-handle-custom (url)
6426 "Follow a Custom URL."
6427 (customize-apropos (gnus-url-unhex-string url)))
6429 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6431 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6434 (defun gnus-button-handle-describe-function (url)
6435 "Call `describe-function' when pushing the corresponding URL button."
6438 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6440 (defun gnus-button-handle-describe-variable (url)
6441 "Call `describe-variable' when pushing the corresponding URL button."
6444 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6446 (defun gnus-button-handle-symbol (url)
6447 "Display help on variable or function.
6448 Calls `describe-variable' or `describe-function'."
6449 (let ((sym (intern url)))
6451 ((fboundp sym) (describe-function sym))
6452 ((boundp sym) (describe-variable sym))
6453 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6455 (defun gnus-button-handle-describe-key (url)
6456 "Call `describe-key' when pushing the corresponding URL button."
6458 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6459 (keys (ignore-errors (eval `(kbd ,key-string)))))
6462 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6464 (defun gnus-button-handle-apropos (url)
6465 "Call `apropos' when pushing the corresponding URL button."
6466 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6468 (defun gnus-button-handle-apropos-command (url)
6469 "Call `apropos' when pushing the corresponding URL button."
6471 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6473 (defun gnus-button-handle-apropos-variable (url)
6474 "Call `apropos' when pushing the corresponding URL button."
6476 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6477 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6479 (defun gnus-button-handle-apropos-documentation (url)
6480 "Call `apropos' when pushing the corresponding URL button."
6482 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6483 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6485 (defun gnus-button-handle-library (url)
6486 "Call `locate-library' when pushing the corresponding URL button."
6487 (gnus-message 9 "url=`%s'" url)
6488 (let* ((lib (locate-library url))
6489 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6491 (gnus-message 1 "Cannot locale library `%s'." url)
6492 (find-file-read-only file))))
6494 (defun gnus-button-handle-ctan (url)
6495 "Call `browse-url' when pushing a CTAN URL button."
6497 gnus-button-ctan-handler
6500 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6502 (defcustom gnus-button-tex-level 5
6503 "*Integer that says how many TeX-related buttons Gnus will show.
6504 The higher the number, the more buttons will appear and the more false
6505 positives are possible. Note that you can set this variable local to
6506 specific groups. Setting it higher in TeX groups is probably a good idea.
6507 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6508 how to set variables in specific groups."
6509 :group 'gnus-article-buttons
6510 :link '(custom-manual "(gnus)Group Parameters")
6513 (defcustom gnus-button-man-level 5
6514 "*Integer that says how many man-related buttons Gnus will show.
6515 The higher the number, the more buttons will appear and the more false
6516 positives are possible. Note that you can set this variable local to
6517 specific groups. Setting it higher in Unix groups is probably a good idea.
6518 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6519 how to set variables in specific groups."
6520 :group 'gnus-article-buttons
6521 :link '(custom-manual "(gnus)Group Parameters")
6524 (defcustom gnus-button-emacs-level 5
6525 "*Integer that says how many emacs-related buttons Gnus will show.
6526 The higher the number, the more buttons will appear and the more false
6527 positives are possible. Note that you can set this variable local to
6528 specific groups. Setting it higher in Emacs or Gnus related groups is
6529 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6530 `gnus-parameters' on how to set variables in specific groups."
6531 :group 'gnus-article-buttons
6532 :link '(custom-manual "(gnus)Group Parameters")
6535 (defcustom gnus-button-message-level 5
6536 "*Integer that says how many buttons for news or mail messages will appear.
6537 The higher the number, the more buttons will appear and the more false
6538 positives are possible."
6539 ;; mail addresses, MIDs, URLs for news, ...
6540 :group 'gnus-article-buttons
6543 (defcustom gnus-button-browse-level 5
6544 "*Integer that says how many buttons for browsing will appear.
6545 The higher the number, the more buttons will appear and the more false
6546 positives are possible."
6547 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6548 :group 'gnus-article-buttons
6551 (defcustom gnus-button-alist
6552 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6553 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6554 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6555 gnus-button-handle-news 2)
6556 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6557 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6558 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6559 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6560 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6561 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6562 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6563 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6564 ("mailto:\\([-a-z.@_+0-9%=?&]+\\)"
6565 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6566 ("\\bmailto:\\([^ \n\t]+\\)"
6567 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6569 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6570 gnus-button-ctan-directory-regexp
6571 "[^][>)!;:,'\n\t ]+\\)")
6572 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6573 ((concat "\\btex-archive/\\("
6574 gnus-button-ctan-directory-regexp
6575 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6576 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6579 gnus-button-ctan-directory-regexp
6580 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6581 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6582 ;; This is info (home-grown style) <info://foo/bar+baz>
6583 ("\\binfo://\\([^'\">\n\t ]+\\)"
6584 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6585 ;; Info GNOME style <info:foo#bar_baz>
6586 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6587 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6588 ;; Info KDE style <info:(foo)bar baz>
6589 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6590 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6591 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6592 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6593 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6594 ;; Info links like `C-h i d m CC Mode RET'
6595 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6597 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6598 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6599 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6600 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6601 ;; Emacs help commands
6602 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6603 ;; regexp doesn't match arguments containing ` '.
6604 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6605 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6606 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6607 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6608 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6609 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6610 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6611 ;; The following entries may lead to many false positives so don't enable
6612 ;; them by default (use a high button level):
6613 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>"
6614 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6615 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6616 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6617 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6618 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6619 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6620 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6621 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6622 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6623 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6624 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6625 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6626 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6627 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6628 ;; Unlike the other regexps we really have to require quoting
6629 ;; here to determine where it ends.
6630 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6631 ;; This is how URLs _should_ be embedded in text (RFC 1738)...
6632 ("<URL: *\\([^<>]*\\)>"
6633 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6635 (gnus-button-url-regexp
6636 0 (>= gnus-button-browse-level 0) browse-url 0)
6638 ("\\b\\([a-z][a-z]+\\)([1-9])\\W"
6639 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6640 gnus-button-handle-man 1)
6641 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6642 ("\\b\\([a-z][-_.a-z0-9]+\\)([1-9])\\W"
6643 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6644 gnus-button-handle-man 1)
6645 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6646 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6647 ("\\b\\([a-z][-+_.:a-z0-9]+\\)([1-9][X1a-z]*)\\W\\|\\b\\(X\\)([1-9])\\W"
6648 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6649 ;; MID or mail: To avoid too many false positives we don't try to catch
6650 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6651 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6652 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6653 ;; so that non-ambiguous entries (see above) match first.
6654 (gnus-button-mid-or-mail-regexp
6655 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6656 "*Alist of regexps matching buttons in article bodies.
6658 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6659 REGEXP: is the string (case insensitive) matching text around the button (can
6660 also be Lisp expression evaluating to a string),
6661 BUTTON: is the number of the regexp grouping actually matching the button,
6662 FORM: is a Lisp expression which must eval to true for the button to
6664 CALLBACK: is the function to call when the user push this button, and each
6665 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6667 CALLBACK can also be a variable, in that case the value of that
6668 variable it the real callback function."
6669 :group 'gnus-article-buttons
6670 :type '(repeat (list (choice regexp variable sexp)
6671 (integer :tag "Button")
6673 (function :tag "Callback")
6676 (integer :tag "Regexp group")))))
6678 (defcustom gnus-header-button-alist
6679 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6680 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6681 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6682 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6683 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6684 0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6685 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6686 0 (>= gnus-button-browse-level 0) browse-url 0)
6687 ("^Subject:" gnus-button-url-regexp
6688 0 (>= gnus-button-browse-level 0) browse-url 0)
6689 ("^[^:]+:" gnus-button-url-regexp
6690 0 (>= gnus-button-browse-level 0) browse-url 0)
6691 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&]+\\)"
6692 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6693 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6694 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6695 "*Alist of headers and regexps to match buttons in article heads.
6697 This alist is very similar to `gnus-button-alist', except that each
6698 alist has an additional HEADER element first in each entry:
6700 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6702 HEADER is a regexp to match a header. For a fuller explanation, see
6703 `gnus-button-alist'."
6704 :group 'gnus-article-buttons
6705 :group 'gnus-article-headers
6706 :type '(repeat (list (regexp :tag "Header")
6707 (choice regexp variable)
6708 (integer :tag "Button")
6710 (function :tag "Callback")
6713 (integer :tag "Regexp group")))))
6715 (defvar gnus-button-regexp nil)
6716 (defvar gnus-button-marker-list nil)
6717 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6719 (defvar gnus-button-last nil)
6720 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6724 (defun gnus-article-push-button (event)
6725 "Check text under the mouse pointer for a callback function.
6726 If the text under the mouse pointer has a `gnus-callback' property,
6727 call it with the value of the `gnus-data' text property."
6729 (set-buffer (window-buffer (posn-window (event-start event))))
6730 (let* ((pos (posn-point (event-start event)))
6731 (data (get-text-property pos 'gnus-data))
6732 (fun (get-text-property pos 'gnus-callback)))
6735 (funcall fun data))))
6737 (defun gnus-article-press-button ()
6738 "Check text at point for a callback function.
6739 If the text at point has a `gnus-callback' property,
6740 call it with the value of the `gnus-data' text property."
6742 (let ((data (get-text-property (point) 'gnus-data))
6743 (fun (get-text-property (point) 'gnus-callback)))
6745 (funcall fun data))))
6747 (defun gnus-article-prev-button (n)
6748 "Move point to N buttons backward.
6749 If N is negative, move forward instead."
6751 (gnus-article-next-button (- n)))
6753 (defun gnus-article-next-button (n)
6754 "Move point to N buttons forward.
6755 If N is negative, move backward instead."
6757 (let ((function (if (< n 0) 'previous-single-property-change
6758 'next-single-property-change))
6759 (inhibit-point-motion-hooks t)
6761 (limit (if (< n 0) (point-min) (point-max))))
6763 (while (and (not (= limit (point)))
6765 ;; Skip past the current button.
6766 (when (get-text-property (point) 'gnus-callback)
6767 (goto-char (funcall function (point) 'gnus-callback nil limit)))
6768 ;; Go to the next (or previous) button.
6769 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
6770 ;; Put point at the start of the button.
6771 (when (and backward (not (get-text-property (point) 'gnus-callback)))
6772 (goto-char (funcall function (point) 'gnus-callback nil limit)))
6773 ;; Skip past intangible buttons.
6774 (when (get-text-property (point) 'intangible)
6778 (gnus-message 5 "No more buttons"))
6781 (defun gnus-article-highlight (&optional force)
6782 "Highlight current article.
6783 This function calls `gnus-article-highlight-headers',
6784 `gnus-article-highlight-citation',
6785 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6786 do the highlighting. See the documentation for those functions."
6787 (interactive (list 'force))
6788 (gnus-article-highlight-headers)
6789 (gnus-article-highlight-citation force)
6790 (gnus-article-highlight-signature)
6791 (gnus-article-add-buttons force)
6792 (gnus-article-add-buttons-to-head))
6794 (defun gnus-article-highlight-some (&optional force)
6795 "Highlight current article.
6796 This function calls `gnus-article-highlight-headers',
6797 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6798 do the highlighting. See the documentation for those functions."
6799 (interactive (list 'force))
6800 (gnus-article-highlight-headers)
6801 (gnus-article-highlight-signature)
6802 (gnus-article-add-buttons))
6804 (defun gnus-article-highlight-headers ()
6805 "Highlight article headers as specified by `gnus-header-face-alist'."
6808 (set-buffer gnus-article-buffer)
6810 (let ((alist gnus-header-face-alist)
6811 (buffer-read-only nil)
6812 (case-fold-search t)
6813 (inhibit-point-motion-hooks t)
6814 entry regexp header-face field-face from hpoints fpoints)
6815 (article-narrow-to-head)
6816 (while (setq entry (pop alist))
6817 (goto-char (point-min))
6818 (setq regexp (concat "^\\("
6819 (if (string-equal "" (nth 0 entry))
6823 header-face (nth 1 entry)
6824 field-face (nth 2 entry))
6825 (while (and (re-search-forward regexp nil t)
6829 (unless (search-forward ":" nil t)
6831 (when (and header-face
6832 (not (memq (point) hpoints)))
6833 (push (point) hpoints)
6834 (gnus-put-text-property from (point) 'face header-face))
6835 (when (and field-face
6836 (not (memq (setq from (point)) fpoints)))
6838 (if (re-search-forward "^[^ \t]" nil t)
6840 (goto-char (point-max)))
6841 (gnus-put-text-property from (point) 'face field-face))))))))
6843 (defun gnus-article-highlight-signature ()
6844 "Highlight the signature in an article.
6845 It does this by highlighting everything after
6846 `gnus-signature-separator' using `gnus-signature-face'."
6848 (when gnus-signature-face
6850 (set-buffer gnus-article-buffer)
6851 (let ((buffer-read-only nil)
6852 (inhibit-point-motion-hooks t))
6854 (when (gnus-article-narrow-to-signature)
6855 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6856 'face gnus-signature-face)))))))
6858 (defun gnus-article-buttonize-signature ()
6859 "Add button to the signature."
6862 (set-buffer gnus-article-buffer)
6863 (let ((buffer-read-only nil)
6864 (inhibit-point-motion-hooks t))
6865 (when (gnus-article-search-signature)
6866 (gnus-article-add-button (match-beginning 0) (match-end 0)
6867 'gnus-signature-toggle
6868 (set-marker (make-marker)
6869 (1+ (match-end 0))))))))
6871 (defun gnus-button-in-region-p (b e prop)
6872 "Say whether PROP exists in the region."
6873 (text-property-not-all b e prop nil))
6875 (defun gnus-article-add-buttons (&optional force)
6876 "Find external references in the article and make buttons of them.
6877 \"External references\" are things like Message-IDs and URLs, as
6878 specified by `gnus-button-alist'."
6879 (interactive (list 'force))
6881 (set-buffer gnus-article-buffer)
6882 (let ((buffer-read-only nil)
6883 (inhibit-point-motion-hooks t)
6884 (case-fold-search t)
6885 (alist gnus-button-alist)
6887 ;; Remove all old markers.
6888 (let (marker entry new-list)
6889 (while (setq marker (pop gnus-button-marker-list))
6890 (if (or (< marker (point-min)) (>= marker (point-max)))
6891 (push marker new-list)
6893 (when (setq entry (gnus-button-entry))
6894 (put-text-property (match-beginning (nth 1 entry))
6895 (match-end (nth 1 entry))
6896 'gnus-callback nil))
6897 (set-marker marker nil)))
6898 (setq gnus-button-marker-list new-list))
6899 ;; We skip the headers.
6902 (while (setq entry (pop alist))
6903 (setq regexp (eval (car entry)))
6905 (while (re-search-forward regexp nil t)
6906 (let* ((start (and entry (match-beginning (nth 1 entry))))
6907 (end (and entry (match-end (nth 1 entry))))
6908 (from (match-beginning 0)))
6909 (when (and (or (eq t (nth 2 entry))
6910 (eval (nth 2 entry)))
6911 (not (gnus-button-in-region-p
6912 start end 'gnus-callback)))
6913 ;; That optional form returned non-nil, so we add the
6915 (gnus-article-add-button
6916 start end 'gnus-button-push
6917 (car (push (set-marker (make-marker) from)
6918 gnus-button-marker-list))))))))))
6920 ;; Add buttons to the head of an article.
6921 (defun gnus-article-add-buttons-to-head ()
6922 "Add buttons to the head of the article."
6925 (set-buffer gnus-article-buffer)
6927 (let ((buffer-read-only nil)
6928 (inhibit-point-motion-hooks t)
6929 (case-fold-search t)
6930 (alist gnus-header-button-alist)
6932 (article-narrow-to-head)
6934 ;; Each alist entry.
6935 (setq entry (car alist)
6937 (goto-char (point-min))
6938 (while (re-search-forward (car entry) nil t)
6939 ;; Each header matching the entry.
6940 (setq beg (match-beginning 0))
6941 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6942 (match-beginning 0))
6945 (while (re-search-forward (eval (nth 1 entry)) end t)
6946 ;; Each match within a header.
6947 (let* ((entry (cdr entry))
6948 (start (match-beginning (nth 1 entry)))
6949 (end (match-end (nth 1 entry)))
6950 (form (nth 2 entry)))
6951 (goto-char (match-end 0))
6953 (gnus-article-add-button
6954 start end (nth 3 entry)
6955 (buffer-substring (match-beginning (nth 4 entry))
6956 (match-end (nth 4 entry)))))))
6957 (goto-char end)))))))
6959 ;;; External functions:
6961 (defun gnus-article-add-button (from to fun &optional data)
6962 "Create a button between FROM and TO with callback FUN and data DATA."
6963 (when gnus-article-button-face
6964 (gnus-overlay-put (gnus-make-overlay from to)
6965 'face gnus-article-button-face))
6966 (gnus-add-text-properties
6968 (nconc (and gnus-article-mouse-face
6969 (list gnus-mouse-face-prop gnus-article-mouse-face))
6970 (list 'gnus-callback fun)
6971 (and data (list 'gnus-data data))))
6972 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6973 ;; Quote `:button-keymap' for Mule 2.3
6974 ;; but it won't work.
6975 ':button-keymap gnus-widget-button-keymap))
6977 ;;; Internal functions:
6979 (defun gnus-article-set-globals ()
6981 (set-buffer gnus-summary-buffer)
6982 (gnus-set-global-variables)))
6984 (defun gnus-signature-toggle (end)
6986 (set-buffer gnus-article-buffer)
6987 (let ((buffer-read-only nil)
6988 (inhibit-point-motion-hooks t)
6989 (limit (next-single-property-change end 'mime-view-entity
6991 (if (text-property-any end limit 'article-type 'signature)
6993 (gnus-delete-wash-type 'signature)
6994 (gnus-remove-text-properties-when
6995 'article-type 'signature end limit
6996 (cons 'article-type (cons 'signature
6997 gnus-hidden-properties))))
6998 (gnus-add-wash-type 'signature)
6999 (gnus-add-text-properties-when
7000 'article-type nil end limit
7001 (cons 'article-type (cons 'signature
7002 gnus-hidden-properties)))))
7003 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7004 (gnus-set-mode-line 'article))))
7006 (defun gnus-button-entry ()
7007 ;; Return the first entry in `gnus-button-alist' matching this place.
7008 (let ((alist gnus-button-alist)
7011 (setq entry (pop alist))
7012 (if (looking-at (eval (car entry)))
7017 (defun gnus-button-push (marker)
7018 ;; Push button starting at MARKER.
7021 (let* ((entry (gnus-button-entry))
7022 (inhibit-point-motion-hooks t)
7024 (args (mapcar (lambda (group)
7025 (let ((string (match-string group)))
7026 (gnus-set-text-properties
7027 0 (length string) nil string)
7034 (fboundp (symbol-value fun)))
7035 (apply (symbol-value fun) args))
7037 (gnus-message 1 "You must define `%S' to use this button"
7038 (cons fun args)))))))
7040 (defun gnus-parse-news-url (url)
7041 (let (scheme server group message-id articles)
7044 (goto-char (point-min))
7045 (when (looking-at "\\([A-Za-z]+\\):")
7046 (setq scheme (match-string 1))
7047 (goto-char (match-end 0)))
7048 (when (looking-at "//\\([^/]+\\)/")
7049 (setq server (match-string 1))
7050 (goto-char (match-end 0)))
7053 ((looking-at "\\(.*@.*\\)")
7054 (setq message-id (match-string 1)))
7055 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7056 (setq group (match-string 1)
7057 articles (split-string (match-string 2) "-")))
7058 ((looking-at "\\([^/]+\\)/?")
7059 (setq group (match-string 1)))
7061 (error "Unknown news URL syntax"))))
7062 (list scheme server group message-id articles)))
7064 (defun gnus-button-handle-news (url)
7066 (destructuring-bind (scheme server group message-id articles)
7067 (gnus-parse-news-url url)
7071 (set-buffer gnus-summary-buffer)
7073 (let ((gnus-refer-article-method (list (list 'nntp server))))
7074 (gnus-summary-refer-article message-id))
7075 (gnus-summary-refer-article message-id))))
7077 (gnus-button-fetch-group url)))))
7079 (defun gnus-button-handle-man (url)
7081 (funcall gnus-button-man-handler url))
7083 (defun gnus-button-handle-info-url (url)
7084 "Fetch an info URL."
7085 (setq url (mm-subst-char-in-string ?+ ?\ url))
7087 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7088 (gnus-info-find-node
7089 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7091 ")" (gnus-url-unhex-string (match-string 2 url)))))
7092 ((string-match "([^)\"]+)[^\"]+" url)
7094 (gnus-replace-in-string
7095 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7096 (gnus-info-find-node url))
7097 (t (error "Can't parse %s" url))))
7099 (defun gnus-button-handle-info-url-gnome (url)
7100 "Fetch GNOME style info URL."
7101 (setq url (mm-subst-char-in-string ?_ ?\ url))
7102 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7103 (gnus-info-find-node
7105 (gnus-url-unhex-string
7106 (match-string 1 url))
7108 (or (gnus-url-unhex-string
7109 (match-string 2 url))
7111 (error "Can't parse %s" url)))
7113 (defun gnus-button-handle-info-url-kde (url)
7114 "Fetch KDE style info URL."
7115 (gnus-info-find-node (gnus-url-unhex-string url)))
7117 (defun gnus-button-handle-info-keystrokes (url)
7118 "Call `info' when pushing the corresponding URL button."
7119 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7124 (defun gnus-button-message-id (message-id)
7127 (set-buffer gnus-summary-buffer)
7128 (gnus-summary-refer-article message-id)))
7130 (defun gnus-button-fetch-group (address)
7131 "Fetch GROUP specified by ADDRESS."
7132 (if (not (string-match "[:/]" address))
7133 ;; This is just a simple group url.
7134 (gnus-group-read-ephemeral-group address gnus-select-method)
7137 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7139 (error "Can't parse %s" address)
7140 (gnus-group-read-ephemeral-group
7141 (match-string 4 address)
7142 `(nntp ,(match-string 1 address)
7143 (nntp-address ,(match-string 1 address))
7144 (nntp-port-number ,(if (match-end 3)
7145 (match-string 3 address)
7148 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
7150 (defun gnus-url-parse-query-string (query &optional downcase)
7151 (let (retval pairs cur key val)
7152 (setq pairs (split-string query "&"))
7154 (setq cur (car pairs)
7156 (if (not (string-match "=" cur))
7158 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7159 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7161 (setq key (downcase key)))
7162 (setq cur (assoc key retval))
7164 (setcdr cur (cons val (cdr cur)))
7165 (setq retval (cons (list key val) retval)))))
7168 (defun gnus-url-mailto (url)
7169 ;; Send mail to someone
7170 (when (string-match "mailto:/*\\(.*\\)" url)
7171 (setq url (substring url (match-beginning 1) nil)))
7172 (let (to args subject func)
7173 (setq args (gnus-url-parse-query-string
7174 (if (string-match "^\\?" url)
7176 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7177 (concat "to=" (match-string 1 url) "&"
7178 (match-string 2 url))
7179 (concat "to=" url)))
7181 subject (cdr-safe (assoc "subject" args)))
7184 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7187 (message-position-on-field (caar args)))
7188 (insert (gnus-replace-in-string
7189 (mapconcat 'identity (reverse (cdar args)) ", ")
7191 (setq args (cdr args)))
7194 (message-goto-subject))))
7196 (defun gnus-button-embedded-url (address)
7197 "Activate ADDRESS with `browse-url'."
7198 (browse-url (gnus-strip-whitespace address)))
7200 ;;; Next/prev buttons in the article buffer.
7202 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7203 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7205 (defvar gnus-prev-page-map
7206 (let ((map (make-sparse-keymap)))
7207 (unless (>= emacs-major-version 21)
7208 ;; XEmacs doesn't care.
7209 (set-keymap-parent map gnus-article-mode-map))
7210 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7211 (define-key map "\r" 'gnus-button-prev-page)
7214 (defun gnus-insert-prev-page-button ()
7216 (buffer-read-only nil)
7217 (situation (get-text-property (point-min) 'mime-view-situation)))
7219 gnus-prev-page-line-format nil
7220 `(,@(gnus-local-map-property gnus-prev-page-map)
7222 gnus-callback gnus-article-button-prev-page
7223 article-type annotation
7224 mime-view-situation ,situation))
7225 (widget-convert-button
7227 ;; Exclude a newline.
7230 :action 'gnus-button-prev-page
7231 :button-keymap gnus-prev-page-map)))
7233 (defvar gnus-next-page-map
7234 (let ((map (make-sparse-keymap)))
7235 (unless (>= emacs-major-version 21)
7236 ;; XEmacs doesn't care.
7237 (set-keymap-parent map gnus-article-mode-map))
7238 (define-key map gnus-mouse-2 'gnus-button-next-page)
7239 (define-key map "\r" 'gnus-button-next-page)
7242 (defun gnus-button-next-page (&optional args more-args)
7243 "Go to the next page."
7245 (let ((win (selected-window)))
7246 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7247 (gnus-article-next-page)
7248 (select-window win)))
7250 (defun gnus-button-prev-page (&optional args more-args)
7251 "Go to the prev page."
7253 (let ((win (selected-window)))
7254 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7255 (gnus-article-prev-page)
7256 (select-window win)))
7258 (defun gnus-insert-next-page-button ()
7260 (buffer-read-only nil)
7261 (situation (get-text-property (point-min) 'mime-view-situation)))
7262 (gnus-eval-format gnus-next-page-line-format nil
7263 `(,@(gnus-local-map-property gnus-next-page-map)
7265 gnus-callback gnus-article-button-next-page
7266 article-type annotation
7267 mime-view-situation ,situation))
7268 (widget-convert-button
7270 ;; Exclude a newline.
7273 :action 'gnus-button-next-page
7274 :button-keymap gnus-next-page-map)))
7276 (defun gnus-article-button-next-page (arg)
7277 "Go to the next page."
7279 (let ((win (selected-window)))
7280 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7281 (gnus-article-next-page)
7282 (select-window win)))
7284 (defun gnus-article-button-prev-page (arg)
7285 "Go to the prev page."
7287 (let ((win (selected-window)))
7288 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7289 (gnus-article-prev-page)
7290 (select-window win)))
7292 (defvar gnus-decode-header-methods
7293 '(mail-decode-encoded-word-region)
7294 "List of methods used to decode headers.
7296 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7297 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
7298 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7299 whose names match REGEXP.
7302 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7303 mail-decode-encoded-word-region
7304 (\"chinese\" . rfc1843-decode-region))
7307 (defvar gnus-decode-header-methods-cache nil)
7309 (defun gnus-multi-decode-header (start end)
7310 "Apply the functions from `gnus-encoded-word-methods' that match."
7311 (unless (and gnus-decode-header-methods-cache
7312 (eq gnus-newsgroup-name
7313 (car gnus-decode-header-methods-cache)))
7314 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7317 (nconc gnus-decode-header-methods-cache (list x))
7318 (if (and gnus-newsgroup-name
7319 (string-match (car x) gnus-newsgroup-name))
7320 (nconc gnus-decode-header-methods-cache
7322 gnus-decode-header-methods))
7323 (let ((xlist gnus-decode-header-methods-cache))
7326 (narrow-to-region start end)
7328 (funcall (pop xlist) (point-min) (point-max))))))
7331 ;;; Treatment top-level handling.
7334 (defun gnus-treat-article (condition &optional part-number total-parts type)
7335 (let ((length (- (point-max) (point-min)))
7336 (alist gnus-treatment-function-alist)
7337 (article-goto-body-goes-to-point-min-p t)
7341 (let ((list gnus-article-treat-types))
7343 (when (string-match (pop list) type)
7344 (throw 'found t)))))))
7345 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7346 (entity (static-unless (featurep 'xemacs)
7347 (when (eq 'head condition)
7348 (get-text-property (point-min) 'mime-view-entity))))
7349 val elem buttonized)
7350 (gnus-run-hooks 'gnus-part-display-hook)
7351 (unless gnus-inhibit-treatment
7352 (dolist (elem alist)
7355 (when (gnus-buffer-live-p gnus-summary-buffer)
7356 (set-buffer gnus-summary-buffer))
7357 (symbol-value (car elem))))
7358 (when (and (or (consp val)
7360 (gnus-treat-predicate val)
7361 (or (not (get (car elem) 'highlight))
7363 (when (and (not buttonized)
7365 '(gnus-treat-hide-signature
7366 gnus-treat-highlight-signature)))
7367 (gnus-article-buttonize-signature)
7368 (setq buttonized t))
7370 (funcall (cadr elem)))))
7371 ;; FSF Emacsen does not inherit the existing text properties
7372 ;; in the new text, so we should do it for `mime-view-entity'.
7373 (static-unless (featurep 'xemacs)
7375 (put-text-property (point-min) (point-max)
7376 'mime-view-entity entity))))))
7378 ;; Dynamic variables.
7380 (defvar part-number)
7381 (defvar total-parts)
7386 (defun gnus-treat-predicate (val)
7391 (stringp (car val)))
7392 (apply 'gnus-or (mapcar `(lambda (s)
7393 (string-match s ,(or gnus-newsgroup-name "")))
7396 (let ((pred (pop val)))
7399 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7401 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7403 (not (gnus-treat-predicate (car val))))
7405 (equal (car val) type))
7407 (error "%S is not a valid predicate" pred)))))
7417 (eq part-number total-parts))
7421 (error "%S is not a valid value" val))))
7423 (defun gnus-article-encrypt-body (protocol &optional n)
7424 "Encrypt the article body."
7427 (or gnus-article-encrypt-protocol
7428 (completing-read "Encrypt protocol: "
7429 gnus-article-encrypt-protocol-alist
7431 current-prefix-arg))
7432 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7434 (error (format "Can't find the encrypt protocol %s" protocol)))
7435 (if (member gnus-newsgroup-name '("nndraft:delayed"
7438 (error "Can't encrypt the article in group %s"
7439 gnus-newsgroup-name))
7440 (gnus-summary-iterate n
7442 (set-buffer gnus-summary-buffer)
7443 (let ((mail-parse-charset gnus-newsgroup-charset)
7444 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7445 (summary-buffer gnus-summary-buffer)
7447 (gnus-set-global-variables)
7448 (when (gnus-group-read-only-p)
7449 (error "The current newsgroup does not support article encrypt"))
7450 (gnus-summary-show-article t)
7452 (or (mail-header-references gnus-current-headers) ""))
7453 (set-buffer gnus-article-buffer)
7454 (let* ((buffer-read-only nil)
7456 (mapcar (lambda (field)
7457 (and (save-restriction
7458 (message-narrow-to-head)
7459 (goto-char (point-min))
7460 (search-forward field nil t))
7462 (message-narrow-to-field)
7464 (delete-region (point-min) (point-max))
7466 '("Content-Type:" "Content-Transfer-Encoding:"
7467 "Content-Disposition:"))))
7468 (message-narrow-to-head)
7469 (message-remove-header "MIME-Version")
7470 (goto-char (point-max))
7471 (setq point (point))
7472 (insert (apply 'concat headers))
7474 (narrow-to-region point (point-max))
7475 (let ((message-options message-options))
7476 (message-options-set 'message-sender user-mail-address)
7477 (message-options-set 'message-recipients user-mail-address)
7478 (message-options-set 'message-sign-encrypt 'not)
7480 (goto-char (point-min))
7481 (insert "MIME-Version: 1.0\n")
7483 (gnus-summary-edit-article-done
7484 references nil summary-buffer t))
7485 (when gnus-keep-backlog
7486 (gnus-backlog-remove-article
7487 (car gnus-article-current) (cdr gnus-article-current)))
7489 (when (get-buffer gnus-original-article-buffer)
7490 (set-buffer gnus-original-article-buffer)
7491 (setq gnus-original-article nil)))
7492 (when gnus-use-cache
7493 (gnus-cache-update-article
7494 (car gnus-article-current) (cdr gnus-article-current))))))))
7496 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7497 "The following specs can be used:
7498 %t The security MIME type
7501 %D Details if button is pressed")
7503 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7504 "The following specs can be used:
7505 %t The security MIME type
7508 %D Details if button is pressed")
7510 (defvar gnus-mime-security-button-line-format-alist
7511 '((?t gnus-tmp-type ?s)
7512 (?i gnus-tmp-info ?s)
7513 (?d gnus-tmp-details ?s)
7514 (?D gnus-tmp-pressed-details ?s)))
7516 (defvar gnus-mime-security-button-map
7517 (let ((map (make-sparse-keymap)))
7518 (unless (>= (string-to-number emacs-version) 21)
7519 (set-keymap-parent map gnus-article-mode-map))
7520 (define-key map gnus-mouse-2 'gnus-article-push-button)
7521 (define-key map "\r" 'gnus-article-press-button)
7524 (defvar gnus-mime-security-details-buffer nil)
7526 (defvar gnus-mime-security-button-pressed nil)
7528 (defvar gnus-mime-security-show-details-inline t
7529 "If non-nil, show details in the article buffer.")
7531 (defun gnus-mime-security-verify-or-decrypt (handle)
7532 (mm-remove-parts (cdr handle))
7533 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7534 point buffer-read-only)
7536 (goto-char (car region)))
7538 (narrow-to-region (point) (point))
7539 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7540 (let* ((mm-verify-option 'known)
7541 (mm-decrypt-option 'known)
7542 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7543 (unless (eq nparts (cdr handle))
7544 (mm-destroy-parts (cdr handle))
7545 (setcdr handle nparts))))
7546 (setq point (point))
7547 (gnus-mime-display-security handle)
7548 (goto-char (point-max)))
7550 (delete-region (point) (cdr region))
7551 (set-marker (car region) nil)
7552 (set-marker (cdr region) nil))
7555 (defun gnus-mime-security-show-details (handle)
7556 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7558 (gnus-message 5 "No details.")
7559 (if gnus-mime-security-show-details-inline
7560 (let ((gnus-mime-security-button-pressed
7561 (not (get-text-property (point) 'gnus-mime-details)))
7562 (gnus-mime-security-button-line-format
7563 (get-text-property (point) 'gnus-line-format))
7566 (while (eq (get-text-property (point) 'gnus-line-format)
7567 gnus-mime-security-button-line-format)
7571 (narrow-to-region (point) (point))
7572 (gnus-insert-mime-security-button handle))
7573 (delete-region (point)
7574 (or (text-property-not-all
7577 gnus-mime-security-button-line-format)
7580 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7581 (with-current-buffer gnus-mime-security-details-buffer
7584 (setq gnus-mime-security-details-buffer
7585 (gnus-get-buffer-create "*MIME Security Details*")))
7586 (with-current-buffer gnus-mime-security-details-buffer
7588 (goto-char (point-min)))
7589 (pop-to-buffer gnus-mime-security-details-buffer)))))
7591 (defun gnus-mime-security-press-button (handle)
7593 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7594 (gnus-mime-security-show-details handle)
7595 (gnus-mime-security-verify-or-decrypt handle))))
7597 (defun gnus-insert-mime-security-button (handle &optional displayed)
7598 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7601 (or (nth 2 (assoc protocol mm-verify-function-alist))
7602 (nth 2 (assoc protocol mm-decrypt-function-alist))
7604 (if (equal (car handle) "multipart/signed")
7605 " Signed" " Encrypted")
7608 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7611 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7612 gnus-tmp-pressed-details
7614 (setq gnus-tmp-details
7615 (if gnus-tmp-details
7616 (concat "\n" gnus-tmp-details)
7618 (setq gnus-tmp-pressed-details
7619 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7624 gnus-mime-security-button-line-format
7625 gnus-mime-security-button-line-format-alist
7626 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7627 gnus-callback gnus-mime-security-press-button
7628 gnus-line-format ,gnus-mime-security-button-line-format
7629 gnus-mime-details ,gnus-mime-security-button-pressed
7630 article-type annotation
7633 ;; Exclude a newline.
7636 (widget-convert-button
7639 :action 'gnus-widget-press-button
7640 :button-keymap gnus-mime-security-button-map
7642 (lambda (widget/window &optional overlay pos)
7643 ;; Needed to properly clear the message due to a bug in
7644 ;; wid-edit (XEmacs only).
7645 (when (boundp 'help-echo-owns-message)
7646 (setq help-echo-owns-message t))
7649 (aref gnus-mouse-2 0))))))
7651 (defun gnus-mime-display-security (handle)
7653 (narrow-to-region (point) (point))
7654 (unless (gnus-unbuttonized-mime-type-p (car handle))
7655 (gnus-insert-mime-security-button handle))
7656 (gnus-mime-display-mixed (cdr handle))
7659 (unless (gnus-unbuttonized-mime-type-p (car handle))
7660 (let ((gnus-mime-security-button-line-format
7661 gnus-mime-security-button-end-line-format))
7662 (gnus-insert-mime-security-button handle)))
7663 (mm-set-handle-multipart-parameter
7665 (cons (set-marker (make-marker) (point-min))
7666 (set-marker (make-marker) (point-max))))))
7672 (defun gnus-article-header-presentation-method (entity situation)
7673 (mime-insert-header entity)
7674 (article-decode-group-name))
7676 (set-alist 'mime-header-presentation-method-alist
7677 'gnus-original-article-mode
7678 #'gnus-article-header-presentation-method)
7680 (defun gnus-mime-preview-quitting-method ()
7681 (mime-preview-kill-buffer)
7682 (delete-other-windows)
7683 (gnus-article-show-summary)
7684 (gnus-summary-select-article gnus-show-all-headers t))
7686 (set-alist 'mime-preview-quitting-method-alist
7687 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
7689 (set-alist 'mime-preview-following-method-alist
7690 'gnus-original-article-mode #'gnus-following-method)
7692 (set-alist 'mime-preview-over-to-previous-method-alist
7693 'gnus-original-article-mode
7695 (if (> (point-min) 1)
7696 (gnus-article-prev-page)
7697 (gnus-article-read-summary-keys
7698 nil (gnus-character-to-event ?P)))))
7700 (set-alist 'mime-preview-over-to-next-method-alist
7701 'gnus-original-article-mode'
7703 (if (< (point-max) (buffer-size))
7704 (gnus-article-next-page)
7705 (gnus-article-read-summary-keys
7706 nil (gnus-character-to-event ?N)))))
7716 (run-hooks 'gnus-art-load-hook)
7718 ;;; gnus-art.el ends here