1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'static))
44 ;; Avoid byte-compile warnings.
53 (autoload 'gnus-msg-mail "gnus-msg" nil t)
54 (autoload 'gnus-button-mailto "gnus-msg")
55 (autoload 'gnus-button-reply "gnus-msg" nil t)
57 (defgroup gnus-article nil
59 :link '(custom-manual "(gnus)The Article Buffer")
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
78 (defgroup gnus-article-signature nil
80 :link '(custom-manual "(gnus)Article Signature")
83 (defgroup gnus-article-headers nil
85 :link '(custom-manual "(gnus)Hiding Headers")
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
98 (defgroup gnus-article-saving nil
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
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:"
156 "*All headers that start with this regexp will be hidden.
157 This variable can also be a list of regexps of headers to be ignored.
158 If `gnus-visible-headers' is non-nil, this variable will be ignored."
159 :type '(choice :custom-show nil
162 :group 'gnus-article-hiding)
164 (defcustom gnus-visible-headers
165 "^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:"
166 "*All headers that do not match this regexp will be hidden.
167 This variable can also be a list of regexp of headers to remain visible.
168 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
169 :type '(repeat :value-to-internal (lambda (widget value)
170 (custom-split-regexp-maybe value))
171 :match (lambda (widget value)
173 (widget-editable-list-match widget value)))
175 :group 'gnus-article-hiding)
177 (defcustom gnus-sorted-header-list
178 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
179 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
180 "*This variable is a list of regular expressions.
181 If it is non-nil, headers that match the regular expressions will
182 be placed first in the article buffer in the sequence specified by
184 :type '(repeat regexp)
185 :group 'gnus-article-hiding)
187 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
188 "Headers that are only to be displayed if they have interesting data.
189 Possible values in this list are:
191 'empty Headers with no content.
192 'newsgroups Newsgroup identical to Gnus group.
193 'to-address To identical to To-address.
194 'followup-to Followup-to identical to Newsgroups.
195 'reply-to Reply-to identical to From.
196 'date Date less than four days old.
197 'long-to To and/or Cc longer than 1024 characters.
198 'many-to Multiple To and/or Cc."
199 :type '(set (const :tag "Headers with no content." empty)
200 (const :tag "Newsgroups identical to Gnus group." newsgroups)
201 (const :tag "To identical to To-address." to-address)
202 (const :tag "Followup-to identical to Newsgroups." followup-to)
203 (const :tag "Reply-to identical to From." reply-to)
204 (const :tag "Date less than four days old." date)
205 (const :tag "To and/or Cc longer than 1024 characters." long-to)
206 (const :tag "Multiple To and/or Cc headers." many-to))
207 :group 'gnus-article-hiding)
209 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
210 "Regexp matching signature separator.
211 This can also be a list of regexps. In that case, it will be checked
212 from head to tail looking for a separator. Searches will be done from
213 the end of the buffer."
214 :type '(repeat string)
215 :group 'gnus-article-signature)
217 (defcustom gnus-signature-limit nil
218 "Provide a limit to what is considered a signature.
219 If it is a number, no signature may not be longer (in characters) than
220 that number. If it is a floating point number, no signature may be
221 longer (in lines) than that number. If it is a function, the function
222 will be called without any parameters, and if it returns nil, there is
223 no signature in the buffer. If it is a string, it will be used as a
224 regexp. If it matches, the text in question is not a signature."
225 :type '(choice (integer :value 200)
227 (function :value fun)
228 (regexp :value ".*"))
229 :group 'gnus-article-signature)
231 (defcustom gnus-hidden-properties '(invisible t intangible t)
232 "Property list to use for hiding text."
234 :group 'gnus-article-hiding)
236 ;; Fixme: This isn't the right thing for mixed graphical and and
237 ;; non-graphical frames in a session.
238 (defcustom gnus-article-x-face-command
241 (if (or (gnus-image-type-available-p 'xface)
242 (gnus-image-type-available-p 'pbm))
243 'gnus-display-x-face-in-from
244 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
245 ((and (fboundp 'image-type-available-p)
246 (module-installed-p 'x-face-e21))
247 'x-face-decode-message-header)
248 ((gnus-image-type-available-p 'pbm)
249 'gnus-display-x-face-in-from)
251 (module-installed-p 'x-face-mule))
252 'x-face-mule-gnus-article-display-x-face)
254 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
256 "*String or function to be executed to display an X-Face header.
257 If it is a string, the command will be executed in a sub-shell
258 asynchronously. The compressed face will be piped to this command."
260 ,@(let (x-face-e21 x-face-mule)
261 (if (featurep 'xemacs)
263 (setq x-face-e21 (module-installed-p 'x-face-e21)
264 x-face-mule (module-installed-p 'x-face-mule)))
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 '(function-item gnus-display-x-face-in-from))
272 (fboundp 'image-type-available-p))
274 :tag "x-face-decode-message-header (x-face-e21)"
275 x-face-decode-message-header))
278 x-face-mule-gnus-article-display-x-face))
282 :group 'gnus-article-washing)
284 (defcustom gnus-article-x-face-too-ugly nil
285 "Regexp matching posters whose face shouldn't be shown automatically."
286 :type '(choice regexp (const nil))
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-banner-alist nil
290 "Banner alist for stripping.
292 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
294 :type '(repeat (cons symbol regexp))
295 :group 'gnus-article-washing)
297 (gnus-define-group-parameter
300 "Alist of regexps (to match group names) and banner."
301 :variable-group gnus-article-washing
303 '(choice :tag "Banner"
305 (const :tag "Remove signature" signature)
306 (symbol :tag "Item in `gnus-article-banner-alist'" none)
308 (const :tag "None" nil))
310 "If non-nil, specify how to remove `banners' from articles.
312 Symbol `signature' means to remove signatures delimited by
313 `gnus-signature-separator'. Any other symbol is used to look up a
314 regular expression to match the banner in `gnus-article-banner-alist'.
315 A string is used as a regular expression to match the banner
318 (defcustom gnus-emphasis-alist
320 "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
325 ("_/" "/_" underline-italic)
326 ("_\\*" "\\*_" underline-bold)
327 ("\\*/" "/\\*" bold-italic)
328 ("_\\*/" "/\\*_" underline-bold-italic))))
332 (format format (car spec) (car (cdr spec)))
333 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
335 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
336 2 3 gnus-emphasis-underline)))
337 "*Alist that says how to fontify certain phrases.
338 Each item looks like this:
340 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
342 The first element is a regular expression to be matched. The second
343 is a number that says what regular expression grouping used to find
344 the entire emphasized word. The third is a number that says what
345 regexp grouping should be displayed and highlighted. The fourth
346 is the face used for highlighting."
347 :type '(repeat (list :value ("" 0 0 default)
349 (integer :tag "Match group")
350 (integer :tag "Emphasize group")
352 :group 'gnus-article-emphasis)
354 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
355 "A regexp to describe whitespace which should not be emphasized.
356 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
357 The former avoids underlining of leading and trailing whitespace,
358 and the latter avoids underlining any whitespace at all."
360 :group 'gnus-article-emphasis
363 (defface gnus-emphasis-bold '((t (:bold t)))
364 "Face used for displaying strong emphasized text (*word*)."
365 :group 'gnus-article-emphasis)
367 (defface gnus-emphasis-italic '((t (:italic t)))
368 "Face used for displaying italic emphasized text (/word/)."
369 :group 'gnus-article-emphasis)
371 (defface gnus-emphasis-underline '((t (:underline t)))
372 "Face used for displaying underlined emphasized text (_word_)."
373 :group 'gnus-article-emphasis)
375 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
376 "Face used for displaying underlined bold emphasized text (_*word*_)."
377 :group 'gnus-article-emphasis)
379 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
380 "Face used for displaying underlined italic emphasized text (_/word/_)."
381 :group 'gnus-article-emphasis)
383 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
384 "Face used for displaying bold italic emphasized text (/*word*/)."
385 :group 'gnus-article-emphasis)
387 (defface gnus-emphasis-underline-bold-italic
388 '((t (:bold t :italic t :underline t)))
389 "Face used for displaying underlined bold italic emphasized text.
390 Esample: (_/*word*/_)."
391 :group 'gnus-article-emphasis)
393 (defface gnus-emphasis-highlight-words
394 '((t (:background "black" :foreground "yellow")))
395 "Face used for displaying highlighted words."
396 :group 'gnus-article-emphasis)
398 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
399 "Format for display of Date headers in article bodies.
400 See `format-time-string' for the possible values.
402 The variable can also be function, which should return a complete Date
403 header. The function is called with one argument, the time, which can
404 be fed to `format-time-string'."
405 :type '(choice string symbol)
406 :link '(custom-manual "(gnus)Article Date")
407 :group 'gnus-article-washing)
410 (autoload 'mail-extract-address-components "mail-extr"))
412 (defcustom gnus-save-all-headers t
413 "*If non-nil, don't remove any headers before saving."
414 :group 'gnus-article-saving
417 (defcustom gnus-prompt-before-saving 'always
418 "*This variable says how much prompting is to be done when saving articles.
419 If it is nil, no prompting will be done, and the articles will be
420 saved to the default files. If this variable is `always', each and
421 every article that is saved will be preceded by a prompt, even when
422 saving large batches of articles. If this variable is neither nil not
423 `always', there the user will be prompted once for a file name for
424 each invocation of the saving commands."
425 :group 'gnus-article-saving
426 :type '(choice (item always)
427 (item :tag "never" nil)
428 (sexp :tag "once" :format "%t\n" :value t)))
430 (defcustom gnus-saved-headers gnus-visible-headers
431 "Headers to keep if `gnus-save-all-headers' is nil.
432 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
433 If that variable is nil, however, all headers that match this regexp
434 will be kept while the rest will be deleted before saving."
435 :group 'gnus-article-saving
438 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
439 "A function to save articles in your favourite format.
440 The function must be interactively callable (in other words, it must
441 be an Emacs command).
443 Gnus provides the following functions:
445 * gnus-summary-save-in-rmail (Rmail format)
446 * gnus-summary-save-in-mail (Unix mail format)
447 * gnus-summary-save-in-folder (MH folder)
448 * gnus-summary-save-in-file (article format)
449 * gnus-summary-save-body-in-file (article body)
450 * gnus-summary-save-in-vm (use VM's folder format)
451 * gnus-summary-write-to-file (article format -- overwrite)."
452 :group 'gnus-article-saving
453 :type '(radio (function-item gnus-summary-save-in-rmail)
454 (function-item gnus-summary-save-in-mail)
455 (function-item gnus-summary-save-in-folder)
456 (function-item gnus-summary-save-in-file)
457 (function-item gnus-summary-save-body-in-file)
458 (function-item gnus-summary-save-in-vm)
459 (function-item gnus-summary-write-to-file)))
461 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
462 "A function generating a file name to save articles in Rmail format.
463 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
464 :group 'gnus-article-saving
467 (defcustom gnus-mail-save-name 'gnus-plain-save-name
468 "A function generating a file name to save articles in Unix mail format.
469 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
470 :group 'gnus-article-saving
473 (defcustom gnus-folder-save-name 'gnus-folder-save-name
474 "A function generating a file name to save articles in MH folder.
475 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
476 :group 'gnus-article-saving
479 (defcustom gnus-file-save-name 'gnus-numeric-save-name
480 "A function generating a file name to save articles in article format.
481 The function is called with NEWSGROUP, HEADERS, and optional
483 :group 'gnus-article-saving
486 (defcustom gnus-split-methods
487 '((gnus-article-archive-name)
488 (gnus-article-nndoc-name))
489 "*Variable used to suggest where articles are to be saved.
490 For instance, if you would like to save articles related to Gnus in
491 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
492 you could set this variable to something like:
494 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
495 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
497 This variable is an alist where the where the key is the match and the
498 value is a list of possible files to save in if the match is non-nil.
500 If the match is a string, it is used as a regexp match on the
501 article. If the match is a symbol, that symbol will be funcalled
502 from the buffer of the article to be saved with the newsgroup as the
503 parameter. If it is a list, it will be evaled in the same buffer.
505 If this form or function returns a string, this string will be used as
506 a possible file name; and if it returns a non-nil list, that list will
507 be used as possible file names."
508 :group 'gnus-article-saving
509 :type '(repeat (choice (list :value (fun) function)
510 (cons :value ("" "") regexp (repeat string))
513 (defcustom gnus-article-display-method-for-mime
514 'gnus-article-display-mime-message
515 "Function to display a MIME message.
516 The function is called from the article buffer."
517 :group 'gnus-article-mime
520 (defcustom gnus-article-display-method-for-traditional
521 'gnus-article-display-traditional-message
522 "*Function to display a traditional message.
523 The function is called from the article buffer."
524 :group 'gnus-article-mime
527 (defcustom gnus-page-delimiter "^\^L"
528 "*Regexp describing what to use as article page delimiters.
529 The default value is \"^\^L\", which is a form linefeed at the
530 beginning of a line."
532 :group 'gnus-article-various)
534 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
535 "*The format specification for the article mode line.
536 See `gnus-summary-mode-line-format' for a closer description.
538 The following additional specs are available:
540 %w The article washing status.
541 %m The number of MIME parts in the article."
543 :group 'gnus-article-various)
545 (defcustom gnus-article-mode-hook nil
546 "*A hook for Gnus article mode."
548 :group 'gnus-article-various)
550 (when (featurep 'xemacs)
551 ;; Extracted from gnus-xmas-define in order to preserve user settings
552 (when (fboundp 'turn-off-scroll-in-place)
553 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
554 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
555 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
557 (defcustom gnus-article-menu-hook nil
558 "*Hook run after the creation of the article mode menu."
560 :group 'gnus-article-various)
562 (defcustom gnus-article-prepare-hook nil
563 "*A hook called after an article has been prepared in the article buffer."
565 :group 'gnus-article-various)
567 (defcustom gnus-article-hide-pgp-hook nil
568 "*A hook called after successfully hiding a PGP signature."
570 :group 'gnus-article-various)
572 (defcustom gnus-article-button-face 'bold
573 "Face used for highlighting buttons in the article buffer.
575 An article button is a piece of text that you can activate by pressing
576 `RET' or `mouse-2' above it."
578 :group 'gnus-article-buttons)
580 (defcustom gnus-article-mouse-face 'highlight
581 "Face used for mouse highlighting in the article buffer.
583 Article buttons will be displayed in this face when the cursor is
586 :group 'gnus-article-buttons)
588 (defcustom gnus-signature-face 'gnus-signature-face
589 "Face used for highlighting a signature in the article buffer.
590 Obsolete; use the face `gnus-signature-face' for customizations instead."
592 :group 'gnus-article-highlight
593 :group 'gnus-article-signature)
595 (defface gnus-signature-face
598 "Face used for highlighting a signature in the article buffer."
599 :group 'gnus-article-highlight
600 :group 'gnus-article-signature)
602 (defface gnus-header-from-face
605 (:foreground "spring green"))
608 (:foreground "red3"))
611 "Face used for displaying from headers."
612 :group 'gnus-article-headers
613 :group 'gnus-article-highlight)
615 (defface gnus-header-subject-face
618 (:foreground "SeaGreen3"))
621 (:foreground "red4"))
623 (:bold t :italic t)))
624 "Face used for displaying subject headers."
625 :group 'gnus-article-headers
626 :group 'gnus-article-highlight)
628 (defface gnus-header-newsgroups-face
631 (:foreground "yellow" :italic t))
634 (:foreground "MidnightBlue" :italic t))
637 "Face used for displaying newsgroups headers."
638 :group 'gnus-article-headers
639 :group 'gnus-article-highlight)
641 (defface gnus-header-name-face
644 (:foreground "SeaGreen"))
647 (:foreground "maroon"))
650 "Face used for displaying header names."
651 :group 'gnus-article-headers
652 :group 'gnus-article-highlight)
654 (defface gnus-header-content-face
657 (:foreground "forest green" :italic t))
660 (:foreground "indianred4" :italic t))
663 "Face used for displaying header content."
664 :group 'gnus-article-headers
665 :group 'gnus-article-highlight)
667 (defcustom gnus-header-face-alist
668 '(("From" nil gnus-header-from-face)
669 ("Subject" nil gnus-header-subject-face)
670 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
671 ("" gnus-header-name-face gnus-header-content-face))
672 "*Controls highlighting of article header.
674 An alist of the form (HEADER NAME CONTENT).
676 HEADER is a regular expression which should match the name of an
677 header header and NAME and CONTENT are either face names or nil.
679 The name of each header field will be displayed using the face
680 specified by the first element in the list where HEADER match the
681 header name and NAME is non-nil. Similarly, the content will be
682 displayed by the first non-nil matching CONTENT face."
683 :group 'gnus-article-headers
684 :group 'gnus-article-highlight
685 :type '(repeat (list (regexp :tag "Header")
687 (item :tag "skip" nil)
688 (face :value default))
689 (choice :tag "Content"
690 (item :tag "skip" nil)
691 (face :value default)))))
693 (defcustom gnus-article-decode-hook nil
694 "*Hook run to decode charsets in articles."
695 :group 'gnus-article-headers
698 (defcustom gnus-display-mime-function 'gnus-display-mime
699 "Function to display MIME articles."
700 :group 'gnus-article-mime
703 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
704 "Function used to decode headers.")
706 (defvar gnus-article-dumbquotes-map
725 "Table for MS-to-Latin1 translation.")
727 (defcustom gnus-ignored-mime-types nil
728 "List of MIME types that should be ignored by Gnus."
730 :group 'gnus-article-mime
731 :type '(repeat regexp))
733 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
734 "List of MIME types that should not be given buttons when rendered inline.
735 See also `gnus-buttonized-mime-types' which may override this variable."
737 :group 'gnus-article-mime
738 :type '(repeat regexp))
740 (defcustom gnus-buttonized-mime-types nil
741 "List of MIME types that should be given buttons when rendered inline.
742 If set, this variable overrides `gnus-unbuttonized-mime-types'.
743 To see e.g. security buttons you could set this to
744 `(\"multipart/signed\")'."
746 :group 'gnus-article-mime
747 :type '(repeat regexp))
749 (defcustom gnus-body-boundary-delimiter "_"
750 "String used to delimit header and body.
751 This variable is used by `gnus-article-treat-body-boundary' which can
752 be controlled by `gnus-treat-body-boundary'."
753 :group 'gnus-article-various
754 :type '(choice (item :tag "None" :value nil)
757 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
758 "Defines the location of the faces database.
759 For information on obtaining this database of pretty pictures, please
760 see http://www.cs.indiana.edu/picons/ftp/index.html"
761 :type '(repeat directory)
762 :link '(url-link :tag "download"
763 "http://www.cs.indiana.edu/picons/ftp/index.html")
764 :link '(custom-manual "(gnus)Picons")
767 (defun gnus-picons-installed-p ()
768 "Say whether picons are installed on your machine."
769 (let ((installed nil))
770 (dolist (database gnus-picon-databases)
771 (when (file-exists-p database)
775 (defcustom gnus-article-mime-part-function nil
776 "Function called with a MIME handle as the argument.
777 This is meant for people who want to do something automatic based
778 on parts -- for instance, adding Vcard info to a database."
779 :group 'gnus-article-mime
782 (defcustom gnus-mime-multipart-functions nil
783 "An alist of MIME types to functions to display them."
785 :group 'gnus-article-mime
788 (defcustom gnus-article-date-lapsed-new-header nil
789 "Whether the X-Sent and Date headers can coexist.
790 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
791 either replace the old \"Date:\" header (if this variable is nil), or
792 be added below it (otherwise)."
794 :group 'gnus-article-headers
797 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
798 "Function called with a MIME handle as the argument.
799 This is meant for people who want to view first matched part.
800 For `undisplayed-alternative' (default), the first undisplayed
801 part or alternative part is used. For `undisplayed', the first
802 undisplayed part is used. For a function, the first part which
803 the function return `t' is used. For `nil', the first part is
806 :group 'gnus-article-mime
808 (item :tag "first" :value nil)
809 (item :tag "undisplayed" :value undisplayed)
810 (item :tag "undisplayed or alternative"
811 :value undisplayed-alternative)
814 (defcustom gnus-mime-action-alist
815 '(("save to file" . gnus-mime-save-part)
816 ("save and strip" . gnus-mime-save-part-and-strip)
817 ("display as text" . gnus-mime-inline-part)
818 ("view the part" . gnus-mime-view-part)
819 ("pipe to command" . gnus-mime-pipe-part)
820 ("toggle display" . gnus-article-press-button)
821 ("toggle display" . gnus-article-view-part-as-charset)
822 ("view as type" . gnus-mime-view-part-as-type)
823 ("view internally" . gnus-mime-view-part-internally)
824 ("view externally" . gnus-mime-view-part-externally))
825 "An alist of actions that run on the MIME attachment."
826 :group 'gnus-article-mime
827 :type '(repeat (cons (string :tag "name")
831 ;;; The treatment variables
834 (defvar gnus-part-display-hook nil
835 "Hook called on parts that are to receive treatment.")
837 (defvar gnus-article-treat-custom
838 '(choice (const :tag "Off" nil)
840 (const :tag "Header" head)
841 (const :tag "Last" last)
842 (const :tag "Mime" mime)
843 (integer :tag "Less")
844 (repeat :tag "Groups" regexp)
845 (sexp :tag "Predicate")))
847 (defvar gnus-article-treat-head-custom
848 '(choice (const :tag "Off" nil)
849 (const :tag "Header" head)))
851 (defvar gnus-article-treat-types '("text/plain")
854 (defvar gnus-inhibit-treatment nil
855 "Whether to inhibit treatment.")
857 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
858 "Highlight the signature.
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See Info node `(gnus)Customizing Articles'."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-custom)
863 (put 'gnus-treat-highlight-signature 'highlight t)
865 (defcustom gnus-treat-buttonize 100000
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See Info node `(gnus)Customizing Articles'."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
871 (put 'gnus-treat-buttonize 'highlight t)
873 (defcustom gnus-treat-buttonize-head 'head
874 "Add buttons to the head.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See Info node `(gnus)Customizing Articles' for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-head-custom)
879 (put 'gnus-treat-buttonize-head 'highlight t)
881 (defcustom gnus-treat-emphasize
882 (and (or window-system
884 (>= (string-to-number emacs-version) 21))
887 Valid values are nil, t, `head', `last', an integer or a predicate.
888 See Info node `(gnus)Customizing Articles' for details."
889 :group 'gnus-article-treat
890 :type gnus-article-treat-custom)
891 (put 'gnus-treat-emphasize 'highlight t)
893 (defcustom gnus-treat-strip-cr nil
894 "Remove carriage returns.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See Info node `(gnus)Customizing Articles' for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-custom)
900 (defcustom gnus-treat-unsplit-urls nil
901 "Remove newlines from within URLs.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See Info node `(gnus)Customizing Articles' for details."
904 :group 'gnus-article-treat
905 :type gnus-article-treat-custom)
907 (defcustom gnus-treat-leading-whitespace nil
908 "Remove leading whitespace in headers.
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See Info node `(gnus)Customizing Articles' for details."
911 :group 'gnus-article-treat
912 :type gnus-article-treat-custom)
914 (defcustom gnus-treat-hide-headers 'head
916 Valid values are nil, t, `head', `last', an integer or a predicate.
917 See Info node `(gnus)Customizing Articles' for details."
918 :group 'gnus-article-treat
919 :type gnus-article-treat-head-custom)
921 (defcustom gnus-treat-hide-boring-headers nil
922 "Hide boring headers.
923 Valid values are nil, t, `head', `last', an integer or a predicate.
924 See Info node `(gnus)Customizing Articles' for details."
925 :group 'gnus-article-treat
926 :type gnus-article-treat-head-custom)
928 (defcustom gnus-treat-hide-signature nil
930 Valid values are nil, t, `head', `last', an integer or a predicate.
931 See Info node `(gnus)Customizing Articles' for details."
932 :group 'gnus-article-treat
933 :type gnus-article-treat-custom)
935 (defcustom gnus-treat-fill-article nil
937 Valid values are nil, t, `head', `last', an integer or a predicate.
938 See Info node `(gnus)Customizing Articles' for details."
939 :group 'gnus-article-treat
940 :type gnus-article-treat-custom)
942 (defcustom gnus-treat-hide-citation nil
944 Valid values are nil, t, `head', `last', an integer or a predicate.
945 See Info node `(gnus)Customizing Articles' for details."
946 :group 'gnus-article-treat
947 :type gnus-article-treat-custom)
949 (defcustom gnus-treat-hide-citation-maybe nil
951 Valid values are nil, t, `head', `last', an integer or a predicate.
952 See Info node `(gnus)Customizing Articles' for details."
953 :group 'gnus-article-treat
954 :type gnus-article-treat-custom)
956 (defcustom gnus-treat-strip-list-identifiers 'head
957 "Strip list identifiers from `gnus-list-identifiers`.
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See Info node `(gnus)Customizing Articles' for details."
961 :group 'gnus-article-treat
962 :type gnus-article-treat-custom)
964 (defcustom gnus-treat-strip-pgp t
965 "Strip PGP signatures.
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 :type gnus-article-treat-custom)
971 (defcustom gnus-treat-strip-pem nil
972 "Strip PEM signatures.
973 Valid values are nil, t, `head', `last', an integer or a predicate.
974 See Info node `(gnus)Customizing Articles' for details."
975 :group 'gnus-article-treat
976 :type gnus-article-treat-custom)
978 (defcustom gnus-treat-strip-banner t
979 "Strip banners from articles.
980 The banner to be stripped is specified in the `banner' group parameter.
981 Valid values are nil, t, `head', `last', an integer or a predicate.
982 See Info node `(gnus)Customizing Articles' for details."
983 :group 'gnus-article-treat
984 :type gnus-article-treat-custom)
986 (defcustom gnus-treat-highlight-headers 'head
987 "Highlight the headers.
988 Valid values are nil, t, `head', `last', an integer or a predicate.
989 See Info node `(gnus)Customizing Articles' for details."
990 :group 'gnus-article-treat
991 :type gnus-article-treat-head-custom)
992 (put 'gnus-treat-highlight-headers 'highlight t)
994 (defcustom gnus-treat-highlight-citation t
995 "Highlight cited text.
996 Valid values are nil, t, `head', `last', an integer or a predicate.
997 See Info node `(gnus)Customizing Articles' for details."
998 :group 'gnus-article-treat
999 :type gnus-article-treat-custom)
1000 (put 'gnus-treat-highlight-citation 'highlight t)
1002 (defcustom gnus-treat-date-ut nil
1003 "Display the Date in UT (GMT).
1004 Valid values are nil, t, `head', `last', an integer or a predicate.
1005 See Info node `(gnus)Customizing Articles' for details."
1006 :group 'gnus-article-treat
1007 :type gnus-article-treat-head-custom)
1009 (defcustom gnus-treat-date-local nil
1010 "Display the Date in the local timezone.
1011 Valid values are nil, t, `head', `last', an integer or a predicate.
1012 See Info node `(gnus)Customizing Articles' for details."
1013 :group 'gnus-article-treat
1014 :type gnus-article-treat-head-custom)
1016 (defcustom gnus-treat-date-english nil
1017 "Display the Date in a format that can be read aloud in English.
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See Info node `(gnus)Customizing Articles' for details."
1020 :group 'gnus-article-treat
1021 :type gnus-article-treat-head-custom)
1023 (defcustom gnus-treat-date-lapsed nil
1024 "Display the Date header in a way that says how much time has elapsed.
1025 Valid values are nil, t, `head', `last', an integer or a predicate.
1026 See Info node `(gnus)Customizing Articles' for details."
1027 :group 'gnus-article-treat
1028 :type gnus-article-treat-head-custom)
1030 (defcustom gnus-treat-date-original nil
1031 "Display the date in the original timezone.
1032 Valid values are nil, t, `head', `last', an integer or a predicate.
1033 See Info node `(gnus)Customizing Articles' for details."
1034 :group 'gnus-article-treat
1035 :type gnus-article-treat-head-custom)
1037 (defcustom gnus-treat-date-iso8601 nil
1038 "Display the date in the ISO8601 format.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See Info node `(gnus)Customizing Articles' for details."
1042 :group 'gnus-article-treat
1043 :type gnus-article-treat-head-custom)
1045 (defcustom gnus-treat-date-user-defined nil
1046 "Display the date in a user-defined format.
1047 The format is defined by the `gnus-article-time-format' variable.
1048 Valid values are nil, t, `head', `last', an integer or a predicate.
1049 See Info node `(gnus)Customizing Articles' for details."
1050 :group 'gnus-article-treat
1051 :type gnus-article-treat-head-custom)
1053 (defcustom gnus-treat-strip-headers-in-body t
1054 "Strip the X-No-Archive header line from the beginning of the body.
1055 Valid values are nil, t, `head', `last', an integer or a predicate.
1056 See Info node `(gnus)Customizing Articles' for details."
1058 :group 'gnus-article-treat
1059 :type gnus-article-treat-custom)
1061 (defcustom gnus-treat-strip-trailing-blank-lines nil
1062 "Strip trailing blank lines.
1063 Valid values are nil, t, `head', `last', an integer or a predicate.
1064 See Info node `(gnus)Customizing Articles' for details."
1065 :group 'gnus-article-treat
1066 :type gnus-article-treat-custom)
1068 (defcustom gnus-treat-strip-leading-blank-lines nil
1069 "Strip leading blank lines.
1070 Valid values are nil, t, `head', `last', an integer or a predicate.
1071 See Info node `(gnus)Customizing Articles' for details."
1072 :group 'gnus-article-treat
1073 :type gnus-article-treat-custom)
1075 (defcustom gnus-treat-strip-multiple-blank-lines nil
1076 "Strip multiple blank lines.
1077 Valid values are nil, t, `head', `last', an integer or a predicate.
1078 See Info node `(gnus)Customizing Articles' for details."
1079 :group 'gnus-article-treat
1080 :type gnus-article-treat-custom)
1082 (defcustom gnus-treat-unfold-headers 'head
1083 "Unfold folded header lines.
1084 Valid values are nil, t, `head', `last', an integer or a predicate.
1085 See Info node `(gnus)Customizing Articles' for details."
1086 :group 'gnus-article-treat
1087 :type gnus-article-treat-custom)
1089 (defcustom gnus-treat-fold-headers nil
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 :type gnus-article-treat-custom)
1096 (defcustom gnus-treat-fold-newsgroups 'head
1097 "Fold the Newsgroups and Followup-To headers.
1098 Valid values are nil, t, `head', `last', an integer or a predicate.
1099 See Info node `(gnus)Customizing Articles' for details."
1100 :group 'gnus-article-treat
1101 :type gnus-article-treat-custom)
1103 (defcustom gnus-treat-overstrike t
1104 "Treat overstrike highlighting.
1105 Valid values are nil, t, `head', `last', an integer or a predicate.
1106 See Info node `(gnus)Customizing Articles' for details."
1107 :group 'gnus-article-treat
1108 :type gnus-article-treat-custom)
1109 (put 'gnus-treat-overstrike 'highlight t)
1111 (defcustom gnus-treat-display-xface
1112 (and (not noninteractive)
1113 (or (and (fboundp 'image-type-available-p)
1114 (image-type-available-p 'xbm)
1115 (string-match "^0x" (shell-command-to-string "uncompface")))
1116 (and (featurep 'xemacs)
1118 (eq 'x-face-mule-gnus-article-display-x-face
1119 gnus-article-x-face-command))
1121 "Display X-Face headers.
1122 Valid values are nil, t, `head', `last', an integer or a predicate.
1123 See Info node `(gnus)Customizing Articles' and Info node
1124 `(gnus)X-Face' for details."
1125 :group 'gnus-article-treat
1127 :type gnus-article-treat-head-custom)
1128 (put 'gnus-treat-display-xface 'highlight t)
1130 (defcustom gnus-article-should-use-smiley-mule
1131 (not (or (featurep 'xemacs)
1132 (gnus-image-type-available-p 'xpm)
1133 (gnus-image-type-available-p 'pbm)))
1134 "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
1135 `smiley'. It defaults to t when Emacs 20 or earlier is running.
1136 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1137 even if you are using Emacs 21+. It has no effect on XEmacs."
1138 :group 'gnus-article-various
1140 :get (lambda (symbol)
1141 (and (default-value symbol)
1142 (not (featurep 'xemacs))
1143 (module-installed-p 'smiley-mule)
1145 :set (lambda (symbol value)
1146 (set-default symbol (and value
1147 (not (featurep 'xemacs))
1148 (module-installed-p 'smiley-mule)
1151 (defvar gnus-article-smiley-mule-loaded-p nil
1152 "Internal variable used to say whether `smiley-mule' is loaded (whether
1153 smiley functions are not overridden by `smiley').")
1155 (defcustom gnus-treat-display-grey-xface
1156 (and (not noninteractive)
1157 (or (featurep 'xemacs)
1158 (and (fboundp 'display-images-p)
1159 (display-images-p)))
1160 (string-match "^0x" (shell-command-to-string "uncompface"))
1162 "Display grey X-Face headers.
1163 Valid values are nil, t."
1164 :group 'gnus-article-treat
1167 (put 'gnus-treat-display-grey-xface 'highlight t)
1169 (defcustom gnus-treat-display-smileys
1170 (if (or (and (featurep 'xemacs)
1172 (gnus-image-type-available-p 'xpm)
1173 (gnus-image-type-available-p 'pbm)
1174 (and (not (featurep 'xemacs))
1176 (module-installed-p 'smiley-mule)))
1180 Valid values are nil, t, `head', `last', an integer or a predicate.
1181 See Info node `(gnus)Customizing Articles' and Info node
1182 `(gnus)Smileys' for details."
1183 :group 'gnus-article-treat
1185 :type gnus-article-treat-custom)
1186 (put 'gnus-treat-display-smileys 'highlight t)
1188 (defcustom gnus-treat-from-picon
1189 (if (and (gnus-image-type-available-p 'xpm)
1190 (gnus-picons-installed-p))
1192 "Display picons in the From header.
1193 Valid values are nil, t, `head', `last', an integer or a predicate.
1194 See Info node `(gnus)Customizing Articles' and Info node
1195 `(gnus)Picons' for details."
1196 :group 'gnus-article-treat
1198 :link '(info-link "(gnus)Customizing Articles")
1199 :link '(info-link "(gnus)Picons")
1200 :type gnus-article-treat-head-custom)
1201 (put 'gnus-treat-from-picon 'highlight t)
1203 (defcustom gnus-treat-mail-picon
1204 (if (and (gnus-image-type-available-p 'xpm)
1205 (gnus-picons-installed-p))
1207 "Display picons in To and Cc headers.
1208 Valid values are nil, t, `head', `last', an integer or a predicate.
1209 See Info node `(gnus)Customizing Articles' and Info node
1210 `(gnus)Picons' for details."
1211 :group 'gnus-article-treat
1213 :link '(info-link "(gnus)Customizing Articles")
1214 :link '(info-link "(gnus)Picons")
1215 :type gnus-article-treat-head-custom)
1216 (put 'gnus-treat-mail-picon 'highlight t)
1218 (defcustom gnus-treat-newsgroups-picon
1219 (if (and (gnus-image-type-available-p 'xpm)
1220 (gnus-picons-installed-p))
1222 "Display picons in the Newsgroups and Followup-To headers.
1223 Valid values are nil, t, `head', `last', an integer or a predicate.
1224 See Info node `(gnus)Customizing Articles' and Info node
1225 `(gnus)Picons' for details."
1226 :group 'gnus-article-treat
1228 :link '(info-link "(gnus)Customizing Articles")
1229 :link '(info-link "(gnus)Picons")
1230 :type gnus-article-treat-head-custom)
1231 (put 'gnus-treat-newsgroups-picon 'highlight t)
1233 (defcustom gnus-treat-body-boundary
1234 (if (or gnus-treat-newsgroups-picon
1235 gnus-treat-mail-picon
1236 gnus-treat-from-picon)
1238 "Draw a boundary at the end of the headers.
1239 Valid values are nil, t, `head', `last', an integer or a predicate.
1240 See Info node `(gnus)Customizing Articles' for details."
1242 :group 'gnus-article-treat
1243 :type gnus-article-treat-custom)
1245 (defcustom gnus-treat-capitalize-sentences nil
1246 "Capitalize sentence-starting words.
1247 Valid values are nil, t, `head', `last', an integer or a predicate.
1248 See Info node `(gnus)Customizing Articles' for details."
1250 :group 'gnus-article-treat
1251 :type gnus-article-treat-custom)
1253 (defcustom gnus-treat-fill-long-lines nil
1255 Valid values are nil, t, `head', `last', an integer or a predicate.
1256 See Info node `(gnus)Customizing Articles' for details."
1257 :group 'gnus-article-treat
1258 :type gnus-article-treat-custom)
1260 (defcustom gnus-treat-play-sounds nil
1262 Valid values are nil, t, `head', `last', an integer or a predicate.
1263 See Info node `(gnus)Customizing Articles' for details."
1265 :group 'gnus-article-treat
1266 :type gnus-article-treat-custom)
1268 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1269 "Decode an article as `default-mime-charset'. For instance, if you want to
1270 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1271 you could set this variable to something like: nil for don't decode, t for
1272 decode the body, '(or header t) for the whole article, etc."
1273 :group 'gnus-article-treat
1274 :type '(radio (const :tag "Off" nil)
1275 (const :tag "Decode body" t)
1276 (const :tag "Decode all" (or head t))))
1278 (defcustom gnus-treat-translate nil
1279 "Translate articles from one language to another.
1280 Valid values are nil, t, `head', `last', an integer or a predicate.
1281 See Info node `(gnus)Customizing Articles' for details."
1283 :group 'gnus-article-treat
1284 :type gnus-article-treat-custom)
1286 (defcustom gnus-treat-x-pgp-sig nil
1288 To automatically treat X-PGP-Sig, set it to head.
1289 Valid values are nil, t, `head', `last', an integer or a predicate.
1290 See Info node `(gnus)Customizing Articles' for details."
1291 :group 'gnus-article-treat
1292 :group 'mime-security
1293 :type gnus-article-treat-custom)
1295 (defcustom gnus-treat-monafy nil
1296 "Display body part with mona font.
1297 Valid values are nil, t, `head', `last', an integer or a predicate.
1298 See Info node `(gnus)Customizing Articles' for details."
1299 :group 'gnus-article-treat
1300 :group 'mime-security
1301 :type gnus-article-treat-custom)
1303 (defvar gnus-article-encrypt-protocol-alist
1304 '(("PGP" . mml2015-self-encrypt)))
1306 ;; Set to nil if more than one protocol added to
1307 ;; gnus-article-encrypt-protocol-alist.
1308 (defcustom gnus-article-encrypt-protocol "PGP"
1309 "The protocol used for encrypt articles.
1310 It is a string, such as \"PGP\". If nil, ask user."
1312 :group 'mime-security)
1314 (defvar gnus-article-wash-function nil
1315 "Function used for converting HTML into text.")
1317 ;;; Internal variables
1319 (defvar gnus-english-month-names
1320 '("January" "February" "March" "April" "May" "June" "July" "August"
1321 "September" "October" "November" "December"))
1323 (defvar article-goto-body-goes-to-point-min-p nil)
1324 (defvar gnus-article-wash-types nil)
1325 (defvar gnus-article-emphasis-alist nil)
1326 (defvar gnus-article-image-alist nil)
1328 (defvar gnus-article-mime-handle-alist-1 nil)
1329 (defvar gnus-treatment-function-alist
1330 '((gnus-treat-decode-article-as-default-mime-charset
1331 gnus-article-decode-article-as-default-mime-charset)
1332 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1333 (gnus-treat-monafy gnus-article-monafy)
1334 (gnus-treat-strip-banner gnus-article-strip-banner)
1335 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1336 (gnus-treat-buttonize gnus-article-add-buttons)
1337 (gnus-treat-fill-article gnus-article-fill-cited-article)
1338 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1339 (gnus-treat-strip-cr gnus-article-remove-cr)
1340 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1341 (gnus-treat-date-ut gnus-article-date-ut)
1342 (gnus-treat-date-local gnus-article-date-local)
1343 (gnus-treat-date-english gnus-article-date-english)
1344 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1345 (gnus-treat-date-original gnus-article-date-original)
1346 (gnus-treat-date-user-defined gnus-article-date-user)
1347 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1348 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1349 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1350 (gnus-treat-hide-signature gnus-article-hide-signature)
1351 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1352 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1353 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1354 (gnus-treat-strip-pem gnus-article-hide-pem)
1355 (gnus-treat-from-picon gnus-treat-from-picon)
1356 (gnus-treat-mail-picon gnus-treat-mail-picon)
1357 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1358 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1359 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1360 (gnus-treat-strip-trailing-blank-lines
1361 gnus-article-remove-trailing-blank-lines)
1362 (gnus-treat-strip-leading-blank-lines
1363 gnus-article-strip-leading-blank-lines)
1364 (gnus-treat-strip-multiple-blank-lines
1365 gnus-article-strip-multiple-blank-lines)
1366 (gnus-treat-overstrike gnus-article-treat-overstrike)
1367 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1368 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1369 ;; Displaying X-Face should be done after unfolding headers
1370 ;; to protect bitmap lines.
1371 (gnus-treat-display-xface gnus-article-display-x-face)
1372 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1373 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1374 (gnus-treat-display-smileys gnus-treat-smiley)
1375 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1376 (gnus-treat-emphasize gnus-article-emphasize)
1377 (gnus-treat-hide-citation gnus-article-hide-citation)
1378 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1379 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1380 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1381 (gnus-treat-play-sounds gnus-earcon-display)))
1383 (defvar gnus-article-mime-handle-alist nil)
1384 (defvar article-lapsed-timer nil)
1385 (defvar gnus-article-current-summary nil)
1387 (defvar gnus-article-mode-syntax-table
1388 (let ((table (copy-syntax-table text-mode-syntax-table)))
1389 ;; This causes the citation match run O(2^n).
1390 ;; (modify-syntax-entry ?- "w" table)
1391 (modify-syntax-entry ?> ")<" table)
1392 (modify-syntax-entry ?< "(>" table)
1394 "Syntax table used in article mode buffers.
1395 Initialized from `text-mode-syntax-table.")
1397 (defvar gnus-save-article-buffer nil)
1399 (defvar gnus-article-mode-line-format-alist
1400 (nconc '((?w (gnus-article-wash-status) ?s)
1401 (?m (gnus-article-mime-part-status) ?s))
1402 gnus-summary-mode-line-format-alist))
1404 (defvar gnus-number-of-articles-to-be-saved nil)
1406 (defvar gnus-inhibit-hiding nil)
1408 ;;; Macros for dealing with the article buffer.
1410 (defmacro gnus-with-article-headers (&rest forms)
1412 (set-buffer gnus-article-buffer)
1414 (let ((buffer-read-only nil)
1415 (inhibit-point-motion-hooks t)
1416 (case-fold-search t))
1417 (article-narrow-to-head)
1420 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1421 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1423 (defmacro gnus-with-article-buffer (&rest forms)
1425 (set-buffer gnus-article-buffer)
1426 (let ((buffer-read-only nil))
1429 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1430 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1432 (defun gnus-article-goto-header (header)
1433 "Go to HEADER, which is a regular expression."
1434 (re-search-forward (concat "^\\(" header "\\):") nil t))
1436 (defsubst gnus-article-hide-text (b e props)
1437 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1438 (gnus-add-text-properties-when 'article-type nil b e props)
1439 (when (memq 'intangible props)
1441 (max (1- b) (point-min))
1442 b 'intangible (cddr (memq 'intangible props)))))
1444 (defsubst gnus-article-unhide-text (b e)
1445 "Remove hidden text properties from region between B and E."
1446 (remove-text-properties b e gnus-hidden-properties)
1447 (when (memq 'intangible gnus-hidden-properties)
1448 (put-text-property (max (1- b) (point-min))
1449 b 'intangible nil)))
1451 (defun gnus-article-hide-text-type (b e type)
1452 "Hide text of TYPE between B and E."
1453 (gnus-add-wash-type type)
1454 (gnus-article-hide-text
1455 b e (cons 'article-type (cons type gnus-hidden-properties))))
1457 (defun gnus-article-unhide-text-type (b e type)
1458 "Unhide text of TYPE between B and E."
1459 (gnus-delete-wash-type type)
1460 (remove-text-properties
1461 b e (cons 'article-type (cons type gnus-hidden-properties)))
1462 (when (memq 'intangible gnus-hidden-properties)
1463 (put-text-property (max (1- b) (point-min))
1464 b 'intangible nil)))
1466 (defun gnus-article-hide-text-of-type (type)
1467 "Hide text of TYPE in the current buffer."
1469 (let ((b (point-min))
1471 (while (setq b (text-property-any b e 'article-type type))
1472 (add-text-properties b (incf b) gnus-hidden-properties)))))
1474 (defun gnus-article-delete-text-of-type (type)
1475 "Delete text of TYPE in the current buffer."
1477 (let ((b (point-min)))
1478 (while (setq b (text-property-any b (point-max) 'article-type type))
1480 b (or (text-property-not-all b (point-max) 'article-type type)
1483 (defun gnus-article-delete-invisible-text ()
1484 "Delete all invisible text in the current buffer."
1486 (let ((b (point-min)))
1487 (while (setq b (text-property-any b (point-max) 'invisible t))
1489 b (or (text-property-not-all b (point-max) 'invisible t)
1492 (defun gnus-article-text-type-exists-p (type)
1493 "Say whether any text of type TYPE exists in the buffer."
1494 (text-property-any (point-min) (point-max) 'article-type type))
1496 (defsubst gnus-article-header-rank ()
1497 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1498 (let ((list gnus-sorted-header-list)
1501 (when (looking-at (car list))
1503 (setq list (cdr list))
1507 (defun article-hide-headers (&optional arg delete)
1508 "Hide unwanted headers and possibly sort them as well."
1509 (interactive (gnus-article-hidden-arg))
1510 ;; Lars said that this function might be inhibited.
1511 (if (gnus-article-check-hidden-text 'headers arg)
1513 ;; Show boring headers as well.
1514 (gnus-article-show-hidden-text 'boring-headers)
1515 (when (eq 1 (point-min))
1516 (set-window-start (get-buffer-window (current-buffer)) 1)))
1517 (unless gnus-inhibit-hiding
1520 (let ((inhibit-read-only t)
1521 (case-fold-search t)
1522 (max (1+ (length gnus-sorted-header-list)))
1523 (ignored (when (not gnus-visible-headers)
1524 (cond ((stringp gnus-ignored-headers)
1525 gnus-ignored-headers)
1526 ((listp gnus-ignored-headers)
1527 (mapconcat 'identity gnus-ignored-headers
1530 (cond ((stringp gnus-visible-headers)
1531 gnus-visible-headers)
1532 ((and gnus-visible-headers
1533 (listp gnus-visible-headers))
1534 (mapconcat 'identity gnus-visible-headers "\\|"))))
1535 (inhibit-point-motion-hooks t)
1537 ;; First we narrow to just the headers.
1538 (article-narrow-to-head)
1539 ;; Hide any "From " lines at the beginning of (mail) articles.
1540 (while (looking-at "From ")
1544 (delete-region (point-min) (point))
1545 (gnus-article-hide-text (point-min) (point)
1546 (nconc (list 'article-type 'headers)
1547 gnus-hidden-properties))))
1548 ;; Then treat the rest of the header lines.
1549 ;; Then we use the two regular expressions
1550 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1551 ;; select which header lines is to remain visible in the
1553 (while (re-search-forward "^[^ \t:]*:" nil t)
1555 ;; Mark the rank of the header.
1557 (point) (1+ (point)) 'message-rank
1558 (if (or (and visible (looking-at visible))
1560 (not (looking-at ignored))))
1561 (gnus-article-header-rank)
1564 (message-sort-headers-1)
1565 (when (setq beg (text-property-any
1566 (point-min) (point-max) 'message-rank (+ 2 max)))
1567 ;; We delete or make invisible the unwanted headers.
1568 (gnus-add-wash-type 'headers)
1571 (add-text-properties
1572 (point-min) (+ 5 (point-min))
1573 '(article-type headers dummy-invisible t))
1574 (delete-region beg (point-max)))
1575 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1577 (defun article-hide-boring-headers (&optional arg)
1578 "Toggle hiding of headers that aren't very interesting.
1579 If given a negative prefix, always show; if given a positive prefix,
1581 (interactive (gnus-article-hidden-arg))
1582 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1583 (not gnus-show-all-headers))
1586 (let ((buffer-read-only nil)
1587 (list gnus-boring-article-headers)
1588 (inhibit-point-motion-hooks t)
1590 (article-narrow-to-head)
1592 (setq elem (pop list))
1593 (goto-char (point-min))
1595 ;; Hide empty headers.
1597 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1599 (gnus-article-hide-text-type
1600 (progn (beginning-of-line) (point))
1603 (if (re-search-forward "^[^ \t]" nil t)
1607 ;; Hide boring Newsgroups header.
1608 ((eq elem 'newsgroups)
1609 (when (gnus-string-equal
1610 (gnus-fetch-field "newsgroups")
1611 (gnus-group-real-name
1612 (if (boundp 'gnus-newsgroup-name)
1615 (gnus-article-hide-header "newsgroups")))
1616 ((eq elem 'to-address)
1617 (let ((to (message-fetch-field "to"))
1619 (gnus-parameter-to-address
1620 (if (boundp 'gnus-newsgroup-name)
1621 gnus-newsgroup-name ""))))
1622 (when (and to to-address
1625 ;; only one address in To
1626 (nth 1 (mail-extract-address-components to))
1628 (gnus-article-hide-header "to"))))
1629 ((eq elem 'followup-to)
1630 (when (gnus-string-equal
1631 (message-fetch-field "followup-to")
1632 (message-fetch-field "newsgroups"))
1633 (gnus-article-hide-header "followup-to")))
1634 ((eq elem 'reply-to)
1635 (let ((from (message-fetch-field "from"))
1636 (reply-to (message-fetch-field "reply-to")))
1641 (nth 1 (mail-extract-address-components from))
1642 (nth 1 (mail-extract-address-components reply-to)))))
1643 (gnus-article-hide-header "reply-to"))))
1645 (let ((date (message-fetch-field "date")))
1647 (< (days-between (current-time-string) date)
1649 (gnus-article-hide-header "date"))))
1651 (let ((to (message-fetch-field "to"))
1652 (cc (message-fetch-field "cc")))
1653 (when (> (length to) 1024)
1654 (gnus-article-hide-header "to"))
1655 (when (> (length cc) 1024)
1656 (gnus-article-hide-header "cc"))))
1660 (goto-char (point-min))
1661 (while (re-search-forward "^to:" nil t)
1662 (setq to-count (1+ to-count)))
1663 (when (> to-count 1)
1664 (while (> to-count 0)
1665 (goto-char (point-min))
1667 (re-search-forward "^to:" nil nil to-count)
1669 (narrow-to-region (point) (point-max))
1670 (gnus-article-hide-header "to"))
1671 (setq to-count (1- to-count))))
1672 (goto-char (point-min))
1673 (while (re-search-forward "^cc:" nil t)
1674 (setq cc-count (1+ cc-count)))
1675 (when (> cc-count 1)
1676 (while (> cc-count 0)
1677 (goto-char (point-min))
1679 (re-search-forward "^cc:" nil nil cc-count)
1681 (narrow-to-region (point) (point-max))
1682 (gnus-article-hide-header "cc"))
1683 (setq cc-count (1- cc-count)))))))))))))
1685 (defun gnus-article-hide-header (header)
1687 (goto-char (point-min))
1688 (when (re-search-forward (concat "^" header ":") nil t)
1689 (gnus-article-hide-text-type
1690 (progn (beginning-of-line) (point))
1693 (if (re-search-forward "^[^ \t]" nil t)
1698 (defun article-toggle-headers (&optional arg)
1699 "Toggle hiding of headers. If given a negative prefix, always show;
1700 if given a positive prefix, always hide."
1701 (interactive (gnus-article-hidden-arg))
1702 (let ((force (when (numberp arg)
1703 (cond ((> arg 0) 'always-hide)
1704 ((< arg 0) 'always-show))))
1705 (window (get-buffer-window gnus-article-buffer))
1706 (header-end (point-min))
1707 header-start field-end field-start
1708 (inhibit-point-motion-hooks t)
1709 (inhibit-read-only t))
1712 (while (and (setq header-start
1713 (text-property-any header-end (point-max)
1714 'article-treated-header t))
1716 (text-property-not-all header-start (point-max)
1717 'article-treated-header t)))
1718 (setq field-end header-start)
1720 (;; Hide exposed invisible fields.
1721 (and (not (eq 'always-show force))
1723 (text-property-any field-end header-end
1724 'exposed-invisible-field t)))
1725 (while (and field-start
1726 (setq field-end (text-property-not-all
1727 field-start header-end
1728 'exposed-invisible-field t)))
1729 (add-text-properties field-start field-end gnus-hidden-properties)
1730 (setq field-start (text-property-any field-end header-end
1731 'exposed-invisible-field t)))
1732 (put-text-property header-start header-end
1733 'exposed-invisible-field nil))
1734 (;; Expose invisible fields.
1735 (and (not (eq 'always-hide force))
1737 (text-property-any field-end header-end 'invisible t)))
1738 (while (and field-start
1739 (setq field-end (text-property-not-all
1740 field-start header-end
1742 ;; If the invisible text is not terminated with newline, we
1743 ;; won't expose it. Because it may be created by x-face-mule.
1744 ;; BTW, XEmacs sometimes fail in putting an invisible text
1745 ;; property with `gnus-article-hide-text' (really?). In that
1746 ;; case, the invisible text might be started from the middle of
1747 ;; a line, so we will expose the sort of thing.
1748 (when (or (not (or (eq header-start field-start)
1749 (eq ?\n (char-before field-start))))
1750 (eq ?\n (char-before field-end))
1751 ;; Expose a boundary line anyway.
1754 (buffer-substring (max (- field-end 13) header-start)
1756 (remove-text-properties field-start field-end
1757 gnus-hidden-properties)
1758 (put-text-property field-start field-end
1759 'exposed-invisible-field t))
1760 (setq field-start (text-property-any field-end header-end
1763 (not (eq 'always-show force))
1764 (narrow-to-region header-start header-end)
1765 (article-hide-headers)
1766 ;; Re-display X-Face image under XEmacs.
1767 (when (and (featurep 'xemacs)
1768 (gnus-functionp gnus-article-x-face-command))
1769 (let ((func (cadr (assq 'gnus-treat-display-xface
1770 gnus-treatment-function-alist)))
1772 (when (and (not gnus-inhibit-treatment)
1774 (gnus-treat-predicate gnus-treat-display-xface))
1776 (put-text-property header-start header-end 'read-only nil))))
1779 (goto-char (point-min))
1781 (set-window-start window (point-min))))))
1783 (defvar gnus-article-normalized-header-length 40
1784 "Length of normalized headers.")
1786 (defun article-normalize-headers ()
1787 "Make all header lines 40 characters long."
1789 (let ((buffer-read-only nil)
1793 (article-narrow-to-head)
1796 ((< (setq column (- (gnus-point-at-eol) (point)))
1797 gnus-article-normalized-header-length)
1799 (insert (make-string
1800 (- gnus-article-normalized-header-length column)
1802 ((> column gnus-article-normalized-header-length)
1803 (gnus-put-text-property
1805 (forward-char gnus-article-normalized-header-length)
1812 (forward-line 1))))))
1814 (defun article-treat-dumbquotes ()
1815 "Translate M****s*** sm*rtq**t*s into proper text.
1816 Note that this function guesses whether a character is a sm*rtq**t* or
1817 not, so it should only be used interactively.
1819 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1820 in an attempt to provide more quoting characters. If you see
1821 something like \\222 or \\264 where you're expecting some kind of
1822 apostrophe or quotation mark, then try this wash."
1824 (article-translate-strings gnus-article-dumbquotes-map))
1826 (defun article-translate-characters (from to)
1827 "Translate all characters in the body of the article according to FROM and TO.
1828 FROM is a string of characters to translate from; to is a string of
1829 characters to translate to."
1831 (when (article-goto-body)
1832 (let ((buffer-read-only nil)
1833 (x (make-string 225 ?x))
1835 (while (< (incf i) (length x))
1838 (while (< i (length from))
1839 (aset x (aref from i) (aref to i))
1841 (translate-region (point) (point-max) x)))))
1843 (defun article-translate-strings (map)
1844 "Translate all string in the body of the article according to MAP.
1845 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1847 (when (article-goto-body)
1848 (let ((buffer-read-only nil)
1850 (while (setq elem (pop map))
1852 (while (search-forward (car elem) nil t)
1853 (replace-match (cadr elem)))))))))
1855 (defun article-treat-overstrike ()
1856 "Translate overstrikes into bold text."
1859 (when (article-goto-body)
1860 (let ((buffer-read-only nil))
1861 (while (search-forward "\b" nil t)
1862 (let ((next (char-after))
1866 previous (char-after))
1870 ;; We do the boldification/underlining by hiding the
1871 ;; overstrikes and putting the proper text property
1875 (gnus-article-hide-text-type start (point) 'overstrike)
1876 (put-text-property (point) end 'face 'bold))
1878 (gnus-article-hide-text-type
1879 (1- (point)) (1+ (point)) 'overstrike)
1881 start (1- (point)) 'face 'underline))
1883 (gnus-article-hide-text-type start (point) 'overstrike)
1885 (point) end 'face 'underline)))))))))
1887 (defun gnus-article-treat-unfold-headers ()
1888 "Unfold folded message headers.
1889 Only the headers that fit into the current window width will be
1892 (gnus-with-article-headers
1896 (mail-header-narrow-to-field)
1897 (let ((header (buffer-substring (point-min) (point-max))))
1900 (goto-char (point-min))
1901 (while (re-search-forward "\n[\t ]" nil t)
1902 (replace-match " " t t)))
1903 (setq length (- (point-max) (point-min) 1)))
1904 (when (< length (window-width))
1905 (while (re-search-forward "\n[\t ]" nil t)
1906 (replace-match " " t t)))
1907 (goto-char (point-max)))))))
1909 (defun gnus-article-treat-fold-headers ()
1910 "Fold message headers."
1912 (gnus-with-article-headers
1915 (mail-header-narrow-to-field)
1916 (mail-header-fold-field)
1917 (goto-char (point-max))))))
1919 (defun gnus-treat-smiley ()
1920 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1922 (unless (featurep 'xemacs)
1923 (when (and (>= emacs-major-version 21)
1924 (not gnus-article-should-use-smiley-mule)
1925 gnus-article-smiley-mule-loaded-p)
1926 (load "smiley" nil t)
1927 (setq gnus-article-smiley-mule-loaded-p nil))
1928 (when (and gnus-article-should-use-smiley-mule
1929 (not gnus-article-smiley-mule-loaded-p))
1930 (load "smiley-mule" nil t)
1931 (setq gnus-article-smiley-mule-loaded-p t)))
1932 (gnus-with-article-buffer
1933 (if (memq 'smiley gnus-article-wash-types)
1934 (gnus-delete-images 'smiley)
1936 (let ((images (smiley-region (point) (point-max))))
1938 (gnus-add-wash-type 'smiley)
1939 (dolist (image images)
1940 (gnus-add-image 'smiley image)))))))
1942 (defun gnus-article-remove-images ()
1943 "Remove all images from the article buffer."
1945 (gnus-with-article-buffer
1946 (dolist (elem gnus-article-image-alist)
1947 (gnus-delete-images (car elem)))))
1949 (defun gnus-article-treat-fold-newsgroups ()
1950 "Unfold folded message headers.
1951 Only the headers that fit into the current window width will be
1954 (gnus-with-article-headers
1955 (while (gnus-article-goto-header "newsgroups\\|followup-to")
1957 (mail-header-narrow-to-field)
1958 (while (re-search-forward ", *" nil t)
1959 (replace-match ", " t t))
1960 (mail-header-fold-field)
1961 (goto-char (point-max))))))
1963 (defun gnus-article-treat-body-boundary ()
1964 "Place a boundary line at the end of the headers."
1966 (when (and gnus-body-boundary-delimiter
1967 (> (length gnus-body-boundary-delimiter) 0))
1968 (gnus-with-article-headers
1969 (goto-char (point-max))
1970 (let ((start (point)))
1971 (insert "X-Boundary: ")
1972 (gnus-add-text-properties start (point) '(invisible t intangible t))
1974 (while (>= (1- (window-width)) (length str))
1975 (setq str (concat str gnus-body-boundary-delimiter)))
1976 (substring str 0 (1- (window-width))))
1978 (gnus-add-text-properties start (point) '(gnus-decoration 'header))))))
1980 (defun article-fill-long-lines ()
1981 "Fill lines that are wider than the window width."
1984 (let ((buffer-read-only nil)
1985 (width (window-width (get-buffer-window (current-buffer)))))
1988 (let ((adaptive-fill-mode nil)) ;Why? -sm
1991 (when (>= (current-column) (min fill-column width))
1992 (narrow-to-region (point) (gnus-point-at-bol))
1993 (fill-paragraph nil)
1994 (goto-char (point-max))
1996 (forward-line 1)))))))
1998 (defun article-capitalize-sentences ()
1999 "Capitalize the first word in each sentence."
2002 (let ((buffer-read-only nil)
2003 (paragraph-start "^[\n\^L]"))
2007 (forward-sentence)))))
2009 (defun article-remove-cr ()
2010 "Remove trailing CRs and then translate remaining CRs into LFs."
2013 (let ((buffer-read-only nil))
2014 (goto-char (point-min))
2015 (while (re-search-forward "\r+$" nil t)
2016 (replace-match "" t t))
2017 (goto-char (point-min))
2018 (while (search-forward "\r" nil t)
2019 (replace-match "\n" t t)))))
2021 (defun article-remove-trailing-blank-lines ()
2022 "Remove all trailing blank lines from the article."
2025 (let ((buffer-read-only nil))
2026 (goto-char (point-max))
2030 (while (and (not (bobp))
2031 (looking-at "^[ \t]*$")
2032 (not (gnus-annotation-in-region-p
2033 (point) (gnus-point-at-eol))))
2038 (defun article-display-x-face (&optional force)
2039 "Look for an X-Face header and display it if present."
2040 (interactive (list 'force))
2041 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2042 (gnus-with-article-headers
2043 ;; Delete the old process, if any.
2044 (when (process-status "article-x-face")
2045 (delete-process "article-x-face"))
2046 (if (memq 'xface gnus-article-wash-types)
2047 ;; We have already displayed X-Faces, so we remove them
2049 (gnus-delete-images 'xface)
2051 (let (x-faces from face grey)
2053 (when (and wash-face-p
2055 (goto-char (point-min))
2056 (not (re-search-forward
2057 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2058 (gnus-buffer-live-p gnus-original-article-buffer))
2059 ;; If type `W f', use gnus-original-article-buffer,
2060 ;; otherwise use the current buffer because displaying
2061 ;; RFC822 parts calls this function too.
2062 (set-buffer gnus-original-article-buffer))
2064 (mail-narrow-to-head)
2065 (if gnus-treat-display-grey-xface
2067 (while (gnus-article-goto-header "X-Face\\(-[0-9]+\\)?")
2068 (if (match-beginning 2)
2071 (push (cons (- (string-to-number (match-string 2)))
2072 (mail-header-field-value))
2074 (push (cons 0 (mail-header-field-value)) x-faces)))
2075 (dolist (x-face (prog1
2077 (sort x-faces 'car-less-than-car)
2079 (setq x-faces nil)))
2080 (push (cdr x-face) x-faces)))
2081 (while (gnus-article-goto-header "X-Face")
2082 (push (mail-header-field-value) x-faces)))
2083 (setq from (message-fetch-field "from"))))
2085 (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
2088 (setq image (gnus-create-image xpm 'xpm t))
2089 (gnus-article-goto-header "from")
2091 (insert "From: [no `from' set]\n")
2093 (gnus-add-wash-type 'xface)
2094 (gnus-add-image 'xface image)
2095 (gnus-put-image image)))
2096 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2097 ;; single external face.
2098 (when (stringp gnus-article-x-face-command)
2099 (setq x-faces (list (car x-faces))))
2100 (while (and (setq face (pop x-faces))
2101 gnus-article-x-face-command
2103 ;; Check whether this face is censored.
2104 (not gnus-article-x-face-too-ugly)
2105 (and gnus-article-x-face-too-ugly from
2106 (not (string-match gnus-article-x-face-too-ugly
2108 ;; We display the face.
2109 (if (symbolp gnus-article-x-face-command)
2110 ;; The command is a lisp function, so we call it.
2111 (if (gnus-functionp gnus-article-x-face-command)
2112 (funcall gnus-article-x-face-command face)
2113 (error "%s is not a function" gnus-article-x-face-command))
2114 ;; The command is a string, so we interpret the command
2115 ;; as a, well, command, and fork it off.
2116 (let ((process-connection-type nil))
2117 (process-kill-without-query
2119 "article-x-face" nil shell-file-name shell-command-switch
2120 gnus-article-x-face-command))
2123 (process-send-region "article-x-face"
2124 (point-min) (point-max)))
2125 (process-send-eof "article-x-face"))))))))))
2127 (defun article-decode-mime-words ()
2128 "Decode all MIME-encoded words in the article."
2131 (set-buffer gnus-article-buffer)
2132 (let ((inhibit-point-motion-hooks t)
2134 (mail-parse-charset gnus-newsgroup-charset)
2135 (mail-parse-ignored-charsets
2136 (save-excursion (set-buffer gnus-summary-buffer)
2137 gnus-newsgroup-ignored-charsets)))
2138 (mail-decode-encoded-word-region (point-min) (point-max)))))
2140 (defun article-decode-charset (&optional prompt)
2141 "Decode charset-encoded text in the article.
2142 If PROMPT (the prefix), prompt for a coding system to use."
2144 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2146 (mail-parse-charset gnus-newsgroup-charset)
2147 (mail-parse-ignored-charsets
2148 (save-excursion (condition-case nil
2149 (set-buffer gnus-summary-buffer)
2151 gnus-newsgroup-ignored-charsets))
2152 ct cte ctl charset format)
2155 (article-narrow-to-head)
2156 (setq ct (message-fetch-field "Content-Type" t)
2157 cte (message-fetch-field "Content-Transfer-Encoding" t)
2158 ctl (and ct (ignore-errors
2159 (mail-header-parse-content-type ct)))
2162 (mm-read-coding-system "Charset to decode: "))
2164 (mail-content-type-get ctl 'charset)))
2165 format (and ctl (mail-content-type-get ctl 'format)))
2167 (setq cte (mail-header-strip cte)))
2168 (if (and ctl (not (string-match "/" (car ctl))))
2170 (goto-char (point-max)))
2173 (narrow-to-region (point) (point-max))
2174 (when (and (eq mail-parse-charset 'gnus-decoded)
2175 (eq (mm-body-7-or-8) '8bit))
2176 ;; The text code could have been decoded.
2177 (setq charset mail-parse-charset))
2178 (when (and (or (not ctl)
2179 (equal (car ctl) "text/plain"))
2180 (not format)) ;; article with format will decode later.
2182 charset (and cte (intern (downcase
2183 (gnus-strip-whitespace cte))))
2186 (defun article-decode-encoded-words ()
2187 "Remove encoded-word encoding from headers."
2188 (let (buffer-read-only)
2189 (let ((charset (save-excursion
2190 (set-buffer gnus-summary-buffer)
2191 default-mime-charset)))
2192 (mime-decode-header-in-buffer charset))))
2194 (defun article-decode-group-name ()
2195 "Decode group names in `Newsgroups:'."
2196 (let ((inhibit-point-motion-hooks t)
2198 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2199 (when (and (or gnus-group-name-charset-method-alist
2200 gnus-group-name-charset-group-alist)
2201 (gnus-buffer-live-p gnus-original-article-buffer))
2202 (when (nnmail-fetch-field "Newsgroups")
2203 (nnheader-replace-header "Newsgroups"
2204 (gnus-decode-newsgroups
2205 (with-current-buffer
2206 gnus-original-article-buffer
2207 (nnmail-fetch-field "Newsgroups"))
2208 gnus-newsgroup-name method)))
2209 (when (nnmail-fetch-field "Followup-To")
2210 (nnheader-replace-header "Followup-To"
2211 (gnus-decode-newsgroups
2212 (with-current-buffer
2213 gnus-original-article-buffer
2214 (nnmail-fetch-field "Followup-To"))
2215 gnus-newsgroup-name method))))))
2217 (defun article-de-quoted-unreadable (&optional force read-charset)
2218 "Translate a quoted-printable-encoded article.
2219 If FORCE, decode the article whether it is marked as quoted-printable
2221 If READ-CHARSET, ask for a coding system."
2222 (interactive (list 'force current-prefix-arg))
2224 (let ((buffer-read-only nil) type charset)
2225 (if (gnus-buffer-live-p gnus-original-article-buffer)
2226 (with-current-buffer gnus-original-article-buffer
2228 (gnus-fetch-field "content-transfer-encoding"))
2229 (let* ((ct (gnus-fetch-field "content-type"))
2232 (mail-header-parse-content-type ct)))))
2233 (setq charset (and ctl
2234 (mail-content-type-get ctl 'charset)))
2235 (if (stringp charset)
2236 (setq charset (intern (downcase charset)))))))
2238 (setq charset (mm-read-coding-system "Charset: " charset)))
2240 (setq charset gnus-newsgroup-charset))
2242 (and type (let ((case-fold-search t))
2243 (string-match "quoted-printable" type))))
2245 (quoted-printable-decode-region
2246 (point) (point-max) (mm-charset-to-coding-system charset))))))
2248 (defun article-de-base64-unreadable (&optional force read-charset)
2249 "Translate a base64 article.
2250 If FORCE, decode the article whether it is marked as base64 not.
2251 If READ-CHARSET, ask for a coding system."
2252 (interactive (list 'force current-prefix-arg))
2254 (let ((buffer-read-only nil) type charset)
2255 (if (gnus-buffer-live-p gnus-original-article-buffer)
2256 (with-current-buffer gnus-original-article-buffer
2258 (gnus-fetch-field "content-transfer-encoding"))
2259 (let* ((ct (gnus-fetch-field "content-type"))
2262 (mail-header-parse-content-type ct)))))
2263 (setq charset (and ctl
2264 (mail-content-type-get ctl 'charset)))
2265 (if (stringp charset)
2266 (setq charset (intern (downcase charset)))))))
2268 (setq charset (mm-read-coding-system "Charset: " charset)))
2270 (setq charset gnus-newsgroup-charset))
2272 (and type (let ((case-fold-search t))
2273 (string-match "base64" type))))
2276 (narrow-to-region (point) (point-max))
2277 (base64-decode-region (point-min) (point-max))
2278 (mm-decode-coding-region
2279 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2284 (defun article-decode-HZ ()
2285 "Translate a HZ-encoded article."
2289 (let ((buffer-read-only nil))
2290 (rfc1843-decode-region (point-min) (point-max)))))
2292 (defun article-unsplit-urls ()
2293 "Remove the newlines that some other mailers insert into URLs."
2296 (let ((buffer-read-only nil))
2297 (goto-char (point-min))
2298 (while (re-search-forward
2299 "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2300 (replace-match "\\1\\3" t)))
2301 (when gnus-display-mime-function
2302 (funcall gnus-display-mime-function))))
2305 (defun article-wash-html (&optional read-charset)
2306 "Format an html article.
2307 If READ-CHARSET, ask for a coding system."
2310 (let ((buffer-read-only nil)
2312 (if (gnus-buffer-live-p gnus-original-article-buffer)
2313 (with-current-buffer gnus-original-article-buffer
2314 (let* ((ct (gnus-fetch-field "content-type"))
2317 (mail-header-parse-content-type ct)))))
2318 (setq charset (and ctl
2319 (mail-content-type-get ctl 'charset)))
2320 (if (stringp charset)
2321 (setq charset (intern (downcase charset)))))))
2323 (setq charset (mm-read-coding-system "Charset: " charset)))
2325 (setq charset gnus-newsgroup-charset))
2327 (save-window-excursion
2329 (narrow-to-region (point) (point-max))
2330 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2331 (entry (assq func mm-text-html-washer-alist)))
2333 (setq func (cdr entry)))
2335 ((gnus-functionp func)
2338 (apply (car func) (cdr func))))))))))
2340 (defun gnus-article-wash-html-with-w3 ()
2341 "Wash the current buffer with w3."
2343 (let ((w3-strict-width (window-width))
2344 (url-standalone-mode t)
2345 (url-gateway-unplugged t)
2346 (w3-honor-stylesheets nil))
2348 (w3-region (point-min) (point-max))
2351 (defun gnus-article-wash-html-with-w3m ()
2352 "Wash the current buffer with emacs-w3m."
2355 (narrow-to-region (point) (point-max))
2356 (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2359 (w3m-display-inline-images mm-inline-text-html-with-images)
2360 w3m-force-redisplay)
2361 (w3m-region (point-min) (point-max)))
2362 (when mm-inline-text-html-with-w3m-keymap
2363 (add-text-properties
2364 (point-min) (point-max)
2365 (append '(mm-inline-text-html-with-w3m t)
2366 (gnus-local-map-property mm-w3m-mode-map))))))
2368 (defun article-hide-list-identifiers ()
2369 "Remove list identifies from the Subject header.
2370 The `gnus-list-identifiers' variable specifies what to do."
2372 (let ((inhibit-point-motion-hooks t)
2373 (regexp (if (consp gnus-list-identifiers)
2374 (mapconcat 'identity gnus-list-identifiers " *\\|")
2375 gnus-list-identifiers))
2380 (article-narrow-to-head)
2381 (goto-char (point-min))
2382 (while (re-search-forward
2383 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2385 (delete-region (match-beginning 2) (match-end 0))
2386 (beginning-of-line))
2387 (when (re-search-forward
2388 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2389 (delete-region (match-beginning 1) (match-end 1))))))))
2391 (defun article-hide-pgp ()
2392 "Remove any PGP headers and signatures in the current article."
2396 (let ((inhibit-point-motion-hooks t)
2397 buffer-read-only beg end)
2399 ;; Hide the "header".
2400 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2401 (gnus-add-wash-type 'pgp)
2402 (delete-region (match-beginning 0) (match-end 0))
2403 ;; Remove armor headers (rfc2440 6.2)
2404 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2407 ;; Hide the actual signature.
2408 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2409 (setq end (1+ (match-beginning 0)))
2412 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2414 ;; Perhaps we shouldn't hide to the end of the buffer
2415 ;; if there is no end to the signature?
2417 ;; Hide "- " PGP quotation markers.
2419 (narrow-to-region beg end)
2420 (goto-char (point-min))
2421 (while (re-search-forward "^- " nil t)
2423 (match-beginning 0) (match-end 0)))
2425 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2427 (defun article-hide-pem (&optional arg)
2428 "Toggle hiding of any PEM headers and signatures in the current article.
2429 If given a negative prefix, always show; if given a positive prefix,
2431 (interactive (gnus-article-hidden-arg))
2432 (unless (gnus-article-check-hidden-text 'pem arg)
2434 (let (buffer-read-only end)
2435 (goto-char (point-min))
2436 ;; Hide the horrendously ugly "header".
2437 (when (and (search-forward
2438 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2440 (setq end (1+ (match-beginning 0))))
2441 (gnus-add-wash-type 'pem)
2442 (gnus-article-hide-text-type
2444 (if (search-forward "\n\n" nil t)
2448 ;; Hide the trailer as well
2449 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2451 (gnus-article-hide-text-type
2452 (match-beginning 0) (match-end 0) 'pem)))))))
2454 (defun article-strip-banner ()
2455 "Strip the banner specified by the `banner' group parameter."
2459 (let ((inhibit-point-motion-hooks t)
2460 (banner (gnus-parameter-banner gnus-newsgroup-name))
2461 (gnus-signature-limit nil)
2462 buffer-read-only beg end)
2466 ((eq banner 'signature)
2467 (when (gnus-article-narrow-to-signature)
2470 (delete-region (point) (point-max))))
2472 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2473 (while (re-search-forward banner nil t)
2474 (delete-region (match-beginning 0) (match-end 0)))))
2476 (while (re-search-forward banner nil t)
2477 (delete-region (match-beginning 0) (match-end 0))))))))))
2479 (defun article-babel ()
2480 "Translate article using an online translation service."
2484 (set-buffer gnus-article-buffer)
2485 (when (article-goto-body)
2486 (let* ((buffer-read-only nil)
2489 (orig (buffer-substring start end))
2490 (trans (babel-as-string orig)))
2492 (narrow-to-region start end)
2493 (delete-region start end)
2496 (defun article-hide-signature (&optional arg)
2497 "Hide the signature in the current article.
2498 If given a negative prefix, always show; if given a positive prefix,
2500 (interactive (gnus-article-hidden-arg))
2506 (article-goto-body))
2507 (goto-char (point-min)))
2508 (unless (gnus-article-check-hidden-text 'signature arg)
2509 (let ((buffer-read-only nil)
2511 (while (setq button (text-property-any button (point-max)
2513 'gnus-signature-toggle))
2514 (setq button (text-property-not-all button (point-max)
2516 'gnus-signature-toggle))
2517 (when (and button (not (eobp)))
2518 (gnus-article-hide-text-type
2520 (next-single-property-change (1+ button) 'mime-view-entity
2523 (gnus-set-mode-line 'article))
2525 (defun article-strip-headers-in-body ()
2526 "Strip offensive headers from bodies."
2530 (let ((case-fold-search t))
2531 (when (looking-at "x-no-archive:")
2532 (gnus-delete-line)))))
2534 (defun article-strip-leading-blank-lines ()
2535 "Remove all blank lines from the beginning of the article."
2538 (let ((inhibit-point-motion-hooks t)
2540 (when (article-goto-body)
2541 (while (and (not (eobp))
2542 (looking-at "[ \t]*$"))
2543 (gnus-delete-line))))))
2545 (defun article-narrow-to-head ()
2546 "Narrow the buffer to the head of the message.
2547 Point is left at the beginning of the narrowed-to region."
2549 (goto-char (point-min))
2550 (if (search-forward "\n\n" nil 1)
2553 (goto-char (point-min)))
2555 (defun article-goto-body ()
2556 "Place point at the start of the body."
2557 (goto-char (point-min))
2559 ;; This variable is only bound when dealing with separate
2561 (article-goto-body-goes-to-point-min-p
2563 ((search-forward "\n\n" nil t)
2566 (goto-char (point-max))
2569 (defun article-strip-multiple-blank-lines ()
2570 "Replace consecutive blank lines with one empty line."
2573 (let ((inhibit-point-motion-hooks t)
2575 ;; First make all blank lines empty.
2577 (while (re-search-forward "^[ \t]+$" nil t)
2578 (unless (gnus-annotation-in-region-p
2579 (match-beginning 0) (match-end 0))
2580 (replace-match "" nil t)))
2581 ;; Then replace multiple empty lines with a single empty line.
2583 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2584 (unless (gnus-annotation-in-region-p
2585 (match-beginning 0) (match-end 0))
2586 (delete-region (match-beginning 1) (match-end 1)))))))
2588 (defun article-strip-leading-space ()
2589 "Remove all white space from the beginning of the lines in the article."
2592 (let ((inhibit-point-motion-hooks t)
2595 (while (re-search-forward "^[ \t]+" nil t)
2596 (replace-match "" t t)))))
2598 (defun article-strip-trailing-space ()
2599 "Remove all white space from the end of the lines in the article."
2602 (let ((inhibit-point-motion-hooks t)
2605 (while (re-search-forward "[ \t]+$" nil t)
2606 (replace-match "" t t)))))
2608 (defun article-strip-blank-lines ()
2609 "Strip leading, trailing and multiple blank lines."
2611 (article-strip-leading-blank-lines)
2612 (article-remove-trailing-blank-lines)
2613 (article-strip-multiple-blank-lines))
2615 (defun article-strip-all-blank-lines ()
2616 "Strip all blank lines."
2619 (let ((inhibit-point-motion-hooks t)
2622 (while (re-search-forward "^[ \t]*\n" nil t)
2623 (replace-match "" t t)))))
2625 (defun gnus-article-narrow-to-signature ()
2626 "Narrow to the signature; return t if a signature is found, else nil."
2627 (let ((inhibit-point-motion-hooks t))
2628 (when (gnus-article-search-signature)
2630 ;; Check whether we have some limits to what we consider
2631 ;; to be a signature.
2632 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2633 (list gnus-signature-limit)))
2635 (while (setq limit (pop limits))
2636 (if (or (and (integerp limit)
2637 (< (- (point-max) (point)) limit))
2639 (< (count-lines (point) (point-max)) limit))
2640 (and (gnus-functionp limit)
2642 (and (stringp limit)
2643 (not (re-search-forward limit nil t))))
2644 () ; This limit did not succeed.
2648 (narrow-to-region (point) (point-max))
2651 (defun gnus-article-search-signature ()
2652 "Search the current buffer for the signature separator.
2653 Put point at the beginning of the signature separator."
2654 (let ((cur (point)))
2655 (goto-char (point-max))
2656 (if (if (stringp gnus-signature-separator)
2657 (re-search-backward gnus-signature-separator nil t)
2658 (let ((seps gnus-signature-separator))
2660 (not (re-search-backward (car seps) nil t)))
2667 (defun gnus-article-hidden-arg ()
2668 "Return the current prefix arg as a number, or 0 if no prefix."
2669 (list (if current-prefix-arg
2670 (prefix-numeric-value current-prefix-arg)
2673 (defun gnus-article-check-hidden-text (type arg)
2674 "Return nil if hiding is necessary.
2675 Arg can be nil or a number. nil and positive means hide, negative
2676 means show, 0 means toggle."
2679 (let ((hide (gnus-article-hidden-text-p type)))
2685 (gnus-article-show-hidden-text type)
2688 (if (eq hide 'hidden)
2690 (gnus-article-show-hidden-text type)
2694 (defun gnus-article-hidden-text-p (type)
2695 "Say whether the current buffer contains hidden text of type TYPE."
2696 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2698 (not (get-text-property pos 'invisible))
2699 (not (get-text-property pos 'dummy-invisible)))
2701 (text-property-any (1+ pos) (point-max) 'article-type type)))
2706 (defun gnus-article-show-hidden-text (type &optional dummy)
2707 "Show all hidden text of type TYPE.
2708 Originally it is hide instead of DUMMY."
2709 (let ((buffer-read-only nil)
2710 (inhibit-point-motion-hooks t))
2711 (gnus-remove-text-properties-when
2713 (point-min) (point-max)
2714 (cons 'article-type (cons type
2715 gnus-hidden-properties)))
2716 (gnus-delete-wash-type type)))
2718 (defconst article-time-units
2719 `((year . ,(* 365.25 24 60 60))
2720 (week . ,(* 7 24 60 60))
2721 (day . ,(* 24 60 60))
2725 "Mapping from time units to seconds.")
2727 (defun article-date-ut (&optional type highlight header)
2728 "Convert DATE date to universal time in the current article.
2729 If TYPE is `local', convert to local time; if it is `lapsed', output
2730 how much time has lapsed since DATE. For `lapsed', the value of
2731 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2732 should replace the \"Date:\" one, or should be added below it."
2733 (interactive (list 'ut t))
2734 (let* ((header (or header
2735 (and (eq 1 (point-min))
2736 (mail-header-date (save-excursion
2737 (set-buffer gnus-summary-buffer)
2738 gnus-current-headers)))
2739 (message-fetch-field "date")
2741 (date (if (vectorp header) (mail-header-date header)
2743 (inhibit-point-motion-hooks t)
2744 bface eface date-pos)
2745 (when (and date (not (string= date "")))
2748 (article-narrow-to-head)
2749 (when (or (and (eq type 'lapsed)
2750 gnus-article-date-lapsed-new-header
2751 ;; Attempt to get the face of X-Sent first.
2752 (re-search-forward "^X-Sent:[ \t]" nil t))
2753 (re-search-forward "^Date:[ \t]" nil t)
2754 ;; If Date is missing, try again for X-Sent.
2755 (re-search-forward "^X-Sent:[ \t]" nil t))
2756 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2757 date (or (get-text-property (gnus-point-at-bol)
2760 eface (get-text-property (1- (gnus-point-at-eol))
2762 (let ((buffer-read-only nil))
2763 ;; Delete any old X-Sent headers.
2764 (when (setq date-pos
2765 (text-property-any (point-min) (point-max)
2766 'article-date-lapsed t))
2767 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2768 (delete-region (match-beginning 0)
2769 (progn (forward-line 1) (point))))
2770 (goto-char (point-min))
2771 ;; Delete any old Date headers.
2772 (while (re-search-forward "^Date:[ \t]" nil t)
2774 (setq date-pos (match-beginning 0)))
2775 (unless (and (eq type 'lapsed)
2776 gnus-article-date-lapsed-new-header)
2777 (delete-region (match-beginning 0)
2778 (progn (message-next-header) (point)))))
2781 (goto-char date-pos)
2783 ;; Possibly, Date has been deleted.
2785 (when (and (eq type 'lapsed)
2786 gnus-article-date-lapsed-new-header
2787 (looking-at "Date:"))
2789 (goto-char (point-min)))
2790 (insert (article-make-date-line date type))
2791 (when (eq type 'lapsed)
2792 (put-text-property (gnus-point-at-bol) (point)
2793 'article-date-lapsed t))
2797 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2798 (put-text-property (match-beginning 1) (1+ (match-end 1))
2799 'original-date date)
2800 (put-text-property (match-beginning 1) (1+ (match-end 1))
2802 (put-text-property (match-beginning 2) (match-end 2)
2805 (defun article-make-date-line (date type)
2806 "Return a DATE line of TYPE."
2807 (unless (memq type '(local ut original user iso8601 lapsed english))
2808 (error "Unknown conversion type: %s" type))
2810 (let ((time (date-to-time date)))
2812 ;; Convert to the local timezone.
2814 (let ((tz (car (current-time-zone time))))
2815 (format "Date: %s %s%02d%02d" (current-time-string time)
2816 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2817 (/ (% (abs tz) 3600) 60))))
2818 ;; Convert to Universal Time.
2821 (current-time-string
2822 (let* ((e (parse-time-string date))
2823 (tm (apply 'encode-time e))
2825 (ls (- (cadr tm) (car (current-time-zone time)))))
2826 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2827 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2830 ;; Get the original date from the article.
2831 ((eq type 'original)
2832 (concat "Date: " (if (string-match "\n+$" date)
2833 (substring date 0 (match-beginning 0))
2835 ;; Let the user define the format.
2837 (if (gnus-functionp gnus-article-time-format)
2838 (funcall gnus-article-time-format time)
2841 (format-time-string gnus-article-time-format time))))
2844 (let ((tz (car (current-time-zone time))))
2847 (format-time-string "%Y%m%dT%H%M%S" time)
2848 (format "%s%02d%02d"
2849 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2850 (/ (% (abs tz) 3600) 60)))))
2851 ;; Do an X-Sent lapsed format.
2853 ;; If the date is seriously mangled, the timezone functions are
2854 ;; liable to bug out, so we ignore all errors.
2855 (let* ((now (current-time))
2856 (real-time (subtract-time now time))
2857 (real-sec (and real-time
2858 (+ (* (float (car real-time)) 65536)
2860 (sec (and real-time (abs real-sec)))
2870 ;; This is a bit convoluted, but basically we go
2871 ;; through the time units for years, weeks, etc,
2872 ;; and divide things to see whether that results
2873 ;; in positive answers.
2876 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2877 ;; The (remaining) seconds are too few to
2878 ;; be divided into this time unit.
2880 ;; It's big enough, so we output it.
2881 (setq sec (- sec (* num (cdr unit))))
2883 (concat (if prev ", " "") (int-to-string
2885 " " (symbol-name (car unit))
2886 (if (> num 1) "s" ""))
2888 article-time-units "")
2889 ;; If dates are odd, then it might appear like the
2890 ;; article was sent in the future.
2893 " in the future"))))))
2894 ;; Display the date in proper English
2896 (let ((dtime (decode-time time)))
2899 (number-to-string (nth 3 dtime))
2900 (let ((digit (% (nth 3 dtime) 10)))
2902 ((memq (nth 3 dtime) '(11 12 13)) "th")
2908 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2910 (number-to-string (nth 5 dtime))
2912 (format "%02d" (nth 2 dtime))
2914 (format "%02d" (nth 1 dtime)))))))
2916 (format "Date: %s (from Oort)" date))))
2918 (defun article-date-local (&optional highlight)
2919 "Convert the current article date to the local timezone."
2920 (interactive (list t))
2921 (article-date-ut 'local highlight))
2923 (defun article-date-english (&optional highlight)
2924 "Convert the current article date to something that is proper English."
2925 (interactive (list t))
2926 (article-date-ut 'english highlight))
2928 (defun article-date-original (&optional highlight)
2929 "Convert the current article date to what it was originally.
2930 This is only useful if you have used some other date conversion
2931 function and want to see what the date was before converting."
2932 (interactive (list t))
2933 (article-date-ut 'original highlight))
2935 (defun article-date-lapsed (&optional highlight)
2936 "Convert the current article date to time lapsed since it was sent."
2937 (interactive (list t))
2938 (article-date-ut 'lapsed highlight))
2940 (defun article-update-date-lapsed ()
2941 "Function to be run from a timer to update the lapsed time line."
2942 (let (deactivate-mark)
2947 (set-buffer (window-buffer w))
2948 (when (eq major-mode 'gnus-article-mode)
2949 (goto-char (point-min))
2950 (when (re-search-forward "^X-Sent:" nil t)
2951 (article-date-lapsed t))))
2954 (defun gnus-start-date-timer (&optional n)
2955 "Start a timer to update the X-Sent header in the article buffers.
2956 The numerical prefix says how frequently (in seconds) the function
2961 (gnus-stop-date-timer)
2962 (setq article-lapsed-timer
2963 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2965 (defun gnus-stop-date-timer ()
2966 "Stop the X-Sent timer."
2968 (when article-lapsed-timer
2969 (nnheader-cancel-timer article-lapsed-timer)
2970 (setq article-lapsed-timer nil)))
2972 (defun article-date-user (&optional highlight)
2973 "Convert the current article date to the user-defined format.
2974 This format is defined by the `gnus-article-time-format' variable."
2975 (interactive (list t))
2976 (article-date-ut 'user highlight))
2978 (defun article-date-iso8601 (&optional highlight)
2979 "Convert the current article date to ISO8601."
2980 (interactive (list t))
2981 (article-date-ut 'iso8601 highlight))
2983 ;; (defun article-show-all ()
2984 ;; "Show all hidden text in the article buffer."
2988 ;; (let ((buffer-read-only nil))
2989 ;; (gnus-article-unhide-text (point-min) (point-max))
2990 ;; (gnus-remove-text-with-property 'gnus-prev)
2991 ;; (gnus-remove-text-with-property 'gnus-next))))
2993 (defun article-show-all-headers ()
2994 "Show all hidden headers in the article buffer."
2999 (article-narrow-to-head)
3000 (let ((buffer-read-only nil))
3001 (gnus-article-unhide-text (point-min) (point-max))))))
3003 (defun article-remove-leading-whitespace ()
3004 "Remove excessive whitespace from all headers."
3008 (let ((buffer-read-only nil))
3009 (article-narrow-to-head)
3010 (goto-char (point-min))
3011 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3012 (delete-region (match-beginning 1) (match-end 1)))))))
3014 (defun article-emphasize (&optional arg)
3015 "Emphasize text according to `gnus-emphasis-alist'."
3016 (interactive (gnus-article-hidden-arg))
3017 (unless (gnus-article-check-hidden-text 'emphasis arg)
3021 (with-current-buffer gnus-summary-buffer
3022 gnus-article-emphasis-alist)
3024 gnus-emphasis-alist))
3025 (buffer-read-only nil)
3026 (props (append '(article-type emphasis)
3027 gnus-hidden-properties))
3028 regexp elem beg invisible visible face)
3031 (while (setq elem (pop alist))
3033 (setq regexp (car elem)
3034 invisible (nth 1 elem)
3035 visible (nth 2 elem)
3037 (while (re-search-forward regexp nil t)
3038 (when (and (match-beginning visible) (match-beginning invisible))
3039 (gnus-article-hide-text
3040 (match-beginning invisible) (match-end invisible) props)
3041 (gnus-article-unhide-text-type
3042 (match-beginning visible) (match-end visible) 'emphasis)
3043 (gnus-put-overlay-excluding-newlines
3044 (match-beginning visible) (match-end visible) 'face face)
3045 (gnus-add-wash-type 'emphasis)
3046 (goto-char (match-end invisible)))))))))
3048 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3049 "Setup newsgroup emphasis alist."
3050 (unless gnus-article-emphasis-alist
3051 (let ((name (and gnus-newsgroup-name
3052 (gnus-group-real-name gnus-newsgroup-name))))
3053 (make-local-variable 'gnus-article-emphasis-alist)
3054 (setq gnus-article-emphasis-alist
3056 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3057 (while (setq elem (pop alist))
3058 (when (and name (string-match (car elem) name))
3060 highlight (copy-sequence (cdr elem)))))
3062 (copy-sequence highlight-words)
3063 (if gnus-newsgroup-name
3064 (copy-sequence (gnus-group-find-parameter
3065 gnus-newsgroup-name 'highlight-words t)))
3066 gnus-emphasis-alist)))))
3069 (defvar gnus-summary-article-menu)
3070 (defvar gnus-summary-post-menu))
3072 ;;; Saving functions.
3074 (defun gnus-article-save (save-buffer file &optional num)
3075 "Save the currently selected article."
3076 (unless gnus-save-all-headers
3077 ;; Remove headers according to `gnus-saved-headers'.
3078 (let ((gnus-visible-headers
3079 (or gnus-saved-headers gnus-visible-headers))
3080 (gnus-article-buffer save-buffer))
3082 (set-buffer save-buffer)
3083 (article-hide-headers 1 t))))
3084 (save-window-excursion
3085 (if (not gnus-default-article-saver)
3086 (error "No default saver is defined")
3087 ;; !!! Magic! The saving functions all save
3088 ;; `gnus-save-article-buffer' (or so they think), but we
3089 ;; bind that variable to our save-buffer.
3090 (set-buffer gnus-article-buffer)
3091 (let* ((gnus-save-article-buffer save-buffer)
3094 ((not gnus-prompt-before-saving) 'default)
3095 ((eq gnus-prompt-before-saving 'always) nil)
3097 (gnus-number-of-articles-to-be-saved
3098 (when (eq gnus-prompt-before-saving t)
3100 (set-buffer gnus-article-current-summary)
3101 (funcall gnus-default-article-saver filename)))))
3103 (defun gnus-read-save-file-name (prompt &optional filename
3104 function group headers variable)
3106 (funcall function group headers (symbol-value variable)))
3111 ((eq filename 'default)
3117 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3120 (if (and gnus-number-of-articles-to-be-saved
3121 (> gnus-number-of-articles-to-be-saved 1))
3122 (format "these %d articles"
3123 gnus-number-of-articles-to-be-saved)
3126 ;; Let the split methods have their say.
3128 ;; No split name was found.
3131 (concat prompt " (default "
3132 (file-name-nondirectory default-name) ") ")
3133 (file-name-directory default-name)
3135 ;; A single group name is returned.
3136 ((stringp split-name)
3138 (funcall function split-name headers
3139 (symbol-value variable)))
3141 (concat prompt " (default "
3142 (file-name-nondirectory default-name) ") ")
3143 (file-name-directory default-name)
3145 ;; A single split name was found
3146 ((= 1 (length split-name))
3147 (let* ((name (expand-file-name
3149 gnus-article-save-directory))
3150 (dir (cond ((file-directory-p name)
3151 (file-name-as-directory name))
3152 ((file-exists-p name) name)
3153 (t gnus-article-save-directory))))
3155 (concat prompt " (default " name ") ")
3157 ;; A list of splits was found.
3159 (setq split-name (nreverse split-name))
3161 (let ((file-name-history
3162 (nconc split-name file-name-history)))
3166 (concat prompt " (`M-p' for defaults) ")
3167 gnus-article-save-directory
3169 gnus-article-save-directory)))
3170 (car (push result file-name-history)))))))
3171 ;; Create the directory.
3172 (gnus-make-directory (file-name-directory file))
3173 ;; If we have read a directory, we append the default file name.
3174 (when (file-directory-p file)
3175 (setq file (expand-file-name (file-name-nondirectory
3177 (file-name-as-directory file))))
3178 ;; Possibly translate some characters.
3179 (nnheader-translate-file-chars file))))))
3180 (gnus-make-directory (file-name-directory result))
3181 (set variable result)))
3183 (defun gnus-article-archive-name (group)
3184 "Return the first instance of an \"Archive-name\" in the current buffer."
3185 (let ((case-fold-search t))
3186 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3187 (nnheader-concat gnus-article-save-directory
3188 (match-string 1)))))
3190 (defun gnus-article-nndoc-name (group)
3191 "If GROUP is an nndoc group, return the name of the parent group."
3192 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3193 (gnus-group-get-parameter group 'save-article-group)))
3195 (defun gnus-summary-save-in-rmail (&optional filename)
3196 "Append this article to Rmail file.
3197 Optional argument FILENAME specifies file name.
3198 Directory to save to is default to `gnus-article-save-directory'."
3199 (setq filename (gnus-read-save-file-name
3200 "Save %s in rmail file:" filename
3201 gnus-rmail-save-name gnus-newsgroup-name
3202 gnus-current-headers 'gnus-newsgroup-last-rmail))
3203 (gnus-eval-in-buffer-window gnus-save-article-buffer
3207 (gnus-output-to-rmail filename))))
3210 (defun gnus-summary-save-in-mail (&optional filename)
3211 "Append this article to Unix mail file.
3212 Optional argument FILENAME specifies file name.
3213 Directory to save to is default to `gnus-article-save-directory'."
3214 (setq filename (gnus-read-save-file-name
3215 "Save %s in Unix mail file:" filename
3216 gnus-mail-save-name gnus-newsgroup-name
3217 gnus-current-headers 'gnus-newsgroup-last-mail))
3218 (gnus-eval-in-buffer-window gnus-save-article-buffer
3222 (if (and (file-readable-p filename)
3223 (mail-file-babyl-p filename))
3224 (rmail-output-to-rmail-file filename t)
3225 (gnus-output-to-mail filename)))))
3228 (defun gnus-summary-save-in-file (&optional filename overwrite)
3229 "Append this article to file.
3230 Optional argument FILENAME specifies file name.
3231 Directory to save to is default to `gnus-article-save-directory'."
3232 (setq filename (gnus-read-save-file-name
3233 "Save %s in file:" filename
3234 gnus-file-save-name gnus-newsgroup-name
3235 gnus-current-headers 'gnus-newsgroup-last-file))
3236 (gnus-eval-in-buffer-window gnus-save-article-buffer
3240 (when (and overwrite
3241 (file-exists-p filename))
3242 (delete-file filename))
3243 (gnus-output-to-file filename))))
3246 (defun gnus-summary-write-to-file (&optional filename)
3247 "Write this article to a file, overwriting it if the file exists.
3248 Optional argument FILENAME specifies file name.
3249 The directory to save in defaults to `gnus-article-save-directory'."
3250 (gnus-summary-save-in-file nil t))
3252 (defun gnus-summary-save-body-in-file (&optional filename)
3253 "Append this article body to a file.
3254 Optional argument FILENAME specifies file name.
3255 The directory to save in defaults to `gnus-article-save-directory'."
3256 (setq filename (gnus-read-save-file-name
3257 "Save %s body in file:" filename
3258 gnus-file-save-name gnus-newsgroup-name
3259 gnus-current-headers 'gnus-newsgroup-last-file))
3260 (gnus-eval-in-buffer-window gnus-save-article-buffer
3264 (when (article-goto-body)
3265 (narrow-to-region (point) (point-max)))
3266 (gnus-output-to-file filename))))
3269 (defun gnus-summary-save-in-pipe (&optional command)
3270 "Pipe this article to subprocess."
3272 (cond ((and (eq command 'default)
3273 gnus-last-shell-command)
3274 gnus-last-shell-command)
3279 "Shell command on %s: "
3280 (if (and gnus-number-of-articles-to-be-saved
3281 (> gnus-number-of-articles-to-be-saved 1))
3282 (format "these %d articles"
3283 gnus-number-of-articles-to-be-saved)
3285 gnus-last-shell-command))))
3286 (when (string-equal command "")
3287 (if gnus-last-shell-command
3288 (setq command gnus-last-shell-command)
3289 (error "A command is required")))
3290 (gnus-eval-in-buffer-window gnus-article-buffer
3293 (shell-command-on-region (point-min) (point-max) command nil)))
3294 (setq gnus-last-shell-command command))
3296 (defun gnus-summary-pipe-to-muttprint (&optional command)
3297 "Pipe this article to muttprint."
3298 (setq command (read-string
3299 "Print using command: " gnus-summary-muttprint-program
3300 nil gnus-summary-muttprint-program))
3301 (gnus-summary-save-in-pipe command))
3303 ;;; Article file names when saving.
3305 (defun gnus-capitalize-newsgroup (newsgroup)
3306 "Capitalize NEWSGROUP name."
3307 (when (not (zerop (length newsgroup)))
3308 (concat (char-to-string (upcase (aref newsgroup 0)))
3309 (substring newsgroup 1))))
3311 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3312 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3313 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3314 Otherwise, it is like ~/News/news/group/num."
3317 (concat (if (gnus-use-long-file-name 'not-save)
3318 (gnus-capitalize-newsgroup newsgroup)
3319 (gnus-newsgroup-directory-form newsgroup))
3320 "/" (int-to-string (mail-header-number headers)))
3321 gnus-article-save-directory)))
3323 (string-equal (file-name-directory default)
3324 (file-name-directory last-file))
3325 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3327 (or last-file default))))
3329 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3330 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3331 If variable `gnus-use-long-file-name' is non-nil, it is
3332 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3335 (concat (if (gnus-use-long-file-name 'not-save)
3337 (gnus-newsgroup-directory-form newsgroup))
3338 "/" (int-to-string (mail-header-number headers)))
3339 gnus-article-save-directory)))
3341 (string-equal (file-name-directory default)
3342 (file-name-directory last-file))
3343 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3345 (or last-file default))))
3347 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3348 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3349 If variable `gnus-use-long-file-name' is non-nil, it is
3350 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3353 (if (gnus-use-long-file-name 'not-save)
3356 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3358 gnus-article-save-directory)))
3360 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3361 "Generate file name from sender."
3362 (let ((from (mail-header-from headers)))
3364 (if (and from (string-match "\\([^ <]+\\)@" from))
3365 (match-string 1 from)
3367 gnus-article-save-directory)))
3369 (defun article-verify-x-pgp-sig ()
3372 (if (gnus-buffer-live-p gnus-original-article-buffer)
3373 (let ((sig (with-current-buffer gnus-original-article-buffer
3374 (gnus-fetch-field "X-PGP-Sig")))
3378 (mml2015-clear-verify-function))
3380 (insert-buffer-substring gnus-original-article-buffer)
3381 (setq items (split-string sig))
3382 (message-narrow-to-head)
3383 (let ((inhibit-point-motion-hooks t)
3384 (case-fold-search t))
3385 ;; Don't verify multiple headers.
3386 (setq headers (mapconcat (lambda (header)
3388 (mail-fetch-field header) "\n"))
3389 (split-string (nth 1 items) ",") "")))
3390 (delete-region (point-min) (point-max))
3391 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3392 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3397 (if (looking-at "^-")
3400 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3401 (insert "Version: " (car items) "\n\n")
3402 (insert (mapconcat 'identity (cddr items) "\n"))
3403 (insert "\n-----END PGP SIGNATURE-----\n")
3404 (let ((mm-security-handle (list (format "multipart/signed"))))
3405 (mml2015-clean-buffer)
3406 (let ((coding-system-for-write (or gnus-newsgroup-charset
3408 (funcall (mml2015-clear-verify-function)))
3410 (or (mm-handle-multipart-ctl-parameter
3411 mm-security-handle 'gnus-details)
3412 (mm-handle-multipart-ctl-parameter
3413 mm-security-handle 'gnus-info)))))
3415 (let (buffer-read-only bface eface)
3417 (message-narrow-to-head)
3418 (goto-char (point-max))
3420 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3421 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3422 (message-remove-header "X-Gnus-PGP-Verify")
3423 (if (re-search-forward "^X-PGP-Sig:" nil t)
3425 (goto-char (point-max)))
3426 (narrow-to-region (point) (point))
3427 (insert "X-Gnus-PGP-Verify: " info "\n")
3428 (goto-char (point-min))
3431 (if (not (looking-at "^[ \t]"))
3435 (goto-char (point-min))
3436 (when (looking-at "\\([^:]+\\): *")
3437 (put-text-property (match-beginning 1) (1+ (match-end 1))
3439 (put-text-property (match-end 0) (point-max)
3440 'face eface)))))))))
3442 (defun article-verify-cancel-lock ()
3443 "Verify Cancel-Lock header."
3445 (if (gnus-buffer-live-p gnus-original-article-buffer)
3446 (canlock-verify gnus-original-article-buffer)))
3448 (defun article-monafy ()
3449 "Display body part with mona font."
3451 (unless (if (featurep 'xemacs)
3452 (find-face 'gnus-mona-face)
3453 (facep 'gnus-mona-face))
3454 (require 'navi2ch-mona)
3455 (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3457 (let ((buffer-read-only nil))
3460 (gnus-make-overlay (point) (point-max))
3461 'face 'gnus-mona-face))))
3468 (setq afunc (car func)
3471 gfunc (intern (format "gnus-%s" func))))
3473 (when (fboundp afunc)
3474 `(lambda (&optional interactive &rest args)
3475 ,(documentation afunc t)
3476 (interactive (list t))
3478 (set-buffer gnus-article-buffer)
3480 (call-interactively ',afunc)
3481 (apply ',afunc args))))))))
3482 '(article-hide-headers
3483 article-verify-x-pgp-sig
3484 article-verify-cancel-lock
3486 article-hide-boring-headers
3487 article-toggle-headers
3488 article-treat-overstrike
3489 article-fill-long-lines
3490 article-capitalize-sentences
3492 article-remove-leading-whitespace
3493 article-display-x-face
3494 article-de-quoted-unreadable
3495 article-de-base64-unreadable
3498 article-unsplit-urls
3499 article-hide-list-identifiers
3501 article-strip-banner
3504 article-hide-signature
3505 article-strip-headers-in-body
3506 article-remove-trailing-blank-lines
3507 article-strip-leading-blank-lines
3508 article-strip-multiple-blank-lines
3509 article-strip-leading-space
3510 article-strip-trailing-space
3511 article-strip-blank-lines
3512 article-strip-all-blank-lines
3514 article-date-english
3515 article-date-iso8601
3516 article-date-original
3518 article-decode-mime-words
3519 article-decode-charset
3520 article-decode-encoded-words
3524 article-treat-dumbquotes
3525 article-normalize-headers
3526 (article-show-all-headers . gnus-article-show-all-headers)
3527 ;; (article-show-all . gnus-article-show-all)
3531 ;;; Gnus article mode
3534 (put 'gnus-article-mode 'mode-class 'special)
3536 (gnus-define-keys gnus-article-mode-map
3537 " " gnus-article-goto-next-page
3538 "\177" gnus-article-goto-prev-page
3539 [delete] gnus-article-goto-prev-page
3540 [backspace] gnus-article-goto-prev-page
3541 "\C-c^" gnus-article-refer-article
3542 "h" gnus-article-show-summary
3543 "s" gnus-article-show-summary
3544 "\C-c\C-m" gnus-article-mail
3545 "?" gnus-article-describe-briefly
3546 "e" gnus-summary-edit-article
3547 "<" beginning-of-buffer
3549 "\C-c\C-i" gnus-info-find-node
3551 "R" gnus-article-reply-with-original
3552 "F" gnus-article-followup-with-original
3553 "\C-hk" gnus-article-describe-key
3554 "\C-hc" gnus-article-describe-key-briefly
3556 "\C-d" gnus-article-read-summary-keys
3557 "\M-*" gnus-article-read-summary-keys
3558 "\M-#" gnus-article-read-summary-keys
3559 "\M-^" gnus-article-read-summary-keys
3560 "\M-g" gnus-article-read-summary-keys)
3562 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3566 (push (char-to-string key) keys)
3568 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3569 (setq key (car elem))
3570 (when (and (> (length key) 0)
3571 (not (eq 'menu-bar (aref key 0)))
3572 (symbolp (lookup-key gnus-summary-mode-map key)))
3575 (unless (lookup-key gnus-article-mode-map key)
3576 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3578 (defun gnus-article-make-menu-bar ()
3579 (unless (boundp 'gnus-article-commands-menu)
3580 (gnus-summary-make-menu-bar))
3581 (gnus-turn-off-edit-menu 'article)
3582 (unless (boundp 'gnus-article-article-menu)
3584 gnus-article-article-menu gnus-article-mode-map ""
3586 ["Scroll forwards" gnus-article-goto-next-page t]
3587 ["Scroll backwards" gnus-article-goto-prev-page t]
3588 ["Show summary" gnus-article-show-summary t]
3589 ["Fetch Message-ID at point" gnus-article-refer-article t]
3590 ["Mail to address at point" gnus-article-mail t]
3591 ["Send a bug report" gnus-bug t]))
3594 gnus-article-treatment-menu gnus-article-mode-map ""
3595 ;; Fixme: this should use :active (and maybe :visible).
3597 ["Hide headers" gnus-article-toggle-headers t]
3598 ["Hide signature" gnus-article-hide-signature t]
3599 ["Hide citation" gnus-article-hide-citation t]
3600 ["Treat overstrike" gnus-article-treat-overstrike t]
3601 ["Remove carriage return" gnus-article-remove-cr t]
3602 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3603 ["Treat html" gnus-article-wash-html t]
3604 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3605 ["Decode HZ" gnus-article-decode-HZ t]))
3607 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3609 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3611 (gnus-run-hooks 'gnus-article-menu-hook)))
3613 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3616 (defun gnus-article-mode ()
3617 "Major mode for displaying an article.
3619 All normal editing commands are switched off.
3621 The following commands are available in addition to all summary mode
3623 \\<gnus-article-mode-map>
3624 \\[gnus-article-next-page]\t Scroll the article one page forwards
3625 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3626 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3627 \\[gnus-article-show-summary]\t Display the summary buffer
3628 \\[gnus-article-mail]\t Send a reply to the address near point
3629 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3630 \\[gnus-info-find-node]\t Go to the Gnus info node"
3632 (gnus-simplify-mode-line)
3633 (setq mode-name "Article")
3634 (setq major-mode 'gnus-article-mode)
3635 (make-local-variable 'minor-mode-alist)
3636 (unless (assq 'gnus-show-mime minor-mode-alist)
3637 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3638 (use-local-map gnus-article-mode-map)
3639 (when (gnus-visual-p 'article-menu 'menu)
3640 (gnus-article-make-menu-bar))
3641 (gnus-update-format-specifications nil 'article-mode)
3642 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3643 (make-local-variable 'gnus-page-broken)
3644 (make-local-variable 'gnus-button-marker-list)
3645 (make-local-variable 'gnus-article-current-summary)
3646 (make-local-variable 'gnus-article-mime-handles)
3647 (make-local-variable 'gnus-article-decoded-p)
3648 (make-local-variable 'gnus-article-mime-handle-alist)
3649 (make-local-variable 'gnus-article-wash-types)
3650 (make-local-variable 'gnus-article-image-alist)
3651 (make-local-variable 'gnus-article-charset)
3652 (make-local-variable 'gnus-article-ignored-charsets)
3653 (gnus-set-default-directory)
3654 (buffer-disable-undo)
3655 (setq buffer-read-only t)
3656 (set-syntax-table gnus-article-mode-syntax-table)
3657 (gnus-run-hooks 'gnus-article-mode-hook))
3659 (defun gnus-article-setup-buffer ()
3660 "Initialize the article buffer."
3661 (let* ((name (if gnus-single-article-buffer "*Article*"
3662 (concat "*Article " gnus-newsgroup-name "*")))
3664 (progn (string-match "\\*Article" name)
3665 (concat " *Original Article"
3666 (substring name (match-end 0))))))
3667 (setq gnus-article-buffer name)
3668 (setq gnus-original-article-buffer original)
3669 (setq gnus-article-mime-handle-alist nil)
3670 ;; This might be a variable local to the summary buffer.
3671 (unless gnus-single-article-buffer
3673 (set-buffer gnus-summary-buffer)
3674 (setq gnus-article-buffer name)
3675 (setq gnus-original-article-buffer original)
3676 (gnus-set-global-variables)))
3677 (gnus-article-setup-highlight-words)
3678 ;; Init original article buffer.
3680 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3681 (set-buffer-multibyte t)
3682 (setq major-mode 'gnus-original-article-mode)
3683 (make-local-variable 'gnus-original-article))
3684 (if (get-buffer name)
3687 (buffer-disable-undo)
3688 (setq buffer-read-only t)
3689 (unless (eq major-mode 'gnus-article-mode)
3690 (gnus-article-mode))
3693 (set-buffer (gnus-get-buffer-create name))
3695 (make-local-variable 'gnus-summary-buffer)
3696 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3697 (current-buffer)))))
3699 ;; Set article window start at LINE, where LINE is the number of lines
3700 ;; from the head of the article.
3701 (defun gnus-article-set-window-start (&optional line)
3703 (gnus-get-buffer-window gnus-article-buffer t)
3705 (set-buffer gnus-article-buffer)
3706 (goto-char (point-min))
3709 (gnus-message 6 "Moved to bookmark")
3710 (search-forward "\n\n" nil t)
3714 ;;; @@ article filters
3717 (defun gnus-article-display-mime-message ()
3718 "Article display method for MIME message."
3719 ;; called from `gnus-original-article-buffer'.
3720 (let (charset all-headers)
3721 (with-current-buffer gnus-summary-buffer
3722 (setq charset default-mime-charset
3723 all-headers gnus-have-all-headers))
3724 (make-local-variable 'default-mime-charset)
3725 (setq default-mime-charset charset)
3726 (with-current-buffer (get-buffer-create gnus-article-buffer)
3727 (make-local-variable 'default-mime-charset)
3728 (setq default-mime-charset charset))
3729 (mime-display-message mime-message-structure
3730 gnus-article-buffer nil gnus-article-mode-map)
3732 (gnus-article-hide-headers nil -1)))
3733 (run-hooks 'gnus-mime-article-prepare-hook))
3735 (defun gnus-article-display-traditional-message ()
3736 "Article display method for traditional message."
3737 (set-buffer gnus-article-buffer)
3738 (let (buffer-read-only)
3740 (insert-buffer-substring gnus-original-article-buffer)))
3742 (defun gnus-article-make-full-mail-header (&optional number charset)
3743 "Create a new mail header structure in a raw article buffer."
3744 (unless (and number charset)
3745 (save-current-buffer
3746 (set-buffer gnus-summary-buffer)
3748 (setq number (or (cdr gnus-article-current) 0)))
3750 (setq charset (or default-mime-charset 'x-ctext)))))
3751 (goto-char (point-min))
3752 (let ((header-end (if (search-forward "\n\n" nil t)
3754 (goto-char (point-max))))
3755 (chars (- (point-max) (point)))
3756 (lines (count-lines (point) (point-max)))
3757 (default-mime-charset charset)
3759 (narrow-to-region (point-min) header-end)
3760 (setq xref (std11-fetch-field "xref"))
3762 (make-full-mail-header
3764 (std11-fetch-field "subject")
3765 (std11-fetch-field "from")
3766 (std11-fetch-field "date")
3767 (std11-fetch-field "message-id")
3768 (std11-fetch-field "references")
3771 (when xref (concat "Xref: " xref)))
3774 (defun gnus-article-prepare (article &optional all-headers header)
3775 "Prepare ARTICLE in article mode buffer.
3776 ARTICLE should either be an article number or a Message-ID.
3777 If ARTICLE is an id, HEADER should be the article headers.
3778 If ALL-HEADERS is non-nil, no headers are hidden."
3780 ;; Make sure we start in a summary buffer.
3781 (unless (eq major-mode 'gnus-summary-mode)
3782 (set-buffer gnus-summary-buffer))
3783 (setq gnus-summary-buffer (current-buffer))
3784 (let* ((gnus-article (if header (mail-header-number header) article))
3785 (summary-buffer (current-buffer))
3786 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3787 (group gnus-newsgroup-name)
3790 (gnus-article-setup-buffer)
3791 (set-buffer gnus-article-buffer)
3792 ;; Deactivate active regions.
3793 (when (and (boundp 'transient-mark-mode)
3794 transient-mark-mode)
3795 (setq mark-active nil))
3796 (if (not (setq result (let ((buffer-read-only nil))
3797 (gnus-request-article-this-buffer
3799 ;; There is no such article.
3801 (when (and (numberp article)
3802 (not (memq article gnus-newsgroup-sparse)))
3803 (setq gnus-article-current
3804 (cons gnus-newsgroup-name article))
3805 (set-buffer gnus-summary-buffer)
3806 (setq gnus-current-article article)
3807 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3809 (gnus-summary-set-agent-mark article)
3810 (message "Message marked for downloading"))
3811 (gnus-summary-mark-article article gnus-canceled-mark)
3812 (unless (memq article gnus-newsgroup-sparse)
3813 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3814 (if (or (eq result 'pseudo)
3815 (eq result 'nneething))
3818 (set-buffer summary-buffer)
3819 (push article gnus-newsgroup-history)
3820 (setq gnus-last-article gnus-current-article
3821 gnus-current-article 0
3822 gnus-current-headers nil
3823 gnus-article-current nil)
3824 (if (eq result 'nneething)
3825 (gnus-configure-windows 'summary)
3826 (gnus-configure-windows 'article))
3827 (gnus-set-global-variables))
3828 (let ((gnus-article-mime-handle-alist-1
3829 gnus-article-mime-handle-alist))
3830 (gnus-set-mode-line 'article)))
3831 ;; The result from the `request' was an actual article -
3832 ;; or at least some text that is now displayed in the
3834 (when (and (numberp article)
3835 (not (eq article gnus-current-article)))
3836 ;; Seems like a new article has been selected.
3837 ;; `gnus-current-article' must be an article number.
3839 (set-buffer summary-buffer)
3840 (push article gnus-newsgroup-history)
3841 (setq gnus-last-article gnus-current-article
3842 gnus-current-article article
3843 gnus-current-headers
3844 (gnus-summary-article-header gnus-current-article)
3845 gnus-article-current
3846 (cons gnus-newsgroup-name gnus-current-article))
3847 (unless (vectorp gnus-current-headers)
3848 (setq gnus-current-headers nil))
3849 (gnus-summary-goto-subject gnus-current-article)
3850 (when (gnus-summary-show-thread)
3851 ;; If the summary buffer really was folded, the
3852 ;; previous goto may not actually have gone to
3853 ;; the right article, but the thread root instead.
3855 (gnus-summary-goto-subject gnus-current-article))
3856 (gnus-run-hooks 'gnus-mark-article-hook)
3857 (gnus-set-mode-line 'summary)
3858 (when (gnus-visual-p 'article-highlight 'highlight)
3859 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3860 ;; Set the global newsgroup variables here.
3861 (gnus-set-global-variables)
3862 (setq gnus-have-all-headers
3863 (or all-headers gnus-show-all-headers))))
3865 (gnus-configure-windows 'article))
3866 (when (or (numberp article)
3868 (gnus-article-prepare-display)
3870 (goto-char (point-min))
3871 (setq gnus-page-broken
3872 (when gnus-break-pages
3873 (gnus-narrow-to-page)
3875 (let ((gnus-article-mime-handle-alist-1
3876 gnus-article-mime-handle-alist))
3877 (gnus-set-mode-line 'article))
3881 (set-window-point (get-buffer-window (current-buffer)) (point))
3882 (gnus-configure-windows 'article)
3885 (defun gnus-article-prepare-mime-display (&optional number)
3886 (goto-char (point-min))
3887 (when (re-search-forward "^[^\t ]+:" nil t)
3888 (goto-char (match-beginning 0)))
3889 (let ((entity (if (eq 1 (point-min))
3890 (get-text-property 1 'mime-view-entity)
3891 (get-text-property (point) 'mime-view-entity)))
3892 last-entity child-entity next type)
3893 (setq child-entity (mime-entity-children entity))
3895 (setq last-entity (nth (1- (length child-entity))
3897 (setq last-entity entity))
3899 (narrow-to-region (point)
3900 (if (search-forward "\n\n" nil t)
3903 (gnus-treat-article 'head)
3904 (put-text-property (point-min) (point-max) 'article-treated-header t)
3905 (goto-char (point-max)))
3906 (while (and (not (eobp)) entity)
3907 (setq next (set-marker
3909 (next-single-property-change (point) 'mime-view-entity
3911 (let ((types (mime-entity-content-type entity)))
3912 (while (eq 'multipart (mime-content-type-primary-type types))
3913 (setq entity (car (mime-entity-children entity))
3914 types (mime-entity-content-type entity)))
3916 (setq type (format "%s/%s"
3917 (mime-content-type-primary-type types)
3918 (mime-content-type-subtype types)))))
3919 (if (string-equal type "message/rfc822")
3922 (let ((children (mime-entity-children entity))
3925 (setq last-children (nth (1- (length children)) children))
3928 (not (eq last-children
3929 (get-text-property next 'mime-view-entity)))
3931 (next-single-property-change next
3933 nil (point-max)))))))
3934 (setq next (next-single-property-change next 'mime-view-entity
3937 (narrow-to-region (point) next)
3938 (gnus-article-prepare-mime-display)
3939 (goto-char (point-max)))
3940 (setq entity (get-text-property (point) 'mime-view-entity)))
3942 (narrow-to-region (point) next)
3943 ;; Kludge. We have to count true number, but for now,
3944 ;; part number is here only to achieve `last'.
3945 (gnus-treat-article nil 1
3946 (if (eq entity last-entity)
3949 (goto-char (point-max)))
3950 (setq entity (get-text-property next 'mime-view-entity))))))
3953 (defun gnus-article-prepare-display ()
3954 "Make the current buffer look like a nice article."
3955 (let ((gnus-article-buffer (current-buffer))
3957 (unless (eq major-mode 'gnus-article-mode)
3958 (gnus-article-mode))
3959 (setq buffer-read-only nil
3960 gnus-button-marker-list nil
3961 gnus-article-wash-types nil
3962 gnus-article-image-alist nil)
3965 (static-if (featurep 'xemacs)
3966 (map-extents (lambda (extent maparg) (delete-extent extent)))
3967 (let ((lists (overlay-lists)))
3968 (dolist (overlay (nconc (car lists) (cdr lists)))
3969 (delete-overlay overlay)))))
3970 (gnus-run-hooks 'gnus-tmp-internal-hook))
3971 (set-buffer gnus-original-article-buffer)
3973 (setq mime-message-structure gnus-current-headers)
3974 (mime-buffer-entity-set-buffer-internal mime-message-structure
3975 gnus-original-article-buffer)
3976 (mime-entity-set-representation-type-internal mime-message-structure
3977 'mime-buffer-entity)
3978 (luna-send mime-message-structure 'initialize-instance
3979 mime-message-structure)
3981 (let (mime-display-header-hook mime-display-text/plain-hook)
3982 (funcall gnus-article-display-method-for-mime))
3983 (funcall gnus-article-display-method-for-traditional))
3984 ;; Call the treatment functions.
3985 (let ((inhibit-read-only t))
3989 (gnus-article-prepare-mime-display)
3990 (narrow-to-region (goto-char (point-min))
3991 (if (search-forward "\n\n" nil t)
3994 (gnus-treat-article 'head)
3995 (put-text-property (point-min) (point-max) 'article-treated-header t)
3996 (goto-char (point-max))
3998 (narrow-to-region (point) (point-max))
3999 (gnus-treat-article nil))
4000 (put-text-property (point-min) (point-max) 'read-only nil)))
4001 (gnus-run-hooks 'gnus-article-prepare-hook))
4003 (defun gnus-article-decode-article-as-default-mime-charset ()
4004 "Decode an article as `default-mime-charset'. It won't work if the
4005 value of the variable `gnus-show-mime' is non-nil."
4006 (unless gnus-show-mime
4007 (set (make-local-variable 'default-mime-charset)
4008 (with-current-buffer gnus-summary-buffer
4009 default-mime-charset))
4010 (decode-mime-charset-region (point-min) (point-max)
4011 default-mime-charset)))
4014 ;;; Gnus MIME viewing functions
4017 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4018 "Format of the MIME buttons.
4020 Valid specifiers include:
4022 %T MIME type, along with additional info
4023 %n The `name' parameter
4024 %d The description, if any
4025 %l The length of the encoded part
4026 %p The part identifier number
4027 %e Dots if the part isn't displayed
4029 General format specifiers can also be used. See
4030 (gnus)Formatting Variables.")
4032 (defvar gnus-mime-button-line-format-alist
4033 '((?t gnus-tmp-type ?s)
4034 (?T gnus-tmp-type-long ?s)
4035 (?n gnus-tmp-name ?s)
4036 (?d gnus-tmp-description ?s)
4038 (?l gnus-tmp-length ?d)
4039 (?e gnus-tmp-dots ?s)))
4041 (defvar gnus-mime-button-commands
4042 '((gnus-article-press-button "\r" "Toggle Display")
4043 (gnus-mime-view-part "v" "View Interactively...")
4044 (gnus-mime-view-part-as-type "t" "View As Type...")
4045 (gnus-mime-view-part-as-charset "C" "View As charset...")
4046 (gnus-mime-save-part "o" "Save...")
4047 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4048 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4049 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4050 (gnus-mime-view-part-internally "E" "View Internally")
4051 (gnus-mime-view-part-externally "e" "View Externally")
4052 (gnus-mime-print-part "p" "Print")
4053 (gnus-mime-pipe-part "|" "Pipe To Command...")
4054 (gnus-mime-action-on-part "." "Take action on the part")))
4056 (defun gnus-article-mime-part-status ()
4057 (with-current-buffer gnus-article-buffer
4058 (let ((entity (get-text-property (point-min) 'mime-view-entity))
4061 (setq children (mime-entity-children entity))
4062 (setq children (length children)))
4065 (format " (%d parts)" children))
4068 (defvar gnus-mime-button-map
4069 (let ((map (make-sparse-keymap)))
4070 (unless (>= (string-to-number emacs-version) 21)
4071 ;; XEmacs doesn't care.
4072 (set-keymap-parent map gnus-article-mode-map))
4073 (define-key map gnus-mouse-2 'gnus-article-push-button)
4074 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4075 (dolist (c gnus-mime-button-commands)
4076 (define-key map (cadr c) (car c)))
4079 (defun gnus-mime-button-menu (event)
4080 "Construct a context-sensitive menu of MIME commands."
4082 (save-window-excursion
4083 (let ((pos (event-start event)))
4084 (select-window (posn-window pos))
4085 (goto-char (posn-point pos))
4086 (gnus-article-check-buffer)
4087 (let ((response (x-popup-menu
4089 ("" ,@(mapcar (lambda (c)
4090 (cons (caddr c) (car c)))
4091 gnus-mime-button-commands))))))
4093 (call-interactively response))))))
4095 (defun gnus-mime-view-all-parts (&optional handles)
4096 "View all the MIME parts."
4098 (save-current-buffer
4099 (set-buffer gnus-article-buffer)
4100 (let ((handles (or handles gnus-article-mime-handles))
4101 (mail-parse-charset gnus-newsgroup-charset)
4102 (mail-parse-ignored-charsets
4103 (with-current-buffer gnus-summary-buffer
4104 gnus-newsgroup-ignored-charsets)))
4106 (mm-remove-parts handles)
4107 (goto-char (point-min))
4108 (or (search-forward "\n\n") (goto-char (point-max)))
4109 (let (buffer-read-only)
4110 (delete-region (point) (point-max))
4111 (mm-display-parts handles))))))
4113 (defun gnus-mime-save-part-and-strip ()
4114 "Save the MIME part under point then replace it with an external body."
4116 (gnus-article-check-buffer)
4117 (let* ((data (get-text-property (point) 'gnus-data))
4119 (handles gnus-article-mime-handles))
4120 (if (mm-multiple-handles gnus-article-mime-handles)
4121 (error "This function is not implemented"))
4122 (setq file (and data (mm-save-part data)))
4124 (with-current-buffer (mm-handle-buffer data)
4126 (insert "Content-Type: " (mm-handle-media-type data))
4127 (mml-insert-parameter-string (cdr (mm-handle-type data))
4130 (insert "Content-ID: " (message-make-message-id) "\n")
4131 (insert "Content-Transfer-Encoding: binary\n")
4134 (cdr (mm-make-handle nil
4135 `("message/external-body"
4136 (access-type . "LOCAL-FILE")
4138 (set-buffer gnus-summary-buffer)
4139 (gnus-article-edit-article
4142 (let ((mail-parse-charset (or gnus-article-charset
4143 ',gnus-newsgroup-charset))
4144 (mail-parse-ignored-charsets
4145 (or gnus-article-ignored-charsets
4146 ',gnus-newsgroup-ignored-charsets))
4147 (mbl mml-buffer-list))
4148 (setq mml-buffer-list nil)
4149 (insert-buffer gnus-original-article-buffer)
4150 (mime-to-mml ',handles)
4151 (setq gnus-article-mime-handles nil)
4152 (let ((mbl1 mml-buffer-list))
4153 (setq mml-buffer-list mbl)
4154 (set (make-local-variable 'mml-buffer-list) mbl1))
4155 ;; LOCAL argument of add-hook differs between GNU Emacs
4156 ;; and XEmacs. make-local-hook makes sure they are local.
4157 (make-local-hook 'kill-buffer-hook)
4158 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4159 `(lambda (no-highlight)
4160 (let ((mail-parse-charset (or gnus-article-charset
4161 ',gnus-newsgroup-charset))
4162 (message-options message-options)
4163 (message-options-set-recipient)
4164 (mail-parse-ignored-charsets
4165 (or gnus-article-ignored-charsets
4166 ',gnus-newsgroup-ignored-charsets)))
4168 (mml-destroy-buffers)
4169 (remove-hook 'kill-buffer-hook
4170 'mml-destroy-buffers t)
4171 (kill-local-variable 'mml-buffer-list))
4172 (gnus-summary-edit-article-done
4173 ,(or (mail-header-references gnus-current-headers) "")
4174 ,(gnus-group-read-only-p)
4175 ,gnus-summary-buffer no-highlight))))))
4177 (defun gnus-mime-save-part ()
4178 "Save the MIME part under point."
4180 (gnus-article-check-buffer)
4181 (let ((data (get-text-property (point) 'gnus-data)))
4183 (mm-save-part data))))
4185 (defun gnus-mime-pipe-part ()
4186 "Pipe the MIME part under point to a process."
4188 (gnus-article-check-buffer)
4189 (let ((data (get-text-property (point) 'gnus-data)))
4191 (mm-pipe-part data))))
4193 (defun gnus-mime-view-part ()
4194 "Interactively choose a viewing method for the MIME part under point."
4196 (gnus-article-check-buffer)
4197 (let ((data (get-text-property (point) 'gnus-data)))
4199 (setq gnus-article-mime-handles
4201 gnus-article-mime-handles (setq data (copy-sequence data))))
4202 (mm-interactively-view-part data))))
4204 (defun gnus-mime-view-part-as-type-internal ()
4205 (gnus-article-check-buffer)
4206 (let* ((name (mail-content-type-get
4207 (mm-handle-type (get-text-property (point) 'gnus-data))
4209 (def-type (and name (mm-default-file-encoding name))))
4210 (and def-type (cons def-type 0))))
4212 (defun gnus-mime-view-part-as-type (&optional mime-type)
4213 "Choose a MIME media type, and view the part as such."
4216 (setq mime-type (completing-read
4217 "View as MIME type: "
4218 (mapcar #'list (mailcap-mime-types))
4220 (gnus-mime-view-part-as-type-internal))))
4221 (gnus-article-check-buffer)
4222 (let ((handle (get-text-property (point) 'gnus-data)))
4225 (mm-make-handle (mm-handle-buffer handle)
4226 (cons mime-type (cdr (mm-handle-type handle)))
4227 (mm-handle-encoding handle)
4228 (mm-handle-undisplayer handle)
4229 (mm-handle-disposition handle)
4230 (mm-handle-description handle)
4232 (mm-handle-id handle)))
4233 (setq gnus-article-mime-handles
4234 (mm-merge-handles gnus-article-mime-handles handle))
4235 (gnus-mm-display-part handle))))
4237 (defun gnus-mime-copy-part (&optional handle)
4238 "Put the MIME part under point into a new buffer."
4240 (gnus-article-check-buffer)
4241 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4242 (contents (and handle (mm-get-part handle)))
4244 (file-name-nondirectory
4246 (mail-content-type-get (mm-handle-type handle) 'name)
4247 (mail-content-type-get (mm-handle-type handle)
4250 (buffer (and base (generate-new-buffer base))))
4252 (switch-to-buffer buffer)
4254 ;; We do it this way to make `normal-mode' set the appropriate mode.
4257 (setq buffer-file-name (expand-file-name base))
4259 (setq buffer-file-name nil))
4260 (goto-char (point-min)))))
4262 (defun gnus-mime-print-part (&optional handle filename)
4263 "Print the MIME part under point."
4264 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4265 (gnus-article-check-buffer)
4266 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4267 (contents (and handle (mm-get-part handle)))
4268 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4269 (printer (mailcap-mime-info (mm-handle-type handle) "print")))
4274 (with-temp-file file
4276 (call-process shell-file-name nil
4277 (generate-new-buffer " *mm*")
4279 shell-command-switch
4281 printer file (mm-handle-type handle))))
4285 (gnus-print-buffer))
4286 (ps-despool filename)))))
4288 (defun gnus-mime-inline-part (&optional handle arg)
4289 "Insert the MIME part under point into the current buffer."
4290 (interactive (list nil current-prefix-arg))
4291 (gnus-article-check-buffer)
4292 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4297 (if (and (not arg) (mm-handle-undisplayer handle))
4298 (mm-remove-part handle)
4299 (setq contents (mm-get-part handle))
4302 (setq charset (or (mail-content-type-get
4303 (mm-handle-type handle) 'charset)
4304 gnus-newsgroup-charset)))
4306 (if (mm-handle-undisplayer handle)
4307 (mm-remove-part handle))
4310 gnus-summary-show-article-charset-alist))
4311 (mm-read-coding-system "Charset: ")))))
4313 (mm-insert-inline handle
4315 (setq charset (mm-charset-to-coding-system
4317 (not (eq charset 'ascii)))
4318 (mm-decode-coding-string contents charset)
4322 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4323 "Insert the MIME part under point into the current buffer using the
4325 (interactive (list nil current-prefix-arg))
4326 (gnus-article-check-buffer)
4327 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4332 (if (mm-handle-undisplayer handle)
4333 (mm-remove-part handle))
4334 (let ((gnus-newsgroup-charset
4336 gnus-summary-show-article-charset-alist))
4337 (mm-read-coding-system "Charset: ")))
4338 (gnus-newsgroup-ignored-charsets 'gnus-all))
4339 (gnus-article-press-button)))))
4341 (defun gnus-mime-view-part-externally (&optional handle)
4342 "View the MIME part under point with an external viewer."
4344 (gnus-article-check-buffer)
4345 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4346 (mm-user-display-methods nil)
4347 (mm-inlined-types nil)
4348 (mail-parse-charset gnus-newsgroup-charset)
4349 (mail-parse-ignored-charsets
4350 (save-excursion (set-buffer gnus-summary-buffer)
4351 gnus-newsgroup-ignored-charsets)))
4353 (if (mm-handle-undisplayer handle)
4354 (mm-remove-part handle)
4355 (mm-display-part handle)))))
4357 (defun gnus-mime-view-part-internally (&optional handle)
4358 "View the MIME part under point with an internal viewer.
4359 If no internal viewer is available, use an external viewer."
4361 (gnus-article-check-buffer)
4362 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4363 (mm-inlined-types '(".*"))
4364 (mm-inline-large-images t)
4365 (mail-parse-charset gnus-newsgroup-charset)
4366 (mail-parse-ignored-charsets
4367 (save-excursion (set-buffer gnus-summary-buffer)
4368 gnus-newsgroup-ignored-charsets)))
4370 (if (mm-handle-undisplayer handle)
4371 (mm-remove-part handle)
4372 (mm-display-part handle)))))
4374 (defun gnus-mime-action-on-part (&optional action)
4375 "Do something with the MIME attachment at \(point\)."
4377 (list (completing-read "Action: " gnus-mime-action-alist)))
4378 (gnus-article-check-buffer)
4379 (let ((action-pair (assoc action gnus-mime-action-alist)))
4381 (funcall (cdr action-pair)))))
4383 (defun gnus-article-part-wrapper (n function)
4384 (save-current-buffer
4385 (set-buffer gnus-article-buffer)
4386 (when (> n (length gnus-article-mime-handle-alist))
4387 (error "No such part"))
4388 (gnus-article-goto-part n)
4389 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4390 (funcall function handle))))
4392 (defun gnus-article-pipe-part (n)
4393 "Pipe MIME part N, which is the numerical prefix."
4395 (gnus-article-part-wrapper n 'mm-pipe-part))
4397 (defun gnus-article-save-part (n)
4398 "Save MIME part N, which is the numerical prefix."
4400 (gnus-article-part-wrapper n 'mm-save-part))
4402 (defun gnus-article-interactively-view-part (n)
4403 "View MIME part N interactively, which is the numerical prefix."
4405 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4407 (defun gnus-article-copy-part (n)
4408 "Copy MIME part N, which is the numerical prefix."
4410 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4412 (defun gnus-article-view-part-as-charset (n)
4413 "Copy MIME part N, which is the numerical prefix."
4415 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4417 (defun gnus-article-view-part-externally (n)
4418 "View MIME part N externally, which is the numerical prefix."
4420 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4422 (defun gnus-article-inline-part (n)
4423 "Inline MIME part N, which is the numerical prefix."
4425 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4427 (defun gnus-article-mime-match-handle-first (condition)
4429 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4430 (while (setq ihandle (pop alist))
4432 ((functionp condition)
4433 (funcall condition (cdr ihandle)))
4434 ((eq condition 'undisplayed)
4435 (not (or (mm-handle-undisplayer (cdr ihandle))
4436 (equal (mm-handle-media-type (cdr ihandle))
4437 "multipart/alternative"))))
4438 ((eq condition 'undisplayed-alternative)
4439 (not (mm-handle-undisplayer (cdr ihandle))))
4441 (gnus-article-goto-part (car ihandle))
4442 (or (not n) (< (car ihandle) n)))
4443 (setq n (car ihandle))))
4447 (defun gnus-article-view-part (&optional n)
4448 "View MIME part N, which is the numerical prefix."
4450 (save-current-buffer
4451 (set-buffer gnus-article-buffer)
4452 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4453 gnus-article-mime-match-handle-function)))
4454 (when (> n (length gnus-article-mime-handle-alist))
4455 (error "No such part"))
4456 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4457 (when (gnus-article-goto-part n)
4458 (if (equal (car handle) "multipart/alternative")
4459 (gnus-article-press-button)
4460 (when (eq (gnus-mm-display-part handle) 'internal)
4461 (gnus-set-window-start)))))))
4463 (defsubst gnus-article-mime-total-parts ()
4464 (if (bufferp (car gnus-article-mime-handles))
4466 (1- (length gnus-article-mime-handles))))
4468 (defun gnus-mm-display-part (handle)
4469 "Display HANDLE and fix MIME button."
4470 (let ((id (get-text-property (point) 'gnus-part))
4475 (let ((window (selected-window))
4476 (mail-parse-charset gnus-newsgroup-charset)
4477 (mail-parse-ignored-charsets
4478 (if (gnus-buffer-live-p gnus-summary-buffer)
4480 (set-buffer gnus-summary-buffer)
4481 gnus-newsgroup-ignored-charsets)
4485 (let ((win (gnus-get-buffer-window (current-buffer) t))
4488 (select-window win))
4491 (if (mm-handle-displayed-p handle)
4492 ;; This will remove the part.
4493 (mm-display-part handle)
4495 (narrow-to-region (point)
4496 (if (eobp) (point) (1+ (point))))
4497 (mm-display-part handle)
4498 ;; We narrow to the part itself and
4499 ;; then call the treatment functions.
4500 (goto-char (point-min))
4502 (narrow-to-region (point) (point-max))
4505 (gnus-article-mime-total-parts)
4506 (mm-handle-media-type handle)))))
4507 (if (window-live-p window)
4508 (select-window window)))))
4510 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4511 (gnus-insert-mime-button
4512 handle id (list (mm-handle-displayed-p handle)))
4513 (goto-char point))))
4515 (defun gnus-article-goto-part (n)
4516 "Go to MIME part N."
4517 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4519 (goto-char point))))
4521 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4522 (let ((gnus-tmp-name
4523 (or (mail-content-type-get (mm-handle-type handle) 'name)
4524 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4525 (mail-content-type-get (mm-handle-type handle) 'url)
4527 (gnus-tmp-type (mm-handle-media-type handle))
4528 (gnus-tmp-description
4529 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4532 (if (if displayed (car displayed)
4533 (mm-handle-displayed-p handle))
4535 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4537 gnus-tmp-type-long b e)
4538 (when (string-match ".*/" gnus-tmp-name)
4539 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4540 (setq gnus-tmp-type-long (concat gnus-tmp-type
4541 (and (not (equal gnus-tmp-name ""))
4542 (concat "; " gnus-tmp-name))))
4543 (unless (equal gnus-tmp-description "")
4544 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4549 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4550 `(,@(gnus-local-map-property gnus-mime-button-map)
4551 gnus-callback gnus-mm-display-part
4552 gnus-part ,gnus-tmp-id
4553 article-type annotation
4556 (widget-convert-button
4559 :action 'gnus-widget-press-button
4560 :button-keymap gnus-mime-button-map
4562 (lambda (widget/window &optional overlay pos)
4563 ;; Needed to properly clear the message due to a bug in
4564 ;; wid-edit (XEmacs only).
4565 (if (boundp 'help-echo-owns-message)
4566 (setq help-echo-owns-message t))
4568 "%S: %s the MIME part; %S: more options"
4569 (aref gnus-mouse-2 0)
4570 ;; XEmacs will get a single widget arg; Emacs 21 will get
4571 ;; window, overlay, position.
4572 (if (mm-handle-displayed-p
4574 (with-current-buffer (gnus-overlay-buffer overlay)
4575 (widget-get (widget-at (gnus-overlay-start overlay))
4577 (widget-get widget/window :mime-handle)))
4579 (aref gnus-down-mouse-3 0))))))
4581 (defun gnus-widget-press-button (elems el)
4582 (goto-char (widget-get elems :from))
4583 (gnus-article-press-button))
4585 (defvar gnus-displaying-mime nil)
4587 (defun gnus-display-mime (&optional ihandles)
4588 "Display the MIME parts."
4590 (save-selected-window
4591 (let ((window (get-buffer-window gnus-article-buffer))
4594 (select-window window)
4595 ;; We have to do this since selecting the window
4596 ;; may change the point. So we set the window point.
4597 (set-window-point window point)))
4598 (let* ((handles (or ihandles (mm-dissect-buffer
4599 nil gnus-article-loose-mime)
4601 buffer-read-only handle name type b e display)
4602 (when (and (not ihandles)
4603 (not gnus-displaying-mime))
4604 ;; Top-level call; we clean up.
4605 (when gnus-article-mime-handles
4606 (mm-destroy-parts gnus-article-mime-handles)
4607 (setq gnus-article-mime-handle-alist nil));; A trick.
4608 (setq gnus-article-mime-handles handles)
4609 ;; We allow users to glean info from the handles.
4610 (when gnus-article-mime-part-function
4611 (gnus-mime-part-function handles)))
4613 (or (not (stringp (car handles)))
4616 (when (and (not ihandles)
4617 (not gnus-displaying-mime))
4618 ;; Clean up for mime parts.
4620 (delete-region (point) (point-max)))
4621 (let ((gnus-displaying-mime t))
4622 (gnus-mime-display-part handles)))
4625 (narrow-to-region (point) (point-max))
4626 (gnus-treat-article nil 1 1)
4629 ;; Highlight the headers.
4633 (narrow-to-region (point-min) (point))
4634 (gnus-treat-article 'head))))))))
4636 (defvar gnus-mime-display-multipart-as-mixed nil)
4637 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4638 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4640 (defun gnus-mime-display-part (handle)
4643 ((not (stringp (car handle)))
4644 (gnus-mime-display-single handle))
4645 ;; User-defined multipart
4646 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4647 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4649 ;; multipart/alternative
4650 ((and (equal (car handle) "multipart/alternative")
4651 (not (or gnus-mime-display-multipart-as-mixed
4652 gnus-mime-display-multipart-alternative-as-mixed)))
4653 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4654 (push (cons id handle) gnus-article-mime-handle-alist)
4655 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4656 ;; multipart/related
4657 ((and (equal (car handle) "multipart/related")
4658 (not (or gnus-mime-display-multipart-as-mixed
4659 gnus-mime-display-multipart-related-as-mixed)))
4660 ;;;!!!We should find the start part, but we just default
4661 ;;;!!!to the first part.
4662 ;;(gnus-mime-display-part (cadr handle))
4663 ;;;!!! Most multipart/related is an HTML message plus images.
4664 ;;;!!! Unfortunately we are unable to let W3 display those
4665 ;;;!!! included images, so we just display it as a mixed multipart.
4666 ;;(gnus-mime-display-mixed (cdr handle))
4667 ;;;!!! No, w3 can display everything just fine.
4668 (gnus-mime-display-part (cadr handle)))
4669 ((equal (car handle) "multipart/signed")
4670 (gnus-add-wash-type 'signed)
4671 (gnus-mime-display-security handle))
4672 ((equal (car handle) "multipart/encrypted")
4673 (gnus-add-wash-type 'encrypted)
4674 (gnus-mime-display-security handle))
4675 ;; Other multiparts are handled like multipart/mixed.
4677 (gnus-mime-display-mixed (cdr handle)))))
4679 (defun gnus-mime-part-function (handles)
4680 (if (stringp (car handles))
4681 (mapcar 'gnus-mime-part-function (cdr handles))
4682 (funcall gnus-article-mime-part-function handles)))
4684 (defun gnus-mime-display-mixed (handles)
4685 (mapcar 'gnus-mime-display-part handles))
4687 (defun gnus-mime-display-single (handle)
4688 (let ((type (mm-handle-media-type handle))
4689 (ignored gnus-ignored-mime-types)
4696 (when (string-match (pop ignored) type)
4697 (throw 'ignored nil)))
4698 (if (and (setq not-attachment
4699 (and (not (mm-inline-override-p handle))
4700 (or (not (mm-handle-disposition handle))
4701 (equal (car (mm-handle-disposition handle))
4703 (mm-attachment-override-p handle))))
4704 (mm-automatic-display-p handle)
4706 (mm-inlinable-p handle)
4707 (mm-inlined-p handle))
4708 (mm-automatic-external-display-p type)))
4710 (when (equal (mm-handle-media-supertype handle) "text")
4712 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4714 (push (cons id handle) gnus-article-mime-handle-alist)
4715 (when (or (not display)
4716 (not (gnus-unbuttonized-mime-type-p type)))
4717 ;(gnus-article-insert-newline)
4718 (gnus-insert-mime-button
4719 handle id (list (or display (and not-attachment text))))
4720 (gnus-article-insert-newline)
4721 ;(gnus-article-insert-newline)
4722 ;; Remember modify the number of forward lines.
4730 (let ((mail-parse-charset gnus-newsgroup-charset)
4731 (mail-parse-ignored-charsets
4732 (save-excursion (condition-case ()
4733 (set-buffer gnus-summary-buffer)
4735 gnus-newsgroup-ignored-charsets)))
4736 (mm-display-part handle t))
4737 (goto-char (point-max)))
4738 ((and text not-attachment)
4742 (gnus-article-insert-newline)
4743 (mm-insert-inline handle (mm-get-part handle))
4744 (goto-char (point-max))))
4748 (narrow-to-region beg (point))
4751 (gnus-article-mime-total-parts)
4752 (mm-handle-media-type handle)))))))))
4754 (defun gnus-unbuttonized-mime-type-p (type)
4755 "Say whether TYPE is to be unbuttonized."
4756 (unless gnus-inhibit-mime-unbuttonizing
4758 (let ((types gnus-unbuttonized-mime-types))
4760 (when (string-match (pop types) type)
4761 (throw 'found t)))))
4763 (let ((types gnus-buttonized-mime-types))
4765 (when (string-match (pop types) type)
4766 (throw 'found t)))))))))
4768 (defun gnus-article-insert-newline ()
4769 "Insert a newline, but mark it as undeletable."
4770 (gnus-put-text-property
4771 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4773 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4774 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4777 handle buffer-read-only from props begend not-pref)
4778 (save-window-excursion
4781 (narrow-to-region (car ibegend)
4784 (goto-char (car ibegend))
4787 (delete-region (point-min) (point-max))
4788 (mm-remove-parts handles))
4789 (setq begend (list (point-marker)))
4791 (unless (setq not-pref (cadr (member preferred ihandles)))
4792 (setq not-pref (car ihandles)))
4795 (not (gnus-unbuttonized-mime-type-p
4796 "multipart/alternative")))
4797 (gnus-add-text-properties
4800 (insert (format "%d. " id))
4804 (unless ,(not ibegend)
4805 (setq gnus-article-mime-handle-alist
4806 ',gnus-article-mime-handle-alist))
4807 (gnus-mime-display-alternative
4808 ',ihandles ',not-pref ',begend ,id))
4809 ,@(gnus-local-map-property gnus-mime-button-map)
4810 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4811 face ,gnus-article-button-face
4814 (widget-convert-button 'link from (point)
4815 :action 'gnus-widget-press-button
4816 :button-keymap gnus-widget-button-keymap)
4818 (while (setq handle (pop handles))
4819 (gnus-add-text-properties
4822 (insert (format "(%c) %-18s"
4823 (if (equal handle preferred) ?* ? )
4824 (mm-handle-media-type handle)))
4828 (unless ,(not ibegend)
4829 (setq gnus-article-mime-handle-alist
4830 ',gnus-article-mime-handle-alist))
4831 (gnus-mime-display-alternative
4832 ',ihandles ',handle ',begend ,id))
4833 ,@(gnus-local-map-property gnus-mime-button-map)
4834 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4835 face ,gnus-article-button-face
4838 (widget-convert-button 'link from (point)
4839 :action 'gnus-widget-press-button
4840 :button-keymap gnus-widget-button-keymap)
4844 (if (stringp (car preferred))
4845 (gnus-display-mime preferred)
4846 (let ((mail-parse-charset gnus-newsgroup-charset)
4847 (mail-parse-ignored-charsets
4848 (save-excursion (set-buffer gnus-summary-buffer)
4849 gnus-newsgroup-ignored-charsets)))
4850 (mm-display-part preferred)
4854 (narrow-to-region (car begend) (point-max))
4856 nil (length gnus-article-mime-handle-alist)
4857 (gnus-article-mime-total-parts)
4858 (mm-handle-media-type handle))))))
4859 (goto-char (point-max))
4860 (setcdr begend (point-marker)))))
4862 (goto-char point))))
4864 (defconst gnus-article-wash-status-strings
4865 (let ((alist '((cite "c" "Possible hidden citation text"
4866 " " "All citation text visible")
4867 (headers "h" "Hidden headers"
4868 " " "All headers visible.")
4869 (pgp "p" "Encrypted or signed message status hidden"
4870 " " "No hidden encryption nor digital signature status")
4871 (signature "s" "Signature has been hidden"
4872 " " "Signature is visible")
4873 (overstrike "o" "Overstrike (^H) characters applied"
4874 " " "No overstrike characters applied")
4875 (gnus-show-mime "m" "Mime processing is activated"
4876 " " "Mime processing is not activated")
4877 (emphasis "e" "/*_Emphasis_*/ characters applied"
4878 " " "No /*_emphasis_*/ characters applied")))
4880 (dolist (entry alist result)
4881 (let ((key (nth 0 entry))
4882 (on (copy-sequence (nth 1 entry)))
4883 (on-help (nth 2 entry))
4884 (off (copy-sequence (nth 3 entry)))
4885 (off-help (nth 4 entry)))
4886 (put-text-property 0 1 'help-echo on-help on)
4887 (put-text-property 0 1 'help-echo off-help off)
4888 (push (list key on off) result))))
4889 "Alist of strings describing wash status in the mode line.
4890 Each entry has the form (KEY ON OF), where the KEY is a symbol
4891 representing the particular washing function, ON is the string to use
4892 in the article mode line when the washing function is active, and OFF
4893 is the string to use when it is inactive.")
4895 (defun gnus-article-wash-status-entry (key value)
4896 (let ((entry (assoc key gnus-article-wash-status-strings)))
4897 (if value (nth 1 entry) (nth 2 entry))))
4899 (defun gnus-article-wash-status ()
4900 "Return a string which display status of article washing."
4902 (set-buffer gnus-article-buffer)
4903 (let ((cite (memq 'cite gnus-article-wash-types))
4904 (headers (memq 'headers gnus-article-wash-types))
4905 (boring (memq 'boring-headers gnus-article-wash-types))
4906 (pgp (memq 'pgp gnus-article-wash-types))
4907 (pem (memq 'pem gnus-article-wash-types))
4908 (signed (memq 'signed gnus-article-wash-types))
4909 (encrypted (memq 'encrypted gnus-article-wash-types))
4910 (signature (memq 'signature gnus-article-wash-types))
4911 (overstrike (memq 'overstrike gnus-article-wash-types))
4912 (emphasis (memq 'emphasis gnus-article-wash-types)))
4914 (gnus-article-wash-status-entry 'cite cite)
4915 (gnus-article-wash-status-entry 'headers (or headers boring))
4916 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4917 (gnus-article-wash-status-entry 'signature signature)
4918 (gnus-article-wash-status-entry 'overstrike overstrike)
4919 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
4920 (gnus-article-wash-status-entry 'emphasis emphasis)))))
4922 (defun gnus-add-wash-type (type)
4923 "Add a washing of TYPE to the current status."
4924 (add-to-list 'gnus-article-wash-types type))
4926 (defun gnus-delete-wash-type (type)
4927 "Add a washing of TYPE to the current status."
4928 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4930 (defun gnus-add-image (category image)
4931 "Add IMAGE of CATEGORY to the list of displayed images."
4932 (let ((entry (assq category gnus-article-image-alist)))
4934 (setq entry (list category))
4935 (push entry gnus-article-image-alist))
4936 (nconc entry (list image))))
4938 (defun gnus-delete-images (category)
4939 "Delete all images in CATEGORY."
4940 (let ((entry (assq category gnus-article-image-alist)))
4941 (dolist (image (cdr entry))
4942 (gnus-remove-image image))
4943 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4944 (gnus-delete-wash-type category)))
4946 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4948 (defun gnus-article-maybe-hide-headers ()
4949 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4950 Provided for backwards compatibility."
4951 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4952 (not (save-excursion (set-buffer gnus-summary-buffer)
4953 gnus-have-all-headers)))
4954 (not gnus-inhibit-hiding))
4955 (gnus-article-hide-headers)))
4959 (defun gnus-output-to-file (file-name)
4960 "Append the current article to a file named FILE-NAME."
4961 (let ((artbuf (current-buffer)))
4963 (insert-buffer-substring artbuf)
4964 ;; Append newline at end of the buffer as separator, and then
4966 (goto-char (point-max))
4968 (let ((file-name-coding-system nnmail-pathname-coding-system)
4969 (pathname-coding-system nnmail-pathname-coding-system))
4970 (write-region-as-binary (point-min) (point-max) file-name 'append))
4973 (defun gnus-narrow-to-page (&optional arg)
4974 "Narrow the article buffer to a page.
4975 If given a numerical ARG, move forward ARG pages."
4977 (setq arg (if arg (prefix-numeric-value arg) 0))
4979 (set-buffer gnus-article-buffer)
4980 (goto-char (point-min))
4982 ;; Remove any old next/prev buttons.
4983 (when (gnus-visual-p 'page-marker)
4984 (let ((buffer-read-only nil))
4985 (gnus-remove-text-with-property 'gnus-prev)
4986 (gnus-remove-text-with-property 'gnus-next)))
4989 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4991 (re-search-forward page-delimiter nil 'move arg)))
4992 (goto-char (match-end 0)))
4995 (if (re-search-forward page-delimiter nil 'move)
4998 (when (and (gnus-visual-p 'page-marker)
4999 (not (= (point-min) 1)))
5001 (goto-char (point-min))
5002 (gnus-insert-prev-page-button)))
5003 (when (and (gnus-visual-p 'page-marker)
5004 (< (+ (point-max) 2) (buffer-size)))
5006 (goto-char (point-max))
5007 (gnus-insert-next-page-button)))))
5009 ;; Article mode commands
5011 (defun gnus-article-goto-next-page ()
5012 "Show the next page of the article."
5014 (when (gnus-article-next-page)
5015 (goto-char (point-min))
5016 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5018 (defun gnus-article-goto-prev-page ()
5019 "Show the next page of the article."
5021 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5022 (gnus-article-prev-page nil)))
5024 (defun gnus-article-next-page (&optional lines)
5025 "Show the next page of the current article.
5026 If end of article, return non-nil. Otherwise return nil.
5027 Argument LINES specifies lines to be scrolled up."
5029 (let ((start (window-start))
5030 end-of-buffer end-of-page)
5032 (move-to-window-line -1)
5033 (if (<= (point) start)
5036 (setq start (point)))
5039 (unless (or (cond ((eq (1+ (buffer-size)) (point))
5040 (and (pos-visible-in-window-p)
5041 (setq end-of-buffer t)))
5043 (setq end-of-page t)))
5045 (move-to-window-line lines)
5046 (unless (search-backward "\n\n" nil t)
5047 (setq start (point)))))
5048 (cond (end-of-buffer t)
5050 (gnus-narrow-to-page 1)
5054 (set-window-start (selected-window) start)
5055 (let (window-pixel-scroll-increment)
5059 (defun gnus-article-prev-page (&optional lines)
5060 "Show previous page of current article.
5061 Argument LINES specifies lines to be scrolled down."
5063 (let (beginning-of-buffer beginning-of-page)
5065 (move-to-window-line 0)
5066 (cond ((eq 1 (point))
5067 (setq beginning-of-buffer t))
5069 (setq beginning-of-page t))))
5070 (cond (beginning-of-buffer)
5072 (gnus-narrow-to-page -1))
5075 (let (window-pixel-scroll-increment)
5076 (scroll-down lines))
5077 (beginning-of-buffer
5078 (goto-char (point-min))))))))
5080 (defun gnus-article-refer-article ()
5081 "Read article specified by message-id around point."
5083 (let ((point (point)))
5084 (search-forward ">" nil t) ;Move point to end of "<....>".
5085 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
5086 (let ((message-id (match-string 1)))
5088 (set-buffer gnus-summary-buffer)
5089 (gnus-summary-refer-article message-id))
5091 (error "No references around point"))))
5093 (defun gnus-article-show-summary ()
5094 "Reconfigure windows to show summary buffer."
5096 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5097 (error "There is no summary buffer for this article buffer")
5098 (gnus-article-set-globals)
5099 (gnus-configure-windows 'article)
5100 (gnus-summary-goto-subject gnus-current-article)
5101 (gnus-summary-position-point)))
5103 (defun gnus-article-describe-briefly ()
5104 "Describe article mode commands briefly."
5106 (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")))
5108 (defun gnus-article-summary-command ()
5109 "Execute the last keystroke in the summary buffer."
5111 (let ((obuf (current-buffer))
5112 (owin (current-window-configuration))
5114 (switch-to-buffer gnus-article-current-summary 'norecord)
5115 (setq func (lookup-key (current-local-map) (this-command-keys)))
5116 (call-interactively func)
5118 (set-window-configuration owin)
5119 (set-window-point (get-buffer-window (current-buffer)) (point))))
5121 (defun gnus-article-summary-command-nosave ()
5122 "Execute the last keystroke in the summary buffer."
5125 (pop-to-buffer gnus-article-current-summary 'norecord)
5126 (setq func (lookup-key (current-local-map) (this-command-keys)))
5127 (call-interactively func)))
5129 (defun gnus-article-check-buffer ()
5130 "Beep if not in an article buffer."
5131 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5132 (error "Command invoked outside of a Gnus article buffer")))
5134 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5135 "Read a summary buffer key sequence and execute it from the article buffer."
5137 (gnus-article-check-buffer)
5139 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5140 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5141 "=" "^" "\M-^" "|"))
5147 '("n" "Gn" "p" "Gp"))
5150 (set-buffer gnus-article-current-summary)
5151 (let (gnus-pick-mode)
5152 (push (or key last-command-event) unread-command-events)
5153 (setq keys (static-if (featurep 'xemacs)
5154 (events-to-keys (read-key-sequence nil))
5155 (read-key-sequence nil)))))
5158 (if (or (member keys nosaves)
5159 (member keys nosave-but-article)
5160 (member keys nosave-in-article))
5162 (save-window-excursion
5163 (pop-to-buffer gnus-article-current-summary 'norecord)
5164 ;; We disable the pick minor mode commands.
5165 (let (gnus-pick-mode)
5166 (setq func (lookup-key (current-local-map) keys))))
5170 (unless (member keys nosave-in-article)
5171 (set-buffer gnus-article-current-summary))
5172 (call-interactively func)
5173 (setq new-sum-point (point)))
5174 (when (member keys nosave-but-article)
5175 (pop-to-buffer gnus-article-buffer 'norecord)))
5176 ;; These commands should restore window configuration.
5177 (let ((obuf (current-buffer))
5178 (owin (current-window-configuration))
5180 (summary gnus-article-current-summary)
5181 func in-buffer selected)
5182 (if not-restore-window
5183 (pop-to-buffer summary 'norecord)
5184 (switch-to-buffer summary 'norecord))
5185 (setq in-buffer (current-buffer))
5186 ;; We disable the pick minor mode commands.
5187 (if (and (setq func (let (gnus-pick-mode)
5188 (lookup-key (current-local-map) keys)))
5191 (call-interactively func)
5192 (setq new-sum-point (point))
5193 (when (eq in-buffer (current-buffer))
5194 (setq selected (gnus-summary-select-article))
5196 (unless not-restore-window
5197 (set-window-configuration owin))
5198 (when (eq selected 'old)
5200 (set-window-start (get-buffer-window (current-buffer))
5202 (set-window-point (get-buffer-window (current-buffer))
5204 (let ((win (get-buffer-window gnus-article-current-summary)))
5206 (set-window-point win new-sum-point)))) )
5207 (switch-to-buffer gnus-article-buffer)
5210 (defun gnus-article-describe-key (key)
5211 "Display documentation of the function invoked by KEY. KEY is a string."
5212 (interactive "kDescribe key: ")
5213 (gnus-article-check-buffer)
5214 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5216 (set-buffer gnus-article-current-summary)
5217 (let (gnus-pick-mode)
5218 (if (featurep 'xemacs)
5220 (push (elt key 0) unread-command-events)
5221 (setq key (events-to-keys
5222 (read-key-sequence "Describe key: "))))
5223 (setq unread-command-events
5225 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5227 (setq key (read-key-sequence "Describe key: "))))
5229 (describe-key key)))
5231 (defun gnus-article-describe-key-briefly (key &optional insert)
5232 "Display documentation of the function invoked by KEY. KEY is a string."
5233 (interactive "kDescribe key: \nP")
5234 (gnus-article-check-buffer)
5235 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5237 (set-buffer gnus-article-current-summary)
5238 (let (gnus-pick-mode)
5239 (if (featurep 'xemacs)
5241 (push (elt key 0) unread-command-events)
5242 (setq key (events-to-keys
5243 (read-key-sequence "Describe key: "))))
5244 (setq unread-command-events
5246 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5248 (setq key (read-key-sequence "Describe key: "))))
5249 (describe-key-briefly key insert))
5250 (describe-key-briefly key insert)))
5252 (defun gnus-article-reply-with-original (&optional wide)
5253 "Start composing a reply mail to the current message.
5254 The text in the region will be yanked. If the region isn't active,
5255 the entire article will be yanked."
5257 (let ((article (cdr gnus-article-current)) cont)
5259 (gnus-summary-reply (list (list article)) wide)
5260 (setq cont (buffer-substring (point) (mark t)))
5261 ;; Deactivate active regions.
5262 (when (and (boundp 'transient-mark-mode)
5263 transient-mark-mode)
5264 (setq mark-active nil))
5266 (list (list article cont)) wide))))
5268 (defun gnus-article-followup-with-original ()
5269 "Compose a followup to the current article.
5270 The text in the region will be yanked. If the region isn't active,
5271 the entire article will be yanked."
5273 (let ((article (cdr gnus-article-current))
5276 (gnus-summary-followup (list (list article)))
5277 (setq cont (buffer-substring (point) (mark t)))
5278 ;; Deactivate active regions.
5279 (when (and (boundp 'transient-mark-mode)
5280 transient-mark-mode)
5281 (setq mark-active nil))
5282 (gnus-summary-followup
5283 (list (list article cont))))))
5285 (defun gnus-article-hide (&optional arg force)
5286 "Hide all the gruft in the current article.
5287 This means that PGP stuff, signatures, cited text and (some)
5288 headers will be hidden.
5289 If given a prefix, show the hidden text instead."
5290 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5291 (gnus-article-hide-headers arg)
5292 (gnus-article-hide-list-identifiers arg)
5293 (gnus-article-hide-pgp arg)
5294 (gnus-article-hide-citation-maybe arg force)
5295 (gnus-article-hide-signature arg))
5297 (defun gnus-article-maybe-highlight ()
5298 "Do some article highlighting if article highlighting is requested."
5299 (when (gnus-visual-p 'article-highlight 'highlight)
5300 (gnus-article-highlight-some)))
5302 (defun gnus-check-group-server ()
5303 ;; Make sure the connection to the server is alive.
5304 (unless (gnus-server-opened
5305 (gnus-find-method-for-group gnus-newsgroup-name))
5306 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5307 (gnus-request-group gnus-newsgroup-name t)))
5310 (autoload 'nneething-get-file-name "nneething"))
5312 (defun gnus-request-article-this-buffer (article group)
5313 "Get an article and insert it into this buffer."
5314 (let (do-update-line sparse-header)
5318 (gnus-kill-all-overlays)
5319 (setq group (or group gnus-newsgroup-name))
5321 ;; Using `gnus-request-article' directly will insert the article into
5322 ;; `nntp-server-buffer' - so we'll save some time by not having to
5323 ;; copy it from the server buffer into the article buffer.
5325 ;; We only request an article by message-id when we do not have the
5326 ;; headers for it, so we'll have to get those.
5327 (when (stringp article)
5328 (gnus-read-header article))
5330 ;; If the article number is negative, that means that this article
5331 ;; doesn't belong in this newsgroup (possibly), so we find its
5332 ;; message-id and request it by id instead of number.
5333 (when (and (numberp article)
5335 (get-buffer gnus-summary-buffer)
5336 (gnus-buffer-exists-p gnus-summary-buffer))
5338 (set-buffer gnus-summary-buffer)
5339 (let ((header (gnus-summary-article-header article)))
5342 ((memq article gnus-newsgroup-sparse)
5343 ;; This is a sparse gap article.
5344 (setq do-update-line article)
5345 (setq article (mail-header-id header))
5346 (setq sparse-header (gnus-read-header article))
5347 (setq gnus-newsgroup-sparse
5348 (delq article gnus-newsgroup-sparse)))
5350 ;; It's a real article.
5351 (setq article (mail-header-id header)))
5353 ;; It is an extracted pseudo-article.
5354 (setq article 'pseudo)
5355 (gnus-request-pseudo-article header))))
5357 (let ((method (gnus-find-method-for-group
5358 gnus-newsgroup-name)))
5359 (when (and (eq (car method) 'nneething)
5361 (let ((dir (nneething-get-file-name
5362 (mail-header-id header))))
5363 (when (and (stringp dir)
5364 (file-directory-p dir))
5365 (setq article 'nneething)
5366 (gnus-group-enter-directory dir))))))))
5369 ;; Refuse to select canceled articles.
5370 ((and (numberp article)
5372 (get-buffer gnus-summary-buffer)
5373 (gnus-buffer-exists-p gnus-summary-buffer)
5374 (eq (cdr (save-excursion
5375 (set-buffer gnus-summary-buffer)
5376 (assq article gnus-newsgroup-reads)))
5377 gnus-canceled-mark))
5379 ;; We first check `gnus-original-article-buffer'.
5380 ((and (get-buffer gnus-original-article-buffer)
5383 (set-buffer gnus-original-article-buffer)
5384 (and (equal (car gnus-original-article) group)
5385 (eq (cdr gnus-original-article) article))))
5386 (insert-buffer-substring gnus-original-article-buffer)
5388 ;; Check the backlog.
5389 ((and gnus-keep-backlog
5390 (gnus-backlog-request-article group article (current-buffer)))
5392 ;; Check asynchronous pre-fetch.
5393 ((gnus-async-request-fetched-article group article (current-buffer))
5394 (gnus-async-prefetch-next group article gnus-summary-buffer)
5395 (when (and (numberp article) gnus-keep-backlog)
5396 (gnus-backlog-enter-article group article (current-buffer)))
5399 ((and gnus-use-cache
5401 (gnus-cache-request-article article group))
5403 ;; Check the agent cache.
5404 ((and gnus-agent gnus-agent-cache gnus-plugged
5406 (gnus-agent-request-article article group))
5408 ;; Get the article and put into the article buffer.
5409 ((or (stringp article)
5411 (let ((gnus-override-method gnus-override-method)
5412 (methods (and (stringp article)
5413 gnus-refer-article-method))
5414 (backend (car (gnus-find-method-for-group
5415 gnus-newsgroup-name)))
5417 (buffer-read-only nil))
5418 (if (or (not (listp methods))
5419 (and (symbolp (car methods))
5420 (assq (car methods) nnoo-definition-alist)))
5421 (setq methods (list methods)))
5422 (when (and (null gnus-override-method)
5424 (setq gnus-override-method (pop methods)))
5426 (when (eq gnus-override-method 'current)
5427 (setq gnus-override-method
5428 (with-current-buffer gnus-summary-buffer
5429 gnus-current-select-method)))
5431 (gnus-kill-all-overlays)
5432 (let ((gnus-newsgroup-name group))
5433 (gnus-check-group-server))
5435 ((gnus-request-article article group (current-buffer))
5436 (when (numberp article)
5437 (gnus-async-prefetch-next group article
5438 gnus-summary-buffer)
5439 (when gnus-keep-backlog
5440 (gnus-backlog-enter-article
5441 group article (current-buffer))))
5442 (setq result 'article))
5444 (setq gnus-override-method (pop methods)))
5445 ((not (string-match "^400 "
5446 (nnheader-get-report backend)))
5447 ;; If we get 400 server disconnect, reconnect and
5448 ;; retry; otherwise, assume the article has expired.
5449 (setq result 'done))))
5450 (and (eq result 'article) 'article)))
5454 ;; Associate this article with the current summary buffer.
5455 (setq gnus-article-current-summary gnus-summary-buffer)
5457 ;; Take the article from the original article buffer
5458 ;; and place it in the buffer it's supposed to be in.
5459 (when (and (get-buffer gnus-article-buffer)
5460 (equal (buffer-name (current-buffer))
5461 (buffer-name (get-buffer gnus-article-buffer))))
5463 (if (get-buffer gnus-original-article-buffer)
5464 (set-buffer gnus-original-article-buffer)
5465 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5466 (buffer-disable-undo)
5467 (setq major-mode 'gnus-original-article-mode)
5468 (setq buffer-read-only t))
5469 (let (buffer-read-only)
5471 (insert-buffer-substring gnus-article-buffer))
5472 (setq gnus-original-article (cons group article)))
5475 (run-hooks 'gnus-article-decode-hook)
5476 ;; Mark article as decoded or not.
5477 (setq gnus-article-decoded-p gnus-article-decode-hook))
5479 ;; Update sparse articles.
5480 (when (and do-update-line
5481 (or (numberp article)
5483 (let ((buf (current-buffer)))
5484 (set-buffer gnus-summary-buffer)
5485 (gnus-summary-update-article do-update-line sparse-header)
5486 (gnus-summary-goto-subject do-update-line nil t)
5487 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5489 (set-buffer buf))))))
5495 (defcustom gnus-article-edit-mode-hook nil
5496 "Hook run in article edit mode buffers."
5497 :group 'gnus-article-various
5500 (defcustom gnus-article-edit-article-setup-function
5501 'gnus-article-mime-edit-article-setup
5502 "Function called to setup an editing article buffer."
5503 :group 'gnus-article-various
5506 (defvar gnus-article-edit-done-function nil)
5508 (defvar gnus-article-edit-mode-map nil)
5510 ;; Should we be using derived.el for this?
5511 (unless gnus-article-edit-mode-map
5512 (setq gnus-article-edit-mode-map (make-keymap))
5513 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5515 (gnus-define-keys gnus-article-edit-mode-map
5516 "\C-c?" describe-mode
5517 "\C-c\C-c" gnus-article-edit-done
5518 "\C-c\C-k" gnus-article-edit-exit
5519 "\C-c\C-f\C-t" message-goto-to
5520 "\C-c\C-f\C-o" message-goto-from
5521 "\C-c\C-f\C-b" message-goto-bcc
5522 ;;"\C-c\C-f\C-w" message-goto-fcc
5523 "\C-c\C-f\C-c" message-goto-cc
5524 "\C-c\C-f\C-s" message-goto-subject
5525 "\C-c\C-f\C-r" message-goto-reply-to
5526 "\C-c\C-f\C-n" message-goto-newsgroups
5527 "\C-c\C-f\C-d" message-goto-distribution
5528 "\C-c\C-f\C-f" message-goto-followup-to
5529 "\C-c\C-f\C-m" message-goto-mail-followup-to
5530 "\C-c\C-f\C-k" message-goto-keywords
5531 "\C-c\C-f\C-u" message-goto-summary
5532 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5533 "\C-c\C-f\C-a" message-gen-unsubscribed-mft
5534 "\C-c\C-b" message-goto-body
5535 "\C-c\C-i" message-goto-signature
5537 "\C-c\C-t" message-insert-to
5538 "\C-c\C-n" message-insert-newsgroups
5539 "\C-c\C-o" message-sort-headers
5540 "\C-c\C-e" message-elide-region
5541 "\C-c\C-v" message-delete-not-region
5542 "\C-c\C-z" message-kill-to-signature
5543 "\M-\r" message-newline-and-reformat
5544 "\C-c\C-a" mml-attach-file
5545 "\C-a" message-beginning-of-line
5547 "\M-;" comment-region)
5549 (gnus-define-keys (gnus-article-edit-wash-map
5550 "\C-c\C-w" gnus-article-edit-mode-map)
5551 "f" gnus-article-edit-full-stops))
5554 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5556 ["Fetch To" message-insert-to t]
5557 ["Fetch Newsgroups" message-insert-newsgroups t]
5559 ["To" message-goto-to t]
5560 ["From" message-goto-from t]
5561 ["Subject" message-goto-subject t]
5562 ["Cc" message-goto-cc t]
5563 ["Reply-To" message-goto-reply-to t]
5564 ["Summary" message-goto-summary t]
5565 ["Keywords" message-goto-keywords t]
5566 ["Newsgroups" message-goto-newsgroups t]
5567 ["Followup-To" message-goto-followup-to t]
5568 ["Mail-Followup-To" message-goto-mail-followup-to t]
5569 ["Distribution" message-goto-distribution t]
5570 ["Body" message-goto-body t]
5571 ["Signature" message-goto-signature t]))
5573 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5574 "Major mode for editing articles.
5575 This is an extended text-mode.
5577 \\{gnus-article-edit-mode-map}"
5578 (make-local-variable 'gnus-article-edit-done-function)
5579 (make-local-variable 'gnus-prev-winconf)
5580 (set (make-local-variable 'font-lock-defaults)
5581 '(message-font-lock-keywords t))
5582 (set (make-local-variable 'mail-header-separator) "")
5583 (easy-menu-add message-mode-field-menu message-mode-map)
5584 (setq buffer-read-only nil)
5585 (buffer-enable-undo)
5588 (defun gnus-article-edit (&optional force)
5589 "Edit the current article.
5590 This will have permanent effect only in mail groups.
5591 If FORCE is non-nil, allow editing of articles even in read-only
5594 (when (and (not force)
5595 (gnus-group-read-only-p))
5596 (error "The current newsgroup does not support article editing"))
5597 (gnus-article-date-original)
5598 (gnus-article-edit-article
5600 `(lambda (no-highlight)
5602 (gnus-summary-edit-article-done
5603 ,(or (mail-header-references gnus-current-headers) "")
5604 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5606 (defun gnus-article-edit-article (start-func exit-func)
5607 "Start editing the contents of the current article buffer."
5608 (let ((winconf (current-window-configuration)))
5609 (set-buffer gnus-article-buffer)
5610 (gnus-article-edit-mode)
5611 (funcall start-func)
5612 (set-buffer-modified-p nil)
5613 (gnus-configure-windows 'edit-article)
5614 (setq gnus-article-edit-done-function exit-func)
5615 (setq gnus-prev-winconf winconf)
5616 (when gnus-article-edit-article-setup-function
5617 (funcall gnus-article-edit-article-setup-function))
5618 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5620 (defun gnus-article-edit-done (&optional arg)
5621 "Update the article edits and exit."
5623 (let ((func gnus-article-edit-done-function)
5624 (buf (current-buffer))
5625 (start (window-start))
5627 (winconf gnus-prev-winconf))
5628 (remove-hook 'gnus-article-mode-hook
5629 'gnus-article-mime-edit-article-unwind)
5630 (widen) ;; Widen it in case that users narrowed the buffer.
5633 ;; The cache and backlog have to be flushed somewhat.
5634 (when gnus-keep-backlog
5635 (gnus-backlog-remove-article
5636 (car gnus-article-current) (cdr gnus-article-current)))
5637 ;; Flush original article as well.
5639 (when (get-buffer gnus-original-article-buffer)
5640 (set-buffer gnus-original-article-buffer)
5641 (setq gnus-original-article nil)))
5642 (when gnus-use-cache
5643 (gnus-cache-update-article
5644 (car gnus-article-current) (cdr gnus-article-current)))
5645 ;; We remove all text props from the article buffer.
5646 (kill-all-local-variables)
5647 (gnus-set-text-properties (point-min) (point-max) nil)
5649 (set-window-configuration winconf)
5651 (set-window-start (get-buffer-window buf) start)
5652 (set-window-point (get-buffer-window buf) (point))))
5654 (defun gnus-article-edit-exit ()
5655 "Exit the article editing without updating."
5657 (when (or (not (buffer-modified-p))
5658 (yes-or-no-p "Article modified; kill anyway? "))
5659 (let ((curbuf (current-buffer))
5661 (window-start (window-start)))
5663 (if (gnus-buffer-live-p gnus-original-article-buffer)
5664 (insert-buffer-substring gnus-original-article-buffer))
5665 (let ((winconf gnus-prev-winconf))
5667 (set-window-configuration winconf)
5668 ;; Tippy-toe some to make sure that point remains where it was.
5669 (save-current-buffer
5671 (set-window-start (get-buffer-window (current-buffer)) window-start)
5674 (defun gnus-article-edit-full-stops ()
5675 "Interactively repair spacing at end of sentences."
5678 (goto-char (point-min))
5679 (search-forward-regexp "^$" nil t)
5680 (let ((case-fold-search nil))
5681 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5684 ;;; Article editing with MIME-Edit
5687 (defcustom gnus-article-mime-edit-article-setup-hook nil
5688 "Hook run after setting up a MIME editing article buffer."
5689 :group 'gnus-article-various
5692 (defun gnus-article-mime-edit-article-unwind ()
5693 "Unwind `gnus-article-buffer' if article editing was given up."
5694 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5695 (when (featurep 'font-lock)
5696 (setq font-lock-defaults nil)
5697 (font-lock-mode -1))
5698 (when mime-edit-mode-flag
5699 (mime-edit-exit 'nomime 'no-error)
5702 (defun gnus-article-mime-edit-article-setup ()
5703 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5704 after replacing with the original article."
5705 (setq gnus-show-mime t)
5706 (setq gnus-article-edit-done-function
5707 `(lambda (&rest args)
5708 (when mime-edit-mode-flag
5709 (let (mime-edit-insert-user-agent-field)
5712 (goto-char (point-min))
5713 (let (case-fold-search)
5714 (when (re-search-forward
5715 (format "^%s$" (regexp-quote mail-header-separator))
5717 (replace-match "")))
5718 (apply ,gnus-article-edit-done-function args)
5721 (buffer-substring-no-properties (point-min) (point-max))
5722 (set-buffer (get-buffer-create gnus-original-article-buffer))
5724 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5725 (set-buffer gnus-article-buffer)
5726 (gnus-article-prepare-display)))
5727 (substitute-key-definition 'gnus-article-edit-done
5728 'gnus-article-mime-edit-done
5729 gnus-article-edit-mode-map)
5730 (substitute-key-definition 'gnus-article-edit-exit
5731 'gnus-article-mime-edit-exit
5732 gnus-article-edit-mode-map)
5734 (insert-buffer-substring gnus-original-article-buffer)
5735 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5736 (fset 'mime-edit-decode-single-part-in-buffer
5737 (lambda (&rest args)
5738 (if (let ((content-type (car args)))
5739 (and (eq 'message (mime-content-type-primary-type
5741 (eq 'rfc822 (mime-content-type-subtype content-type))))
5742 (setcar (cdr args) 'not-decode-text))
5746 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5747 (when (featurep 'font-lock)
5748 (set (make-local-variable 'font-lock-defaults)
5749 '(message-font-lock-keywords t))
5750 (font-lock-set-defaults)
5751 (turn-on-font-lock))
5752 (set-buffer-modified-p nil)
5753 (delete-other-windows)
5754 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5755 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5757 (defun gnus-article-mime-edit-done (&optional arg)
5758 "Update the article MIME edits and exit."
5760 (when (featurep 'font-lock)
5761 (setq font-lock-defaults nil)
5762 (font-lock-mode -1))
5763 (gnus-article-edit-done arg))
5765 (defun gnus-article-mime-edit-exit ()
5766 "Exit the article MIME editing without updating."
5768 (when (or (not (buffer-modified-p))
5769 (yes-or-no-p "Article modified; kill anyway? "))
5770 (when (featurep 'font-lock)
5771 (setq font-lock-defaults nil)
5772 (font-lock-mode -1))
5773 (when mime-edit-mode-flag
5774 (let (mime-edit-insert-user-agent-field)
5777 (goto-char (point-min))
5778 (let (case-fold-search)
5779 (when (re-search-forward
5780 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5781 (replace-match "")))
5782 (let ((winconf gnus-prev-winconf))
5784 (buffer-substring-no-properties (point-min) (point-max))
5785 (set-buffer (get-buffer-create gnus-original-article-buffer))
5787 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5788 (set-buffer gnus-article-buffer)
5789 (gnus-article-prepare-display)
5790 (set-window-configuration winconf))))
5793 ;;; Article highlights
5796 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5798 ;;; Internal Variables:
5800 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
5801 "Regular expression that matches URLs."
5802 :group 'gnus-article-buttons
5805 (defcustom gnus-button-alist
5806 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5807 0 t gnus-button-handle-news 3)
5808 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5809 gnus-button-handle-news 2)
5810 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5812 gnus-button-fetch-group 4)
5813 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5814 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5815 t gnus-button-message-id 3)
5816 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5817 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5818 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5820 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
5821 gnus-button-handle-info 2)
5822 ;; This is how URLs _should_ be embedded in text...
5823 ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5825 (gnus-button-url-regexp 0 t browse-url 0))
5826 "*Alist of regexps matching buttons in article bodies.
5828 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5829 REGEXP: is the string matching text around the button,
5830 BUTTON: is the number of the regexp grouping actually matching the button,
5831 FORM: is a lisp expression which must eval to true for the button to
5833 CALLBACK: is the function to call when the user push this button, and each
5834 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5836 CALLBACK can also be a variable, in that case the value of that
5837 variable it the real callback function."
5838 :group 'gnus-article-buttons
5839 :type '(repeat (list (choice regexp variable)
5840 (integer :tag "Button")
5842 (function :tag "Callback")
5845 (integer :tag "Regexp group")))))
5847 (defcustom gnus-header-button-alist
5848 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5849 0 t gnus-button-message-id 0)
5850 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5851 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5852 0 t gnus-button-mailto 0)
5853 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5854 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5855 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5856 ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5857 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5858 gnus-button-message-id 3))
5859 "*Alist of headers and regexps to match buttons in article heads.
5861 This alist is very similar to `gnus-button-alist', except that each
5862 alist has an additional HEADER element first in each entry:
5864 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5866 HEADER is a regexp to match a header. For a fuller explanation, see
5867 `gnus-button-alist'."
5868 :group 'gnus-article-buttons
5869 :group 'gnus-article-headers
5870 :type '(repeat (list (regexp :tag "Header")
5872 (integer :tag "Button")
5874 (function :tag "Callback")
5877 (integer :tag "Regexp group")))))
5879 (defvar gnus-button-regexp nil)
5880 (defvar gnus-button-marker-list nil)
5881 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5883 (defvar gnus-button-last nil)
5884 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5888 (defun gnus-article-push-button (event)
5889 "Check text under the mouse pointer for a callback function.
5890 If the text under the mouse pointer has a `gnus-callback' property,
5891 call it with the value of the `gnus-data' text property."
5893 (set-buffer (window-buffer (posn-window (event-start event))))
5894 (let* ((pos (posn-point (event-start event)))
5895 (data (get-text-property pos 'gnus-data))
5896 (fun (get-text-property pos 'gnus-callback)))
5899 (funcall fun data))))
5901 (defun gnus-article-press-button ()
5902 "Check text at point for a callback function.
5903 If the text at point has a `gnus-callback' property,
5904 call it with the value of the `gnus-data' text property."
5906 (let* ((data (get-text-property (point) 'gnus-data))
5907 (fun (get-text-property (point) 'gnus-callback)))
5909 (funcall fun data))))
5911 (defun gnus-article-prev-button (n)
5912 "Move point to N buttons backward.
5913 If N is negative, move forward instead."
5915 (gnus-article-next-button (- n)))
5917 (defun gnus-article-next-button (n)
5918 "Move point to N buttons forward.
5919 If N is negative, move backward instead."
5921 (let ((function (if (< n 0) 'previous-single-property-change
5922 'next-single-property-change))
5923 (inhibit-point-motion-hooks t)
5925 (limit (if (< n 0) (point-min) (point-max))))
5927 (while (and (not (= limit (point)))
5929 ;; Skip past the current button.
5930 (when (get-text-property (point) 'gnus-callback)
5931 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5932 ;; Go to the next (or previous) button.
5933 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5934 ;; Put point at the start of the button.
5935 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5936 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5937 ;; Skip past intangible buttons.
5938 (when (get-text-property (point) 'intangible)
5942 (gnus-message 5 "No more buttons"))
5945 (defun gnus-article-highlight (&optional force)
5946 "Highlight current article.
5947 This function calls `gnus-article-highlight-headers',
5948 `gnus-article-highlight-citation',
5949 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5950 do the highlighting. See the documentation for those functions."
5951 (interactive (list 'force))
5952 (gnus-article-highlight-headers)
5953 (gnus-article-highlight-citation force)
5954 (gnus-article-highlight-signature)
5955 (gnus-article-add-buttons force)
5956 (gnus-article-add-buttons-to-head))
5958 (defun gnus-article-highlight-some (&optional force)
5959 "Highlight current article.
5960 This function calls `gnus-article-highlight-headers',
5961 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5962 do the highlighting. See the documentation for those functions."
5963 (interactive (list 'force))
5964 (gnus-article-highlight-headers)
5965 (gnus-article-highlight-signature)
5966 (gnus-article-add-buttons))
5968 (defun gnus-article-highlight-headers ()
5969 "Highlight article headers as specified by `gnus-header-face-alist'."
5972 (set-buffer gnus-article-buffer)
5974 (let ((alist gnus-header-face-alist)
5975 (buffer-read-only nil)
5976 (case-fold-search t)
5977 (inhibit-point-motion-hooks t)
5978 entry regexp header-face field-face from hpoints fpoints)
5979 (article-narrow-to-head)
5980 (while (setq entry (pop alist))
5981 (goto-char (point-min))
5982 (setq regexp (concat "^\\("
5983 (if (string-equal "" (nth 0 entry))
5987 header-face (nth 1 entry)
5988 field-face (nth 2 entry))
5989 (while (and (re-search-forward regexp nil t)
5993 (unless (search-forward ":" nil t)
5995 (when (and header-face
5996 (not (memq (point) hpoints)))
5997 (push (point) hpoints)
5998 (gnus-put-text-property from (point) 'face header-face))
5999 (when (and field-face
6000 (not (memq (setq from (point)) fpoints)))
6002 (if (re-search-forward "^[^ \t]" nil t)
6004 (goto-char (point-max)))
6005 (gnus-put-text-property from (point) 'face field-face))))))))
6007 (defun gnus-article-highlight-signature ()
6008 "Highlight the signature in an article.
6009 It does this by highlighting everything after
6010 `gnus-signature-separator' using `gnus-signature-face'."
6012 (when gnus-signature-face
6014 (set-buffer gnus-article-buffer)
6015 (let ((buffer-read-only nil)
6016 (inhibit-point-motion-hooks t))
6018 (when (gnus-article-narrow-to-signature)
6019 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6020 'face gnus-signature-face)))))))
6022 (defun gnus-article-buttonize-signature ()
6023 "Add button to the signature."
6026 (set-buffer gnus-article-buffer)
6027 (let ((buffer-read-only nil)
6028 (inhibit-point-motion-hooks t))
6029 (when (gnus-article-search-signature)
6030 (gnus-article-add-button (match-beginning 0) (match-end 0)
6031 'gnus-signature-toggle
6032 (set-marker (make-marker)
6033 (1+ (match-end 0))))))))
6035 (defun gnus-button-in-region-p (b e prop)
6036 "Say whether PROP exists in the region."
6037 (text-property-not-all b e prop nil))
6039 (defun gnus-article-add-buttons (&optional force)
6040 "Find external references in the article and make buttons of them.
6041 \"External references\" are things like Message-IDs and URLs, as
6042 specified by `gnus-button-alist'."
6043 (interactive (list 'force))
6045 (set-buffer gnus-article-buffer)
6046 (let ((buffer-read-only nil)
6047 (inhibit-point-motion-hooks t)
6048 (case-fold-search t)
6049 (alist gnus-button-alist)
6051 ;; Remove all old markers.
6052 (let (marker entry new-list)
6053 (while (setq marker (pop gnus-button-marker-list))
6054 (if (or (< marker (point-min)) (>= marker (point-max)))
6055 (push marker new-list)
6057 (when (setq entry (gnus-button-entry))
6058 (put-text-property (match-beginning (nth 1 entry))
6059 (match-end (nth 1 entry))
6060 'gnus-callback nil))
6061 (set-marker marker nil)))
6062 (setq gnus-button-marker-list new-list))
6063 ;; We skip the headers.
6066 (while (setq entry (pop alist))
6067 (setq regexp (eval (car entry)))
6069 (while (re-search-forward regexp nil t)
6070 (let* ((start (and entry (match-beginning (nth 1 entry))))
6071 (end (and entry (match-end (nth 1 entry))))
6072 (from (match-beginning 0)))
6073 (when (and (or (eq t (nth 2 entry))
6074 (eval (nth 2 entry)))
6075 (not (gnus-button-in-region-p
6076 start end 'gnus-callback)))
6077 ;; That optional form returned non-nil, so we add the
6079 (gnus-article-add-button
6080 start end 'gnus-button-push
6081 (car (push (set-marker (make-marker) from)
6082 gnus-button-marker-list))))))))))
6084 ;; Add buttons to the head of an article.
6085 (defun gnus-article-add-buttons-to-head ()
6086 "Add buttons to the head of the article."
6089 (set-buffer gnus-article-buffer)
6091 (let ((buffer-read-only nil)
6092 (inhibit-point-motion-hooks t)
6093 (case-fold-search t)
6094 (alist gnus-header-button-alist)
6096 (article-narrow-to-head)
6098 ;; Each alist entry.
6099 (setq entry (car alist)
6101 (goto-char (point-min))
6102 (while (re-search-forward (car entry) nil t)
6103 ;; Each header matching the entry.
6104 (setq beg (match-beginning 0))
6105 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6106 (match-beginning 0))
6109 (while (re-search-forward (nth 1 entry) end t)
6110 ;; Each match within a header.
6111 (let* ((entry (cdr entry))
6112 (start (match-beginning (nth 1 entry)))
6113 (end (match-end (nth 1 entry)))
6114 (form (nth 2 entry)))
6115 (goto-char (match-end 0))
6117 (gnus-article-add-button
6118 start end (nth 3 entry)
6119 (buffer-substring (match-beginning (nth 4 entry))
6120 (match-end (nth 4 entry)))))))
6121 (goto-char end)))))))
6123 ;;; External functions:
6125 (defun gnus-article-add-button (from to fun &optional data)
6126 "Create a button between FROM and TO with callback FUN and data DATA."
6127 (when gnus-article-button-face
6128 (gnus-overlay-put (gnus-make-overlay from to)
6129 'face gnus-article-button-face))
6130 (gnus-add-text-properties
6132 (nconc (and gnus-article-mouse-face
6133 (list gnus-mouse-face-prop gnus-article-mouse-face))
6134 (list 'gnus-callback fun)
6135 (and data (list 'gnus-data data))))
6136 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6137 ;; Quote `:button-keymap' for Mule 2.3
6138 ;; but it won't work.
6139 ':button-keymap gnus-widget-button-keymap))
6141 ;;; Internal functions:
6143 (defun gnus-article-set-globals ()
6145 (set-buffer gnus-summary-buffer)
6146 (gnus-set-global-variables)))
6148 (defun gnus-signature-toggle (end)
6150 (set-buffer gnus-article-buffer)
6151 (let ((buffer-read-only nil)
6152 (inhibit-point-motion-hooks t)
6153 (limit (next-single-property-change end 'mime-view-entity
6155 (if (text-property-any end limit 'article-type 'signature)
6157 (gnus-delete-wash-type 'signature)
6158 (gnus-remove-text-properties-when
6159 'article-type 'signature end limit
6160 (cons 'article-type (cons 'signature
6161 gnus-hidden-properties))))
6162 (gnus-add-wash-type 'signature)
6163 (gnus-add-text-properties-when
6164 'article-type nil end limit
6165 (cons 'article-type (cons 'signature
6166 gnus-hidden-properties)))))
6167 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6168 (gnus-set-mode-line 'article))))
6170 (defun gnus-button-entry ()
6171 ;; Return the first entry in `gnus-button-alist' matching this place.
6172 (let ((alist gnus-button-alist)
6175 (setq entry (pop alist))
6176 (if (looking-at (eval (car entry)))
6181 (defun gnus-button-push (marker)
6182 ;; Push button starting at MARKER.
6185 (let* ((entry (gnus-button-entry))
6186 (inhibit-point-motion-hooks t)
6188 (args (mapcar (lambda (group)
6189 (let ((string (match-string group)))
6190 (gnus-set-text-properties
6191 0 (length string) nil string)
6198 (fboundp (symbol-value fun)))
6199 (apply (symbol-value fun) args))
6201 (gnus-message 1 "You must define `%S' to use this button"
6202 (cons fun args)))))))
6204 (defun gnus-parse-news-url (url)
6205 (let (scheme server group message-id articles)
6208 (goto-char (point-min))
6209 (when (looking-at "\\([A-Za-z]+\\):")
6210 (setq scheme (match-string 1))
6211 (goto-char (match-end 0)))
6212 (when (looking-at "//\\([^/]+\\)/")
6213 (setq server (match-string 1))
6214 (goto-char (match-end 0)))
6217 ((looking-at "\\(.*@.*\\)")
6218 (setq message-id (match-string 1)))
6219 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6220 (setq group (match-string 1)
6221 articles (split-string (match-string 2) "-")))
6222 ((looking-at "\\([^/]+\\)/?")
6223 (setq group (match-string 1)))
6225 (error "Unknown news URL syntax"))))
6226 (list scheme server group message-id articles)))
6228 (defun gnus-button-handle-news (url)
6230 (destructuring-bind (scheme server group message-id articles)
6231 (gnus-parse-news-url url)
6235 (set-buffer gnus-summary-buffer)
6237 (let ((gnus-refer-article-method (list (list 'nntp server))))
6238 (gnus-summary-refer-article message-id))
6239 (gnus-summary-refer-article message-id))))
6241 (gnus-button-fetch-group url)))))
6243 (defun gnus-button-handle-info (url)
6244 "Fetch an info URL."
6246 "^\\([^:/]+\\)?/\\(.*\\)"
6248 (gnus-info-find-node
6249 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6252 (gnus-url-unhex-string (match-string 2 url))))
6253 (error "Can't parse %s" url)))
6255 (defun gnus-button-message-id (message-id)
6258 (set-buffer gnus-summary-buffer)
6259 (gnus-summary-refer-article message-id)))
6261 (defun gnus-button-fetch-group (address)
6262 "Fetch GROUP specified by ADDRESS."
6263 (if (not (string-match "[:/]" address))
6264 ;; This is just a simple group url.
6265 (gnus-group-read-ephemeral-group address gnus-select-method)
6268 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6270 (error "Can't parse %s" address)
6271 (gnus-group-read-ephemeral-group
6272 (match-string 4 address)
6273 `(nntp ,(match-string 1 address)
6274 (nntp-address ,(match-string 1 address))
6275 (nntp-port-number ,(if (match-end 3)
6276 (match-string 3 address)
6279 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6281 (defun gnus-url-parse-query-string (query &optional downcase)
6282 (let (retval pairs cur key val)
6283 (setq pairs (split-string query "&"))
6285 (setq cur (car pairs)
6287 (if (not (string-match "=" cur))
6289 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6290 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6292 (setq key (downcase key)))
6293 (setq cur (assoc key retval))
6295 (setcdr cur (cons val (cdr cur)))
6296 (setq retval (cons (list key val) retval)))))
6299 (defun gnus-url-mailto (url)
6300 ;; Send mail to someone
6301 (when (string-match "mailto:/*\\(.*\\)" url)
6302 (setq url (substring url (match-beginning 1) nil)))
6303 (let (to args subject func)
6304 (if (string-match (regexp-quote "?") url)
6305 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
6306 args (gnus-url-parse-query-string
6307 (substring url (match-end 0) nil) t))
6308 (setq to (gnus-url-unhex-string url)))
6309 (setq args (cons (list "to" to) args)
6310 subject (cdr-safe (assoc "subject" args)))
6313 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6316 (message-position-on-field (caar args)))
6317 (insert (mapconcat 'identity (cdar args) ", "))
6318 (setq args (cdr args)))
6321 (message-goto-subject))))
6323 (defun gnus-button-embedded-url (address)
6324 "Activate ADDRESS with `browse-url'."
6325 (browse-url (gnus-strip-whitespace address)))
6327 ;;; Next/prev buttons in the article buffer.
6329 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6330 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6332 (defvar gnus-prev-page-map
6333 (let ((map (make-sparse-keymap)))
6334 (unless (>= emacs-major-version 21)
6335 ;; XEmacs doesn't care.
6336 (set-keymap-parent map gnus-article-mode-map))
6337 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6338 (define-key map "\r" 'gnus-button-prev-page)
6341 (defun gnus-insert-prev-page-button ()
6343 (buffer-read-only nil)
6344 (situation (get-text-property (point-min) 'mime-view-situation)))
6346 gnus-prev-page-line-format nil
6347 `(,@(gnus-local-map-property gnus-prev-page-map)
6349 gnus-callback gnus-article-button-prev-page
6350 article-type annotation
6351 mime-view-situation ,situation))
6352 (widget-convert-button
6354 :action 'gnus-button-prev-page
6355 :button-keymap gnus-prev-page-map)))
6357 (defvar gnus-next-page-map
6358 (let ((map (make-sparse-keymap)))
6359 (unless (>= emacs-major-version 21)
6360 ;; XEmacs doesn't care.
6361 (set-keymap-parent map gnus-article-mode-map))
6362 (define-key map gnus-mouse-2 'gnus-button-next-page)
6363 (define-key map "\r" 'gnus-button-next-page)
6366 (defun gnus-button-next-page (&optional args more-args)
6367 "Go to the next page."
6369 (let ((win (selected-window)))
6370 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6371 (gnus-article-next-page)
6372 (select-window win)))
6374 (defun gnus-button-prev-page (&optional args more-args)
6375 "Go to the prev page."
6377 (let ((win (selected-window)))
6378 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6379 (gnus-article-prev-page)
6380 (select-window win)))
6382 (defun gnus-insert-next-page-button ()
6384 (buffer-read-only nil)
6385 (situation (get-text-property (point-min) 'mime-view-situation)))
6386 (gnus-eval-format gnus-next-page-line-format nil
6387 `(,@(gnus-local-map-property gnus-next-page-map)
6389 gnus-callback gnus-article-button-next-page
6390 article-type annotation
6391 mime-view-situation ,situation))
6392 (widget-convert-button
6394 :action 'gnus-button-next-page
6395 :button-keymap gnus-next-page-map)))
6397 (defun gnus-article-button-next-page (arg)
6398 "Go to the next page."
6400 (let ((win (selected-window)))
6401 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6402 (gnus-article-next-page)
6403 (select-window win)))
6405 (defun gnus-article-button-prev-page (arg)
6406 "Go to the prev page."
6408 (let ((win (selected-window)))
6409 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6410 (gnus-article-prev-page)
6411 (select-window win)))
6413 (defvar gnus-decode-header-methods
6414 '(mail-decode-encoded-word-region)
6415 "List of methods used to decode headers.
6417 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6418 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
6419 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
6420 whose names match REGEXP.
6423 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6424 mail-decode-encoded-word-region
6425 (\"chinese\" . rfc1843-decode-region))
6428 (defvar gnus-decode-header-methods-cache nil)
6430 (defun gnus-multi-decode-header (start end)
6431 "Apply the functions from `gnus-encoded-word-methods' that match."
6432 (unless (and gnus-decode-header-methods-cache
6433 (eq gnus-newsgroup-name
6434 (car gnus-decode-header-methods-cache)))
6435 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6438 (nconc gnus-decode-header-methods-cache (list x))
6439 (if (and gnus-newsgroup-name
6440 (string-match (car x) gnus-newsgroup-name))
6441 (nconc gnus-decode-header-methods-cache
6443 gnus-decode-header-methods))
6444 (let ((xlist gnus-decode-header-methods-cache))
6447 (narrow-to-region start end)
6449 (funcall (pop xlist) (point-min) (point-max))))))
6452 ;;; Treatment top-level handling.
6455 (defun gnus-treat-article (condition &optional part-number total-parts type)
6456 (let ((length (- (point-max) (point-min)))
6457 (alist gnus-treatment-function-alist)
6458 (article-goto-body-goes-to-point-min-p t)
6462 (let ((list gnus-article-treat-types))
6464 (when (string-match (pop list) type)
6465 (throw 'found t)))))))
6466 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6467 (entity (static-unless (featurep 'xemacs)
6468 (when (eq 'head condition)
6469 (get-text-property (point-min) 'mime-view-entity))))
6470 val elem buttonized)
6471 (gnus-run-hooks 'gnus-part-display-hook)
6472 (unless gnus-inhibit-treatment
6473 (while (setq elem (pop alist))
6476 (if (gnus-buffer-live-p gnus-summary-buffer)
6477 (set-buffer gnus-summary-buffer))
6478 (symbol-value (car elem))))
6479 (when (and (or (consp val)
6481 (gnus-treat-predicate val)
6482 (or (not (get (car elem) 'highlight))
6484 (when (and (not buttonized)
6486 '(gnus-treat-hide-signature
6487 gnus-treat-highlight-signature)))
6488 (gnus-article-buttonize-signature)
6489 (setq buttonized t))
6491 (funcall (cadr elem)))))
6492 ;; FSF Emacsen does not inherit the existing text properties
6493 ;; in the new text, so we should do it for `mime-view-entity'.
6494 (static-unless (featurep 'xemacs)
6496 (put-text-property (point-min) (point-max)
6497 'mime-view-entity entity))))))
6499 ;; Dynamic variables.
6501 (defvar part-number)
6502 (defvar total-parts)
6507 (defun gnus-treat-predicate (val)
6512 (stringp (car val)))
6513 (apply 'gnus-or (mapcar `(lambda (s)
6514 (string-match s ,(or gnus-newsgroup-name "")))
6517 (let ((pred (pop val)))
6520 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6522 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6524 (not (gnus-treat-predicate (car val))))
6526 (equal (car val) type))
6528 (error "%S is not a valid predicate" pred)))))
6538 (eq part-number total-parts))
6542 (error "%S is not a valid value" val))))
6544 (defun gnus-article-encrypt-body (protocol &optional n)
6545 "Encrypt the article body."
6548 (or gnus-article-encrypt-protocol
6549 (completing-read "Encrypt protocol: "
6550 gnus-article-encrypt-protocol-alist
6552 current-prefix-arg))
6553 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6555 (error (format "Can't find the encrypt protocol %s" protocol)))
6556 (if (equal gnus-newsgroup-name "nndraft:drafts")
6557 (error "Can't encrypt the article in group nndraft:drafts"))
6558 (if (equal gnus-newsgroup-name "nndraft:queue")
6559 (error "Don't encrypt the article in group nndraft:queue"))
6560 (gnus-summary-iterate n
6562 (set-buffer gnus-summary-buffer)
6563 (let ((mail-parse-charset gnus-newsgroup-charset)
6564 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6565 (summary-buffer gnus-summary-buffer)
6567 (gnus-set-global-variables)
6568 (when (gnus-group-read-only-p)
6569 (error "The current newsgroup does not support article encrypt"))
6570 (gnus-summary-show-article t)
6572 (or (mail-header-references gnus-current-headers) ""))
6573 (set-buffer gnus-article-buffer)
6574 (let* ((buffer-read-only nil)
6576 (mapcar (lambda (field)
6577 (and (save-restriction
6578 (message-narrow-to-head)
6579 (goto-char (point-min))
6580 (search-forward field nil t))
6582 (message-narrow-to-field)
6583 (buffer-substring (point-min) (point-max))
6584 (delete-region (point-min) (point-max))
6586 '("Content-Type:" "Content-Transfer-Encoding:"
6587 "Content-Disposition:"))))
6588 (message-narrow-to-head)
6589 (message-remove-header "MIME-Version")
6590 (goto-char (point-max))
6591 (setq point (point))
6592 (insert (apply 'concat headers))
6594 (narrow-to-region point (point-max))
6595 (let ((message-options message-options))
6596 (message-options-set 'message-sender user-mail-address)
6597 (message-options-set 'message-recipients user-mail-address)
6598 (message-options-set 'message-sign-encrypt 'not)
6600 (goto-char (point-min))
6601 (insert "MIME-Version: 1.0\n")
6603 (gnus-summary-edit-article-done
6604 references nil summary-buffer t))
6605 (when gnus-keep-backlog
6606 (gnus-backlog-remove-article
6607 (car gnus-article-current) (cdr gnus-article-current)))
6609 (when (get-buffer gnus-original-article-buffer)
6610 (set-buffer gnus-original-article-buffer)
6611 (setq gnus-original-article nil)))
6612 (when gnus-use-cache
6613 (gnus-cache-update-article
6614 (car gnus-article-current) (cdr gnus-article-current))))))))
6616 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6617 "The following specs can be used:
6618 %t The security MIME type
6621 %D Details if button is pressed")
6623 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6624 "The following specs can be used:
6625 %t The security MIME type
6628 %D Details if button is pressed")
6630 (defvar gnus-mime-security-button-line-format-alist
6631 '((?t gnus-tmp-type ?s)
6632 (?i gnus-tmp-info ?s)
6633 (?d gnus-tmp-details ?s)
6634 (?D gnus-tmp-pressed-details ?s)))
6636 (defvar gnus-mime-security-button-map
6637 (let ((map (make-sparse-keymap)))
6638 (unless (>= (string-to-number emacs-version) 21)
6639 (set-keymap-parent map gnus-article-mode-map))
6640 (define-key map gnus-mouse-2 'gnus-article-push-button)
6641 (define-key map "\r" 'gnus-article-press-button)
6644 (defvar gnus-mime-security-details-buffer nil)
6646 (defvar gnus-mime-security-button-pressed nil)
6648 (defvar gnus-mime-security-show-details-inline t
6649 "If non-nil, show details in the article buffer.")
6651 (defun gnus-mime-security-verify-or-decrypt (handle)
6652 (mm-remove-parts (cdr handle))
6653 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6654 point buffer-read-only)
6656 (goto-char (car region)))
6658 (narrow-to-region (point) (point))
6659 (with-current-buffer (mm-handle-multipart-original-buffer handle)
6660 (let* ((mm-verify-option 'known)
6661 (mm-decrypt-option 'known)
6662 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6663 (unless (eq nparts (cdr handle))
6664 (mm-destroy-parts (cdr handle))
6665 (setcdr handle nparts))))
6666 (setq point (point))
6667 (gnus-mime-display-security handle)
6668 (goto-char (point-max)))
6670 (delete-region (point) (cdr region))
6671 (set-marker (car region) nil)
6672 (set-marker (cdr region) nil))
6675 (defun gnus-mime-security-show-details (handle)
6676 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6678 (if gnus-mime-security-show-details-inline
6679 (let ((gnus-mime-security-button-pressed t)
6680 (gnus-mime-security-button-line-format
6681 (get-text-property (point) 'gnus-line-format))
6684 (while (eq (get-text-property (point) 'gnus-line-format)
6685 gnus-mime-security-button-line-format)
6689 (narrow-to-region (point) (point))
6690 (gnus-insert-mime-security-button handle))
6691 (delete-region (point)
6692 (or (text-property-not-all
6695 gnus-mime-security-button-line-format)
6697 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6698 (with-current-buffer gnus-mime-security-details-buffer
6701 (setq gnus-mime-security-details-buffer
6702 (gnus-get-buffer-create "*MIME Security Details*")))
6703 (with-current-buffer gnus-mime-security-details-buffer
6705 (goto-char (point-min)))
6706 (pop-to-buffer gnus-mime-security-details-buffer))
6707 (gnus-message 5 "No details."))))
6709 (defun gnus-mime-security-press-button (handle)
6710 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6711 (gnus-mime-security-show-details handle)
6712 (gnus-mime-security-verify-or-decrypt handle)))
6714 (defun gnus-insert-mime-security-button (handle &optional displayed)
6715 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6718 (or (nth 2 (assoc protocol mm-verify-function-alist))
6719 (nth 2 (assoc protocol mm-decrypt-function-alist))
6721 (if (equal (car handle) "multipart/signed")
6722 " Signed" " Encrypted")
6725 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6728 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6729 gnus-tmp-pressed-details
6731 (setq gnus-tmp-details
6732 (if gnus-tmp-details
6733 (concat "\n" gnus-tmp-details) ""))
6734 (setq gnus-tmp-pressed-details
6735 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6740 gnus-mime-security-button-line-format
6741 gnus-mime-security-button-line-format-alist
6742 `(,@(gnus-local-map-property gnus-mime-security-button-map)
6743 gnus-callback gnus-mime-security-press-button
6744 gnus-line-format ,gnus-mime-security-button-line-format
6745 article-type annotation
6748 (widget-convert-button
6751 :action 'gnus-widget-press-button
6752 :button-keymap gnus-mime-security-button-map
6754 (lambda (widget/window &optional overlay pos)
6755 ;; Needed to properly clear the message due to a bug in
6756 ;; wid-edit (XEmacs only).
6757 (if (boundp 'help-echo-owns-message)
6758 (setq help-echo-owns-message t))
6761 (aref gnus-mouse-2 0))))))
6763 (defun gnus-mime-display-security (handle)
6765 (narrow-to-region (point) (point))
6766 (unless (gnus-unbuttonized-mime-type-p (car handle))
6767 (gnus-insert-mime-security-button handle))
6768 (gnus-mime-display-mixed (cdr handle))
6771 (unless (gnus-unbuttonized-mime-type-p (car handle))
6772 (let ((gnus-mime-security-button-line-format
6773 gnus-mime-security-button-end-line-format))
6774 (gnus-insert-mime-security-button handle)))
6775 (mm-set-handle-multipart-parameter
6777 (cons (set-marker (make-marker) (point-min))
6778 (set-marker (make-marker) (point-max))))))
6784 (defun gnus-article-header-presentation-method (entity situation)
6785 (mime-insert-header entity)
6786 (article-decode-group-name))
6788 (set-alist 'mime-header-presentation-method-alist
6789 'gnus-original-article-mode
6790 #'gnus-article-header-presentation-method)
6792 (defun gnus-mime-preview-quitting-method ()
6793 (mime-preview-kill-buffer)
6794 (delete-other-windows)
6795 (gnus-article-show-summary)
6796 (gnus-summary-select-article gnus-show-all-headers t))
6798 (set-alist 'mime-preview-quitting-method-alist
6799 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6801 (set-alist 'mime-preview-following-method-alist
6802 'gnus-original-article-mode #'gnus-following-method)
6804 (set-alist 'mime-preview-over-to-previous-method-alist
6805 'gnus-original-article-mode
6807 (if (> (point-min) 1)
6808 (gnus-article-prev-page)
6809 (gnus-article-read-summary-keys
6810 nil (gnus-character-to-event ?P)))))
6812 (set-alist 'mime-preview-over-to-next-method-alist
6813 'gnus-original-article-mode'
6815 (if (< (point-max) (buffer-size))
6816 (gnus-article-next-page)
6817 (gnus-article-read-summary-keys
6818 nil (gnus-character-to-event ?N)))))
6828 (run-hooks 'gnus-art-load-hook)
6830 ;;; gnus-art.el ends here