1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
31 (defvar tool-bar-map))
34 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
36 (let ((recursive-load-depth-limit 100))
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (defgroup gnus-article nil
56 :link '(custom-manual "(gnus)Article Buffer")
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
75 (defgroup gnus-article-signature nil
77 :link '(custom-manual "(gnus)Article Signature")
80 (defgroup gnus-article-headers nil
82 :link '(custom-manual "(gnus)Hiding Headers")
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
95 (defgroup gnus-article-saving nil
97 :link '(custom-manual "(gnus)Saving Articles")
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
157 "*All headers that start with this regexp will be hidden.
158 This variable can also be a list of regexps of headers to be ignored.
159 If `gnus-visible-headers' is non-nil, this variable will be ignored."
160 :type '(choice :custom-show nil
163 :group 'gnus-article-hiding)
165 (defcustom gnus-visible-headers
166 "^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:"
167 "*All headers that do not match this regexp will be hidden.
168 This variable can also be a list of regexp of headers to remain visible.
169 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
170 :type '(repeat :value-to-internal (lambda (widget value)
171 (custom-split-regexp-maybe value))
172 :match (lambda (widget value)
174 (widget-editable-list-match widget value)))
176 :group 'gnus-article-hiding)
178 (defcustom gnus-sorted-header-list
179 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
180 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
181 "*This variable is a list of regular expressions.
182 If it is non-nil, headers that match the regular expressions will
183 be placed first in the article buffer in the sequence specified by
185 :type '(repeat regexp)
186 :group 'gnus-article-hiding)
188 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
189 "Headers that are only to be displayed if they have interesting data.
190 Possible values in this list are:
192 'empty Headers with no content.
193 'newsgroups Newsgroup identical to Gnus group.
194 'to-address To identical to To-address.
195 'to-list To identical to To-list.
196 'cc-list CC identical to To-list.
197 'followup-to Followup-to identical to Newsgroups.
198 'reply-to Reply-to identical to From.
199 'date Date less than four days old.
200 'long-to To and/or Cc longer than 1024 characters.
201 'many-to Multiple To and/or Cc."
202 :type '(set (const :tag "Headers with no content." empty)
203 (const :tag "Newsgroups identical to Gnus group." newsgroups)
204 (const :tag "To identical to To-address." to-address)
205 (const :tag "To identical to To-list." to-list)
206 (const :tag "CC identical to To-list." cc-list)
207 (const :tag "Followup-to identical to Newsgroups." followup-to)
208 (const :tag "Reply-to identical to From." reply-to)
209 (const :tag "Date less than four days old." date)
210 (const :tag "To and/or Cc longer than 1024 characters." long-to)
211 (const :tag "Multiple To and/or Cc headers." many-to))
212 :group 'gnus-article-hiding)
214 (defcustom gnus-article-skip-boring nil
215 "Skip over text that is not worth reading.
216 By default, if you set this t, then Gnus will display citations and
217 signatures, but will never scroll down to show you a page consisting
218 only of boring text. Boring text is controlled by
219 `gnus-article-boring-faces'."
222 :group 'gnus-article-hiding)
224 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
225 "Regexp matching signature separator.
226 This can also be a list of regexps. In that case, it will be checked
227 from head to tail looking for a separator. Searches will be done from
228 the end of the buffer."
229 :type '(repeat string)
230 :group 'gnus-article-signature)
232 (defcustom gnus-signature-limit nil
233 "Provide a limit to what is considered a signature.
234 If it is a number, no signature may not be longer (in characters) than
235 that number. If it is a floating point number, no signature may be
236 longer (in lines) than that number. If it is a function, the function
237 will be called without any parameters, and if it returns nil, there is
238 no signature in the buffer. If it is a string, it will be used as a
239 regexp. If it matches, the text in question is not a signature.
241 This can also be a list of the above values."
242 :type '(choice (integer :value 200)
244 (function :value fun)
245 (regexp :value ".*"))
246 :group 'gnus-article-signature)
248 (defcustom gnus-hidden-properties '(invisible t intangible t)
249 "Property list to use for hiding text."
251 :group 'gnus-article-hiding)
253 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
254 ;; frames in a session.
255 (defcustom gnus-article-x-face-command
256 (if (featurep 'xemacs)
257 (if (or (gnus-image-type-available-p 'xface)
258 (gnus-image-type-available-p 'pbm))
259 'gnus-display-x-face-in-from
260 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
261 (if (gnus-image-type-available-p 'pbm)
262 'gnus-display-x-face-in-from
263 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
265 "*String or function to be executed to display an X-Face header.
266 If it is a string, the command will be executed in a sub-shell
267 asynchronously. The compressed face will be piped to this command."
268 :type `(choice string
269 (function-item gnus-display-x-face-in-from)
273 :group 'gnus-article-washing)
275 (defcustom gnus-article-x-face-too-ugly nil
276 "Regexp matching posters whose face shouldn't be shown automatically."
277 :type '(choice regexp (const nil))
278 :group 'gnus-article-washing)
280 (defcustom gnus-article-banner-alist nil
281 "Banner alist for stripping.
283 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
285 :type '(repeat (cons symbol regexp))
286 :group 'gnus-article-washing)
288 (gnus-define-group-parameter
291 "Alist of regexps (to match group names) and banner."
292 :variable-group gnus-article-washing
294 '(choice :tag "Banner"
296 (const :tag "Remove signature" signature)
297 (symbol :tag "Item in `gnus-article-banner-alist'" none)
299 (const :tag "None" nil))
301 "If non-nil, specify how to remove `banners' from articles.
303 Symbol `signature' means to remove signatures delimited by
304 `gnus-signature-separator'. Any other symbol is used to look up a
305 regular expression to match the banner in `gnus-article-banner-alist'.
306 A string is used as a regular expression to match the banner
309 (defcustom gnus-article-address-banner-alist nil
310 "Alist of mail addresses and banners.
311 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
312 to match a mail address in the From: header, BANNER is one of a symbol
313 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
314 If ADDRESS matches author's mail address, it will remove things like
315 advertisements. For example:
317 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
321 (regexp :tag "Address")
322 (choice :tag "Banner" :value nil
323 (const :tag "Remove signature" signature)
324 (symbol :tag "Item in `gnus-article-banner-alist'" none)
326 (const :tag "None" nil))))
328 :group 'gnus-article-washing)
330 (defmacro gnus-emphasis-custom-with-format (&rest body)
332 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
333 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
336 (defun gnus-emphasis-custom-value-to-external (value)
337 (gnus-emphasis-custom-with-format
338 (if (consp (car value))
339 (list (format format (car (car value)) (cdr (car value)))
341 (if (nth 1 value) 2 3)
345 (defun gnus-emphasis-custom-value-to-internal (value)
346 (gnus-emphasis-custom-with-format
347 (let ((regexp (concat "\\`"
348 (format (regexp-quote format)
349 "\\([^()]+\\)" "\\([^()]+\\)")
352 (if (string-match regexp (setq pattern (car value)))
353 (list (cons (match-string 1 pattern) (match-string 2 pattern))
358 (defcustom gnus-emphasis-alist
360 '(("\\*" "\\*" bold nil 2)
363 ("_/" "/_" underline-italic)
364 ("_\\*" "\\*_" underline-bold)
365 ("\\*/" "/\\*" bold-italic)
366 ("_\\*/" "/\\*_" underline-bold-italic))))
368 (gnus-emphasis-custom-with-format
369 (mapcar (lambda (spec)
370 (list (format format (car spec) (cadr spec))
373 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
375 '(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
376 2 3 gnus-emphasis-underline))))
377 "*Alist that says how to fontify certain phrases.
378 Each item looks like this:
380 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
382 The first element is a regular expression to be matched. The second
383 is a number that says what regular expression grouping used to find
384 the entire emphasized word. The third is a number that says what
385 regexp grouping should be displayed and highlighted. The fourth
386 is the face used for highlighting."
390 :format "%[Customizing Style%]\n%v"
392 (group :tag "Default"
393 :value ("" 0 0 default)
396 (let ((value (widget-get
397 (cadr (widget-get (widget-get widget :parent)
400 (if (not (eq (nth 2 value) 'default))
404 (gnus-emphasis-custom-value-to-external value))))
405 (widget-group-value-create widget))
407 (integer :format "Match group: %v")
408 (integer :format "Emphasize group: %v")
411 :value (("_" . "_") nil default)
413 (regexp :format "Start regexp: %v")
414 (regexp :format "End regexp: %v"))
415 (boolean :format "Show start and end patterns: %[%v%]\n"
416 :on " On " :off " Off ")
418 :get (lambda (symbol)
419 (mapcar 'gnus-emphasis-custom-value-to-internal
420 (default-value symbol)))
421 :set (lambda (symbol value)
422 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
424 :group 'gnus-article-emphasis)
426 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
427 "A regexp to describe whitespace which should not be emphasized.
428 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
429 The former avoids underlining of leading and trailing whitespace,
430 and the latter avoids underlining any whitespace at all."
432 :group 'gnus-article-emphasis
435 (defface gnus-emphasis-bold '((t (:bold t)))
436 "Face used for displaying strong emphasized text (*word*)."
437 :group 'gnus-article-emphasis)
439 (defface gnus-emphasis-italic '((t (:italic t)))
440 "Face used for displaying italic emphasized text (/word/)."
441 :group 'gnus-article-emphasis)
443 (defface gnus-emphasis-underline '((t (:underline t)))
444 "Face used for displaying underlined emphasized text (_word_)."
445 :group 'gnus-article-emphasis)
447 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
448 "Face used for displaying underlined bold emphasized text (_*word*_)."
449 :group 'gnus-article-emphasis)
451 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
452 "Face used for displaying underlined italic emphasized text (_/word/_)."
453 :group 'gnus-article-emphasis)
455 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
456 "Face used for displaying bold italic emphasized text (/*word*/)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-underline-bold-italic
460 '((t (:bold t :italic t :underline t)))
461 "Face used for displaying underlined bold italic emphasized text.
462 Example: (_/*word*/_)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
466 '((t (:strikethru t)))
467 '((t (:strike-through t))))
468 "Face used for displaying strike-through text (-word-)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-highlight-words
472 '((t (:background "black" :foreground "yellow")))
473 "Face used for displaying highlighted words."
474 :group 'gnus-article-emphasis)
476 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
477 "Format for display of Date headers in article bodies.
478 See `format-time-string' for the possible values.
480 The variable can also be function, which should return a complete Date
481 header. The function is called with one argument, the time, which can
482 be fed to `format-time-string'."
483 :type '(choice string function)
484 :link '(custom-manual "(gnus)Article Date")
485 :group 'gnus-article-washing)
488 (autoload 'mail-extract-address-components "mail-extr"))
490 (defcustom gnus-save-all-headers t
491 "*If non-nil, don't remove any headers before saving."
492 :group 'gnus-article-saving
495 (defcustom gnus-prompt-before-saving 'always
496 "*This variable says how much prompting is to be done when saving articles.
497 If it is nil, no prompting will be done, and the articles will be
498 saved to the default files. If this variable is `always', each and
499 every article that is saved will be preceded by a prompt, even when
500 saving large batches of articles. If this variable is neither nil not
501 `always', there the user will be prompted once for a file name for
502 each invocation of the saving commands."
503 :group 'gnus-article-saving
504 :type '(choice (item always)
505 (item :tag "never" nil)
506 (sexp :tag "once" :format "%t\n" :value t)))
508 (defcustom gnus-saved-headers gnus-visible-headers
509 "Headers to keep if `gnus-save-all-headers' is nil.
510 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
511 If that variable is nil, however, all headers that match this regexp
512 will be kept while the rest will be deleted before saving."
513 :group 'gnus-article-saving
516 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
517 "A function to save articles in your favourite format.
518 The function must be interactively callable (in other words, it must
519 be an Emacs command).
521 Gnus provides the following functions:
523 * gnus-summary-save-in-rmail (Rmail format)
524 * gnus-summary-save-in-mail (Unix mail format)
525 * gnus-summary-save-in-folder (MH folder)
526 * gnus-summary-save-in-file (article format)
527 * gnus-summary-save-body-in-file (article body)
528 * gnus-summary-save-in-vm (use VM's folder format)
529 * gnus-summary-write-to-file (article format -- overwrite)."
530 :group 'gnus-article-saving
531 :type '(radio (function-item gnus-summary-save-in-rmail)
532 (function-item gnus-summary-save-in-mail)
533 (function-item gnus-summary-save-in-folder)
534 (function-item gnus-summary-save-in-file)
535 (function-item gnus-summary-save-body-in-file)
536 (function-item gnus-summary-save-in-vm)
537 (function-item gnus-summary-write-to-file)))
539 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
540 "A function generating a file name to save articles in Rmail format.
541 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
542 :group 'gnus-article-saving
545 (defcustom gnus-mail-save-name 'gnus-plain-save-name
546 "A function generating a file name to save articles in Unix mail format.
547 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
548 :group 'gnus-article-saving
551 (defcustom gnus-folder-save-name 'gnus-folder-save-name
552 "A function generating a file name to save articles in MH folder.
553 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
554 :group 'gnus-article-saving
557 (defcustom gnus-file-save-name 'gnus-numeric-save-name
558 "A function generating a file name to save articles in article format.
559 The function is called with NEWSGROUP, HEADERS, and optional
561 :group 'gnus-article-saving
564 (defcustom gnus-split-methods
565 '((gnus-article-archive-name)
566 (gnus-article-nndoc-name))
567 "*Variable used to suggest where articles are to be saved.
568 For instance, if you would like to save articles related to Gnus in
569 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
570 you could set this variable to something like:
572 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
573 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
575 This variable is an alist where the key is the match and the
576 value is a list of possible files to save in if the match is
579 If the match is a string, it is used as a regexp match on the
580 article. If the match is a symbol, that symbol will be funcalled
581 from the buffer of the article to be saved with the newsgroup as
582 the parameter. If it is a list, it will be evaled in the same
585 If this form or function returns a string, this string will be
586 used as a possible file name; and if it returns a non-nil list,
587 that list will be used as possible file names."
588 :group 'gnus-article-saving
589 :type '(repeat (choice (list :value (fun) function)
590 (cons :value ("" "") regexp (repeat string))
593 (defcustom gnus-page-delimiter "^\^L"
594 "*Regexp describing what to use as article page delimiters.
595 The default value is \"^\^L\", which is a form linefeed at the
596 beginning of a line."
598 :group 'gnus-article-various)
600 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
601 "*The format specification for the article mode line.
602 See `gnus-summary-mode-line-format' for a closer description.
604 The following additional specs are available:
606 %w The article washing status.
607 %m The number of MIME parts in the article."
609 :group 'gnus-article-various)
611 (defcustom gnus-article-mode-hook nil
612 "*A hook for Gnus article mode."
614 :group 'gnus-article-various)
616 (when (featurep 'xemacs)
617 ;; Extracted from gnus-xmas-define in order to preserve user settings
618 (when (fboundp 'turn-off-scroll-in-place)
619 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
620 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
621 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
623 (defcustom gnus-article-menu-hook nil
624 "*Hook run after the creation of the article mode menu."
626 :group 'gnus-article-various)
628 (defcustom gnus-article-prepare-hook nil
629 "*A hook called after an article has been prepared in the article buffer."
631 :group 'gnus-article-various)
633 (defcustom gnus-copy-article-ignored-headers nil
634 "List of headers to be removed when copying an article.
635 Each element is a regular expression."
636 :version "22.0" ;; No Gnus
637 :type '(repeat regexp)
638 :group 'gnus-article-various)
640 (make-obsolete-variable 'gnus-article-hide-pgp-hook
641 "This variable is obsolete in Gnus 5.10.")
643 (defcustom gnus-article-button-face 'bold
644 "Face used for highlighting buttons in the article buffer.
646 An article button is a piece of text that you can activate by pressing
647 `RET' or `mouse-2' above it."
649 :group 'gnus-article-buttons)
651 (defcustom gnus-article-mouse-face 'highlight
652 "Face used for mouse highlighting in the article buffer.
654 Article buttons will be displayed in this face when the cursor is
657 :group 'gnus-article-buttons)
659 (defcustom gnus-signature-face 'gnus-signature-face
660 "Face used for highlighting a signature in the article buffer.
661 Obsolete; use the face `gnus-signature-face' for customizations instead."
663 :group 'gnus-article-highlight
664 :group 'gnus-article-signature)
666 (defface gnus-signature-face
669 "Face used for highlighting a signature in the article buffer."
670 :group 'gnus-article-highlight
671 :group 'gnus-article-signature)
673 (defface gnus-header-from-face
676 (:foreground "spring green"))
679 (:foreground "red3"))
682 "Face used for displaying from headers."
683 :group 'gnus-article-headers
684 :group 'gnus-article-highlight)
686 (defface gnus-header-subject-face
689 (:foreground "SeaGreen3"))
692 (:foreground "red4"))
694 (:bold t :italic t)))
695 "Face used for displaying subject headers."
696 :group 'gnus-article-headers
697 :group 'gnus-article-highlight)
699 (defface gnus-header-newsgroups-face
702 (:foreground "yellow" :italic t))
705 (:foreground "MidnightBlue" :italic t))
708 "Face used for displaying newsgroups headers.
709 In the default setup this face is only used for crossposted
711 :group 'gnus-article-headers
712 :group 'gnus-article-highlight)
714 (defface gnus-header-name-face
717 (:foreground "SeaGreen"))
720 (:foreground "maroon"))
723 "Face used for displaying header names."
724 :group 'gnus-article-headers
725 :group 'gnus-article-highlight)
727 (defface gnus-header-content-face
730 (:foreground "forest green" :italic t))
733 (:foreground "indianred4" :italic t))
735 (:italic t))) "Face used for displaying header content."
736 :group 'gnus-article-headers
737 :group 'gnus-article-highlight)
739 (defcustom gnus-header-face-alist
740 '(("From" nil gnus-header-from-face)
741 ("Subject" nil gnus-header-subject-face)
742 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
743 ("" gnus-header-name-face gnus-header-content-face))
744 "*Controls highlighting of article headers.
746 An alist of the form (HEADER NAME CONTENT).
748 HEADER is a regular expression which should match the name of a
749 header and NAME and CONTENT are either face names or nil.
751 The name of each header field will be displayed using the face
752 specified by the first element in the list where HEADER matches
753 the header name and NAME is non-nil. Similarly, the content will
754 be displayed by the first non-nil matching CONTENT face."
755 :group 'gnus-article-headers
756 :group 'gnus-article-highlight
757 :type '(repeat (list (regexp :tag "Header")
759 (item :tag "skip" nil)
760 (face :value default))
761 (choice :tag "Content"
762 (item :tag "skip" nil)
763 (face :value default)))))
765 (defcustom gnus-article-decode-hook
766 '(article-decode-charset article-decode-encoded-words
767 article-decode-group-name article-decode-idna-rhs)
768 "*Hook run to decode charsets in articles."
769 :group 'gnus-article-headers
772 (defcustom gnus-display-mime-function 'gnus-display-mime
773 "Function to display MIME articles."
774 :group 'gnus-article-mime
777 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
778 "Function used to decode headers.")
780 (defvar gnus-article-dumbquotes-map
800 "Table for MS-to-Latin1 translation.")
802 (defcustom gnus-ignored-mime-types nil
803 "List of MIME types that should be ignored by Gnus."
805 :group 'gnus-article-mime
806 :type '(repeat regexp))
808 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
809 "List of MIME types that should not be given buttons when rendered inline.
810 See also `gnus-buttonized-mime-types' which may override this variable.
811 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
813 :group 'gnus-article-mime
814 :type '(repeat regexp))
816 (defcustom gnus-buttonized-mime-types nil
817 "List of MIME types that should be given buttons when rendered inline.
818 If set, this variable overrides `gnus-unbuttonized-mime-types'.
819 To see e.g. security buttons you could set this to
820 `(\"multipart/signed\")'.
821 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
823 :group 'gnus-article-mime
824 :type '(repeat regexp))
826 (defcustom gnus-inhibit-mime-unbuttonizing nil
827 "If non-nil, all MIME parts get buttons.
828 When nil (the default value), then some MIME parts do not get buttons,
829 as described by the variables `gnus-buttonized-mime-types' and
830 `gnus-unbuttonized-mime-types'."
832 :group 'gnus-article-mime
835 (defcustom gnus-body-boundary-delimiter "_"
836 "String used to delimit header and body.
837 This variable is used by `gnus-article-treat-body-boundary' which can
838 be controlled by `gnus-treat-body-boundary'."
840 :group 'gnus-article-various
841 :type '(choice (item :tag "None" :value nil)
844 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
846 "Defines the location of the faces database.
847 For information on obtaining this database of pretty pictures, please
848 see http://www.cs.indiana.edu/picons/ftp/index.html"
850 :type '(repeat directory)
851 :link '(url-link :tag "download"
852 "http://www.cs.indiana.edu/picons/ftp/index.html")
853 :link '(custom-manual "(gnus)Picons")
856 (defun gnus-picons-installed-p ()
857 "Say whether picons are installed on your machine."
858 (let ((installed nil))
859 (dolist (database gnus-picon-databases)
860 (when (file-exists-p database)
864 (defcustom gnus-article-mime-part-function nil
865 "Function called with a MIME handle as the argument.
866 This is meant for people who want to do something automatic based
867 on parts -- for instance, adding Vcard info to a database."
868 :group 'gnus-article-mime
871 (defcustom gnus-mime-multipart-functions nil
872 "An alist of MIME types to functions to display them."
874 :group 'gnus-article-mime
875 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
877 (defcustom gnus-article-date-lapsed-new-header nil
878 "Whether the X-Sent and Date headers can coexist.
879 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
880 either replace the old \"Date:\" header (if this variable is nil), or
881 be added below it (otherwise)."
883 :group 'gnus-article-headers
886 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
887 "Function called with a MIME handle as the argument.
888 This is meant for people who want to view first matched part.
889 For `undisplayed-alternative' (default), the first undisplayed
890 part or alternative part is used. For `undisplayed', the first
891 undisplayed part is used. For a function, the first part which
892 the function return t is used. For nil, the first part is
895 :group 'gnus-article-mime
897 (item :tag "first" :value nil)
898 (item :tag "undisplayed" :value undisplayed)
899 (item :tag "undisplayed or alternative"
900 :value undisplayed-alternative)
903 (defcustom gnus-mime-action-alist
904 '(("save to file" . gnus-mime-save-part)
905 ("save and strip" . gnus-mime-save-part-and-strip)
906 ("delete part" . gnus-mime-delete-part)
907 ("display as text" . gnus-mime-inline-part)
908 ("view the part" . gnus-mime-view-part)
909 ("pipe to command" . gnus-mime-pipe-part)
910 ("toggle display" . gnus-article-press-button)
911 ("toggle display" . gnus-article-view-part-as-charset)
912 ("view as type" . gnus-mime-view-part-as-type)
913 ("view internally" . gnus-mime-view-part-internally)
914 ("view externally" . gnus-mime-view-part-externally))
915 "An alist of actions that run on the MIME attachment."
916 :group 'gnus-article-mime
917 :type '(repeat (cons (string :tag "name")
921 ;;; The treatment variables
924 (defvar gnus-part-display-hook nil
925 "Hook called on parts that are to receive treatment.")
927 (defvar gnus-article-treat-custom
928 '(choice (const :tag "Off" nil)
930 (const :tag "Header" head)
931 (const :tag "Last" last)
932 (integer :tag "Less")
933 (repeat :tag "Groups" regexp)
934 (sexp :tag "Predicate")))
936 (defvar gnus-article-treat-head-custom
937 '(choice (const :tag "Off" nil)
938 (const :tag "Header" head)))
940 (defvar gnus-article-treat-types '("text/plain")
943 (defvar gnus-inhibit-treatment nil
944 "Whether to inhibit treatment.")
946 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
947 "Highlight the signature.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See Info node `(gnus)Customizing Articles'."
950 :group 'gnus-article-treat
951 :link '(custom-manual "(gnus)Customizing Articles")
952 :type gnus-article-treat-custom)
953 (put 'gnus-treat-highlight-signature 'highlight t)
955 (defcustom gnus-treat-buttonize 100000
957 Valid values are nil, t, `head', `last', an integer or a predicate.
958 See Info node `(gnus)Customizing Articles'."
959 :group 'gnus-article-treat
960 :link '(custom-manual "(gnus)Customizing Articles")
961 :type gnus-article-treat-custom)
962 (put 'gnus-treat-buttonize 'highlight t)
964 (defcustom gnus-treat-buttonize-head 'head
965 "Add buttons to the head.
966 Valid values are nil, t, `head', `last', an integer or a predicate.
967 See Info node `(gnus)Customizing Articles' for details."
968 :group 'gnus-article-treat
969 :link '(custom-manual "(gnus)Customizing Articles")
970 :type gnus-article-treat-head-custom)
971 (put 'gnus-treat-buttonize-head 'highlight t)
973 (defcustom gnus-treat-emphasize
974 (and (or window-system
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)
983 (put 'gnus-treat-emphasize 'highlight t)
985 (defcustom gnus-treat-strip-cr nil
986 "Remove carriage returns.
987 Valid values are nil, t, `head', `last', an integer or a predicate.
988 See Info node `(gnus)Customizing Articles' for details."
990 :group 'gnus-article-treat
991 :link '(custom-manual "(gnus)Customizing Articles")
992 :type gnus-article-treat-custom)
994 (defcustom gnus-treat-unsplit-urls nil
995 "Remove newlines from within URLs.
996 Valid values are nil, t, `head', `last', an integer or a predicate.
997 See Info node `(gnus)Customizing Articles' for details."
999 :group 'gnus-article-treat
1000 :link '(custom-manual "(gnus)Customizing Articles")
1001 :type gnus-article-treat-custom)
1003 (defcustom gnus-treat-leading-whitespace nil
1004 "Remove leading whitespace in headers.
1005 Valid values are nil, t, `head', `last', an integer or a predicate.
1006 See Info node `(gnus)Customizing Articles' for details."
1008 :group 'gnus-article-treat
1009 :link '(custom-manual "(gnus)Customizing Articles")
1010 :type gnus-article-treat-custom)
1012 (defcustom gnus-treat-hide-headers 'head
1014 Valid values are nil, t, `head', `last', an integer or a predicate.
1015 See Info node `(gnus)Customizing Articles' for details."
1016 :group 'gnus-article-treat
1017 :link '(custom-manual "(gnus)Customizing Articles")
1018 :type gnus-article-treat-head-custom)
1020 (defcustom gnus-treat-hide-boring-headers nil
1021 "Hide boring headers.
1022 Valid values are nil, t, `head', `last', an integer or a predicate.
1023 See Info node `(gnus)Customizing Articles' for details."
1024 :group 'gnus-article-treat
1025 :link '(custom-manual "(gnus)Customizing Articles")
1026 :type gnus-article-treat-head-custom)
1028 (defcustom gnus-treat-hide-signature nil
1029 "Hide the signature.
1030 Valid values are nil, t, `head', `last', an integer or a predicate.
1031 See Info node `(gnus)Customizing Articles' for details."
1032 :group 'gnus-article-treat
1033 :link '(custom-manual "(gnus)Customizing Articles")
1034 :type gnus-article-treat-custom)
1036 (defcustom gnus-treat-fill-article nil
1038 Valid values are nil, t, `head', `last', an integer or a predicate.
1039 See Info node `(gnus)Customizing Articles' for details."
1040 :group 'gnus-article-treat
1041 :link '(custom-manual "(gnus)Customizing Articles")
1042 :type gnus-article-treat-custom)
1044 (defcustom gnus-treat-hide-citation nil
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-hide-citation-maybe nil
1054 Valid values are nil, t, `head', `last', an integer or a predicate.
1055 See Info node `(gnus)Customizing Articles' for details."
1056 :group 'gnus-article-treat
1057 :link '(custom-manual "(gnus)Customizing Articles")
1058 :type gnus-article-treat-custom)
1060 (defcustom gnus-treat-strip-list-identifiers 'head
1061 "Strip list identifiers from `gnus-list-identifiers`.
1062 Valid values are nil, t, `head', `last', an integer or a predicate.
1063 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-custom)
1069 (make-obsolete-variable 'gnus-treat-strip-pgp
1070 "This option is obsolete in Gnus 5.10.")
1072 (defcustom gnus-treat-strip-pem nil
1073 "Strip PEM signatures.
1074 Valid values are nil, t, `head', `last', an integer or a predicate.
1075 See Info node `(gnus)Customizing Articles' for details."
1076 :group 'gnus-article-treat
1077 :link '(custom-manual "(gnus)Customizing Articles")
1078 :type gnus-article-treat-custom)
1080 (defcustom gnus-treat-strip-banner t
1081 "Strip banners from articles.
1082 The banner to be stripped is specified in the `banner' group parameter.
1083 Valid values are nil, t, `head', `last', an integer or a predicate.
1084 See Info node `(gnus)Customizing Articles' for details."
1085 :group 'gnus-article-treat
1086 :link '(custom-manual "(gnus)Customizing Articles")
1087 :type gnus-article-treat-custom)
1089 (defcustom gnus-treat-highlight-headers 'head
1090 "Highlight the headers.
1091 Valid values are nil, t, `head', `last', an integer or a predicate.
1092 See Info node `(gnus)Customizing Articles' for details."
1093 :group 'gnus-article-treat
1094 :link '(custom-manual "(gnus)Customizing Articles")
1095 :type gnus-article-treat-head-custom)
1096 (put 'gnus-treat-highlight-headers 'highlight t)
1098 (defcustom gnus-treat-highlight-citation t
1099 "Highlight cited text.
1100 Valid values are nil, t, `head', `last', an integer or a predicate.
1101 See Info node `(gnus)Customizing Articles' for details."
1102 :group 'gnus-article-treat
1103 :link '(custom-manual "(gnus)Customizing Articles")
1104 :type gnus-article-treat-custom)
1105 (put 'gnus-treat-highlight-citation 'highlight t)
1107 (defcustom gnus-treat-date-ut nil
1108 "Display the Date in UT (GMT).
1109 Valid values are nil, t, `head', `last', an integer or a predicate.
1110 See Info node `(gnus)Customizing Articles' for details."
1111 :group 'gnus-article-treat
1112 :link '(custom-manual "(gnus)Customizing Articles")
1113 :type gnus-article-treat-head-custom)
1115 (defcustom gnus-treat-date-local nil
1116 "Display the Date in the local timezone.
1117 Valid values are nil, t, `head', `last', an integer or a predicate.
1118 See Info node `(gnus)Customizing Articles' for details."
1119 :group 'gnus-article-treat
1120 :link '(custom-manual "(gnus)Customizing Articles")
1121 :type gnus-article-treat-head-custom)
1123 (defcustom gnus-treat-date-english nil
1124 "Display the Date in a format that can be read aloud in English.
1125 Valid values are nil, t, `head', `last', an integer or a predicate.
1126 See Info node `(gnus)Customizing Articles' for details."
1128 :group 'gnus-article-treat
1129 :link '(custom-manual "(gnus)Customizing Articles")
1130 :type gnus-article-treat-head-custom)
1132 (defcustom gnus-treat-date-lapsed nil
1133 "Display the Date header in a way that says how much time has elapsed.
1134 Valid values are nil, t, `head', `last', an integer or a predicate.
1135 See Info node `(gnus)Customizing Articles' for details."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-head-custom)
1140 (defcustom gnus-treat-date-original nil
1141 "Display the date in the original timezone.
1142 Valid values are nil, t, `head', `last', an integer or a predicate.
1143 See Info node `(gnus)Customizing Articles' for details."
1144 :group 'gnus-article-treat
1145 :link '(custom-manual "(gnus)Customizing Articles")
1146 :type gnus-article-treat-head-custom)
1148 (defcustom gnus-treat-date-iso8601 nil
1149 "Display the date in the ISO8601 format.
1150 Valid values are nil, t, `head', `last', an integer or a predicate.
1151 See Info node `(gnus)Customizing Articles' for details."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-head-custom)
1157 (defcustom gnus-treat-date-user-defined nil
1158 "Display the date in a user-defined format.
1159 The format is defined by the `gnus-article-time-format' variable.
1160 Valid values are nil, t, `head', `last', an integer or a predicate.
1161 See Info node `(gnus)Customizing Articles' for details."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-strip-headers-in-body t
1167 "Strip the X-No-Archive header line from the beginning of the body.
1168 Valid values are nil, t, `head', `last', an integer or a predicate.
1169 See Info node `(gnus)Customizing Articles' for details."
1171 :group 'gnus-article-treat
1172 :link '(custom-manual "(gnus)Customizing Articles")
1173 :type gnus-article-treat-custom)
1175 (defcustom gnus-treat-strip-trailing-blank-lines nil
1176 "Strip trailing blank lines.
1177 Valid values are nil, t, `head', `last', an integer or a predicate.
1178 See Info node `(gnus)Customizing Articles' for details."
1179 :group 'gnus-article-treat
1180 :link '(custom-manual "(gnus)Customizing Articles")
1181 :type gnus-article-treat-custom)
1183 (defcustom gnus-treat-strip-leading-blank-lines nil
1184 "Strip leading blank lines.
1185 Valid values are nil, t, `head', `last', an integer or a predicate.
1186 See Info node `(gnus)Customizing Articles' for details."
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-custom)
1191 (defcustom gnus-treat-strip-multiple-blank-lines nil
1192 "Strip multiple blank lines.
1193 Valid values are nil, t, `head', `last', an integer or a predicate.
1194 See Info node `(gnus)Customizing Articles' for details."
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-unfold-headers 'head
1200 "Unfold folded header lines.
1201 Valid values are nil, t, `head', `last', an integer or a predicate.
1202 See Info node `(gnus)Customizing Articles' for details."
1204 :group 'gnus-article-treat
1205 :link '(custom-manual "(gnus)Customizing Articles")
1206 :type gnus-article-treat-custom)
1208 (defcustom gnus-treat-fold-headers nil
1210 Valid values are nil, t, `head', `last', an integer or a predicate.
1211 See Info node `(gnus)Customizing Articles' for details."
1213 :group 'gnus-article-treat
1214 :link '(custom-manual "(gnus)Customizing Articles")
1215 :type gnus-article-treat-custom)
1217 (defcustom gnus-treat-fold-newsgroups 'head
1218 "Fold the Newsgroups and Followup-To headers.
1219 Valid values are nil, t, `head', `last', an integer or a predicate.
1220 See Info node `(gnus)Customizing Articles' for details."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-overstrike t
1227 "Treat overstrike highlighting.
1228 Valid values are nil, t, `head', `last', an integer or a predicate.
1229 See Info node `(gnus)Customizing Articles' for details."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1233 (put 'gnus-treat-overstrike 'highlight t)
1235 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1236 "Treat ANSI SGR control sequences.
1237 Valid values are nil, t, `head', `last', an integer or a predicate.
1238 See Info node `(gnus)Customizing Articles' for details."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-custom)
1243 (make-obsolete-variable 'gnus-treat-display-xface
1244 'gnus-treat-display-x-face)
1246 (defcustom gnus-treat-display-x-face
1247 (and (not noninteractive)
1248 (or (and (fboundp 'image-type-available-p)
1249 (image-type-available-p 'xbm)
1250 (string-match "^0x" (shell-command-to-string "uncompface"))
1251 (executable-find "icontopbm"))
1252 (and (featurep 'xemacs)
1255 "Display X-Face headers.
1256 Valid values are nil, t, `head', `last', an integer or a predicate.
1257 See Info node `(gnus)Customizing Articles' and Info node
1258 `(gnus)X-Face' for details."
1259 :group 'gnus-article-treat
1261 :link '(custom-manual "(gnus)Customizing Articles")
1262 :link '(custom-manual "(gnus)X-Face")
1263 :type gnus-article-treat-head-custom
1264 :set (lambda (symbol value)
1267 (cond ((or (boundp symbol) (get symbol 'saved-value))
1269 ((boundp 'gnus-treat-display-xface)
1271 ** gnus-treat-display-xface is an obsolete variable;\
1272 use gnus-treat-display-x-face instead")
1273 (default-value 'gnus-treat-display-xface))
1274 ((get 'gnus-treat-display-xface 'saved-value)
1276 ** gnus-treat-display-xface is an obsolete variable;\
1277 use gnus-treat-display-x-face instead")
1278 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1281 (put 'gnus-treat-display-x-face 'highlight t)
1283 (defcustom gnus-treat-display-face
1284 (and (not noninteractive)
1285 (or (and (fboundp 'image-type-available-p)
1286 (image-type-available-p 'png))
1287 (and (featurep 'xemacs)
1290 "Display Face headers.
1291 Valid values are nil, t, `head', `last', an integer or a predicate.
1292 See Info node `(gnus)Customizing Articles' and Info node
1293 `(gnus)X-Face' for details."
1294 :group 'gnus-article-treat
1296 :link '(custom-manual "(gnus)Customizing Articles")
1297 :link '(custom-manual "(gnus)X-Face")
1298 :type gnus-article-treat-head-custom)
1299 (put 'gnus-treat-display-face 'highlight t)
1301 (defcustom gnus-treat-display-smileys
1302 (if (or (and (featurep 'xemacs)
1304 (and (fboundp 'image-type-available-p)
1305 (image-type-available-p 'pbm)))
1308 Valid values are nil, t, `head', `last', an integer or a predicate.
1309 See Info node `(gnus)Customizing Articles' and Info node
1310 `(gnus)Smileys' for details."
1311 :group 'gnus-article-treat
1313 :link '(custom-manual "(gnus)Customizing Articles")
1314 :link '(custom-manual "(gnus)Smileys")
1315 :type gnus-article-treat-custom)
1316 (put 'gnus-treat-display-smileys 'highlight t)
1318 (defcustom gnus-treat-from-picon
1319 (if (and (gnus-image-type-available-p 'xpm)
1320 (gnus-picons-installed-p))
1322 "Display picons in the From header.
1323 Valid values are nil, t, `head', `last', an integer or a predicate.
1324 See Info node `(gnus)Customizing Articles' and Info node
1325 `(gnus)Picons' for details."
1327 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :link '(custom-manual "(gnus)Picons")
1331 :type gnus-article-treat-head-custom)
1332 (put 'gnus-treat-from-picon 'highlight t)
1334 (defcustom gnus-treat-mail-picon
1335 (if (and (gnus-image-type-available-p 'xpm)
1336 (gnus-picons-installed-p))
1338 "Display picons in To and Cc headers.
1339 Valid values are nil, t, `head', `last', an integer or a predicate.
1340 See Info node `(gnus)Customizing Articles' and Info node
1341 `(gnus)Picons' for details."
1343 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :link '(custom-manual "(gnus)Picons")
1347 :type gnus-article-treat-head-custom)
1348 (put 'gnus-treat-mail-picon 'highlight t)
1350 (defcustom gnus-treat-newsgroups-picon
1351 (if (and (gnus-image-type-available-p 'xpm)
1352 (gnus-picons-installed-p))
1354 "Display picons in the Newsgroups and Followup-To headers.
1355 Valid values are nil, t, `head', `last', an integer or a predicate.
1356 See Info node `(gnus)Customizing Articles' and Info node
1357 `(gnus)Picons' for details."
1359 :group 'gnus-article-treat
1361 :link '(custom-manual "(gnus)Customizing Articles")
1362 :link '(custom-manual "(gnus)Picons")
1363 :type gnus-article-treat-head-custom)
1364 (put 'gnus-treat-newsgroups-picon 'highlight t)
1366 (defcustom gnus-treat-body-boundary
1367 (if (and (eq window-system 'x)
1368 (or gnus-treat-newsgroups-picon
1369 gnus-treat-mail-picon
1370 gnus-treat-from-picon))
1372 "Draw a boundary at the end of the headers.
1373 Valid values are nil and `head'.
1374 See Info node `(gnus)Customizing Articles' for details."
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-head-custom)
1380 (defcustom gnus-treat-capitalize-sentences nil
1381 "Capitalize sentence-starting words.
1382 Valid values are nil, t, `head', `last', an integer or a predicate.
1383 See Info node `(gnus)Customizing Articles' for details."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-wash-html nil
1391 Valid values are nil, t, `head', `last', an integer or a predicate.
1392 See Info node `(gnus)Customizing Articles' for details."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (defcustom gnus-treat-fill-long-lines nil
1400 Valid values are nil, t, `head', `last', an integer or a predicate.
1401 See Info node `(gnus)Customizing Articles' for details."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1406 (defcustom gnus-treat-play-sounds nil
1408 Valid values are nil, t, `head', `last', an integer or a predicate.
1409 See Info node `(gnus)Customizing Articles' for details."
1411 :group 'gnus-article-treat
1412 :link '(custom-manual "(gnus)Customizing Articles")
1413 :type gnus-article-treat-custom)
1415 (defcustom gnus-treat-translate nil
1416 "Translate articles from one language to another.
1417 Valid values are nil, t, `head', `last', an integer or a predicate.
1418 See Info node `(gnus)Customizing Articles' for details."
1420 :group 'gnus-article-treat
1421 :link '(custom-manual "(gnus)Customizing Articles")
1422 :type gnus-article-treat-custom)
1424 (defcustom gnus-treat-x-pgp-sig nil
1426 To automatically treat X-PGP-Sig, set it to head.
1427 Valid values are nil, t, `head', `last', an integer or a predicate.
1428 See Info node `(gnus)Customizing Articles' for details."
1430 :group 'gnus-article-treat
1431 :group 'mime-security
1432 :link '(custom-manual "(gnus)Customizing Articles")
1433 :type gnus-article-treat-custom)
1435 (defvar gnus-article-encrypt-protocol-alist
1436 '(("PGP" . mml2015-self-encrypt)))
1438 ;; Set to nil if more than one protocol added to
1439 ;; gnus-article-encrypt-protocol-alist.
1440 (defcustom gnus-article-encrypt-protocol "PGP"
1441 "The protocol used for encrypt articles.
1442 It is a string, such as \"PGP\". If nil, ask user."
1445 :group 'mime-security)
1447 (defvar gnus-article-wash-function nil
1448 "Function used for converting HTML into text.")
1450 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1451 (mm-coding-system-p 'utf-8)
1452 (executable-find idna-program))
1453 "Whether IDNA decoding of headers is used when viewing messages.
1454 This requires GNU Libidn, and by default only enabled if it is found."
1456 :group 'gnus-article-headers
1459 (defcustom gnus-article-over-scroll nil
1460 "If non-nil, allow scrolling the article buffer even when there no more text."
1462 :group 'gnus-article
1465 ;;; Internal variables
1467 (defvar gnus-english-month-names
1468 '("January" "February" "March" "April" "May" "June" "July" "August"
1469 "September" "October" "November" "December"))
1471 (defvar gnus-button-regexp nil)
1472 (defvar gnus-button-marker-list nil)
1473 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1475 (defvar gnus-button-last nil)
1476 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
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-x-pgp-sig gnus-article-verify-x-pgp-sig)
1486 (gnus-treat-strip-banner gnus-article-strip-banner)
1487 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1488 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1489 (gnus-treat-buttonize gnus-article-add-buttons)
1490 (gnus-treat-fill-article gnus-article-fill-cited-article)
1491 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1492 (gnus-treat-strip-cr gnus-article-remove-cr)
1493 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1494 (gnus-treat-date-ut gnus-article-date-ut)
1495 (gnus-treat-date-local gnus-article-date-local)
1496 (gnus-treat-date-english gnus-article-date-english)
1497 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1498 (gnus-treat-date-original gnus-article-date-original)
1499 (gnus-treat-date-user-defined gnus-article-date-user)
1500 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1501 (gnus-treat-display-x-face gnus-article-display-x-face)
1502 (gnus-treat-display-face gnus-article-display-face)
1503 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1504 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1505 (gnus-treat-hide-signature gnus-article-hide-signature)
1506 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1507 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1508 (gnus-treat-strip-pem gnus-article-hide-pem)
1509 (gnus-treat-from-picon gnus-treat-from-picon)
1510 (gnus-treat-mail-picon gnus-treat-mail-picon)
1511 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1512 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1513 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1514 (gnus-treat-strip-trailing-blank-lines
1515 gnus-article-remove-trailing-blank-lines)
1516 (gnus-treat-strip-leading-blank-lines
1517 gnus-article-strip-leading-blank-lines)
1518 (gnus-treat-strip-multiple-blank-lines
1519 gnus-article-strip-multiple-blank-lines)
1520 (gnus-treat-overstrike gnus-article-treat-overstrike)
1521 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1522 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1523 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1524 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1525 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1526 (gnus-treat-display-smileys gnus-treat-smiley)
1527 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1528 (gnus-treat-wash-html gnus-article-wash-html)
1529 (gnus-treat-emphasize gnus-article-emphasize)
1530 (gnus-treat-hide-citation gnus-article-hide-citation)
1531 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1532 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1533 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1534 (gnus-treat-play-sounds gnus-earcon-display)))
1536 (defvar gnus-article-mime-handle-alist nil)
1537 (defvar article-lapsed-timer nil)
1538 (defvar gnus-article-current-summary nil)
1540 (defvar gnus-article-mode-syntax-table
1541 (let ((table (copy-syntax-table text-mode-syntax-table)))
1542 ;; This causes the citation match run O(2^n).
1543 ;; (modify-syntax-entry ?- "w" table)
1544 (modify-syntax-entry ?> ")<" table)
1545 (modify-syntax-entry ?< "(>" table)
1546 ;; make M-. in article buffers work for `foo' strings
1547 (modify-syntax-entry ?' " " table)
1548 (modify-syntax-entry ?` " " table)
1550 "Syntax table used in article mode buffers.
1551 Initialized from `text-mode-syntax-table.")
1553 (defvar gnus-save-article-buffer nil)
1555 (defvar gnus-article-mode-line-format-alist
1556 (nconc '((?w (gnus-article-wash-status) ?s)
1557 (?m (gnus-article-mime-part-status) ?s))
1558 gnus-summary-mode-line-format-alist))
1560 (defvar gnus-number-of-articles-to-be-saved nil)
1562 (defvar gnus-inhibit-hiding nil)
1564 (defvar gnus-article-edit-mode nil)
1566 ;;; Macros for dealing with the article buffer.
1568 (defmacro gnus-with-article-headers (&rest forms)
1570 (set-buffer gnus-article-buffer)
1572 (let ((inhibit-read-only t)
1573 (inhibit-point-motion-hooks t)
1574 (case-fold-search t))
1575 (article-narrow-to-head)
1578 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1579 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1581 (defmacro gnus-with-article-buffer (&rest forms)
1583 (set-buffer gnus-article-buffer)
1584 (let ((inhibit-read-only t))
1587 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1588 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1590 (defun gnus-article-goto-header (header)
1591 "Go to HEADER, which is a regular expression."
1592 (re-search-forward (concat "^\\(" header "\\):") nil t))
1594 (defsubst gnus-article-hide-text (b e props)
1595 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1596 (gnus-add-text-properties-when 'article-type nil b e props)
1597 (when (memq 'intangible props)
1599 (max (1- b) (point-min))
1600 b 'intangible (cddr (memq 'intangible props)))))
1602 (defsubst gnus-article-unhide-text (b e)
1603 "Remove hidden text properties from region between B and E."
1604 (remove-text-properties b e gnus-hidden-properties)
1605 (when (memq 'intangible gnus-hidden-properties)
1606 (put-text-property (max (1- b) (point-min))
1607 b 'intangible nil)))
1609 (defun gnus-article-hide-text-type (b e type)
1610 "Hide text of TYPE between B and E."
1611 (gnus-add-wash-type type)
1612 (gnus-article-hide-text
1613 b e (cons 'article-type (cons type gnus-hidden-properties))))
1615 (defun gnus-article-unhide-text-type (b e type)
1616 "Unhide text of TYPE between B and E."
1617 (gnus-delete-wash-type type)
1618 (remove-text-properties
1619 b e (cons 'article-type (cons type gnus-hidden-properties)))
1620 (when (memq 'intangible gnus-hidden-properties)
1621 (put-text-property (max (1- b) (point-min))
1622 b 'intangible nil)))
1624 (defun gnus-article-hide-text-of-type (type)
1625 "Hide text of TYPE in the current buffer."
1627 (let ((b (point-min))
1629 (while (setq b (text-property-any b e 'article-type type))
1630 (add-text-properties b (incf b) gnus-hidden-properties)))))
1632 (defun gnus-article-delete-text-of-type (type)
1633 "Delete text of TYPE in the current buffer."
1635 (let ((b (point-min)))
1636 (while (setq b (text-property-any b (point-max) 'article-type type))
1638 b (or (text-property-not-all b (point-max) 'article-type type)
1641 (defun gnus-article-delete-invisible-text ()
1642 "Delete all invisible text in the current buffer."
1644 (let ((b (point-min)))
1645 (while (setq b (text-property-any b (point-max) 'invisible t))
1647 b (or (text-property-not-all b (point-max) 'invisible t)
1650 (defun gnus-article-text-type-exists-p (type)
1651 "Say whether any text of type TYPE exists in the buffer."
1652 (text-property-any (point-min) (point-max) 'article-type type))
1654 (defsubst gnus-article-header-rank ()
1655 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1656 (let ((list gnus-sorted-header-list)
1659 (if (looking-at (car list))
1661 (setq list (cdr list))
1665 (defun article-hide-headers (&optional arg delete)
1666 "Hide unwanted headers and possibly sort them as well."
1668 ;; This function might be inhibited.
1669 (unless gnus-inhibit-hiding
1670 (let ((inhibit-read-only nil)
1671 (case-fold-search t)
1672 (max (1+ (length gnus-sorted-header-list)))
1673 (inhibit-point-motion-hooks t)
1674 (cur (current-buffer))
1675 ignored visible beg)
1677 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1678 ;; group parameters, so we should go to the summary buffer.
1681 (progn (set-buffer gnus-summary-buffer) t)
1683 (setq ignored (when (not gnus-visible-headers)
1684 (cond ((stringp gnus-ignored-headers)
1685 gnus-ignored-headers)
1686 ((listp gnus-ignored-headers)
1687 (mapconcat 'identity
1688 gnus-ignored-headers
1690 visible (cond ((stringp gnus-visible-headers)
1691 gnus-visible-headers)
1692 ((and gnus-visible-headers
1693 (listp gnus-visible-headers))
1694 (mapconcat 'identity
1695 gnus-visible-headers
1699 ;; First we narrow to just the headers.
1700 (article-narrow-to-head)
1701 ;; Hide any "From " lines at the beginning of (mail) articles.
1702 (while (looking-at "From ")
1705 (delete-region (point-min) (point)))
1706 ;; Then treat the rest of the header lines.
1707 ;; Then we use the two regular expressions
1708 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1709 ;; select which header lines is to remain visible in the
1711 (while (re-search-forward "^[^ \t:]*:" nil t)
1713 ;; Mark the rank of the header.
1715 (point) (1+ (point)) 'message-rank
1716 (if (or (and visible (looking-at visible))
1718 (not (looking-at ignored))))
1719 (gnus-article-header-rank)
1722 (message-sort-headers-1)
1723 (when (setq beg (text-property-any
1724 (point-min) (point-max) 'message-rank (+ 2 max)))
1725 ;; We delete the unwanted headers.
1726 (gnus-add-wash-type 'headers)
1727 (add-text-properties (point-min) (+ 5 (point-min))
1728 '(article-type headers dummy-invisible t))
1729 (delete-region beg (point-max))))))))
1731 (defun article-hide-boring-headers (&optional arg)
1732 "Toggle hiding of headers that aren't very interesting.
1733 If given a negative prefix, always show; if given a positive prefix,
1735 (interactive (gnus-article-hidden-arg))
1736 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1737 (not gnus-show-all-headers))
1740 (let ((inhibit-read-only t)
1741 (inhibit-point-motion-hooks t))
1742 (article-narrow-to-head)
1743 (dolist (elem gnus-boring-article-headers)
1744 (goto-char (point-min))
1746 ;; Hide empty headers.
1748 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1750 (gnus-article-hide-text-type
1754 (if (re-search-forward "^[^ \t]" nil t)
1758 ;; Hide boring Newsgroups header.
1759 ((eq elem 'newsgroups)
1760 (when (gnus-string-equal
1761 (gnus-fetch-field "newsgroups")
1762 (gnus-group-real-name
1763 (if (boundp 'gnus-newsgroup-name)
1766 (gnus-article-hide-header "newsgroups")))
1767 ((eq elem 'to-address)
1768 (let ((to (message-fetch-field "to"))
1770 (gnus-parameter-to-address
1771 (if (boundp 'gnus-newsgroup-name)
1772 gnus-newsgroup-name ""))))
1773 (when (and to to-address
1776 ;; only one address in To
1777 (nth 1 (mail-extract-address-components to))
1779 (gnus-article-hide-header "to"))))
1781 (let ((to (message-fetch-field "to"))
1783 (gnus-parameter-to-list
1784 (if (boundp 'gnus-newsgroup-name)
1785 gnus-newsgroup-name ""))))
1786 (when (and to to-list
1789 ;; only one address in To
1790 (nth 1 (mail-extract-address-components to))
1792 (gnus-article-hide-header "to"))))
1794 (let ((cc (message-fetch-field "cc"))
1796 (gnus-parameter-to-list
1797 (if (boundp 'gnus-newsgroup-name)
1798 gnus-newsgroup-name ""))))
1799 (when (and cc to-list
1802 ;; only one address in CC
1803 (nth 1 (mail-extract-address-components cc))
1805 (gnus-article-hide-header "cc"))))
1806 ((eq elem 'followup-to)
1807 (when (gnus-string-equal
1808 (message-fetch-field "followup-to")
1809 (message-fetch-field "newsgroups"))
1810 (gnus-article-hide-header "followup-to")))
1811 ((eq elem 'reply-to)
1812 (if (gnus-group-find-parameter
1813 gnus-newsgroup-name 'broken-reply-to)
1814 (gnus-article-hide-header "reply-to")
1815 (let ((from (message-fetch-field "from"))
1816 (reply-to (message-fetch-field "reply-to")))
1823 (lambda (x) (downcase (cadr x)))
1824 (mail-extract-address-components from t))
1827 (lambda (x) (downcase (cadr x)))
1828 (mail-extract-address-components reply-to t))
1830 (gnus-article-hide-header "reply-to")))))
1832 (let ((date (message-fetch-field "date")))
1834 (< (days-between (current-time-string) date)
1836 (gnus-article-hide-header "date"))))
1838 (let ((to (message-fetch-field "to"))
1839 (cc (message-fetch-field "cc")))
1840 (when (> (length to) 1024)
1841 (gnus-article-hide-header "to"))
1842 (when (> (length cc) 1024)
1843 (gnus-article-hide-header "cc"))))
1847 (goto-char (point-min))
1848 (while (re-search-forward "^to:" nil t)
1849 (setq to-count (1+ to-count)))
1850 (when (> to-count 1)
1851 (while (> to-count 0)
1852 (goto-char (point-min))
1854 (re-search-forward "^to:" nil nil to-count)
1856 (narrow-to-region (point) (point-max))
1857 (gnus-article-hide-header "to"))
1858 (setq to-count (1- to-count))))
1859 (goto-char (point-min))
1860 (while (re-search-forward "^cc:" nil t)
1861 (setq cc-count (1+ cc-count)))
1862 (when (> cc-count 1)
1863 (while (> cc-count 0)
1864 (goto-char (point-min))
1866 (re-search-forward "^cc:" nil nil cc-count)
1868 (narrow-to-region (point) (point-max))
1869 (gnus-article-hide-header "cc"))
1870 (setq cc-count (1- cc-count)))))))))))))
1872 (defun gnus-article-hide-header (header)
1874 (goto-char (point-min))
1875 (when (re-search-forward (concat "^" header ":") nil t)
1876 (gnus-article-hide-text-type
1880 (if (re-search-forward "^[^ \t]" nil t)
1885 (defvar gnus-article-normalized-header-length 40
1886 "Length of normalized headers.")
1888 (defun article-normalize-headers ()
1889 "Make all header lines 40 characters long."
1891 (let ((inhibit-read-only t)
1895 (article-narrow-to-head)
1898 ((< (setq column (- (point-at-eol) (point)))
1899 gnus-article-normalized-header-length)
1901 (insert (make-string
1902 (- gnus-article-normalized-header-length column)
1904 ((> column gnus-article-normalized-header-length)
1905 (gnus-put-text-property
1907 (forward-char gnus-article-normalized-header-length)
1914 (forward-line 1))))))
1916 (defun article-treat-dumbquotes ()
1917 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1918 Note that this function guesses whether a character is a sm*rtq**t* or
1919 not, so it should only be used interactively.
1921 Sm*rtq**t*s are M****s***'s unilateral extension to the
1922 iso-8859-1 character map in an attempt to provide more quoting
1923 characters. If you see something like \\222 or \\264 where
1924 you're expecting some kind of apostrophe or quotation mark, then
1927 (article-translate-strings gnus-article-dumbquotes-map))
1929 (defun article-translate-characters (from to)
1930 "Translate all characters in the body of the article according to FROM and TO.
1931 FROM is a string of characters to translate from; to is a string of
1932 characters to translate to."
1934 (when (article-goto-body)
1935 (let ((inhibit-read-only t)
1936 (x (make-string 225 ?x))
1938 (while (< (incf i) (length x))
1941 (while (< i (length from))
1942 (aset x (aref from i) (aref to i))
1944 (translate-region (point) (point-max) x)))))
1946 (defun article-translate-strings (map)
1947 "Translate all string in the body of the article according to MAP.
1948 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1950 (when (article-goto-body)
1951 (let ((inhibit-read-only t))
1954 (while (search-forward (car elem) nil t)
1955 (replace-match (cadr elem)))))))))
1957 (defun article-treat-overstrike ()
1958 "Translate overstrikes into bold text."
1961 (when (article-goto-body)
1962 (let ((inhibit-read-only t))
1963 (while (search-forward "\b" nil t)
1964 (let ((next (char-after))
1965 (previous (char-after (- (point) 2))))
1966 ;; We do the boldification/underlining by hiding the
1967 ;; overstrikes and putting the proper text property
1971 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1972 (put-text-property (point) (1+ (point)) 'face 'bold))
1974 (gnus-article-hide-text-type
1975 (1- (point)) (1+ (point)) 'overstrike)
1977 (- (point) 2) (1- (point)) 'face 'underline))
1979 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1981 (point) (1+ (point)) 'face 'underline)))))))))
1983 (defun article-treat-ansi-sequences ()
1984 "Translate ANSI SGR control sequences into overlays or extents."
1987 (when (article-goto-body)
1988 (let ((inhibit-read-only t))
1989 (ansi-color-apply-on-region (point) (point-max))))))
1991 (defun gnus-article-treat-unfold-headers ()
1992 "Unfold folded message headers.
1993 Only the headers that fit into the current window width will be
1996 (gnus-with-article-headers
2000 (mail-header-narrow-to-field)
2001 (let ((header (buffer-string)))
2004 (goto-char (point-min))
2005 (while (re-search-forward "\n[\t ]" nil t)
2006 (replace-match " " t t)))
2007 (setq length (- (point-max) (point-min) 1)))
2008 (when (< length (window-width))
2009 (while (re-search-forward "\n[\t ]" nil t)
2010 (replace-match " " t t)))
2011 (goto-char (point-max)))))))
2013 (defun gnus-article-treat-fold-headers ()
2014 "Fold message headers."
2016 (gnus-with-article-headers
2019 (mail-header-narrow-to-field)
2020 (mail-header-fold-field)
2021 (goto-char (point-max))))))
2023 (defun gnus-treat-smiley ()
2024 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2026 (gnus-with-article-buffer
2027 (if (memq 'smiley gnus-article-wash-types)
2028 (gnus-delete-images 'smiley)
2030 (let ((images (smiley-region (point) (point-max))))
2032 (gnus-add-wash-type 'smiley)
2033 (dolist (image images)
2034 (gnus-add-image 'smiley image)))))))
2036 (defun gnus-article-remove-images ()
2037 "Remove all images from the article buffer."
2039 (gnus-with-article-buffer
2040 (dolist (elem gnus-article-image-alist)
2041 (gnus-delete-images (car elem)))))
2043 (defun gnus-article-treat-fold-newsgroups ()
2044 "Unfold folded message headers.
2045 Only the headers that fit into the current window width will be
2048 (gnus-with-article-headers
2049 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2051 (mail-header-narrow-to-field)
2052 (while (re-search-forward ", *" nil t)
2053 (replace-match ", " t t))
2054 (mail-header-fold-field)
2055 (goto-char (point-max))))))
2057 (defun gnus-article-treat-body-boundary ()
2058 "Place a boundary line at the end of the headers."
2060 (when (and gnus-body-boundary-delimiter
2061 (> (length gnus-body-boundary-delimiter) 0))
2062 (gnus-with-article-headers
2063 (goto-char (point-max))
2064 (let ((start (point)))
2065 (insert "X-Boundary: ")
2066 (gnus-add-text-properties start (point) '(invisible t intangible t))
2068 (while (>= (1- (window-width)) (length str))
2069 (setq str (concat str gnus-body-boundary-delimiter)))
2070 (substring str 0 (1- (window-width))))
2072 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2074 (defun article-fill-long-lines ()
2075 "Fill lines that are wider than the window width."
2078 (let ((inhibit-read-only t)
2079 (width (window-width (get-buffer-window (current-buffer)))))
2082 (let ((adaptive-fill-mode nil)) ;Why? -sm
2085 (when (>= (current-column) (min fill-column width))
2086 (narrow-to-region (min (1+ (point)) (point-max))
2088 (let ((goback (point-marker)))
2089 (fill-paragraph nil)
2090 (goto-char (marker-position goback)))
2092 (forward-line 1)))))))
2094 (defun article-capitalize-sentences ()
2095 "Capitalize the first word in each sentence."
2098 (let ((inhibit-read-only t)
2099 (paragraph-start "^[\n\^L]"))
2103 (forward-sentence)))))
2105 (defun article-remove-cr ()
2106 "Remove trailing CRs and then translate remaining CRs into LFs."
2109 (let ((inhibit-read-only t))
2110 (goto-char (point-min))
2111 (while (re-search-forward "\r+$" nil t)
2112 (replace-match "" t t))
2113 (goto-char (point-min))
2114 (while (search-forward "\r" nil t)
2115 (replace-match "\n" t t)))))
2117 (defun article-remove-trailing-blank-lines ()
2118 "Remove all trailing blank lines from the article."
2121 (let ((inhibit-read-only t))
2122 (goto-char (point-max))
2126 (while (and (not (bobp))
2127 (looking-at "^[ \t]*$")
2128 (not (gnus-annotation-in-region-p
2129 (point) (point-at-eol))))
2135 (defvar gnus-face-properties-alist))
2137 (defun article-display-face ()
2138 "Display any Face headers in the header."
2140 (let ((wash-face-p buffer-read-only))
2141 (gnus-with-article-headers
2142 ;; When displaying parts, this function can be called several times on
2143 ;; the same article, without any intended toggle semantic (as typing `W
2144 ;; D d' would have). So face deletion must occur only when we come from
2145 ;; an interactive command, that is when the *Article* buffer is
2147 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2148 (gnus-delete-images 'face)
2151 (when (and wash-face-p
2153 (goto-char (point-min))
2154 (not (re-search-forward "^Face:[\t ]*" nil t)))
2155 (gnus-buffer-live-p gnus-original-article-buffer))
2156 (set-buffer gnus-original-article-buffer))
2158 (mail-narrow-to-head)
2159 (while (gnus-article-goto-header "Face")
2160 (setq faces (nconc faces (list (mail-header-field-value)))))))
2161 (dolist (face faces)
2162 (let ((png (gnus-convert-face-to-png face))
2166 (apply 'gnus-create-image png 'png t
2167 (cdr (assq 'png gnus-face-properties-alist))))
2168 (gnus-article-goto-header "from")
2170 (insert "From: [no `from' set]\n")
2172 (gnus-add-wash-type 'face)
2173 (gnus-add-image 'face image)
2174 (gnus-put-image image nil 'face))))))
2177 (defun article-display-x-face (&optional force)
2178 "Look for an X-Face header and display it if present."
2179 (interactive (list 'force))
2180 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2181 (gnus-with-article-headers
2182 ;; Delete the old process, if any.
2183 (when (process-status "article-x-face")
2184 (delete-process "article-x-face"))
2185 ;; See the comment in `article-display-face'.
2186 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2187 ;; We have already displayed X-Faces, so we remove them
2189 (gnus-delete-images 'xface)
2191 (let (x-faces from face)
2193 (when (and wash-face-p
2195 (goto-char (point-min))
2196 (not (re-search-forward
2197 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2198 (gnus-buffer-live-p gnus-original-article-buffer))
2199 ;; If type `W f', use gnus-original-article-buffer,
2200 ;; otherwise use the current buffer because displaying
2201 ;; RFC822 parts calls this function too.
2202 (set-buffer gnus-original-article-buffer))
2204 (mail-narrow-to-head)
2205 (while (gnus-article-goto-header "X-Face")
2206 (push (mail-header-field-value) x-faces))
2207 (setq from (message-fetch-field "from"))))
2208 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2209 ;; single external face.
2210 (when (stringp gnus-article-x-face-command)
2211 (setq x-faces (list (car x-faces))))
2212 (while (and (setq face (pop x-faces))
2213 gnus-article-x-face-command
2215 ;; Check whether this face is censored.
2216 (not gnus-article-x-face-too-ugly)
2217 (and gnus-article-x-face-too-ugly from
2218 (not (string-match gnus-article-x-face-too-ugly
2220 ;; We display the face.
2221 (cond ((stringp gnus-article-x-face-command)
2222 ;; The command is a string, so we interpret the command
2223 ;; as a, well, command, and fork it off.
2224 (let ((process-connection-type nil))
2225 (process-kill-without-query
2227 "article-x-face" nil shell-file-name
2228 shell-command-switch gnus-article-x-face-command))
2231 (process-send-region "article-x-face"
2232 (point-min) (point-max)))
2233 (process-send-eof "article-x-face")))
2234 ((functionp gnus-article-x-face-command)
2235 ;; The command is a lisp function, so we call it.
2236 (funcall gnus-article-x-face-command face))
2238 (error "%s is not a function"
2239 gnus-article-x-face-command)))))))))
2241 (defun article-decode-mime-words ()
2242 "Decode all MIME-encoded words in the article."
2244 (gnus-with-article-buffer
2245 (let ((inhibit-point-motion-hooks t)
2246 (mail-parse-charset gnus-newsgroup-charset)
2247 (mail-parse-ignored-charsets
2248 (with-current-buffer gnus-summary-buffer
2249 gnus-newsgroup-ignored-charsets)))
2250 (mail-decode-encoded-word-region (point-min) (point-max)))))
2252 (defun article-decode-charset (&optional prompt)
2253 "Decode charset-encoded text in the article.
2254 If PROMPT (the prefix), prompt for a coding system to use."
2256 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2257 (inhibit-read-only t)
2258 (mail-parse-charset gnus-newsgroup-charset)
2259 (mail-parse-ignored-charsets
2260 (save-excursion (condition-case nil
2261 (set-buffer gnus-summary-buffer)
2263 gnus-newsgroup-ignored-charsets))
2264 ct cte ctl charset format)
2267 (article-narrow-to-head)
2268 (setq ct (message-fetch-field "Content-Type" t)
2269 cte (message-fetch-field "Content-Transfer-Encoding" t)
2270 ctl (and ct (ignore-errors
2271 (mail-header-parse-content-type ct)))
2274 (mm-read-coding-system "Charset to decode: "))
2276 (mail-content-type-get ctl 'charset)))
2277 format (and ctl (mail-content-type-get ctl 'format)))
2279 (setq cte (mail-header-strip cte)))
2280 (if (and ctl (not (string-match "/" (car ctl))))
2282 (goto-char (point-max)))
2285 (narrow-to-region (point) (point-max))
2286 (when (and (eq mail-parse-charset 'gnus-decoded)
2287 (eq (mm-body-7-or-8) '8bit))
2288 ;; The text code could have been decoded.
2289 (setq charset mail-parse-charset))
2290 (when (and (or (not ctl)
2291 (equal (car ctl) "text/plain"))
2292 (not format)) ;; article with format will decode later.
2294 charset (and cte (intern (downcase
2295 (gnus-strip-whitespace cte))))
2298 (defun article-decode-encoded-words ()
2299 "Remove encoded-word encoding from headers."
2300 (let ((inhibit-point-motion-hooks t)
2301 (mail-parse-charset gnus-newsgroup-charset)
2302 (mail-parse-ignored-charsets
2303 (save-excursion (condition-case nil
2304 (set-buffer gnus-summary-buffer)
2306 gnus-newsgroup-ignored-charsets))
2307 (inhibit-read-only t))
2309 (article-narrow-to-head)
2310 (funcall gnus-decode-header-function (point-min) (point-max)))))
2312 (defun article-decode-group-name ()
2313 "Decode group names in `Newsgroups:'."
2314 (let ((inhibit-point-motion-hooks t)
2315 (inhibit-read-only t)
2316 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2317 (when (and (or gnus-group-name-charset-method-alist
2318 gnus-group-name-charset-group-alist)
2319 (gnus-buffer-live-p gnus-original-article-buffer))
2321 (article-narrow-to-head)
2322 (with-current-buffer gnus-original-article-buffer
2323 (goto-char (point-min)))
2324 (while (re-search-forward
2325 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2326 (replace-match (save-match-data
2327 (gnus-decode-newsgroups
2328 ;; XXX how to use data in article buffer?
2329 (with-current-buffer gnus-original-article-buffer
2331 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2334 gnus-newsgroup-name method))
2336 (goto-char (point-min))
2337 (with-current-buffer gnus-original-article-buffer
2338 (goto-char (point-min)))
2339 (while (re-search-forward
2340 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2341 (replace-match (save-match-data
2342 (gnus-decode-newsgroups
2343 ;; XXX how to use data in article buffer?
2344 (with-current-buffer gnus-original-article-buffer
2346 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2349 gnus-newsgroup-name method))
2352 (autoload 'idna-to-unicode "idna")
2354 (defun article-decode-idna-rhs ()
2355 "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2358 (let ((inhibit-point-motion-hooks t)
2359 (inhibit-read-only t))
2360 (article-narrow-to-head)
2361 (goto-char (point-min))
2362 (while (re-search-forward "@.*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2364 (when (save-match-data
2365 (and (setq ace (match-string 1))
2367 (and (re-search-backward "^[^ \t]" nil t)
2368 (looking-at "From\\|To\\|Cc")))
2369 (setq unicode (idna-to-unicode ace))))
2370 (unless (string= ace unicode)
2371 (replace-match unicode nil nil nil 1)))))))))
2373 (defun article-de-quoted-unreadable (&optional force read-charset)
2374 "Translate a quoted-printable-encoded article.
2375 If FORCE, decode the article whether it is marked as quoted-printable
2377 If READ-CHARSET, ask for a coding system."
2378 (interactive (list 'force current-prefix-arg))
2380 (let ((inhibit-read-only t) type charset)
2381 (if (gnus-buffer-live-p gnus-original-article-buffer)
2382 (with-current-buffer gnus-original-article-buffer
2384 (gnus-fetch-field "content-transfer-encoding"))
2385 (let* ((ct (gnus-fetch-field "content-type"))
2388 (mail-header-parse-content-type ct)))))
2389 (setq charset (and ctl
2390 (mail-content-type-get ctl 'charset)))
2391 (if (stringp charset)
2392 (setq charset (intern (downcase charset)))))))
2394 (setq charset (mm-read-coding-system "Charset: " charset)))
2396 (setq charset gnus-newsgroup-charset))
2398 (and type (let ((case-fold-search t))
2399 (string-match "quoted-printable" type))))
2401 (quoted-printable-decode-region
2402 (point) (point-max) (mm-charset-to-coding-system charset))))))
2404 (defun article-de-base64-unreadable (&optional force read-charset)
2405 "Translate a base64 article.
2406 If FORCE, decode the article whether it is marked as base64 not.
2407 If READ-CHARSET, ask for a coding system."
2408 (interactive (list 'force current-prefix-arg))
2410 (let ((inhibit-read-only t) type charset)
2411 (if (gnus-buffer-live-p gnus-original-article-buffer)
2412 (with-current-buffer gnus-original-article-buffer
2414 (gnus-fetch-field "content-transfer-encoding"))
2415 (let* ((ct (gnus-fetch-field "content-type"))
2418 (mail-header-parse-content-type ct)))))
2419 (setq charset (and ctl
2420 (mail-content-type-get ctl 'charset)))
2421 (if (stringp charset)
2422 (setq charset (intern (downcase charset)))))))
2424 (setq charset (mm-read-coding-system "Charset: " charset)))
2426 (setq charset gnus-newsgroup-charset))
2428 (and type (let ((case-fold-search t))
2429 (string-match "base64" type))))
2432 (narrow-to-region (point) (point-max))
2433 (base64-decode-region (point-min) (point-max))
2434 (mm-decode-coding-region
2435 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2440 (defun article-decode-HZ ()
2441 "Translate a HZ-encoded article."
2445 (let ((inhibit-read-only t))
2446 (rfc1843-decode-region (point-min) (point-max)))))
2448 (defun article-unsplit-urls ()
2449 "Remove the newlines that some other mailers insert into URLs."
2452 (let ((inhibit-read-only t))
2453 (goto-char (point-min))
2454 (while (re-search-forward
2455 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2456 (replace-match "\\1\\3" t)))
2457 (when (interactive-p)
2458 (gnus-treat-article nil))))
2461 (defun article-wash-html (&optional read-charset)
2462 "Format an HTML article.
2463 If READ-CHARSET, ask for a coding system."
2466 (let ((inhibit-read-only t)
2468 (when (gnus-buffer-live-p gnus-original-article-buffer)
2469 (with-current-buffer gnus-original-article-buffer
2470 (let* ((ct (gnus-fetch-field "content-type"))
2473 (mail-header-parse-content-type ct)))))
2474 (setq charset (and ctl
2475 (mail-content-type-get ctl 'charset)))
2476 (when (stringp charset)
2477 (setq charset (intern (downcase charset)))))))
2479 (setq charset (mm-read-coding-system "Charset: " charset)))
2481 (setq charset gnus-newsgroup-charset))
2483 (save-window-excursion
2485 (narrow-to-region (point) (point-max))
2486 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2487 (entry (assq func mm-text-html-washer-alist)))
2489 (setq func (cdr entry)))
2494 (apply (car func) (cdr func))))))))))
2496 (defun gnus-article-wash-html-with-w3 ()
2497 "Wash the current buffer with w3."
2499 (let ((w3-strict-width (window-width))
2500 (url-standalone-mode t)
2501 (url-gateway-unplugged t)
2502 (w3-honor-stylesheets nil))
2504 (w3-region (point-min) (point-max))
2507 (defun gnus-article-wash-html-with-w3m ()
2508 "Wash the current buffer with emacs-w3m."
2511 (narrow-to-region (point) (point-max))
2512 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2513 w3m-force-redisplay)
2514 (w3m-region (point-min) (point-max)))
2515 (when (and mm-inline-text-html-with-w3m-keymap
2516 (boundp 'w3m-minor-mode-map)
2518 (add-text-properties
2519 (point-min) (point-max)
2520 (list 'keymap w3m-minor-mode-map
2521 ;; Put the mark meaning this part was rendered by emacs-w3m.
2522 'mm-inline-text-html-with-w3m t)))))
2524 (defun article-hide-list-identifiers ()
2525 "Remove list identifies from the Subject header.
2526 The `gnus-list-identifiers' variable specifies what to do."
2528 (let ((inhibit-point-motion-hooks t)
2529 (regexp (if (consp gnus-list-identifiers)
2530 (mapconcat 'identity gnus-list-identifiers " *\\|")
2531 gnus-list-identifiers))
2532 (inhibit-read-only t))
2536 (article-narrow-to-head)
2537 (goto-char (point-min))
2538 (while (re-search-forward
2539 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2541 (delete-region (match-beginning 2) (match-end 0))
2542 (beginning-of-line))
2543 (when (re-search-forward
2544 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2545 (delete-region (match-beginning 1) (match-end 1))))))))
2547 (defun article-hide-pem (&optional arg)
2548 "Toggle hiding of any PEM headers and signatures in the current article.
2549 If given a negative prefix, always show; if given a positive prefix,
2551 (interactive (gnus-article-hidden-arg))
2552 (unless (gnus-article-check-hidden-text 'pem arg)
2554 (let ((inhibit-read-only t) end)
2555 (goto-char (point-min))
2556 ;; Hide the horrendously ugly "header".
2557 (when (and (search-forward
2558 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2560 (setq end (1+ (match-beginning 0))))
2561 (gnus-add-wash-type 'pem)
2562 (gnus-article-hide-text-type
2564 (if (search-forward "\n\n" nil t)
2568 ;; Hide the trailer as well
2569 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2571 (gnus-article-hide-text-type
2572 (match-beginning 0) (match-end 0) 'pem)))))))
2574 (defun article-strip-banner ()
2575 "Strip the banners specified by the `banner' group parameter and by
2576 `gnus-article-address-banner-alist'."
2580 (let ((inhibit-point-motion-hooks t))
2581 (when (gnus-parameter-banner gnus-newsgroup-name)
2582 (article-really-strip-banner
2583 (gnus-parameter-banner gnus-newsgroup-name)))
2584 (when gnus-article-address-banner-alist
2585 ;; It is necessary to encode from fields before checking,
2586 ;; because `mail-header-parse-addresses' does not work
2587 ;; (reliably) on decoded headers. And more, it is
2588 ;; impossible to use `gnus-fetch-original-field' here,
2589 ;; because `article-strip-banner' may be called in draft
2590 ;; buffers to preview them.
2591 (let ((from (save-restriction
2593 (article-narrow-to-head)
2594 (mail-fetch-field "from"))))
2597 (caar (mail-header-parse-addresses
2598 (mail-encode-encoded-word-string from)))))
2600 (dolist (pair gnus-article-address-banner-alist)
2601 (when (string-match (car pair) from)
2603 (article-really-strip-banner (cdr pair)))))))))))))
2605 (defun article-really-strip-banner (banner)
2606 "Strip the banner specified by the argument."
2609 (let ((inhibit-point-motion-hooks t)
2610 (gnus-signature-limit nil)
2611 (inhibit-read-only t))
2614 ((eq banner 'signature)
2615 (when (gnus-article-narrow-to-signature)
2618 (delete-region (point) (point-max))))
2620 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2621 (while (re-search-forward banner nil t)
2622 (delete-region (match-beginning 0) (match-end 0)))))
2624 (while (re-search-forward banner nil t)
2625 (delete-region (match-beginning 0) (match-end 0)))))))))
2627 (defun article-babel ()
2628 "Translate article using an online translation service."
2631 (gnus-with-article-buffer
2632 (when (article-goto-body)
2633 (let* ((start (point))
2635 (orig (buffer-substring start end))
2636 (trans (babel-as-string orig)))
2638 (narrow-to-region start end)
2639 (delete-region start end)
2642 (defun article-hide-signature (&optional arg)
2643 "Hide the signature in the current article.
2644 If given a negative prefix, always show; if given a positive prefix,
2646 (interactive (gnus-article-hidden-arg))
2647 (unless (gnus-article-check-hidden-text 'signature arg)
2650 (let ((inhibit-read-only t))
2651 (when (gnus-article-narrow-to-signature)
2652 (gnus-article-hide-text-type
2653 (point-min) (point-max) 'signature))))))
2654 (gnus-set-mode-line 'article))
2656 (defun article-strip-headers-in-body ()
2657 "Strip offensive headers from bodies."
2661 (let ((case-fold-search t))
2662 (when (looking-at "x-no-archive:")
2663 (gnus-delete-line)))))
2665 (defun article-strip-leading-blank-lines ()
2666 "Remove all blank lines from the beginning of the article."
2669 (let ((inhibit-point-motion-hooks t)
2670 (inhibit-read-only t))
2671 (when (article-goto-body)
2672 (while (and (not (eobp))
2673 (looking-at "[ \t]*$"))
2674 (gnus-delete-line))))))
2676 (defun article-narrow-to-head ()
2677 "Narrow the buffer to the head of the message.
2678 Point is left at the beginning of the narrowed-to region."
2680 (goto-char (point-min))
2681 (if (search-forward "\n\n" nil 1)
2684 (goto-char (point-min)))
2686 (defun article-goto-body ()
2687 "Place point at the start of the body."
2688 (goto-char (point-min))
2690 ;; This variable is only bound when dealing with separate
2692 (article-goto-body-goes-to-point-min-p
2694 ((search-forward "\n\n" nil t)
2697 (goto-char (point-max))
2700 (defun article-strip-multiple-blank-lines ()
2701 "Replace consecutive blank lines with one empty line."
2704 (let ((inhibit-point-motion-hooks t)
2705 (inhibit-read-only t))
2706 ;; First make all blank lines empty.
2708 (while (re-search-forward "^[ \t]+$" nil t)
2709 (unless (gnus-annotation-in-region-p
2710 (match-beginning 0) (match-end 0))
2711 (replace-match "" nil t)))
2712 ;; Then replace multiple empty lines with a single empty line.
2714 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2715 (unless (gnus-annotation-in-region-p
2716 (match-beginning 0) (match-end 0))
2717 (delete-region (match-beginning 1) (match-end 1)))))))
2719 (defun article-strip-leading-space ()
2720 "Remove all white space from the beginning of the lines in the article."
2723 (let ((inhibit-point-motion-hooks t)
2724 (inhibit-read-only t))
2726 (while (re-search-forward "^[ \t]+" nil t)
2727 (replace-match "" t t)))))
2729 (defun article-strip-trailing-space ()
2730 "Remove all white space from the end of the lines in the article."
2733 (let ((inhibit-point-motion-hooks t)
2734 (inhibit-read-only t))
2736 (while (re-search-forward "[ \t]+$" nil t)
2737 (replace-match "" t t)))))
2739 (defun article-strip-blank-lines ()
2740 "Strip leading, trailing and multiple blank lines."
2742 (article-strip-leading-blank-lines)
2743 (article-remove-trailing-blank-lines)
2744 (article-strip-multiple-blank-lines))
2746 (defun article-strip-all-blank-lines ()
2747 "Strip all blank lines."
2750 (let ((inhibit-point-motion-hooks t)
2751 (inhibit-read-only t))
2753 (while (re-search-forward "^[ \t]*\n" nil t)
2754 (replace-match "" t t)))))
2756 (defun gnus-article-narrow-to-signature ()
2757 "Narrow to the signature; return t if a signature is found, else nil."
2758 (let ((inhibit-point-motion-hooks t))
2759 (when (gnus-article-search-signature)
2761 ;; Check whether we have some limits to what we consider
2762 ;; to be a signature.
2763 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2764 (list gnus-signature-limit)))
2766 (while (setq limit (pop limits))
2767 (if (or (and (integerp limit)
2768 (< (- (point-max) (point)) limit))
2770 (< (count-lines (point) (point-max)) limit))
2771 (and (functionp limit)
2773 (and (stringp limit)
2774 (not (re-search-forward limit nil t))))
2775 () ; This limit did not succeed.
2779 (narrow-to-region (point) (point-max))
2782 (defun gnus-article-search-signature ()
2783 "Search the current buffer for the signature separator.
2784 Put point at the beginning of the signature separator."
2785 (let ((cur (point)))
2786 (goto-char (point-max))
2787 (if (if (stringp gnus-signature-separator)
2788 (re-search-backward gnus-signature-separator nil t)
2789 (let ((seps gnus-signature-separator))
2791 (not (re-search-backward (car seps) nil t)))
2798 (defun gnus-article-hidden-arg ()
2799 "Return the current prefix arg as a number, or 0 if no prefix."
2800 (list (if current-prefix-arg
2801 (prefix-numeric-value current-prefix-arg)
2804 (defun gnus-article-check-hidden-text (type arg)
2805 "Return nil if hiding is necessary.
2806 Arg can be nil or a number. nil and positive means hide, negative
2807 means show, 0 means toggle."
2810 (let ((hide (gnus-article-hidden-text-p type)))
2816 (gnus-article-show-hidden-text type)
2819 (if (eq hide 'hidden)
2821 (gnus-article-show-hidden-text type)
2825 (defun gnus-article-hidden-text-p (type)
2826 "Say whether the current buffer contains hidden text of type TYPE."
2827 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2829 (not (get-text-property pos 'invisible))
2830 (not (get-text-property pos 'dummy-invisible)))
2832 (text-property-any (1+ pos) (point-max) 'article-type type)))
2837 (defun gnus-article-show-hidden-text (type &optional dummy)
2838 "Show all hidden text of type TYPE.
2839 Originally it is hide instead of DUMMY."
2840 (let ((inhibit-read-only t)
2841 (inhibit-point-motion-hooks t))
2842 (gnus-remove-text-properties-when
2844 (point-min) (point-max)
2845 (cons 'article-type (cons type
2846 gnus-hidden-properties)))
2847 (gnus-delete-wash-type type)))
2849 (defconst article-time-units
2850 `((year . ,(* 365.25 24 60 60))
2851 (week . ,(* 7 24 60 60))
2852 (day . ,(* 24 60 60))
2856 "Mapping from time units to seconds.")
2858 (defun gnus-article-forward-header ()
2859 "Move point to the start of the next header.
2860 If the current header is a continuation header, this can be several
2865 (if (looking-at "[ \t]+[^ \t]")
2869 (defun article-date-ut (&optional type highlight header)
2870 "Convert DATE date to universal time in the current article.
2871 If TYPE is `local', convert to local time; if it is `lapsed', output
2872 how much time has lapsed since DATE. For `lapsed', the value of
2873 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2874 should replace the \"Date:\" one, or should be added below it."
2875 (interactive (list 'ut t))
2876 (let* ((header (or header
2877 (message-fetch-field "date")
2879 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2882 ((not gnus-article-date-lapsed-new-header)
2888 (date (if (vectorp header) (mail-header-date header)
2890 (inhibit-point-motion-hooks t)
2895 (article-narrow-to-head)
2896 (when (re-search-forward tdate-regexp nil t)
2897 (setq bface (get-text-property (point-at-bol) 'face)
2898 date (or (get-text-property (point-at-bol)
2901 eface (get-text-property (1- (point-at-eol)) 'face))
2903 (when (and date (not (string= date "")))
2904 (goto-char (point-min))
2905 (let ((inhibit-read-only t))
2906 ;; Delete any old Date headers.
2907 (while (re-search-forward date-regexp nil t)
2909 (delete-region (point-at-bol)
2910 (progn (gnus-article-forward-header)
2912 (delete-region (point-at-bol)
2913 (progn (gnus-article-forward-header)
2916 (setq pos (point))))
2917 (when (and (not pos)
2918 (re-search-forward tdate-regexp nil t))
2920 (gnus-goto-char pos)
2921 (insert (article-make-date-line date (or type 'ut)))
2927 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2928 (add-text-properties (match-beginning 1) (1+ (match-end 1))
2929 (list 'original-date date 'face bface))
2930 (put-text-property (match-beginning 2) (match-end 2)
2933 (defun article-make-date-line (date type)
2934 "Return a DATE line of TYPE."
2935 (unless (memq type '(local ut original user iso8601 lapsed english))
2936 (error "Unknown conversion type: %s" type))
2938 (let ((time (date-to-time date)))
2940 ;; Convert to the local timezone.
2942 (concat "Date: " (message-make-date time)))
2943 ;; Convert to Universal Time.
2948 (let* ((e (parse-time-string date))
2949 (tm (apply 'encode-time e))
2951 (ls (- (cadr tm) (car (current-time-zone time)))))
2952 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2953 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2957 ;; Get the original date from the article.
2958 ((eq type 'original)
2959 (concat "Date: " (if (string-match "\n+$" date)
2960 (substring date 0 (match-beginning 0))
2962 ;; Let the user define the format.
2964 (let ((format (or (condition-case nil
2965 (with-current-buffer gnus-summary-buffer
2966 gnus-article-time-format)
2968 gnus-article-time-format)))
2969 (if (functionp format)
2970 (funcall format time)
2971 (concat "Date: " (format-time-string format time)))))
2974 (let ((tz (car (current-time-zone time))))
2977 (format-time-string "%Y%m%dT%H%M%S" time)
2978 (format "%s%02d%02d"
2979 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2980 (/ (% (abs tz) 3600) 60)))))
2981 ;; Do an X-Sent lapsed format.
2983 ;; If the date is seriously mangled, the timezone functions are
2984 ;; liable to bug out, so we ignore all errors.
2985 (let* ((now (current-time))
2986 (real-time (subtract-time now time))
2987 (real-sec (and real-time
2988 (+ (* (float (car real-time)) 65536)
2990 (sec (and real-time (abs real-sec)))
3000 ;; This is a bit convoluted, but basically we go
3001 ;; through the time units for years, weeks, etc,
3002 ;; and divide things to see whether that results
3003 ;; in positive answers.
3006 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3007 ;; The (remaining) seconds are too few to
3008 ;; be divided into this time unit.
3010 ;; It's big enough, so we output it.
3011 (setq sec (- sec (* num (cdr unit))))
3013 (concat (if prev ", " "") (int-to-string
3015 " " (symbol-name (car unit))
3016 (if (> num 1) "s" ""))
3018 article-time-units "")
3019 ;; If dates are odd, then it might appear like the
3020 ;; article was sent in the future.
3023 " in the future"))))))
3024 ;; Display the date in proper English
3026 (let ((dtime (decode-time time)))
3029 (number-to-string (nth 3 dtime))
3030 (let ((digit (% (nth 3 dtime) 10)))
3032 ((memq (nth 3 dtime) '(11 12 13)) "th")
3038 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3040 (number-to-string (nth 5 dtime))
3042 (format "%02d" (nth 2 dtime))
3044 (format "%02d" (nth 1 dtime)))))))
3046 (format "Date: %s (from Gnus)" date))))
3048 (defun article-date-local (&optional highlight)
3049 "Convert the current article date to the local timezone."
3050 (interactive (list t))
3051 (article-date-ut 'local highlight))
3053 (defun article-date-english (&optional highlight)
3054 "Convert the current article date to something that is proper English."
3055 (interactive (list t))
3056 (article-date-ut 'english highlight))
3058 (defun article-date-original (&optional highlight)
3059 "Convert the current article date to what it was originally.
3060 This is only useful if you have used some other date conversion
3061 function and want to see what the date was before converting."
3062 (interactive (list t))
3063 (article-date-ut 'original highlight))
3065 (defun article-date-lapsed (&optional highlight)
3066 "Convert the current article date to time lapsed since it was sent."
3067 (interactive (list t))
3068 (article-date-ut 'lapsed highlight))
3070 (defun article-update-date-lapsed ()
3071 "Function to be run from a timer to update the lapsed time line."
3072 (let (deactivate-mark)
3077 (set-buffer (window-buffer w))
3078 (when (eq major-mode 'gnus-article-mode)
3079 (let ((mark (point-marker)))
3080 (goto-char (point-min))
3081 (when (re-search-forward "^X-Sent:" nil t)
3082 (article-date-lapsed t))
3083 (goto-char (marker-position mark))
3084 (move-marker mark nil))))
3087 (defun gnus-start-date-timer (&optional n)
3088 "Start a timer to update the X-Sent header in the article buffers.
3089 The numerical prefix says how frequently (in seconds) the function
3094 (gnus-stop-date-timer)
3095 (setq article-lapsed-timer
3096 (run-at-time 1 n 'article-update-date-lapsed)))
3098 (defun gnus-stop-date-timer ()
3099 "Stop the X-Sent timer."
3101 (when article-lapsed-timer
3102 (nnheader-cancel-timer article-lapsed-timer)
3103 (setq article-lapsed-timer nil)))
3105 (defun article-date-user (&optional highlight)
3106 "Convert the current article date to the user-defined format.
3107 This format is defined by the `gnus-article-time-format' variable."
3108 (interactive (list t))
3109 (article-date-ut 'user highlight))
3111 (defun article-date-iso8601 (&optional highlight)
3112 "Convert the current article date to ISO8601."
3113 (interactive (list t))
3114 (article-date-ut 'iso8601 highlight))
3116 ;; (defun article-show-all ()
3117 ;; "Show all hidden text in the article buffer."
3120 ;; (let ((inhibit-read-only t))
3121 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3123 (defun article-remove-leading-whitespace ()
3124 "Remove excessive whitespace from all headers."
3128 (let ((inhibit-read-only t))
3129 (article-narrow-to-head)
3130 (goto-char (point-min))
3131 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3132 (delete-region (match-beginning 1) (match-end 1)))))))
3134 (defun article-emphasize (&optional arg)
3135 "Emphasize text according to `gnus-emphasis-alist'."
3136 (interactive (gnus-article-hidden-arg))
3137 (unless (gnus-article-check-hidden-text 'emphasis arg)
3141 (with-current-buffer gnus-summary-buffer
3142 gnus-article-emphasis-alist)
3144 gnus-emphasis-alist))
3145 (inhibit-read-only t)
3146 (props (append '(article-type emphasis)
3147 gnus-hidden-properties))
3148 regexp elem beg invisible visible face)
3151 (while (setq elem (pop alist))
3153 (setq regexp (car elem)
3154 invisible (nth 1 elem)
3155 visible (nth 2 elem)
3157 (while (re-search-forward regexp nil t)
3158 (when (and (match-beginning visible) (match-beginning invisible))
3159 (gnus-article-hide-text
3160 (match-beginning invisible) (match-end invisible) props)
3161 (gnus-article-unhide-text-type
3162 (match-beginning visible) (match-end visible) 'emphasis)
3163 (gnus-put-overlay-excluding-newlines
3164 (match-beginning visible) (match-end visible) 'face face)
3165 (gnus-add-wash-type 'emphasis)
3166 (goto-char (match-end invisible)))))))))
3168 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3169 "Setup newsgroup emphasis alist."
3170 (unless gnus-article-emphasis-alist
3171 (let ((name (and gnus-newsgroup-name
3172 (gnus-group-real-name gnus-newsgroup-name))))
3173 (make-local-variable 'gnus-article-emphasis-alist)
3174 (setq gnus-article-emphasis-alist
3176 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3177 (while (setq elem (pop alist))
3178 (when (and name (string-match (car elem) name))
3180 highlight (copy-sequence (cdr elem)))))
3182 (copy-sequence highlight-words)
3183 (if gnus-newsgroup-name
3184 (copy-sequence (gnus-group-find-parameter
3185 gnus-newsgroup-name 'highlight-words t)))
3186 gnus-emphasis-alist)))))
3189 (defvar gnus-summary-article-menu)
3190 (defvar gnus-summary-post-menu))
3192 ;;; Saving functions.
3194 (defun gnus-article-save (save-buffer file &optional num)
3195 "Save the currently selected article."
3196 (unless gnus-save-all-headers
3197 ;; Remove headers according to `gnus-saved-headers'.
3198 (let ((gnus-visible-headers
3199 (or gnus-saved-headers gnus-visible-headers))
3200 (gnus-article-buffer save-buffer))
3202 (set-buffer save-buffer)
3203 (article-hide-headers 1 t))))
3204 (save-window-excursion
3205 (if (not gnus-default-article-saver)
3206 (error "No default saver is defined")
3207 ;; !!! Magic! The saving functions all save
3208 ;; `gnus-save-article-buffer' (or so they think), but we
3209 ;; bind that variable to our save-buffer.
3210 (set-buffer gnus-article-buffer)
3211 (let* ((gnus-save-article-buffer save-buffer)
3214 ((not gnus-prompt-before-saving) 'default)
3215 ((eq gnus-prompt-before-saving 'always) nil)
3217 (gnus-number-of-articles-to-be-saved
3218 (when (eq gnus-prompt-before-saving t)
3220 (set-buffer gnus-article-current-summary)
3221 (funcall gnus-default-article-saver filename)))))
3223 (defun gnus-read-save-file-name (prompt &optional filename
3224 function group headers variable)
3226 (funcall function group headers (symbol-value variable)))
3231 ((eq filename 'default)
3237 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3240 (if (and gnus-number-of-articles-to-be-saved
3241 (> gnus-number-of-articles-to-be-saved 1))
3242 (format "these %d articles"
3243 gnus-number-of-articles-to-be-saved)
3246 ;; Let the split methods have their say.
3248 ;; No split name was found.
3251 (concat prompt " (default "
3252 (file-name-nondirectory default-name) ") ")
3253 (file-name-directory default-name)
3255 ;; A single group name is returned.
3256 ((stringp split-name)
3258 (funcall function split-name headers
3259 (symbol-value variable)))
3261 (concat prompt " (default "
3262 (file-name-nondirectory default-name) ") ")
3263 (file-name-directory default-name)
3265 ;; A single split name was found
3266 ((= 1 (length split-name))
3267 (let* ((name (expand-file-name
3269 gnus-article-save-directory))
3270 (dir (cond ((file-directory-p name)
3271 (file-name-as-directory name))
3272 ((file-exists-p name) name)
3273 (t gnus-article-save-directory))))
3275 (concat prompt " (default " name ") ")
3277 ;; A list of splits was found.
3279 (setq split-name (nreverse split-name))
3281 (let ((file-name-history
3282 (nconc split-name file-name-history)))
3286 (concat prompt " (`M-p' for defaults) ")
3287 gnus-article-save-directory
3289 gnus-article-save-directory)))
3290 (car (push result file-name-history)))))))
3291 ;; Create the directory.
3292 (gnus-make-directory (file-name-directory file))
3293 ;; If we have read a directory, we append the default file name.
3294 (when (file-directory-p file)
3295 (setq file (expand-file-name (file-name-nondirectory
3297 (file-name-as-directory file))))
3298 ;; Possibly translate some characters.
3299 (nnheader-translate-file-chars file))))))
3300 (gnus-make-directory (file-name-directory result))
3301 (set variable result)))
3303 (defun gnus-article-archive-name (group)
3304 "Return the first instance of an \"Archive-name\" in the current buffer."
3305 (let ((case-fold-search t))
3306 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3307 (nnheader-concat gnus-article-save-directory
3308 (match-string 1)))))
3310 (defun gnus-article-nndoc-name (group)
3311 "If GROUP is an nndoc group, return the name of the parent group."
3312 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3313 (gnus-group-get-parameter group 'save-article-group)))
3315 (defun gnus-summary-save-in-rmail (&optional filename)
3316 "Append this article to Rmail file.
3317 Optional argument FILENAME specifies file name.
3318 Directory to save to is default to `gnus-article-save-directory'."
3319 (setq filename (gnus-read-save-file-name
3320 "Save %s in rmail file:" filename
3321 gnus-rmail-save-name gnus-newsgroup-name
3322 gnus-current-headers 'gnus-newsgroup-last-rmail))
3323 (gnus-eval-in-buffer-window gnus-save-article-buffer
3327 (gnus-output-to-rmail filename))))
3330 (defun gnus-summary-save-in-mail (&optional filename)
3331 "Append this article to Unix mail file.
3332 Optional argument FILENAME specifies file name.
3333 Directory to save to is default to `gnus-article-save-directory'."
3334 (setq filename (gnus-read-save-file-name
3335 "Save %s in Unix mail file:" filename
3336 gnus-mail-save-name gnus-newsgroup-name
3337 gnus-current-headers 'gnus-newsgroup-last-mail))
3338 (gnus-eval-in-buffer-window gnus-save-article-buffer
3342 (if (and (file-readable-p filename)
3343 (file-regular-p filename)
3344 (mail-file-babyl-p filename))
3345 (rmail-output-to-rmail-file filename t)
3346 (gnus-output-to-mail filename)))))
3349 (defun gnus-summary-save-in-file (&optional filename overwrite)
3350 "Append this article to file.
3351 Optional argument FILENAME specifies file name.
3352 Directory to save to is default to `gnus-article-save-directory'."
3353 (setq filename (gnus-read-save-file-name
3354 "Save %s in file:" filename
3355 gnus-file-save-name gnus-newsgroup-name
3356 gnus-current-headers 'gnus-newsgroup-last-file))
3357 (gnus-eval-in-buffer-window gnus-save-article-buffer
3361 (when (and overwrite
3362 (file-exists-p filename))
3363 (delete-file filename))
3364 (gnus-output-to-file filename))))
3367 (defun gnus-summary-write-to-file (&optional filename)
3368 "Write this article to a file, overwriting it if the file exists.
3369 Optional argument FILENAME specifies file name.
3370 The directory to save in defaults to `gnus-article-save-directory'."
3371 (gnus-summary-save-in-file nil t))
3373 (defun gnus-summary-save-body-in-file (&optional filename)
3374 "Append this article body to a file.
3375 Optional argument FILENAME specifies file name.
3376 The directory to save in defaults to `gnus-article-save-directory'."
3377 (setq filename (gnus-read-save-file-name
3378 "Save %s body in file:" filename
3379 gnus-file-save-name gnus-newsgroup-name
3380 gnus-current-headers 'gnus-newsgroup-last-file))
3381 (gnus-eval-in-buffer-window gnus-save-article-buffer
3385 (when (article-goto-body)
3386 (narrow-to-region (point) (point-max)))
3387 (gnus-output-to-file filename))))
3390 (defun gnus-summary-save-in-pipe (&optional command)
3391 "Pipe this article to subprocess."
3393 (cond ((and (eq command 'default)
3394 gnus-last-shell-command)
3395 gnus-last-shell-command)
3400 "Shell command on %s: "
3401 (if (and gnus-number-of-articles-to-be-saved
3402 (> gnus-number-of-articles-to-be-saved 1))
3403 (format "these %d articles"
3404 gnus-number-of-articles-to-be-saved)
3406 gnus-last-shell-command))))
3407 (when (string-equal command "")
3408 (if gnus-last-shell-command
3409 (setq command gnus-last-shell-command)
3410 (error "A command is required")))
3411 (gnus-eval-in-buffer-window gnus-article-buffer
3414 (shell-command-on-region (point-min) (point-max) command nil)))
3415 (setq gnus-last-shell-command command))
3417 (defun gnus-summary-pipe-to-muttprint (&optional command)
3418 "Pipe this article to muttprint."
3419 (setq command (read-string
3420 "Print using command: " gnus-summary-muttprint-program
3421 nil gnus-summary-muttprint-program))
3422 (gnus-summary-save-in-pipe command))
3424 ;;; Article file names when saving.
3426 (defun gnus-capitalize-newsgroup (newsgroup)
3427 "Capitalize NEWSGROUP name."
3428 (when (not (zerop (length newsgroup)))
3429 (concat (char-to-string (upcase (aref newsgroup 0)))
3430 (substring newsgroup 1))))
3432 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3433 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3434 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3435 Otherwise, it is like ~/News/news/group/num."
3438 (concat (if (gnus-use-long-file-name 'not-save)
3439 (gnus-capitalize-newsgroup newsgroup)
3440 (gnus-newsgroup-directory-form newsgroup))
3441 "/" (int-to-string (mail-header-number headers)))
3442 gnus-article-save-directory)))
3444 (string-equal (file-name-directory default)
3445 (file-name-directory last-file))
3446 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3448 (or last-file default))))
3450 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3451 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3452 If variable `gnus-use-long-file-name' is non-nil, it is
3453 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3456 (concat (if (gnus-use-long-file-name 'not-save)
3458 (gnus-newsgroup-directory-form newsgroup))
3459 "/" (int-to-string (mail-header-number headers)))
3460 gnus-article-save-directory)))
3462 (string-equal (file-name-directory default)
3463 (file-name-directory last-file))
3464 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3466 (or last-file default))))
3468 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3469 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3470 If variable `gnus-use-long-file-name' is non-nil, it is
3471 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3474 (if (gnus-use-long-file-name 'not-save)
3477 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3479 gnus-article-save-directory)))
3481 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3482 "Generate file name from sender."
3483 (let ((from (mail-header-from headers)))
3485 (if (and from (string-match "\\([^ <]+\\)@" from))
3486 (match-string 1 from)
3488 gnus-article-save-directory)))
3490 (defun article-verify-x-pgp-sig ()
3493 (if (gnus-buffer-live-p gnus-original-article-buffer)
3494 (let ((sig (with-current-buffer gnus-original-article-buffer
3495 (gnus-fetch-field "X-PGP-Sig")))
3499 (mml2015-clear-verify-function))
3501 (insert-buffer-substring gnus-original-article-buffer)
3502 (setq items (split-string sig))
3503 (message-narrow-to-head)
3504 (let ((inhibit-point-motion-hooks t)
3505 (case-fold-search t))
3506 ;; Don't verify multiple headers.
3507 (setq headers (mapconcat (lambda (header)
3509 (mail-fetch-field header)
3511 (split-string (nth 1 items) ",") "")))
3512 (delete-region (point-min) (point-max))
3513 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3514 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3519 (if (looking-at "^-")
3522 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3523 (insert "Version: " (car items) "\n\n")
3524 (insert (mapconcat 'identity (cddr items) "\n"))
3525 (insert "\n-----END PGP SIGNATURE-----\n")
3526 (let ((mm-security-handle (list (format "multipart/signed"))))
3527 (mml2015-clean-buffer)
3528 (let ((coding-system-for-write (or gnus-newsgroup-charset
3530 (funcall (mml2015-clear-verify-function)))
3532 (or (mm-handle-multipart-ctl-parameter
3533 mm-security-handle 'gnus-details)
3534 (mm-handle-multipart-ctl-parameter
3535 mm-security-handle 'gnus-info)))))
3537 (let ((inhibit-read-only t) bface eface)
3539 (message-narrow-to-head)
3540 (goto-char (point-max))
3542 (setq bface (get-text-property (point-at-bol) 'face)
3543 eface (get-text-property (1- (point-at-eol)) 'face))
3544 (message-remove-header "X-Gnus-PGP-Verify")
3545 (if (re-search-forward "^X-PGP-Sig:" nil t)
3547 (goto-char (point-max)))
3548 (narrow-to-region (point) (point))
3549 (insert "X-Gnus-PGP-Verify: " info "\n")
3550 (goto-char (point-min))
3553 (if (not (looking-at "^[ \t]"))
3557 (goto-char (point-min))
3558 (when (looking-at "\\([^:]+\\): *")
3559 (put-text-property (match-beginning 1) (1+ (match-end 1))
3561 (put-text-property (match-end 0) (point-max)
3562 'face eface)))))))))
3564 (defun article-verify-cancel-lock ()
3565 "Verify Cancel-Lock header."
3567 (if (gnus-buffer-live-p gnus-original-article-buffer)
3568 (canlock-verify gnus-original-article-buffer)))
3575 (setq afunc (car func)
3578 gfunc (intern (format "gnus-%s" func))))
3580 (when (fboundp afunc)
3581 `(lambda (&optional interactive &rest args)
3582 ,(documentation afunc t)
3583 (interactive (list t))
3585 (set-buffer gnus-article-buffer)
3587 (call-interactively ',afunc)
3588 (apply ',afunc args))))))))
3589 '(article-hide-headers
3590 article-verify-x-pgp-sig
3591 article-verify-cancel-lock
3592 article-hide-boring-headers
3593 article-treat-overstrike
3594 article-treat-ansi-sequences
3595 article-fill-long-lines
3596 article-capitalize-sentences
3598 article-remove-leading-whitespace
3599 article-display-x-face
3600 article-display-face
3601 article-de-quoted-unreadable
3602 article-de-base64-unreadable
3605 article-unsplit-urls
3606 article-hide-list-identifiers
3607 article-strip-banner
3610 article-hide-signature
3611 article-strip-headers-in-body
3612 article-remove-trailing-blank-lines
3613 article-strip-leading-blank-lines
3614 article-strip-multiple-blank-lines
3615 article-strip-leading-space
3616 article-strip-trailing-space
3617 article-strip-blank-lines
3618 article-strip-all-blank-lines
3620 article-date-english
3621 article-date-iso8601
3622 article-date-original
3624 article-decode-mime-words
3625 article-decode-charset
3626 article-decode-encoded-words
3630 article-treat-dumbquotes
3631 article-normalize-headers
3632 ;; (article-show-all . gnus-article-show-all-headers)
3636 ;;; Gnus article mode
3639 (put 'gnus-article-mode 'mode-class 'special)
3641 (set-keymap-parent gnus-article-mode-map widget-keymap)
3643 (gnus-define-keys gnus-article-mode-map
3644 " " gnus-article-goto-next-page
3645 "\177" gnus-article-goto-prev-page
3646 [delete] gnus-article-goto-prev-page
3647 [backspace] gnus-article-goto-prev-page
3648 "\C-c^" gnus-article-refer-article
3649 "h" gnus-article-show-summary
3650 "s" gnus-article-show-summary
3651 "\C-c\C-m" gnus-article-mail
3652 "?" gnus-article-describe-briefly
3653 "e" gnus-summary-edit-article
3654 "<" beginning-of-buffer
3656 "\C-c\C-i" gnus-info-find-node
3658 "R" gnus-article-reply-with-original
3659 "F" gnus-article-followup-with-original
3660 "\C-hk" gnus-article-describe-key
3661 "\C-hc" gnus-article-describe-key-briefly
3663 "\C-d" gnus-article-read-summary-keys
3664 "\M-*" gnus-article-read-summary-keys
3665 "\M-#" gnus-article-read-summary-keys
3666 "\M-^" gnus-article-read-summary-keys
3667 "\M-g" gnus-article-read-summary-keys)
3669 (substitute-key-definition
3670 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3672 (defun gnus-article-make-menu-bar ()
3673 (unless (boundp 'gnus-article-commands-menu)
3674 (gnus-summary-make-menu-bar))
3675 (gnus-turn-off-edit-menu 'article)
3676 (unless (boundp 'gnus-article-article-menu)
3678 gnus-article-article-menu gnus-article-mode-map ""
3680 ["Scroll forwards" gnus-article-goto-next-page t]
3681 ["Scroll backwards" gnus-article-goto-prev-page t]
3682 ["Show summary" gnus-article-show-summary t]
3683 ["Fetch Message-ID at point" gnus-article-refer-article t]
3684 ["Mail to address at point" gnus-article-mail t]
3685 ["Send a bug report" gnus-bug t]))
3688 gnus-article-treatment-menu gnus-article-mode-map ""
3689 ;; Fixme: this should use :active (and maybe :visible).
3691 ["Hide headers" gnus-article-hide-headers t]
3692 ["Hide signature" gnus-article-hide-signature t]
3693 ["Hide citation" gnus-article-hide-citation t]
3694 ["Treat overstrike" gnus-article-treat-overstrike t]
3695 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3696 ["Remove carriage return" gnus-article-remove-cr t]
3697 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3698 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3699 ["Remove base64" gnus-article-de-base64-unreadable t]
3700 ["Treat html" gnus-article-wash-html t]
3701 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3702 ["Decode HZ" gnus-article-decode-HZ t]))
3704 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3706 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3708 (gnus-run-hooks 'gnus-article-menu-hook)))
3710 (defun gnus-article-mode ()
3711 "Major mode for displaying an article.
3713 All normal editing commands are switched off.
3715 The following commands are available in addition to all summary mode
3717 \\<gnus-article-mode-map>
3718 \\[gnus-article-next-page]\t Scroll the article one page forwards
3719 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3720 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3721 \\[gnus-article-show-summary]\t Display the summary buffer
3722 \\[gnus-article-mail]\t Send a reply to the address near point
3723 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3724 \\[gnus-info-find-node]\t Go to the Gnus info node"
3726 (gnus-simplify-mode-line)
3727 (setq mode-name "Article")
3728 (setq major-mode 'gnus-article-mode)
3729 (make-local-variable 'minor-mode-alist)
3730 (use-local-map gnus-article-mode-map)
3731 (when (gnus-visual-p 'article-menu 'menu)
3732 (gnus-article-make-menu-bar)
3733 (when gnus-summary-tool-bar-map
3734 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3735 (gnus-update-format-specifications nil 'article-mode)
3736 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3737 (set (make-local-variable 'gnus-page-broken) nil)
3738 (make-local-variable 'gnus-button-marker-list)
3739 (make-local-variable 'gnus-article-current-summary)
3740 (make-local-variable 'gnus-article-mime-handles)
3741 (make-local-variable 'gnus-article-decoded-p)
3742 (make-local-variable 'gnus-article-mime-handle-alist)
3743 (make-local-variable 'gnus-article-wash-types)
3744 (make-local-variable 'gnus-article-image-alist)
3745 (make-local-variable 'gnus-article-charset)
3746 (make-local-variable 'gnus-article-ignored-charsets)
3747 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3748 (set (make-local-variable 'show-nonbreak-escape) nil)
3749 (gnus-set-default-directory)
3750 (buffer-disable-undo)
3751 (setq buffer-read-only t
3752 show-trailing-whitespace nil)
3753 (set-syntax-table gnus-article-mode-syntax-table)
3754 (mm-enable-multibyte)
3755 (gnus-run-hooks 'gnus-article-mode-hook))
3757 (defun gnus-article-setup-buffer ()
3758 "Initialize the article buffer."
3759 (let* ((name (if gnus-single-article-buffer "*Article*"
3760 (concat "*Article " gnus-newsgroup-name "*")))
3762 (progn (string-match "\\*Article" name)
3763 (concat " *Original Article"
3764 (substring name (match-end 0))))))
3765 (setq gnus-article-buffer name)
3766 (setq gnus-original-article-buffer original)
3767 (setq gnus-article-mime-handle-alist nil)
3768 ;; This might be a variable local to the summary buffer.
3769 (unless gnus-single-article-buffer
3771 (set-buffer gnus-summary-buffer)
3772 (setq gnus-article-buffer name)
3773 (setq gnus-original-article-buffer original)
3774 (gnus-set-global-variables)))
3775 (gnus-article-setup-highlight-words)
3776 ;; Init original article buffer.
3778 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3779 (mm-enable-multibyte)
3780 (setq major-mode 'gnus-original-article-mode)
3781 (make-local-variable 'gnus-original-article))
3782 (if (and (get-buffer name)
3783 (with-current-buffer name
3784 (if gnus-article-edit-mode
3785 (if (y-or-n-p "Article mode edit in progress; discard? ")
3787 (set-buffer-modified-p nil)
3788 (gnus-kill-buffer name)
3791 (error "Action aborted"))
3795 (set (make-local-variable 'gnus-article-edit-mode) nil)
3796 (when gnus-article-mime-handles
3797 (mm-destroy-parts gnus-article-mime-handles)
3798 (setq gnus-article-mime-handles nil))
3799 ;; Set it to nil in article-buffer!
3800 (setq gnus-article-mime-handle-alist nil)
3801 (buffer-disable-undo)
3802 (setq buffer-read-only t)
3803 ;; This list just keeps growing if we don't reset it.
3804 (setq gnus-button-marker-list nil)
3805 (unless (eq major-mode 'gnus-article-mode)
3806 (gnus-article-mode))
3809 (set-buffer (gnus-get-buffer-create name))
3811 (make-local-variable 'gnus-summary-buffer)
3812 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3813 (current-buffer)))))
3815 ;; Set article window start at LINE, where LINE is the number of lines
3816 ;; from the head of the article.
3817 (defun gnus-article-set-window-start (&optional line)
3819 (gnus-get-buffer-window gnus-article-buffer t)
3821 (set-buffer gnus-article-buffer)
3822 (goto-char (point-min))
3825 (gnus-message 6 "Moved to bookmark")
3826 (search-forward "\n\n" nil t)
3830 (defun gnus-article-prepare (article &optional all-headers header)
3831 "Prepare ARTICLE in article mode buffer.
3832 ARTICLE should either be an article number or a Message-ID.
3833 If ARTICLE is an id, HEADER should be the article headers.
3834 If ALL-HEADERS is non-nil, no headers are hidden."
3836 ;; Make sure we start in a summary buffer.
3837 (unless (eq major-mode 'gnus-summary-mode)
3838 (set-buffer gnus-summary-buffer))
3839 (setq gnus-summary-buffer (current-buffer))
3840 (let* ((gnus-article (if header (mail-header-number header) article))
3841 (summary-buffer (current-buffer))
3842 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3843 (group gnus-newsgroup-name)
3846 (gnus-article-setup-buffer)
3847 (set-buffer gnus-article-buffer)
3848 ;; Deactivate active regions.
3849 (when (and (boundp 'transient-mark-mode)
3850 transient-mark-mode)
3851 (setq mark-active nil))
3852 (if (not (setq result (let ((inhibit-read-only t))
3853 (gnus-request-article-this-buffer
3855 ;; There is no such article.
3857 (when (and (numberp article)
3858 (not (memq article gnus-newsgroup-sparse)))
3859 (setq gnus-article-current
3860 (cons gnus-newsgroup-name article))
3861 (set-buffer gnus-summary-buffer)
3862 (setq gnus-current-article article)
3863 (if (and (memq article gnus-newsgroup-undownloaded)
3864 (not (gnus-online (gnus-find-method-for-group
3865 gnus-newsgroup-name))))
3867 (gnus-summary-set-agent-mark article)
3868 (message "Message marked for downloading"))
3869 (gnus-summary-mark-article article gnus-canceled-mark)
3870 (unless (memq article gnus-newsgroup-sparse)
3871 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3872 (if (or (eq result 'pseudo)
3873 (eq result 'nneething))
3876 (set-buffer summary-buffer)
3877 (push article gnus-newsgroup-history)
3878 (setq gnus-last-article gnus-current-article
3879 gnus-current-article 0
3880 gnus-current-headers nil
3881 gnus-article-current nil)
3882 (if (eq result 'nneething)
3883 (gnus-configure-windows 'summary)
3884 (gnus-configure-windows 'article))
3885 (gnus-set-global-variables))
3886 (let ((gnus-article-mime-handle-alist-1
3887 gnus-article-mime-handle-alist))
3888 (gnus-set-mode-line 'article)))
3889 ;; The result from the `request' was an actual article -
3890 ;; or at least some text that is now displayed in the
3892 (when (and (numberp article)
3893 (not (eq article gnus-current-article)))
3894 ;; Seems like a new article has been selected.
3895 ;; `gnus-current-article' must be an article number.
3897 (set-buffer summary-buffer)
3898 (push article gnus-newsgroup-history)
3899 (setq gnus-last-article gnus-current-article
3900 gnus-current-article article
3901 gnus-current-headers
3902 (gnus-summary-article-header gnus-current-article)
3903 gnus-article-current
3904 (cons gnus-newsgroup-name gnus-current-article))
3905 (unless (vectorp gnus-current-headers)
3906 (setq gnus-current-headers nil))
3907 (gnus-summary-goto-subject gnus-current-article)
3908 (when (gnus-summary-show-thread)
3909 ;; If the summary buffer really was folded, the
3910 ;; previous goto may not actually have gone to
3911 ;; the right article, but the thread root instead.
3913 (gnus-summary-goto-subject gnus-current-article))
3914 (gnus-run-hooks 'gnus-mark-article-hook)
3915 (gnus-set-mode-line 'summary)
3916 (when (gnus-visual-p 'article-highlight 'highlight)
3917 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3918 ;; Set the global newsgroup variables here.
3919 (gnus-set-global-variables)
3920 (setq gnus-have-all-headers
3921 (or all-headers gnus-show-all-headers))))
3923 (gnus-configure-windows 'article))
3924 (when (or (numberp article)
3926 (gnus-article-prepare-display)
3928 (goto-char (point-min))
3929 (when gnus-break-pages
3930 (gnus-narrow-to-page)))
3931 (let ((gnus-article-mime-handle-alist-1
3932 gnus-article-mime-handle-alist))
3933 (gnus-set-mode-line 'article))
3937 (set-window-point (get-buffer-window (current-buffer)) (point))
3938 (gnus-configure-windows 'article)
3942 (defun gnus-article-prepare-display ()
3943 "Make the current buffer look like a nice article."
3944 ;; Hooks for getting information from the article.
3945 ;; This hook must be called before being narrowed.
3946 (let ((gnus-article-buffer (current-buffer))
3948 (inhibit-read-only t))
3949 (unless (eq major-mode 'gnus-article-mode)
3950 (gnus-article-mode))
3951 (setq buffer-read-only nil
3952 gnus-article-wash-types nil
3953 gnus-article-image-alist nil)
3954 (gnus-run-hooks 'gnus-tmp-internal-hook)
3955 (when gnus-display-mime-function
3956 (funcall gnus-display-mime-function))
3957 (gnus-run-hooks 'gnus-article-prepare-hook)))
3960 ;;; Gnus MIME viewing functions
3963 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3964 "Format of the MIME buttons.
3966 Valid specifiers include:
3968 %T MIME type, along with additional info
3969 %n The `name' parameter
3970 %d The description, if any
3971 %l The length of the encoded part
3972 %p The part identifier number
3973 %e Dots if the part isn't displayed
3975 General format specifiers can also be used. See Info node
3976 `(gnus)Formatting Variables'.")
3978 (defvar gnus-mime-button-line-format-alist
3979 '((?t gnus-tmp-type ?s)
3980 (?T gnus-tmp-type-long ?s)
3981 (?n gnus-tmp-name ?s)
3982 (?d gnus-tmp-description ?s)
3984 (?l gnus-tmp-length ?d)
3985 (?e gnus-tmp-dots ?s)))
3987 (defvar gnus-mime-button-commands
3988 '((gnus-article-press-button "\r" "Toggle Display")
3989 (gnus-mime-view-part "v" "View Interactively...")
3990 (gnus-mime-view-part-as-type "t" "View As Type...")
3991 (gnus-mime-view-part-as-charset "C" "View As charset...")
3992 (gnus-mime-save-part "o" "Save...")
3993 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3994 (gnus-mime-delete-part "d" "Delete part")
3995 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3996 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3997 (gnus-mime-view-part-internally "E" "View Internally")
3998 (gnus-mime-view-part-externally "e" "View Externally")
3999 (gnus-mime-print-part "p" "Print")
4000 (gnus-mime-pipe-part "|" "Pipe To Command...")
4001 (gnus-mime-action-on-part "." "Take action on the part...")))
4003 (defun gnus-article-mime-part-status ()
4004 (if gnus-article-mime-handle-alist-1
4005 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4007 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4010 (defvar gnus-mime-button-map
4011 (let ((map (make-sparse-keymap)))
4012 (define-key map gnus-mouse-2 'gnus-article-push-button)
4013 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4014 (dolist (c gnus-mime-button-commands)
4015 (define-key map (cadr c) (car c)))
4019 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4021 ,@(mapcar (lambda (c)
4022 (vector (caddr c) (car c) :enable t))
4023 gnus-mime-button-commands)))
4025 (defun gnus-mime-button-menu (event prefix)
4026 "Construct a context-sensitive menu of MIME commands."
4027 (interactive "e\nP")
4028 (save-window-excursion
4029 (let ((pos (event-start event)))
4030 (select-window (posn-window pos))
4031 (goto-char (posn-point pos))
4032 (gnus-article-check-buffer)
4033 (popup-menu gnus-mime-button-menu nil prefix))))
4035 (defun gnus-mime-view-all-parts (&optional handles)
4036 "View all the MIME parts."
4038 (with-current-buffer gnus-article-buffer
4039 (let ((handles (or handles gnus-article-mime-handles))
4040 (mail-parse-charset gnus-newsgroup-charset)
4041 (mail-parse-ignored-charsets
4042 (with-current-buffer gnus-summary-buffer
4043 gnus-newsgroup-ignored-charsets)))
4045 (mm-remove-parts handles)
4046 (goto-char (point-min))
4047 (or (search-forward "\n\n") (goto-char (point-max)))
4048 (let ((inhibit-read-only t))
4049 (delete-region (point) (point-max))
4050 (mm-display-parts handles))))))
4053 (defsubst gnus-article-edit-part (handles)
4054 "Edit an article in order to delete a mime part.
4055 This function is exclusively used by `gnus-mime-save-part-and-strip'
4056 and `gnus-mime-delete-part', and not provided at run-time normally."
4057 (gnus-article-edit-article
4060 (let ((mail-parse-charset (or gnus-article-charset
4061 ',gnus-newsgroup-charset))
4062 (mail-parse-ignored-charsets
4063 (or gnus-article-ignored-charsets
4064 ',gnus-newsgroup-ignored-charsets))
4065 (mbl mml-buffer-list))
4066 (setq mml-buffer-list nil)
4067 (insert-buffer gnus-original-article-buffer)
4068 (mime-to-mml ',handles)
4069 (setq gnus-article-mime-handles nil)
4070 (let ((mbl1 mml-buffer-list))
4071 (setq mml-buffer-list mbl)
4072 (set (make-local-variable 'mml-buffer-list) mbl1))
4073 (gnus-make-local-hook 'kill-buffer-hook)
4074 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4075 `(lambda (no-highlight)
4076 (let ((mail-parse-charset (or gnus-article-charset
4077 ',gnus-newsgroup-charset))
4078 (message-options message-options)
4079 (message-options-set-recipient)
4080 (mail-parse-ignored-charsets
4081 (or gnus-article-ignored-charsets
4082 ',gnus-newsgroup-ignored-charsets)))
4084 (mml-destroy-buffers)
4085 (remove-hook 'kill-buffer-hook
4086 'mml-destroy-buffers t)
4087 (kill-local-variable 'mml-buffer-list))
4088 (gnus-summary-edit-article-done
4089 ,(or (mail-header-references gnus-current-headers) "")
4090 ,(gnus-group-read-only-p)
4091 ,gnus-summary-buffer no-highlight)))
4092 (gnus-article-edit-done)
4093 (gnus-summary-expand-window)
4094 (gnus-summary-show-article)))
4096 (defun gnus-mime-save-part-and-strip ()
4097 "Save the MIME part under point then replace it with an external body."
4099 (gnus-article-check-buffer)
4100 (when (gnus-group-read-only-p)
4101 (error "The current group does not support deleting of parts"))
4102 (when (mm-complicated-handles gnus-article-mime-handles)
4104 The current article has a complicated MIME structure, giving up..."))
4105 (when (gnus-yes-or-no-p "\
4106 Deleting parts may malfunction or destroy the article; continue? ")
4107 (let* ((data (get-text-property (point) 'gnus-data))
4109 (handles gnus-article-mime-handles))
4110 (setq file (and data (mm-save-part data)))
4112 (with-current-buffer (mm-handle-buffer data)
4114 (insert "Content-Type: " (mm-handle-media-type data))
4115 (mml-insert-parameter-string (cdr (mm-handle-type data))
4118 (insert "Content-ID: " (message-make-message-id) "\n")
4119 (insert "Content-Transfer-Encoding: binary\n")
4122 (cdr (mm-make-handle nil
4123 `("message/external-body"
4124 (access-type . "LOCAL-FILE")
4126 (set-buffer gnus-summary-buffer)
4127 (gnus-article-edit-part handles)))))
4129 (defun gnus-mime-delete-part ()
4130 "Delete the MIME part under point.
4131 Replace it with some information about the removed part."
4133 (gnus-article-check-buffer)
4134 (when (gnus-group-read-only-p)
4135 (error "The current group does not support deleting of parts"))
4136 (when (mm-complicated-handles gnus-article-mime-handles)
4138 The current article has a complicated MIME structure, giving up..."))
4139 (when (gnus-yes-or-no-p "\
4140 Deleting parts may malfunction or destroy the article; continue? ")
4141 (let* ((data (get-text-property (point) 'gnus-data))
4142 (handles gnus-article-mime-handles)
4146 (mail-decode-encoded-word-string (or (mm-handle-description data)
4149 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4151 (type (mm-handle-media-type data)))
4153 (error "No MIME part under point"))
4154 (with-current-buffer (mm-handle-buffer data)
4155 (let ((bsize (format "%s" (buffer-size))))
4160 "| The following attachment has been deleted:\n"
4162 "| Type: " type "\n"
4163 "| Filename: " filename "\n"
4164 "| Size (encoded): " bsize " Byte\n"
4165 "| Description: " description "\n"
4168 (cdr (mm-make-handle
4169 nil `("text/plain") nil nil
4171 (format "Deleted attachment (%s bytes)" bsize))))))
4172 (set-buffer gnus-summary-buffer)
4173 (gnus-article-edit-part handles))))
4175 (defun gnus-mime-save-part ()
4176 "Save the MIME part under point."
4178 (gnus-article-check-buffer)
4179 (let ((data (get-text-property (point) 'gnus-data)))
4181 (mm-save-part data))))
4183 (defun gnus-mime-pipe-part ()
4184 "Pipe the MIME part under point to a process."
4186 (gnus-article-check-buffer)
4187 (let ((data (get-text-property (point) 'gnus-data)))
4189 (mm-pipe-part data))))
4191 (defun gnus-mime-view-part ()
4192 "Interactively choose a viewing method for the MIME part under point."
4194 (gnus-article-check-buffer)
4195 (let ((data (get-text-property (point) 'gnus-data)))
4197 (setq gnus-article-mime-handles
4199 gnus-article-mime-handles (setq data (copy-sequence data))))
4200 (mm-interactively-view-part data))))
4202 (defun gnus-mime-view-part-as-type-internal ()
4203 (gnus-article-check-buffer)
4204 (let* ((name (mail-content-type-get
4205 (mm-handle-type (get-text-property (point) 'gnus-data))
4207 (def-type (and name (mm-default-file-encoding name))))
4208 (and def-type (cons def-type 0))))
4210 (defun gnus-mime-view-part-as-type (&optional mime-type)
4211 "Choose a MIME media type, and view the part as such."
4214 (setq mime-type (completing-read
4215 "View as MIME type: "
4216 (mapcar #'list (mailcap-mime-types))
4218 (gnus-mime-view-part-as-type-internal))))
4219 (gnus-article-check-buffer)
4220 (let ((handle (get-text-property (point) 'gnus-data)))
4223 (mm-make-handle (mm-handle-buffer handle)
4224 (cons mime-type (cdr (mm-handle-type handle)))
4225 (mm-handle-encoding handle)
4226 (mm-handle-undisplayer handle)
4227 (mm-handle-disposition handle)
4228 (mm-handle-description handle)
4230 (mm-handle-id handle)))
4231 (setq gnus-article-mime-handles
4232 (mm-merge-handles gnus-article-mime-handles handle))
4233 (gnus-mm-display-part handle))))
4235 (defun gnus-mime-copy-part (&optional handle arg)
4236 "Put the MIME part under point into a new buffer.
4237 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4239 (interactive (list nil current-prefix-arg))
4240 (gnus-article-check-buffer)
4242 (setq handle (get-text-property (point) 'gnus-data)))
4244 (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4246 (mail-content-type-get (mm-handle-disposition handle)
4248 contents dont-decode charset coding-system)
4249 (mm-with-unibyte-buffer
4250 (mm-insert-part handle)
4251 (setq contents (or (condition-case nil
4252 (mm-decompress-buffer filename nil 'sig)
4254 (setq dont-decode t)
4257 (setq filename (cond (filename (file-name-nondirectory filename))
4258 (dont-decode "*raw data*")
4263 (unless (setq charset (mail-content-type-get
4264 (mm-handle-type handle) 'charset))
4265 (unless (setq coding-system (mm-with-unibyte-buffer
4267 (mm-find-buffer-file-coding-system)))
4268 (setq charset gnus-newsgroup-charset))))
4270 (setq charset (or (cdr (assq arg
4271 gnus-summary-show-article-charset-alist))
4272 (mm-read-coding-system "Charset: ")))))
4273 (switch-to-buffer (generate-new-buffer filename))
4274 (if (or coding-system
4276 (setq coding-system (mm-charset-to-coding-system charset))
4277 (not (eq charset 'ascii))))
4279 (mm-enable-multibyte)
4280 (insert (mm-decode-coding-string contents coding-system))
4281 (setq buffer-file-coding-system
4282 (if (boundp 'last-coding-system-used)
4283 (symbol-value 'last-coding-system-used)
4285 (mm-disable-multibyte)
4287 (setq buffer-file-coding-system mm-binary-coding-system))
4288 ;; We do it this way to make `normal-mode' set the appropriate mode.
4291 (setq buffer-file-name (expand-file-name filename))
4293 (setq buffer-file-name nil))
4294 (goto-char (point-min)))))
4296 (defun gnus-mime-print-part (&optional handle filename)
4297 "Print the MIME part under point."
4298 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4299 (gnus-article-check-buffer)
4300 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4301 (contents (and handle (mm-get-part handle)))
4302 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4303 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4308 (mm-save-part-to-file handle file)
4309 (call-process shell-file-name nil
4310 (generate-new-buffer " *mm*")
4312 shell-command-switch
4314 printer file (mm-handle-type handle))))
4318 (gnus-print-buffer))
4319 (ps-despool filename)))))
4321 (defun gnus-mime-inline-part (&optional handle arg)
4322 "Insert the MIME part under point into the current buffer.
4323 Compressed files like .gz and .bz2 are decompressed."
4324 (interactive (list nil current-prefix-arg))
4325 (gnus-article-check-buffer)
4327 (setq handle (get-text-property (point) 'gnus-data)))
4330 (inhibit-read-only t)
4331 contents charset coding-system)
4332 (if (and (not arg) (mm-handle-undisplayer handle))
4333 (mm-remove-part handle)
4334 (mm-with-unibyte-buffer
4335 (mm-insert-part handle)
4337 (or (mm-decompress-buffer
4338 (or (mail-content-type-get (mm-handle-disposition handle)
4340 (mail-content-type-get (mm-handle-disposition handle)
4346 (unless (setq charset (mail-content-type-get
4347 (mm-handle-type handle) 'charset))
4348 (unless (setq coding-system
4349 (mm-with-unibyte-buffer
4351 (mm-find-buffer-file-coding-system)))
4352 (setq charset gnus-newsgroup-charset))))
4354 (if (mm-handle-undisplayer handle)
4355 (mm-remove-part handle))
4358 gnus-summary-show-article-charset-alist))
4359 (mm-read-coding-system "Charset: "))))
4361 (if (mm-handle-undisplayer handle)
4362 (mm-remove-part handle))))
4366 (if (or coding-system
4369 (mm-charset-to-coding-system charset))
4370 (not (eq charset 'ascii))))
4371 (mm-decode-coding-string contents coding-system)
4372 (mm-string-to-multibyte contents)))
4375 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4376 "Insert the MIME part under point into the current buffer using the
4378 (interactive (list nil current-prefix-arg))
4379 (gnus-article-check-buffer)
4380 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4383 (inhibit-read-only t))
4385 (if (mm-handle-undisplayer handle)
4386 (mm-remove-part handle))
4387 (let ((gnus-newsgroup-charset
4389 gnus-summary-show-article-charset-alist))
4390 (mm-read-coding-system "Charset: ")))
4391 (gnus-newsgroup-ignored-charsets 'gnus-all))
4392 (gnus-article-press-button)))))
4394 (defun gnus-mime-view-part-externally (&optional handle)
4395 "View the MIME part under point with an external viewer."
4397 (gnus-article-check-buffer)
4398 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4399 (mm-user-display-methods nil)
4400 (mm-inlined-types nil)
4401 (mail-parse-charset gnus-newsgroup-charset)
4402 (mail-parse-ignored-charsets
4403 (with-current-buffer gnus-summary-buffer
4404 gnus-newsgroup-ignored-charsets)))
4406 (if (mm-handle-undisplayer handle)
4407 (mm-remove-part handle)
4408 (mm-display-part handle)))))
4410 (defun gnus-mime-view-part-internally (&optional handle)
4411 "View the MIME part under point with an internal viewer.
4412 If no internal viewer is available, use an external viewer."
4414 (gnus-article-check-buffer)
4415 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4416 (mm-inlined-types '(".*"))
4417 (mm-inline-large-images t)
4418 (mail-parse-charset gnus-newsgroup-charset)
4419 (mail-parse-ignored-charsets
4420 (with-current-buffer gnus-summary-buffer
4421 gnus-newsgroup-ignored-charsets))
4422 (inhibit-read-only t))
4424 (if (mm-handle-undisplayer handle)
4425 (mm-remove-part handle)
4426 (mm-display-part handle)))))
4428 (defun gnus-mime-action-on-part (&optional action)
4429 "Do something with the MIME attachment at \(point\)."
4431 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4432 (gnus-article-check-buffer)
4433 (let ((action-pair (assoc action gnus-mime-action-alist)))
4435 (funcall (cdr action-pair)))))
4437 (defun gnus-article-part-wrapper (n function)
4438 (with-current-buffer gnus-article-buffer
4439 (when (> n (length gnus-article-mime-handle-alist))
4440 (error "No such part"))
4441 (gnus-article-goto-part n)
4442 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4443 (funcall function handle))))
4445 (defun gnus-article-pipe-part (n)
4446 "Pipe MIME part N, which is the numerical prefix."
4448 (gnus-article-part-wrapper n 'mm-pipe-part))
4450 (defun gnus-article-save-part (n)
4451 "Save MIME part N, which is the numerical prefix."
4453 (gnus-article-part-wrapper n 'mm-save-part))
4455 (defun gnus-article-interactively-view-part (n)
4456 "View MIME part N interactively, which is the numerical prefix."
4458 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4460 (defun gnus-article-copy-part (n)
4461 "Copy MIME part N, which is the numerical prefix."
4463 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4465 (defun gnus-article-view-part-as-charset (n)
4466 "View MIME part N using a specified charset.
4467 N is the numerical prefix."
4469 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4471 (defun gnus-article-view-part-externally (n)
4472 "View MIME part N externally, which is the numerical prefix."
4474 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4476 (defun gnus-article-inline-part (n)
4477 "Inline MIME part N, which is the numerical prefix."
4479 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4481 (defun gnus-article-mime-match-handle-first (condition)
4484 (dolist (ihandle gnus-article-mime-handle-alist)
4486 ((functionp condition)
4487 (funcall condition (cdr ihandle)))
4488 ((eq condition 'undisplayed)
4489 (not (or (mm-handle-undisplayer (cdr ihandle))
4490 (equal (mm-handle-media-type (cdr ihandle))
4491 "multipart/alternative"))))
4492 ((eq condition 'undisplayed-alternative)
4493 (not (mm-handle-undisplayer (cdr ihandle))))
4495 (gnus-article-goto-part (car ihandle))
4496 (or (not n) (< (car ihandle) n)))
4497 (setq n (car ihandle))))
4501 (defun gnus-article-view-part (&optional n)
4502 "View MIME part N, which is the numerical prefix."
4504 (with-current-buffer gnus-article-buffer
4505 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4506 gnus-article-mime-match-handle-function)))
4507 (when (> n (length gnus-article-mime-handle-alist))
4508 (error "No such part"))
4509 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4510 (when (gnus-article-goto-part n)
4511 (if (equal (car handle) "multipart/alternative")
4512 (gnus-article-press-button)
4513 (when (eq (gnus-mm-display-part handle) 'internal)
4514 (gnus-set-window-start)))))))
4516 (defsubst gnus-article-mime-total-parts ()
4517 (if (bufferp (car gnus-article-mime-handles))
4519 (1- (length gnus-article-mime-handles))))
4521 (defun gnus-mm-display-part (handle)
4522 "Display HANDLE and fix MIME button."
4523 (let ((id (get-text-property (point) 'gnus-part))
4525 (inhibit-read-only t))
4528 (let ((window (selected-window))
4529 (mail-parse-charset gnus-newsgroup-charset)
4530 (mail-parse-ignored-charsets
4531 (if (gnus-buffer-live-p gnus-summary-buffer)
4532 (with-current-buffer gnus-summary-buffer
4533 gnus-newsgroup-ignored-charsets)
4537 (let ((win (gnus-get-buffer-window (current-buffer) t))
4540 (select-window win))
4543 (if (mm-handle-displayed-p handle)
4544 ;; This will remove the part.
4545 (mm-display-part handle)
4547 (narrow-to-region (point)
4548 (if (eobp) (point) (1+ (point))))
4549 (mm-display-part handle)
4550 ;; We narrow to the part itself and
4551 ;; then call the treatment functions.
4552 (goto-char (point-min))
4554 (narrow-to-region (point) (point-max))
4557 (gnus-article-mime-total-parts)
4558 (mm-handle-media-type handle)))))
4559 (if (window-live-p window)
4560 (select-window window)))))
4563 (gnus-insert-mime-button
4564 handle id (list (mm-handle-displayed-p handle)))
4565 (goto-char point))))
4567 (defun gnus-article-goto-part (n)
4568 "Go to MIME part N."
4569 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4571 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4572 (let ((gnus-tmp-name
4573 (or (mail-content-type-get (mm-handle-type handle) 'name)
4574 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4575 (mail-content-type-get (mm-handle-type handle) 'url)
4577 (gnus-tmp-type (mm-handle-media-type handle))
4578 (gnus-tmp-description
4579 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4582 (if (if displayed (car displayed)
4583 (mm-handle-displayed-p handle))
4585 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4587 gnus-tmp-type-long b e)
4588 (when (string-match ".*/" gnus-tmp-name)
4589 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4590 (setq gnus-tmp-type-long (concat gnus-tmp-type
4591 (and (not (equal gnus-tmp-name ""))
4592 (concat "; " gnus-tmp-name))))
4593 (unless (equal gnus-tmp-description "")
4594 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4599 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4600 `(keymap ,gnus-mime-button-map
4601 gnus-callback gnus-mm-display-part
4602 gnus-part ,gnus-tmp-id
4603 article-type annotation
4606 ;; Exclude a newline.
4609 (widget-convert-button
4612 :action 'gnus-widget-press-button
4613 :button-keymap gnus-mime-button-map
4615 (lambda (widget/window &optional overlay pos)
4616 ;; Needed to properly clear the message due to a bug in
4617 ;; wid-edit (XEmacs only).
4618 (if (boundp 'help-echo-owns-message)
4619 (setq help-echo-owns-message t))
4621 "%S: %s the MIME part; %S: more options"
4622 (aref gnus-mouse-2 0)
4623 ;; XEmacs will get a single widget arg; Emacs 21 will get
4624 ;; window, overlay, position.
4625 (if (mm-handle-displayed-p
4627 (with-current-buffer (gnus-overlay-buffer overlay)
4628 (widget-get (widget-at (gnus-overlay-start overlay))
4630 (widget-get widget/window :mime-handle)))
4632 (aref gnus-down-mouse-3 0))))))
4634 (defun gnus-widget-press-button (elems el)
4635 (goto-char (widget-get elems :from))
4636 (gnus-article-press-button))
4638 (defvar gnus-displaying-mime nil)
4640 (defun gnus-display-mime (&optional ihandles)
4641 "Display the MIME parts."
4643 (save-selected-window
4644 (let ((window (get-buffer-window gnus-article-buffer))
4647 (select-window window)
4648 ;; We have to do this since selecting the window
4649 ;; may change the point. So we set the window point.
4650 (set-window-point window point)))
4651 (let ((handles ihandles)
4652 (inhibit-read-only t)
4653 handle name type b e display)
4655 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4656 (when gnus-article-emulate-mime
4657 (mm-uu-dissect-text-parts handles)))
4658 (gnus-article-emulate-mime
4659 (setq handles (mm-uu-dissect))))
4660 (when (and (not ihandles)
4661 (not gnus-displaying-mime))
4662 ;; Top-level call; we clean up.
4663 (when gnus-article-mime-handles
4664 (mm-destroy-parts gnus-article-mime-handles)
4665 (setq gnus-article-mime-handle-alist nil));; A trick.
4666 (setq gnus-article-mime-handles handles)
4667 ;; We allow users to glean info from the handles.
4668 (when gnus-article-mime-part-function
4669 (gnus-mime-part-function handles)))
4671 (or (not (stringp (car handles)))
4674 (when (and (not ihandles)
4675 (not gnus-displaying-mime))
4676 ;; Clean up for mime parts.
4678 (delete-region (point) (point-max)))
4679 (let ((gnus-displaying-mime t))
4680 (gnus-mime-display-part handles)))
4683 (narrow-to-region (point) (point-max))
4684 (gnus-treat-article nil 1 1)
4687 ;; Highlight the headers.
4691 (narrow-to-region (point-min) (point))
4692 (gnus-treat-article 'head))))))))
4694 (defcustom gnus-mime-display-multipart-as-mixed nil
4695 "Display \"multipart\" parts as \"multipart/mixed\".
4697 If t, it overrides nil values of
4698 `gnus-mime-display-multipart-alternative-as-mixed' and
4699 `gnus-mime-display-multipart-related-as-mixed'."
4700 :group 'gnus-article-mime
4703 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4704 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4706 :group 'gnus-article-mime
4709 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4710 "Display \"multipart/related\" parts as \"multipart/mixed\".
4712 If displaying \"text/html\" is discouraged \(see
4713 `mm-discouraged-alternatives'\) images or other material inside a
4714 \"multipart/related\" part might be overlooked when this variable is nil."
4716 :group 'gnus-article-mime
4719 (defun gnus-mime-display-part (handle)
4722 ((not (stringp (car handle)))
4723 (gnus-mime-display-single handle))
4724 ;; User-defined multipart
4725 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4726 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4728 ;; multipart/alternative
4729 ((and (equal (car handle) "multipart/alternative")
4730 (not (or gnus-mime-display-multipart-as-mixed
4731 gnus-mime-display-multipart-alternative-as-mixed)))
4732 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4733 (push (cons id handle) gnus-article-mime-handle-alist)
4734 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4735 ;; multipart/related
4736 ((and (equal (car handle) "multipart/related")
4737 (not (or gnus-mime-display-multipart-as-mixed
4738 gnus-mime-display-multipart-related-as-mixed)))
4739 ;;;!!!We should find the start part, but we just default
4740 ;;;!!!to the first part.
4741 ;;(gnus-mime-display-part (cadr handle))
4742 ;;;!!! Most multipart/related is an HTML message plus images.
4743 ;;;!!! Unfortunately we are unable to let W3 display those
4744 ;;;!!! included images, so we just display it as a mixed multipart.
4745 ;;(gnus-mime-display-mixed (cdr handle))
4746 ;;;!!! No, w3 can display everything just fine.
4747 (gnus-mime-display-part (cadr handle)))
4748 ((equal (car handle) "multipart/signed")
4749 (gnus-add-wash-type 'signed)
4750 (gnus-mime-display-security handle))
4751 ((equal (car handle) "multipart/encrypted")
4752 (gnus-add-wash-type 'encrypted)
4753 (gnus-mime-display-security handle))
4754 ;; Other multiparts are handled like multipart/mixed.
4756 (gnus-mime-display-mixed (cdr handle)))))
4758 (defun gnus-mime-part-function (handles)
4759 (if (stringp (car handles))
4760 (mapcar 'gnus-mime-part-function (cdr handles))
4761 (funcall gnus-article-mime-part-function handles)))
4763 (defun gnus-mime-display-mixed (handles)
4764 (mapcar 'gnus-mime-display-part handles))
4766 (defun gnus-mime-display-single (handle)
4767 (let ((type (mm-handle-media-type handle))
4768 (ignored gnus-ignored-mime-types)
4775 (when (string-match (pop ignored) type)
4776 (throw 'ignored nil)))
4777 (if (and (setq not-attachment
4778 (and (not (mm-inline-override-p handle))
4779 (or (not (mm-handle-disposition handle))
4780 (equal (car (mm-handle-disposition handle))
4782 (mm-attachment-override-p handle))))
4783 (mm-automatic-display-p handle)
4785 (mm-inlinable-p handle)
4786 (mm-inlined-p handle))
4787 (mm-automatic-external-display-p type)))
4789 (when (equal (mm-handle-media-supertype handle) "text")
4791 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4793 (push (cons id handle) gnus-article-mime-handle-alist)
4794 (when (or (not display)
4795 (not (gnus-unbuttonized-mime-type-p type)))
4796 (gnus-insert-mime-button
4797 handle id (list (or display (and not-attachment text))))
4798 (gnus-article-insert-newline)
4799 ;; Remember modify the number of forward lines.
4807 (let ((mail-parse-charset gnus-newsgroup-charset)
4808 (mail-parse-ignored-charsets
4809 (save-excursion (condition-case ()
4810 (set-buffer gnus-summary-buffer)
4812 gnus-newsgroup-ignored-charsets)))
4813 (mm-display-part handle t))
4814 (goto-char (point-max)))
4815 ((and text not-attachment)
4819 (gnus-article-insert-newline)
4820 (mm-display-inline handle)
4821 (goto-char (point-max))))
4825 (narrow-to-region beg (point))
4828 (gnus-article-mime-total-parts)
4829 (mm-handle-media-type handle)))))))))
4831 (defun gnus-unbuttonized-mime-type-p (type)
4832 "Say whether TYPE is to be unbuttonized."
4833 (unless gnus-inhibit-mime-unbuttonizing
4835 (let ((types gnus-unbuttonized-mime-types))
4837 (when (string-match (pop types) type)
4838 (throw 'found t)))))
4840 (let ((types gnus-buttonized-mime-types))
4842 (when (string-match (pop types) type)
4843 (throw 'found t)))))))))
4845 (defun gnus-article-insert-newline ()
4846 "Insert a newline, but mark it as undeletable."
4847 (gnus-put-text-property
4848 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4850 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4851 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4854 handle (inhibit-read-only t) from props begend not-pref)
4855 (save-window-excursion
4858 (narrow-to-region (car ibegend)
4861 (goto-char (car ibegend))
4864 (delete-region (point-min) (point-max))
4865 (mm-remove-parts handles))
4866 (setq begend (list (point-marker)))
4868 (unless (setq not-pref (cadr (member preferred ihandles)))
4869 (setq not-pref (car ihandles)))
4872 (not (gnus-unbuttonized-mime-type-p
4873 "multipart/alternative")))
4874 (gnus-add-text-properties
4877 (insert (format "%d. " id))
4881 (unless ,(not ibegend)
4882 (setq gnus-article-mime-handle-alist
4883 ',gnus-article-mime-handle-alist))
4884 (gnus-mime-display-alternative
4885 ',ihandles ',not-pref ',begend ,id))
4886 keymap ,gnus-mime-button-map
4887 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4888 face ,gnus-article-button-face
4891 (widget-convert-button 'link from (point)
4892 :action 'gnus-widget-press-button
4893 :button-keymap gnus-widget-button-keymap)
4895 (while (setq handle (pop handles))
4896 (gnus-add-text-properties
4899 (insert (format "(%c) %-18s"
4900 (if (equal handle preferred) ?* ? )
4901 (mm-handle-media-type handle)))
4905 (unless ,(not ibegend)
4906 (setq gnus-article-mime-handle-alist
4907 ',gnus-article-mime-handle-alist))
4908 (gnus-mime-display-alternative
4909 ',ihandles ',handle ',begend ,id))
4910 keymap ,gnus-mime-button-map
4911 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4912 face ,gnus-article-button-face
4915 (widget-convert-button 'link from (point)
4916 :action 'gnus-widget-press-button
4917 :button-keymap gnus-widget-button-keymap)
4921 (if (stringp (car preferred))
4922 (gnus-display-mime preferred)
4923 (let ((mail-parse-charset gnus-newsgroup-charset)
4924 (mail-parse-ignored-charsets
4925 (with-current-buffer gnus-summary-buffer
4926 gnus-newsgroup-ignored-charsets)))
4927 (mm-display-part preferred)
4931 (narrow-to-region (car begend) (point-max))
4933 nil (length gnus-article-mime-handle-alist)
4934 (gnus-article-mime-total-parts)
4935 (mm-handle-media-type handle))))))
4936 (goto-char (point-max))
4937 (setcdr begend (point-marker)))))
4939 (goto-char point))))
4941 (defconst gnus-article-wash-status-strings
4942 (let ((alist '((cite "c" "Possible hidden citation text"
4943 " " "All citation text visible")
4944 (headers "h" "Hidden headers"
4945 " " "All headers visible.")
4946 (pgp "p" "Encrypted or signed message status hidden"
4947 " " "No hidden encryption nor digital signature status")
4948 (signature "s" "Signature has been hidden"
4949 " " "Signature is visible")
4950 (overstrike "o" "Overstrike (^H) characters applied"
4951 " " "No overstrike characters applied")
4952 (emphasis "e" "/*_Emphasis_*/ characters applied"
4953 " " "No /*_emphasis_*/ characters applied")))
4955 (dolist (entry alist result)
4956 (let ((key (nth 0 entry))
4957 (on (copy-sequence (nth 1 entry)))
4958 (on-help (nth 2 entry))
4959 (off (copy-sequence (nth 3 entry)))
4960 (off-help (nth 4 entry)))
4961 (put-text-property 0 1 'help-echo on-help on)
4962 (put-text-property 0 1 'help-echo off-help off)
4963 (push (list key on off) result))))
4964 "Alist of strings describing wash status in the mode line.
4965 Each entry has the form (KEY ON OF), where the KEY is a symbol
4966 representing the particular washing function, ON is the string to use
4967 in the article mode line when the washing function is active, and OFF
4968 is the string to use when it is inactive.")
4970 (defun gnus-article-wash-status-entry (key value)
4971 (let ((entry (assoc key gnus-article-wash-status-strings)))
4972 (if value (nth 1 entry) (nth 2 entry))))
4974 (defun gnus-article-wash-status ()
4975 "Return a string which display status of article washing."
4976 (with-current-buffer gnus-article-buffer
4977 (let ((cite (memq 'cite gnus-article-wash-types))
4978 (headers (memq 'headers gnus-article-wash-types))
4979 (boring (memq 'boring-headers gnus-article-wash-types))
4980 (pgp (memq 'pgp gnus-article-wash-types))
4981 (pem (memq 'pem gnus-article-wash-types))
4982 (signed (memq 'signed gnus-article-wash-types))
4983 (encrypted (memq 'encrypted gnus-article-wash-types))
4984 (signature (memq 'signature gnus-article-wash-types))
4985 (overstrike (memq 'overstrike gnus-article-wash-types))
4986 (emphasis (memq 'emphasis gnus-article-wash-types)))
4988 (gnus-article-wash-status-entry 'cite cite)
4989 (gnus-article-wash-status-entry 'headers (or headers boring))
4990 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4991 (gnus-article-wash-status-entry 'signature signature)
4992 (gnus-article-wash-status-entry 'overstrike overstrike)
4993 (gnus-article-wash-status-entry 'emphasis emphasis)))))
4995 (defun gnus-add-wash-type (type)
4996 "Add a washing of TYPE to the current status."
4997 (add-to-list 'gnus-article-wash-types type))
4999 (defun gnus-delete-wash-type (type)
5000 "Add a washing of TYPE to the current status."
5001 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5003 (defun gnus-add-image (category image)
5004 "Add IMAGE of CATEGORY to the list of displayed images."
5005 (let ((entry (assq category gnus-article-image-alist)))
5007 (setq entry (list category))
5008 (push entry gnus-article-image-alist))
5009 (nconc entry (list image))))
5011 (defun gnus-delete-images (category)
5012 "Delete all images in CATEGORY."
5013 (let ((entry (assq category gnus-article-image-alist)))
5014 (dolist (image (cdr entry))
5015 (gnus-remove-image image category))
5016 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5017 (gnus-delete-wash-type category)))
5019 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5021 (defun gnus-article-maybe-hide-headers ()
5022 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5023 Provided for backwards compatibility."
5024 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5025 (not (with-current-buffer gnus-summary-buffer
5026 gnus-have-all-headers)))
5027 (not gnus-inhibit-hiding))
5028 (gnus-article-hide-headers)))
5032 (defun gnus-output-to-file (file-name)
5033 "Append the current article to a file named FILE-NAME."
5034 (let ((artbuf (current-buffer)))
5036 (insert-buffer-substring artbuf)
5037 ;; Append newline at end of the buffer as separator, and then
5039 (goto-char (point-max))
5041 (let ((file-name-coding-system nnmail-pathname-coding-system))
5042 (mm-append-to-file (point-min) (point-max) file-name))
5045 (defun gnus-narrow-to-page (&optional arg)
5046 "Narrow the article buffer to a page.
5047 If given a numerical ARG, move forward ARG pages."
5049 (setq arg (if arg (prefix-numeric-value arg) 0))
5051 (set-buffer gnus-article-buffer)
5052 (goto-char (point-min))
5054 ;; Remove any old next/prev buttons.
5055 (when (gnus-visual-p 'page-marker)
5056 (let ((inhibit-read-only t))
5057 (gnus-remove-text-with-property 'gnus-prev)
5058 (gnus-remove-text-with-property 'gnus-next)))
5061 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5063 (re-search-forward page-delimiter nil 'move arg)))
5064 (goto-char (match-end 0))
5066 (goto-char (point-min))
5067 (setq gnus-page-broken
5068 (and (re-search-forward page-delimiter nil t) t))))
5069 (when gnus-page-broken
5072 (if (re-search-forward page-delimiter nil 'move)
5075 (when (and (gnus-visual-p 'page-marker)
5076 (> (point-min) (save-restriction (widen) (point-min))))
5078 (goto-char (point-min))
5079 (gnus-insert-prev-page-button)))
5080 (when (and (gnus-visual-p 'page-marker)
5081 (< (point-max) (save-restriction (widen) (point-max))))
5083 (goto-char (point-max))
5084 (gnus-insert-next-page-button))))))
5086 ;; Article mode commands
5088 (defun gnus-article-goto-next-page ()
5089 "Show the next page of the article."
5091 (when (gnus-article-next-page)
5092 (goto-char (point-min))
5093 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5096 (defun gnus-article-goto-prev-page ()
5097 "Show the previous page of the article."
5100 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5101 (gnus-article-prev-page nil)))
5103 ;; This is cleaner but currently breaks `gnus-pick-mode':
5105 ;; (defun gnus-article-goto-next-page ()
5106 ;; "Show the next page of the article."
5108 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5109 ;; (gnus-summary-next-page)))
5111 ;; (defun gnus-article-goto-prev-page ()
5112 ;; "Show the next page of the article."
5114 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5115 ;; (gnus-summary-prev-page)))
5117 (defun gnus-article-next-page (&optional lines)
5118 "Show the next page of the current article.
5119 If end of article, return non-nil. Otherwise return nil.
5120 Argument LINES specifies lines to be scrolled up."
5122 (move-to-window-line -1)
5125 (and (pos-visible-in-window-p) ;Not continuation line.
5126 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5127 ;; Nothing in this page.
5128 (if (or (not gnus-page-broken)
5133 (eobp)))) ;Real end-of-buffer?
5135 (when gnus-article-over-scroll
5136 (gnus-article-next-page-1 lines))
5138 (gnus-narrow-to-page 1) ;Go to next page.
5140 ;; More in this page.
5141 (gnus-article-next-page-1 lines)
5144 (defun gnus-article-next-page-1 (lines)
5145 (let ((scroll-in-place nil))
5149 ;; Long lines may cause an end-of-buffer error.
5150 (goto-char (point-max)))))
5151 (move-to-window-line 0))
5153 (defun gnus-article-prev-page (&optional lines)
5154 "Show previous page of current article.
5155 Argument LINES specifies lines to be scrolled down."
5157 (move-to-window-line 0)
5158 (if (and gnus-page-broken
5160 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5162 (gnus-narrow-to-page -1) ;Go to previous page.
5163 (goto-char (point-max))
5165 (let ((scroll-in-place nil))
5169 (beginning-of-buffer
5170 (goto-char (point-min))))
5171 (move-to-window-line 0)))))
5173 (defun gnus-article-only-boring-p ()
5174 "Decide whether there is only boring text remaining in the article.
5175 Something \"interesting\" is a word of at least two letters that does
5176 not have a face in `gnus-article-boring-faces'."
5177 (when (and gnus-article-skip-boring
5178 (boundp 'gnus-article-boring-faces)
5179 (symbol-value 'gnus-article-boring-faces))
5182 (while (re-search-forward "\\b\\w\\w" nil t)
5184 (when (not (gnus-intersection
5185 (gnus-faces-at (point))
5186 (symbol-value 'gnus-article-boring-faces)))
5187 (throw 'only-boring nil)))
5188 (throw 'only-boring t)))))
5190 (defun gnus-article-refer-article ()
5191 "Read article specified by message-id around point."
5194 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5195 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5196 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5197 (let ((msg-id (concat "<" (match-string 0) ">")))
5198 (set-buffer gnus-summary-buffer)
5199 (gnus-summary-refer-article msg-id))
5200 (error "No references around point"))))
5202 (defun gnus-article-show-summary ()
5203 "Reconfigure windows to show summary buffer."
5205 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5206 (error "There is no summary buffer for this article buffer")
5207 (gnus-article-set-globals)
5208 (gnus-configure-windows 'article)
5209 (gnus-summary-goto-subject gnus-current-article)
5210 (gnus-summary-position-point)))
5212 (defun gnus-article-describe-briefly ()
5213 "Describe article mode commands briefly."
5215 (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")))
5217 (defun gnus-article-summary-command ()
5218 "Execute the last keystroke in the summary buffer."
5220 (let ((obuf (current-buffer))
5221 (owin (current-window-configuration))
5223 (switch-to-buffer gnus-article-current-summary 'norecord)
5224 (setq func (lookup-key (current-local-map) (this-command-keys)))
5225 (call-interactively func)
5227 (set-window-configuration owin)
5228 (set-window-point (get-buffer-window (current-buffer)) (point))))
5230 (defun gnus-article-summary-command-nosave ()
5231 "Execute the last keystroke in the summary buffer."
5234 (pop-to-buffer gnus-article-current-summary 'norecord)
5235 (setq func (lookup-key (current-local-map) (this-command-keys)))
5236 (call-interactively func)))
5238 (defun gnus-article-check-buffer ()
5239 "Beep if not in an article buffer."
5240 (unless (equal major-mode 'gnus-article-mode)
5241 (error "Command invoked outside of a Gnus article buffer")))
5243 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5244 "Read a summary buffer key sequence and execute it from the article buffer."
5246 (gnus-article-check-buffer)
5248 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5249 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5250 "=" "^" "\M-^" "|"))
5256 '("n" "Gn" "p" "Gp"))
5259 (set-buffer gnus-article-current-summary)
5260 (let (gnus-pick-mode)
5261 (push (or key last-command-event) unread-command-events)
5262 (setq keys (if (featurep 'xemacs)
5263 (events-to-keys (read-key-sequence nil))
5264 (read-key-sequence nil)))))
5268 (if (or (member keys nosaves)
5269 (member keys nosave-but-article)
5270 (member keys nosave-in-article))
5272 (save-window-excursion
5273 (pop-to-buffer gnus-article-current-summary 'norecord)
5274 ;; We disable the pick minor mode commands.
5275 (let (gnus-pick-mode)
5276 (setq func (lookup-key (current-local-map) keys))))
5280 (unless (member keys nosave-in-article)
5281 (set-buffer gnus-article-current-summary))
5282 (call-interactively func)
5283 (setq new-sum-point (point)))
5284 (when (member keys nosave-but-article)
5285 (pop-to-buffer gnus-article-buffer 'norecord)))
5286 ;; These commands should restore window configuration.
5287 (let ((obuf (current-buffer))
5288 (owin (current-window-configuration))
5290 win func in-buffer selected new-sum-start new-sum-hscroll)
5291 (cond (not-restore-window
5292 (pop-to-buffer gnus-article-current-summary 'norecord))
5293 ((setq win (get-buffer-window gnus-article-current-summary))
5294 (select-window win))
5296 (switch-to-buffer gnus-article-current-summary 'norecord)))
5297 (setq in-buffer (current-buffer))
5298 ;; We disable the pick minor mode commands.
5299 (if (and (setq func (let (gnus-pick-mode)
5300 (lookup-key (current-local-map) keys)))
5303 (call-interactively func)
5304 (when (eq win (selected-window))
5305 (setq new-sum-point (point)
5306 new-sum-start (window-start win)
5307 new-sum-hscroll (window-hscroll win))
5308 (when (eq in-buffer (current-buffer))
5309 (setq selected (gnus-summary-select-article))
5311 (unless not-restore-window
5312 (set-window-configuration owin))
5313 (when (eq selected 'old)
5315 (set-window-start (get-buffer-window (current-buffer))
5317 (set-window-point (get-buffer-window (current-buffer))
5319 (when (and (not not-restore-window)
5321 (set-window-point win new-sum-point)
5322 (set-window-start win new-sum-start)
5323 (set-window-hscroll win new-sum-hscroll)))))
5324 (set-window-configuration owin)
5327 (defun gnus-article-describe-key (key)
5328 "Display documentation of the function invoked by KEY. KEY is a string."
5329 (interactive "kDescribe key: ")
5330 (gnus-article-check-buffer)
5331 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5333 (set-buffer gnus-article-current-summary)
5334 (let (gnus-pick-mode)
5335 (if (featurep 'xemacs)
5337 (push (elt key 0) unread-command-events)
5338 (setq key (events-to-keys
5339 (read-key-sequence "Describe key: "))))
5340 (setq unread-command-events
5342 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5343 (string-to-list key)))
5344 (setq key (read-key-sequence "Describe key: "))))
5346 (describe-key key)))
5348 (defun gnus-article-describe-key-briefly (key &optional insert)
5349 "Display documentation of the function invoked by KEY. KEY is a string."
5350 (interactive "kDescribe key: \nP")
5351 (gnus-article-check-buffer)
5352 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5354 (set-buffer gnus-article-current-summary)
5355 (let (gnus-pick-mode)
5356 (if (featurep 'xemacs)
5358 (push (elt key 0) unread-command-events)
5359 (setq key (events-to-keys
5360 (read-key-sequence "Describe key: "))))
5361 (setq unread-command-events
5363 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5364 (string-to-list key)))
5365 (setq key (read-key-sequence "Describe key: "))))
5366 (describe-key-briefly key insert))
5367 (describe-key-briefly key insert)))
5369 (defun gnus-article-reply-with-original (&optional wide)
5370 "Start composing a reply mail to the current message.
5371 The text in the region will be yanked. If the region isn't active,
5372 the entire article will be yanked."
5374 (let ((article (cdr gnus-article-current))
5376 (if (not (gnus-region-active-p))
5377 (with-current-buffer gnus-summary-buffer
5378 (gnus-summary-reply (list (list article)) wide))
5379 (setq contents (buffer-substring (point) (mark t)))
5380 ;; Deactivate active regions.
5381 (when (and (boundp 'transient-mark-mode)
5382 transient-mark-mode)
5383 (setq mark-active nil))
5384 (with-current-buffer gnus-summary-buffer
5386 (list (list article contents)) wide)))))
5388 (defun gnus-article-followup-with-original ()
5389 "Compose a followup to the current article.
5390 The text in the region will be yanked. If the region isn't active,
5391 the entire article will be yanked."
5393 (let ((article (cdr gnus-article-current))
5395 (if (not (gnus-region-active-p))
5396 (with-current-buffer gnus-summary-buffer
5397 (gnus-summary-followup (list (list article))))
5398 (setq contents (buffer-substring (point) (mark t)))
5399 ;; Deactivate active regions.
5400 (when (and (boundp 'transient-mark-mode)
5401 transient-mark-mode)
5402 (setq mark-active nil))
5403 (with-current-buffer gnus-summary-buffer
5404 (gnus-summary-followup
5405 (list (list article contents)))))))
5407 (defun gnus-article-hide (&optional arg force)
5408 "Hide all the gruft in the current article.
5409 This means that signatures, cited text and (some) headers will be
5411 If given a prefix, show the hidden text instead."
5412 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5413 (gnus-article-hide-headers arg)
5414 (gnus-article-hide-list-identifiers arg)
5415 (gnus-article-hide-citation-maybe arg force)
5416 (gnus-article-hide-signature arg))
5418 (defun gnus-article-maybe-highlight ()
5419 "Do some article highlighting if article highlighting is requested."
5420 (when (gnus-visual-p 'article-highlight 'highlight)
5421 (gnus-article-highlight-some)))
5423 (defun gnus-check-group-server ()
5424 ;; Make sure the connection to the server is alive.
5425 (unless (gnus-server-opened
5426 (gnus-find-method-for-group gnus-newsgroup-name))
5427 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5428 (gnus-request-group gnus-newsgroup-name t)))
5431 (autoload 'nneething-get-file-name "nneething"))
5433 (defun gnus-request-article-this-buffer (article group)
5434 "Get an article and insert it into this buffer."
5435 (let (do-update-line sparse-header)
5439 (gnus-kill-all-overlays)
5440 (setq group (or group gnus-newsgroup-name))
5442 ;; Using `gnus-request-article' directly will insert the article into
5443 ;; `nntp-server-buffer' - so we'll save some time by not having to
5444 ;; copy it from the server buffer into the article buffer.
5446 ;; We only request an article by message-id when we do not have the
5447 ;; headers for it, so we'll have to get those.
5448 (when (stringp article)
5449 (gnus-read-header article))
5451 ;; If the article number is negative, that means that this article
5452 ;; doesn't belong in this newsgroup (possibly), so we find its
5453 ;; message-id and request it by id instead of number.
5454 (when (and (numberp article)
5456 (get-buffer gnus-summary-buffer)
5457 (gnus-buffer-exists-p gnus-summary-buffer))
5459 (set-buffer gnus-summary-buffer)
5460 (let ((header (gnus-summary-article-header article)))
5463 ((memq article gnus-newsgroup-sparse)
5464 ;; This is a sparse gap article.
5465 (setq do-update-line article)
5466 (setq article (mail-header-id header))
5467 (setq sparse-header (gnus-read-header article))
5468 (setq gnus-newsgroup-sparse
5469 (delq article gnus-newsgroup-sparse)))
5471 ;; It's a real article.
5472 (setq article (mail-header-id header)))
5474 ;; It is an extracted pseudo-article.
5475 (setq article 'pseudo)
5476 (gnus-request-pseudo-article header))))
5478 (let ((method (gnus-find-method-for-group
5479 gnus-newsgroup-name)))
5480 (when (and (eq (car method) 'nneething)
5482 (let ((dir (nneething-get-file-name
5483 (mail-header-id header))))
5484 (when (and (stringp dir)
5485 (file-directory-p dir))
5486 (setq article 'nneething)
5487 (gnus-group-enter-directory dir))))))))
5490 ;; Refuse to select canceled articles.
5491 ((and (numberp article)
5493 (get-buffer gnus-summary-buffer)
5494 (gnus-buffer-exists-p gnus-summary-buffer)
5495 (eq (cdr (with-current-buffer gnus-summary-buffer
5496 (assq article gnus-newsgroup-reads)))
5497 gnus-canceled-mark))
5499 ;; We first check `gnus-original-article-buffer'.
5500 ((and (get-buffer gnus-original-article-buffer)
5502 (with-current-buffer gnus-original-article-buffer
5503 (and (equal (car gnus-original-article) group)
5504 (eq (cdr gnus-original-article) article))))
5505 (insert-buffer-substring gnus-original-article-buffer)
5507 ;; Check the backlog.
5508 ((and gnus-keep-backlog
5509 (gnus-backlog-request-article group article (current-buffer)))
5511 ;; Check asynchronous pre-fetch.
5512 ((gnus-async-request-fetched-article group article (current-buffer))
5513 (gnus-async-prefetch-next group article gnus-summary-buffer)
5514 (when (and (numberp article) gnus-keep-backlog)
5515 (gnus-backlog-enter-article group article (current-buffer)))
5518 ((and gnus-use-cache
5520 (gnus-cache-request-article article group))
5522 ;; Check the agent cache.
5523 ((gnus-agent-request-article article group)
5525 ;; Get the article and put into the article buffer.
5526 ((or (stringp article)
5528 (let ((gnus-override-method gnus-override-method)
5529 (methods (and (stringp article)
5530 gnus-refer-article-method))
5531 (backend (car (gnus-find-method-for-group
5532 gnus-newsgroup-name)))
5534 (inhibit-read-only t))
5535 (if (or (not (listp methods))
5536 (and (symbolp (car methods))
5537 (assq (car methods) nnoo-definition-alist)))
5538 (setq methods (list methods)))
5539 (when (and (null gnus-override-method)
5541 (setq gnus-override-method (pop methods)))
5543 (when (eq gnus-override-method 'current)
5544 (setq gnus-override-method
5545 (with-current-buffer gnus-summary-buffer
5546 gnus-current-select-method)))
5548 (gnus-kill-all-overlays)
5549 (let ((gnus-newsgroup-name group))
5550 (gnus-check-group-server))
5552 ((gnus-request-article article group (current-buffer))
5553 (when (numberp article)
5554 (gnus-async-prefetch-next group article
5555 gnus-summary-buffer)
5556 (when gnus-keep-backlog
5557 (gnus-backlog-enter-article
5558 group article (current-buffer))))
5559 (setq result 'article))
5561 (setq gnus-override-method (pop methods)))
5562 ((not (string-match "^400 "
5563 (nnheader-get-report backend)))
5564 ;; If we get 400 server disconnect, reconnect and
5565 ;; retry; otherwise, assume the article has expired.
5566 (setq result 'done))))
5567 (and (eq result 'article) 'article)))
5571 ;; Associate this article with the current summary buffer.
5572 (setq gnus-article-current-summary gnus-summary-buffer)
5574 ;; Take the article from the original article buffer
5575 ;; and place it in the buffer it's supposed to be in.
5576 (when (and (get-buffer gnus-article-buffer)
5577 (equal (buffer-name (current-buffer))
5578 (buffer-name (get-buffer gnus-article-buffer))))
5580 (if (get-buffer gnus-original-article-buffer)
5581 (set-buffer gnus-original-article-buffer)
5582 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5583 (buffer-disable-undo)
5584 (setq major-mode 'gnus-original-article-mode)
5585 (setq buffer-read-only t))
5586 (let ((inhibit-read-only t))
5588 (insert-buffer-substring gnus-article-buffer))
5589 (setq gnus-original-article (cons group article)))
5592 (run-hooks 'gnus-article-decode-hook)
5593 ;; Mark article as decoded or not.
5594 (setq gnus-article-decoded-p gnus-article-decode-hook))
5596 ;; Update sparse articles.
5597 (when (and do-update-line
5598 (or (numberp article)
5600 (let ((buf (current-buffer)))
5601 (set-buffer gnus-summary-buffer)
5602 (gnus-summary-update-article do-update-line sparse-header)
5603 (gnus-summary-goto-subject do-update-line nil t)
5604 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5606 (set-buffer buf))))))
5612 (defcustom gnus-article-edit-mode-hook nil
5613 "Hook run in article edit mode buffers."
5614 :group 'gnus-article-various
5617 (defvar gnus-article-edit-done-function nil)
5619 (defvar gnus-article-edit-mode-map nil)
5621 ;; Should we be using derived.el for this?
5622 (unless gnus-article-edit-mode-map
5623 (setq gnus-article-edit-mode-map (make-keymap))
5624 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5626 (gnus-define-keys gnus-article-edit-mode-map
5627 "\C-c?" describe-mode
5628 "\C-c\C-c" gnus-article-edit-done
5629 "\C-c\C-k" gnus-article-edit-exit
5630 "\C-c\C-f\C-t" message-goto-to
5631 "\C-c\C-f\C-o" message-goto-from
5632 "\C-c\C-f\C-b" message-goto-bcc
5633 ;;"\C-c\C-f\C-w" message-goto-fcc
5634 "\C-c\C-f\C-c" message-goto-cc
5635 "\C-c\C-f\C-s" message-goto-subject
5636 "\C-c\C-f\C-r" message-goto-reply-to
5637 "\C-c\C-f\C-n" message-goto-newsgroups
5638 "\C-c\C-f\C-d" message-goto-distribution
5639 "\C-c\C-f\C-f" message-goto-followup-to
5640 "\C-c\C-f\C-m" message-goto-mail-followup-to
5641 "\C-c\C-f\C-k" message-goto-keywords
5642 "\C-c\C-f\C-u" message-goto-summary
5643 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5644 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5645 "\C-c\C-b" message-goto-body
5646 "\C-c\C-i" message-goto-signature
5648 "\C-c\C-t" message-insert-to
5649 "\C-c\C-n" message-insert-newsgroups
5650 "\C-c\C-o" message-sort-headers
5651 "\C-c\C-e" message-elide-region
5652 "\C-c\C-v" message-delete-not-region
5653 "\C-c\C-z" message-kill-to-signature
5654 "\M-\r" message-newline-and-reformat
5655 "\C-c\C-a" mml-attach-file
5656 "\C-a" message-beginning-of-line
5658 "\M-;" comment-region)
5660 (gnus-define-keys (gnus-article-edit-wash-map
5661 "\C-c\C-w" gnus-article-edit-mode-map)
5662 "f" gnus-article-edit-full-stops))
5665 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5667 ["Fetch To" message-insert-to t]
5668 ["Fetch Newsgroups" message-insert-newsgroups t]
5670 ["To" message-goto-to t]
5671 ["From" message-goto-from t]
5672 ["Subject" message-goto-subject t]
5673 ["Cc" message-goto-cc t]
5674 ["Reply-To" message-goto-reply-to t]
5675 ["Summary" message-goto-summary t]
5676 ["Keywords" message-goto-keywords t]
5677 ["Newsgroups" message-goto-newsgroups t]
5678 ["Followup-To" message-goto-followup-to t]
5679 ["Mail-Followup-To" message-goto-mail-followup-to t]
5680 ["Distribution" message-goto-distribution t]
5681 ["Body" message-goto-body t]
5682 ["Signature" message-goto-signature t]))
5684 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5685 "Major mode for editing articles.
5686 This is an extended text-mode.
5688 \\{gnus-article-edit-mode-map}"
5689 (make-local-variable 'gnus-article-edit-done-function)
5690 (make-local-variable 'gnus-prev-winconf)
5691 (set (make-local-variable 'font-lock-defaults)
5692 '(message-font-lock-keywords t))
5693 (set (make-local-variable 'mail-header-separator) "")
5694 (set (make-local-variable 'gnus-article-edit-mode) t)
5695 (easy-menu-add message-mode-field-menu message-mode-map)
5697 (setq buffer-read-only nil)
5698 (buffer-enable-undo)
5701 (defun gnus-article-edit (&optional force)
5702 "Edit the current article.
5703 This will have permanent effect only in mail groups.
5704 If FORCE is non-nil, allow editing of articles even in read-only
5707 (when (and (not force)
5708 (gnus-group-read-only-p))
5709 (error "The current newsgroup does not support article editing"))
5710 (gnus-article-date-original)
5711 (gnus-article-edit-article
5713 `(lambda (no-highlight)
5715 (gnus-summary-edit-article-done
5716 ,(or (mail-header-references gnus-current-headers) "")
5717 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5719 (defun gnus-article-edit-article (start-func exit-func)
5720 "Start editing the contents of the current article buffer."
5721 (let ((winconf (current-window-configuration)))
5722 (set-buffer gnus-article-buffer)
5723 (let ((message-auto-save-directory
5724 ;; Don't associate the article buffer with a draft file.
5726 (gnus-article-edit-mode))
5727 (funcall start-func)
5728 (set-buffer-modified-p nil)
5729 (gnus-configure-windows 'edit-article)
5730 (setq gnus-article-edit-done-function exit-func)
5731 (setq gnus-prev-winconf winconf)
5732 (gnus-message 6 "C-c C-c to end edits")))
5734 (defun gnus-article-edit-done (&optional arg)
5735 "Update the article edits and exit."
5737 (let ((func gnus-article-edit-done-function)
5738 (buf (current-buffer))
5739 (start (window-start))
5741 (winconf gnus-prev-winconf))
5742 (widen) ;; Widen it in case that users narrowed the buffer.
5745 ;; The cache and backlog have to be flushed somewhat.
5746 (when gnus-keep-backlog
5747 (gnus-backlog-remove-article
5748 (car gnus-article-current) (cdr gnus-article-current)))
5749 ;; Flush original article as well.
5751 (when (get-buffer gnus-original-article-buffer)
5752 (set-buffer gnus-original-article-buffer)
5753 (setq gnus-original-article nil)))
5754 (when gnus-use-cache
5755 (gnus-cache-update-article
5756 (car gnus-article-current) (cdr gnus-article-current)))
5757 ;; We remove all text props from the article buffer.
5758 (kill-all-local-variables)
5759 (set-text-properties (point-min) (point-max) nil)
5761 (set-window-configuration winconf)
5763 (set-window-start (get-buffer-window buf) start)
5764 (set-window-point (get-buffer-window buf) (point)))
5765 (gnus-summary-show-article))
5767 (defun gnus-article-edit-exit ()
5768 "Exit the article editing without updating."
5770 (when (or (not (buffer-modified-p))
5771 (yes-or-no-p "Article modified; kill anyway? "))
5772 (let ((curbuf (current-buffer))
5774 (window-start (window-start)))
5776 (if (gnus-buffer-live-p gnus-original-article-buffer)
5777 (insert-buffer gnus-original-article-buffer))
5778 (let ((winconf gnus-prev-winconf))
5779 (kill-all-local-variables)
5781 (set-window-configuration winconf)
5782 ;; Tippy-toe some to make sure that point remains where it was.
5783 (save-current-buffer
5785 (set-window-start (get-buffer-window (current-buffer)) window-start)
5787 (gnus-summary-show-article)))
5789 (defun gnus-article-edit-full-stops ()
5790 "Interactively repair spacing at end of sentences."
5793 (goto-char (point-min))
5794 (search-forward-regexp "^$" nil t)
5795 (let ((case-fold-search nil))
5796 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5799 ;;; Article highlights
5802 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5804 ;;; Internal Variables:
5806 (defcustom gnus-button-url-regexp
5807 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5808 "\\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:]]\\)"
5809 "\\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\\)\\)")
5810 "Regular expression that matches URLs."
5811 :group 'gnus-article-buttons
5814 (defcustom gnus-button-valid-fqdn-regexp
5815 message-valid-fqdn-regexp
5816 "Regular expression that matches a valid FQDN."
5818 :group 'gnus-article-buttons
5821 (defcustom gnus-button-man-handler 'manual-entry
5822 "Function to use for displaying man pages.
5823 The function must take at least one argument with a string naming the
5826 :type '(choice (function-item :tag "Man" manual-entry)
5827 (function-item :tag "Woman" woman)
5828 (function :tag "Other"))
5829 :group 'gnus-article-buttons)
5831 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5832 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5833 If the default site is too slow, try to find a CTAN mirror, see
5834 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
5835 the variable `gnus-button-handle-ctan'."
5837 :group 'gnus-article-buttons
5838 :link '(custom-manual "(gnus)Group Parameters")
5839 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5840 (const "http://tug.ctan.org/tex-archive/")
5841 (const "http://www.dante.de/CTAN/")
5842 (string :tag "Other")))
5844 (defcustom gnus-button-ctan-handler 'browse-url
5845 "Function to use for displaying CTAN links.
5846 The function must take one argument, the string naming the URL."
5848 :type '(choice (function-item :tag "Browse Url" browse-url)
5849 (function :tag "Other"))
5850 :group 'gnus-article-buttons)
5852 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5853 "Bogus strings removed from CTAN URLs."
5855 :group 'gnus-article-buttons
5856 :type '(choice (const "^/?tex-archive/\\|/")
5857 (regexp :tag "Other")))
5859 (defcustom gnus-button-ctan-directory-regexp
5862 "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
5863 "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
5864 "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
5866 "Regular expression for ctan directories.
5867 It should match all directories in the top level of `gnus-ctan-url'."
5869 :group 'gnus-article-buttons
5872 (defcustom gnus-button-mid-or-mail-regexp
5873 (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
5874 ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
5875 gnus-button-valid-fqdn-regexp
5877 "Regular expression that matches a message ID or a mail address."
5879 :group 'gnus-article-buttons
5882 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5883 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5884 Strings like this can be either a message ID or a mail address. If it is one
5885 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5886 message ID or a mail address, respectively. If this variable is set to the
5887 symbol `ask', always query the user what do do. If it is a function, this
5888 function will be called with the string as it's only argument. The function
5889 must return `mid', `mail', `invalid' or `ask'."
5891 :group 'gnus-article-buttons
5892 :type '(choice (function-item :tag "Heuristic function"
5893 gnus-button-mid-or-mail-heuristic)
5898 (defcustom gnus-button-mid-or-mail-heuristic-alist
5899 '((-10.0 . ".+\\$.+@")
5902 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
5903 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5904 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5905 (-1.0 . "^[^a-z]+@")
5907 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5908 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5909 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
5910 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5913 (-1.0 . "^[0-9][0-9]")
5915 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5916 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5917 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5918 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5920 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5921 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5924 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5926 ;; compensation for TDMA dated mail addresses:
5927 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5929 (-20.0 . "\\.fsf@") ;; Gnus
5932 (-20.0 . "_-_") ;; Subject change in thread
5934 (-20.0 . "\\.ln@") ;; leafnode
5935 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5936 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5938 ;; (5.0 . "") ;; $local_part_len <= 7
5939 (10.0 . "^[^0-9]+@")
5940 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5941 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5944 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
5946 (0.5 . "^[A-Z][a-z]")
5947 (0.5 . "^[A-Z][a-z][a-z]")
5948 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5949 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5950 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5952 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5953 address. The REGEXP is processed with `case-fold-search' set to nil."
5955 :group 'gnus-article-buttons
5956 :type '(repeat (cons (number :tag "Rate")
5957 (regexp :tag "Regexp"))))
5959 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5960 "Guess whether MID-OR-MAIL is a message ID or a mail address.
5961 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5962 address, `ask' if unsure and `invalid' if the string is invalid."
5963 (let ((case-fold-search nil)
5964 (list gnus-button-mid-or-mail-heuristic-alist)
5965 (result 0) rate regexp lpartlen elem)
5967 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5968 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5969 ;; Certain special cases...
5972 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
5973 "^[0-9]+\\.[0-9]+@compuserve\\|"
5974 "@public\\.gmane\\.org")
5976 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
5977 (setq result 'mail))
5978 (when (string-match "@.*@\\| " mid-or-mail)
5979 (gnus-message 8 "`%s' is invalid." mid-or-mail)
5980 (setq result 'invalid))
5981 ;; Nothing more to do, if result is not a number here...
5982 (when (numberp result)
5984 (setq elem (car list)
5988 (when (string-match regexp mid-or-mail)
5989 (setq result (+ result rate))
5991 9 "`%s' matched `%s', rate `%s', result `%s'."
5992 mid-or-mail regexp rate result)))
5993 (when (<= lpartlen 7)
5994 (setq result (+ result 5.0))
5995 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
5996 mid-or-mail result))
5997 (when (>= lpartlen 12)
5998 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6000 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6001 ;; Long local part should contain realname if e-mail address,
6002 ;; too many digits: message-id.
6003 ;; $score -= 5.0 + 0.1 * $local_part_len;
6004 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6005 (setq result (+ result rate))
6007 9 "Many digits in `%s', rate `%s', result `%s'."
6008 mid-or-mail rate result))
6009 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6011 ;; Too few vowels [^aeiouy]{4,}.*\@
6012 (setq result (+ result -5.0))
6014 9 "Few vowels in `%s', rate `%s', result `%s'."
6015 mid-or-mail -5.0 result))
6017 (setq result (+ result 5.0))
6019 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6020 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6021 ;; Maybe we should make this a customizable alist: (condition . 'result)
6023 ((symbolp result) result)
6024 ;; Now convert number into proper results:
6025 ((< result -10.0) 'mid)
6026 ((> result 10.0) 'mail)
6029 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6030 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6031 (url-mid (concat "news" ":" mid-or-mail))
6032 (url-mailto (concat "mailto" ":" mid-or-mail)))
6033 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6034 (when (fboundp pref)
6036 ;; get rid of surrounding angles...
6038 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6039 (if (or (eq 'mid guessed) (eq 'mail guessed))
6043 (save-window-excursion
6044 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6047 (cond ((eq pref 'mid)
6048 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6049 (gnus-button-handle-news url-mid))
6051 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6052 (gnus-url-mailto url-mailto))
6053 (t (gnus-message 3 "Invalid string.")))))
6055 (defun gnus-button-handle-custom (url)
6056 "Follow a Custom URL."
6057 (customize-apropos (gnus-url-unhex-string url)))
6059 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6061 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6064 (defun gnus-button-handle-describe-function (url)
6065 "Call `describe-function' when pushing the corresponding URL button."
6068 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6070 (defun gnus-button-handle-describe-variable (url)
6071 "Call `describe-variable' when pushing the corresponding URL button."
6074 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6076 (defun gnus-button-handle-symbol (url)
6077 "Display help on variable or function.
6078 Calls `describe-variable' or `describe-function'."
6079 (let ((sym (intern url)))
6081 ((fboundp sym) (describe-function sym))
6082 ((boundp sym) (describe-variable sym))
6083 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6085 (defun gnus-button-handle-describe-key (url)
6086 "Call `describe-key' when pushing the corresponding URL button."
6088 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6089 (keys (ignore-errors (eval `(kbd ,key-string)))))
6092 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6094 (defun gnus-button-handle-apropos (url)
6095 "Call `apropos' when pushing the corresponding URL button."
6096 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6098 (defun gnus-button-handle-apropos-command (url)
6099 "Call `apropos' when pushing the corresponding URL button."
6101 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6103 (defun gnus-button-handle-apropos-variable (url)
6104 "Call `apropos' when pushing the corresponding URL button."
6106 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6107 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6109 (defun gnus-button-handle-apropos-documentation (url)
6110 "Call `apropos' when pushing the corresponding URL button."
6112 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6113 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6115 (defun gnus-button-handle-library (url)
6116 "Call `locate-library' when pushing the corresponding URL button."
6117 (gnus-message 9 "url=`%s'" url)
6118 (let* ((lib (locate-library url))
6119 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6121 (gnus-message 1 "Cannot locale library `%s'." url)
6122 (find-file-read-only file))))
6124 (defun gnus-button-handle-ctan (url)
6125 "Call `browse-url' when pushing a CTAN URL button."
6127 gnus-button-ctan-handler
6130 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6132 (defcustom gnus-button-tex-level 5
6133 "*Integer that says how many TeX-related buttons Gnus will show.
6134 The higher the number, the more buttons will appear and the more false
6135 positives are possible. Note that you can set this variable local to
6136 specific groups. Setting it higher in TeX groups is probably a good idea.
6137 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6138 how to set variables in specific groups."
6140 :group 'gnus-article-buttons
6141 :link '(custom-manual "(gnus)Group Parameters")
6144 (defcustom gnus-button-man-level 5
6145 "*Integer that says how many man-related buttons Gnus will show.
6146 The higher the number, the more buttons will appear and the more false
6147 positives are possible. Note that you can set this variable local to
6148 specific groups. Setting it higher in Unix groups is probably a good idea.
6149 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6150 how to set variables in specific groups."
6152 :group 'gnus-article-buttons
6153 :link '(custom-manual "(gnus)Group Parameters")
6156 (defcustom gnus-button-emacs-level 5
6157 "*Integer that says how many emacs-related buttons Gnus will show.
6158 The higher the number, the more buttons will appear and the more false
6159 positives are possible. Note that you can set this variable local to
6160 specific groups. Setting it higher in Emacs or Gnus related groups is
6161 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6162 `gnus-parameters' on how to set variables in specific groups."
6164 :group 'gnus-article-buttons
6165 :link '(custom-manual "(gnus)Group Parameters")
6168 (defcustom gnus-button-message-level 5
6169 "*Integer that says how many buttons for news or mail messages will appear.
6170 The higher the number, the more buttons will appear and the more false
6171 positives are possible."
6172 ;; mail addresses, MIDs, URLs for news, ...
6174 :group 'gnus-article-buttons
6177 (defcustom gnus-button-browse-level 5
6178 "*Integer that says how many buttons for browsing will appear.
6179 The higher the number, the more buttons will appear and the more false
6180 positives are possible."
6181 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6183 :group 'gnus-article-buttons
6186 (defcustom gnus-button-alist
6187 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6188 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6189 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6190 gnus-button-handle-news 2)
6191 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6192 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6193 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6194 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6195 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6196 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6197 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6198 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6199 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6200 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6201 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6202 ;; RFC 2368 (The mailto URL scheme)
6203 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6204 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6205 ("\\bmailto:\\([^ \n\t]+\\)"
6206 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6208 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6209 gnus-button-ctan-directory-regexp
6210 "[^][>)!;:,'\n\t ]+\\)")
6211 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6212 ((concat "\\btex-archive/\\("
6213 gnus-button-ctan-directory-regexp
6214 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6215 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6218 gnus-button-ctan-directory-regexp
6219 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6220 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6221 ;; This is info (home-grown style) <info://foo/bar+baz>
6222 ("\\binfo://\\([^'\">\n\t ]+\\)"
6223 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6224 ;; Info GNOME style <info:foo#bar_baz>
6225 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6226 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6227 ;; Info KDE style <info:(foo)bar baz>
6228 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6229 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6230 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6231 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6232 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6233 ;; Info links like `C-h i d m CC Mode RET'
6234 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6236 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6237 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6238 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6239 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6240 ;; Emacs help commands
6241 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6242 ;; regexp doesn't match arguments containing ` '.
6243 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6244 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6245 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6246 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6247 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6248 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6249 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6250 ;; The following entries may lead to many false positives so don't enable
6251 ;; them by default (use a high button level).
6252 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6253 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6254 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6255 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6256 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6257 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6258 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6259 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6260 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6261 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6262 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6263 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6264 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6265 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6266 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6267 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6268 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6269 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6270 ;; Unlike the other regexps we really have to require quoting
6271 ;; here to determine where it ends.
6272 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6273 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6274 ("<URL: *\\([^<>]*\\)>"
6275 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6276 ;; RFC 2396 (2.4.3., delims) ...
6277 ("\"URL: *\\([^\"]*\\)\""
6278 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6279 ;; RFC 2396 (2.4.3., delims) ...
6280 ("\"URL: *\\([^\"]*\\)\""
6281 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6283 (gnus-button-url-regexp
6284 0 (>= gnus-button-browse-level 0) browse-url 0)
6286 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6287 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6288 gnus-button-handle-man 1)
6289 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6290 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6291 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6292 gnus-button-handle-man 1)
6293 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6294 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6295 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6296 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6297 ;; MID or mail: To avoid too many false positives we don't try to catch
6298 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6299 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6300 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6301 ;; so that non-ambiguous entries (see above) match first.
6302 (gnus-button-mid-or-mail-regexp
6303 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6304 "*Alist of regexps matching buttons in article bodies.
6306 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6307 REGEXP: is the string (case insensitive) matching text around the button (can
6308 also be Lisp expression evaluating to a string),
6309 BUTTON: is the number of the regexp grouping actually matching the button,
6310 FORM: is a Lisp expression which must eval to true for the button to
6312 CALLBACK: is the function to call when the user push this button, and each
6313 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6315 CALLBACK can also be a variable, in that case the value of that
6316 variable it the real callback function."
6317 :group 'gnus-article-buttons
6318 :type '(repeat (list (choice regexp variable sexp)
6319 (integer :tag "Button")
6321 (function :tag "Callback")
6324 (integer :tag "Regexp group")))))
6326 (defcustom gnus-header-button-alist
6327 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6328 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6329 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6330 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6331 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6332 0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6333 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6334 0 (>= gnus-button-browse-level 0) browse-url 0)
6335 ("^Subject:" gnus-button-url-regexp
6336 0 (>= gnus-button-browse-level 0) browse-url 0)
6337 ("^[^:]+:" gnus-button-url-regexp
6338 0 (>= gnus-button-browse-level 0) browse-url 0)
6339 ("^OpenPGP:.*url=" gnus-button-url-regexp
6340 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
6341 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6342 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6343 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6344 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6345 "*Alist of headers and regexps to match buttons in article heads.
6347 This alist is very similar to `gnus-button-alist', except that each
6348 alist has an additional HEADER element first in each entry:
6350 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6352 HEADER is a regexp to match a header. For a fuller explanation, see
6353 `gnus-button-alist'."
6354 :group 'gnus-article-buttons
6355 :group 'gnus-article-headers
6356 :type '(repeat (list (regexp :tag "Header")
6357 (choice regexp variable)
6358 (integer :tag "Button")
6360 (function :tag "Callback")
6363 (integer :tag "Regexp group")))))
6367 (defun gnus-article-push-button (event)
6368 "Check text under the mouse pointer for a callback function.
6369 If the text under the mouse pointer has a `gnus-callback' property,
6370 call it with the value of the `gnus-data' text property."
6372 (set-buffer (window-buffer (posn-window (event-start event))))
6373 (let* ((pos (posn-point (event-start event)))
6374 (data (get-text-property pos 'gnus-data))
6375 (fun (get-text-property pos 'gnus-callback)))
6378 (funcall fun data))))
6380 (defun gnus-article-press-button ()
6381 "Check text at point for a callback function.
6382 If the text at point has a `gnus-callback' property,
6383 call it with the value of the `gnus-data' text property."
6385 (let ((data (get-text-property (point) 'gnus-data))
6386 (fun (get-text-property (point) 'gnus-callback)))
6388 (funcall fun data))))
6390 (defun gnus-article-highlight (&optional force)
6391 "Highlight current article.
6392 This function calls `gnus-article-highlight-headers',
6393 `gnus-article-highlight-citation',
6394 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6395 do the highlighting. See the documentation for those functions."
6396 (interactive (list 'force))
6397 (gnus-article-highlight-headers)
6398 (gnus-article-highlight-citation force)
6399 (gnus-article-highlight-signature)
6400 (gnus-article-add-buttons force)
6401 (gnus-article-add-buttons-to-head))
6403 (defun gnus-article-highlight-some (&optional force)
6404 "Highlight current article.
6405 This function calls `gnus-article-highlight-headers',
6406 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6407 do the highlighting. See the documentation for those functions."
6408 (interactive (list 'force))
6409 (gnus-article-highlight-headers)
6410 (gnus-article-highlight-signature)
6411 (gnus-article-add-buttons))
6413 (defun gnus-article-highlight-headers ()
6414 "Highlight article headers as specified by `gnus-header-face-alist'."
6416 (gnus-with-article-headers
6417 (let (regexp header-face field-face from hpoints fpoints)
6418 (dolist (entry gnus-header-face-alist)
6419 (goto-char (point-min))
6420 (setq regexp (concat "^\\("
6421 (if (string-equal "" (nth 0 entry))
6425 header-face (nth 1 entry)
6426 field-face (nth 2 entry))
6427 (while (and (re-search-forward regexp nil t)
6431 (unless (search-forward ":" nil t)
6433 (when (and header-face
6434 (not (memq (point) hpoints)))
6435 (push (point) hpoints)
6436 (gnus-put-text-property from (point) 'face header-face))
6437 (when (and field-face
6438 (not (memq (setq from (point)) fpoints)))
6440 (if (re-search-forward "^[^ \t]" nil t)
6442 (goto-char (point-max)))
6443 (gnus-put-text-property from (point) 'face field-face)))))))
6445 (defun gnus-article-highlight-signature ()
6446 "Highlight the signature in an article.
6447 It does this by highlighting everything after
6448 `gnus-signature-separator' using `gnus-signature-face'."
6450 (gnus-with-article-buffer
6451 (let ((inhibit-point-motion-hooks t))
6453 (when (and gnus-signature-face
6454 (gnus-article-narrow-to-signature))
6455 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6456 'face gnus-signature-face)
6458 (gnus-article-search-signature)
6459 (let ((start (match-beginning 0))
6460 (end (set-marker (make-marker) (1+ (match-end 0)))))
6461 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6464 (defun gnus-button-in-region-p (b e prop)
6465 "Say whether PROP exists in the region."
6466 (text-property-not-all b e prop nil))
6468 (defun gnus-article-add-buttons (&optional force)
6469 "Find external references in the article and make buttons of them.
6470 \"External references\" are things like Message-IDs and URLs, as
6471 specified by `gnus-button-alist'."
6472 (interactive (list 'force))
6473 (gnus-with-article-buffer
6474 (let ((inhibit-point-motion-hooks t)
6475 (case-fold-search t)
6476 (alist gnus-button-alist)
6478 ;; Remove all old markers.
6479 (let (marker entry new-list)
6480 (while (setq marker (pop gnus-button-marker-list))
6481 (if (or (< marker (point-min)) (>= marker (point-max)))
6482 (push marker new-list)
6484 (when (setq entry (gnus-button-entry))
6485 (put-text-property (match-beginning (nth 1 entry))
6486 (match-end (nth 1 entry))
6487 'gnus-callback nil))
6488 (set-marker marker nil)))
6489 (setq gnus-button-marker-list new-list))
6490 ;; We skip the headers.
6493 (while (setq entry (pop alist))
6494 (setq regexp (eval (car entry)))
6496 (while (re-search-forward regexp nil t)
6497 (let* ((start (and entry (match-beginning (nth 1 entry))))
6498 (end (and entry (match-end (nth 1 entry))))
6499 (from (match-beginning 0)))
6500 (when (and (or (eq t (nth 2 entry))
6501 (eval (nth 2 entry)))
6502 (not (gnus-button-in-region-p
6503 start end 'gnus-callback)))
6504 ;; That optional form returned non-nil, so we add the
6506 (gnus-article-add-button
6507 start end 'gnus-button-push
6508 (car (push (set-marker (make-marker) from)
6509 gnus-button-marker-list))))))))))
6511 ;; Add buttons to the head of an article.
6512 (defun gnus-article-add-buttons-to-head ()
6513 "Add buttons to the head of the article."
6515 (gnus-with-article-headers
6517 (dolist (entry gnus-header-button-alist)
6518 ;; Each alist entry.
6519 (goto-char (point-min))
6520 (while (re-search-forward (car entry) nil t)
6521 ;; Each header matching the entry.
6522 (setq beg (match-beginning 0))
6523 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6524 (match-beginning 0))
6527 (while (re-search-forward (eval (nth 1 entry)) end t)
6528 ;; Each match within a header.
6529 (let* ((entry (cdr entry))
6530 (start (match-beginning (nth 1 entry)))
6531 (end (match-end (nth 1 entry)))
6532 (form (nth 2 entry)))
6533 (goto-char (match-end 0))
6535 (gnus-article-add-button
6536 start end (nth 3 entry)
6537 (buffer-substring (match-beginning (nth 4 entry))
6538 (match-end (nth 4 entry)))))))
6539 (goto-char end))))))
6541 ;;; External functions:
6543 (defun gnus-article-add-button (from to fun &optional data)
6544 "Create a button between FROM and TO with callback FUN and data DATA."
6545 (when gnus-article-button-face
6546 (gnus-overlay-put (gnus-make-overlay from to)
6547 'face gnus-article-button-face))
6548 (gnus-add-text-properties
6550 (nconc (and gnus-article-mouse-face
6551 (list gnus-mouse-face-prop gnus-article-mouse-face))
6552 (list 'gnus-callback fun)
6553 (and data (list 'gnus-data data))))
6554 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6555 :button-keymap gnus-widget-button-keymap))
6557 ;;; Internal functions:
6559 (defun gnus-article-set-globals ()
6560 (with-current-buffer gnus-summary-buffer
6561 (gnus-set-global-variables)))
6563 (defun gnus-signature-toggle (end)
6564 (gnus-with-article-buffer
6565 (let ((inhibit-point-motion-hooks t))
6566 (if (text-property-any end (point-max) 'article-type 'signature)
6568 (gnus-delete-wash-type 'signature)
6569 (gnus-remove-text-properties-when
6570 'article-type 'signature end (point-max)
6571 (cons 'article-type (cons 'signature
6572 gnus-hidden-properties))))
6573 (gnus-add-wash-type 'signature)
6574 (gnus-add-text-properties-when
6575 'article-type nil end (point-max)
6576 (cons 'article-type (cons 'signature
6577 gnus-hidden-properties)))))
6578 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6579 (gnus-set-mode-line 'article))))
6581 (defun gnus-button-entry ()
6582 ;; Return the first entry in `gnus-button-alist' matching this place.
6583 (let ((alist gnus-button-alist)
6586 (setq entry (pop alist))
6587 (if (looking-at (eval (car entry)))
6592 (defun gnus-button-push (marker)
6593 ;; Push button starting at MARKER.
6596 (let* ((entry (gnus-button-entry))
6597 (inhibit-point-motion-hooks t)
6599 (args (mapcar (lambda (group)
6600 (let ((string (match-string group)))
6601 (set-text-properties
6602 0 (length string) nil string)
6609 (fboundp (symbol-value fun)))
6610 (apply (symbol-value fun) args))
6612 (gnus-message 1 "You must define `%S' to use this button"
6613 (cons fun args)))))))
6615 (defun gnus-parse-news-url (url)
6616 (let (scheme server port group message-id articles)
6619 (goto-char (point-min))
6620 (when (looking-at "\\([A-Za-z]+\\):")
6621 (setq scheme (match-string 1))
6622 (goto-char (match-end 0)))
6623 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
6624 (setq server (match-string 1))
6625 (setq port (if (stringp (match-string 3))
6626 (string-to-number (match-string 3))
6628 (goto-char (match-end 0)))
6631 ((looking-at "\\(.*@.*\\)")
6632 (setq message-id (match-string 1)))
6633 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6634 (setq group (match-string 1)
6635 articles (split-string (match-string 2) "-")))
6636 ((looking-at "\\([^/]+\\)/?")
6637 (setq group (match-string 1)))
6639 (error "Unknown news URL syntax"))))
6640 (list scheme server port group message-id articles)))
6642 (defun gnus-button-handle-news (url)
6644 (destructuring-bind (scheme server port group message-id articles)
6645 (gnus-parse-news-url url)
6649 (set-buffer gnus-summary-buffer)
6651 (let ((gnus-refer-article-method
6652 (nconc (list (list 'nntp server))
6653 gnus-refer-article-method))
6654 (nntp-port-number (or port "nntp")))
6655 (gnus-message 7 "Fetching %s with %s"
6656 message-id gnus-refer-article-method)
6657 (gnus-summary-refer-article message-id))
6658 (gnus-summary-refer-article message-id))))
6660 (gnus-button-fetch-group url)))))
6662 (defun gnus-button-handle-man (url)
6664 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6665 (when (eq gnus-button-man-handler 'woman)
6666 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6667 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6668 (funcall gnus-button-man-handler url))
6670 (defun gnus-button-handle-info-url (url)
6671 "Fetch an info URL."
6672 (setq url (mm-subst-char-in-string ?+ ?\ url))
6674 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6675 (gnus-info-find-node
6676 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6678 ")" (gnus-url-unhex-string (match-string 2 url)))))
6679 ((string-match "([^)\"]+)[^\"]+" url)
6681 (gnus-replace-in-string
6682 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6683 (gnus-info-find-node url))
6684 (t (error "Can't parse %s" url))))
6686 (defun gnus-button-handle-info-url-gnome (url)
6687 "Fetch GNOME style info URL."
6688 (setq url (mm-subst-char-in-string ?_ ?\ url))
6689 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6690 (gnus-info-find-node
6692 (gnus-url-unhex-string
6693 (match-string 1 url))
6695 (or (gnus-url-unhex-string
6696 (match-string 2 url))
6698 (error "Can't parse %s" url)))
6700 (defun gnus-button-handle-info-url-kde (url)
6701 "Fetch KDE style info URL."
6702 (gnus-info-find-node (gnus-url-unhex-string url)))
6704 (defun gnus-button-handle-info-keystrokes (url)
6705 "Call `info' when pushing the corresponding URL button."
6706 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6711 (defun gnus-button-openpgp (url)
6712 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
6714 (mm-url-insert-file-contents-external url)
6715 (pgg-snarf-keys-region (point-min) (point-max))
6716 (pgg-display-output-buffer nil nil nil)))
6718 (defun gnus-button-message-id (message-id)
6720 (with-current-buffer gnus-summary-buffer
6721 (gnus-summary-refer-article message-id)))
6723 (defun gnus-button-fetch-group (address)
6724 "Fetch GROUP specified by ADDRESS."
6725 (if (not (string-match "[:/]" address))
6726 ;; This is just a simple group url.
6727 (gnus-group-read-ephemeral-group address gnus-select-method)
6730 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6732 (error "Can't parse %s" address)
6733 (gnus-group-read-ephemeral-group
6734 (match-string 4 address)
6735 `(nntp ,(match-string 1 address)
6736 (nntp-address ,(match-string 1 address))
6737 (nntp-port-number ,(if (match-end 3)
6738 (match-string 3 address)
6741 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6743 (defun gnus-url-parse-query-string (query &optional downcase)
6744 (let (retval pairs cur key val)
6745 (setq pairs (split-string query "&"))
6747 (setq cur (car pairs)
6749 (if (not (string-match "=" cur))
6751 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6752 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6754 (setq key (downcase key)))
6755 (setq cur (assoc key retval))
6757 (setcdr cur (cons val (cdr cur)))
6758 (setq retval (cons (list key val) retval)))))
6761 (defun gnus-url-mailto (url)
6762 ;; Send mail to someone
6763 (when (string-match "mailto:/*\\(.*\\)" url)
6764 (setq url (substring url (match-beginning 1) nil)))
6765 (let (to args subject func)
6766 (setq args (gnus-url-parse-query-string
6767 (if (string-match "^\\?" url)
6769 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
6770 (concat "to=" (match-string 1 url) "&"
6771 (match-string 2 url))
6772 (concat "to=" url)))
6774 subject (cdr-safe (assoc "subject" args)))
6777 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6780 (message-position-on-field (caar args)))
6781 (insert (gnus-replace-in-string
6782 (mapconcat 'identity (reverse (cdar args)) ", ")
6784 (setq args (cdr args)))
6787 (message-goto-subject))))
6789 (defun gnus-button-embedded-url (address)
6790 "Activate ADDRESS with `browse-url'."
6791 (browse-url (gnus-strip-whitespace address)))
6793 ;;; Next/prev buttons in the article buffer.
6795 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6796 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6798 (defvar gnus-prev-page-map
6799 (let ((map (make-sparse-keymap)))
6800 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6801 (define-key map "\r" 'gnus-button-prev-page)
6804 (defvar gnus-next-page-map
6805 (let ((map (make-sparse-keymap)))
6806 (unless (>= emacs-major-version 21)
6807 ;; XEmacs doesn't care.
6808 (set-keymap-parent map gnus-article-mode-map))
6809 (define-key map gnus-mouse-2 'gnus-button-next-page)
6810 (define-key map "\r" 'gnus-button-next-page)
6813 (defun gnus-insert-prev-page-button ()
6815 (inhibit-read-only t))
6817 gnus-prev-page-line-format nil
6818 `(keymap ,gnus-prev-page-map
6820 gnus-callback gnus-article-button-prev-page
6821 article-type annotation))
6822 (widget-convert-button
6824 ;; Exclude a newline.
6827 :action 'gnus-button-prev-page
6828 :button-keymap gnus-prev-page-map)))
6830 (defun gnus-button-next-page (&optional args more-args)
6831 "Go to the next page."
6833 (let ((win (selected-window)))
6834 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6835 (gnus-article-next-page)
6836 (select-window win)))
6838 (defun gnus-button-prev-page (&optional args more-args)
6839 "Go to the prev page."
6841 (let ((win (selected-window)))
6842 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6843 (gnus-article-prev-page)
6844 (select-window win)))
6846 (defun gnus-insert-next-page-button ()
6848 (inhibit-read-only t))
6849 (gnus-eval-format gnus-next-page-line-format nil
6850 `(keymap ,gnus-next-page-map
6852 gnus-callback gnus-article-button-next-page
6853 article-type annotation))
6854 (widget-convert-button
6856 ;; Exclude a newline.
6859 :action 'gnus-button-next-page
6860 :button-keymap gnus-next-page-map)))
6862 (defun gnus-article-button-next-page (arg)
6863 "Go to the next page."
6865 (let ((win (selected-window)))
6866 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6867 (gnus-article-next-page)
6868 (select-window win)))
6870 (defun gnus-article-button-prev-page (arg)
6871 "Go to the prev page."
6873 (let ((win (selected-window)))
6874 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6875 (gnus-article-prev-page)
6876 (select-window win)))
6878 (defvar gnus-decode-header-methods
6879 '(mail-decode-encoded-word-region)
6880 "List of methods used to decode headers.
6882 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6883 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
6884 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
6885 whose names match REGEXP.
6888 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6889 mail-decode-encoded-word-region
6890 (\"chinese\" . rfc1843-decode-region))
6893 (defvar gnus-decode-header-methods-cache nil)
6895 (defun gnus-multi-decode-header (start end)
6896 "Apply the functions from `gnus-encoded-word-methods' that match."
6897 (unless (and gnus-decode-header-methods-cache
6898 (eq gnus-newsgroup-name
6899 (car gnus-decode-header-methods-cache)))
6900 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6903 (nconc gnus-decode-header-methods-cache (list x))
6904 (if (and gnus-newsgroup-name
6905 (string-match (car x) gnus-newsgroup-name))
6906 (nconc gnus-decode-header-methods-cache
6908 gnus-decode-header-methods))
6909 (let ((xlist gnus-decode-header-methods-cache))
6912 (narrow-to-region start end)
6914 (funcall (pop xlist) (point-min) (point-max))))))
6917 ;;; Treatment top-level handling.
6920 (defun gnus-treat-article (condition &optional part-number total-parts type)
6921 (let ((length (- (point-max) (point-min)))
6922 (alist gnus-treatment-function-alist)
6923 (article-goto-body-goes-to-point-min-p t)
6927 (let ((list gnus-article-treat-types))
6929 (when (string-match (pop list) type)
6930 (throw 'found t)))))))
6931 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6933 (gnus-run-hooks 'gnus-part-display-hook)
6934 (dolist (elem alist)
6937 (when (gnus-buffer-live-p gnus-summary-buffer)
6938 (set-buffer gnus-summary-buffer))
6939 (symbol-value (car elem))))
6940 (when (and (or (consp val)
6942 (gnus-treat-predicate val)
6943 (or (not (get (car elem) 'highlight))
6946 (funcall (cadr elem)))))))
6948 ;; Dynamic variables.
6950 (defvar part-number)
6951 (defvar total-parts)
6956 (defun gnus-treat-predicate (val)
6963 (stringp (car val)))
6964 (apply 'gnus-or (mapcar `(lambda (s)
6965 (string-match s ,(or gnus-newsgroup-name "")))
6968 (let ((pred (pop val)))
6971 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6973 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6975 (not (gnus-treat-predicate (car val))))
6977 (equal (car val) type))
6979 (error "%S is not a valid predicate" pred)))))
6985 (eq part-number total-parts))
6989 (error "%S is not a valid value" val))))
6991 (defun gnus-article-encrypt-body (protocol &optional n)
6992 "Encrypt the article body."
6995 (or gnus-article-encrypt-protocol
6996 (completing-read "Encrypt protocol: "
6997 gnus-article-encrypt-protocol-alist
6999 current-prefix-arg))
7000 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7002 (error (format "Can't find the encrypt protocol %s" protocol)))
7003 (if (member gnus-newsgroup-name '("nndraft:delayed"
7006 (error "Can't encrypt the article in group %s"
7007 gnus-newsgroup-name))
7008 (gnus-summary-iterate n
7010 (set-buffer gnus-summary-buffer)
7011 (let ((mail-parse-charset gnus-newsgroup-charset)
7012 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7013 (summary-buffer gnus-summary-buffer)
7015 (gnus-set-global-variables)
7016 (when (gnus-group-read-only-p)
7017 (error "The current newsgroup does not support article encrypt"))
7018 (gnus-summary-show-article t)
7020 (or (mail-header-references gnus-current-headers) ""))
7021 (set-buffer gnus-article-buffer)
7022 (let* ((inhibit-read-only t)
7024 (mapcar (lambda (field)
7025 (and (save-restriction
7026 (message-narrow-to-head)
7027 (goto-char (point-min))
7028 (search-forward field nil t))
7030 (message-narrow-to-field)
7032 (delete-region (point-min) (point-max))
7034 '("Content-Type:" "Content-Transfer-Encoding:"
7035 "Content-Disposition:"))))
7036 (message-narrow-to-head)
7037 (message-remove-header "MIME-Version")
7038 (goto-char (point-max))
7039 (setq point (point))
7040 (insert (apply 'concat headers))
7042 (narrow-to-region point (point-max))
7043 (let ((message-options message-options))
7044 (message-options-set 'message-sender user-mail-address)
7045 (message-options-set 'message-recipients user-mail-address)
7046 (message-options-set 'message-sign-encrypt 'not)
7048 (goto-char (point-min))
7049 (insert "MIME-Version: 1.0\n")
7051 (gnus-summary-edit-article-done
7052 references nil summary-buffer t))
7053 (when gnus-keep-backlog
7054 (gnus-backlog-remove-article
7055 (car gnus-article-current) (cdr gnus-article-current)))
7057 (when (get-buffer gnus-original-article-buffer)
7058 (set-buffer gnus-original-article-buffer)
7059 (setq gnus-original-article nil)))
7060 (when gnus-use-cache
7061 (gnus-cache-update-article
7062 (car gnus-article-current) (cdr gnus-article-current))))))))
7064 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7065 "The following specs can be used:
7066 %t The security MIME type
7069 %D Details if button is pressed")
7071 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7072 "The following specs can be used:
7073 %t The security MIME type
7076 %D Details if button is pressed")
7078 (defvar gnus-mime-security-button-line-format-alist
7079 '((?t gnus-tmp-type ?s)
7080 (?i gnus-tmp-info ?s)
7081 (?d gnus-tmp-details ?s)
7082 (?D gnus-tmp-pressed-details ?s)))
7084 (defvar gnus-mime-security-button-map
7085 (let ((map (make-sparse-keymap)))
7086 (define-key map gnus-mouse-2 'gnus-article-push-button)
7087 (define-key map "\r" 'gnus-article-press-button)
7090 (defvar gnus-mime-security-details-buffer nil)
7092 (defvar gnus-mime-security-button-pressed nil)
7094 (defvar gnus-mime-security-show-details-inline t
7095 "If non-nil, show details in the article buffer.")
7097 (defun gnus-mime-security-verify-or-decrypt (handle)
7098 (mm-remove-parts (cdr handle))
7099 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7100 point (inhibit-read-only t))
7102 (goto-char (car region)))
7104 (narrow-to-region (point) (point))
7105 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7106 (let* ((mm-verify-option 'known)
7107 (mm-decrypt-option 'known)
7108 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7109 (unless (eq nparts (cdr handle))
7110 (mm-destroy-parts (cdr handle))
7111 (setcdr handle nparts))))
7112 (setq point (point))
7113 (gnus-mime-display-security handle)
7114 (goto-char (point-max)))
7116 (delete-region (point) (cdr region))
7117 (set-marker (car region) nil)
7118 (set-marker (cdr region) nil))
7121 (defun gnus-mime-security-show-details (handle)
7122 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7124 (gnus-message 5 "No details.")
7125 (if gnus-mime-security-show-details-inline
7126 (let ((gnus-mime-security-button-pressed
7127 (not (get-text-property (point) 'gnus-mime-details)))
7128 (gnus-mime-security-button-line-format
7129 (get-text-property (point) 'gnus-line-format))
7130 (inhibit-read-only t))
7132 (while (eq (get-text-property (point) 'gnus-line-format)
7133 gnus-mime-security-button-line-format)
7137 (narrow-to-region (point) (point))
7138 (gnus-insert-mime-security-button handle))
7139 (delete-region (point)
7140 (or (text-property-not-all
7143 gnus-mime-security-button-line-format)
7146 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7147 (with-current-buffer gnus-mime-security-details-buffer
7150 (setq gnus-mime-security-details-buffer
7151 (gnus-get-buffer-create "*MIME Security Details*")))
7152 (with-current-buffer gnus-mime-security-details-buffer
7154 (goto-char (point-min)))
7155 (pop-to-buffer gnus-mime-security-details-buffer)))))
7157 (defun gnus-mime-security-press-button (handle)
7159 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7160 (gnus-mime-security-show-details handle)
7161 (gnus-mime-security-verify-or-decrypt handle))))
7163 (defun gnus-insert-mime-security-button (handle &optional displayed)
7164 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7167 (or (nth 2 (assoc protocol mm-verify-function-alist))
7168 (nth 2 (assoc protocol mm-decrypt-function-alist))
7170 (if (equal (car handle) "multipart/signed")
7171 " Signed" " Encrypted")
7174 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7177 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7178 gnus-tmp-pressed-details
7180 (setq gnus-tmp-details
7181 (if gnus-tmp-details
7182 (concat "\n" gnus-tmp-details)
7184 (setq gnus-tmp-pressed-details
7185 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7190 gnus-mime-security-button-line-format
7191 gnus-mime-security-button-line-format-alist
7192 `(keymap ,gnus-mime-security-button-map
7193 gnus-callback gnus-mime-security-press-button
7194 gnus-line-format ,gnus-mime-security-button-line-format
7195 gnus-mime-details ,gnus-mime-security-button-pressed
7196 article-type annotation
7199 ;; Exclude a newline.
7202 (widget-convert-button
7205 :action 'gnus-widget-press-button
7206 :button-keymap gnus-mime-security-button-map
7208 (lambda (widget/window &optional overlay pos)
7209 ;; Needed to properly clear the message due to a bug in
7210 ;; wid-edit (XEmacs only).
7211 (when (boundp 'help-echo-owns-message)
7212 (setq help-echo-owns-message t))
7215 (aref gnus-mouse-2 0))))))
7217 (defun gnus-mime-display-security (handle)
7219 (narrow-to-region (point) (point))
7220 (unless (gnus-unbuttonized-mime-type-p (car handle))
7221 (gnus-insert-mime-security-button handle))
7222 (gnus-mime-display-mixed (cdr handle))
7225 (unless (gnus-unbuttonized-mime-type-p (car handle))
7226 (let ((gnus-mime-security-button-line-format
7227 gnus-mime-security-button-end-line-format))
7228 (gnus-insert-mime-security-button handle)))
7229 (mm-set-handle-multipart-parameter
7231 (cons (set-marker (make-marker) (point-min))
7232 (set-marker (make-marker) (point-max))))))
7238 (run-hooks 'gnus-art-load-hook)
7240 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7241 ;;; gnus-art.el ends here